diff options
Diffstat (limited to 'modules-available/sysconfig/install.inc.php')
-rw-r--r-- | modules-available/sysconfig/install.inc.php | 71 |
1 files changed, 62 insertions, 9 deletions
diff --git a/modules-available/sysconfig/install.inc.php b/modules-available/sysconfig/install.inc.php index 9322578e..53882882 100644 --- a/modules-available/sysconfig/install.inc.php +++ b/modules-available/sysconfig/install.inc.php @@ -7,6 +7,7 @@ $update[] = tableCreate('configtgz', " `title` varchar(200) NOT NULL, `filepath` varchar(255) NOT NULL, `status` enum('OK','OUTDATED','MISSING') NOT NULL DEFAULT 'MISSING', + `warnings` TEXT NULL DEFAULT NULL, `dateline` int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`configid`) "); @@ -16,7 +17,7 @@ $update[] = tableCreate('configtgz_module', " `title` varchar(200) NOT NULL, `moduletype` varchar(16) NOT NULL, `filepath` varchar(250) NOT NULL, - `contents` text NOT NULL, + `contents` longblob NOT NULL, `version` int(10) unsigned NOT NULL DEFAULT '0', `status` enum('OK','MISSING','OUTDATED') NOT NULL DEFAULT 'MISSING', `dateline` int(10) unsigned NOT NULL DEFAULT '0', @@ -86,7 +87,7 @@ if (!tableHasColumn('configtgz_module', 'dateline')) { $update[] = UPDATE_DONE; // Infer from module's filemtime $res = Database::simpleQuery('SELECT moduleid, filepath FROM configtgz_module'); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { Database::exec('UPDATE configtgz_module SET dateline = :mtime WHERE moduleid = :moduleid', ['moduleid' => $row['moduleid'], 'mtime' => filemtime($row['filepath'])]); } @@ -101,25 +102,77 @@ if (!tableHasColumn('configtgz', 'dateline')) { INNER JOIN configtgz_x_module cxm USING (configid) INNER JOIN configtgz_module m USING (moduleid) GROUP BY configid'); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { Database::exec('UPDATE configtgz SET dateline = :mtime WHERE configid = :configid', ['configid' => $row['configid'], 'mtime' => $row['dateline']]); } } +// 2020-01-16: Change contents column type +Database::exec("ALTER TABLE `configtgz_module` CHANGE `contents` `contents` LONGBLOB NOT NULL"); + +// 2020-11-02: Add warnings column +if (!tableHasColumn('configtgz', 'warnings')) { + if (Database::exec("ALTER TABLE `configtgz` ADD `warnings` TEXT NULL DEFAULT NULL") === false) { + finalResponse(UPDATE_FAILED, 'Could not add warnings to configtgz: ' . Database::lastError()); + } + $update[] = UPDATE_DONE; +} + // ----- rebuild configs ------ -// TEMPORARY HACK; Rebuild configs.. move somewhere else? +// PERMANENT HACK; Rebuild configs.. move somewhere else? Module::isAvailable('sysconfig'); $list = ConfigModule::getAll(); -if ($list === false) { - EventLog::warning('Could not regenerate AD/LDAP configs - please do so manually'); +$parentTask = null; +$configList = []; +if ($list === null) { + EventLog::warning('Could not regenerate configs - please do so manually'); } else { - foreach ($list as $ad) { - if ($ad->needRebuild()) { - $ad->generate(false); + foreach ($list as $confMod) { + if ($confMod->moduleType() === 'SshConfig') { + // 2020-11-12: Split SshConfig into SshConfig and SshKey + $pubkey = $confMod->getData('publicKey'); + if (!empty($pubkey)) { + error_log('Legacy module with pubkey ' . $confMod->id()); + $key = ConfigModule::getInstanceOrNull('SshKey'); + if ($key !== null) { + $key->setData('publicKey', $pubkey); + if ($key->insert($confMod->title())) { + // Insert worked, remove key from old module, add this module to the same configs + $task = $key->generate(false, $parentTask); + if ($task !== false) { + $parentTask = $task; + } + error_log('Inserted new module with id ' . $key->id()); + $confMod->setData('publicKey', false); + $confMod->update(); + $configs = ConfigTgz::getAllForModule($confMod->id()); + foreach ($configs as $config) { + // Add newly created key-only module to all configs + $new = array_merge($config->getModuleIds(), [$key->id()]); + error_log(implode(',', $config->getModuleIds()) . ' -> ' . implode(',', $new)); + $config->update('', $new); + $configList[] = $config; + } + } + } + } + } + if ($confMod->needRebuild()) { + $update[] = UPDATE_DONE; + $task = $confMod->generate(false, $parentTask); + if ($task !== false) { + $parentTask = $task; + } } } + foreach ($configList as $config) { + $config->generate(false, 0, $parentTask); + } } +// Start any changed services +ConfigModuleBaseLdap::ldadp(); + // Create response for browser responseFromArray($update); |