Example #1
0
function vhosts($noecho = false)
{
    $ldap = new clladp();
    $sock = new sockets();
    $unix = new unix();
    $ApacheGroupware = $sock->GET_INFO("ApacheGroupware");
    if ($ApacheGroupware == null) {
        $ApacheGroupware = 1;
    }
    echo "Starting......: " . date("H:i:s") . " Apache Groupware enabled ? -> {$ApacheGroupware}\n";
    $ApacheGroupwareListenIP = $sock->GET_INFO("ApacheGroupwareListenIP");
    $ApacheGroupWarePort = $sock->GET_INFO("ApacheGroupWarePort");
    $ApacheGroupWarePortSSL = $sock->GET_INFO("ApacheGroupWarePortSSL");
    $SSLStrictSNIVHostCheck = $sock->GET_INFO("SSLStrictSNIVHostCheck");
    $FreeWebsDisableSSLv2 = $sock->GET_INFO("FreeWebsDisableSSLv2");
    $d_path = $unix->APACHE_DIR_SITES_ENABLED();
    if ($ApacheGroupware == 0) {
        $ApacheGroupwareListenIP = $unix->APACHE_ListenDefaultAddress();
        $ApacheGroupWarePort = $sock->GET_INFO("FreeWebListenPort");
        $ApacheGroupWarePortSSL = $sock->GET_INFO("FreeWebListenSSLPort");
        echo "Starting......: " . date("H:i:s") . " Apache Groupware switch to Apache source\n";
        foreach (glob("{$d_path}/groupware-artica-*") as $filename) {
            echo "Starting......: " . date("H:i:s") . " Apache Groupware removing " . basename($filename) . "\n";
        }
    }
    if (!is_numeric($ApacheGroupWarePortSSL)) {
        $ApacheGroupWarePortSSL = 443;
    }
    if (!is_numeric($ApacheGroupWarePort)) {
        $ApacheGroupWarePort = 80;
    }
    if (!is_numeric($FreeWebsDisableSSLv2)) {
        $FreeWebsDisableSSLv2 = 0;
    }
    if ($ApacheGroupwareListenIP == null) {
        $ApacheGroupwareListenIP = "*";
    }
    echo "Starting......: " . date("H:i:s") . " Apache Port....: {$ApacheGroupwareListenIP}:{$ApacheGroupWarePort}\n";
    echo "Starting......: " . date("H:i:s") . " Apache SSL Port: {$ApacheGroupwareListenIP}:{$ApacheGroupWarePortSSL}\n";
    $pattern = "(&(objectclass=apacheConfig)(apacheServerName=*))";
    $attr = array();
    $sr = @ldap_search($ldap->ldap_connection, $ldap->suffix, $pattern, $attr);
    $hash = ldap_get_entries($ldap->ldap_connection, $sr);
    //print_r($hash);
    for ($i = 0; $i < $hash["count"]; $i++) {
        $ApacheGroupWarePort_WRITE = $ApacheGroupWarePort;
        $root = $hash[$i]["apachedocumentroot"][0];
        $apacheservername = trim($hash[$i]["apacheservername"][0]);
        $wwwservertype = trim($hash[$i]["wwwservertype"][0]);
        if ($wwwservertype == "WEBDAV") {
            continue;
        }
        if ($wwwservertype == "BACKUPPC") {
            continue;
        }
        $wwwsslmode = $hash[$i]["wwwsslmode"][0];
        $DirectoryIndex = "index.php";
        $magic_quotes_gpc = "off";
        $adds = null;
        $ssl = null;
        if ($wwwsslmode == "TRUE") {
            $ssl = "\tSSLEngine on\n";
            $ssl = $ssl . "\tSSLCertificateFile {$GLOBALS["SSLKEY_PATH"]}/{$apacheservername}.crt\n";
            $ssl = $ssl . "\tSSLCertificateKeyFile {$GLOBALS["SSLKEY_PATH"]}/{$apacheservername}.key\n";
            if ($FreeWebsDisableSSLv2 == 1) {
                $ssl = $ssl . "\tSSLProtocol -ALL +SSLv3 +TLSv1\n";
                $ssl = $ssl . "\tSSLCipherSuite ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM\n";
            }
            vhosts_BuildCertificate($apacheservername);
            $ApacheGroupWarePort_WRITE = $ApacheGroupWarePortSSL;
            $SSLMODE = true;
            $conf = $conf . "\n<VirtualHost *:{$ApacheGroupWarePort}>\n";
            $conf = $conf . "\tServerName {$apacheservername}\n";
            $conf = $conf . "\tRedirect / https://{$apacheservername}\n";
            $conf = $conf . "</VirtualHost>\n\n";
        }
        $open_basedir = $root;
        if ($wwwservertype == "OBM2") {
            $adds = $adds . "\tSetEnv OBM_INCLUDE_VAR obminclude\n";
            $adds = $adds . "\tAddDefaultCharset ISO-8859-15\n";
            $adds = $adds . "\tphp_value  include_path \".:/usr/share/php:/usr/share/php5:{$root}\"\n";
            $magic_quotes_gpc = "On";
            $DirectoryIndex = "obm.php";
            $alias = "\tAlias /images {$root}/resources\n";
            $root = "{$root}/php";
        }
        if ($wwwservertype == "DRUPAL") {
            $DirectoryIndex = "index.php";
            $adds = null;
            $adds = $adds . "\tAddDefaultCharset ISO-8859-15\n";
            $adds = $adds . "\tAccessFileName .htaccess\n";
            $rewrite[] = "\t\t\t<IfModule mod_rewrite.c>";
            $rewrite[] = "\t\t\t\tRewriteEngine on";
            $rewrite[] = "\t\t\t\tRewriteBase /";
            $rewrite[] = "\t\t\t\tRewriteCond %{REQUEST_FILENAME} !-f";
            $rewrite[] = "\t\t\t\tRewriteCond %{REQUEST_FILENAME} !-d";
            $rewrite[] = "\t\t\t\tRewriteRule ^(.*)\$ index.php?q=\$1 [L,QSA]";
            $rewrite[] = "\t\t\t</IfModule>";
            $rewrite[] = "\t\t\t<FilesMatch \"\\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\\.php)?|xtmpl)\$|^(code-style\\.pl|Entries.*|Repository|Root|Tag|Template)\$\">";
            $rewrite[] = "\t\t\t\tOrder allow,deny";
            $rewrite[] = "\t\t\t\tdeny from all";
            $rewrite[] = "\t\t\t</FilesMatch>";
            $dirplus[] = "\t\t\t<Location /cron.php>";
            $dirplus[] = "\t\t\t\tOrder deny,allow";
            $dirplus[] = "\t\t\t\tdeny from all";
            $dirplus[] = "\t\t\t\tallow from 127.0.0.1";
            $dirplus[] = "\t\t\t\tallow from IP";
            $dirplus[] = "\t\t\t</Location>";
            $root = "/usr/share/drupal";
            @mkdir("/usr/share/drupal/sites/{$apacheservername}/files", 0755, true);
            @chmod("/usr/share/drupal/sites/{$apacheservername}/files", 0777);
        }
        if ($wwwservertype == "SQUID_STATS") {
            $DirectoryIndex = "squid.logon.php";
            $open_basedir = "/usr/share/artica-postfix/ressources:/usr/share/artica-postfix:/usr/share/artica-postfix/framework:{$root}:{$root}/resources:{$root}/ressources/logs";
        }
        if ($wwwservertype == "GROUPOFFICE") {
            $open_basedir = null;
        }
        if ($wwwservertype == "ARTICA_USR") {
            $open_basedir = "/usr/share/artica-postfix/ressources:/usr/share/artica-postfix:/usr/share/artica-postfix/framework:{$root}:{$root}/resources:{$root}/ressources/logs";
        }
        if ($GLOBALS["VERBOSE"]) {
            echo " *** OPENBASE DIR: {$wwwservertype} *** \n";
        }
        if ($GLOBALS["VERBOSE"]) {
            echo " *** OPENBASE DIR: {$open_basedir} *** \n";
        }
        @mkdir("{$root}/php_logs/{$apacheservername}", 0755, true);
        $conf = $conf . "\n\n<VirtualHost {$ApacheGroupwareListenIP}:{$ApacheGroupWarePort_WRITE}>\n";
        $conf = $conf . "\tServerName {$apacheservername}\n";
        $conf = $conf . "\tServerAdmin webmaster@{$apacheservername}\n";
        $conf = $conf . "\tDocumentRoot {$root}\n";
        $conf = $conf . $ssl;
        $conf = $conf . $alias;
        $conf = $conf . $adds;
        $conf = $conf . "\tphp_value  error_log  \"{$root}/php_logs/{$apacheservername}/php.log\"\n";
        if ($open_basedir == null) {
            $conf = $conf . "\tphp_value open_basedir \"{$root}\"\n";
        }
        $conf = $conf . "\tphp_value magic_quotes_gpc {$magic_quotes_gpc}\n";
        $conf = $conf . "\t<Directory \"{$root}\">\n";
        if (is_array($rewrite)) {
            $conf = $conf . @implode("\n", $rewrite) . "\n";
        }
        $conf = $conf . "\t\t\tDirectoryIndex {$DirectoryIndex}\n";
        $conf = $conf . "\t\t\tOptions Indexes FollowSymLinks MultiViews\n";
        $conf = $conf . "\t\t\tAllowOverride all\n";
        $conf = $conf . "\t\t\tOrder allow,deny\n";
        $conf = $conf . "\t\t\tAllow from all\n";
        $conf = $conf . "\t</Directory>\n";
        if (is_array($dirplus)) {
            $conf = $conf . @implode("\n", $dirplus) . "\n";
        }
        $conf = $conf . "\tCustomLog /usr/local/apache-groupware/logs/{$apacheservername}_access.log \"%h %l %u %t \\\"%r\\\" %>s %b \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\" %V\"\n";
        $conf = $conf . "\tErrorLog /usr/local/apache-groupware/logs/{$apacheservername}_err.log\n";
        $conf = $conf . "</VirtualHost>\n";
        if ($ApacheGroupware == 0) {
            $a2ensite = $unix->find_program("a2ensite");
            @mkdir($d_path, 0755, true);
            echo "Starting......: " . date("H:i:s") . " Apache Groupware adding {$d_path}/groupware-artica-{$apacheservername}.conf\n";
            @file_put_contents("{$d_path}/groupware-artica-{$apacheservername}.conf", $conf);
            if (is_file($a2ensite)) {
                shell_exec("{$a2ensite} {$d_path}/groupware-artica-{$apacheservername}.conf");
            }
            $conf = null;
        }
    }
    if ($SSLMODE) {
        if ($SSLStrictSNIVHostCheck == 1) {
            $SSLStrictSNIVHostCheck = "\nSSLStrictSNIVHostCheck off";
        }
        $conf = "Listen {$ApacheGroupWarePortSSL}{$SSLStrictSNIVHostCheck}\nNameVirtualHost *:{$ApacheGroupWarePortSSL}\n" . $conf;
    }
    $mailmanhosts = mailmanhosts();
    if ($ApacheGroupware == 0) {
        echo "Starting......: " . date("H:i:s") . " Apache Groupware adding {$d_path}/groupware-artica-mailmanhosts.conf\n";
        @file_put_contents("{$d_path}/groupware-artica-mailmanhosts.conf", $mailmanhosts);
        $apache2ctl = $unix->LOCATE_APACHE_CTL();
        if (is_file($apache2ctl)) {
            shell_exec("{$apache2ctl} -k restart");
        }
    }
    $conf = $conf . $mailmanhosts;
    if ($noecho) {
        return $conf;
    }
    echo $conf;
}
Example #2
0
function vhosts($noecho = false)
{
    $ldap = new clladp();
    $sock = new sockets();
    $ApacheGroupWarePort = $sock->GET_INFO("ApacheGroupWarePort");
    $SSLStrictSNIVHostCheck = $sock->GET_INFO("SSLStrictSNIVHostCheck");
    $pattern = "(&(objectclass=apacheConfig)(apacheServerName=*))";
    $attr = array();
    $sr = @ldap_search($ldap->ldap_connection, $ldap->suffix, $pattern, $attr);
    $hash = ldap_get_entries($ldap->ldap_connection, $sr);
    //print_r($hash);
    for ($i = 0; $i < $hash["count"]; $i++) {
        $ApacheGroupWarePort_WRITE = $ApacheGroupWarePort;
        $root = $hash[$i]["apachedocumentroot"][0];
        $apacheservername = trim($hash[$i]["apacheservername"][0]);
        $wwwservertype = trim($hash[$i]["wwwservertype"][0]);
        if ($wwwservertype == "WEBDAV") {
            continue;
        }
        if ($wwwservertype == "BACKUPPC") {
            continue;
        }
        $wwwsslmode = $hash[$i]["wwwsslmode"][0];
        $DirectoryIndex = "index.php";
        unset($rewrite);
        unset($dirplus);
        $magic_quotes_gpc = "off";
        $adds = null;
        $ssl = null;
        if ($wwwsslmode == "TRUE") {
            $ssl = "\tSSLEngine on\n";
            $ssl = $ssl . "\tSSLCertificateFile {$GLOBALS["SSLKEY_PATH"]}/{$apacheservername}.crt\n";
            $ssl = $ssl . "\tSSLCertificateKeyFile {$GLOBALS["SSLKEY_PATH"]}/{$apacheservername}.key\n";
            vhosts_BuildCertificate($apacheservername);
            $ApacheGroupWarePort_WRITE = "443";
            $SSLMODE = true;
            $conf = $conf . "\n<VirtualHost *:{$ApacheGroupWarePort}>\n";
            $conf = $conf . "\tServerName {$apacheservername}\n";
            $conf = $conf . "\tRedirect / https://{$apacheservername}\n";
            $conf = $conf . "</VirtualHost>\n\n";
        }
        $open_basedir = $root;
        if ($wwwservertype == "OBM2") {
            $adds = $adds . "\tSetEnv OBM_INCLUDE_VAR obminclude\n";
            $adds = $adds . "\tAddDefaultCharset ISO-8859-15\n";
            $adds = $adds . "\tphp_value  include_path \".:/usr/share/php:/usr/share/php5:{$root}\"\n";
            $magic_quotes_gpc = "On";
            $DirectoryIndex = "obm.php";
            $alias = "\tAlias /images {$root}/resources\n";
            $root = "{$root}/php";
        }
        if ($wwwservertype == "DRUPAL") {
            $DirectoryIndex = "index.php";
            $adds = null;
            $adds = $adds . "\tAddDefaultCharset ISO-8859-15\n";
            $adds = $adds . "\tAccessFileName .htaccess\n";
            $rewrite[] = "\t\t\t<IfModule mod_rewrite.c>";
            $rewrite[] = "\t\t\t\tRewriteEngine on";
            $rewrite[] = "\t\t\t\tRewriteBase /";
            $rewrite[] = "\t\t\t\tRewriteCond %{REQUEST_FILENAME} !-f";
            $rewrite[] = "\t\t\t\tRewriteCond %{REQUEST_FILENAME} !-d";
            $rewrite[] = "\t\t\t\tRewriteRule ^(.*)\$ index.php?q=\$1 [L,QSA]";
            $rewrite[] = "\t\t\t</IfModule>";
            $rewrite[] = "\t\t\t<FilesMatch \"\\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\\.php)?|xtmpl)\$|^(code-style\\.pl|Entries.*|Repository|Root|Tag|Template)\$\">";
            $rewrite[] = "\t\t\t\tOrder allow,deny";
            $rewrite[] = "\t\t\t\tdeny from all";
            $rewrite[] = "\t\t\t</FilesMatch>";
            $dirplus[] = "\t\t\t<Location /cron.php>";
            $dirplus[] = "\t\t\t\tOrder deny,allow";
            $dirplus[] = "\t\t\t\tdeny from all";
            $dirplus[] = "\t\t\t\tallow from 127.0.0.1";
            $dirplus[] = "\t\t\t\tallow from IP";
            $dirplus[] = "\t\t\t</Location>";
            $root = "/usr/share/drupal";
            @mkdir("/usr/share/drupal/sites/{$apacheservername}/files", 0755, true);
            @chmod("/usr/share/drupal/sites/{$apacheservername}/files", 0777);
        }
        if ($wwwservertype == "GROUPOFFICE") {
            $open_basedir = null;
        }
        @mkdir("{$root}/php_logs/{$apacheservername}", 0755, true);
        $conf = $conf . "\n\n<VirtualHost *:{$ApacheGroupWarePort_WRITE}>\n";
        $conf = $conf . "\tServerName {$apacheservername}\n";
        $conf = $conf . "\tServerAdmin webmaster@{$apacheservername}\n";
        $conf = $conf . "\tDocumentRoot {$root}\n";
        $conf = $conf . $ssl;
        $conf = $conf . $alias;
        $conf = $conf . $adds;
        $conf = $conf . "\tphp_value  error_log  \"{$root}/php_logs/{$apacheservername}/php.log\"\n";
        if ($open_basedir != null) {
            $conf = $conf . "\tphp_value open_basedir \"{$root}\"\n";
        }
        $conf = $conf . "\tphp_value magic_quotes_gpc {$magic_quotes_gpc}\n";
        $conf = $conf . "\t<Directory \"{$root}\">\n";
        if (is_array($rewrite)) {
            $conf = $conf . @implode("\n", $rewrite) . "\n";
        }
        $conf = $conf . "\t\t\tDirectoryIndex {$DirectoryIndex}\n";
        $conf = $conf . "\t\t\tOptions Indexes FollowSymLinks MultiViews\n";
        $conf = $conf . "\t\t\tAllowOverride all\n";
        $conf = $conf . "\t\t\tOrder allow,deny\n";
        $conf = $conf . "\t\t\tAllow from all\n";
        $conf = $conf . "\t</Directory>\n";
        if (is_array($dirplus)) {
            $conf = $conf . @implode("\n", $dirplus) . "\n";
        }
        $conf = $conf . "\tCustomLog /usr/local/apache-groupware/logs/{$apacheservername}_access.log \"%h %l %u %t \\\"%r\\\" %>s %b \\\"%{Referer}i\\\" \\\"%{User-Agent}i\\\" %V\"\n";
        $conf = $conf . "\tErrorLog /usr/local/apache-groupware/logs/{$apacheservername}_err.log\n";
        $conf = $conf . "</VirtualHost>\n";
    }
    if ($SSLMODE) {
        if ($SSLStrictSNIVHostCheck == 1) {
            $SSLStrictSNIVHostCheck = "\nSSLStrictSNIVHostCheck off";
        }
        $conf = "Listen 443{$SSLStrictSNIVHostCheck}\nNameVirtualHost *:443\n" . $conf;
    }
    $conf = $conf . mailmanhosts();
    if ($noecho) {
        return $conf;
    }
    echo $conf;
}