Skip to content

Commit 76b6b67

Browse files
author
pedro_morgan
committed
Tidy up theispconfig install function
1 parent 77ab0a9 commit 76b6b67

File tree

1 file changed

+74
-68
lines changed

1 file changed

+74
-68
lines changed

install/lib/installer_base.lib.php

Lines changed: 74 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ function configure_amavis() {
451451
// Executing the postconf commands
452452
foreach($postconf_commands as $cmd) {
453453
$command = "postconf -e '$cmd'";
454-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
454+
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
455455
}
456456

457457
// Append the configuration for amavisd to the master.cf file
@@ -484,13 +484,13 @@ function configure_getmail() {
484484
global $conf;
485485

486486
$command = 'useradd -d '.$conf["dist"]["getmail"]["config_dir"].' getmail';
487-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
487+
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
488488

489489
$command = 'chown -R getmail '.$conf["dist"]["getmail"]["config_dir"];
490-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
490+
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
491491

492492
$command = 'chmod -R 700 '.$conf["dist"]["getmail"]["config_dir"];
493-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
493+
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
494494
}
495495

496496

@@ -535,96 +535,102 @@ function configure_mydns() {
535535

536536
}
537537

538-
function configure_apache() {
539-
global $conf;
540-
541-
// Create the logging directory for the vhost logfiles
542-
exec("mkdir -p /var/log/ispconfig/httpd");
538+
public function configure_apache()
539+
{
540+
//* Create the logging directory for the vhost logfiles
541+
exec('mkdir -p /var/log/ispconfig/httpd');
543542

544543
}
545544

546545

547-
function install_ispconfig() {
548-
global $conf;
549-
550-
// Create the ISPConfig installation directory
551-
$command = "mkdir ".$conf["ispconfig_install_dir"];
552-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
546+
public function install_ispconfig()
547+
{
548+
$install_dir = $this->conf['ispconfig_install_dir'];
549+
550+
//* Create the ISPConfig installation directory
551+
$command = "mkdir $install_dir";
552+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
553553

554-
// Create a ISPConfig user and group
555-
$command = "groupadd ispconfig";
556-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
554+
//* Create a ISPConfig user and group
555+
$command = 'groupadd ispconfig';
556+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
557557

558-
$command = "useradd -g ispconfig -d ".$conf["ispconfig_install_dir"]." ispconfig";
559-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
558+
$command = "useradd -g ispconfig -d $install_dir ispconfig";
559+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
560560

561-
// copy the ISPConfig interface part
562-
$command = "cp -rf ../interface ".$conf["ispconfig_install_dir"];
563-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
561+
//* copy the ISPConfig interface part
562+
$command = "cp -rf ../interface $install_dir";
563+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
564564

565-
// copy the ISPConfig server part
566-
$command = "cp -rf ../server ".$conf["ispconfig_install_dir"];
567-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
565+
//* copy the ISPConfig server part
566+
$command = "cp -rf ../server $install_dir";
567+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
568568

569-
// Create a symlink, so ISPConfig is accessible via web
570-
$command = "ln -s ".$conf["ispconfig_install_dir"]."/interface/web/ /var/www/ispconfig";
571-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
569+
//* Create a symlink, so ISPConfig is accessible via web
570+
$command = "ln -s $install_dir/interface/web/ /var/www/ispconfig";
571+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
572572

573-
// Create the config file for ISPConfig interface
573+
//* Create the config file for ISPConfig interface
574574
$configfile = 'config.inc.php';
575-
if(is_file($conf["ispconfig_install_dir"].'/interface/lib/'.$configfile)) copy($conf["ispconfig_install_dir"].'/interface/lib/'.$configfile,$conf["ispconfig_install_dir"].'/interface/lib/'.$configfile.'~');
576-
$content = rf("tpl/".$configfile.".master");
577-
$content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql"]["ispconfig_user"],$content);
578-
$content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql"]["ispconfig_password"],$content);
579-
$content = str_replace('{mysql_server_database}',$conf["mysql"]["database"],$content);
580-
$content = str_replace('{mysql_server_host}',$conf["mysql"]["host"],$content);
581-
wf($conf["ispconfig_install_dir"].'/interface/lib/'.$configfile,$content);
575+
if(is_file($install_dir.'/interface/lib/'.$configfile)){
576+
copy("$install_dir/interface/lib/$configfile", "$install_dir/interface/lib/$configfile~");
577+
}
578+
$content = rf("tpl/$configfile.master");
579+
$content = str_replace('{mysql_server_ispconfig_user}', $this->conf['mysql']['ispconfig_user'], $content);
580+
$content = str_replace('{mysql_server_ispconfig_password}',$this->conf['mysql']['ispconfig_password'], $content);
581+
$content = str_replace('{mysql_server_database}', $this->conf['mysql']['database'], $content);
582+
$content = str_replace('{mysql_server_host}', $this->conf['mysql']['host'], $content);
583+
wf("$install_dir/interface/lib/$configfile", $content);
582584

583-
// Create the config file for ISPConfig server
585+
//* Create the config file for ISPConfig server
584586
$configfile = 'config.inc.php';
585-
if(is_file($conf["ispconfig_install_dir"].'/server/lib/'.$configfile)) copy($conf["ispconfig_install_dir"].'/server/lib/'.$configfile,$conf["ispconfig_install_dir"].'/interface/lib/'.$configfile.'~');
586-
$content = rf("tpl/".$configfile.".master");
587-
$content = str_replace('{mysql_server_ispconfig_user}',$conf["mysql"]["ispconfig_user"],$content);
588-
$content = str_replace('{mysql_server_ispconfig_password}',$conf["mysql"]["ispconfig_password"],$content);
589-
$content = str_replace('{mysql_server_database}',$conf["mysql"]["database"],$content);
590-
$content = str_replace('{mysql_server_host}',$conf["mysql"]["host"],$content);
591-
$content = str_replace('{server_id}',$conf["server_id"],$content);
592-
wf($conf["ispconfig_install_dir"].'/server/lib/'.$configfile,$content);
587+
if(is_file($install_dir.'/server/lib/'.$configfile)){
588+
copy("$install_dir/server/lib/$configfile", "$install_dir/interface/lib/$configfile~");
589+
}
590+
$content = rf("tpl/$configfile.master");
591+
$content = str_replace('{mysql_server_ispconfig_user}', $this->conf['mysql']['ispconfig_user'], $content);
592+
$content = str_replace('{mysql_server_ispconfig_password}', $this->conf['mysql']['ispconfig_password'], $content);
593+
$content = str_replace('{mysql_server_database}', $this->conf['mysql']['database'], $content);
594+
$content = str_replace('{mysql_server_host}', $this->conf['mysql']['host'], $content);
595+
$content = str_replace('{server_id}', $this->conf['server_id'], $content);
596+
wf("$install_dir/server/lib/$configfile", $content);
593597

594598

595-
// Chmod the files
596-
$command = "chmod -R 750 ".$conf["ispconfig_install_dir"];
597-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
599+
//* Chmod the files
600+
$command = "chmod -R 750 $install_dir";
601+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
598602

599-
// chown the files to the ispconfig user and group
600-
$command = "chown -R ispconfig:ispconfig ".$conf["ispconfig_install_dir"];
601-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
603+
//* chown the files to the ispconfig user and group
604+
$command = "chown -R ispconfig:ispconfig $install_dir";
605+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
602606

603-
// make sure that the server config file (not the interface one) is only readable by the root user
604-
exec('chmod 600 '.$conf["ispconfig_install_dir"].'/server/lib/'.$configfile);
605-
exec('chown root:root '.$conf["ispconfig_install_dir"].'/server/lib/'.$configfile);
607+
//* make sure that the server config file (not the interface one) is only readable by the root user
608+
exec("chmod 600 $install_dir/server/lib/$configfile");
609+
exec("chown root:root $install_dir/server/lib/$configfile");
606610

607611
// TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
608612
// and must be fixed as this will allow the apache user to read the ispconfig files.
609613
// Later this must run as own apache server or via suexec!
614+
$command = 'adduser www-data ispconfig';
615+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
610616

611-
$command = "adduser www-data ispconfig";
612-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
613-
614-
// Make the shell scripts executable
615-
$command = "chmod +x ".$conf["ispconfig_install_dir"]."/server/scripts/*.sh";
616-
caselog($command." &> /dev/null", __FILE__, __LINE__,"EXECUTED: ".$command,"Failed to execute the command ".$command);
617+
//* Make the shell scripts executable
618+
$command = "chmod +x $install_dir/server/scripts/*.sh";
619+
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
617620

618-
// Copy the ISPConfig vhost for the controlpanel
619-
copy('tpl/apache_ispconfig.vhost.master',$conf["dist"]["apache"]["vhost_conf_dir"].'/ispconfig.vhost');
620-
// and create the symlink
621-
if(!is_link($conf["dist"]["apache"]["vhost_conf_enabled_dir"].'/ispconfig.vhost')) {
622-
exec('ln -s '.$conf["dist"]["apache"]["vhost_conf_dir"].'/ispconfig.vhost '.$conf["dist"]["apache"]["vhost_conf_enabled_dir"].'/ispconfig.vhost');
621+
//* Copy the ISPConfig vhost for the controlpanel
622+
//TODO These are missing! should they be "vhost_dist_*_dir" ?
623+
$vhost_conf_dir = $this->conf['dist']['apache']['vhost_conf_dir'];
624+
$vhost_conf_enabled_dir = $this->conf['dist']['apache']['vhost_conf_enabled_dir'];
625+
copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
626+
//* and create the symlink
627+
if(!is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) {
628+
exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/ispconfig.vhost");
623629
}
624-
625630
}
626631

627-
function install_crontab() {
632+
public function install_crontab()
633+
{
628634
global $conf;
629635

630636
// Root Crontab

0 commit comments

Comments
 (0)