Commit 6aa06901 authored by Florian Schaal's avatar Florian Schaal
Browse files

update affected websites when a directive snippet was updated (Implements #5632)

parent 3caef955
......@@ -62,3 +62,6 @@ ALTER TABLE `mail_user` MODIFY `move_junk` enum('y','a','n') NOT NULL DEFAULT 'y
-- Change id_rsa column to TEXT format
ALTER TABLE `client` CHANGE `id_rsa` `id_rsa` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '';
ALTER TABLE `directive_snippets` ADD `update_sites` ENUM('y','n') NOT NULL DEFAULT 'n' ;
......@@ -470,6 +470,7 @@ CREATE TABLE IF NOT EXISTS `directive_snippets` (
`required_php_snippets` varchar(255) NOT NULL DEFAULT '',
`active` enum('n','y') NOT NULL DEFAULT 'y',
`master_directive_snippets_id` int(11) unsigned NOT NULL DEFAULT '0',
`update_sites` ENUM('y','n') NOT NULL DEFAULT 'n',
PRIMARY KEY (`directive_snippets_id`)
) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
......
......@@ -75,22 +75,52 @@ class page_action extends tform_actions {
$app->tpl->setVar("snippet", $this->dataRecord['snippet'], true);
}
}
$app->tpl->setVar("is_master", $is_master);
if($this->dataRecord['managed_snippet_id'] > 0) {
}
parent::onShowEnd();
}
function onSubmit() {
global $app, $conf;
if($this->id > 0){
$record = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ?", $this->id);
if($record['master_directive_snippets_id'] > 0){
unset($app->tform->formDef["tabs"]['directive_snippets']['fields']['name'], $app->tform->formDef["tabs"]['directive_snippets']['fields']['type'], $app->tform->formDef["tabs"]['directive_snippets']['fields']['snippet'], $app->tform->formDef["tabs"]['directive_snippets']['fields']['required_php_snippets']);
}
if(isset($this->dataRecord['update_sites'])) {
parent::onSubmit();
} else {
$app->db->query('UPDATE directive_snippets SET name = ?, type = ?, snippet = ?, customer_viewable = ?, required_php_snippets = ?, active = ? WHERE directive_snippets_id = ?', $this->dataRecord['name'], $this->dataRecord['type'], $this->dataRecord['snippet'], $this->dataRecord['customer_viewable'], implode(',', $this->dataRecord['required_php_snippets']), $this->dataRecord['active'], $this->id);
if($_REQUEST["next_tab"] == '') {
$list_name = $_SESSION["s"]["form"]["return_to"];
if($list_name != '' && $_SESSION["s"]["list"][$list_name]["parent_name"] != $app->tform->formDef["name"]) {
$redirect = "Location: ".$_SESSION["s"]["list"][$list_name]["parent_script"]."?id=".$_SESSION["s"]["list"][$list_name]["parent_id"]."&next_tab=".$_SESSION["s"]["list"][$list_name]["parent_tab"];
$_SESSION["s"]["form"]["return_to"] = '';
session_write_close();
header($redirect);
} elseif (isset($_SESSION["s"]["form"]["return_to_url"]) && $_SESSION["s"]["form"]["return_to_url"] != '') {
$redirect = $_SESSION["s"]["form"]["return_to_url"];
$_SESSION["s"]["form"]["return_to_url"] = '';
session_write_close();
header("Location: ".$redirect);
exit;
} else {
header("Location: ".$app->tform->formDef['list_default']);
}
exit;
}
}
unset($record);
}
parent::onSubmit();
}
......
......@@ -110,6 +110,12 @@ $form["tabs"]['directive_snippets'] = array (
'default' => 'y',
'value' => array(0 => 'n', 1 => 'y')
),
'update_sites' => array (
'datatype' => 'VARCHAR',
'formtype' => 'CHECKBOX',
'default' => 'y',
'value' => array(0 => 'n', 1 => 'y')
),
'required_php_snippets' => array (
'datatype' => 'VARCHAR',
'formtype' => 'CHECKBOXARRAY',
......
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'Já existe uma diretiva com este
$wb['variables_txt'] = 'Variáveis';
$wb['customer_viewable_txt'] = 'Visualização personalizada';
$wb['required_php_snippets_txt'] = 'Trecho de código exige php';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Proměnné';
$wb['customer_viewable_txt'] = 'Dostupná volba pro klienta';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'Es existiert schon ein Direktiven
$wb['variables_txt'] = 'Variablen';
$wb['customer_viewable_txt'] = 'Sichtbar für Kunden';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'Der er allerede et direktiv uddra
$wb['variables_txt'] = 'Variabler';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb["directive_snippets_name_error_unique"] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
\ No newline at end of file
......@@ -9,4 +9,5 @@ $wb['snippet_txt'] = 'Fragmento';
$wb['type_txt'] = 'Tipo';
$wb['variables_txt'] = 'Variables';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'Već postoji direktiva sa tim ime
$wb['variables_txt'] = 'Varijable';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'Esiste già una direttiva snippet
$wb['variables_txt'] = 'Variabili';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'Er is al een Directive Snippet me
$wb['variables_txt'] = 'Variabelen';
$wb['customer_viewable_txt'] = 'Zichtbaar voor klanten';
$wb['required_php_snippets_txt'] = 'Vereiste PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'Istnieje już zestaw dyrektyw o p
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'Уже есть заготовк
$wb['variables_txt'] = 'Переменные:';
$wb['customer_viewable_txt'] = 'Видимый клиентам';
$wb['required_php_snippets_txt'] = 'Обязательная PHP-заготовка';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'There is already a directive snip
$wb['variables_txt'] = 'Variables';
$wb['customer_viewable_txt'] = 'Customer viewable';
$wb['required_php_snippets_txt'] = 'Requiered PHP Snippet';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -9,4 +9,5 @@ $wb['directive_snippets_name_error_unique'] = 'Aynı adlı bir yönerge kod par
$wb['variables_txt'] = 'Değişkenler';
$wb['customer_viewable_txt'] = 'Müşteri görebilir';
$wb['required_php_snippets_txt'] = 'Gerekli PHP Parçası';
$wb['update_sites_txt'] = 'Update sites using this snippet';
?>
......@@ -36,7 +36,10 @@
{tmpl_var name='active'}
</div>
</div>
<div class="form-group">
<label for="update_sites" class="col-sm-3 control-label">{tmpl_var name='update_sites_txt'}</label>
<div class="col-sm-9">{tmpl_var name='update_sites'}</div>
</div>
<input type="hidden" name="id" value="{tmpl_var name='id'}">
......
......@@ -32,7 +32,8 @@ class web_module {
var $module_name = 'web_module';
var $class_name = 'web_module';
var $actions_available = array( 'web_domain_insert',
var $actions_available = array(
'web_domain_insert',
'web_domain_update',
'web_domain_delete',
'ftp_user_insert',
......@@ -64,7 +65,9 @@ class web_module {
'aps_package_delete',
'aps_setting_insert',
'aps_setting_update',
'aps_setting_delete');
'aps_setting_delete',
'directive_snippets_update'
);
//* This function is called during ispconfig installation to determine
// if a symlink shall be created for this plugin.
......@@ -114,6 +117,7 @@ class web_module {
$app->modules->registerTableHook('aps_instances_settings', 'web_module', 'process');
$app->modules->registerTableHook('aps_packages', 'web_module', 'process');
$app->modules->registerTableHook('aps_settings', 'web_module', 'process');
$app->modules->registerTableHook('directive_snippets', 'web_module', 'process');
// Register service
$app->services->registerService('httpd', 'web_module', 'restartHttpd');
......@@ -185,6 +189,11 @@ class web_module {
if($action == 'u') $app->plugins->raiseEvent('aps_setting_update', $data);
if($action == 'd') $app->plugins->raiseEvent('aps_setting_delete', $data);
break;
case 'directive_snippets':
if($action == 'i') $app->plugins->raiseEvent('directive_snippets_insert', $data);
if($action == 'u') $app->plugins->raiseEvent('directive_snippets_update', $data);
if($action == 'd') $app->plugins->raiseEvent('directive_snippets_delete', $data);
break;
} // end switch
} // end function
......
......@@ -93,6 +93,34 @@ class apache2_plugin {
$app->plugins->registerEvent('ftp_user_delete', $this->plugin_name, 'ftp_user_delete');
$app->plugins->registerAction('php_ini_changed', $this->plugin_name, 'php_ini_changed');
$app->plugins->registerEvent('directive_snippets_update', $this->plugin_name, 'directive_snippets');
}
function directive_snippets($event_name, $data) {
global $app, $conf;
$snippet = $data['new'];
if($snippet['active'] == 'y' && $snippet['update_sites'] == 'y') {
if($snippet['type'] == 'php') {
$rlike = $snippet['directive_snippets_id'].'|,'.$snippet['directive_snippets_id'].'|'.$snippet['directive_snippets_id'].',';
$affected_snippets = $app->db->queryAllRecords('SELECT directive_snippets_id FROM directive_snippets WHERE required_php_snippets RLIKE(?) AND type = ?', $rlike, 'apache');
if(is_array($affected_snippets) && !empty($affected_snippets)) {
foreach($affected_snippets as $snippet) $sql_in[] = $snippet['directive_snippets_id'];
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id IN('.implode(',', $sql_in).')', $conf['server_id']);
}
}
if($snippet['type'] == 'apache') $affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id = ?', $conf['server_id'], $snippet['directive_snippets_id']);
if(is_array($affected_sites) && !empty($affected_sites)) {
foreach($affected_sites as $site) {
$website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ?', $site['domain_id']);
$new_data['old'] = $website;
$new_data['new'] = $website;
$this->update('web_domain_update', $new_data);
}
}
}
}
private function get_master_php_ini_content($web_data) {
......
......@@ -88,6 +88,35 @@ class nginx_plugin {
$app->plugins->registerEvent('web_folder_update', $this->plugin_name, 'web_folder_update');
$app->plugins->registerEvent('web_folder_delete', $this->plugin_name, 'web_folder_delete');
$app->plugins->registerEvent('directive_snippets_update', $this->plugin_name, 'directive_snippets');
}
function directive_snippets($event_name, $data) {
global $app, $conf;
$snippet = $data['new'];
if($snippet['active'] == 'y' && $snippet['update_sites'] == 'y') {
if($snippet['type'] == 'php') {
$rlike = $snippet['directive_snippets_id'].'|,'.$snippet['directive_snippets_id'].'|'.$snippet['directive_snippets_id'].',';
$affected_snippets = $app->db->queryAllRecords('SELECT directive_snippets_id FROM directive_snippets WHERE required_php_snippets RLIKE(?) AND type = ?', $rlike, 'nginx');
if(is_array($affected_snippets) && !empty($affected_snippets)) {
foreach($affected_snippets as $snippet) $sql_in[] = $snippet['directive_snippets_id'];
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id IN('.implode(',', $sql_in).')', $conf['server_id']);
}
}
if($snippet['type'] == 'nginx') $affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id = ?', $conf['server_id'], $snippet['directive_snippets_id']);
if(is_array($affected_sites) && !empty($affected_sites)) {
foreach($affected_sites as $site) {
$website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ?', $site['domain_id']);
$new_data['old'] = $website;
$new_data['new'] = $website;
$this->update('web_domain_update', $new_data);
}
}
}
}
// Handle the creation of SSL certificates
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment