summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorJonathan Bauer2016-04-01 16:50:13 +0200
committerJonathan Bauer2016-04-01 16:50:13 +0200
commitdbc0d9614421e064cc62aacf116ebb783c83f2f3 (patch)
tree091844b8578ff1d9ac18edfd3cee3e63210133d7 /inc
parent[ldapauth] Add homedir conf to ldap wizard (diff)
downloadslx-admin-dbc0d9614421e064cc62aacf116ebb783c83f2f3.tar.gz
slx-admin-dbc0d9614421e064cc62aacf116ebb783c83f2f3.tar.xz
slx-admin-dbc0d9614421e064cc62aacf116ebb783c83f2f3.zip
[merge] merging c3sl / fr - initial commit
Diffstat (limited to 'inc')
-rw-r--r--inc/configmodule/adauth.inc.php3
-rw-r--r--inc/configmodule/ldapauth.inc.php3
-rw-r--r--inc/dictionary.inc.php20
-rw-r--r--inc/event.inc.php19
-rw-r--r--inc/message.inc.php6
-rw-r--r--inc/paginate.inc.php2
-rw-r--r--inc/render.inc.php86
-rw-r--r--inc/taskmanagercallback.inc.php7
-rw-r--r--inc/trigger.inc.php1
-rw-r--r--inc/user.inc.php23
10 files changed, 135 insertions, 35 deletions
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 . '}}', '<b>' . htmlspecialchars($text) . '</b>', $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 . '}}', '<b>' . htmlspecialchars($text) . '</b>', $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
'<!DOCTYPE html>
<html>
@@ -50,6 +54,9 @@ class Render
<link href="style/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="style/bootstrap-tagsinput.css" rel="stylesheet" media="screen">
<link href="style/default.css" rel="stylesheet" media="screen">
+ <link href="style/bootstrap-switch.css" rel="stylesheet" media="screen">
+
+ <script src="script/bootstrap-switch.js"></script>
<script type="text/javascript">
var TOKEN = "' . Session::get('token') . '";
</script>
@@ -58,11 +65,15 @@ class Render
,
' </head>
<body>
- <div class="container" id="mainpage">
+ <div class="container-fluid" id="mainpage">
+ <div class="row">
',
+ self::$dashboard
+ ,
self::$body
,
' </div>
+ </div>
<script src="script/jquery.js"></script>
<script src="script/bootstrap.min.js"></script>
<script src="script/taskmanager.js"></script>
@@ -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 '<h3>Template ' . htmlspecialchars($template) . '</h3>' . nl2br(htmlspecialchars(print_r($params, true))) . '<hr>';
}
// 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 = '<b>Non-existent template ' . $template . ' requested!</b>';
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 = '<div class="col-sm-3 col-md-2 sidebar">';
+ foreach ($categories as $cat => $modules) {
+ self::$dashboard .= '<div class="dash-header"></span> <span class="glyphicon glyphicon-' . self::getGlyphicon($cat)
+ . '" aria-hidden="true"></span> ' . Dictionary::translate('lang_' . $cat) . '</div>';
+ self::$dashboard .= '<ul class="nav nav-sidebar">';
+ foreach ($modules as $module) {
+ self::$dashboard .= '<li class="' . (($page == $module) ? 'active' : '')
+ . '"><a href="?do=' . ucfirst($module) . '"> ' . (Dictionary::translate('lang_' . $module)) . '</a></li>';
+ }
+ self::$dashboard .= '</ul>';
+ }
+ self::$dashboard .= '</div> <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">';
+ }
+ }
+
+ /**
+ * 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'] );
+ }
+
}