<% local msg = {} if _SESSION["logined"] ~= nil then local name = _POST["name"] local ssh_key_path = _POST["ssh_key_path"] local ssh_password = _POST["ssh_password"] local modify = _POST["modify"] if modify == nil then local result = c_GetSSHKey(name) if result ~= nil then rawset(msg, "code", -2) rawset(msg, "error", "ssh config already exists") else local retval = c_AddSSHKey(name,ssh_key_path,ssh_password) if retval == false then rawset(msg, "code", -3) rawset(msg, "error", "add ssh key config ["..name.."] failed.") c_AddAdminLog("administrator '".._SESSION["admin"].."' added ssh key config ["..name.."] failed.",ADMIN_LOG_ERROR) else rawset(msg, "code", 0) c_AddAdminLog("administrator '".._SESSION["admin"].."' added ssh key config ["..name.."]",ADMIN_LOG_OK) end end else local retval = c_AddSSHKey(name,ssh_key_path,ssh_password) if retval == false then rawset(msg, "code", -3) rawset(msg, "error", "modify ssh key config ["..name.."] failed.") c_AddAdminLog("administrator '".._SESSION["admin"].."' modified ssh key config ["..name.."] failed.",ADMIN_LOG_ERROR) else rawset(msg, "code", 0) c_AddAdminLog("administrator '".._SESSION["admin"].."' modified ssh key config ["..name.."]",ADMIN_LOG_OK) end end print(json.encode(msg)) else rawset(msg, "code", -1) rawset(msg, "error", "not logged in") print(json.encode(msg)) end %>