diff options
author | Simon Rettberg | 2016-06-08 18:33:30 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-06-08 18:33:30 +0200 |
commit | ffffab643e031524b6fdfe0c39adae1f6c8e9c4d (patch) | |
tree | 84e55c5a7ea0e02481b9f44730814ae788f05e12 | |
parent | [dashboard] Remove needsSchemaUpdate call (diff) | |
download | slx-admin-ffffab643e031524b6fdfe0c39adae1f6c8e9c4d.tar.gz slx-admin-ffffab643e031524b6fdfe0c39adae1f6c8e9c4d.tar.xz slx-admin-ffffab643e031524b6fdfe0c39adae1f6c8e9c4d.zip |
[install] Implement install scripts for most modules
-rw-r--r-- | apis/update.inc.php | 273 | ||||
-rw-r--r-- | inc/database.inc.php | 29 | ||||
-rw-r--r-- | inc/defaultdata.inc.php | 204 | ||||
-rw-r--r-- | inc/dictionary.inc.php | 1 | ||||
-rw-r--r-- | install.php | 23 | ||||
-rw-r--r-- | modules-available/baseconfig/install.inc.php | 58 | ||||
-rw-r--r-- | modules-available/eventlog/install.inc.php | 31 | ||||
-rw-r--r-- | modules-available/locations/install.inc.php | 39 | ||||
-rw-r--r-- | modules-available/main/install.inc.php | 73 | ||||
-rw-r--r-- | modules-available/news/install.inc.php | 24 | ||||
-rw-r--r-- | modules-available/statistics/install.inc.php | 97 | ||||
-rw-r--r-- | modules-available/sysconfig/inc/configmodule/adauth.inc.php | 6 | ||||
-rw-r--r-- | modules-available/sysconfig/inc/configmodule/branding.inc.php | 6 | ||||
-rw-r--r-- | modules-available/sysconfig/inc/configmodule/customodule.inc.php | 6 | ||||
-rw-r--r-- | modules-available/sysconfig/inc/configmodule/ldapauth.inc.php | 6 | ||||
-rw-r--r-- | modules-available/sysconfig/inc/configmodule/sshconfig.inc.php | 6 | ||||
-rw-r--r-- | modules-available/sysconfig/install.inc.php | 90 | ||||
-rw-r--r-- | modules-available/syslog/install.inc.php | 38 | ||||
-rw-r--r-- | script/install.js | 35 |
19 files changed, 536 insertions, 509 deletions
diff --git a/apis/update.inc.php b/apis/update.inc.php index e7ecc6bd..d3262eb3 100644 --- a/apis/update.inc.php +++ b/apis/update.inc.php @@ -56,277 +56,4 @@ if ($list === false) { Message::addSuccess('db-update-done'); if (tableExists('eventlog')) EventLog::info("Database updated to version $currentVersion"); -DefaultData::populate(); Util::redirect('index.php?do=Main'); - -//////////////// - -function tableHasColumn($table, $column) -{ - $table = preg_replace('/\W/', '', $table); - $column = preg_replace('/\W/', '', $column); - $res = Database::simpleQuery("DESCRIBE `$table`", array(), true); - if ($res !== false) { - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - if ((is_array($column) && in_array($row['Field'], $column)) || (is_string($column) && $row['Field'] === $column)) - return true; - } - } - return false; -} - -function tableDropColumn($table, $column) -{ - $table = preg_replace('/\W/', '', $table); - $column = preg_replace('/\W/', '', $column); - $res = Database::simpleQuery("DESCRIBE `$table`", array(), true); - if ($res !== false) { - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - if ((is_array($column) && in_array($row['Field'], $column)) || (is_string($column) && $row['Field'] === $column)) - Database::exec("ALTER TABLE `$table` DROP `{$row['Field']}`"); - } - } -} - -function tableExists($table) -{ - $res = Database::simpleQuery("SHOW TABLES", array(), true); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - if ($row['Tables_in_openslx'] === $table) - return true; - } - return false; -} - -// The update functions. Number at the end refers to current version, the function will update to the next version -// ####################### -// ##### 2014-05-28 -// Add dateline field to property table - -function update_1() -{ - if (!tableHasColumn('property', 'dateline')) { - Database::exec("ALTER TABLE `property` ADD `dateline` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `name` , ADD INDEX ( `dateline` )"); - } else { - Database::exec("ALTER TABLE `property` CHANGE `dateline` `dateline` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'"); - } - return true; -} - -// ####################### -// ##### 2014-06-05 -// Add 'news' table to database schema -function update_2() -{ - if (!tableExists('news')) { - // create table - Database::exec("CREATE TABLE IF NOT EXISTS `news` ( - `newsid` int(10) unsigned NOT NULL AUTO_INCREMENT, - `dateline` int(10) unsigned NOT NULL, - `title` varchar(200) DEFAULT NULL, - `content` text, - PRIMARY KEY (`newsid`), - KEY `dateline` (`dateline`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 - "); - } - return true; -} - -// ####################### -// ##### 2014-08-18 -// Remove setting descriptions from DB, put into json files now -function update_3() -{ - tableDropColumn('setting', array('de', 'en', 'pt', 'description')); - tableDropColumn('cat_setting', array('de', 'en', 'pt', 'name')); - return true; -} - -// ####################### -// ##### 2014-08-18 -// Remove description column from permission table, add eventlog table -function update_4() -{ - tableDropColumn('permission', 'description'); - if (!tableExists('eventlog')) { - // create table - Database::exec("CREATE TABLE IF NOT EXISTS `eventlog` ( - `logid` int(10) unsigned NOT NULL AUTO_INCREMENT, - `dateline` int(10) unsigned NOT NULL, - `logtypeid` varchar(30) NOT NULL, - `description` varchar(255) NOT NULL, - PRIMARY KEY (`logid`), - KEY `dateline` (`dateline`), - KEY `logtypeid` (`logtypeid`,`dateline`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - "); - } - return true; -} - -// ####################### -// ##### 2014-08-18 -// Add details column to eventlog table, add callback table -function update_5() -{ - if (!tableHasColumn('eventlog', 'extra')) - Database::exec("ALTER TABLE `eventlog` ADD `extra` TEXT NOT NULL"); - if (!tableHasColumn('user', 'lasteventid')) - Database::exec("ALTER TABLE `user` ADD `lasteventid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'"); - if (!tableExists('callback')) { - Database::exec("CREATE TABLE IF NOT EXISTS `callback` ( - `taskid` varchar(40) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, - `dateline` int(10) unsigned NOT NULL, - `cbfunction` varchar(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, - PRIMARY KEY (`taskid`,`cbfunction`), - KEY `dateline` (`dateline`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 - "); - } - return true; -} - -// ####################### -// ##### 2014-12-04 -// Add displayvalue column to setting_* -function update_6() -{ - foreach (array('setting_global', 'setting_distro') as $table) { - if (!tableHasColumn($table, 'displayvalue')) { - Database::exec("ALTER TABLE $table ADD `displayvalue` TEXT NOT NULL"); - Database::exec("UPDATE $table SET displayvalue = value"); - } - } - return true; -} - -// ####################### -// ##### 2014-12-12 -// Rename config modules -function update_7() -{ - Database::exec("UPDATE configtgz_module SET moduletype = 'Branding' WHERE moduletype = 'BRANDING'"); - Database::exec("UPDATE configtgz_module SET moduletype = 'AdAuth' WHERE moduletype = 'AD_AUTH'"); - Database::exec("UPDATE configtgz_module SET moduletype = 'CustomModule' WHERE moduletype = 'custom'"); - return true; -} - -// ####################### -// ##### 2015-01-16 -// Extend config module db table, add argument feature to callbacks -function update_8() -{ - tableDropColumn('configtgz_module', 'haschanged'); - if (!tableHasColumn('configtgz_module', 'version')) - Database::exec("ALTER TABLE `configtgz_module` ADD `version` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'"); - if (!tableHasColumn('configtgz_module', 'status')) - Database::exec("ALTER TABLE `configtgz_module` ADD `status` ENUM( 'OK', 'MISSING', 'OUTDATED' ) NOT NULL DEFAULT 'MISSING'"); - if (!tableHasColumn('callback', 'args')) - Database::exec("ALTER TABLE `callback` ADD `args` TEXT NOT NULL DEFAULT ''"); - if (!tableHasColumn('configtgz', 'status')) - Database::exec("ALTER TABLE `configtgz` ADD `status` ENUM( 'OK', 'OUTDATED', 'MISSING' ) NOT NULL DEFAULT 'MISSING'"); - return true; -} - -// ####################### -// ##### 2015-05-21 -// Add statistics table, for logging of session length and idle times -function update_9() -{ - Database::exec("CREATE TABLE IF NOT EXISTS `statistic` ( - `logid` int(10) unsigned NOT NULL AUTO_INCREMENT, - `dateline` int(10) unsigned NOT NULL, - `typeid` varchar(30) NOT NULL, - `clientip` varchar(40) NOT NULL, - `username` varchar(30) NOT NULL, - `data` varchar(255) NOT NULL, - PRIMARY KEY (`logid`), - KEY `dateline` (`dateline`), - KEY `logtypeid` (`typeid`,`dateline`), - KEY `clientip` (`clientip`,`dateline`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8"); - return true; -} - -// ####################### -// ##### 2015-12-21 -// Add machine uuid column to statistics table -function update_10() -{ - if (!tableHasColumn('statistic', 'machineuuid')) { - Database::exec('ALTER TABLE statistic' - . ' ADD COLUMN `machineuuid` varchar(36) CHARACTER SET ascii DEFAULT NULL AFTER clientip,' - . ' ADD INDEX `machineuuid` (`machineuuid`,`dateline`)'); - } - Database::exec("CREATE TABLE IF NOT EXISTS `machine` ( - `machineuuid` char(36) CHARACTER SET ascii NOT NULL, - `locationid` int(11) DEFAULT NULL, - `macaddr` char(17) CHARACTER SET ascii NOT NULL, - `clientip` varchar(45) CHARACTER SET ascii NOT NULL, - `firstseen` int(10) unsigned NOT NULL, - `lastseen` int(10) unsigned NOT NULL, - `logintime` int(10) unsigned NOT NULL, - `position` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, - `lastboot` int(10) unsigned NOT NULL, - `realcores` smallint(5) unsigned NOT NULL, - `mbram` int(10) unsigned NOT NULL, - `kvmstate` enum('UNKNOWN','UNSUPPORTED','DISABLED','ENABLED') NOT NULL, - `cpumodel` varchar(120) NOT NULL, - `systemmodel` varchar(120) NOT NULL DEFAULT '', - `id44mb` int(10) unsigned NOT NULL, - `badsectors` int(10) unsigned NOT NULL, - `data` mediumtext NOT NULL, - `hostname` varchar(200) NOT NULL DEFAULT '', - `notes` text, - PRIMARY KEY (`machineuuid`), - KEY `macaddr` (`macaddr`), - KEY `clientip` (`clientip`), - KEY `realcores` (`realcores`), - KEY `mbram` (`mbram`), - KEY `kvmstate` (`kvmstate`), - KEY `id44mb` (`id44mb`), - KEY `locationid` (`locationid`), - KEY `lastseen` (`lastseen`), - KEY `cpumodel` (`cpumodel`), - KEY `systemmodel` (`systemmodel`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8"); - return true; -} - -function update_11() -{ - if (tableHasColumn('machine', 'roomid')) { - Database::exec("ALTER TABLE `machine` CHANGE `roomid` `locationid` INT(11) DEFAULT NULL"); - } - Database::exec("CREATE TABLE IF NOT EXISTS `setting_location` ( - `locationid` int(11) NOT NULL, - `setting` varchar(28) NOT NULL, - `value` text NOT NULL, - `displayvalue` text NOT NULL, - PRIMARY KEY (`locationid`,`setting`), - KEY `setting` (`setting`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8"); - Database::exec("CREATE TABLE IF NOT EXISTS `location` ( - `locationid` int(11) NOT NULL AUTO_INCREMENT, - `parentlocationid` int(11) NOT NULL, - `locationname` varchar(100) NOT NULL, - PRIMARY KEY (`locationid`), - KEY `locationname` (`locationname`), - KEY `parentlocationid` (`parentlocationid`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - Database::exec("CREATE TABLE IF NOT EXISTS `subnet` ( - `subnetid` int(11) NOT NULL AUTO_INCREMENT, - `startaddr` decimal(39,0) unsigned NOT NULL, - `endaddr` decimal(39,0) unsigned NOT NULL, - `locationid` int(11) NOT NULL, - PRIMARY KEY (`subnetid`), - KEY `startaddr` (`startaddr`,`endaddr`), - KEY `locationid` (`locationid`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - return true; -} - -// TODO: Remove setting_distro, setting, cat_setting -// TODO: Add toggle column to setting_global -// TODO: Add pciid table
\ No newline at end of file diff --git a/inc/database.inc.php b/inc/database.inc.php index ee45f6c0..4a5821f4 100644 --- a/inc/database.inc.php +++ b/inc/database.inc.php @@ -8,19 +8,24 @@ class Database { /** - * * @var \PDO Database handle */ private static $dbh = false; + /* + * @var \PDOStatement[] + */ private static $statements = array(); + private static $returnErrors; + private static $lastError = false; /** * Connect to the DB if not already connected. */ - public static function init($returnSuccess = false) + public static function init($returnErrors = false) { if (self::$dbh !== false) return true; + self::$returnErrors = $returnErrors; try { if (CONFIG_SQL_FORCE_UTF8) { self::$dbh = new PDO(CONFIG_SQL_DSN, CONFIG_SQL_USER, CONFIG_SQL_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); @@ -28,7 +33,7 @@ class Database self::$dbh = new PDO(CONFIG_SQL_DSN, CONFIG_SQL_USER, CONFIG_SQL_PASS); } } catch (PDOException $e) { - if ($returnSuccess) + if (self::$returnErrors) return false; Util::traceError('Connecting to the local database failed: ' . $e->getMessage()); } @@ -77,6 +82,14 @@ class Database } /** + * @return string|bool return last error returned by query + */ + public static function lastError() + { + return self::$lastError; + } + + /** * Execute the given query and return the corresponding PDOStatement object * Note that this will re-use PDOStatements, so if you run the same * query again with different params, do not rely on the first PDOStatement @@ -94,15 +107,17 @@ class Database self::$statements[$query]->closeCursor(); } if (self::$statements[$query]->execute($args) === false) { - if ($ignoreError) + self::$lastError = implode("\n", self::$statements[$query]->errorInfo()); + if ($ignoreError || self::$returnErrors) return false; - Util::traceError("Database Error: \n" . implode("\n", self::$statements[$query]->errorInfo())); + Util::traceError("Database Error: \n" . self::$lastError); } return self::$statements[$query]; } catch (Exception $e) { - if ($ignoreError) + self::$lastError = '(' . $e->getCode() . ') ' . $e->getMessage(); + if ($ignoreError || self::$returnErrors) return false; - Util::traceError("Database Error: \n" . $e->getMessage()); + Util::traceError("Database Error: \n" . self::$lastError); } return false; } diff --git a/inc/defaultdata.inc.php b/inc/defaultdata.inc.php deleted file mode 100644 index 2d993e72..00000000 --- a/inc/defaultdata.inc.php +++ /dev/null @@ -1,204 +0,0 @@ -<?php - -/** - * This class is supposed to fill the database with default entries (where required). - * The insertion should be non-destructive, so if an entry already exists (and - * possibly changed), it should be skipped. - */ -class DefaultData -{ - - public static function populate() - { - self::addSettingCategories(); - self::addSettings(); - } - - /** - * Categories for basic system config / config variables - */ - private static function addSettingCategories() - { - $cats = array( - 1 => 30, // Inactivity/Shutdown - 2 => 50, // Internet access - 3 => 100, // Timesync - 4 => 10, // System config - //5 => 15, // Public Shared folder - 6 => 20000, // Unassigned/no category - 7 => 20, - ); - foreach ($cats as $cat => $sort) { - Database::exec("INSERT IGNORE INTO cat_setting (catid, sortval) VALUES (:catid, :sortval)", array( - 'catid' => $cat, - 'sortval' => $sort - )); - } - } - - /** - * Settings for basic system config - */ - private static function addSettings() - { - $data = array( - array( - 'setting' => 'SLX_ADDONS', - 'catid' => '6', - 'defaultvalue' => 'vmware', - 'permissions' => '2', - 'validator' => '' - ), - array( - 'setting' => 'SLX_BIOS_CLOCK', - 'catid' => '3', - 'defaultvalue' => 'off', - 'permissions' => '2', - 'validator' => 'list:off|local|utc' - ), - array( - 'setting' => 'SLX_LOGOUT_TIMEOUT', - 'catid' => '1', - 'defaultvalue' => '2700', - 'permissions' => '2', - 'validator' => 'regex:/^\d*$/' - ), - array( - 'setting' => 'SLX_NET_DOMAIN', - 'catid' => '2', - 'defaultvalue' => '', - 'permissions' => '2', - 'validator' => '' - ), - array( - 'setting' => 'SLX_NTP_SERVER', - 'catid' => '3', - 'defaultvalue' => '0.de.pool.ntp.org 1.de.pool.ntp.org', - 'permissions' => '2', - 'validator' => '' - ), - array( - 'setting' => 'SLX_PROXY_BLACKLIST', - 'catid' => '2', - 'defaultvalue' => '', - 'permissions' => '2', - 'validator' => '' - ), - array( - 'setting' => 'SLX_PROXY_IP', - 'catid' => '2', - 'defaultvalue' => '', - 'permissions' => '2', - 'validator' => '' - ), - array( - 'setting' => 'SLX_PROXY_MODE', - 'catid' => '2', - 'defaultvalue' => 'off', - 'permissions' => '2', - 'validator' => 'list:off|on|auto' - ), - array( - 'setting' => 'SLX_PROXY_PORT', - 'catid' => '2', - 'defaultvalue' => '', - 'permissions' => '2', - 'validator' => 'regex:/^\d*$/' - ), - array( - 'setting' => 'SLX_PROXY_TYPE', - 'catid' => '2', - 'defaultvalue' => 'socks5', - 'permissions' => '2', - 'validator' => 'list:socks4|socks5|http-connect|http-relay' - ), - array( - 'setting' => 'SLX_REMOTE_LOG_SESSIONS', - 'catid' => '6', - 'defaultvalue' => 'anonymous', - 'permissions' => '2', - 'validator' => 'list:yes|anonymous|no' - ), - array( - 'setting' => 'SLX_ROOT_PASS', - 'catid' => '4', - 'defaultvalue' => '', - 'permissions' => '2', - 'validator' => 'function:linuxPassword' - ), - array( - 'setting' => 'SLX_DEMO_PASS', - 'catid' => '4', - 'defaultvalue' => '', - 'permissions' => '2', - 'validator' => 'function:linuxPassword' - ), - array( - 'setting' => 'SLX_BWIDM_AUTH', - 'catid' => '4', - 'defaultvalue' => 'no', - 'permissions' => '2', - 'validator' => 'list:yes|no' - ), - array( - 'setting' => 'SLX_SHUTDOWN_SCHEDULE', - 'catid' => '1', - 'defaultvalue' => '22:10 00:00', - 'permissions' => '2', - 'validator' => 'regex:/^(\s*\d{1,2}:\d{1,2})*\s*$/' - ), - array( - 'setting' => 'SLX_SHUTDOWN_TIMEOUT', - 'catid' => '1', - 'defaultvalue' => '1200', - 'permissions' => '2', - 'validator' => 'regex:/^\d*$/' - ), - /* - array( - 'setting' => 'SLX_COMMON_SHARE_PATH', - 'catid' => '5', - 'defaultvalue' => '', - 'permissions' => '2', - 'validator' => 'function:networkShare' - ), - array( - 'setting' => 'SLX_COMMON_SHARE_AUTH', - 'catid' => '5', - 'defaultvalue' => 'guest', - 'permissions' => '2', - 'validator' => 'list:guest|user' - ), - */ - array( - 'setting' => 'SLX_BENCHMARK_VM', - 'catid' => '6', - 'defaultvalue' => '', - 'permissions' => '2', - 'validator' => '' - ), - array( - 'setting' => 'SLX_VMCHOOSER_TAB', - 'catid' => '7', - 'defaultvalue' => 'AUTO', - 'permissions' => '2', - 'validator' => 'list:0|1|2|AUTO' - ), - array( - 'setting' => 'SLX_VMCHOOSER_TEMPLATES', - 'catid' => '7', - 'defaultvalue' => 'IGNORE', - 'permissions' => '2', - 'validator' => 'list:IGNORE|BUMP' - ), - array( - 'setting' => 'SLX_VMCHOOSER_FORLOCATION', - 'catid' => '7', - 'defaultvalue' => 'BUMP', - 'permissions' => '2', - 'validator' => 'list:IGNORE|BUMP|EXCLUSIVE' - ), - ); - } - -} diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php index f5886bda..6ae8fb9b 100644 --- a/inc/dictionary.inc.php +++ b/inc/dictionary.inc.php @@ -79,6 +79,7 @@ class Dictionary public static function translateFile($path, $tag) { + // TODO: Handle case where we have no active module/no page class return self::translateFileModule(Page::getModule()->getIdentifier(), $path, $tag); } diff --git a/install.php b/install.php index e579dd52..f3469abc 100644 --- a/install.php +++ b/install.php @@ -33,7 +33,7 @@ function finalResponse($status, $message = '') echo json_encode(array('status' => $status, 'message' => $message)); } else { echo 'STATUS=', $status, "\n"; - echo 'MESSAGE=', $message; + echo 'MESSAGE=', str_replace("\n", " -- ", $message); } exit; } @@ -77,13 +77,28 @@ function tableDropColumn($table, $column) function tableExists($table) { $res = Database::simpleQuery("SHOW TABLES", array(), true); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - if ($row['Tables_in_openslx'] === $table) + while ($row = $res->fetch(PDO::FETCH_NUM)) { + if ($row[0] === $table) return true; } return false; } +function tableCreate($table, $structure, $fatalOnError = true) +{ + if (tableExists($table)) { + return UPDATE_NOOP; + } + $ret = Database::exec("CREATE TABLE IF NOT EXISTS `{$table}` ( {$structure} ) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + if ($ret !== false) { + return UPDATE_DONE; + } + if ($fatalOnError) { + finalResponse(UPDATE_FAILED, 'DB-Error: ' . Database::lastError()); + } + return UPDATE_FAILED; +} + /* * Rest of install script.... */ @@ -230,7 +245,7 @@ HERE; echo <<<HERE </table> <br><br> - <button onclick="slxRunInstall()">Install/Upgrade</button> + <button onclick="slxRunInstall(this)">Install/Upgrade</button> <script src="script/jquery.js"></script> <script src="script/install.js"></script> </body> diff --git a/modules-available/baseconfig/install.inc.php b/modules-available/baseconfig/install.inc.php new file mode 100644 index 00000000..8f1cb1e7 --- /dev/null +++ b/modules-available/baseconfig/install.inc.php @@ -0,0 +1,58 @@ +<?php + +$res = array(); + +$res[] = tableCreate('setting_global', " + `setting` varchar(28) NOT NULL, + `value` text NOT NULL, + `displayvalue` text NOT NULL, + `enabled` tinyint(1) UNSIGNED NOT NULL DEFAULT '1' + PRIMARY KEY (`setting`) +"); + +// Update path + +// Add toggle field + +if (!tableHasColumn('setting_global', 'enabled')) { + if (tableHasColumn('setting_global', 'toggle')) { + $ret = Database::exec("ALTER TABLE `setting_global` CHANGE `toggle` `enabled` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1'"); + } else { + $ret = Database::exec("ALTER TABLE `setting_global` ADD COLUMN `enabled` tinyint(1) UNSIGNED NOT NULL DEFAULT '1'"); + } + if ($ret === false) { + finalResponse(UPDATE_FAILED, 'Adding enabled to setting_global failed: ' . Database::lastError()); + } +} + +// Add displayvalue field + +if (!tableHasColumn('setting_global', 'displayvalue')) { + Database::exec("ALTER TABLE `setting_global` ADD `displayvalue` TEXT NOT NULL"); + Database::exec("UPDATE `setting_global` SET `displayvalue` = `value`"); + $res[] = UPDATE_DONE; +} + +// Delete old tables + +/* +Keep disabled for a while, in case some customer made unexpected important changes etc... + +if (tableExists('setting')) { + Database::exec('DROP TABLE setting'); +} +if (tableExists('setting_distro')) { + Database::exec('DROP TABLE setting_distro'); +} +if (tableExists('cat_setting')) { + Database::exec('DROP TABLE cat_setting'); +} +*/ + +// Create response for browser + +if (in_array(UPDATE_DONE, $res)) { + finalResponse(UPDATE_DONE, 'Tables created successfully'); +} + +finalResponse(UPDATE_NOOP, 'Everything already up to date'); diff --git a/modules-available/eventlog/install.inc.php b/modules-available/eventlog/install.inc.php new file mode 100644 index 00000000..e5fd32f6 --- /dev/null +++ b/modules-available/eventlog/install.inc.php @@ -0,0 +1,31 @@ +<?php + +$res = array(); + +$res[] = tableCreate('eventlog', " +`logid` int(10) unsigned NOT NULL AUTO_INCREMENT, +`dateline` int(10) unsigned NOT NULL, +`logtypeid` varchar(30) NOT NULL, +`description` varchar(255) NOT NULL, +`extra` TEXT NOT NULL, +PRIMARY KEY (`logid`), +KEY `dateline` (`dateline`), +KEY `logtypeid` (`logtypeid`,`dateline`) +"); + +// Update path + +if (!tableHasColumn('eventlog', 'extra')) { + if (Database::exec("ALTER TABLE `eventlog` ADD `extra` TEXT NOT NULL") === false) { + finalResponse(UPDATE_FAILED, 'Could not add extra to eventlog: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} + +// Create response for browser + +if (in_array(UPDATE_DONE, $res)) { + finalResponse(UPDATE_DONE, 'Tables created successfully'); +} + +finalResponse(UPDATE_NOOP, 'Everything already up to date'); diff --git a/modules-available/locations/install.inc.php b/modules-available/locations/install.inc.php new file mode 100644 index 00000000..f833568d --- /dev/null +++ b/modules-available/locations/install.inc.php @@ -0,0 +1,39 @@ +<?php + +$res = array(); + +$res[] = tableCreate('setting_location', ' + `locationid` INT(11) NOT NULL, + `setting` VARCHAR(28) NOT NULL, + `value` TEXT NOT NULL, + `displayvalue` TEXT NOT NULL, + PRIMARY KEY (`locationid`,`setting`), + KEY `setting` (`setting`) +'); + +$res[] = tableCreate('location', ' + `locationid` INT(11) NOT NULL AUTO_INCREMENT, + `parentlocationid` INT(11) NOT NULL, + `locationname` VARCHAR(100) NOT NULL, + PRIMARY KEY (`locationid`), + KEY `locationname` (`locationname`), + KEY `parentlocationid` (`parentlocationid`) +'); + +$res[] = tableCreate('subnet', ' + `subnetid` INT(11) NOT NULL AUTO_INCREMENT, + `startaddr` DECIMAL(39,0) UNSIGNED NOT NULL, + `endaddr` DECIMAL(39,0) UNSIGNED NOT NULL, + `locationid` INT(11) NOT NULL, + PRIMARY KEY (`subnetid`), + KEY `startaddr` (`startaddr`,`endaddr`), + KEY `locationid` (`locationid`) +'); + +// Create response for browser + +if (in_array(UPDATE_DONE, $res)) { + finalResponse(UPDATE_DONE, 'Tables created successfully'); +} + +finalResponse(UPDATE_NOOP, 'Everything already up to date'); diff --git a/modules-available/main/install.inc.php b/modules-available/main/install.inc.php new file mode 100644 index 00000000..4c9d4baa --- /dev/null +++ b/modules-available/main/install.inc.php @@ -0,0 +1,73 @@ +<?php + +$res = array(); + +$res[] = tableCreate('callback', " + `taskid` varchar(40) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + `dateline` int(10) unsigned NOT NULL, + `cbfunction` varchar(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + `args` text NOT NULL, + PRIMARY KEY (`taskid`,`cbfunction`), + KEY `dateline` (`dateline`) +"); + +$res[] = tableCreate('permission', " + `mask` int(10) unsigned NOT NULL, + `identifier` varchar(32) NOT NULL, + PRIMARY KEY (`mask`), + UNIQUE KEY `identifier` (`identifier`) +"); + +$res[] = tableCreate('property', " + `name` varchar(50) NOT NULL, + `dateline` int(10) unsigned NOT NULL DEFAULT '0', + `value` text NOT NULL, + PRIMARY KEY (`name`), + KEY `dateline` (`dateline`) +"); + +$res[] = tableCreate('user', " + `userid` int(10) unsigned NOT NULL AUTO_INCREMENT, + `login` varchar(100) NOT NULL, + `passwd` varchar(150) NOT NULL, + `fullname` varchar(100) DEFAULT NULL, + `phone` varchar(100) DEFAULT NULL, + `email` varchar(100) DEFAULT NULL, + `permissions` int(10) unsigned NOT NULL, + `lasteventid` int(10) unsigned NOT NULL DEFAULT '0', + PRIMARY KEY (`userid`), + UNIQUE KEY `login` (`login`) +"); + +// Update path + +// ####################### +// ##### 2014-05-28 +// Add dateline field to property table +if (!tableHasColumn('property', 'dateline')) { + Database::exec("ALTER TABLE `property` ADD `dateline` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `name` , ADD INDEX ( `dateline` )"); +} + +// ####################### +// ##### 2014-08-18 +// Remove description column from permission table +tableDropColumn('permission', 'description'); +// Add details column to eventlog table +if (!tableHasColumn('user', 'lasteventid')) { + Database::exec("ALTER TABLE `user` ADD `lasteventid` INT(10) UNSIGNED NOT NULL DEFAULT '0'"); +} + +// ####################### +// ##### 2015-01-16 +// Extend config module db table, add argument feature to callbacks +if (!tableHasColumn('callback', 'args')) { + Database::exec("ALTER TABLE `callback` ADD `args` TEXT NOT NULL DEFAULT ''"); +} + +// Create response for browser + +if (in_array(UPDATE_DONE, $res)) { + finalResponse(UPDATE_DONE, 'Tables created successfully'); +} + +finalResponse(UPDATE_NOOP, 'Everything already up to date'); diff --git a/modules-available/news/install.inc.php b/modules-available/news/install.inc.php new file mode 100644 index 00000000..69db5aa9 --- /dev/null +++ b/modules-available/news/install.inc.php @@ -0,0 +1,24 @@ +<?php + +$res = array(); + +$res[] = tableCreate('news', " + `newsid` int(10) unsigned NOT NULL AUTO_INCREMENT, + `dateline` int(10) unsigned NOT NULL, + `title` varchar(200) DEFAULT NULL, + `content` text, + PRIMARY KEY (`newsid`), + KEY `dateline` (`dateline`) +"); + +// Update path + +// *crickets* + +// Create response for browser + +if (in_array(UPDATE_DONE, $res)) { + finalResponse(UPDATE_DONE, 'Tables created successfully'); +} + +finalResponse(UPDATE_NOOP, 'Everything already up to date'); diff --git a/modules-available/statistics/install.inc.php b/modules-available/statistics/install.inc.php new file mode 100644 index 00000000..f5203d7a --- /dev/null +++ b/modules-available/statistics/install.inc.php @@ -0,0 +1,97 @@ +<?php + +$res = array(); + +// The main statistic table used for log entries + +$res[] = tableCreate('statistic', " + `logid` int(10) unsigned NOT NULL AUTO_INCREMENT, + `dateline` int(10) unsigned NOT NULL, + `typeid` varchar(30) NOT NULL, + `clientip` varchar(40) NOT NULL, + `machineuuid` varchar(36) CHARACTER SET ascii DEFAULT NULL, + `username` varchar(30) NOT NULL, + `data` varchar(255) NOT NULL, + PRIMARY KEY (`logid`), + KEY `dateline` (`dateline`), + KEY `logtypeid` (`typeid`,`dateline`), + KEY `clientip` (`clientip`,`dateline`), + KEY `machineuuid` (`machineuuid`,`dateline`) +"); + +// Main table containing all known clients + +$res[] = tableCreate('machine', " + `machineuuid` char(36) CHARACTER SET ascii NOT NULL, + `locationid` int(11) DEFAULT NULL, + `macaddr` char(17) CHARACTER SET ascii NOT NULL, + `clientip` varchar(45) CHARACTER SET ascii NOT NULL, + `firstseen` int(10) unsigned NOT NULL, + `lastseen` int(10) unsigned NOT NULL, + `logintime` int(10) unsigned NOT NULL, + `position` varchar(40) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, + `lastboot` int(10) unsigned NOT NULL, + `realcores` smallint(5) unsigned NOT NULL, + `mbram` int(10) unsigned NOT NULL, + `kvmstate` enum('UNKNOWN','UNSUPPORTED','DISABLED','ENABLED') NOT NULL, + `cpumodel` varchar(120) NOT NULL, + `systemmodel` varchar(120) NOT NULL DEFAULT '', + `id44mb` int(10) unsigned NOT NULL, + `badsectors` int(10) unsigned NOT NULL, + `data` mediumtext NOT NULL, + `hostname` varchar(200) NOT NULL DEFAULT '', + `notes` text, + PRIMARY KEY (`machineuuid`), + KEY `macaddr` (`macaddr`), + KEY `clientip` (`clientip`), + KEY `realcores` (`realcores`), + KEY `mbram` (`mbram`), + KEY `kvmstate` (`kvmstate`), + KEY `id44mb` (`id44mb`), + KEY `locationid` (`locationid`), + KEY `lastseen` (`lastseen`), + KEY `cpumodel` (`cpumodel`), + KEY `systemmodel` (`systemmodel`) +"); + +// PCI-ID cache + +$res[] = tableCreate('pciid', " + `category` enum('CLASS','VENDOR','DEVICE') NOT NULL, + `id` varchar(10) CHARACTER SET ascii NOT NULL, + `value` varchar(200) NOT NULL, + `dateline` int(10) unsigned NOT NULL, + PRIMARY KEY (`category`,`id`) +"); + +// +// This was added/changed later -- keep update path +// + +// 2015-12-21: Add machine uuid column to statistics table +if (!tableHasColumn('statistic', 'machineuuid')) { + $ret = Database::exec('ALTER TABLE statistic' + . ' ADD COLUMN `machineuuid` varchar(36) CHARACTER SET ascii DEFAULT NULL AFTER clientip,' + . ' ADD INDEX `machineuuid` (`machineuuid`,`dateline`)'); + if ($ret === false) { + finalResponse(UPDATE_FAILED, 'Adding machineuuid to statistic failed: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} + +if (tableHasColumn('machine', 'roomid')) { + $ret = Database::exec("ALTER TABLE `machine` CHANGE `roomid` `locationid` INT(11) DEFAULT NULL") !== false; + $ret = Database::exec("ALTER TABLE `machine` DROP `roomid`") !== false || $ret; + if ($ret === false) { + finalResponse(UPDATE_FAILED, 'Renaming roomid to locationid in statistic failed: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} + +// Create response + +if (in_array(UPDATE_DONE, $res)) { + finalResponse(UPDATE_DONE, 'Tables created successfully'); +} + +finalResponse(UPDATE_NOOP, 'Everything already up to date'); diff --git a/modules-available/sysconfig/inc/configmodule/adauth.inc.php b/modules-available/sysconfig/inc/configmodule/adauth.inc.php index a03be43c..180ac717 100644 --- a/modules-available/sysconfig/inc/configmodule/adauth.inc.php +++ b/modules-available/sysconfig/inc/configmodule/adauth.inc.php @@ -2,9 +2,9 @@ ConfigModule::registerModule( ConfigModule_AdAuth::MODID, // ID - Dictionary::translateFile('config-module', 'adAuth_title'), // Title - Dictionary::translateFile('config-module', 'adAuth_description'), // Description - Dictionary::translateFile('config-module', 'group_authentication'), // Group + Dictionary::translateFileModule('sysconfig', 'config-module', 'adAuth_title'), // Title + Dictionary::translateFileModule('sysconfig', 'config-module', 'adAuth_description'), // Description + Dictionary::translateFileModule('sysconfig', 'config-module', 'group_authentication'), // Group true // Only one per config? ); diff --git a/modules-available/sysconfig/inc/configmodule/branding.inc.php b/modules-available/sysconfig/inc/configmodule/branding.inc.php index 479b406c..4a9718d6 100644 --- a/modules-available/sysconfig/inc/configmodule/branding.inc.php +++ b/modules-available/sysconfig/inc/configmodule/branding.inc.php @@ -2,9 +2,9 @@ ConfigModule::registerModule( ConfigModule_Branding::MODID, // ID - Dictionary::translateFile('config-module', 'branding_title'), // Title - Dictionary::translateFile('config-module', 'branding_description'), // Description - Dictionary::translateFile('config-module', 'group_branding'), // Group + Dictionary::translateFileModule('sysconfig', 'config-module', 'branding_title'), // Title + Dictionary::translateFileModule('sysconfig', 'config-module', 'branding_description'), // Description + Dictionary::translateFileModule('sysconfig', 'config-module', 'group_branding'), // Group true // Only one per config? ); diff --git a/modules-available/sysconfig/inc/configmodule/customodule.inc.php b/modules-available/sysconfig/inc/configmodule/customodule.inc.php index 09b621cc..8d1b6bf0 100644 --- a/modules-available/sysconfig/inc/configmodule/customodule.inc.php +++ b/modules-available/sysconfig/inc/configmodule/customodule.inc.php @@ -2,9 +2,9 @@ ConfigModule::registerModule( ConfigModule_CustomModule::MODID, // ID - Dictionary::translateFile('config-module', 'custom_title'), // Title - Dictionary::translateFile('config-module', 'custom_description'), // Description - Dictionary::translateFile('config-module', 'group_generic'), // Group + Dictionary::translateFileModule('sysconfig', 'config-module', 'custom_title'), // Title + Dictionary::translateFileModule('sysconfig', 'config-module', 'custom_description'), // Description + Dictionary::translateFileModule('sysconfig', 'config-module', 'group_generic'), // Group false, // Only one per config? 100 // Sort order ); diff --git a/modules-available/sysconfig/inc/configmodule/ldapauth.inc.php b/modules-available/sysconfig/inc/configmodule/ldapauth.inc.php index 0f386033..ed1a47c3 100644 --- a/modules-available/sysconfig/inc/configmodule/ldapauth.inc.php +++ b/modules-available/sysconfig/inc/configmodule/ldapauth.inc.php @@ -2,9 +2,9 @@ ConfigModule::registerModule( ConfigModule_LdapAuth::MODID, // ID - Dictionary::translateFile('config-module', 'ldapAuth_title'), // Title - Dictionary::translateFile('config-module', 'ldapAuth_description'), // Description - Dictionary::translateFile('config-module', 'group_authentication'), // Group + Dictionary::translateFileModule('sysconfig', 'config-module', 'ldapAuth_title'), // Title + Dictionary::translateFileModule('sysconfig', 'config-module', 'ldapAuth_description'), // Description + Dictionary::translateFileModule('sysconfig', 'config-module', 'group_authentication'), // Group true // Only one per config? ); diff --git a/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php b/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php index b1d58153..8814b86b 100644 --- a/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php +++ b/modules-available/sysconfig/inc/configmodule/sshconfig.inc.php @@ -2,9 +2,9 @@ ConfigModule::registerModule( ConfigModule_SshConfig::MODID, // ID - Dictionary::translateFile('config-module', 'sshconfig_title'), // Title - Dictionary::translateFile('config-module', 'sshconfig_description'), // Description - Dictionary::translateFile('config-module', 'group_sshconfig'), // Group + Dictionary::translateFileModule('sysconfig', 'config-module', 'sshconfig_title'), // Title + Dictionary::translateFileModule('sysconfig', 'config-module', 'sshconfig_description'), // Description + Dictionary::translateFileModule('sysconfig', 'config-module', 'group_sshconfig'), // Group true // Only one per config? ); diff --git a/modules-available/sysconfig/install.inc.php b/modules-available/sysconfig/install.inc.php new file mode 100644 index 00000000..0b7bbc1b --- /dev/null +++ b/modules-available/sysconfig/install.inc.php @@ -0,0 +1,90 @@ +<?php + +$res = array(); + +$res[] = tableCreate('configtgz', " + `configid` int(10) unsigned NOT NULL AUTO_INCREMENT, + `title` varchar(200) NOT NULL, + `filepath` varchar(255) NOT NULL, + `status` enum('OK','OUTDATED','MISSING') NOT NULL DEFAULT 'MISSING', + PRIMARY KEY (`configid`) +"); + +$res[] = tableCreate('configtgz_module', " + `moduleid` int(10) unsigned NOT NULL AUTO_INCREMENT, + `title` varchar(200) NOT NULL, + `moduletype` varchar(16) NOT NULL, + `filepath` varchar(250) NOT NULL, + `contents` text NOT NULL, + `version` int(10) unsigned NOT NULL DEFAULT '0', + `status` enum('OK','MISSING','OUTDATED') NOT NULL DEFAULT 'MISSING', + PRIMARY KEY (`moduleid`), + KEY `title` (`title`), + KEY `moduletype` (`moduletype`,`title`) +"); + +$res[] = tableCreate('configtgz_x_module', " + `configid` int(10) unsigned NOT NULL, + `moduleid` int(10) unsigned NOT NULL, + PRIMARY KEY (`configid`,`moduleid`), + KEY `moduleid` (`moduleid`) +"); + + +// Constraints +if (in_array(UPDATE_DONE, $res)) { + Database::exec("ALTER TABLE `configtgz_x_module` + ADD CONSTRAINT `configtgz_x_module_ibfk_1` FOREIGN KEY (`configid`) REFERENCES `configtgz` (`configid`) ON DELETE CASCADE, + ADD CONSTRAINT `configtgz_x_module_ibfk_2` FOREIGN KEY (`moduleid`) REFERENCES `configtgz_module` (`moduleid`)"); +} + +// Update path + +// ##### 2014-12-12 +// Rename config modules +Database::exec("UPDATE configtgz_module SET moduletype = 'Branding' WHERE moduletype = 'BRANDING'"); +Database::exec("UPDATE configtgz_module SET moduletype = 'AdAuth' WHERE moduletype = 'AD_AUTH'"); +Database::exec("UPDATE configtgz_module SET moduletype = 'CustomModule' WHERE moduletype = 'custom'"); + +// ####################### +// ##### 2015-01-16 +// Extend config module db tables +tableDropColumn('configtgz_module', 'haschanged'); +if (!tableHasColumn('configtgz_module', 'version')) { + if (Database::exec("ALTER TABLE `configtgz_module` ADD `version` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'") === false) { + finalResponse(UPDATE_FAILED, 'Could not add version to configtgz_module: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} +if (!tableHasColumn('configtgz_module', 'status')) { + if (Database::exec("ALTER TABLE `configtgz_module` ADD `status` ENUM( 'OK', 'MISSING', 'OUTDATED' ) NOT NULL DEFAULT 'MISSING'") === false) { + finalResponse(UPDATE_FAILED, 'Could not add status to configtgz_module: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} +if (!tableHasColumn('configtgz', 'status')) { + if (Database::exec("ALTER TABLE `configtgz` ADD `status` ENUM( 'OK', 'OUTDATED', 'MISSING' ) NOT NULL DEFAULT 'MISSING'") === false) { + finalResponse(UPDATE_FAILED, 'Could not add status to configtgz: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} + +// ----- rebuild AD configs ------ +// TEMPORARY HACK; Rebuild AD configs.. move somewhere else +Module::isAvailable('sysconfig'); +$list = array_merge(ConfigModule::getAll('AdAuth'), ConfigModule::getAll('LdapAuth')); +if ($list === false) { + EventLog::warning('Could not regenerate AD/LDAP configs - please do so manually'); +} else { + foreach ($list as $ad) { + $ad->generate(false); + } +} + +// Create response for browser + +if (in_array(UPDATE_DONE, $res)) { + finalResponse(UPDATE_DONE, 'Tables created successfully'); +} + +finalResponse(UPDATE_NOOP, 'Everything already up to date'); diff --git a/modules-available/syslog/install.inc.php b/modules-available/syslog/install.inc.php new file mode 100644 index 00000000..539f2449 --- /dev/null +++ b/modules-available/syslog/install.inc.php @@ -0,0 +1,38 @@ +<?php + +$res = array(); + +$res[] = tableCreate('clientlog', " + `logid` int(10) unsigned NOT NULL AUTO_INCREMENT, + `dateline` int(10) unsigned NOT NULL, + `logtypeid` varchar(30) NOT NULL, + `clientip` varchar(40) NOT NULL, + `machineuuid` varchar(36) CHARACTER SET ascii DEFAULT NULL, + `description` varchar(255) NOT NULL, + `extra` text NOT NULL, + PRIMARY KEY (`logid`), + KEY `dateline` (`dateline`), + KEY `logtypeid` (`logtypeid`,`dateline`), + KEY `clientip` (`clientip`,`dateline`), + KEY `machineuuid` (`machineuuid`,`dateline`) +"); + +// Update path + +if (!tableHasColumn('clientlog', 'machineuuid')) { + $ret = Database::exec('ALTER TABLE clientlog' + . ' ADD COLUMN `machineuuid` varchar(36) CHARACTER SET ascii DEFAULT NULL AFTER clientip,' + . ' ADD INDEX `machineuuid` (`machineuuid`,`dateline`)'); + if ($ret === false) { + finalResponse(UPDATE_FAILED, 'Adding machineuuid to clientlog failed: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} + +// Create response for browser + +if (in_array(UPDATE_DONE, $res)) { + finalResponse(UPDATE_DONE, 'Tables created successfully'); +} + +finalResponse(UPDATE_NOOP, 'Everything already up to date'); diff --git a/script/install.js b/script/install.js index 2dec46d4..a85f869c 100644 --- a/script/install.js +++ b/script/install.js @@ -2,10 +2,12 @@ var onceOnlyGoddammit = false; var slxModules = {}; var slxTries = {}; var slxCurrent = false; +var slxTimer = false; -function slxRunInstall() { +function slxRunInstall(btn) { if (onceOnlyGoddammit) return; + $(btn).prop('disabled', true); onceOnlyGoddammit = true; var first = false; list = $('.id-col').each(function () { @@ -38,9 +40,11 @@ function slxRun(moduleName) { return; slxModules[moduleName] = 'WORKING'; dest.text('Working.....'); + slxCancelTimer(); slxCurrent = moduleName; $.post('install.php', {module: moduleName}, makeCallback(slxDone, moduleName), 'json') .always(makeCallback(slxTrigger, moduleName)); + slxTimer = window.setTimeout(slxWatchdog, 5000); } } @@ -56,20 +60,24 @@ var slxDone = function (elem, moduleName, jsonReply) { if (jsonReply.message) { status = status + ' (' + jsonReply.message + ')'; } - console.log('D'); - console.log(elem); slxModules[moduleName] = jsonReply.status; $('#mod-' + moduleName).text(status); - if (jsonReply.status === 'UPDATE_NOOP' || jsonReply.status === 'UPDATE_DONE') { + if (jsonReply.status === 'UPDATE_DONE') { $('#mod-' + moduleName).css('color', '#0c0'); } - console.log('E'); + if (jsonReply.status === 'UPDATE_FAILED') { + $('#mod-' + moduleName).css('color', '#c00'); + } + if (jsonReply.status === 'UPDATE_RETRY') { + $('#mod-' + moduleName).css('color', '#c50'); + } } var slxTrigger = function (elem, moduleName) { + //alert('always: ' + moduleName + ', status: ' + slxModules[moduleName] + ', current: ' + slxCurrent); if (slxModules[moduleName] === 'WORKING') { slxModules[moduleName] = 'UPDATE_FAILED'; - $(elem).text('UPDATE_FAILED (No response from server)'); + $('#mod-' + moduleName).text('UPDATE_FAILED (No response from server)'); } if (slxCurrent === moduleName) { slxCurrent = false; @@ -103,6 +111,21 @@ function slxRunNext(lastModule) { if (next !== false) { slxRun(next); } else { + slxCancelTimer(); alert('Done.'); } +} + +function slxCancelTimer() +{ + if (slxTimer !== false) { + window.clearTimeout(slxTimer); + slxTimer = false; + } +} + +var slxWatchdog = function() +{ + slxTimer = false; + slxRunNext(slxCurrent); }
\ No newline at end of file |