From dbc0d9614421e064cc62aacf116ebb783c83f2f3 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Fri, 1 Apr 2016 16:50:13 +0200 Subject: [merge] merging c3sl / fr - initial commit --- inc/configmodule/adauth.inc.php | 3 +- inc/configmodule/ldapauth.inc.php | 3 +- inc/dictionary.inc.php | 20 +++++---- inc/event.inc.php | 19 +++++++-- inc/message.inc.php | 6 ++- inc/paginate.inc.php | 2 +- inc/render.inc.php | 86 ++++++++++++++++++++++++++++++++++----- inc/taskmanagercallback.inc.php | 7 ---- inc/trigger.inc.php | 1 + inc/user.inc.php | 23 +++++++++++ 10 files changed, 135 insertions(+), 35 deletions(-) (limited to 'inc') diff --git a/inc/configmodule/adauth.inc.php b/inc/configmodule/adauth.inc.php index 9fe32f43..efc8afd7 100644 --- a/inc/configmodule/adauth.inc.php +++ b/inc/configmodule/adauth.inc.php @@ -14,8 +14,7 @@ class ConfigModule_AdAuth extends ConfigModule const VERSION = 1; private static $REQUIRED_FIELDS = array('server', 'searchbase', 'binddn'); - private static $OPTIONAL_FIELDS = array('bindpw', 'home', 'ssl', 'fingerprint', 'certificate', 'homeattr', - 'shareRemapMode', 'shareRemapCreate', 'shareDocuments', 'shareDownloads', 'shareDesktop', 'shareMedia', 'shareOther', 'shareHomeDrive'); + private static $OPTIONAL_FIELDS = array('bindpw', 'home', 'ssl', 'fingerprint', 'certificate', 'homeattr'); protected function generateInternal($tgz, $parent) { diff --git a/inc/configmodule/ldapauth.inc.php b/inc/configmodule/ldapauth.inc.php index 118e324f..67b1997a 100644 --- a/inc/configmodule/ldapauth.inc.php +++ b/inc/configmodule/ldapauth.inc.php @@ -14,8 +14,7 @@ class ConfigModule_LdapAuth extends ConfigModule const VERSION = 1; private static $REQUIRED_FIELDS = array('server', 'searchbase'); - private static $OPTIONAL_FIELDS = array('binddn', 'bindpw', 'home', 'ssl', 'fingerprint', 'certificate', - 'shareRemapMode', 'shareRemapCreate', 'shareDocuments', 'shareDownloads', 'shareDesktop', 'shareMedia', 'shareOther', 'shareHomeDrive'); + private static $OPTIONAL_FIELDS = array('binddn', 'bindpw', 'home', 'ssl', 'fingerprint', 'certificate'); protected function generateInternal($tgz, $parent) { diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php index fc509112..ec4f4195 100644 --- a/inc/dictionary.inc.php +++ b/inc/dictionary.inc.php @@ -51,21 +51,26 @@ class Dictionary define('LANG', $language); } - public static function getArrayTemplate($template, $lang = false) + public static function getArrayTemplate($template, $module = false, $lang = false) { - return self::getArray('templates/' . $template, $lang); + return self::getArray($module . "/" . $template, $lang); } - public static function getArray($section, $lang = false) + public static function getArray($module, $lang = false, $isMessage = false) { if ($lang === false) $lang = LANG; - $file = Util::safePath("lang/" . $lang . "/" . $section . ".json"); + if(!$isMessage) + $file = Util::safePath("lang/" . $lang . "/modules/" . $module . ".json"); + else + $file = Util::safePath("lang/" . $lang . "/" . $module . ".json"); + if (isset(self::$stringCache[$file])) return self::$stringCache[$file]; $content = @file_get_contents($file); - if ($content === false) // File does not exist for language + if ($content === false) {// File does not exist for language { return array(); + } $json = json_decode($content, true); if (!is_array($json)) return array(); @@ -83,9 +88,10 @@ class Dictionary return "(missing: $string :missing)"; return self::$hardcodedMessages[$string]; } - $strings = self::getArray($section); - if (!isset($strings[$string])) + $strings = self::getArray($section, false, true); + if (!isset($strings[$string])) { return "(missing: '$string' in '$section')"; + } return $strings[$string]; } diff --git a/inc/event.inc.php b/inc/event.inc.php index e014666a..01a148b0 100644 --- a/inc/event.inc.php +++ b/inc/event.inc.php @@ -26,7 +26,8 @@ class Event $mountId = Trigger::mount(); $autoIp = Trigger::autoUpdateServerIp(); $ldadpId = Trigger::ldadp(); - + $ipxeId = Trigger::ipxe(); + Taskmanager::submit('DozmodLauncher', array( 'operation' => 'start' )); @@ -59,6 +60,17 @@ class Event EventLog::failure("The server's IP address could not be determined automatically, and there is no valid address configured."); $everythingFine = false; } + // iPXE generation + if ($ipxeId === false) { + EventLog::failure('Cannot generate PXE menu: Taskmanager unreachable!'); + $everythingFine = false; + } else { + $res = Taskmanager::waitComplete($ipxeId, 5000); + if (Taskmanager::isFailed($res)) { + EventLog::failure('Update PXE Menu failed', $res['data']['error']); + $everythingFine = false; + } + } // Just so we know booting is done (and we don't expect any more errors from booting up) if ($everythingFine) { @@ -73,11 +85,9 @@ class Event */ public static function serverIpChanged() { + error_log('Server ip changed'); global $tidIpxe; $tidIpxe = Trigger::ipxe(); - if (is_string($tidIpxe)) { - TaskmanagerCallback::addCallback($tidIpxe, 'cbIpxeBuilt'); - } ConfigModule::serverIpChanged(); } @@ -86,6 +96,7 @@ class Event */ public static function activeConfigChanged() { + error_log('Active config changed'); $task = Trigger::ldadp(); TaskmanagerCallback::addCallback($task, 'ldadpStartup'); } diff --git a/inc/message.inc.php b/inc/message.inc.php index 472811ff..d2fd74b9 100644 --- a/inc/message.inc.php +++ b/inc/message.inc.php @@ -59,20 +59,22 @@ class Message foreach ($item['params'] as $index => $text) { $message = str_replace('{{' . $index . '}}', '' . htmlspecialchars($text) . '', $message); } - echo Render::parse('messagebox-' . $item['type'], array('message' => $message)); + echo Render::parse('messagebox-' . $item['type'], array('message' => $message), 'main'); } self::$list = array(); return; } // Non-Ajax + if (!self::$flushed) Render::openTag('div', array('class' => 'container')); foreach (self::$list as $item) { $message = Dictionary::getMessage($item['id']); foreach ($item['params'] as $index => $text) { $message = str_replace('{{' . $index . '}}', '' . htmlspecialchars($text) . '', $message); } - Render::addTemplate('messagebox-' . $item['type'], array('message' => $message)); + Render::addTemplate('messagebox-' . $item['type'], array('message' => $message),'main'); self::$alreadyDisplayed[] = $item; } + if (!self::$flushed) Render::closeTag('div'); self::$list = array(); self::$flushed = true; } diff --git a/inc/paginate.inc.php b/inc/paginate.inc.php index 62345ffe..91f52077 100644 --- a/inc/paginate.inc.php +++ b/inc/paginate.inc.php @@ -104,7 +104,7 @@ class Paginate $pages = Render::parse('pagenav', array( 'url' => $this->url, 'pages' => $pages, - )); + ),'main'); $data['page'] = $this->currentPage; $data['pagenav'] = $pages; Render::addTemplate($template, $data); diff --git a/inc/render.inc.php b/inc/render.inc.php index 6de00eee..10d18514 100644 --- a/inc/render.inc.php +++ b/inc/render.inc.php @@ -18,6 +18,7 @@ class Render private static $mustache = false; private static $body = ''; private static $header = ''; + private static $dashboard = ''; private static $footer = ''; private static $title = ''; private static $templateCache = array(); @@ -39,6 +40,9 @@ class Render $zip = isset($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false); if ($zip) ob_start(); + $page = strtolower($_GET['do']); + if(User::isLoggedIn()) + self::createDashboard($page); echo ' @@ -50,6 +54,9 @@ class Render + + + @@ -58,11 +65,15 @@ class Render , ' -
+
+
', + self::$dashboard + , self::$body , '
+
@@ -129,9 +140,9 @@ class Render /** * Add the given template to the output, using the given params for placeholders in the template */ - public static function addTemplate($template, $params = false) + public static function addTemplate($template, $params = false, $module = false) { - self::$body .= self::parse($template, $params); + self::$body .= self::parse($template, $params, $module); } /** @@ -148,7 +159,7 @@ class Render 'title' => $title, 'next' => $next, 'body' => self::parse($template, $params) - )); + ), 'main'); } /** @@ -164,15 +175,19 @@ class Render * @param string $template name of template, relative to templates/, without .html extension * @return string Rendered template */ - public static function parse($template, $params = false) + public static function parse($template, $params = false, $module = false) { // Load html snippet - $html = self::getTemplate($template); + $html = self::getTemplate($template,$module); if ($html === false) { return '

Template ' . htmlspecialchars($template) . '

' . nl2br(htmlspecialchars(print_r($params, true))) . '
'; } // Get all translated strings for this template - $dictionary = Dictionary::getArrayTemplate($template); + if($module === false){ + $module = strtolower(empty($_REQUEST['do']) ? 'main' : $_REQUEST['do']); + } + $dictionary = Dictionary::getArrayTemplate($template, $module); + // Now find all language tags in this array preg_match_all('/{{(lang_.+?)}}/', $html, $out); foreach ($out[1] as $tag) { @@ -183,7 +198,7 @@ class Render // Always add token to parameter list if (is_array($params) || $params === false || is_null($params)) $params['token'] = Session::get('token'); - // Likewise, add currently selected language (its two letter code) to params + // Likewise, add currently selected language ( its two letter code) to params $params['current_lang'] = LANG; // Add desired password field type $params['password_type'] = Property::getPasswordFieldType(); @@ -224,15 +239,66 @@ class Render /** * Private helper: Load the given template and return it */ - private static function getTemplate($template) + private static function getTemplate($template, $module = false) { if (isset(self::$templateCache[$template])) { return self::$templateCache[$template]; } + // Select current module + if(!$module){ + $module = strtolower(empty($_REQUEST['do']) ? 'Main' : $_REQUEST['do']); + } // Load from disk - $data = @file_get_contents('templates/' . $template . '.html'); + $data = @file_get_contents('modules/' . $module . '/templates/' . $template . '.html'); + if ($data === false) + $data = 'Non-existent template ' . $template . ' requested!'; self::$templateCache[$template] = & $data; return $data; } + /** + * Create the dashboard menu + */ + private static function createDashboard($page) + { + // Check all required modules + $requiredModules = array('adduser','main','session','translation','usermanagement'); + $notFound = ''; + foreach ($requiredModules as $module) { + if(!is_dir('modules/' . $module . '/')){ + $notFound .= '\'' . $module . '\' '; + } + } + if(strlen($notFound) > 0){ + Util::traceError('At least one required module was not found: ' . $notFound); + }else{ + $modules = array_diff(scandir('modules/'), array('..', '.')); + $categories = array(); + foreach ($modules as $module) { + $json = json_decode(file_get_contents("modules/" . $module . "/config.json"),true); + $categories[$json['category']][] = $module; + } + unset($categories['hidden']); + self::$dashboard = '
'; + } + } + + /** + * get categories glyph icons + */ + private static function getGlyphicon($category){ + return json_decode(file_get_contents("style/categories.json"),true)[$category]; + } + } diff --git a/inc/taskmanagercallback.inc.php b/inc/taskmanagercallback.inc.php index efa5aacd..cec763fb 100644 --- a/inc/taskmanagercallback.inc.php +++ b/inc/taskmanagercallback.inc.php @@ -116,13 +116,6 @@ class TaskmanagerCallback EventLog::warning("Could not generate Active Directory configuration", $task['data']['error']); } - public static function cbIpxeBuilt($task) - { - if (Taskmanager::isFailed($task)) { - EventLog::warning("Could not recompile iPXE menu.", $task['data']['error']); - } - } - /** * Generating a config module has finished. * diff --git a/inc/trigger.inc.php b/inc/trigger.inc.php index 0f7e1b13..353d6d69 100644 --- a/inc/trigger.inc.php +++ b/inc/trigger.inc.php @@ -15,6 +15,7 @@ class Trigger * Compile iPXE pxelinux menu. Needs to be done whenever the server's IP * address changes. * + * @param boolean $force force recompilation even if it seems up to date * @return boolean|string false if launching task failed, task-id otherwise */ public static function ipxe() diff --git a/inc/user.inc.php b/inc/user.inc.php index 111849fe..d3cdc65a 100644 --- a/inc/user.inc.php +++ b/inc/user.inc.php @@ -12,6 +12,13 @@ class User return self::$user !== false; } + public static function getId() + { + if (!self::isLoggedIn()) + return false; + return self::$user['userid']; + } + public static function getName() { if (!self::isLoggedIn()) @@ -58,6 +65,7 @@ class User public static function logout() { + error_log("in logout"); Session::delete(); Header('Location: ?do=Main&fromlogout'); exit(0); @@ -81,4 +89,19 @@ class User return self::$user['lasteventid']; } + public static function addUser($data){ + Database::exec ( "INSERT INTO user SET login = :login, passwd = :pass, fullname = :name, phone = :phone, email = :email, permissions = 4", $data ); + $ret = Database::queryFirst('SELECT userid FROM user WHERE login = :user LIMIT 1', array('user' => $data['login'])); + $user = array( + 'user' => $ret['userid'] + ); + Database::exec ( "INSERT INTO setting_partition SET partition_id = '44', size = '5G', mount_point = '/tmp', user = :user", $user ); + Database::exec ( "INSERT INTO setting_partition SET partition_id = '43', size = '20G', mount_point = '/boot', options = 'bootable', user = :user", $user ); + Database::exec ( "INSERT INTO setting_partition SET partition_id = '40', size = '20G', mount_point = '/cache/export/dnbd3', user = :user", $user ); + Database::exec ( "INSERT INTO setting_partition SET partition_id = '41', size = '5G', mount_point = '/home', user = :user", $user ); + Database::exec ( "INSERT INTO setting_partition SET partition_id = '82', size = '1G', user = :user", $user ); + Message::addSuccess('add-user'); + EventLog::info ( User::getName () . ' created user ' . $data['login'] ); + } + } -- cgit v1.2.3-55-g7522