From ee27ec0d2bc44fece8b438a4ea58ac956198d300 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sat, 24 May 2014 18:42:23 +0200 Subject: WIP --- modules/main.inc.php | 10 +-- modules/serversetup.inc.php | 121 ++++++++++++++++++++++----------- modules/sysconfig.inc.php | 2 + modules/sysconfig/addmodule_ad.inc.php | 31 ++++----- 4 files changed, 99 insertions(+), 65 deletions(-) (limited to 'modules') diff --git a/modules/main.inc.php b/modules/main.inc.php index 3b35ad53..ddbc37a4 100644 --- a/modules/main.inc.php +++ b/modules/main.inc.php @@ -17,15 +17,7 @@ class Page_Main extends Page return; } // Logged in here - $ipxe = true; - $file = CONFIG_IPXE_DIR . '/last-ip'; - if (file_exists($file)) { - $last = file_get_contents($file); - exec('/bin/ip a', $ips); - foreach ($ips as $ip) { - if (preg_match("#inet $last/\d+.*scope#", $ip)) $ipxe = false; - } - } + $ipxe = (Property::getServerIp() !== Property::getIPxeIp()); $sysconfig = !file_exists(CONFIG_HTTP_DIR . '/default/config.tgz'); $minilinux = !file_exists(CONFIG_HTTP_DIR . '/default/kernel') || !file_exists(CONFIG_HTTP_DIR . '/default/initramfs-stage31') || !file_exists(CONFIG_HTTP_DIR . '/default/stage32.sqfs'); Render::addTemplate('page-main', array('user' => User::getName(), 'ipxe' => $ipxe, 'sysconfig' => $sysconfig, 'minilinux' => $minilinux)); diff --git a/modules/serversetup.inc.php b/modules/serversetup.inc.php index daa3b4e8..3e98b4ad 100644 --- a/modules/serversetup.inc.php +++ b/modules/serversetup.inc.php @@ -2,37 +2,77 @@ class Page_ServerSetup extends Page { + private $taskStatus; private $currentAddress; - + private $currentMenu; + protected function doPreprocess() { User::load(); - + if (!User::hasPermission('superadmin')) { Message::addError('no-permission'); Util::redirect('?do=Main'); } - $this->currentAddress = Property::getServerIp(); - $newAddress = Request::post('ip', 'none'); + $this->currentMenu = Property::getBootMenu(); + + $action = Request::post('action'); + + if ($action === false) { + $this->currentAddress = Property::getServerIp(); + $this->getLocalAddresses(); + } + + if ($action === 'ip') { + // New address is to be set + $this->getLocalAddresses(); + $this->updateLocalAddress(); + } - $this->taskStatus = Taskmanager::submit('LocalAddressesList', array()); + if ($action === 'ipxe') { + // iPXE stuff changes + $this->updatePxeMenu(); + } + } + + protected function doRender() + { + Render::setTitle('Serverseitige Konfiguration'); + Render::addTemplate('serversetup/ipaddress', array( + 'ips' => $this->taskStatus['data']['addresses'], + 'token' => Session::get('token') + )); + $data = $this->currentMenu; + $data['token'] = Session::get('token'); + $data['taskid'] = Property::getIPxeTaskId(); + if ($data['defaultentry'] === 'net') $data['active-net'] = 'checked'; + if ($data['defaultentry'] === 'hdd') $data['active-hdd'] = 'checked'; + if ($data['defaultentry'] === 'custom') $data['active-custom'] = 'checked'; + Render::addTemplate('serversetup/ipxe', $data); + } + + // ----------------------------------------------------------------------------------------------- + + private function getLocalAddresses() + { + $this->taskStatus = Taskmanager::submit('LocalAddressesList', array()); + if ($this->taskStatus === false) { - Util::redirect('?do=Main'); + $this->taskStatus['data']['addresses'] = false; + return false; } - + if ($this->taskStatus['statusCode'] === TASK_WAITING) { // TODO: Async if just displaying $this->taskStatus = Taskmanager::waitComplete($this->taskStatus['id']); } - + $sortIp = array(); foreach (array_keys($this->taskStatus['data']['addresses']) as $key) { - $item =& $this->taskStatus['data']['addresses'][$key]; - if (!isset($item['ip']) - || !preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $item['ip']) - || substr($item['ip'], 0, 4) === '127.') { + $item = & $this->taskStatus['data']['addresses'][$key]; + if (!isset($item['ip']) || !preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $item['ip']) || substr($item['ip'], 0, 4) === '127.') { unset($this->taskStatus['data']['addresses'][$key]); continue; } @@ -43,35 +83,40 @@ class Page_ServerSetup extends Page } unset($item); array_multisort($sortIp, SORT_STRING, $this->taskStatus['data']['addresses']); + return true; + } - if ($newAddress !== 'none') { - // New address is to be set - check if it is valid - $valid = false; - foreach ($this->taskStatus['data']['addresses'] as $item) { - if ($item['ip'] !== $newAddress) continue; - $valid = true; - break; - } - if ($valid) { - Property::setServerIp($newAddress); - Trigger::ipxe(); - } else { - Message::addError('invalid-ip', $newAddress); - } - Util::redirect(); + private function updateLocalAddress() + { + $newAddress = Request::post('ip', 'none'); + $valid = false; + foreach ($this->taskStatus['data']['addresses'] as $item) { + if ($item['ip'] !== $newAddress) + continue; + $valid = true; + break; } - + if ($valid) { + Property::setServerIp($newAddress); + Trigger::ipxe(); + } else { + Message::addError('invalid-ip', $newAddress); + } + Util::redirect(); } - protected function doRender() + private function updatePxeMenu() { - Render::addTemplate('serversetup/ipaddress', array( - 'ips' => $this->taskStatus['data']['addresses'], - 'token' => Session::get('token') - )); - Render::addTemplate('serversetup/ipxe', array( - 'token' => Session::get('token'), - 'taskid' => Property::getIPxeTaskId() - )); + $timeout = Request::post('timeout', 10); + if (!is_numeric($timeout)) { + Message::addError('value-invalid', 'timeout', $timeout); + } + $this->currentMenu['defaultentry'] = Request::post('defaultentry', 'net'); + $this->currentMenu['timeout'] = $timeout; + $this->currentMenu['custom'] = Request::post('custom', ''); + Property::setBootMenu($this->currentMenu); + Trigger::ipxe(true); + Util::redirect('?do=ServerSetup'); } -} \ No newline at end of file + +} diff --git a/modules/sysconfig.inc.php b/modules/sysconfig.inc.php index 7c23ce56..ebccf036 100644 --- a/modules/sysconfig.inc.php +++ b/modules/sysconfig.inc.php @@ -51,6 +51,8 @@ class Page_SysConfig extends Page */ protected function doRender() { + Render::setTitle('Lokalisierung'); + $action = Request::any('action', 'list'); switch ($action) { case 'addmodule': diff --git a/modules/sysconfig/addmodule_ad.inc.php b/modules/sysconfig/addmodule_ad.inc.php index ac820bbc..459d7f2c 100644 --- a/modules/sysconfig/addmodule_ad.inc.php +++ b/modules/sysconfig/addmodule_ad.inc.php @@ -22,6 +22,7 @@ class AdModule_Start extends AddModule_Base 'searchbase' => Request::post('searchbase'), 'binddn' => Request::post('binddn'), 'bindpw' => Request::post('bindpw'), + 'home' => Request::post('home'), 'token' => Session::get('token') )); } @@ -43,23 +44,19 @@ class AdModule_CheckConnection extends AddModule_Base AddModule_Base::setStep('AdModule_Start'); // Continues with AdModule_Start for render() return; } - /* - $data = Taskmanager::submit('LdapSearch', array( - 'id' => $this->taskId, - 'uri' => '' + $ldapSearch = Taskmanager::submit('LdapSearch', array( + 'home' => Request::post('home'), + 'server' => $server, + 'searchbase' => $searchbase, + 'binddn' => $binddn, + 'bindpw' => $bindpw )); - */ - $ldapSearch = Taskmanager::submit('DummyTask', array()); - if (isset($ldapSearch['id'])) { - $dummy = Taskmanager::submit('DummyTask', array('parentTask' => $ldapSearch['id'])); - } - if (!isset($ldapSearch['id']) || !isset($dummy['id'])) { + if (!isset($ldapSearch['id'])) { AddModule_Base::setStep('AdModule_Start'); // Continues with AdModule_Start for render() return; } $this->taskIds = array( - 'tm-search' => $ldapSearch['id'], - 'tm-dummy' => $dummy['id'] + 'tm-search' => $ldapSearch['id'] ); } @@ -72,6 +69,7 @@ class AdModule_CheckConnection extends AddModule_Base 'binddn' => Request::post('binddn'), 'bindpw' => Request::post('bindpw'), 'token' => Session::get('token'), + 'home' => Request::post('home'), 'step' => 'AdModule_Finish' )) ); @@ -90,20 +88,17 @@ class AdModule_Finish extends AddModule_Base Request::post('server'), Request::post('searchbase'), Request::post('binddn'), - Request::post('bindpw') + Request::post('bindpw'), + Request::post('home') ); $config['proxyip'] = Property::getServerIp(); $tgz = Taskmanager::submit('CreateAdConfig', $config); - if (isset($tgz['id'])) { - $ldadp = Taskmanager::submit('DummyTask', array('parentTask' => $tgz['id'])); - } - if (!isset($tgz['id']) || !isset($ldadp['id'])) { + if (!isset($tgz['id'])) { AddModule_Base::setStep('AdModule_Start'); // Continues with AdModule_Start for render() return; } $this->taskIds = array( 'tm-config' => $tgz['id'], - 'tm-ldadp' => $ldadp['id'] ); } -- cgit v1.2.3-55-g7522