diff options
author | Simon Rettberg | 2016-05-03 19:03:09 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-05-03 19:03:09 +0200 |
commit | 50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66 (patch) | |
tree | 05e99fdffa696434960d7c77966c0bc36d6339e8 /modules-available/sysconfignew/page.inc.php | |
parent | Second half of merge.... (diff) | |
download | slx-admin-50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66.tar.gz slx-admin-50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66.tar.xz slx-admin-50404f3b23b7fd6aeae4c9d2f6df0ea25e984e66.zip |
WIP
Diffstat (limited to 'modules-available/sysconfignew/page.inc.php')
-rw-r--r-- | modules-available/sysconfignew/page.inc.php | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/modules-available/sysconfignew/page.inc.php b/modules-available/sysconfignew/page.inc.php new file mode 100644 index 00000000..105ad6c7 --- /dev/null +++ b/modules-available/sysconfignew/page.inc.php @@ -0,0 +1,113 @@ +<?php + +class Page_SysConfigNew extends Page +{ + // private $tmpath = '/srv/openslx/www/'; + private $tmpath = '/home/raul/tm-scripts/server'; + private $tmconfigs; + private $tmmodules; + + protected function doPreprocess(){ + User::load(); + if (!User::hasPermission('baseconfig_local')) { + Message::addError('no-permission'); + Util::redirect('?do=Main'); + } + + $this->tmconfigs = $this->tmpath . '/configs'; + $this->tmmodules = $this->tmpath . '/modules'; + } + + + protected function doRender(){ + $module = $_GET['module']; + if(isset($module)){ + Render::addTemplate('module-editor',array( + "module" => $module + )); + }else{ + if(is_dir($this->tmpath)){ + $configs = array(); + $modules = array(); + + foreach($this->listDirectory($this->tmconfigs) as $key => $value) + $configs[] = array( + "name" => $value + ); + + foreach($this->listDirectory($this->tmmodules) as $key => $value) + $modules[] = array( + "name" => $value + ); + + $data = array( + "configs" => $configs, + "modules" => $modules + ); + Render::addTemplate('_pagenew',$data); + }else{ + Message::addError('no-tm-scripts'); + } + } + } + + protected function doAjax(){ + $request = $_GET['request']; + switch($request){ + case "module-contents": + $path = $this->tmpath . '/modules/' . Request::get('module'); + $data = $this->getDirContents($path); + $json = json_encode($data); + print_r($json); + break; + case "configs": + $this->tmconfigs = $this->tmpath . '/configs'; + $this->tmmodules = $this->tmpath . '/modules'; + $userModules = $this->listDirectory($this->tmconfigs . '/' . Request::get('config')); + $modules = array(); + foreach($this->listDirectory($this->tmmodules) as $key => $value){ + $chosen = (in_array($value, $userModules)) ? true : false; + $modules[] = array( + "name" => $value, + "chosen" => $chosen + ); + } + + foreach ($modules as $module) { + $class = ($module['chosen']) ? "select-item select-item-selected" : "select-item"; + $ret .= "<button type='button' class='" . $class . "' onclick='select(this)' >"; + $ret .= $module['name']; + $ret .= "</button>"; + } + + echo $ret; + break; + } + + } + + private function getDirContents($path){ + $ret = array(); + foreach ($this->listDirectory($path) as $key => $value) { + if(is_dir($path . "/" . $value)){ + $ret["dir_" . $value] = $this->getDirContents($path . "/" . $value); + }else{ + if(is_link($path . "/" . $value)){ + $ret["link_" . $value] = readlink($path . "/" . $value); + }else{ + if(mime_content_type($path . "/" . $value) == "text/plain"){ + $ret["file_" . $value] = file_get_contents($path . "/" . $value); + }else{ + $ret["lock_" . $value] = " oops"; + } + } + } + } + return $ret; + } + + private function listDirectory($path){ + return array_diff(scandir($path), array('..', '.')); + } + +} |