xajax-free version

This commit is contained in:
olevole
2016-11-30 00:04:44 +03:00
parent 68d17c1a60
commit 2e90529dc3
647 changed files with 3036 additions and 130 deletions

549
php/clonos.php Normal file
View File

@@ -0,0 +1,549 @@
<?php
//include_once($_REALPATH.'/forms.php');
class ClonOS
{
public $workdir='';
public $realpath_php='';
public $realpath_public='';
private $_post=false;
private $_db=null;
/*
public $projectId=0;
public $jailId=0;
public $moduleId=0;
public $helper='';
public $mode='';
public $form='';
private $_vars=array();
private $_db_tasks=null;
private $_db_jails=null;
*/
const CBSD_CMD='env NOCOLOR=1 /usr/local/bin/sudo /usr/local/bin/cbsd ';
function cbsd_cmd($cmd)
{
$descriptorspec = array(
0 => array('pipe','r'),
1 => array('pipe','w'),
2 => array('pipe','r')
);
//echo self::CBSD_CMD.$cmd;exit;
$process = proc_open(self::CBSD_CMD.trim($cmd),$descriptorspec,$pipes,null,null);
$error=false;
$error_message='';
$message='';
if (is_resource($process))
{
$buf=stream_get_contents($pipes[1]);
$buf0=stream_get_contents($pipes[0]);
$buf1=stream_get_contents($pipes[2]);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
$task_id=-1;
$return_value = proc_close($process);
if($return_value!=0)
{
$error=true;
$error_message=$buf;
//$log_file='/tmp';
//if(file_exists())
}else{
$message=trim($buf);
}
//echo self::CBSD_CMD.$cmd;
return array('cmd'=>$cmd,'retval'=>$return_value, 'message'=>$message, 'error'=>$error,'error_message'=>$error_message);
}
}
function __construct($_REALPATH) # /usr/home/web/cp/clonos
{
$this->workdir=getenv('WORKDIR');
# // /usr/jails
$this->realpath_php=$_REALPATH.'/php/';
# /usr/home/web/cp/clonos/php/
$this->realpath_php=$_REALPATH.'/public/';
# /usr/home/web/cp/clonos/public/
include('config.php');
include('db.php');
include('menu.php');
$this->config=new Config();
$this->menu=new Menu($this->config->menu);
return;
//echo base64_encode(file_get_contents($rp.'/images/tree-minus.gif'));exit;
if(substr($rp,-7)=='/webdev')
{
$this->realpath=substr($rp,0,-7);
}else{
$this->realpath=$rp;
}
include_once($this->realpath.'/db.php');
$this->_db=new Db('sqlite_webdev');
$this->_db_tasks=new Db('sqlite_cbsd','tasks');
$this->_db_jails=new Db('sqlite_cbsd','jails');
$this->_post=($_SERVER['REQUEST_METHOD']=='POST');
if(isset($_POST['groupsUpdate'])) return;
if($this->_post)
{
$this->_vars=$_POST;
unset($_POST);
$this->projectId=intval($this->_vars['project']);
$this->jailId=intval($this->_vars['jail']);
$this->moduleId=intval($this->_vars['module']);
if(isset($this->_vars['helper']))
$this->helper=$this->_vars['helper'];
$this->mode=$this->_vars['mode'];
if(isset($this->_vars['form_data'])) $this->form=$this->_vars['form_data'];
switch($this->mode)
{
case 'getProjectsList':
$projects=$this->getProjectsList();
echo json_encode(array('projects'=>$projects));
return;break;
case 'getJailsList':
$projects=$this->getProjectsList();
$jails=$this->getJailsList();
echo json_encode(array('jails'=>$jails,'projects'=>$projects));
return;break;
case 'getModulesList':
$jails=$this->getJailsList();
$modules=$this->getModulesList();
echo json_encode(array('jails'=>$jails,'modules'=>$modules));
return;break;
case 'getModuleSettings':
$modules=$this->getModulesList();
$settings=$this->getModuleSettings();
echo json_encode(array('modules'=>$modules,'settings'=>$settings));
return;break;
case 'getHelpersList':
$jails=$this->getJailsList();
$helpers=$this->getHelpersList();
echo json_encode(array('jails'=>$jails,'helpers'=>$helpers));
return;break;
case 'getHelper':
//$jails=$this->getJailsList();
$modules=$this->getHelpersList();
$helper=$this->getHelper();
echo json_encode(array('modules'=>$modules,'helpers'=>$helper));
return;break;
case 'installHelper':
$res=$this->installHelper();
$modules=$this->getHelpersList();
$helper=$this->getHelper();
echo json_encode(array('modules'=>$modules,'helpers'=>$helper,'res'=>$res));
return;break;
case 'saveHelperValues':
$res=$this->saveHelperValues();
echo json_encode($res);
return;break;
case 'getServicesList':
$jails=$this->getJailsList();
$services=$this->getServicesList();
echo json_encode(array('jails'=>$jails,'services'=>$services));
return;break;
case 'getUsersList':
$jails=$this->getJailsList();
$users=$this->getUsersList();
echo json_encode(array('jails'=>$jails,'users'=>$users));
return;break;
case 'getModulesListForInstall':
//$this->updateCountsModules();
$modules=$this->getModulesListForInstallHtml();
echo json_encode(array('html'=>$modules));
return;break;
/*
case 'getInstalledModulesList':
$jails=$this->getJailsList();
$modules=$this->getInstalledModules();
echo json_encode(array('jails'=>$jails,'html'=>$modules));
return;break;
*/
case 'addProject':
echo json_encode($this->projectAdd());
return;break;
case 'editProject':
echo json_encode($this->projectEdit());
return;break;
case 'addJail':
echo json_encode($this->addJail());
return;break;
case 'editJail':
echo json_encode($this->editJail());
return;break;
/*
case 'jailClone':
echo json_encode($this->jailClone());
return;break;
*/
/*
case 'addModule':
$this->addModule();
return;break;
*/
/*
case 'removeModules':
$this->removeModules();
return;break;
*/
case 'jailStart':
echo json_encode($this->jailStart($this->form['jail_name']));
return;break;
case 'getTasksStatus':
echo json_encode($this->_getTasksStatus($this->form['jsonObj']));
return;break;
case 'getJailSettings':
echo json_encode($this->getJailSettings($this->form['id']));
return;break;
case 'getExportedFiles':
echo json_encode($this->getExportedFiles());
return;break;
case 'getImportedFileInfo':
echo json_encode($this->getImportedFileInfo($this->form));
return;break;
case 'addNewUser':
$new_user=$this->addNewUser($this->form);
$jails=$this->getJailsList();
$users=$this->getUsersList();
echo json_encode(array('jails'=>$jails,'users'=>$users,'new_user'=>$new_user));
return;break;
case 'editUser':
$edit_user=$this->editUser($this->form);
$user=array();
$jails=$this->getJailsList();
$users=$this->getUsersList();
echo json_encode(array('jails'=>$jails,'users'=>$users,'new_user'=>$edit_user));
return;break;
case 'getTaskLog':
$jails=$this->getJailsList();
$log=$this->getTaskLog();
echo json_encode(array('jails'=>$jails,'tasklog'=>$log));
return;break;
case 'getTaskLogItem':
$jails=$this->getJailsList();
$item=$this->getTaskLogItem();
echo json_encode(array('jails'=>$jails,'item'=>$item));
return;break;
case 'getForm':
$res=$this->getForm();
echo json_encode($res);
return;break;
}
}
}
function check_locktime($nodeip)
{
$lockfile=$this->workdir."/ftmp/shmux_${nodeip}.lock";
if (!file_exists($lockfile)) {
return 0;
}
$cur_time = time();
$st_time=filemtime($lockfile);
$difftime=(( $cur_time - $st_time ) / 60 );
if ( $difftime > 1 ) {
return round($difftime);;
} else {
return 0; //lock exist but too fresh
}
}
function get_node_info($nodename,$value)
{
$db = new SQLite3($this->realpath."/var/db/nodes.sqlite"); $db->busyTimeout(5000);
if (!$db) return;
$sql = "SELECT $value FROM nodelist WHERE nodename=\"$nodename\"";
$result = $db->query($sql);//->fetchArray(SQLITE3_ASSOC);
$row = array();
while($res = $result->fetchArray(SQLITE3_ASSOC)){
if(!isset($res["$value"])) return;
return $res["$value"];
}
}
/*
function getProjectsListOnStart()
{
$query='select * from projects';
$res=$this->_db->select($query);
echo ' var projects=',json_encode($res),PHP_EOL;
}
*/
/*
function getTaskStatus($task_id)
{
$status=$this->_db_tasks->selectAssoc("select status,logfile,errcode from taskd where id='{$task_id}'");
if($status['errcode']>0)
{
$status['errmsg']=file_get_contents($status['logfile']);
}
return $status;
}
*/
function _getTasksStatus($jsonObj)
{
$tasks=array();
$obj=json_decode($jsonObj,true);
if(isset($obj['proj_ops'])) return $this->GetProjectTasksStatus($obj);
if(isset($obj['mod_ops'])) return $this->GetModulesTasksStatus($obj);
$ops_array=array('jcreate','jstart','jstop','jedit','jremove','jexport','jimport','jclone','madd','sstart','sstop','projremove'); //,'mremove'
$stat_array=array(
'jcreate'=>array(get_translate('Creating'),get_translate('Not running')),
'jstart'=>array(get_translate('Starting'),get_translate('Launched')),
'jstop'=>array(get_translate('Stopping'),get_translate('Stopped')),
'jedit'=>array(get_translate('Saving'),get_translate('Saved')),
'jremove'=>array(get_translate('Removing'),get_translate('Removed')),
'jexport'=>array(get_translate('Exporting'),get_translate('Exported')),
'jimport'=>array(get_translate('Importing'),get_translate('Imported')),
'jclone'=>array(get_translate('Cloning'),get_translate('Cloned')),
'madd'=>array(get_translate('Installing'),get_translate('Installed')),
//'mremove'=>array('Removing','Removed'),
'sstart'=>array(get_translate('Starting'),get_translate('Started')),
'sstop'=>array(get_translate('Stopping'),get_translate('Stopped')),
//'projremove'=>array('Removing','Removed'),
);
if(!empty($obj)) foreach($obj as $key=>$task)
{
$op=$task['operation'];
$status=$task['status'];
if(in_array($op,$ops_array))
{
$res=false;
if($status==-1)
{
switch($op)
{
case 'jstart': $res=$this->jailStart('jail'.$key,$key);break;
case 'jstop': $res=$this->jailStop('jail'.$key,$key);break;
case 'jedit': $res=$this->jailEdit('jail'.$key);break;
case 'jremove': $res=$this->jailRemove('jail'.$key,$key);break;
case 'jexport': $res=$this->jailExport('jail'.$key,$task['jname'],$key);break;
case 'jimport': $res=$this->jailImport('jail'.$key,$task['jname'],$key);break;
case 'jclone': $res=$this->jailClone('jail'.$key,$key,$obj[$key]);break;
case 'madd': $res=$this->moduleAdd('jail'.$key,$task['jname'],$key);break;
//case 'mremove': $res=$this->moduleRemove('jail'.$key,$task['jname'],$key);break;
case 'sstart': $res=$this->serviceStart($task);break;
case 'sstop': $res=$this->serviceStop($task);break;
//case 'projremove': $res=$this->projectRemove($key,$task);break;
}
}
if($res!==false)
{
if($res['error'])
$obj[$key]['retval']=$res['retval'];
if(!empty($res['error_message']))
$obj[$key]['error_message']=$res['error_message'];
if(isset($res['message']))
{
$task_id=intval($res['message']);
if($task_id>0)
{
$tasks[]=$task_id;
$obj[$key]['task_id']=$task_id;
//$obj[$key]['txt_log']=file_get_contents('/tmp/taskd.'.$task_id.'.log');
}
}
}else{
$tasks[]=$task['task_id'];
}
}
}
$ids=join(',',$tasks);
if(!empty($ids))
{
$query="select id,status,logfile,errcode from taskd where id in ({$ids})";
$statuses=$this->_db_tasks->select($query);
//print_r($statuses);
if(!empty($obj)) foreach($obj as $key=>$task)
{
if(!empty($statuses)) foreach($statuses as $stat)
{
if($task['task_id']==$stat['id'])
{
$obj[$key]['status']=$stat['status'];
$num=($stat['status']<2?0:1);
$obj[$key]['txt_status']=$stat_array[$obj[$key]['operation']][$num];
if($stat['errcode']>0)
{
$obj[$key]['errmsg']=file_get_contents($stat['logfile']);
$obj[$key]['txt_status']=get_translate('Error');
}
# Удаляем джейл
if($stat['status']==2 && $task['operation']=='jremove')
{
$this->jailRemoveFromDb($stat['errcode'],$task);
}
# Удаляем модуль
/*
if($stat['status']==2 && $task['operation']=='mremove')
{
$this->moduleRemoveFromDb($stat['errcode'],$task);
}
*/
# Возвращаем IP клонированному джейлу, если он был присвоен по DHCP
if($stat['status']==2 && $task['operation']=='jclone')
{
//$obj[$key]['new_ip']=$this->getJailIpOnJcloneEnd($key);
}
}
}
}
}
if(isset($res['cloned']) && $res['cloned'])
{
$obj[-1]['jails']=$this->getJailsList();
}
return $obj;
}
function GhzConvert($Hz=0)
{
$h=1;$l='Mhz';
if($Hz>1000){$h=1000;$l='Ghz';}
return round($Hz/$h,2).' '.$l;
}
function fileSizeConvert($bytes, $bytes_in_mb=1024)
{
$bytes = floatval($bytes);
$arBytes = array(
0 => array(
"UNIT" => "TB",
"VALUE" => pow($bytes_in_mb, 4)
),
1 => array(
"UNIT" => "GB",
"VALUE" => pow($bytes_in_mb, 3)
),
2 => array(
"UNIT" => "MB",
"VALUE" => pow($bytes_in_mb, 2)
),
3 => array(
"UNIT" => "KB",
"VALUE" => $bytes_in_mb
),
4 => array(
"UNIT" => "B",
"VALUE" => 1
),
);
$result='0 MB';
foreach($arBytes as $arItem)
{
if($bytes >= $arItem["VALUE"])
{
$result = $bytes / $arItem["VALUE"];
$result = str_replace(".", "," , strval(round($result, 2)))." ".$arItem["UNIT"];
break;
}
}
return $result;
}
}
function translate($phrase)
{
$lang=getLang();
$file=getLangFilePath($lang);
if(!file_exists($file)) $file=getLangFilePath('en');
if(!file_exists($file)) return;
require($file);
if(isset($lang[$phrase]))
echo $lang[$phrase];
else
echo $phrase;
}
function get_translate($phrase)
{
$lang=getLang();
$file=getLangFilePath($lang);
if(!file_exists($file)) $file=getLangFilePath('en');
require($file);
if(isset($lang[$phrase]))
return $lang[$phrase];
else
return $phrase;
}
function getLang()
{
if(isset($_COOKIE['lang']))
$lang=$_COOKIE['lang'];
if(empty($lang)) $lang='en';
return $lang;
}
function getLangFilePath($lang)
{
global $_REALPATH;
return $_REALPATH.'/public/lang/'.$lang.'.php';
}

89
php/config.php Normal file
View File

@@ -0,0 +1,89 @@
<?php
class Config
{
/* Список языков, используемых в проекте */
public $languages=array(
'en'=>'English',
'ru'=>'Russian',
'de'=>'Deutch',
);
/* Меню проекта */
/* Так же можно использовать подменю (в menu.php есть пример) */
public $menu=array(
'overview'=>array(
'name'=>'Overview',
'title'=>'Summary Overview', // заголовки лучше делать более полными, чем просто повторение пункта меню
),
'jailscontainers'=>array(
'name'=>'Jails containers',
'title'=>'Jails containers control panel',
),
'instance_jail'=>array(
'name'=>'Template for jail',
'title'=>'Helpers and wizard for containers',
),
'bhyvevms'=>array(
'name'=>'Bhyve VMs',
'title'=>'Virtual machine control panel',
),
'nodes'=>array(
'name'=>'Nodes',
'title'=>'Nodes control panel',
),
'vpnet'=>array(
'name'=>'Virtual Private Network',
'title'=>'Manage for virtual private networks',
),
'authkey'=>array(
'name'=>'Authkey',
'title'=>'Manage for SSH auth key',
),
'media'=>array(
'name'=>'Storage Media',
'title'=>'Virtual Media Manager',
),
'repo'=>array(
'name'=>'Repository',
'title'=>'Remote repository',
),
'bases'=>array(
'name'=>'FreeBSD Bases',
'title'=>'FreeBSD bases manager',
),
'sources'=>array(
'name'=>'FreeBSD Sources',
'title'=>'FreeBSD sources manager',
),
'jail_marketplace'=>array(
'name'=>'Jail Marketplace',
'title'=>'Public remote containers marketplace',
),
'bhyve_marketplace'=>array(
'name'=>'Bhyve Marketplace',
'title'=>'Public remote virtual machine marketplace',
),
'tasklog'=>array(
'name'=>'TaskLog',
'title'=>'System task log',
),
'sqlite'=>array(
'name'=>'SQLite admin',
'title'=>'SQLite admin interface',
),
);
}

145
php/db.php Normal file
View File

@@ -0,0 +1,145 @@
<?php error_reporting(E_ALL);
class Db
{
private $_pdo=null;
private $_workdir='';
public $error=false;
public $error_message='';
/*
$place = base (это базовый набор баз данных: local, nodes и т.д.)
$place = file (указываем конкретную базу данных по полному пути)
*/
function __construct($place='base',$database='')
{
$this->_workdir=getenv('WORKDIR'); // /usr/jails/
// sqlite:/usr/jails/var/db/local.sqlite
if($place=='base')
{
$file_name=$this->_workdir.'/var/db/'.$database.'.sqlite';
$connect='sqlite:'.$file_name;
}elseif($place=='file'){
}
/*
$databases=array(
'tasks'=>'cbsdtaskd',
'jails'=>'local',
);
switch($driver)
{
case 'sqlite_webdev':
$connect='sqlite:/var/db/webdev/webdev.sqlite';
break;
case 'forms':
$connect='sqlite:/var/db/webdev/forms.sqlite';
break;
case 'helpers':
if(is_array($database))
{
$connect='sqlite:'.$this->_workdir.'/jails-system/'.
$database['jname'].'/helpers/'.$database['helper'].".sqlite";
}else{
$connect='';
}
break;
case 'sqlite_cbsd':
if($database!='')
{
if(!isset($databases[$database])) break;
$db=$databases[$database];
$connect='sqlite:'.$this->_workdir.'/var/db/'.$db.'.sqlite';
}
break;
case 'pkg':
$connect='sqlite:'.$this->_workdir.'/jails-data/'.$database.'-data/var/db/pkg/local.sqlite';
break;
/-*
case 'from_file':
echo $this->_workdir.$database;
$connect='sqlite:'.$this->_workdir.$database;
//"/jails-system/jail".$this->jailId."/helpers/".$this->helper.".sqlite"
break;
*-/
default:
throw new Exception('Unknown database driver!');
break;
}
*/
if(!file_exists($file_name))
{
$this->error=true;
$this->error_message='DB file not found!';
return false;
}
if(!empty($connect))
{
try
{
$this->_pdo = new PDO($connect);
$this->_pdo->setAttribute(PDO::ATTR_TIMEOUT,5000);
}catch (PDOException $e){
$this->error=true;
$this->error_message=$e->getMessage(); //'DB Error';
return false;
}
}else{
return false;
}
}
function getWorkdir()
{
return $this->_workdir;
}
function select($query)
{
if($quer=$this->_pdo->query($query))
{
$res=$quer->fetchAll(PDO::FETCH_ASSOC);
return $res;
}
return array();
}
function selectAssoc($query)
{
if($quer=$this->_pdo->query($query))
{
$res=$quer->fetch(PDO::FETCH_ASSOC);
return $res;
}
return array();
}
function insert($query)
{
if($quer=$this->_pdo->query($query))
{
$lastID=$this->_pdo->lastInsertId();
return array('error'=>false,'lastID'=>$lastID);
}else{
$error=array('error'=>true,'info'=>$this->_pdo->errorInfo());
return $error;
}
return false;
}
function update($query)
{
if($quer=$this->_pdo->query($query))
{
$rowCount=$quer->rowCount();
return array('rowCount'=>$rowCount);
}else{
$error=$this->_pdo->errorInfo();
return $error;
}
return false;
}
}

149
php/forms.php Normal file
View File

@@ -0,0 +1,149 @@
<?php
include_once($_REALPATH.'/db.php');
class Forms
{
private $name='';
private $db='';
private $html='';
function __construct($jname,$helper)
{
$this->name=$jname;
$this->db=new Db('helpers',array('jname'=>$jname,'helper'=>$helper));
}
function generate()
{
$query="select * from forms order by group_id asc, order_id asc";
$fields=$this->db->select($query);
//echo '<pre>';print_r($fields);
$defaults=array();
$last_type='';
$this->html='<form name=""><div class="form-fields">';
foreach($fields as $key=>$field)
{
/*
if($last_type=='delimer' && $field['type']!='delimer')
$this->html.='<div class="pad-head"></div>';
*/
$last_type=$field['type'];
$tpl=$this->getElement($field['type'],$field);
$params=array('param','desc','attr','cur');
foreach($params as $param)
{
if(isset($field[$param]))
$tpl=str_replace('${'.$param.'}',$field[$param],$tpl);
}
//$value=$field['def'];
//if(isset($field['cur']) && !empty($field['cur'])) $value=$field['cur'];
$value=$field['cur'];
$tpl=str_replace('${value}',$value,$tpl);
$value=$field['def'];
$tpl=str_replace('${def}',$value,$tpl);
$required=($field['mandatory']==1)?' required':'';
$tpl=str_replace('${required}',$required,$tpl);
$this->html.=$tpl;
if(!empty($field['def'])) $defaults[$key]=$field['def'];
}
$this->html.='</div>';
$this->setButtons();
$this->html.='</form>';
return array('html'=>$this->html,'defaults'=>$defaults);
}
function getElement($el,$arr=array())
{
$tpl='';
switch(trim($el))
{
case 'inputbox':
$tpl='<div class="form-field"><input type="text" name="${param}" value="${value}" ${attr}${required} /><span class="default val-${def}" title="Click to fill dafault value">[default]</span><span class="small">${desc}</span></div>';
break;
case 'password':
$tpl='<div class="form-field"><input type="password" name="${param}" value="${value}" ${attr}${required} /><span class="default val-${def}" title="Click to fill dafault value">[default]</span><span class="small">${desc}</span></div>';
break;
case 'delimer':
$tpl='<h1>${desc}</h1>';
break;
case 'checkbox':
$tpl='<input type="checkbox" id="chk-${idx}" name="${param}" /><label for="chk-${idx}">${desc}</label>';
break;
case 'select':
$tpl=$this->getSelect($el,$arr);
break;
case 'radio':
$tpl=$this->getRadio($el,$arr);
break;
}
return $tpl;
}
function getSelect($el,$arr)
{
$tpl='<div class="form-field"><select name="${param}">';
if(isset($arr['link']))
{
$query="select * from {$arr['link']} order by order_id asc";
$opts=$this->db->select($query);
array_unshift($opts,array('id'=>0,'text'=>'','order_id'=>-1));
if(!empty($opts))foreach($opts as $key=>$opt)
{
$selected=($opt['id']==$arr['cur'])?' selected':'';
$tpl.='<option value="'.$opt['id'].'"'.$selected.'>'.$opt['text'].'</option>';
}
}
$tpl.='</select><span class="default val-${def}" title="Click to fill dafault value">[default]</span><span class="small">${desc}</span></div>';
return $tpl;
}
function getRadio($el,$arr)
{
$tpl='<div class="form-field"><fieldset><legend>${desc}</legend>';
if(isset($arr['link']))
{
$query="select * from {$arr['link']} order by order_id asc";
$opts=$this->db->select($query);
if(!empty($opts))foreach($opts as $key=>$opt)
{
$checked=($opt['id']==$arr['cur'])?' checked':'';
$tpl.='<label for="${param}-'.$opt['id'].'">'.$opt['text'].':</label><input type="radio" name="${param}" value="'.$opt['id'].'" id="${param}-'.$opt['id'].'"'.$checked.' />';
}
}
$tpl.='</fieldset></div>';
return $tpl;
}
function setButtons($arr=array())
{
$this->html.='<div class="buttons"><input type="button" value="Apply" class="save-helper-values" title="Save and apply params" /> &nbsp; <input type="button" value="Clear" class="clear-helper" title="Restore loaded params" /></div>';
}
}
/*
$form=new Forms('php');
?>
<html>
<style>
body {font-size:100%;font-family:Tahoma,'Sans-Serif',Arial;}
h1 {color:white;background:silver;margin:0;padding:10px;}
.small {font-size:x-small;}
.form-field {padding:4px 10px 0 10px;margin:0 4px; background:#fafafa;}
.form-field span {margin-left:10px;}
.form-field input {width:300px;}
form {border:1px solid gray;padding:0;margin-bottom:10px;width:500px;border-radius:8px;overflow:hidden;box-shadow:4px 4px 6px rgba(0,0,0,0.2);}
.buttons {padding:20px 10px;text-align:center;}
</style>
<?php
$form->generate();
//$form->setButtons(array('save','cancel'));
*/

86
php/menu.php Normal file
View File

@@ -0,0 +1,86 @@
<?php
/*
'news'=>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 $name='';
public $title='Error';
public $path='';
public $first_key=array();
function __construct($menu_config=array())
{
if(!empty($menu_config))
{
reset($menu_config);
$this->first_key=key($menu_config);
}
$this->html='<ul class="menu">'.PHP_EOL;
$qstr=trim($_SERVER['REQUEST_URI'],DIRECTORY_SEPARATOR);
$this->path=$qstr; //$_MENU_PATH
if(!empty($menu_config))foreach($menu_config as $key=>$val)
{
$mname=get_translate($val['name']);
$mtitle=get_translate($val['title']);
$link=$key;
$sel='';
if($qstr==$key){
$sel=' class="sel"';
$this->title=$mtitle; //$_TITLE
$this->name=$mname; //$_MENU_NAME
}
$this->html.=' <li><a href="/'.$link.'/" title="'.$mtitle.'"'.$sel.'>'.$mname.'</a>';
if(!empty($val['submenu']))
{
$this->html.= PHP_EOL.' <ul class="submenu">'.PHP_EOL;
foreach($val['submenu'] as $k=>$s)
{
$sname=get_translate($s['name']);
$stitle=get_translate($s['title']);
$slink=$link.'/'.$k;
$sl=$link.'_'.$k;
$ssel='';
if($qstr==$sl){
$ssel=' class="sel"';
$this->title=$stitle;
$this->name=$sname;
}
$this->html.= ' <li><a href="/'.$slink.'/" title="'.$stitle.'"'.$ssel.'>'.$sname.'</a></li>'.PHP_EOL;
}
$this->html.= ' </ul>'.PHP_EOL.' ';
}
$this->html.= '</li>'.PHP_EOL;
}
$this->html.='</ul>';
}
}

View File

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

Some files were not shown because too many files have changed in this diff Show More