|
|
|
@ -12,16 +12,19 @@
|
|
|
|
|
* user passwords.
|
|
|
|
|
*/
|
|
|
|
|
require __DIR__ . '/required.php';
|
|
|
|
|
require_once __DIR__ . '/lib/login.php';
|
|
|
|
|
header("Content-Type: application/json");
|
|
|
|
|
|
|
|
|
|
//try {
|
|
|
|
|
$key = $VARS['key'];
|
|
|
|
|
if ($database->has('apikeys', ['key' => $key]) !== TRUE) {
|
|
|
|
|
engageRateLimit();
|
|
|
|
|
http_response_code(403);
|
|
|
|
|
insertAuthLog(14, null, "Key: " . $key);
|
|
|
|
|
|
|
|
|
|
if (empty($VARS['key'])) {
|
|
|
|
|
die("\"403 Unauthorized\"");
|
|
|
|
|
} else {
|
|
|
|
|
$key = $VARS['key'];
|
|
|
|
|
if ($database->has('apikeys', ['key' => $key]) !== TRUE) {
|
|
|
|
|
engageRateLimit();
|
|
|
|
|
http_response_code(403);
|
|
|
|
|
Log::insert(LogType::API_BAD_KEY, null, "Key: " . $key);
|
|
|
|
|
die("\"403 Unauthorized\"");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -40,29 +43,31 @@ function getCensoredKey() {
|
|
|
|
|
return $resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($VARS['action'])) {
|
|
|
|
|
http_response_code(404);
|
|
|
|
|
die(json_encode("No action specified."));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch ($VARS['action']) {
|
|
|
|
|
case "ping":
|
|
|
|
|
exit(json_encode(["status" => "OK"]));
|
|
|
|
|
break;
|
|
|
|
|
case "auth":
|
|
|
|
|
$errmsg = "";
|
|
|
|
|
if (authenticate_user($VARS['username'], $VARS['password'], $errmsg)) {
|
|
|
|
|
insertAuthLog(12, null, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
$user = User::byUsername($VARS['username']);
|
|
|
|
|
if ($user->checkPassword($VARS['password'])) {
|
|
|
|
|
Log::insert(LogType::API_AUTH_OK, null, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
exit(json_encode(["status" => "OK", "msg" => $Strings->get("login successful", false)]));
|
|
|
|
|
} else {
|
|
|
|
|
insertAuthLog(13, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
if (!is_empty($errmsg)) {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->build("ldap error", ['error' => $errmsg], false)]));
|
|
|
|
|
}
|
|
|
|
|
if (user_exists($VARS['username'])) {
|
|
|
|
|
switch (get_account_status($VARS['username'])) {
|
|
|
|
|
case "LOCKED_OR_DISABLED":
|
|
|
|
|
Log::insert(LogType::API_AUTH_FAILED, $user->getUID(), "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
if ($user->exists()) {
|
|
|
|
|
switch ($user->getStatus()->get()) {
|
|
|
|
|
case AccountStatus::LOCKED_OR_DISABLED:
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("account locked", false)]));
|
|
|
|
|
case "TERMINATED":
|
|
|
|
|
case AccountStatus::TERMINATED:
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("account terminated", false)]));
|
|
|
|
|
case "CHANGE_PASSWORD":
|
|
|
|
|
case AccountStatus::CHANGE_PASSWORD:
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("password expired", false)]));
|
|
|
|
|
case "NORMAL":
|
|
|
|
|
case AccountStatus::NORMAL:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("account state error", false)]));
|
|
|
|
@ -72,165 +77,132 @@ switch ($VARS['action']) {
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "userinfo":
|
|
|
|
|
if (!is_empty($VARS['username'])) {
|
|
|
|
|
if (user_exists_local($VARS['username'])) {
|
|
|
|
|
$data = $database->select("accounts", ["uid", "username", "realname (name)", "email", "phone" => ["phone1 (1)", "phone2 (2)"], 'pin'], ["username" => strtolower($VARS['username'])])[0];
|
|
|
|
|
$data['pin'] = (is_null($data['pin']) || $data['pin'] == "" ? false : true);
|
|
|
|
|
exit(json_encode(["status" => "OK", "data" => $data]));
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)]));
|
|
|
|
|
}
|
|
|
|
|
} else if (!is_empty($VARS['uid'])) {
|
|
|
|
|
if ($database->has('accounts', ['uid' => $VARS['uid']])) {
|
|
|
|
|
$data = $database->select("accounts", ["uid", "username", "realname (name)", "email", "phone" => ["phone1 (1)", "phone2 (2)"], 'pin'], ["uid" => $VARS['uid']])[0];
|
|
|
|
|
$data['pin'] = (is_null($data['pin']) || $data['pin'] == "" ? false : true);
|
|
|
|
|
exit(json_encode(["status" => "OK", "data" => $data]));
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)]));
|
|
|
|
|
}
|
|
|
|
|
if (!empty($VARS['username'])) {
|
|
|
|
|
$user = User::byUsername($VARS['username']);
|
|
|
|
|
} else if (!empty($VARS['uid']) && is_numeric($VARS['uid'])) {
|
|
|
|
|
$user = new User($VARS['uid']);
|
|
|
|
|
} else {
|
|
|
|
|
http_response_code(400);
|
|
|
|
|
die("\"400 Bad Request\"");
|
|
|
|
|
}
|
|
|
|
|
if ($user->exists()) {
|
|
|
|
|
$data = $database->get("accounts", ["uid", "username", "realname (name)", "email", "phone" => ["phone1 (1)", "phone2 (2)"], 'pin'], ["uid" => $user->getUID()]);
|
|
|
|
|
$data['pin'] = (is_null($data['pin']) || $data['pin'] == "" ? false : true);
|
|
|
|
|
exit(json_encode(["status" => "OK", "data" => $data]));
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)]));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "userexists":
|
|
|
|
|
if (!is_empty($VARS['uid'])) {
|
|
|
|
|
if ($database->has('accounts', ['uid' => $VARS['uid']])) {
|
|
|
|
|
exit(json_encode(["status" => "OK", "exists" => true]));
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "OK", "exists" => false]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (user_exists_local($VARS['username'])) {
|
|
|
|
|
exit(json_encode(["status" => "OK", "exists" => true]));
|
|
|
|
|
if (!empty($VARS['uid']) && is_numeric($VARS['uid'])) {
|
|
|
|
|
$user = new User($VARS['uid']);
|
|
|
|
|
} else if (!empty($VARS['username'])) {
|
|
|
|
|
$user = User::byUsername($VARS['username']);
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "OK", "exists" => false]));
|
|
|
|
|
http_response_code(400);
|
|
|
|
|
die("\"400 Bad Request\"");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exit(json_encode(["status" => "OK", "exists" => $user->exists()]));
|
|
|
|
|
break;
|
|
|
|
|
case "hastotp":
|
|
|
|
|
if (userHasTOTP($VARS['username'])) {
|
|
|
|
|
exit(json_encode(["status" => "OK", "otp" => true]));
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "OK", "otp" => false]));
|
|
|
|
|
}
|
|
|
|
|
exit(json_encode(["status" => "OK", "otp" => User::byUsername($VARS['username'])->has2fa()]));
|
|
|
|
|
break;
|
|
|
|
|
case "verifytotp":
|
|
|
|
|
if (verifyTOTP($VARS['username'], $VARS['code'])) {
|
|
|
|
|
$user = User::byUsername($VARS['username']);
|
|
|
|
|
if ($user->check2fa($VARS['code'])) {
|
|
|
|
|
exit(json_encode(["status" => "OK", "valid" => true]));
|
|
|
|
|
} else {
|
|
|
|
|
insertAuthLog(7, null, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
Log::insert(LogType::API_BAD_2FA, null, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("2fa incorrect", false), "valid" => false]));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "acctstatus":
|
|
|
|
|
exit(json_encode(["status" => "OK", "account" => get_account_status($VARS['username'])]));
|
|
|
|
|
exit(json_encode(["status" => "OK", "account" => User::byUsername($VARS['username'])->getStatus()->getString()]));
|
|
|
|
|
case "login":
|
|
|
|
|
engageRateLimit();
|
|
|
|
|
// simulate a login, checking account status and alerts
|
|
|
|
|
$errmsg = "";
|
|
|
|
|
if (authenticate_user($VARS['username'], $VARS['password'], $errmsg)) {
|
|
|
|
|
$uid = $database->select('accounts', 'uid', ['username' => strtolower($VARS['username'])])[0];
|
|
|
|
|
switch (get_account_status($VARS['username'])) {
|
|
|
|
|
engageRateLimit();
|
|
|
|
|
$user = User::byUsername($VARS['username']);
|
|
|
|
|
if ($user->checkPassword($VARS['password'])) {
|
|
|
|
|
switch ($user->getStatus()->getString()) {
|
|
|
|
|
case "LOCKED_OR_DISABLED":
|
|
|
|
|
insertAuthLog(5, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
Log::insert(LogType::API_LOGIN_FAILED, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("account locked", false)]));
|
|
|
|
|
case "TERMINATED":
|
|
|
|
|
insertAuthLog(5, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
Log::insert(LogType::API_LOGIN_FAILED, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("account terminated", false)]));
|
|
|
|
|
case "CHANGE_PASSWORD":
|
|
|
|
|
insertAuthLog(5, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
Log::insert(LogType::API_LOGIN_FAILED, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("password expired", false)]));
|
|
|
|
|
case "NORMAL":
|
|
|
|
|
insertAuthLog(4, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
Log::insert(LogType::API_LOGIN_OK, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
exit(json_encode(["status" => "OK"]));
|
|
|
|
|
case "ALERT_ON_ACCESS":
|
|
|
|
|
sendLoginAlertEmail($VARS['username']);
|
|
|
|
|
insertAuthLog(4, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
$user->sendAlertEmail();
|
|
|
|
|
Log::insert(LogType::API_LOGIN_OK, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
exit(json_encode(["status" => "OK", "alert" => true]));
|
|
|
|
|
default:
|
|
|
|
|
insertAuthLog(5, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
Log::insert(LogType::API_LOGIN_FAILED, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("account state error", false)]));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
insertAuthLog(5, null, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
if (!is_empty($errmsg)) {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->build("ldap error", ['error' => $errmsg], false)]));
|
|
|
|
|
}
|
|
|
|
|
Log::insert(LogType::API_LOGIN_FAILED, null, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey());
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)]));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "ismanagerof":
|
|
|
|
|
if ($VARS['uid'] == "1") {
|
|
|
|
|
if ($database->has("accounts", ['uid' => $VARS['manager']])) {
|
|
|
|
|
if ($database->has("accounts", ['uid' => $VARS['employee']])) {
|
|
|
|
|
$managerid = $VARS['manager'];
|
|
|
|
|
$employeeid = $VARS['employee'];
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false), "user" => $VARS['employee']]));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false), "user" => $VARS['manager']]));
|
|
|
|
|
}
|
|
|
|
|
$manager = new User($VARS['manager']);
|
|
|
|
|
$employee = new User($VARS['employee']);
|
|
|
|
|
} else {
|
|
|
|
|
if (user_exists_local($VARS['manager'])) {
|
|
|
|
|
if (user_exists_local($VARS['employee'])) {
|
|
|
|
|
$managerid = $database->select('accounts', 'uid', ['username' => strtolower($VARS['manager'])]);
|
|
|
|
|
$employeeid = $database->select('accounts', 'uid', ['username' => strtolower($VARS['employee'])]);
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false), "user" => strtolower($VARS['employee'])]));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false), "user" => strtolower($VARS['manager'])]));
|
|
|
|
|
}
|
|
|
|
|
$manager = User::byUsername($VARS['manager']);
|
|
|
|
|
$employee = User::byUsername($VARS['employee']);
|
|
|
|
|
}
|
|
|
|
|
if (!$manager->exists()) {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false), "user" => $VARS['manager']]));
|
|
|
|
|
}
|
|
|
|
|
if ($database->has('managers', ['AND' => ['managerid' => $managerid, 'employeeid' => $employeeid]])) {
|
|
|
|
|
if (!$employee->exists()) {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false), "user" => $VARS['employee']]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($database->has('managers', ['AND' => ['managerid' => $manager->getUID(), 'employeeid' => $employee->getUID()]])) {
|
|
|
|
|
exit(json_encode(["status" => "OK", "managerof" => true]));
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "OK", "managerof" => false]));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "getmanaged":
|
|
|
|
|
if ($VARS['uid']) {
|
|
|
|
|
if ($database->has("accounts", ['uid' => $VARS['uid']])) {
|
|
|
|
|
$managerid = $VARS['uid'];
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)]));
|
|
|
|
|
}
|
|
|
|
|
} else if ($VARS['username']) {
|
|
|
|
|
if ($database->has("accounts", ['username' => strtolower($VARS['username'])])) {
|
|
|
|
|
$managerid = $database->select('accounts', 'uid', ['username' => strtolower($VARS['username'])]);
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)]));
|
|
|
|
|
}
|
|
|
|
|
if (!empty($VARS['uid'])) {
|
|
|
|
|
$manager = new User($VARS['uid']);
|
|
|
|
|
} else if (!empty($VARS['username'])) {
|
|
|
|
|
$manager = User::byUsername($VARS['username']);
|
|
|
|
|
} else {
|
|
|
|
|
http_response_code(400);
|
|
|
|
|
die("\"400 Bad Request\"");
|
|
|
|
|
}
|
|
|
|
|
if (!$manager->exists()) {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)]));
|
|
|
|
|
}
|
|
|
|
|
if ($VARS['get'] == "username") {
|
|
|
|
|
$managed = $database->select('managers', ['[>]accounts' => ['employeeid' => 'uid']], 'username', ['managerid' => $managerid]);
|
|
|
|
|
$managed = $database->select('managers', ['[>]accounts' => ['employeeid' => 'uid']], 'username', ['managerid' => $manager->getUID()]);
|
|
|
|
|
} else {
|
|
|
|
|
$managed = $database->select('managers', 'employeeid', ['managerid' => $managerid]);
|
|
|
|
|
$managed = $database->select('managers', 'employeeid', ['managerid' => $manager->getUID()]);
|
|
|
|
|
}
|
|
|
|
|
exit(json_encode(["status" => "OK", "employees" => $managed]));
|
|
|
|
|
break;
|
|
|
|
|
case "getmanagers":
|
|
|
|
|
if ($VARS['uid']) {
|
|
|
|
|
if ($database->has("accounts", ['uid' => $VARS['uid']])) {
|
|
|
|
|
$empid = $VARS['uid'];
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)]));
|
|
|
|
|
}
|
|
|
|
|
} else if ($VARS['username']) {
|
|
|
|
|
if ($database->has("accounts", ['username' => strtolower($VARS['username'])])) {
|
|
|
|
|
$empid = $database->select('accounts', 'uid', ['username' => strtolower($VARS['username'])]);
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)]));
|
|
|
|
|
}
|
|
|
|
|
if (!empty($VARS['uid'])) {
|
|
|
|
|
$emp = new User($VARS['uid']);
|
|
|
|
|
} else if (!empty($VARS['username'])) {
|
|
|
|
|
$emp = User::byUsername($VARS['username']);
|
|
|
|
|
} else {
|
|
|
|
|
http_response_code(400);
|
|
|
|
|
die("\"400 Bad Request\"");
|
|
|
|
|
}
|
|
|
|
|
$managers = $database->select('managers', 'managerid', ['employeeid' => $empid]);
|
|
|
|
|
if (!$emp->exists()) {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)]));
|
|
|
|
|
}
|
|
|
|
|
$managers = $database->select('managers', 'managerid', ['employeeid' => $emp->getUID()]);
|
|
|
|
|
exit(json_encode(["status" => "OK", "managers" => $managers]));
|
|
|
|
|
break;
|
|
|
|
|
case "usersearch":
|
|
|
|
@ -241,29 +213,23 @@ switch ($VARS['action']) {
|
|
|
|
|
exit(json_encode(["status" => "OK", "result" => $data]));
|
|
|
|
|
break;
|
|
|
|
|
case "permission":
|
|
|
|
|
if (is_empty($VARS['code'])) {
|
|
|
|
|
if (empty($VARS['code'])) {
|
|
|
|
|
http_response_code(400);
|
|
|
|
|
die("\"400 Bad Request\"");
|
|
|
|
|
}
|
|
|
|
|
$perm = $VARS['code'];
|
|
|
|
|
if ($VARS['uid']) {
|
|
|
|
|
if ($database->has("accounts", ['uid' => $VARS['uid']])) {
|
|
|
|
|
$user = $database->select('accounts', ['username'], ['uid' => $VARS['uid']])[0]['username'];
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)]));
|
|
|
|
|
}
|
|
|
|
|
} else if ($VARS['username']) {
|
|
|
|
|
if ($database->has("accounts", ['username' => strtolower($VARS['username'])])) {
|
|
|
|
|
$user = $VARS['username'];
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)]));
|
|
|
|
|
}
|
|
|
|
|
if (!empty($VARS['uid'])) {
|
|
|
|
|
$user = new User($VARS['uid']);
|
|
|
|
|
} else if (!empty($VARS['username'])) {
|
|
|
|
|
$user = User::byUsername($VARS['username']);
|
|
|
|
|
} else {
|
|
|
|
|
http_response_code(400);
|
|
|
|
|
die("\"400 Bad Request\"");
|
|
|
|
|
}
|
|
|
|
|
$hasperm = account_has_permission($user, $perm);
|
|
|
|
|
exit(json_encode(["status" => "OK", "has_permission" => $hasperm]));
|
|
|
|
|
if (!$user->exists()) {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)]));
|
|
|
|
|
}
|
|
|
|
|
exit(json_encode(["status" => "OK", "has_permission" => $user->hasPermission($perm)]));
|
|
|
|
|
break;
|
|
|
|
|
case "mobileenabled":
|
|
|
|
|
exit(json_encode(["status" => "OK", "mobile" => MOBILE_ENABLED]));
|
|
|
|
@ -277,7 +243,7 @@ switch ($VARS['action']) {
|
|
|
|
|
exit(json_encode(["status" => "OK", "valid" => $user_key_valid]));
|
|
|
|
|
case "alertemail":
|
|
|
|
|
engageRateLimit();
|
|
|
|
|
if (is_empty($VARS['username']) || !user_exists($VARS['username'])) {
|
|
|
|
|
if (is_empty($VARS['username']) || !User::byUsername($VARS['username'])->exists()) {
|
|
|
|
|
http_response_code(400);
|
|
|
|
|
die("\"400 Bad Request\"");
|
|
|
|
|
}
|
|
|
|
@ -285,7 +251,7 @@ switch ($VARS['action']) {
|
|
|
|
|
if (!is_empty($VARS['appname'])) {
|
|
|
|
|
$appname = $VARS['appname'];
|
|
|
|
|
}
|
|
|
|
|
$result = sendLoginAlertEmail($VARS['username'], $appname);
|
|
|
|
|
$result = User::byUsername($VARS['username'])->sendAlertEmail($appname);
|
|
|
|
|
if ($result === TRUE) {
|
|
|
|
|
exit(json_encode(["status" => "OK"]));
|
|
|
|
|
}
|
|
|
|
@ -371,22 +337,19 @@ switch ($VARS['action']) {
|
|
|
|
|
http_response_code(400);
|
|
|
|
|
die("\"400 Bad Request\"");
|
|
|
|
|
}
|
|
|
|
|
if (!is_empty($VARS['username'])) {
|
|
|
|
|
if (user_exists_local($VARS['username'])) {
|
|
|
|
|
$pin = $database->get("accounts", "pin", ["username" => strtolower($VARS['username'])]);
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)]));
|
|
|
|
|
}
|
|
|
|
|
} else if (!is_empty($VARS['uid'])) {
|
|
|
|
|
if ($database->has('accounts', ['uid' => $VARS['uid']])) {
|
|
|
|
|
$pin = $database->get("accounts", "pin", ["uid" => strtolower($VARS['uid'])]);
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)]));
|
|
|
|
|
}
|
|
|
|
|
if (!empty($VARS['username'])) {
|
|
|
|
|
$user = User::byUsername($VARS['username']);
|
|
|
|
|
} else if (!empty($VARS['uid'])) {
|
|
|
|
|
$user = new User($VARS['uid']);
|
|
|
|
|
} else {
|
|
|
|
|
http_response_code(400);
|
|
|
|
|
die("\"400 Bad Request\"");
|
|
|
|
|
}
|
|
|
|
|
if ($user->exists()) {
|
|
|
|
|
$pin = $database->get("accounts", "pin", ["uid" => $user->getUID()]);
|
|
|
|
|
} else {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)]));
|
|
|
|
|
}
|
|
|
|
|
if (is_null($pin) || $pin == "") {
|
|
|
|
|
exit(json_encode(["status" => "ERROR", "pinvalid" => false, "nopinset" => true]));
|
|
|
|
|
}
|
|
|
|
@ -395,8 +358,4 @@ switch ($VARS['action']) {
|
|
|
|
|
default:
|
|
|
|
|
http_response_code(404);
|
|
|
|
|
die(json_encode("404 Not Found: the requested action is not available."));
|
|
|
|
|
}
|
|
|
|
|
/* } catch (Exception $e) {
|
|
|
|
|
header("HTTP/1.1 500 Internal Server Error");
|
|
|
|
|
die("\"500 Internal Server Error\"");
|
|
|
|
|
} */
|
|
|
|
|
}
|