Skip to content

Commit 7ed7413

Browse files
committed
Fixed: FS#1149 - Ispconfig(apache) Breaks on bad format SSL certificate
1 parent e631410 commit 7ed7413

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

install/tpl/server.ini.master

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ awstats_pl=/usr/lib/cgi-bin/awstats.pl
5353
awstats_buildstaticpages_pl=/usr/share/awstats/tools/awstats_buildstaticpages.pl
5454
php_ini_path_apache=/etc/php5/apache2/php.ini
5555
php_ini_path_cgi=/etc/php5/cgi/php.ini
56+
check_apache_config=y
5657

5758
[dns]
5859
bind_user=root

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@
376376
'default' => '20',
377377
'value' => array('10' => 'Medium', '20' => 'High')
378378
),
379+
'check_apache_config' => array (
380+
'datatype' => 'VARCHAR',
381+
'formtype' => 'CHECKBOX',
382+
'default' => 'y',
383+
'value' => array(0 => 'n',1 => 'y')
384+
),
379385
'user' => array (
380386
'datatype' => 'VARCHAR',
381387
'formtype' => 'TEXT',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,5 @@ $wb["backup_dir_txt"] = 'Backup directory';
7373
$wb["named_conf_local_path_txt"] = 'BIND named.conf.local path';
7474
$wb["php_ini_path_cgi_txt"] = 'CGI php.ini path';
7575
$wb["php_ini_path_apache_txt"] = 'Apache php.ini path';
76+
$wb["check_apache_config_txt"] = 'Test apache configuration on restart';
7677
?>

interface/web/admin/templates/server_config_web_edit.htm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ <h2><tmpl_var name="list_head_txt"></h2>
3333
</select>
3434
</div>
3535
</div>
36+
<div class="ctrlHolder">
37+
<p class="label">{tmpl_var name='check_apache_config_txt'}</p>
38+
<div class="multiField">
39+
{tmpl_var name='check_apache_config'}
40+
</div>
41+
</div>
3642
<div class="ctrlHolder">
3743
<label for="user">{tmpl_var name='web_user_txt'}</label>
3844
<input name="user" id="user" value="{tmpl_var name='user'}" size="40" maxlength="255" type="text" class="textInput" />

server/plugins-available/apache2_plugin.inc.php

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ function update($event_name,$data) {
825825
}
826826

827827
$vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["new"]["domain"].'.vhost');
828+
//* Make a backup copy of vhost file
829+
copy($vhost_file,$vhost_file.'~');
830+
831+
//* Write vhost file
828832
file_put_contents($vhost_file,$tpl->grab());
829833
$app->log("Writing the vhost file: $vhost_file",LOGLEVEL_DEBUG);
830834
unset($tpl);
@@ -879,14 +883,36 @@ function update($event_name,$data) {
879883
if($data["new"]["stats_type"] == 'awstats' && $data["new"]["type"] == "vhost") {
880884
$this->awstats_update($data,$web_config);
881885
}
886+
887+
if($web_config['check_apache_config'] == 'y') {
888+
//* Test if apache starts with the new configuration file
889+
$apache_online_status_before_restart = $this->_checkTcp('localhost',80);
890+
$app->log("Apache status is: ".$apache_online_status_before_restart,LOGLEVEL_DEBUG);
882891

883-
884-
if($apache_chrooted) {
885-
$app->services->restartServiceDelayed('httpd','restart');
892+
$app->services->restartService('httpd','restart');
893+
894+
//* Check if apache restarted successfully if it was online before
895+
$apache_online_status_after_restart = $this->_checkTcp('localhost',80);
896+
$app->log("Apache online status after restart is: ".$apache_online_status_after_restart,LOGLEVEL_DEBUG);
897+
if($apache_online_status_before_restart && !$apache_online_status_after_restart) {
898+
$app->log("Apache did not restart after the configuration change for website ".$data["new"]["domain"].' Reverting the configuration. Saved not working config as '.$vhost_file.'.err',LOGLEVEL_WARN);
899+
copy($vhost_file,$vhost_file.'.err');
900+
copy($vhost_file.'~',$vhost_file);
901+
$app->services->restartService('httpd','restart');
902+
}
886903
} else {
887-
// request a httpd reload when all records have been processed
888-
$app->services->restartServiceDelayed('httpd','reload');
904+
//* We do not check the apache config after changes (is faster)
905+
if($apache_chrooted) {
906+
$app->services->restartServiceDelayed('httpd','restart');
907+
} else {
908+
// request a httpd reload when all records have been processed
909+
$app->services->restartServiceDelayed('httpd','reload');
910+
}
889911
}
912+
913+
// Remove the backup copy of the config file.
914+
unlink($vhost_file.'~');
915+
890916

891917
//* Unset action to clean it for next processed vhost.
892918
$this->action = '';
@@ -1283,6 +1309,18 @@ private function _exec($command) {
12831309
$app->log("exec: ".$command,LOGLEVEL_DEBUG);
12841310
exec($command);
12851311
}
1312+
1313+
private function _checkTcp ($host,$port) {
1314+
1315+
$fp = @fsockopen ($host, $port, $errno, $errstr, 2);
1316+
1317+
if ($fp) {
1318+
fclose($fp);
1319+
return true;
1320+
} else {
1321+
return false;
1322+
}
1323+
}
12861324

12871325

12881326
} // end class

0 commit comments

Comments
 (0)