Ejemplo n.º 1
0
 function init($args = false)
 {
     if (get_magic_quotes_gpc()) {
         $_POST = sxd_antimagic($_POST);
     }
     include 'cfg.php';
     $this->loadLang($CFG['lang']);
     if (!ini_get('safe_mode') && function_exists('set_time_limit') && strpos(ini_get('disable_functions'), 'set_time_limit') === false) {
         @set_time_limit($CFG['time_web']);
     } elseif (ini_get('max_execution_time') < $CFG['time_web']) {
         $CFG['time_web'] = ini_get('max_execution_time');
     }
     $this->CFG =& $CFG;
     $this->try = false;
     $this->virtualize = false;
     $this->cron_mode = false;
     // Проверяем авторизацию и делаем коннект к базе
     if (empty($this->CFG['my_user'])) {
         $this->CFG['my_host'] = 'localhost';
         $this->CFG['my_port'] = 3306;
         $this->CFG['my_user'] = '******';
         $this->CFG['my_pass'] = '';
         $this->CFG['my_comp'] = 0;
         $this->CFG['my_db'] = '';
     }
     if ($args) {
         // консольный режим
         foreach ($args as $key => $arg) {
             if (preg_match("/^-([hupoj])=(.*?)\$/", $arg, $m)) {
                 switch ($m[1]) {
                     case 'h':
                         $this->CFG['my_host'] = $m[2];
                         break;
                         // хост
                     // хост
                     case 'o':
                         $this->CFG['my_port'] = $m[2];
                         break;
                         // порт
                     // порт
                     case 'u':
                         $this->CFG['my_user'] = $m[2];
                         break;
                         // логин
                     // логин
                     case 'p':
                         $this->CFG['my_pass'] = $m[2];
                         break;
                         // пароль
                     // пароль
                     case 'j':
                         $this->CFG['sjob'] = $m[2];
                         break;
                         // job-файл
                 }
             }
         }
         set_time_limit($CFG['time_cron']);
         // Загружаем конфиг файл, если нужно
         $auth = $this->connect();
         if ($auth && !empty($this->CFG['sjob'])) {
             $this->ajax($this->loadJob($this->CFG['sjob']));
             echo file_get_contents($this->JOB['file_log']);
             if (file_exists($this->JOB['file_log'])) {
                 unlink($this->JOB['file_log']);
             }
             if (file_exists($this->JOB['file_rtl'])) {
                 unlink($this->JOB['file_rtl']);
             }
         } else {
             echo 'Auth error';
         }
         exit;
     } elseif (!empty($this->CFG['auth'])) {
         // Авторизация
         $auth = false;
         $sfile = 'ses.php';
         if (!empty($_COOKIE['sxd']) && preg_match('/^[\\da-f]{32}$/', $_COOKIE['sxd'])) {
             include $sfile;
             if (isset($SES[$_COOKIE['sxd']])) {
                 $auth = true;
                 $this->CFG = $SES[$_COOKIE['sxd']]['cfg'];
                 $this->SES =& $SES;
                 $this->loadLang($this->CFG['lang']);
             }
         }
         if (!$auth) {
             $user = !empty($_POST['user']) ? $_POST['user'] : '';
             $pass = !empty($_POST['pass']) ? $_POST['pass'] : '';
             $host = !empty($_POST['host']) ? $_POST['host'] : 'localhost';
             $port = !empty($_POST['port']) && is_numeric($_POST['port']) ? $_POST['port'] : 3306;
             $temp = preg_split('/\\s+/', $this->CFG['auth']);
             if (!empty($_REQUEST['lang']) && preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $_REQUEST['lang'])) {
                 $this->loadLang($_REQUEST['lang']);
             }
             foreach ($temp as $a) {
                 switch ($a) {
                     case 'cfg':
                         if (empty($user)) {
                             continue;
                         }
                         $auth = !empty($CFG['user']) && isset($CFG['pass']) && $CFG['user'] == $user && $CFG['pass'] == $pass;
                         break;
                     case 'mysql':
                         if (empty($user)) {
                             continue;
                         }
                         $auth = $this->connect($host, $port, $user, $pass);
                         break;
                     default:
                         $file = 'auth_' . $a . '.php';
                         if (!file_exists($file)) {
                             continue;
                         }
                         include $file;
                 }
                 if ($auth) {
                     break;
                 }
             }
             if ($auth) {
                 $key = md5(rand(1, 100000) . $user . microtime());
                 $CFG['lang'] = $this->LNG['name'];
                 $_COOKIE['sxd'] = $key;
                 $this->saveCFG();
                 setcookie('sxd', $key, !empty($_POST['save']) ? time() + 31536000 : 0);
                 header("Location: ./");
                 exit;
             }
             foreach (array('user', 'pass', 'host', 'port') as $key) {
                 $_POST[$key] = !empty($_POST[$key]) ? htmlspecialchars($_POST[$key], ENT_NOQUOTES) : '';
             }
             $_POST['save'] = !empty($_POST['save']) ? ' CHECKED' : '';
         }
         if (!$auth) {
             if (!empty($_POST['ajax'])) {
                 echo "sxd.hideLoading();alert('Session not found');";
                 exit;
             }
             $this->lng_list = '<option value="auto">- auto -</opinion>';
             if (!isset($this->langs)) {
                 include 'lang/list.php';
                 $this->langs =& $langs;
             }
             foreach ($this->langs as $k => $v) {
                 $this->lng_list .= "<option value=\"{$k}\"" . ($k == (!empty($_REQUEST['lang']) ? $this->LNG['name'] : $this->CFG['lang']) ? ' SELECTED' : '') . ">{$v}</opinion>";
             }
             echo sxd_tpl_auth();
             exit;
         }
     }
     /*if(!empty($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] == 'exit') {
     			setcookie('sxd', '', 0);
     			header("Location: {$this->CFG['exitURL']}");
     			exit;
     		}*/
     if (empty($_POST['ajax']['act']) || $_POST['ajax']['act'] != 'save_connect') {
         $this->connect();
     }
     if (isset($_POST['ajax'])) {
         $this->ajax($_POST['ajax']);
     } else {
         $this->main();
     }
 }
Ejemplo n.º 2
0
 function init($args = false)
 {
     if (get_magic_quotes_gpc()) {
         $_POST = sxd_antimagic($_POST);
     }
     include "cfg.php";
     $this->loadLang($CFG["lang"]);
     if (!ini_get("safe_mode") && function_exists("set_time_limit") && strpos(ini_get("disable_functions"), "set_time_limit") === false) {
         @set_time_limit($CFG["time_web"]);
     } elseif (ini_get("max_execution_time") < $CFG["time_web"]) {
         $CFG["time_web"] = ini_get("max_execution_time");
     }
     $this->CFG =& $CFG;
     $this->try = false;
     $this->virtualize = false;
     $this->cron_mode = false;
     if (empty($this->CFG["my_user"])) {
         $this->CFG["my_host"] = "localhost";
         $this->CFG["my_port"] = 3306;
         $this->CFG["my_user"] = "******";
         $this->CFG["my_pass"] = "";
         $this->CFG["my_comp"] = 0;
         $this->CFG["my_db"] = "";
     }
     if ($args) {
         foreach ($args as $key => $arg) {
             if (preg_match("/^-([hupoj])=(.*?)\$/", $arg, $m)) {
                 switch ($m[1]) {
                     case "h":
                         $this->CFG["my_host"] = $m[2];
                         break;
                     case "o":
                         $this->CFG["my_port"] = $m[2];
                         break;
                     case "u":
                         $this->CFG["my_user"] = $m[2];
                         break;
                     case "p":
                         $this->CFG["my_pass"] = $m[2];
                         break;
                     case "j":
                         $this->CFG["sjob"] = $m[2];
                         break;
                 }
             }
         }
         $this->cron_mode = true;
         set_time_limit($CFG["time_cron"]);
         $auth = $this->connect();
         if ($auth && !empty($this->CFG["sjob"])) {
             $this->ajax($this->loadJob($this->CFG["sjob"]));
             echo file_get_contents($this->JOB["file_log"]);
             if (file_exists($this->JOB["file_log"])) {
                 unlink($this->JOB["file_log"]);
             }
             if (file_exists($this->JOB["file_rtl"])) {
                 unlink($this->JOB["file_rtl"]);
             }
         } else {
             echo "Auth error";
         }
         exit;
     } elseif (!empty($this->CFG["auth"])) {
         $auth = false;
         $sfile = "ses.php";
         if (!empty($_COOKIE["sxd"]) && preg_match("/^[\\da-f]{32}\$/", $_COOKIE["sxd"])) {
             include $sfile;
             if (isset($SES[$_COOKIE["sxd"]])) {
                 $auth = true;
                 $this->CFG = $SES[$_COOKIE["sxd"]]["cfg"];
                 $this->SES =& $SES;
                 $this->loadLang($this->CFG["lang"]);
             }
         }
         if (!$auth) {
             $user = !empty($_POST["user"]) ? $_POST["user"] : "";
             $pass = !empty($_POST["pass"]) ? $_POST["pass"] : "";
             $host = !empty($_POST["host"]) ? $_POST["host"] : (!empty($this->CFG["my_host"]) ? $this->CFG["my_host"] : "localhost");
             $port = !empty($_POST["port"]) && is_numeric($_POST["port"]) ? $_POST["port"] : 3306;
             $temp = preg_split("/\\s+/", $this->CFG["auth"]);
             if (!empty($_REQUEST["lang"]) && preg_match("/^[a-z]{2}(-[a-z]{2})?\$/", $_REQUEST["lang"])) {
                 $this->loadLang($_REQUEST["lang"]);
             }
             foreach ($temp as $a) {
                 switch ($a) {
                     case "cfg":
                         if (empty($user)) {
                             continue;
                         }
                         $auth = !empty($CFG["user"]) && isset($CFG["pass"]) && $CFG["user"] == $user && $CFG["pass"] == $pass;
                         break;
                     case "mysql":
                         if (empty($user)) {
                             continue;
                         }
                         if ($host != "localhost" && !empty($this->CFG["my_host"]) && $this->CFG["my_host"] != $host) {
                             continue;
                         }
                         $auth = $this->connect($host, $port, $user, $pass);
                         break;
                     default:
                         $file = "auth_" . $a . ".php";
                         if (!file_exists($file)) {
                             continue;
                         }
                         include $file;
                 }
                 if ($auth) {
                     break;
                 }
             }
             if ($auth) {
                 $key = md5(rand(1, 100000) . $user . microtime());
                 $CFG["lang"] = $this->LNG["name"];
                 $_COOKIE["sxd"] = $key;
                 $this->saveCFG();
                 if (V_PHP > 50200) {
                     setcookie("sxd", $key, !empty($_POST["save"]) ? time() + 31536000 : 0, "", "", false, true);
                 } else {
                     setcookie("sxd", $key, !empty($_POST["save"]) ? time() + 31536000 : 0, "", "", false);
                 }
                 header("Location: {$this->url}");
                 exit;
             }
             foreach (array("user", "pass", "host", "port") as $key) {
                 $_POST[$key] = !empty($_POST[$key]) ? htmlspecialchars($_POST[$key], ENT_NOQUOTES) : "";
             }
             $_POST["save"] = !empty($_POST["save"]) ? " CHECKED" : "";
         }
         if (!$auth) {
             if (!empty($_POST["ajax"])) {
                 echo "sxd.hideLoading();alert('Session not found');";
                 exit;
             }
             $this->lng_list = "<option value=\"auto\">- auto -</opinion>";
             if (!isset($this->langs)) {
                 include "lang/list.php";
                 $this->langs =& $langs;
             }
             foreach ($this->langs as $k => $v) {
                 $this->lng_list .= "<option value=\"{$k}\"" . ($k == (!empty($_REQUEST["lang"]) ? $this->LNG["name"] : $this->CFG["lang"]) ? " SELECTED" : "") . ">{$v}</opinion>";
             }
             include "tmpl.php";
             echo sxd_tpl_auth();
             exit;
         }
     }
     if (empty($_POST["ajax"]["act"]) || $_POST["ajax"]["act"] != "save_connect") {
         $this->connect();
     }
     if (isset($_POST["ajax"])) {
         $this->ajax($_POST["ajax"]);
     } else {
         $this->main();
     }
     exit;
 }