From f85251f7074a90c4b5f2489abbd4bfcd557d783b Mon Sep 17 00:00:00 2001 From: Benjamin Sonntag Date: Fri, 13 Feb 2015 10:49:57 +0100 Subject: [PATCH] adding proper postinst, postrm, install domaines_types in alternc.install instead of SQL script, uninstall properly, setup name-based virtual hosts on apache2 --- debian/alternc-ssl.postrm | 16 +++++--- ssl/Makefile | 2 +- ssl/alternc-ssl.install | 9 ----- ssl/alternc-ssl.install.php | 74 +++++++++++++++++++++++++++++++++++++ ssl/panel/class/m_ssl.php | 4 +- 5 files changed, 87 insertions(+), 18 deletions(-) delete mode 100644 ssl/alternc-ssl.install create mode 100644 ssl/alternc-ssl.install.php diff --git a/debian/alternc-ssl.postrm b/debian/alternc-ssl.postrm index a04820e9..a6c764dd 100755 --- a/debian/alternc-ssl.postrm +++ b/debian/alternc-ssl.postrm @@ -8,13 +8,17 @@ case "$1" in alternc.install || true # don't fail removal if alternc.install bails out # TODO : we don't purge *-ssl vhosts or *-ssl templates, they may break the hosting ... - ;; + if [ -e "$CONFIGFILE" -a -x "/usr/bin/mysql" ]; then + mysql --defaults-file=${CONFIGFILE} -f -e "DELETE FROM domaines_type WHERE name IN ('vhost-ssl,'vhost-mixssl','roundcube-ssl','squirrelmail-ssl','panel-ssl','php52-ssl','php52-mixssl');" + mysql --defaults-file=${CONFIGFILE} -f -e "UPDATE sub_domaines SET web_action='DELETE' WHERE type IN ('vhost-ssl,'vhost-mixssl','roundcube-ssl','squirrelmail-ssl','panel-ssl','php52-ssl','php52-mixssl');" + fi +;; purge) - # but yes, at purge time we should - #if [ -e "$CONFIGFILE" -a -x "/usr/bin/mysql" ]; then - # mysql --defaults-file=${CONFIGFILE} -f -e "DROP TABLE IF EXISTS certificate" - # and other purges... - #fi + # Purge the certificate and alias table: + if [ -e "$CONFIGFILE" -a -x "/usr/bin/mysql" ]; then + mysql --defaults-file=${CONFIGFILE} -f -e "DROP TABLE IF EXISTS certificate;" + mysql --defaults-file=${CONFIGFILE} -f -e "DROP TABLE IF EXISTS certif_alias;" + fi ;; esac diff --git a/ssl/Makefile b/ssl/Makefile index 4930d505..2c9f248d 100755 --- a/ssl/Makefile +++ b/ssl/Makefile @@ -18,7 +18,7 @@ install: install -m 0644 -g root -o root ssl.sql $(DESTDIR)/usr/share/alternc/install/ - install -m 0755 -g root -o root alternc-ssl.install $(DESTDIR)/usr/lib/alternc/install.d/ + install -m 0755 -g root -o root alternc-ssl.install.php $(DESTDIR)/usr/lib/alternc/install.d/ install -m 0755 -g root -o root update_ssl.php $(DESTDIR)/usr/lib/alternc/ # incron install -m 0755 -g root -o root ssl_alias_manager.sh $(DESTDIR)/usr/lib/alternc/ diff --git a/ssl/alternc-ssl.install b/ssl/alternc-ssl.install deleted file mode 100644 index ce2a92dd..00000000 --- a/ssl/alternc-ssl.install +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/php -query("INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibility, enable, only_dns, need_dns, advanced ) VALUES + ('vhost-ssl', 'Locally hosted forcing HTTPS', 'DIRECTORY', '%SUB% IN A @@PUBLIC_IP@@', 'vhost,url,txt,defmx,defmx2,mx,mx2', 'ALL', 0, 0, 0);"); + + $db->query("INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibility, enable, only_dns, need_dns, advanced ) VALUES + ('vhost-mixssl', 'Locally hosted HTTP and HTTPS', 'DIRECTORY', '%SUB% IN A @@PUBLIC_IP@@', 'vhost,url,txt,defmx,defmx2,mx,mx2', 'ALL', 0, 0, 0);"); + + $db->query("INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibility, enable, only_dns, need_dns, advanced ) VALUES + ('panel-ssl', 'AlternC panel access WITH SSL', 'NONE', '%SUB% IN A @@PUBLIC_IP@@', 'ip,ipv6,cname,txt,mx,mx2,defmx,defmx2', 'ALL', 0, 0, 1);"); + + $db - query("SELECT * FROM domaines_type WHERE name='roundcube';"); + if ($db->next_record()) { + $db->query("INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibility, enable, only_dns, need_dns, advanced ) VALUES + ('roundcube-ssl', 'Roundcube Webmail access WITH SSL', 'NONE', '%SUB% IN A @@PUBLIC_IP@@', 'mx,mx2,defmx,defmx2,txt', 'ALL', 0, 0, 1;"); + } else { + $db->query("DELETE FROM domaines_type WHERE name='roundcube-ssl';"); + $db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE type='roundcube-ssl';"); + } + + $db - query("SELECT * FROM domaines_type WHERE name='squirrelmail';"); + if ($db->next_record()) { + $db->query("INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibility, enable, only_dns, need_dns, advanced ) VALUES + ('squirrelmail-ssl', 'Squirrelmail Webmail access WITH SSL', 'NONE', '%SUB% IN A @@PUBLIC_IP@@', 'mx,mx2,defmx,defmx2,txt', 'ALL', 0, 0, 1);"); + } else { + $db->query("DELETE FROM domaines_type WHERE name='squirrelmail-ssl';"); + $db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE type='squirrelmail-ssl';"); + } + + $db - query("SELECT * FROM domaines_type WHERE name='php52';"); + if ($db->next_record()) { + $db->query("INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibility, enable, only_dns, need_dns, advanced ) VALUES + ('php52-ssl', 'php52 forcing HTTPS', 'DIRECTORY', '%SUB% IN A @@PUBLIC_IP@@', 'vhost,url,txt,defmx,defmx2,mx,mx2', 'ALL', 0, 0, 0);"); + $db->query("INSERT IGNORE INTO `domaines_type` (name, description, target, entry, compatibility, enable, only_dns, need_dns, advanced ) VALUES + ('php52-mixssl', 'php52 HTTP and HTTPS', 'DIRECTORY', '%SUB% IN A @@PUBLIC_IP@@', 'vhost,url,txt,defmx,defmx2,mx,mx2', 'ALL', 0, 0, 0);"); + } else { + $db->query("DELETE FROM domaines_type WHERE name='php52-ssl';"); + $db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE type='php52-ssl';"); + $db->query("DELETE FROM domaines_type WHERE name='php52-mixssl';"); + $db->query("UPDATE sub_domaines SET web_action='DELETE' WHERE type='php52-mixssl';"); + } + + // Enable name-based virtual hosts in Apache2 : + $f = fopen("/etc/apache2/ports.conf", "rb"); + if (!$f) { + echo "FATAL: there is no /etc/apache2/ports.conf ! I can't configure name-based virtual hosts\n"; + } else { + $found = false; + while ($s = fgets($f, 1024)) { + if (preg_match("#NameVirtualHost.*443#", $s)) { + $found = true; + break; + } + } + fclose($f); + if (!$found) { + $f = fopen("/etc/apache2/ports.conf", "ab"); + fputs($f, "\n\n NameVirtualHost *:443\n\n\n"); + fclose($f); + } + } + + +} // before-reload diff --git a/ssl/panel/class/m_ssl.php b/ssl/panel/class/m_ssl.php index 4bf75535..bd52a213 100644 --- a/ssl/panel/class/m_ssl.php +++ b/ssl/panel/class/m_ssl.php @@ -46,7 +46,7 @@ class m_ssl { var $myDomainesTypes = array("vhost-ssl", "url-ssl", "panel-ssl", "roundcube-ssl", "squirrelmail-ssl"); - const KEY_REPOSITORY = "/var/lib/alternc/ssl/private/"; + const KEY_REPOSITORY = "/var/lib/alternc/ssl/private"; // ----------------------------------------------------------------- /** @@ -387,7 +387,7 @@ class m_ssl { if (!in_array($type, $this->myDomainesTypes)) { return; // nothing to do : the type is not our to start with ;) } - if ($action == "create") { + if ($action == "postinst") { $err->log("ssl", "update_domain:CREATE($action,$type,$fqdn)"); $offset = 0; $found = false;