|
@@ -12,5 +12,149 @@
|
|
|
|
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
|
|
|
|
|
|
|
|
|
|
+// Returns true if both strings are the same. Performs a case-insensitive comparison unless third parameter is true.
|
|
|
|
|
+function ARE_STRINGS_EQUAL($str1, $str2, $case_sensitive = false){
|
|
|
|
|
+
|
|
|
|
|
+ switch($case_sensitive){
|
|
|
|
|
+ case true:
|
|
|
|
|
+ if (strcmp($str1, $str2) == 0){
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ if (strcasecmp($str1, $str2) == 0){
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function GET_JSON_DATA_FROM_FILE($full_path_to_file){
|
|
|
|
|
+
|
|
|
|
|
+ $filename = $full_path_to_file;
|
|
|
|
|
+ $fp = fopen($filename, 'r');
|
|
|
|
|
+ $data = fread($fp, filesize($filename));
|
|
|
|
|
+ fclose($fp);
|
|
|
|
|
+
|
|
|
|
|
+ $r = json_decode($data, true);
|
|
|
|
|
+ return $r;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// Returns the language-specific string with the specified key.
|
|
|
|
|
+function GET_LANG_STR($str){
|
|
|
|
|
+
|
|
|
|
|
+ $lang = "en";
|
|
|
|
|
+ $filename = "lang_strings.json";
|
|
|
|
|
+ $not_found = strtoupper($str);
|
|
|
|
|
+
|
|
|
|
|
+ if (!isset($filename)){
|
|
|
|
|
+ return $not_found;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $contents = file_get_contents($filename);
|
|
|
|
|
+ $json = json_decode($contents, true);
|
|
|
|
|
+
|
|
|
|
|
+ if ($json == null){
|
|
|
|
|
+ return $not_found;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (array_key_exists($lang, $json)){
|
|
|
|
|
+ if (array_key_exists($str, $json[$lang])){
|
|
|
|
|
+ return $json[$lang][$str];
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ return $not_found;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ return $not_found;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// Die with error string.
|
|
|
|
|
+function DIE_ERR($str){
|
|
|
|
|
+
|
|
|
|
|
+ if (!DETAILED_ERRORS){
|
|
|
|
|
+ $str = substr($str, 0, -2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (ENCLOSE_ERRORS_WITH_PRE_TAG){
|
|
|
|
|
+ die("<pre>" . GET_LANG_STR($str) . "</pre>");
|
|
|
|
|
+ }else{
|
|
|
|
|
+ die(GET_LANG_STR($str));
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+function CHECK_USER(&$err){
|
|
|
|
|
+
|
|
|
|
|
+ // Is a valid user provided?
|
|
|
|
|
+ if (isset($_REQUEST['u']) && !empty($_REQUEST['u'])){
|
|
|
|
|
+
|
|
|
|
|
+ // Is a valid API key provided?
|
|
|
|
|
+ if (isset($_REQUEST['k']) && !empty($_REQUEST['k'])){
|
|
|
|
|
+
|
|
|
|
|
+ // Save request username and API key.
|
|
|
|
|
+ $r_user = $_REQUEST['u'];
|
|
|
|
|
+ $r_key = $_REQUEST['k'];
|
|
|
|
|
+
|
|
|
|
|
+ // Fetch user database and check the username and API key combination.
|
|
|
|
|
+ $users = GET_JSON_DATA_FROM_FILE(USERS_JSON);
|
|
|
|
|
+
|
|
|
|
|
+ // Does user exist?
|
|
|
|
|
+ if (isset($users[$r_user])){
|
|
|
|
|
+
|
|
|
|
|
+ // Is user access enabled?
|
|
|
|
|
+ if (isset($users[$r_user]['enabled'])){
|
|
|
|
|
+
|
|
|
|
|
+ if ($users[$r_user]['enabled']){
|
|
|
|
|
+
|
|
|
|
|
+ if (ARE_STRINGS_EQUAL($r_key, $users[$r_user]['api_key'], FORCE_CASE_SENSITIVE_API_KEYS)){
|
|
|
|
|
+ // ALL USER CHECKS PASS.
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ $err = "error_403_4";
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ $err = "error_403_3";
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ $err = "error_403_2";
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ $err = "error_403_1";
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else{
|
|
|
|
|
+
|
|
|
|
|
+ $err = "error_401_2";
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ else{
|
|
|
|
|
+
|
|
|
|
|
+ $err = "error_401_1";
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|