Skip to content

Commit de9ea81

Browse files
author
Marius Burkard
committed
- remove entries customer_viewable != y from select box for admins
- move all updates to onAfterUpdate - remove server parts that are not needed
1 parent 695761b commit de9ea81

File tree

6 files changed

+51
-113
lines changed

6 files changed

+51
-113
lines changed

interface/web/admin/directive_snippets_edit.php

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ class page_action extends tform_actions {
5151

5252
function onShow() {
5353
global $app, $conf;
54-
54+
5555
if($this->id > 0){
5656
$record = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ?", $this->id);
5757
if($record['master_directive_snippets_id'] > 0){
5858
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']);
5959
}
6060
unset($record);
6161
}
62-
62+
6363
parent::onShow();
6464
}
65-
65+
6666
function onShowEnd() {
67-
global $app, $conf;
68-
67+
global $app;
68+
6969
$is_master = false;
7070
if($this->id > 0){
7171
if($this->dataRecord['master_directive_snippets_id'] > 0){
@@ -77,53 +77,52 @@ function onShowEnd() {
7777
}
7878

7979
$app->tpl->setVar("is_master", $is_master);
80-
80+
8181
parent::onShowEnd();
8282
}
83-
84-
function onSubmit() {
83+
84+
public function onAfterUpdate() {
8585
global $app, $conf;
8686

87+
if(isset($this->dataRecord['update_sites']) && $this->dataRecord['update_sites'] === 'y') {
88+
if($this->dataRecord['active'] == 'y' && $this->dataRecord['update_sites'] == 'y') {
89+
if($this->dataRecord['type'] == 'php') {
90+
$rlike = $this->dataRecord['directive_snippets_id'].'|,'.$this->dataRecord['directive_snippets_id'].'|'.$this->dataRecord['directive_snippets_id'].',';
91+
$affected_snippets = $app->db->queryAllRecords('SELECT directive_snippets_id FROM directive_snippets WHERE required_php_snippets RLIKE(?) AND type = ?', $rlike, 'apache');
92+
if(is_array($affected_snippets) && !empty($affected_snippets)) {
93+
foreach($affected_snippets as $snippet) {
94+
$sql_in[] = $snippet['directive_snippets_id'];
95+
}
96+
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id IN ?', $conf['server_id'], $sql_in);
97+
}
98+
} elseif($this->dataRecord['type'] == 'apache') {
99+
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id = ?', $conf['server_id'], $this->dataRecord['directive_snippets_id']);
100+
}
101+
102+
if(is_array($affected_sites) && !empty($affected_sites)) {
103+
foreach($affected_sites as $site) {
104+
$website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ?', $site['domain_id']);
105+
$app->db->datalogUpdate('web_domain', $website, 'domain_id', $site['domain_id'], true);
106+
}
107+
}
108+
}
109+
}
110+
}
111+
112+
public function onSubmit() {
113+
global $app;
114+
87115
if($this->id > 0){
88116
$record = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ?", $this->id);
89117
if($record['master_directive_snippets_id'] > 0){
90118
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']);
91119
}
92-
93-
if(isset($this->dataRecord['update_sites'])) {
94-
parent::onSubmit();
95-
} else {
96-
$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);
97-
98-
if($_REQUEST["next_tab"] == '') {
99-
$list_name = $_SESSION["s"]["form"]["return_to"];
100-
if($list_name != '' && $_SESSION["s"]["list"][$list_name]["parent_name"] != $app->tform->formDef["name"]) {
101-
$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"];
102-
$_SESSION["s"]["form"]["return_to"] = '';
103-
session_write_close();
104-
header($redirect);
105-
} elseif (isset($_SESSION["s"]["form"]["return_to_url"]) && $_SESSION["s"]["form"]["return_to_url"] != '') {
106-
$redirect = $_SESSION["s"]["form"]["return_to_url"];
107-
$_SESSION["s"]["form"]["return_to_url"] = '';
108-
session_write_close();
109-
header("Location: ".$redirect);
110-
exit;
111-
} else {
112-
header("Location: ".$app->tform->formDef['list_default']);
113-
}
114-
exit;
115-
}
116-
}
117-
118-
unset($record);
119120
}
120121

121122
parent::onSubmit();
122123
}
123-
124+
124125
}
125126

126127
$page = new page_action;
127-
$page->onLoad();
128-
129-
?>
128+
$page->onLoad();

interface/web/admin/templates/directive_snippets_edit.htm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
</div></tmpl_if>
1818
</div>
1919
<tmpl_if name='is_master'></tmpl_else>
20+
<tmpl_if name='required_php_snippets'>
2021
<div class="form-group php">
2122
<label class="col-sm-3 control-label">{tmpl_var name='required_php_snippets_txt'}</label>
2223
<div class="col-sm-9">
2324
{tmpl_var name='required_php_snippets'}
2425
</div>
2526
</div>
27+
</tmpl_if>
2628
</tmpl_if>
2729
<div class="form-group">
2830
<label class="col-sm-3 control-label">{tmpl_var name='customer_viewable_txt'}</label>

interface/web/sites/web_vhost_domain_edit.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,11 +854,12 @@ function onShowEnd() {
854854
$directive_snippets_id_select .= '</optgroup>';
855855
}
856856

857-
if($is_admin) {
857+
// it does not make sense to display those for admins as they are NOT applied to vhosts anyway!
858+
/*if($is_admin) {
858859
$directive_snippets = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE active = 'y' AND master_directive_snippets_id = 0 AND type = ? ORDER BY name ASC", $server_type);
859-
} else {
860+
} else {*/
860861
$directive_snippets = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND active = 'y' AND master_directive_snippets_id = 0 AND type = ? ORDER BY name ASC", $server_type);
861-
}
862+
//}
862863
if(is_array($directive_snippets) && !empty($directive_snippets)){
863864
$directive_snippets_id_select .= '<optgroup label="'.$app->tform->wordbook["select_directive_snippet_txt"].'">';
864865
foreach($directive_snippets as $directive_snippet){

server/mods-available/web_module.inc.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ class web_module {
6565
'aps_package_delete',
6666
'aps_setting_insert',
6767
'aps_setting_update',
68-
'aps_setting_delete',
69-
'directive_snippets_update'
68+
'aps_setting_delete'
7069
);
7170

7271
//* This function is called during ispconfig installation to determine
@@ -117,7 +116,6 @@ class that contains the function functionname.
117116
$app->modules->registerTableHook('aps_instances_settings', 'web_module', 'process');
118117
$app->modules->registerTableHook('aps_packages', 'web_module', 'process');
119118
$app->modules->registerTableHook('aps_settings', 'web_module', 'process');
120-
$app->modules->registerTableHook('directive_snippets', 'web_module', 'process');
121119

122120
// Register service
123121
$app->services->registerService('httpd', 'web_module', 'restartHttpd');
@@ -189,11 +187,6 @@ function process($tablename, $action, $data) {
189187
if($action == 'u') $app->plugins->raiseEvent('aps_setting_update', $data);
190188
if($action == 'd') $app->plugins->raiseEvent('aps_setting_delete', $data);
191189
break;
192-
case 'directive_snippets':
193-
if($action == 'i') $app->plugins->raiseEvent('directive_snippets_insert', $data);
194-
if($action == 'u') $app->plugins->raiseEvent('directive_snippets_update', $data);
195-
if($action == 'd') $app->plugins->raiseEvent('directive_snippets_delete', $data);
196-
break;
197190
} // end switch
198191
} // end function
199192

@@ -229,7 +222,7 @@ function restartHttpd($action = 'restart') {
229222
} else {
230223
$cmd = $app->system->getinitcommand($daemon, 'reload');
231224
}
232-
225+
233226
if($web_config['server_type'] == 'nginx'){
234227
$app->log("Checking nginx configuration...", LOGLEVEL_DEBUG);
235228
exec('nginx -t 2>&1', $retval['output'], $retval['retval']);
@@ -240,16 +233,16 @@ function restartHttpd($action = 'restart') {
240233
return $retval;
241234
}
242235
}
243-
236+
244237
exec($cmd.' 2>&1', $retval['output'], $retval['retval']);
245-
238+
246239
// if restart failed despite successful syntax check => try again
247240
if($web_config['server_type'] == 'nginx' && $retval['retval'] > 0){
248241
sleep(2);
249242
exec($cmd.' 2>&1', $retval['output'], $retval['retval']);
250243
}
251244
$app->log("Restarting httpd: $cmd", LOGLEVEL_DEBUG);
252-
245+
253246
// nginx: do a syntax check because on some distributions, the init script always returns 0 - even if the syntax is not ok (how stupid is that?)
254247
//if($web_config['server_type'] == 'nginx' && $retval['retval'] == 0){
255248
//exec('nginx -t 2>&1', $retval['output'], $retval['retval']);
@@ -272,7 +265,7 @@ function restartPHP_FPM($action = 'restart') {
272265
} else {
273266
$path_parts = pathinfo($init_script);
274267
$initcommand = $app->system->getinitcommand($path_parts['basename'], $action, $path_parts['dirname']);
275-
268+
276269
if($action == 'reload' && $init_script == $conf['init_scripts'].'/'.$web_config['php_fpm_init_script']) {
277270
// we have to do a workaround because of buggy ubuntu fpm reload handling
278271
// @see: https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1242376
@@ -289,7 +282,7 @@ function restartPHP_FPM($action = 'restart') {
289282
}
290283
*/
291284
unset($tmp);
292-
}
285+
}
293286
}
294287
/*
295288
if($action == 'reload') {

server/plugins-available/apache2_plugin.inc.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,34 +95,6 @@ function onLoad() {
9595
$app->plugins->registerEvent('ftp_user_delete', $this->plugin_name, 'ftp_user_delete');
9696

9797
$app->plugins->registerAction('php_ini_changed', $this->plugin_name, 'php_ini_changed');
98-
99-
$app->plugins->registerEvent('directive_snippets_update', $this->plugin_name, 'directive_snippets');
100-
}
101-
102-
function directive_snippets($event_name, $data) {
103-
global $app, $conf;
104-
105-
$snippet = $data['new'];
106-
if($snippet['active'] == 'y' && $snippet['update_sites'] == 'y') {
107-
if($snippet['type'] == 'php') {
108-
$rlike = $snippet['directive_snippets_id'].'|,'.$snippet['directive_snippets_id'].'|'.$snippet['directive_snippets_id'].',';
109-
$affected_snippets = $app->db->queryAllRecords('SELECT directive_snippets_id FROM directive_snippets WHERE required_php_snippets RLIKE(?) AND type = ?', $rlike, 'apache');
110-
if(is_array($affected_snippets) && !empty($affected_snippets)) {
111-
foreach($affected_snippets as $snippet) $sql_in[] = $snippet['directive_snippets_id'];
112-
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id IN ?', $conf['server_id'], $sql_in);
113-
}
114-
}
115-
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']);
116-
117-
if(is_array($affected_sites) && !empty($affected_sites)) {
118-
foreach($affected_sites as $site) {
119-
$website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ?', $site['domain_id']);
120-
$new_data['old'] = $website;
121-
$new_data['new'] = $website;
122-
$this->update('web_domain_update', $new_data);
123-
}
124-
}
125-
}
12698
}
12799

128100
private function get_master_php_ini_content($web_data) {

server/plugins-available/nginx_plugin.inc.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,35 +90,6 @@ function onLoad() {
9090

9191
$app->plugins->registerEvent('web_folder_update', $this->plugin_name, 'web_folder_update');
9292
$app->plugins->registerEvent('web_folder_delete', $this->plugin_name, 'web_folder_delete');
93-
94-
$app->plugins->registerEvent('directive_snippets_update', $this->plugin_name, 'directive_snippets');
95-
}
96-
97-
function directive_snippets($event_name, $data) {
98-
global $app, $conf;
99-
100-
$snippet = $data['new'];
101-
102-
if($snippet['active'] == 'y' && $snippet['update_sites'] == 'y') {
103-
if($snippet['type'] == 'php') {
104-
$rlike = $snippet['directive_snippets_id'].'|,'.$snippet['directive_snippets_id'].'|'.$snippet['directive_snippets_id'].',';
105-
$affected_snippets = $app->db->queryAllRecords('SELECT directive_snippets_id FROM directive_snippets WHERE required_php_snippets RLIKE(?) AND type = ?', $rlike, 'nginx');
106-
if(is_array($affected_snippets) && !empty($affected_snippets)) {
107-
foreach($affected_snippets as $snippet) $sql_in[] = $snippet['directive_snippets_id'];
108-
$affected_sites = $app->db->queryAllRecords('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id IN ?', $conf['server_id'], $sql_in);
109-
}
110-
}
111-
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']);
112-
113-
if(is_array($affected_sites) && !empty($affected_sites)) {
114-
foreach($affected_sites as $site) {
115-
$website = $app->db->queryOneRecord('SELECT * FROM web_domain WHERE domain_id = ?', $site['domain_id']);
116-
$new_data['old'] = $website;
117-
$new_data['new'] = $website;
118-
$this->update('web_domain_update', $new_data);
119-
}
120-
}
121-
}
12293
}
12394

12495
// Handle the creation of SSL certificates

0 commit comments

Comments
 (0)