Skip to content

Commit a2156eb

Browse files
committed
Added new namevirtualhost port functions to the installer and apache plugin.
1 parent 72ce788 commit a2156eb

File tree

7 files changed

+84
-17
lines changed

7 files changed

+84
-17
lines changed

install/dist/lib/fedora.lib.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,28 @@ public function configure_apache()
521521
$vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
522522

523523
// copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
524-
$content = rf("tpl/apache_ispconfig.conf.master");
525-
$records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
524+
$content = rf('tpl/apache_ispconfig.conf.master');
525+
$records = $this->db->queryAllRecords('SELECT * FROM '.$conf['mysql']['master_database'].'.server_ip WHERE server_id = '.$conf['server_id']." AND virtualhost = 'y'");
526+
526527
if(is_array($records) && count($records) > 0) {
527528
foreach($records as $rec) {
528-
$content .= "NameVirtualHost ".$rec["ip_address"].":80\n";
529-
$content .= "NameVirtualHost ".$rec["ip_address"].":443\n";
529+
if($rec['ip_type'] == 'IPv6') {
530+
$ip_address = '['.$rec['ip_address'].']';
531+
} else {
532+
$ip_address = $rec['ip_address'];
533+
}
534+
$ports = explode(',',$rec['virtualhost_port']);
535+
if(is_array($ports)) {
536+
foreach($ports as $port) {
537+
$port = intval($port);
538+
if($port > 0 && $port < 65536 && $ip_address != '') {
539+
$content .= 'NameVirtualHost '.$ip_address.":".$port."\n";
540+
}
541+
}
542+
}
530543
}
531544
}
545+
532546
$content .= "\n";
533547
wf($vhost_conf_dir.'/ispconfig.conf',$content);
534548

install/dist/lib/opensuse.lib.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,28 @@ public function configure_apache()
535535
$vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
536536

537537
//copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
538-
$content = rf("tpl/apache_ispconfig.conf.master");
539-
$records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
538+
$content = rf('tpl/apache_ispconfig.conf.master');
539+
$records = $this->db->queryAllRecords('SELECT * FROM '.$conf['mysql']['master_database'].'.server_ip WHERE server_id = '.$conf['server_id']." AND virtualhost = 'y'");
540+
540541
if(is_array($records) && count($records) > 0) {
541542
foreach($records as $rec) {
542-
$content .= "NameVirtualHost ".$rec["ip_address"].":80\n";
543-
$content .= "NameVirtualHost ".$rec["ip_address"].":443\n";
543+
if($rec['ip_type'] == 'IPv6') {
544+
$ip_address = '['.$rec['ip_address'].']';
545+
} else {
546+
$ip_address = $rec['ip_address'];
547+
}
548+
$ports = explode(',',$rec['virtualhost_port']);
549+
if(is_array($ports)) {
550+
foreach($ports as $port) {
551+
$port = intval($port);
552+
if($port > 0 && $port < 65536 && $ip_address != '') {
553+
$content .= 'NameVirtualHost '.$ip_address.":".$port."\n";
554+
}
555+
}
556+
}
544557
}
545558
}
559+
546560
$content .= "\n";
547561
wf($vhost_conf_dir.'/ispconfig.conf',$content);
548562

install/lib/installer_base.lib.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,15 +1145,29 @@ public function configure_apache() {
11451145
$vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
11461146

11471147
// copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
1148-
1148+
11491149
$content = rf('tpl/apache_ispconfig.conf.master');
11501150
$records = $this->db->queryAllRecords('SELECT * FROM '.$conf['mysql']['master_database'].'.server_ip WHERE server_id = '.$conf['server_id']." AND virtualhost = 'y'");
1151+
11511152
if(is_array($records) && count($records) > 0) {
11521153
foreach($records as $rec) {
1153-
$content .= 'NameVirtualHost '.$rec['ip_address'].":80\n";
1154-
$content .= 'NameVirtualHost '.$rec['ip_address'].":443\n";
1154+
if($rec['ip_type'] == 'IPv6') {
1155+
$ip_address = '['.$rec['ip_address'].']';
1156+
} else {
1157+
$ip_address = $rec['ip_address'];
1158+
}
1159+
$ports = explode(',',$rec['virtualhost_port']);
1160+
if(is_array($ports)) {
1161+
foreach($ports as $port) {
1162+
$port = intval($port);
1163+
if($port > 0 && $port < 65536 && $ip_address != '') {
1164+
$content .= 'NameVirtualHost '.$ip_address.":".$port."\n";
1165+
}
1166+
}
1167+
}
11551168
}
11561169
}
1170+
11571171
$content .= "\n";
11581172
wf($vhost_conf_dir.'/ispconfig.conf',$content);
11591173

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@
137137
'virtualhost_port' => array (
138138
'datatype' => 'VARCHAR',
139139
'formtype' => 'TEXT',
140-
'default' => '',
140+
'validators' => array ( 0 => array ( 'type' => 'REGEX',
141+
'regex' => '/^([0-9]{1,5}\,{0,1}){1,}$/i',
142+
'errmsg'=> 'error_port_syntax'),
143+
),
144+
'default' => '80,443',
141145
'value' => '',
142146
'separator' => '',
143147
'width' => '15',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ $wb["virtualhost_txt"] = 'HTTP NameVirtualHost';
77
$wb["virtualhost_port_txt"] = 'HTTP Ports';
88
$wb["ip_error_wrong"] = 'The IP address is invalid';
99
$wb["ip_error_unique"] = 'The IP address must be unique';
10+
$wb["error_port_syntax"] = 'Invalid chars in port field, please enter only comma separated numbers. Example: 80,443';
1011
?>

server/conf/apache_ispconfig.conf.master

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ CustomLog "| /usr/local/ispconfig/server/scripts/vlogger -s access.log -t \"%Y%m
5050
Alias /awstats-icon "/usr/share/awstats/icon"
5151

5252
<tmpl_loop name="ip_adresses">
53-
NameVirtualHost {tmpl_var name="ip_address"}:80
54-
NameVirtualHost {tmpl_var name="ip_address"}:443
53+
NameVirtualHost {tmpl_var name="ip_address"}:{tmpl_var name="port"}
5554
</tmpl_loop>
5655

server/plugins-available/apache2_plugin.inc.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,30 @@ function server_ip($event_name,$data) {
11811181
$tpl = new tpl();
11821182
$tpl->newTemplate('apache_ispconfig.conf.master');
11831183
$records = $app->db->queryAllRecords('SELECT * FROM server_ip WHERE server_id = '.$conf['server_id']." AND virtualhost = 'y'");
1184-
1185-
if(count($records) > 0) {
1186-
$tpl->setLoop('ip_adresses',$records);
1184+
1185+
$records_out= array();
1186+
if(is_array($records)) {
1187+
foreach($records as $rec) {
1188+
if($rec['ip_type'] == 'IPv6') {
1189+
$ip_address = '['.$rec['ip_address'].']';
1190+
} else {
1191+
$ip_address = $rec['ip_address'];
1192+
}
1193+
$ports = explode(',',$rec['virtualhost_port']);
1194+
if(is_array($ports)) {
1195+
foreach($ports as $port) {
1196+
$port = intval($port);
1197+
if($port > 0 && $port < 65536 && $ip_address != '') {
1198+
$records_out[] = array('ip_address' => $ip_address, 'port' => $port);
1199+
}
1200+
}
1201+
}
1202+
}
1203+
}
1204+
1205+
1206+
if(count($records_out) > 0) {
1207+
$tpl->setLoop('ip_adresses',$records_out);
11871208
}
11881209

11891210
$vhost_file = escapeshellcmd($web_config['vhost_conf_dir'].'/ispconfig.conf');

0 commit comments

Comments
 (0)