diff --git a/cache/.empty b/cache/.empty new file mode 100644 index 00000000..e69de29b diff --git a/php/Parser.php b/php/Parser.php new file mode 100644 index 00000000..d316cb74 --- /dev/null +++ b/php/Parser.php @@ -0,0 +1,309 @@ + [ + '({loop.*?})', + '/{loop="(?\${0,1}[^"]*)"(?: as (?\$.*?)(?: => (?\$.*?)){0,1}){0,1}}/' + ], + 'loop_close' => ['({\/loop})', '/{\/loop}/'], + 'loop_break' => ['({break})', '/{break}/'], + 'loop_continue' => ['({continue})', '/{continue}/'], + 'if' => ['({if.*?})', '/{if="([^"]*)"}/'], + 'elseif' => ['({elseif.*?})', '/{elseif="([^"]*)"}/'], + 'else' => ['({else})', '/{else}/'], + 'if_close' => ['({\/if})', '/{\/if}/'], + 'autoescape' => ['({autoescape.*?})', '/{autoescape="([^"]*)"}/'], + 'autoescape_close' => ['({\/autoescape})', '/{\/autoescape}/'], + 'noparse' => ['({noparse})', '/{noparse}/'], + 'noparse_close' => ['({\/noparse})', '/{\/noparse}/'], + 'ignore' => ['({ignore}|{\*)', '/{ignore}|{\*/'], + 'ignore_close' => ['({\/ignore}|\*})', '/{\/ignore}|\*}/'], + 'include' => ['({include.*?})', '/{include="([^"]*)"}/'], + 'function' =>[ + '({function.*?})', + '/{function="([a-zA-Z_][a-zA-Z_0-9\:]*)(\(.*\)){0,1}"}/' + ], + 'ternary' => ['({.[^{?}]*?\?.*?\:.*?})', '/{(.[^{?}]*?)\?(.*?)\:(.*?)}/'], + 'variable' => ['({\$.*?})', '/{(\$.*?)}/'], + 'constant' => ['({#.*?})', '/{#(.*?)#{0,1}}/'], + 'translate' => ['({translate})', '/{translate::(.*)}/'] + ); + + function __construct($config) + { + $this->config = $config; + } + + /** + * Compile the file and save it in the cache + * @param string $filePath: full path to the template to be compiled + */ + public function compileFile($filePath) + { + // read the template + $code = file_get_contents($filePath); + + // xml substitution + $code = preg_replace("/<\?xml(.*?)\?>/s", /*'; ?>"; + }, $code); + + // set tags + $tagSplit = []; + $tagMatch = []; + + foreach ($this->tags as $tag => $tagArray) { + $tagSplit[] = $tagArray[0]; + $tagMatch[$tag] = $tagArray[1]; + } + + //Remove comments + if ($this->config['remove_comments']) { + $code = preg_replace('//Uis', '', $code); + } + + //split the code with the tags regexp + $codeSplit = preg_split("/" . implode("|", $tagSplit) . "/", $code, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + if ($codeSplit == false){ + // no parsing required + return $code; + } + + unset($code); // we don't need it any longer + + //variables initialization + $parsedCode = ''; + $commentIsOpen = $ignoreIsOpen = false; + $auto_escape_global = $this->config['auto_escape']; + $openIf = 0; + + //read all parsed code + foreach ($codeSplit as $html) { + + switch(true){ + //close ignore tag + case (!$commentIsOpen && preg_match($tagMatch['ignore_close'], $html)): + $ignoreIsOpen = false; + break; + //code between tag ignore id deleted + case ($ignoreIsOpen): + break; + //close no parse tag + case (preg_match($tagMatch['noparse_close'], $html)): + $commentIsOpen = false; + break; + //code between tag noparse is not compiled + case ($commentIsOpen): + $parsedCode .= $html; + break; + //ignore + case (preg_match($tagMatch['ignore'], $html)): + $ignoreIsOpen = true; + break; + //noparse + case (preg_match($tagMatch['noparse'], $html)): + $commentIsOpen = true; + break; + //include tag + case (preg_match($tagMatch['include'], $html, $matches)): + + // reduce the path + $matches[1] = preg_replace(array("#(://(*SKIP)(*FAIL))|(/{2,})#", "#(/\./+)#", "#\\\#"), array("/", "/","\\\\\\"), $matches[1]); + while(preg_match('#\w+\.\./#', $matches[1])) { + $matches[1] = preg_replace('#\w+/\.\./#', '', $matches[1]); + } + // parse + $includeTemplate = $this->varReplace($matches[1]); + + //dynamic include + if ((strpos($matches[1], '$') !== false)) { + $parsedCode .= 'checkTemplate(' . $includeTemplate . ');?>'; + } else { + $parsedCode .= 'checkTemplate("' . $includeTemplate . '");?>'; + } + break; + //loop + case(preg_match($tagMatch['loop'], $html, $matches)): + + //replace the variable in the loop + $var = $this->varReplace($matches['variable'], false); + + $this->loopLevel++; // increase the loop counter + + if (preg_match('#\(#', $var)) { + $newvar = "\$newvar{$this->loopLevel}"; + $assignNewVar = "$newvar=$var;"; + } else { + $newvar = $var; + $assignNewVar = NULL; + } + + //loop variables + $counter = "\$counter{$this->loopLevel}"; // count iteration + + if (isset($matches['key']) && isset($matches['value'])) { + $key = $matches['key']; + $value = $matches['value']; + } elseif (isset($matches['key'])) { + $key = "\$key{$this->loopLevel}"; + $value = $matches['key']; + } else { + $key = "\$key{$this->loopLevel}"; + $value = "\$value{$this->loopLevel}"; + } + + //loop code + $parsedCode .= " $value ){ $counter++; ?>"; + break; + //close loop tag + case (preg_match($tagMatch['loop_close'], $html)): + $counter = "\$counter{$this->loopLevel}"; //iterator + $this->loopLevel--; //decrease the loop counter + $parsedCode .= ""; //close loop code + break; + //break loop tag + case (preg_match($tagMatch['loop_break'], $html)): + $parsedCode .= ""; //close loop code + break; + //continue loop tag + case (preg_match($tagMatch['loop_continue'], $html)): + $parsedCode .= ""; //close loop code + break; + //if + case (preg_match($tagMatch['if'], $html, $matches)): + $openIf++; //increase open if counter (for intendation) + //variable substitution into condition (no delimiter into the condition) + $parsedCondition = $this->varReplace($matches[1], false); + $parsedCode .= ""; //if code + break; + //elseif + case (preg_match($tagMatch['elseif'], $html, $matches)): + //variable substitution into condition (no delimiter into the condition) + $parsedCondition = $this->varReplace($matches[1], false); + $parsedCode .= ""; + break; + //else + case (preg_match($tagMatch['else'], $html)): + $parsedCode .= ''; //else code + break; + //close if tag + case (preg_match($tagMatch['if_close'], $html)): + $openIf--; //decrease if counter + $parsedCode .= ''; // close if code + break; + //variables + case (preg_match($tagMatch['variable'], $html, $matches)): + //variables substitution (es. {$title}) + $parsedCode .= "varReplace($matches[1], true, true) . "; ?>"; + break; + // autoescape off + case (preg_match($tagMatch['autoescape'], $html, $matches)): + $this->config['auto_escape'] = (in_array($matches[1], ['off','false'])) ? false : true; + break; + // autoescape on + case (preg_match($tagMatch['autoescape_close'], $html, $matches)): + $this->config['auto_escape'] = $auto_escape_global; + break; + // function + case (preg_match($tagMatch['function'], $html, $matches)): + $parsedCode .= "varReplace($matches[2], false) : "()")."; ?>"; + break; + //ternary + case (preg_match($tagMatch['ternary'], $html, $matches)): + $parsedCode .= 'varReplace($matches[1]) . '?' . $this->varReplace($matches[2]) . ':' . $this->varReplace($matches[3]) . '); ?>'; + break; + //constants + case (preg_match($tagMatch['constant'], $html, $matches)): + $parsedCode .= "modifierReplace($matches[1]) . "; ?>"; + break; + case (preg_match($tagMatch['translate'], $html, $matches)): + while (preg_match($tagMatch['translate'], $html, $matches)) { + $html = preg_replace($tagMatch['translate'], '', $html, 1); + } + $parsedCode .= $html; + break; + default: + $parsedCode .= $html; + } + + } + + if ($openIf > 0) { + throw new Exception("Error! You need to close an {if} tag in ".$filePath." template"); + } + + if ($this->loopLevel > 0) { + throw new Exception("Error! You need to close the {loop} tag in ".$filePath." template"); + } + + return "" . $parsedCode; + } + + protected function varReplace($html, $escape = true, $echo = false) + { + // change variable name if loop level + $html = preg_replace(['/(\$key)\b/', '/(\$value)\b/', '/(\$counter)\b/'], ['${1}' . $this->loopLevel, '${1}' . $this->loopLevel, '${1}' . $this->loopLevel], $html); + + // if it is a variable + if (preg_match_all('/(\$[a-z_A-Z][^\s]*)/', $html, $matches)) { + // substitute . and [] with [" "] + for ($i = 0; $i < count($matches[1]); $i++) { + + $rep = preg_replace('/\[(\${0,1}[a-zA-Z_0-9]*)\]/', '["$1"]', $matches[1][$i]); + $rep = preg_replace('/\.(\${0,1}[a-zA-Z_0-9]*(?![a-zA-Z_0-9]*(\'|\")))/', '["$1"]', $rep); + $html = str_replace($matches[0][$i], $rep, $html); + } + + // update modifier + $html = $this->modifierReplace($html); + + // if does not initialize a value, e.g. {$a = 1} + if (!preg_match('/\$.*=.*/', $html)) { + + // escape character + ($this->config['auto_escape'] && $escape) AND $html = "htmlspecialchars($html, ENT_COMPAT, '" . $this->config['charset'] . "', FALSE)"; + ($echo) AND $html = "echo ".$html; + } + } + + return $html; + } + + protected function modifierReplace($html) + { + while (strpos($html,'|') !== false && substr($html, strpos($html,'|')+1,1) != "|") { + + preg_match('/([\$a-z_A-Z0-9\(\),\[\]"->]+)\|([\$a-z_A-Z0-9\(\):,\[\]"->]+)/i', $html, $result); + + $str = explode(":", $result[2]); + $function = $str[0]; + if (count($str) == 2){ + $params = ",".$str[1]; + } else { + $params = ""; + } + + $html = str_replace($result[0], $function . "(" . $result[1] . "$params)", $html); + } + + return $html; + } + +} + +?> \ No newline at end of file diff --git a/php/Tpl.php b/php/Tpl.php new file mode 100644 index 00000000..c84b7833 --- /dev/null +++ b/php/Tpl.php @@ -0,0 +1,131 @@ + 'UTF-8', + 'tpl_dir' => '../templates/', + 'cache_dir' => '../cache/', + 'lang_dir' => '../public/lang/', + 'auto_escape' => true, + 'remove_comments' => false, + 'production_ready' => false + ]; + + public function configure($my_conf) + { + (!is_array($my_conf)) AND die("Invalid config"); + + foreach ($my_conf as $my=>$val){ + if (isset($this->config[$my])){ + $this->config[$my] = $val; + } + } + } + + function __construct($use_locale = true) + { + if ($use_locale){ + + (isset($_COOKIE['lang'])) AND $this->language = $_COOKIE['lang']; + (!array_key_exists($this->language, Config::$languages)) AND $this->language = 'en'; + include($this->config['lang_dir'].$this->language.'.php'); + $this->translate_arr = $lang; + + $this->assign("translate", function($word){ return $this->translate($word); }); + } + } + + public function get_lang() + { + return $this->language; + } + + public function translate($phrase) + { + return (isset($this->translate_arr[$phrase])) ? $this->translate_arr[$phrase] : $phrase; + } + + /** + * Draw the template + * + * @param string $filePath: name of the template file + * @param bool $returnString: if the method should return a string or echo the output + * + * @return void, string: depending of the $returnString + */ + public function draw($filePath, $returnString = FALSE) + { + extract($this->vars); + ob_start(); + + $fileName = basename($filePath); + $filePathCached = $this->config['cache_dir'] . $fileName . ".stpl.php"; + + if (!$this->config['production_ready']){ # in case all is already cached + // set paths + $filePath = $this->config['tpl_dir'] . $fileName . '.html'; + // The results of this function are cached + $fileTime = (int)@filemtime($filePath); + $fileTimeCached = (int)@filemtime($filePathCached); + + // Check if template exists (although there are other reasons for this to be false) + if ($fileTime == 0) { + die('Template ' . $fileName . ' not found!'); + } + + // Compile the template if the original has been updated + if ($fileTimeCached == 0 || $fileTimeCached < $fileTime) { + require_once("parser.php"); + $html = (new Parser($this->config))->compileFile($filePath); + $html = str_replace("?>\n", "?>\n\n", $html); + $ok = file_put_contents($filePathCached, $html); + if ($ok === false) { + die("Cache is not writable"); + } + } + } + + require $filePathCached; + $output = ob_get_clean(); + + if ($returnString){ + return $output; + } else { + echo $output; + } + } + + public function assign($variable, $value = Null) + { + if (is_array($variable)){ + $this->vars = $variable + $this->vars; + } else { + $this->vars[$variable] = $value; + } + } + + public function assign_my_defines() + { + $defines = get_defined_constants(true); + if (isset($defines['user'])){ + foreach($defines['user'] as $variable => $value){ + $this->vars[$variable] = $value; + } + } + } + +} + +?> \ No newline at end of file diff --git a/php/clonos.php b/php/clonos.php index 1c2f28c3..47d90713 100644 --- a/php/clonos.php +++ b/php/clonos.php @@ -2,7 +2,7 @@ require_once("cbsd.php"); require_once('config.php'); -require_once('locale.php'); +require_once('localization.php'); require_once('db.php'); require_once('forms.php'); require_once('utils.php'); @@ -12,7 +12,6 @@ class ClonOS { public $workdir=''; public $environment=''; public $realpath=''; - public $realpath_php=''; public $realpath_public=''; public $realpath_page=''; public $uri_chunks=array(); @@ -56,77 +55,70 @@ class ClonOS { private $_db_jails=null; */ - function __construct($_real_path,$uri_chunks = null){ # /usr/home/web/cp/clonos + function __construct($uri_chunks = null){ - $this->_post=($_SERVER['REQUEST_METHOD']=='POST'); - $this->_vars=$_POST; + $this->_post = ($_SERVER['REQUEST_METHOD']=='POST'); + $this->_vars = $_POST; - $this->workdir=getenv('WORKDIR'); # // /usr/jails - $this->environment=getenv('APPLICATION_ENV'); - $this->realpath=$_real_path.'/'; # /usr/home/web/cp/clonos/ - $this->realpath_php=$_real_path.'/php/'; # /usr/home/web/cp/clonos/php/ - $this->realpath_public=$_real_path.'/public/'; # /usr/home/web/cp/clonos/public/ - $this->media_import=$_real_path.'/media_import/'; + $this->workdir = getenv('WORKDIR'); # // /usr/jails + $this->environment = getenv('APPLICATION_ENV'); + $this->realpath = '../'; # /usr/local/www/clonos/ + $this->realpath_public = '../public/'; # /usr/local/www/clonos/public/ + $this->media_import = '../media_import/'; - if($this->environment=='development'){ - $sentry_file=$this->realpath_php.'sentry.php'; + if($this->environment == 'development'){ + $sentry_file = '../php/sentry.php'; if(file_exists($sentry_file)) include($sentry_file); } if(isset($_SERVER['SERVER_NAME']) && !empty(trim($_SERVER['SERVER_NAME']))){ - $this->server_name=$_SERVER['SERVER_NAME']; + $this->server_name = $_SERVER['SERVER_NAME']; } else { - $this->server_name=$_SERVER['SERVER_ADDR']; + $this->server_name = $_SERVER['SERVER_ADDR']; } if (is_null($uri_chunks)) { # TODO Do we need this ? - $this->uri_chunks=Utils::gen_uri_chunks($uri); + $this->uri_chunks = Utils::gen_uri_chunks(trim($_SERVER['REQUEST_URI'],'/')); } else { - $this->uri_chunks=$uri_chunks; + $this->uri_chunks = $uri_chunks; } - $this->config=new Config(); - - $this->_locale = new Locale($this->realpath_public); - - $this->_client_ip=$_SERVER['REMOTE_ADDR']; + $this->config = new Config(); + $this->_locale = new Localization($this->realpath_public); + $this->_client_ip = $_SERVER['REMOTE_ADDR']; if(isset($this->_vars['path'])){ //$this->realpath_page=$this->realpath_public.'pages/'.trim($this->_vars['path'],'/').'/'; - $this->realpath_page=$this->realpath_public.'pages/'.$this->uri_chunks[0].'/'; - $this->json_name=$this->realpath_page.'a.json.php'; + $this->realpath_page = $this->realpath_public.'pages/'.$this->uri_chunks[0].'/'; + $this->json_name = $this->realpath_page.'a.json.php'; //echo $this->realpath_page; }else if($_SERVER['REQUEST_URI']){ //$this->realpath_page=$this->realpath_public.'pages/'.trim($_SERVER['REQUEST_URI'],'/').'/'; if(isset($this->uri_chunks[0])){ - $this->realpath_page=$this->realpath_public.'pages/'.$this->uri_chunks[0].'/'; + $this->realpath_page = $this->realpath_public.'pages/'.$this->uri_chunks[0].'/'; } } - if(isset($this->_vars['hash'])) $this->url_hash=preg_replace('/^#/','',$this->_vars['hash']); - -// $this->json_name=$this->realpath_php.'pages' -// $clonos->json_name=$file_path.'a.json.php'; - - if(isset($this->_vars['mode'])) $this->mode=$this->_vars['mode']; - if(isset($this->_vars['form_data'])) $this->form=$this->_vars['form_data']; + if(isset($this->_vars['hash'])) $this->url_hash = preg_replace('/^#/','',$this->_vars['hash']); + if(isset($this->_vars['mode'])) $this->mode = $this->_vars['mode']; + if(isset($this->_vars['form_data'])) $this->form = $this->_vars['form_data']; $ures=$this->userAutologin(); $this->sys_vars['authorized']=false; if($ures!==false){ if(isset($ures['id']) && is_numeric($ures['id']) && $ures['id']>0){ - $this->_user_info=$ures; - $this->_user_info['unregistered']=false; - $this->sys_vars['authorized']=true; + $this->_user_info = $ures; + $this->_user_info['unregistered'] = false; + $this->sys_vars['authorized'] = true; }else{ - $this->_user_info['unregistered']=true; + $this->_user_info['unregistered'] = true; if($this->json_req) exit; } } if($this->_post && isset($this->mode)){ if(isset($this->_user_info['error']) && $this->_user_info['error']){ - if($this->mode!='login'){ + if($this->mode != 'login'){ echo json_encode(array('error'=>true,'unregistered_user'=>true)); exit; } diff --git a/php/config.php b/php/config.php index 9f1fe445..dfe776bb 100644 --- a/php/config.php +++ b/php/config.php @@ -4,6 +4,7 @@ class Config { + public static $version = '20.12'; /* Список языков, используемых в проекте */ public static $languages=array( 'en'=>'English', diff --git a/php/locale.php b/php/locale.php deleted file mode 100644 index cc6bca2f..00000000 --- a/php/locale.php +++ /dev/null @@ -1,25 +0,0 @@ -language=$_COOKIE['lang']; - (!array_key_exists($this->language, Config::$languages)) AND $this->language='en'; - include($realpath_public.'/lang/'.$this->language.'.php'); - $this->translate_arr=$lang; - } - - public function get_lang() - { - return $this->language; - } - - public function translate($phrase) - { - return (isset($this->translate_arr[$phrase])) ? $this->translate_arr[$phrase] : $phrase; - } -} \ No newline at end of file diff --git a/php/localization.php b/php/localization.php new file mode 100644 index 00000000..1922de46 --- /dev/null +++ b/php/localization.php @@ -0,0 +1,25 @@ +language = $_COOKIE['lang']; + (!array_key_exists($this->language, Config::$languages)) AND $this->language = 'en'; + include('../public/lang/'.$this->language.'.php'); + $this->translate_arr = $lang; + } + + public function get_lang() + { + return $this->language; + } + + public function translate($phrase) + { + return (isset($this->translate_arr[$phrase])) ? $this->translate_arr[$phrase] : $phrase; + } +} \ No newline at end of file diff --git a/php/menu.php b/php/menu.php deleted file mode 100644 index 3b0fd12a..00000000 --- a/php/menu.php +++ /dev/null @@ -1,91 +0,0 @@ -array( - 'name'=>'Новости', - 'title'=>'Новости сети', - ), - 'connect'=>array( - 'name'=>'Подключение к сети', - 'title'=>'Подключитесь к сети прямо сейчас!', - 'submenu'=>array( - 'map'=>array( - 'name'=>'Зона обслуживания', - 'title'=>'Зона обслуживания абонентов', - ), - 'wifi'=>array( - 'name'=>'Wi-Fi зоны', - 'title'=>'Бесплатные Wi-Fi зоны г. Кириши', - ), - 'docs'=>array( - 'name'=>'Документы', - 'title'=>'Документы' - ) - ) - ), -*/ - -class Menu -{ - public $html=array(); - public $title='Error'; - public $first_key=array(); - - function __construct(Locale $lang, $uri_chunks) - { - $menu_config = Config::$menu; - $this->first_key = array_key_first($menu_config); - - if(getenv('APPLICATION_ENV') != 'development'){ - unset($menu_config['sqlite']); - } - - $this->html=''; - - if($this->title=='Error'){ - $other_titles = Config::$other_titles; - if(isset($other_titles[$qstr])){ - $this->title=$lang->translate($other_titles[$qstr]); - } - } - } -} diff --git a/public/css/styles.css b/public/css/styles.css index 8372a00e..45a18920 100644 --- a/public/css/styles.css +++ b/public/css/styles.css @@ -89,7 +89,6 @@ main { border-width:0 1px; background:#eaeaea url(data:image/gif;base64,R0lGODlhFAAJAJEAAAAAAP///////wAAACH5BAEAAAIALAAAAAAUAAkAAAIdlC+Ain3ADHQNxjQpztJSy23h45HjEpYahq7L6xQAOw==) no-repeat -1px 50%; cursor:pointer; - z-index:1000; } header { position:absolute; @@ -1499,10 +1498,11 @@ dialog#login input[type="password"] { width:250px; } .ccopy { + height: 1px; color:white; text-align:center; position:relative; - top:85%; + margin-top: 23px; font:12px/18px Tahoma, Verdana, Arial; } .login-wait { diff --git a/public/dialogs/system-login.php b/public/dialogs/system-login.php index e85d4662..0d6467b6 100644 --- a/public/dialogs/system-login.php +++ b/public/dialogs/system-login.php @@ -1,6 +1,6 @@ - +
@@ -17,4 +17,4 @@
-
+ \ No newline at end of file diff --git a/public/download.php b/public/download.php index 25f8be9f..21dd1ef7 100644 --- a/public/download.php +++ b/public/download.php @@ -1,39 +1,40 @@ sys_vars['authorized'] != true){ + header('HTTP/1.1 401 Unauthorized'); + exit; + } +} else { # TODO: revisit this + header('HTTP/1.1 401 Unauthorized'); + exit; +} + if(isset($_GET['file'])){ - $file=$_GET['file']; - $filename=$file; -}else{ + $file = $_GET['file']; + $filename = $file; +} else { header('HTTP/1.0 404 Not Found'); exit; } -$res=$clonos->userAutologin(); - -if(isset($res['id']) && $res['id']>0){ +$file = $clonos->media_import.$file; - $file=$clonos->media_import.$file; +header('Content-disposition: attachment; filename='.$filename); +header('Content-type: application/octet-stream'); +header('Cache-Control: must-revalidate'); +header('Pragma: public'); +header('Content-Length: '.filesize($file)); +header("Pragma: no-cache"); +header("Expires: 0"); - header('Content-disposition: attachment; filename='.$filename); - header('Content-type: application/octet-stream'); - header('Cache-Control: must-revalidate'); - header('Pragma: public'); - header('Content-Length: '.filesize($file)); - header("Pragma: no-cache"); - header("Expires: 0"); - - $chunkSize = 1024 * 1024; - $handle = fopen($file, 'rb'); - while (!feof($handle)) - { - $buffer = fread($handle, $chunkSize); - echo $buffer; - ob_flush(); - flush(); - } - fclose($handle); - - exit; +$chunkSize = 1024 * 1024; +$handle = fopen($file, 'rb'); +while (!feof($handle)) +{ + $buffer = fread($handle, $chunkSize); + echo $buffer; + ob_flush(); + flush(); } - -header('HTTP/1.1 401 Unauthorized'); -exit; \ No newline at end of file +fclose($handle); \ No newline at end of file diff --git a/public/index.php b/public/index.php index 509c1b3c..9b0ca77c 100644 --- a/public/index.php +++ b/public/index.php @@ -1,18 +1,33 @@

Sorry, your browser is not supported!

Please, use last version of any browser.

'; - exit; + $title = 'Error'; + + foreach($menu_config as $link => $val){ + if($active == $link){ + $title = $val['title']; + } + } + + if($title == 'Error'){ + if(isset(Config::$other_titles[$active])){ + $title = $other_titles[$active]; + } + } + + return $title; } -$_real_path=realpath('../'); -$uri=trim($_SERVER['REQUEST_URI'],'/'); -require_once($_real_path.'/php/clonos.php'); -require_once($_real_path.'/php/menu.php'); -$chunks=Utils::gen_uri_chunks($uri); -$clonos=new ClonOS($_real_path, $chunks); -$locale = new Locale($_real_path.'/public/'); # /usr/home/web/cp/clonos/public/ -$menu=new Menu($locale, $chunks); +$uri = trim($_SERVER['REQUEST_URI'],'/'); +$chunks = Utils::gen_uri_chunks($uri); + +$clonos = new ClonOS($chunks); +$tpl = new Tpl(); +$lang = $tpl->get_lang(); if(isset($_GET['upload'])){ include('upload.php'); @@ -25,164 +40,46 @@ exit; } -$lang=$locale->get_lang(); -$_ds=DIRECTORY_SEPARATOR; -$root=trim($_SERVER['DOCUMENT_ROOT'], $_ds); - -if(!empty($chunks)) $uri=$chunks[0]; - -$file_path=$_ds.$root.$_ds.'pages'.$_ds.$uri.$_ds; -$file_name=$file_path.$lang.'.index.php'; -$json_name=$file_path.'a.json.php'; +$menu_config = Config::$menu; +$isDev = (getenv('APPLICATION_ENV') == 'development'); +if(!$isDev){ + unset($menu_config['sqlite']); +} if(empty($uri)){ - header('Location: /'.$menu->first_key.'/',true); + header('Location: /'.array_key_first($menu_config).'/',true); exit; +} else { + $uri = $chunks[0]; + $active = trim($uri,'/'); } - -error_reporting(E_ALL); -$user_info=$clonos->userAutologin(); -if(!$user_info['error']){ - $user_info_txt="user_id='${user_info['id']}';user_login='${user_info['username']}';"; -}else{ - $user_info['username']='guest'; +$user_info = $clonos->userAutologin(); +if($user_info['error']){ + $user_info['username'] = 'guest'; } -?> - - - - ClonOS — <?php echo $menu->title; ?> - - - - - - - - - - - - - - - - - - -
-
-
-assign([ + "user_info" => $user_info, + "title" => get_title($menu_config, $active), + "uri" => $uri, + "lang" => $lang +]); +$tpl->draw("index.1"); + +$file_name = 'pages/'.$uri.'/'.$lang.'.index.php'; if(file_exists($file_name)){ include($file_name); } else { - echo '

'.$locale->translate('Not implemented yet').'!

'; + echo '

Not implemented yet!

'; } $clonos->placeDialogs(); -?> -
-
-
-
-
-
Имя клетки:
-
Jail1
-
-
-
-

translate('CPU usage');?>, %:

-
-
-

translate('Memory usage');?>, %:

-
-
-

translate('I/O storage');?>, iops:

-
-
-

translate('I/O storage');?>, bit per seconds:

-
-
-
-
-
-
- - - -
-
- - translate('DONATE'); ?> - - translate('VERSION'),': ',file_get_contents($clonos->realpath.'version'); ?> - - translate('THEMES'); ?>: - - - - -
- -
- - -
-
- - \ No newline at end of file +$tpl->assign([ + "menu_active" => $active, + "menu_conf" => $menu_config, + "version" => Config::$version, + "isDev" => $isDev, + "langs" => Config::$languages +]); +$tpl->draw("index.2"); \ No newline at end of file diff --git a/public/js/clonos.js b/public/js/clonos.js index 68dafcfb..5858b56c 100644 --- a/public/js/clonos.js +++ b/public/js/clonos.js @@ -3245,7 +3245,7 @@ var clonos={ } graphs.getMetrics(); }, - createGraphByGr(gr) + createGraphByGr:function(gr) { $(gr).css({'padding':'1px 0','margin':0,'vertical-align':'middle','font-size':0}); var cl=$(gr).attr('class'); diff --git a/public/json.php b/public/json.php index 9fccf084..5438eb55 100644 --- a/public/json.php +++ b/public/json.php @@ -1,19 +1,18 @@ json_req=true; +if( + !isset($_SERVER['HTTP_X_REQUESTED_WITH']) || + strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest' || + !isset($_POST['path']) +){ + echo '{}'; + exit; +} -//$file_path=$_REALPATH.$_ds.'public/pages'.$_ds.$path.$_ds; -//$clonos->json_name=$file_path.'a.json.php'; +$path = trim($_POST['path'], DIRECTORY_SEPARATOR); + +include('../php/clonos.php'); +$clonos = new ClonOS(); +$clonos->json_req = true; -//if(file_exists($json_name)) include($json_name); else echo '{}'; exit; \ No newline at end of file diff --git a/public/upload.php b/public/upload.php index 4a653514..1ef501cf 100644 --- a/public/upload.php +++ b/public/upload.php @@ -1,7 +1,16 @@ sys_vars['authorized'] != true){ + header('HTTP/1.1 401 Unauthorized'); + exit; + } +} else { # TODO: revisit this + header('HTTP/1.1 401 Unauthorized'); + exit; +} + +header('Content-Type: application/json'); $cmd=''; $status = ''; diff --git a/templates/index.1.html b/templates/index.1.html new file mode 100644 index 00000000..3552839f --- /dev/null +++ b/templates/index.1.html @@ -0,0 +1,41 @@ + + + + ClonOS — {$title|$translate} + + + + + + + + + + + + + + + {noparse} + + +{/noparse} + +
+
+
\ No newline at end of file diff --git a/templates/index.2.html b/templates/index.2.html new file mode 100644 index 00000000..ae749edb --- /dev/null +++ b/templates/index.2.html @@ -0,0 +1,117 @@ +
+
+
+
+
+
Имя клетки:
+
Jail1
+
+
+
+

{translate::('CPU usage')}, %:

+
+
+

{translate::('Memory usage')}, %:

+
+
+

{translate::('I/O storage')}, iops:

+
+
+

{translate::('I/O storage')}, bit per seconds:

+
+
+
+
+
+
+ + + +
+
+ + {translate::('DONATE')} + + {translate::('VERSION')} : {$version} + + {translate::('THEMES')} + + + + +
+ +
+ +{if="$user_info.error"} +