Skip to content

Commit 1fa8f42

Browse files
committed
- Directive snippets can now be made available to clients; clients can select an available directive snippet for a website - the appropriate snippet will then be written to the vhost configuration file. This is useful for example on nginx where clients have no access to the Options tab of a website.
1 parent 756b836 commit 1fa8f42

16 files changed

+177
-5
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE `directive_snippets` ADD `customer_viewable` ENUM('n','y') NOT NULL DEFAULT 'n' AFTER `snippet`;
2+
ALTER TABLE `web_domain` ADD `directive_snippets_id` int(11) unsigned NOT NULL default '0';

install/sql/ispconfig3.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ CREATE TABLE IF NOT EXISTS `directive_snippets` (
429429
`name` varchar(255) DEFAULT NULL,
430430
`type` varchar(255) DEFAULT NULL,
431431
`snippet` mediumtext,
432+
`customer_viewable` ENUM('n','y') NOT NULL DEFAULT 'n',
432433
`active` enum('n','y') NOT NULL DEFAULT 'y',
433434
PRIMARY KEY (`directive_snippets_id`)
434435
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
@@ -1880,6 +1881,7 @@ CREATE TABLE `web_domain` (
18801881
`rewrite_rules` mediumtext,
18811882
`added_date` date NOT NULL DEFAULT '0000-00-00',
18821883
`added_by` varchar(255) DEFAULT NULL,
1884+
`directive_snippets_id` int(11) unsigned NOT NULL default '0',
18831885
PRIMARY KEY (`domain_id`),
18841886
UNIQUE KEY `serverdomain` ( `server_id` , `ip_address`, `domain` )
18851887
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
4+
class plugin_directive_snippets extends plugin_base
5+
{
6+
var $module;
7+
var $form;
8+
var $tab;
9+
var $record_id;
10+
var $formdef;
11+
var $options;
12+
13+
public function onShow()
14+
{
15+
global $app;
16+
17+
$listTpl = new tpl;
18+
$listTpl->newTemplate('templates/web_directive_snippets.htm');
19+
20+
//* Loading language file
21+
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_web_directive_snippets.lng";
22+
23+
include $lng_file;
24+
$listTpl->setVar($wb);
25+
26+
$message = '';
27+
$error = '';
28+
29+
$server_type = $app->getconf->get_server_config($this->form->dataRecord['server_id'], 'web');
30+
$server_type = $server_type['server_type'];
31+
$records = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND type = ? ORDER BY name ASC", $server_type);
32+
33+
for ($i = 0, $c = count($records); $i < $c; $i++)
34+
{
35+
$records[$i]['is_selected'] = false;
36+
37+
if ($this->form->dataRecord['directive_snippets_id'] === $records[$i]['directive_snippets_id'])
38+
$records[$i]['is_selected'] = true;
39+
}
40+
41+
$listTpl->setLoop('records', $records);
42+
43+
$list_name = 'directive_snippets_list';
44+
$_SESSION["s"]["list"][$list_name]["parent_id"] = $this->form->id;
45+
$_SESSION["s"]["list"][$list_name]["parent_name"] = $app->tform->formDef["name"];
46+
$_SESSION["s"]["list"][$list_name]["parent_tab"] = $_SESSION["s"]["form"]["tab"];
47+
$_SESSION["s"]["list"][$list_name]["parent_script"] = $app->tform->formDef["action"];
48+
$_SESSION["s"]["form"]["return_to"] = $list_name;
49+
50+
return $listTpl->grab();
51+
}
52+
53+
public function onUpdate()
54+
{
55+
global $app, $conf;
56+
57+
if (isset($this->form->dataRecord['directive_snippets_id']) && $this->form->oldDataRecord['directive_snippets_id'] !== $this->form->dataRecord['directive_snippets_id']) {
58+
$app->db->query('UPDATE web_domain SET directive_snippets_id = ? WHERE domain_id = ?', $this->form->dataRecord['directive_snippets_id'], $this->form->id);
59+
}
60+
}
61+
62+
public function onInsert()
63+
{
64+
global $app, $conf;
65+
66+
if (isset($this->form->dataRecord['directive_snippets_id'])) {
67+
$app->db->query('UPDATE web_domain SET directive_snippets_id = ? WHERE domain_id = ?', $this->form->dataRecord['directive_snippets_id'], $this->form->id);
68+
}
69+
}
70+
71+
}
72+
?>

interface/web/admin/form/directive_snippets.tform.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@
9393
'maxlength' => '255',
9494
'searchable' => 2
9595
),
96+
'customer_viewable' => array (
97+
'datatype' => 'VARCHAR',
98+
'formtype' => 'CHECKBOX',
99+
'default' => 'n',
100+
'value' => array(0 => 'n', 1 => 'y')
101+
),
96102
'active' => array (
97103
'datatype' => 'VARCHAR',
98104
'formtype' => 'CHECKBOX',

interface/web/admin/lib/lang/de_directive_snippets.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ $wb['active_txt'] = 'Aktiv';
77
$wb['directive_snippets_name_empty'] = 'Bitte geben Sie einen Namen für den Schnipsel an.';
88
$wb['directive_snippets_name_error_unique'] = 'Es existiert schon ein Direktiven-Schnipsel mit diesem Namen.';
99
$wb['variables_txt'] = 'Variablen';
10+
$wb['customer_viewable_txt'] = 'Sichtbar für Kunden';
1011
?>

interface/web/admin/lib/lang/en_directive_snippets.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ $wb["active_txt"] = 'Active';
77
$wb["directive_snippets_name_empty"] = 'Please specify a name for the snippet.';
88
$wb["directive_snippets_name_error_unique"] = 'There is already a directive snippet with this name.';
99
$wb['variables_txt'] = 'Variables';
10+
$wb['customer_viewable_txt'] = 'Customer viewable';
1011
?>

interface/web/admin/templates/directive_snippets_edit.htm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ <h2><tmpl_var name="list_head_txt"></h2>
1818
<div class="ctrlHolder">
1919
<label for="snippet">{tmpl_var name='snippet_txt'}</label>
2020
<textarea name="snippet" id="snippet" rows='10' cols='50' style="width:400px;">{tmpl_var name='snippet'}</textarea><span class="nginx"> &nbsp; {tmpl_var name='variables_txt'}: </span><a href="javascript:void(0);" class="addPlaceholder nginx">{DOCROOT}</a><span class="nginx">, </span><a href="javascript:void(0);" class="addPlaceholder nginx">{FASTCGIPASS}</a>
21+
</div>
22+
<div class="ctrlHolder">
23+
<p class="label">{tmpl_var name='customer_viewable_txt'}</p>
24+
<div class="multiField">
25+
{tmpl_var name='customer_viewable'}
26+
</div>
2127
</div>
2228
<div class="ctrlHolder">
2329
<p class="label">{tmpl_var name='active_txt'}</p>
@@ -43,8 +49,19 @@ <h2><tmpl_var name="list_head_txt"></h2>
4349
} else {
4450
jQuery('.nginx:visible').hide();
4551
}
52+
53+
if (jQuery('#type').val() != 'nginx' && jQuery('#type').val() != 'apache') {
54+
jQuery('#customer_viewable').closest('div.ctrlHolder:visible').hide();
55+
}else {
56+
jQuery('#customer_viewable').closest('div.ctrlHolder:hidden').show();
57+
}
4658

4759
jQuery('#type').change(function(){
60+
if (jQuery(this).val() != 'nginx' && jQuery(this).val() != 'apache') {
61+
jQuery('#customer_viewable').closest('div.ctrlHolder:visible').hide();
62+
} else {
63+
jQuery('#customer_viewable').closest('div.ctrlHolder:hidden').show();
64+
}
4865
if(jQuery(this).val() == 'nginx'){
4966
jQuery('.nginx:hidden').show();
5067
} else {

interface/web/sites/ajax_get_json.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@
190190
$json .= '"}';
191191
}
192192

193+
if ($type == 'getdirectivesnippet') {
194+
$server_type = 'apache';
195+
$web_config = $app->getconf->get_server_config($server_id, 'web');
196+
if (!empty($web_config['server_type']))
197+
$server_type = $web_config['server_type'];
198+
199+
$snippets = $app->db->queryAllRecords("SELECT directive_snippets_id, name FROM directive_snippets WHERE customer_viewable = 'y' AND type = ? ORDER BY name ASC", $server_type);
200+
201+
$json = json_encode($snippets);
202+
}
203+
193204
//}
194205

195206
header('Content-type: application/json');

interface/web/sites/form/web_vhost_domain.tform.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,13 @@
282282
//#################################
283283
// ENDE Datatable fields
284284
//#################################
285-
)
285+
),
286+
'plugins' => array (
287+
// needs serverId for web.server_type
288+
'directive_snippets_id' => array (
289+
'class' => 'plugin_directive_snippets'
290+
),
291+
)
286292
);
287293

288294
// add type-specific field attributes
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
$wb['directive_snippets_id_txt'] = 'Gewünschte Konfiguration';
3+
?>

0 commit comments

Comments
 (0)