From 0aa46a9d4c1e6e22493832e4c7a186e41c0b23c8 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 29 Mar 2018 11:30:56 +0200 Subject: [sysconfig] Stuff ssh config into "empty" global config This is an ugly hack. The "no sysconfig" runmode option creates an obvious problem if an ssh config exists: It won't be provisioned to the client, so it's not reachable via ssh. We need a proper mechanism for managing config, that flags modules by whether they should be ignored for "no sysconfig" runmode or not, and while we're at it, make it possible to assign additional modules to rooms. --- modules-available/sysconfig/api.inc.php | 2 +- modules-available/sysconfig/inc/configtgz.inc.php | 43 +++++++++++++++++++---- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/modules-available/sysconfig/api.inc.php b/modules-available/sysconfig/api.inc.php index 9d621e5c..bb2d9f5e 100644 --- a/modules-available/sysconfig/api.inc.php +++ b/modules-available/sysconfig/api.inc.php @@ -32,7 +32,7 @@ if (Module::isAvailable('runmode')) { } } if ($runmode !== false && $runmode->noSysconfig && file_exists(SysConfig::GLOBAL_MINIMAL_CONFIG)) { - $row = array('filepath' => SysConfig::GLOBAL_MINIMAL_CONFIG); + $row = array('filepath' => SysConfig::GLOBAL_MINIMAL_CONFIG, 'title' => 'config'); } else { $locationId = false; if (Module::isAvailable('locations')) { diff --git a/modules-available/sysconfig/inc/configtgz.inc.php b/modules-available/sysconfig/inc/configtgz.inc.php index 17c9f35d..ea9ace4d 100644 --- a/modules-available/sysconfig/inc/configtgz.inc.php +++ b/modules-available/sysconfig/inc/configtgz.inc.php @@ -63,7 +63,7 @@ class ConfigTgz foreach ($moduleIds as $module) { $idstr .= ',' . (int)$module; // Casting to int should make it safe } - $res = Database::simpleQuery("SELECT moduleid, filepath, status FROM configtgz_module WHERE moduleid IN ($idstr)"); + $res = Database::simpleQuery("SELECT moduleid, moduletype, filepath, status FROM configtgz_module WHERE moduleid IN ($idstr)"); // Delete old connections Database::exec("DELETE FROM configtgz_x_module WHERE configid = :configid", array('configid' => $this->configId)); // Make connection @@ -98,8 +98,13 @@ class ConfigTgz $files = array(); // Get all config modules for system config foreach ($this->modules as $module) { - if (!empty($module['filepath']) && file_exists($module['filepath'])) + if (!empty($module['filepath']) && file_exists($module['filepath'])) { $files[] = $module['filepath']; + } + if ($module['moduletype'] === 'SshConfig') { + // HACK XXX TODO Global + SSH ugly + self::rebuildEmptyGlobalConfig(); + } } $task = self::recompress($files, $this->file); @@ -222,13 +227,39 @@ class ConfigTgz )); $res = Database::simpleQuery("SELECT configid FROM configtgz"); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $module = self::get($row['configid']); - if ($module !== false) { - $module->generate(); + $configTgz = self::get($row['configid']); + if ($configTgz !== false) { + $configTgz->generate(); } } // Build the global "empty" config that just includes global hooks - self::recompress([], SysConfig::GLOBAL_MINIMAL_CONFIG); + self::rebuildEmptyGlobalConfig(); + } + + /** + * Rebuild the general "empty" config that only contains global hook modules + * and forced ones. + */ + private static function rebuildEmptyGlobalConfig() + { + static $onceOnly = false; + if ($onceOnly) + return; + $onceOnly = true; + // HACK TODO XXX -- just stuff (global) ssh config into this one for now, needs proper fix :-( + $res = Database::simpleQuery("SELECT DISTINCT cm.filepath FROM configtgz_module cm + INNER JOIN configtgz_x_module cxm USING (moduleid) + INNER JOIN configtgz_location cl USING (configid) + WHERE cm.moduletype = 'SshConfig' AND cm.status = 'OK' + ORDER BY locationid ASC"); + $extra = []; + while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + if (file_exists($row['filepath'])) { + $extra[] = $row['filepath']; + break; + } + } + self::recompress($extra, SysConfig::GLOBAL_MINIMAL_CONFIG); } /** -- cgit v1.2.3-55-g7522