From 3763d0d48568cd5b619e332ff299221603d590b3 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Mon, 9 Jul 2018 23:16:43 -0600 Subject: [PATCH] Remove lang() and lang2() and rewrite references --- api.php | 64 ++++++++++++++++++++-------------------- apps/404_error.php | 4 +-- apps/change_password.php | 10 +++---- apps/change_pin.php | 10 +++---- apps/setup_2fa.php | 24 +++++++-------- apps/sync_mobile.php | 20 ++++++------- home.php | 14 ++++----- index.php | 38 ++++++++++++------------ lib/login.php | 4 +-- mobile/index.php | 12 ++++---- required.php | 40 ------------------------- 11 files changed, 100 insertions(+), 140 deletions(-) diff --git a/api.php b/api.php index 22ee00f..926443b 100644 --- a/api.php +++ b/api.php @@ -48,27 +48,27 @@ switch ($VARS['action']) { $errmsg = ""; if (authenticate_user($VARS['username'], $VARS['password'], $errmsg)) { insertAuthLog(12, null, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey()); - exit(json_encode(["status" => "OK", "msg" => lang("login successful", false)])); + 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" => lang2("ldap error", ['error' => $errmsg], false)])); + 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": - exit(json_encode(["status" => "ERROR", "msg" => lang("account locked", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("account locked", false)])); case "TERMINATED": - exit(json_encode(["status" => "ERROR", "msg" => lang("account terminated", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("account terminated", false)])); case "CHANGE_PASSWORD": - exit(json_encode(["status" => "ERROR", "msg" => lang("password expired", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("password expired", false)])); case "NORMAL": break; default: - exit(json_encode(["status" => "ERROR", "msg" => lang("account state error", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("account state error", false)])); } } - exit(json_encode(["status" => "ERROR", "msg" => lang("login incorrect", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)])); } break; case "userinfo": @@ -78,7 +78,7 @@ switch ($VARS['action']) { $data['pin'] = (is_null($data['pin']) || $data['pin'] == "" ? false : true); exit(json_encode(["status" => "OK", "data" => $data])); } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("login incorrect", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)])); } } else if (!is_empty($VARS['uid'])) { if ($database->has('accounts', ['uid' => $VARS['uid']])) { @@ -86,7 +86,7 @@ switch ($VARS['action']) { $data['pin'] = (is_null($data['pin']) || $data['pin'] == "" ? false : true); exit(json_encode(["status" => "OK", "data" => $data])); } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("login incorrect", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)])); } } else { http_response_code(400); @@ -119,7 +119,7 @@ switch ($VARS['action']) { exit(json_encode(["status" => "OK", "valid" => true])); } else { insertAuthLog(7, null, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey()); - exit(json_encode(["status" => "ERROR", "msg" => lang("2fa incorrect", false), "valid" => false])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("2fa incorrect", false), "valid" => false])); } break; case "acctstatus": @@ -133,13 +133,13 @@ switch ($VARS['action']) { switch (get_account_status($VARS['username'])) { case "LOCKED_OR_DISABLED": insertAuthLog(5, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey()); - exit(json_encode(["status" => "ERROR", "msg" => lang("account locked", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("account locked", false)])); case "TERMINATED": insertAuthLog(5, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey()); - exit(json_encode(["status" => "ERROR", "msg" => lang("account terminated", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("account terminated", false)])); case "CHANGE_PASSWORD": insertAuthLog(5, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey()); - exit(json_encode(["status" => "ERROR", "msg" => lang("password expired", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("password expired", false)])); case "NORMAL": insertAuthLog(4, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey()); exit(json_encode(["status" => "OK"])); @@ -149,14 +149,14 @@ switch ($VARS['action']) { exit(json_encode(["status" => "OK", "alert" => true])); default: insertAuthLog(5, $uid, "Username: " . strtolower($VARS['username']) . ", Key: " . getCensoredKey()); - exit(json_encode(["status" => "ERROR", "msg" => lang("account state error", false)])); + 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" => lang2("ldap error", ['error' => $errmsg], false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->build("ldap error", ['error' => $errmsg], false)])); } - exit(json_encode(["status" => "ERROR", "msg" => lang("login incorrect", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)])); } break; case "ismanagerof": @@ -166,10 +166,10 @@ switch ($VARS['action']) { $managerid = $VARS['manager']; $employeeid = $VARS['employee']; } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("user does not exist", false), "user" => $VARS['employee']])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false), "user" => $VARS['employee']])); } } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("user does not exist", false), "user" => $VARS['manager']])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false), "user" => $VARS['manager']])); } } else { if (user_exists_local($VARS['manager'])) { @@ -177,10 +177,10 @@ switch ($VARS['action']) { $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" => lang("user does not exist", false), "user" => strtolower($VARS['employee'])])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false), "user" => strtolower($VARS['employee'])])); } } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("user does not exist", false), "user" => strtolower($VARS['manager'])])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false), "user" => strtolower($VARS['manager'])])); } } if ($database->has('managers', ['AND' => ['managerid' => $managerid, 'employeeid' => $employeeid]])) { @@ -194,13 +194,13 @@ switch ($VARS['action']) { if ($database->has("accounts", ['uid' => $VARS['uid']])) { $managerid = $VARS['uid']; } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("user does not exist", false)])); + 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" => lang("user does not exist", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)])); } } else { http_response_code(400); @@ -218,13 +218,13 @@ switch ($VARS['action']) { if ($database->has("accounts", ['uid' => $VARS['uid']])) { $empid = $VARS['uid']; } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("user does not exist", false)])); + 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" => lang("user does not exist", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)])); } } else { http_response_code(400); @@ -250,13 +250,13 @@ switch ($VARS['action']) { if ($database->has("accounts", ['uid' => $VARS['uid']])) { $user = $database->select('accounts', ['username'], ['uid' => $VARS['uid']])[0]['username']; } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("user does not exist", false)])); + 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" => lang("user does not exist", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)])); } } else { http_response_code(400); @@ -296,7 +296,7 @@ switch ($VARS['action']) { $user = $database->get("onetimekeys", ["[>]accounts" => ["uid" => "uid"]], ["username", "realname", "accounts.uid"], ["key" => $VARS['code']]); exit(json_encode(["status" => "OK", "user" => $user])); } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("no such code or code expired", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("no such code or code expired", false)])); } case "listapps": $apps = EXTERNAL_APPS; @@ -312,7 +312,7 @@ switch ($VARS['action']) { if ($database->has("groups", ['groupid' => $VARS['gid']])) { $groupid = $VARS['gid']; } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("group does not exist", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("group does not exist", false)])); } } else { http_response_code(400); @@ -339,13 +339,13 @@ switch ($VARS['action']) { if ($database->has("accounts", ['uid' => $VARS['uid']])) { $empid = $VARS['uid']; } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("user does not exist", false)])); + 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" => lang("user does not exist", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("user does not exist", false)])); } } else { http_response_code(400); @@ -375,13 +375,13 @@ switch ($VARS['action']) { if (user_exists_local($VARS['username'])) { $pin = $database->get("accounts", "pin", ["username" => strtolower($VARS['username'])]); } else { - exit(json_encode(["status" => "ERROR", "msg" => lang("login incorrect", false)])); + 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" => lang("login incorrect", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)])); } } else { http_response_code(400); diff --git a/apps/404_error.php b/apps/404_error.php index 917054c..b78699b 100644 --- a/apps/404_error.php +++ b/apps/404_error.php @@ -6,8 +6,8 @@ dieifnotloggedin(); -$APPS["404_error"]["title"] = lang("404 error", false); +$APPS["404_error"]["title"] = $Strings->get("404 error", false); $APPS["404_error"]["icon"] = "times"; $APPS["404_error"]["type"] = "warning"; -$APPS["404_error"]["content"] = "

" . lang("page not found", false) . "

"; +$APPS["404_error"]["content"] = "

" . $Strings->get("page not found", false) . "

"; ?> \ No newline at end of file diff --git a/apps/change_password.php b/apps/change_password.php index f012820..44c4c1d 100644 --- a/apps/change_password.php +++ b/apps/change_password.php @@ -6,12 +6,12 @@ dieifnotloggedin(); -$oldpass = lang("current password", false); -$newpass = lang("new password", false); -$conpass = lang("confirm password", false); -$change = lang("change password", false); +$oldpass = $Strings->get("current password", false); +$newpass = $Strings->get("new password", false); +$conpass = $Strings->get("confirm password", false); +$change = $Strings->get("change password", false); -$APPS["change_password"]["title"] = lang("change password", false); +$APPS["change_password"]["title"] = $Strings->get("change password", false); $APPS["change_password"]["icon"] = "key"; $APPS["change_password"]["content"] = << diff --git a/apps/change_pin.php b/apps/change_pin.php index 0e0630c..d59c4d5 100644 --- a/apps/change_pin.php +++ b/apps/change_pin.php @@ -6,13 +6,13 @@ dieifnotloggedin(); -$newpin = lang("new pin", false); -$conpin = lang("confirm pin", false); -$change = lang("change pin", false); -$pinexp = lang("pin explanation", false); +$newpin = $Strings->get("new pin", false); +$conpin = $Strings->get("confirm pin", false); +$change = $Strings->get("change pin", false); +$pinexp = $Strings->get("pin explanation", false); -$APPS["change_pin"]["title"] = lang("change pin", false); +$APPS["change_pin"]["title"] = $Strings->get("change pin", false); $APPS["change_pin"]["icon"] = "th"; $APPS["change_pin"]["content"] = << $pinexp diff --git a/apps/setup_2fa.php b/apps/setup_2fa.php index 7b66329..5d840f6 100644 --- a/apps/setup_2fa.php +++ b/apps/setup_2fa.php @@ -13,12 +13,12 @@ use Endroid\QrCode\QrCode; // extra login utils require_once __DIR__ . "/../lib/login.php"; -$APPS["setup_2fa"]["title"] = lang("setup 2fa", false); +$APPS["setup_2fa"]["title"] = $Strings->get("setup 2fa", false); $APPS["setup_2fa"]["icon"] = "lock"; if (userHasTOTP($_SESSION['username'])) { - $APPS["setup_2fa"]["content"] = '
' . lang("2fa active", false) . '
' + $APPS["setup_2fa"]["content"] = '
' . $Strings->get("2fa active", false) . '
' . '' - . lang("remove 2fa", false) . ''; + . $Strings->get("remove 2fa", false) . ''; } else if ($_GET['2fa'] == "generate") { $codeuri = newTOTP($_SESSION['username']); $userdata = $database->select('accounts', ['email', 'authsecret', 'realname'], ['username' => $_SESSION['username']])[0]; @@ -32,12 +32,12 @@ if (userHasTOTP($_SESSION['username'])) { $totp = Factory::loadFromProvisioningUri($codeuri); $codesecret = $totp->getSecret(); $chunk_secret = trim(chunk_split($codesecret, 4, ' ')); - $lang_manualsetup = lang("manual setup", false); - $lang_secretkey = lang("secret key", false); - $lang_label = lang("label", false); - $lang_issuer = lang("issuer", false); - $lang_entercode = lang("enter otp code", false); - $APPS["setup_2fa"]["content"] = '
' . lang("scan 2fa qrcode", false) . '
' . <<get("manual setup", false); + $lang_secretkey = $Strings->get("secret key", false); + $lang_label = $Strings->get("label", false); + $lang_issuer = $Strings->get("issuer", false); + $lang_entercode = $Strings->get("enter otp code", false); + $APPS["setup_2fa"]["content"] = '
' . $Strings->get("scan 2fa qrcode", false) . '
' . << .margintop-15px { margin-top: 15px; @@ -57,7 +57,7 @@ if (userHasTOTP($_SESSION['username'])) { diff --git a/lib/login.php b/lib/login.php index b3660f6..fe2d05f 100644 --- a/lib/login.php +++ b/lib/login.php @@ -325,8 +325,8 @@ function sendLoginAlertEmail($username, $appname = SITE_TITLE) { $mail->setFrom(FROM_EMAIL, 'Account Alerts'); $mail->addAddress(ADMIN_EMAIL, "System Admin"); $mail->isHTML(false); - $mail->Subject = lang("admin alert email subject", false); - $mail->Body = lang2("admin alert email message", ["username" => $username, "datetime" => date("Y-m-d H:i:s"), "ipaddr" => getClientIP(), "appname" => $appname], false); + $mail->Subject = $Strings->get("admin alert email subject", false); + $mail->Body = $Strings->build("admin alert email message", ["username" => $username, "datetime" => date("Y-m-d H:i:s"), "ipaddr" => getClientIP(), "appname" => $appname], false); if (!$mail->send()) { return $mail->ErrorInfo; diff --git a/mobile/index.php b/mobile/index.php index 63616a9..e08ddca 100644 --- a/mobile/index.php +++ b/mobile/index.php @@ -21,7 +21,7 @@ if ($VARS['action'] == "ping") { } if (MOBILE_ENABLED !== TRUE) { - exit(json_encode(["status" => "ERROR", "msg" => lang("mobile login disabled", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("mobile login disabled", false)])); } // Make sure we have a username and access key @@ -60,7 +60,7 @@ switch ($VARS['action']) { engageRateLimit(); if (get_account_status($username) != "NORMAL") { insertAuthLog(20, null, "Username: " . $username . ", Key: " . $key); - exit(json_encode(["status" => "ERROR", "msg" => lang("login failed try on web", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login failed try on web", false)])); } if (authenticate_user($username, $VARS['password'], $autherror)) { $uid = $database->get("accounts", "uid", ["username" => $username]); @@ -72,14 +72,14 @@ switch ($VARS['action']) { exit(json_encode(["status" => "ERROR", "msg" => $autherror])); } else { insertAuthLog(20, null, "Username: " . $username . ", Key: " . $key); - exit(json_encode(["status" => "ERROR", "msg" => lang("login incorrect", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)])); } } case "user_info": engageRateLimit(); if (get_account_status($username) != "NORMAL") { insertAuthLog(20, null, "Username: " . $username . ", Key: " . $key); - exit(json_encode(["status" => "ERROR", "msg" => lang("login failed try on web", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login failed try on web", false)])); } if (authenticate_user($username, $VARS['password'], $autherror)) { $userinfo = $database->get("accounts", ["uid", "username", "realname", "email"], ["username" => $username]); @@ -91,7 +91,7 @@ switch ($VARS['action']) { exit(json_encode(["status" => "ERROR", "msg" => $autherror])); } else { insertAuthLog(20, null, "Username: " . $username . ", Key: " . $key); - exit(json_encode(["status" => "ERROR", "msg" => lang("login incorrect", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)])); } } case "start_session": @@ -107,7 +107,7 @@ switch ($VARS['action']) { } } insertAuthLog(20, null, "Username: " . $username . ", Key: " . $key); - exit(json_encode(["status" => "ERROR", "msg" => lang("login incorrect", false)])); + exit(json_encode(["status" => "ERROR", "msg" => $Strings->get("login incorrect", false)])); case "listapps": $apps = EXTERNAL_APPS; // Format paths as absolute URLs diff --git a/required.php b/required.php index e79d7c7..d4ec046 100644 --- a/required.php +++ b/required.php @@ -131,46 +131,6 @@ function is_empty($str) { return (is_null($str) || !isset($str) || $str == ''); } -/** - * I18N string getter. If the key doesn't exist, outputs the key itself. - * @param string $key I18N string key - * @param boolean $echo whether to echo the result or return it (default echo) - */ -function lang($key, $echo = true) { - global $Strings; - return $Strings->get($key, $echo); -} - -/** - * I18N string getter (with builder). If the key doesn't exist, outputs the key itself. - * @param string $key I18N string key - * @param array $replace key-value array of replacements. - * If the string value is "hello {abc}" and you give ["abc" => "123"], the - * result will be "hello 123". - * @param boolean $echo whether to echo the result or return it (default echo) - */ -function lang2($key, $replace, $echo = true) { - global $Strings; - return $Strings->build($key, $replace, $echo); -} - -/** - * Add strings to the i18n global array. - * @param array $strings ['key' => 'value'] - */ -function addLangStrings($strings) { - $GLOBALS['STRINGS'] = array_merge($GLOBALS['STRINGS'], $strings); -} - -/** - * Add strings to the i18n global array. Accepts an array of language code - * keys, with the values a key-value array of strings. - * @param array $strings ['en_us' => ['key' => 'value']] - */ -function addMultiLangStrings($strings) { - throw new Exception("Calling broken function addMultiLangStrings()"); -} - /** * Checks if an email address is valid. * @param string $email Email to check