summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2015-02-09 19:03:26 +0100
committerSimon Rettberg2015-02-09 19:03:26 +0100
commit3262dfc8be9356bced77419652306bc507025fec (patch)
tree8384ca8493cea707dfd4878fcb68c7c56f126731
parentAdd sshd config module (diff)
downloadslx-admin-3262dfc8be9356bced77419652306bc507025fec.tar.gz
slx-admin-3262dfc8be9356bced77419652306bc507025fec.tar.xz
slx-admin-3262dfc8be9356bced77419652306bc507025fec.zip
Add support for editing existing configs
-rw-r--r--inc/configtgz.inc.php40
-rw-r--r--modules/sysconfig/addconfig.inc.php43
-rw-r--r--templates/sysconfig/_page.html11
-rw-r--r--templates/sysconfig/cfg-start.html7
4 files changed, 91 insertions, 10 deletions
diff --git a/inc/configtgz.inc.php b/inc/configtgz.inc.php
index 2082155c..231960bb 100644
--- a/inc/configtgz.inc.php
+++ b/inc/configtgz.inc.php
@@ -37,6 +37,46 @@ class ConfigTgz
}
return true;
}
+
+ public function getModuleIds()
+ {
+ $ret = array();
+ foreach ($this->modules as $module) {
+ $ret[] = $module['moduleid'];
+ }
+ return $ret;
+ }
+
+ public function update($title, $moduleIds)
+ {
+ if (!is_array($moduleIds))
+ return false;
+ $this->configTitle = $title;
+ $this->modules = array();
+ // Get all modules to put in config
+ $idstr = '0'; // Passed directly in query. Make sure no SQL injection is possible
+ 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)");
+ // Delete old connections
+ Database::exec("DELETE FROM configtgz_x_module WHERE configid = :configid", array('configid' => $this->configId));
+ // Make connection
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ Database::exec("INSERT INTO configtgz_x_module (configid, moduleid) VALUES (:configid, :moduleid)", array(
+ 'configid' => $this->configId,
+ 'moduleid' => $row['moduleid']
+ ));
+ $this->modules[] = $row;
+ }
+ // Update name
+ Database::exec("UPDATE configtgz SET title = :title, status = :status WHERE configid = :configid LIMIT 1", array(
+ 'configid' => $this->configId,
+ 'title' => $title,
+ 'status' => 'OUTDATED'
+ ));
+ return true;
+ }
public static function insert($title, $moduleIds)
{
diff --git a/modules/sysconfig/addconfig.inc.php b/modules/sysconfig/addconfig.inc.php
index daa2cd58..8acf5c32 100644
--- a/modules/sysconfig/addconfig.inc.php
+++ b/modules/sysconfig/addconfig.inc.php
@@ -12,6 +12,12 @@ abstract class AddConfig_Base
* @var \AddConfig_Base
*/
private static $instance = false;
+
+ /**
+ * Config being edited (if any)
+ * @var \ConfigTgz
+ */
+ protected $edit = false;
/**
*
@@ -25,6 +31,12 @@ abstract class AddConfig_Base
Util::redirect('?do=SysConfig');
}
self::$instance = new $step();
+ if (Request::any('edit')) {
+ self::$instance->edit = ConfigTgz::get(Request::any('edit'));
+ if (self::$instance->edit === false)
+ Util::traceError('Invalid config id for editing');
+ Util::addRedirectParam('edit', self::$instance->edit->id());
+ }
}
protected function tmError()
@@ -83,9 +95,10 @@ abstract class AddConfig_Base
public static function render()
{
- if (self::$instance === false) {
+ if (self::$instance === false)
Util::traceError('No step instance yet');
- }
+ if (self::$instance->edit !== false)
+ Message::addInfo('replacing-config', self::$instance->edit->title());
self::$instance->renderInternal();
}
@@ -110,7 +123,11 @@ class AddConfig_Start extends AddConfig_Base
{
$mods = ConfigModule::getList();
$res = Database::simpleQuery("SELECT moduleid, title, moduletype, filepath FROM configtgz_module"
- . " ORDER BY title ASC");
+ . " ORDER BY title ASC"); // Move to ConfigModule
+ if ($this->edit === false)
+ $active = array();
+ else
+ $active = $this->edit->getModuleIds();
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
if (!isset($mods[$row['moduletype']])) {
$mods[$row['moduletype']] = array(
@@ -123,11 +140,20 @@ class AddConfig_Start extends AddConfig_Base
$mods[$row['moduletype']]['groupid'] = $row['moduletype'];
}
if (empty($row['filepath']) || !file_exists($row['filepath'])) $row['missing'] = true;
+ $row['active'] = in_array($row['moduleid'], $active);
$mods[$row['moduletype']]['modules'][] = $row;
}
+ if ($this->edit !== false)
+ $title = $this->edit->title();
+ elseif (Request::any('title'))
+ $title = Request::any('title');
+ else
+ $title = '';
Render::addDialog(Dictionary::translate("lang_configurationCompilation"), false, 'sysconfig/cfg-start', array(
'step' => 'AddConfig_Finish',
- 'groups' => array_values($mods)
+ 'groups' => array_values($mods),
+ 'title' => $title,
+ 'edit' => $this->edit->id()
));
}
@@ -152,8 +178,13 @@ class AddConfig_Finish extends AddConfig_Base
Message::addError('missing-title');
Util::redirect('?do=SysConfig&action=addconfig');
}
- $this->config = ConfigTgz::insert($title, $modules);
- if ($this->config === false || $this->config->generate(true, 10000) !== true) {
+ if ($this->edit === false) {
+ $this->config = ConfigTgz::insert($title, $modules);
+ } else {
+ $this->edit->update($title, $modules);
+ $this->config = $this->edit;
+ }
+ if ($this->config === false || $this->config->generate(true, 150) === false) {
Message::addError('unsuccessful-action');
Util::redirect('?do=SysConfig&action=addconfig');
}
diff --git a/templates/sysconfig/_page.html b/templates/sysconfig/_page.html
index 2f46f2cf..438294e8 100644
--- a/templates/sysconfig/_page.html
+++ b/templates/sysconfig/_page.html
@@ -37,7 +37,8 @@
{{/needrebuild}}
name="rebuild" value="{{configid}}" title="{{lang_rebuild}}"><span class="glyphicon glyphicon-refresh"></span></button>
</td>
- <td>
+ <td class="slx-nowrap">
+ <a class="btn btn-success btn-xs" href="?do=SysConfig&amp;action=addconfig&amp;edit={{configid}}" title="{{lang_edit}}"><span class="glyphicon glyphicon-edit"></span></a>
<button class="btn btn-danger btn-xs" name="del" value="{{configid}}" title="{{lang_delete}}"><span class="glyphicon glyphicon-trash"></span></button>
</td>
</tr>
@@ -116,6 +117,14 @@
<div class="panel-heading">{{lang_legend}}</div>
<div class="panel-body">
<p>
+ <span class="btn btn-default btn-xs" title="{{lang_show}}"><span class="glyphicon glyphicon-eye-open"></span></span>
+ {{lang_showLong}}
+ </p>
+ <p>
+ <span class="btn btn-default btn-xs" title="{{lang_download}}"><span class="glyphicon glyphicon-download-alt"></span></span>
+ {{lang_downloadLong}}
+ </p>
+ <p>
<span class="btn btn-default btn-xs" title="{{lang_rebuild}}"><span class="glyphicon glyphicon-refresh"></span></span>
{{lang_rebuildLong}}
</p>
diff --git a/templates/sysconfig/cfg-start.html b/templates/sysconfig/cfg-start.html
index 7493bf55..50f366ea 100644
--- a/templates/sysconfig/cfg-start.html
+++ b/templates/sysconfig/cfg-start.html
@@ -1,8 +1,9 @@
<form role="form" method="post" action="?do=SysConfig&amp;action=addconfig&amp;step={{step}}">
<input type="hidden" name="token" value="{{token}}">
+ <input type="hidden" name="edit" value="{{edit}}">
<div class="input-group">
<span class="input-group-addon">{{lang_name}} *</span>
- <input type="text" name="title" class="form-control" placeholder="{{lang_configuration}}" autofocus="autofocus">
+ <input type="text" name="title" value="{{title}}" class="form-control" placeholder="{{lang_configuration}}" autofocus="autofocus">
</div>
<hr>
<p>{{lang_configurationChoose}}</p>
@@ -14,10 +15,10 @@
<div class="input-group">
<span class="input-group-addon">
{{#unique}}
- <input type="radio" name="module[{{groupid}}]" value="{{moduleid}}" id="module{{moduleid}}">
+ <input type="radio" name="module[{{groupid}}]" value="{{moduleid}}" id="module{{moduleid}}" {{#active}}checked{{/active}}>
{{/unique}}
{{^unique}}
- <input type="checkbox" name="module[{{moduleid}}]" value="{{moduleid}}" id="module{{moduleid}}">
+ <input type="checkbox" name="module[{{moduleid}}]" value="{{moduleid}}" id="module{{moduleid}}" {{#active}}checked{{/active}}>
{{/unique}}
</span>
<label class="form-control" for="module{{moduleid}}">{{title}}</label>