Skip to content

Commit ca06983

Browse files
author
Florian Schaal
committed
FS#1990 - Additional V-Server Field - this commits add a custom-field for openvz-configs
1 parent 61e08e7 commit ca06983

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+187
-3
lines changed

install/sql/incremental/upd_dev_collection.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,7 @@ CREATE TABLE `server_ip_map` (
168168
ALTER TABLE `web_domain` ADD COLUMN `rewrite_to_https` ENUM('y','n') NOT NULL DEFAULT 'n' AFTER `seo_redirect`;
169169

170170
ALTER TABLE openvz_ip ADD COLUMN `additional` VARCHAR(255) NOT NULL DEFAULT 'n';
171+
172+
ALTER TABLE openvz_template ADD COLUMN `custom` text;
173+
ALTER TABLE openvz_vm ADD COLUMN `custom` text;
174+

install/sql/ispconfig3.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,14 +1093,15 @@ CREATE TABLE IF NOT EXISTS `openvz_template` (
10931093
`capability` varchar(255) DEFAULT NULL,
10941094
`features` varchar(255) DEFAULT NULL,
10951095
`iptables` varchar(255) DEFAULT NULL,
1096+
`custom` text,
10961097
PRIMARY KEY (`template_id`)
10971098
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
10981099

10991100
--
11001101
-- Dumping data for table `openvz_template`
11011102
--
11021103

1103-
INSERT INTO `openvz_template` (`template_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `template_name`, `diskspace`, `traffic`, `bandwidth`, `ram`, `ram_burst`, `cpu_units`, `cpu_num`, `cpu_limit`, `io_priority`, `active`, `description`, `numproc`, `numtcpsock`, `numothersock`, `vmguarpages`, `kmemsize`, `tcpsndbuf`, `tcprcvbuf`, `othersockbuf`, `dgramrcvbuf`, `oomguarpages`, `privvmpages`, `lockedpages`, `shmpages`, `physpages`, `numfile`, `avnumproc`, `numflock`, `numpty`, `numsiginfo`, `dcachesize`, `numiptent`, `swappages`, `hostname`, `nameserver`, `create_dns`, `capability`, `features`, `iptables`) VALUES(1, 1, 1, 'riud', 'riud', '', 'small', 10, -1, -1, 256, 512, 1000, 4, 400, 4, 'y', '', '999999:999999', '7999992:7999992', '7999992:7999992', '65536:65536', '2147483646:2147483646', '214748160:396774400', '214748160:396774400', '214748160:396774400', '214748160:396774400', '65536:65536', '131072:131072', '999999:999999', '65536:65536', '0:2147483647', '23999976:23999976', '180:180', '999999:999999', '500000:500000', '999999:999999', '2147483646:2147483646', '999999:999999', '256000:256000', 'v{VEID}.test.tld', '8.8.8.8 8.8.4.4', 'n', '', '', '');
1104+
INSERT INTO `openvz_template` (`template_id`, `sys_userid`, `sys_groupid`, `sys_perm_user`, `sys_perm_group`, `sys_perm_other`, `template_name`, `diskspace`, `traffic`, `bandwidth`, `ram`, `ram_burst`, `cpu_units`, `cpu_num`, `cpu_limit`, `io_priority`, `active`, `description`, `numproc`, `numtcpsock`, `numothersock`, `vmguarpages`, `kmemsize`, `tcpsndbuf`, `tcprcvbuf`, `othersockbuf`, `dgramrcvbuf`, `oomguarpages`, `privvmpages`, `lockedpages`, `shmpages`, `physpages`, `numfile`, `avnumproc`, `numflock`, `numpty`, `numsiginfo`, `dcachesize`, `numiptent`, `swappages`, `hostname`, `nameserver`, `create_dns`, `capability`, `features`, `iptables`) VALUES(1, 1, 1, 'riud', 'riud', '', 'small', 10, -1, -1, 256, 512, 1000, 4, 400, 4, 'y', '', '999999:999999', '7999992:7999992', '7999992:7999992', '65536:65536', '2147483646:2147483646', '214748160:396774400', '214748160:396774400', '214748160:396774400', '214748160:396774400', '65536:65536', '131072:131072', '999999:999999', '65536:65536', '0:2147483647', '23999976:23999976', '180:180', '999999:999999', '500000:500000', '999999:999999', '2147483646:2147483646', '999999:999999', '256000:256000', 'v{VEID}.test.tld', '8.8.8.8 8.8.4.4', 'n', '', '', '', '');
11041105

11051106
-- --------------------------------------------------------
11061107

@@ -1159,6 +1160,7 @@ CREATE TABLE IF NOT EXISTS `openvz_vm` (
11591160
`features` text,
11601161
`iptabless` text,
11611162
`config` mediumtext,
1163+
`custom` text,
11621164
PRIMARY KEY (`vm_id`)
11631165
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
11641166

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/**
4+
Copyright (c) 2015, Florian Schaal, schaal @it
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification,
8+
are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the name of ISPConfig nor the names of its contributors
16+
may be used to endorse or promote products derived from this software without
17+
specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
30+
@author Florian Schaal, info@schaal-24.de
31+
@copyrighth Florian Schaal, info@schaal-24.de
32+
*/
33+
34+
class validate_openvz {
35+
36+
function get_error($errmsg, $additional='') {
37+
global $app;
38+
if(isset($app->tform->wordbook[$errmsg])) {
39+
return $app->tform->wordbook[$errmsg].$additional."<br>\r\n";
40+
} else {
41+
return $errmsg."<br>".$additional."<br>\r\n";
42+
}
43+
}
44+
45+
function check_custom($field_name, $field_value, $validator) {
46+
$template = file('../vm/templates/openvz.conf.tpl', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
47+
$custom_array = explode("\n", $field_value);
48+
$used_parameters = array();
49+
foreach ($template as $line) {
50+
$line = trim ($line);
51+
if (preg_match('/^[^#].*=\".*\"/', $line)) {
52+
$line = explode('=', $line, 2);
53+
$used_parameters[] = $line[0];
54+
}
55+
}
56+
foreach ($custom_array as $check) {
57+
$check = trim(strtoupper($check));
58+
$check = explode('=', trim($check), 2);
59+
$check = trim($check[0]);
60+
if (in_array($check, $used_parameters)) {
61+
return $this->get_error($validator['errmsg'], $check);
62+
}
63+
}
64+
}
65+
66+
}

interface/lib/plugins/vm_openvz_plugin.inc.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ private function applyTemplate() {
156156
$sql .= "capability = ?, ";
157157
$sql .= "features = ?, ";
158158
$sql .= "iptables = ? ";
159+
$sql .= "custom = ? ";
159160
$sql .= "WHERE vm_id = ?";
160-
$app->db->query($sql, $tpl['diskspace'], $tpl['ram'], $tpl['ram_burst'], $tpl['cpu_units'], $tpl['cpu_num'], $tpl['cpu_limit'], $tpl['io_priority'], $tpl['nameserver'], $tpl['create_dns'], $tpl['capability'], $tpl['features'], $tpl['iptables'], $this->id);
161+
$app->db->query($sql, $tpl['diskspace'], $tpl['ram'], $tpl['ram_burst'], $tpl['cpu_units'], $tpl['cpu_num'], $tpl['cpu_limit'], $tpl['io_priority'], $tpl['nameserver'], $tpl['create_dns'], $tpl['capability'], $tpl['features'], $tpl['iptables'], $tpl['custom'], $this->id);
161162

162163
}
163164

@@ -230,6 +231,8 @@ private function makeOpenVZConfig() {
230231
$tpl->setVar('features', $vm['features']);
231232
$tpl->setVar('iptables', $vm['iptables']);
232233

234+
$tpl->setVar('custom', $vm['custom']);
235+
233236
$tmp = $app->db->queryOneRecord("SELECT template_file FROM openvz_ostemplate WHERE ostemplate_id = ?", $app->functions->intval($vm['ostemplate_id']));
234237
$tpl->setVar('ostemplate', $tmp['template_file']);
235238
unset($tmp);

interface/web/vm/form/openvz_template.tform.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,22 @@
475475
'width' => '30',
476476
'maxlength' => '255'
477477
),
478+
'custom' => array (
479+
'datatype' => 'TEXT',
480+
'formtype' => 'TEXTAREA',
481+
'default' => '',
482+
'value' => '',
483+
'separator' => '',
484+
'width' => '',
485+
'maxlength' => '',
486+
'rows' => '10',
487+
'cols' => '30',
488+
'validators' => array ( 0 => array ('type' => 'CUSTOM',
489+
'class' => 'validate_openvz',
490+
'function' => 'check_custom',
491+
'errmsg'=> 'custom_error'),
492+
),
493+
),
478494
//#################################
479495
// ENDE Datatable fields
480496
//#################################

interface/web/vm/form/openvz_vm.tform.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,23 @@
322322
'width' => '30',
323323
'maxlength' => '255'
324324
),
325+
'custom' => array (
326+
'datatype' => 'TEXT',
327+
'formtype' => 'TEXTAREA',
328+
'default' => '',
329+
'value' => '',
330+
'separator' => '',
331+
'width' => '',
332+
'maxlength' => '',
333+
'rows' => '10',
334+
'cols' => '30',
335+
'searchable' => 2,
336+
'validators' => array ( 0 => array ('type' => 'CUSTOM',
337+
'class' => 'validate_openvz',
338+
'function' => 'check_custom',
339+
'errmsg'=> 'custom_error'),
340+
),
341+
),
325342
//#################################
326343
// ENDE Datatable fields
327344
//#################################

interface/web/vm/lib/lang/ar_openvz_template.lng

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,6 @@ $wb['Template'] = 'Template';
9292
$wb['Advanced'] = 'Advanced';
9393
$wb['features_txt'] = 'Features';
9494
$wb["iptables_txt"] = "IP Tables";
95+
$wb["custom_txt"] = "Custom settings";
96+
$wb["custom_error"] = "Not allowed in Custom settings: ";
9597
?>

interface/web/vm/lib/lang/ar_openvz_vm.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ $wb['Virtual server'] = 'Virtual server';
3939
$wb['Advanced'] = 'Advanced';
4040
$wb['features_txt'] = 'Features';
4141
$wb["iptables_txt"] = "IP Tables";
42+
$wb["custom_txt"] = "Custom settings";
4243
?>

interface/web/vm/lib/lang/bg_openvz_template.lng

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,6 @@ $wb['Template'] = 'Template';
9292
$wb['Advanced'] = 'Advanced';
9393
$wb['features_txt'] = 'Features';
9494
$wb["iptables_txt"] = "IP Tables";
95+
$wb["custom_txt"] = "Custom settings";
96+
$wb["custom_error"] = "Not allowed in Custom settings: ";
9597
?>

interface/web/vm/lib/lang/bg_openvz_vm.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ $wb['Virtual server'] = 'Virtual server';
3939
$wb['Advanced'] = 'Advanced';
4040
$wb['features_txt'] = 'Features';
4141
$wb["iptables_txt"] = "IP Tables";
42+
$wb["custom_txt"] = "Custom settings";
4243
?>

0 commit comments

Comments
 (0)