diff --git a/ee/cli/controllers/base.py b/ee/cli/controllers/base.py index d0ec86f2..4ccc2869 100644 --- a/ee/cli/controllers/base.py +++ b/ee/cli/controllers/base.py @@ -32,3 +32,16 @@ class EEBaseController(CementBaseController): # The 'default.mustache' file would be loaded from # ``ee.cli.templates``, or ``/var/lib/ee/templates/``. # + # ViMbAdmin Nginx configuration + data = dict(site_name='webmail', www_domain='webmail', static=False, + basic=True, wp=False, w3tc=False, wpfc=False, + wpsc=False, multisite=False, wpsubdir=False, + webroot='/var/www', ee_db_name='', + ee_db_user='', ee_db_pass='', ee_db_host='', + rc=True) + self.app.log.debug('Writting the nginx configration for' + ' ViMbAdmin') + ee_rc = open('/etc/nginx/sites-available/webmail.conf', 'w') + self.app.render((data), 'virtualconf.mustache', + out=ee_rc) + ee_rc.close() diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index a847c163..e8a4015c 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -13,6 +13,7 @@ from ee.core.mysql import EEMysql from ee.core.addswap import EESwap from ee.core.git import EEGit from pynginxconfig import NginxConfig +from ee.core.services import EEService import random import string import configparser @@ -144,7 +145,8 @@ class EEStackController(CementBaseController): if set(EEVariables.ee_postfix).issubset(set(apt_packages)): EEGit.add(self, ["/etc/postfix"], msg="Adding Postfix into Git") - pass + EEService.reload_service(self, ['postfix']) + if set(EEVariables.ee_nginx).issubset(set(apt_packages)): if ((not os.path.isfile('/etc/nginx/conf.d/ee-nginx.conf')) and os.path.isfile('/etc/nginx/nginx.conf')): @@ -253,8 +255,74 @@ class EEStackController(CementBaseController): self.app.render((data), 'wpsubdir.mustache', out=ee_nginx) ee_nginx.close() + + # 22222 port settings + self.app.log.debug('Writting the nginx configration to' + 'file /etc/nginx/common/22222.conf') + ee_nginx = open('/etc/nginx/common/22222.conf', 'w') + self.app.render((data), '22222.mustache', + out=ee_nginx) + ee_nginx.close() + + passwd = ''.join([random.choice + (string.ascii_letters + string.digits) + for n in range(6)]) + EEShellExec.cmd_exec(self, "printf \"easyengine:" + "$(openssl passwd -crypt " + "{password} 2> /dev/null)\n\"" + "> /etc/nginx/htpasswd-ee 2>/dev/null" + .format(password=passwd)) + + # Create Symbolic link for 22222 + EEFileUtils.create_symlink(self, ['/etc/nginx/' + 'sites-available/' + '22222.conf', + '/etc/nginx/' + 'sites-enabled/' + '22222.conf']) + # Create log and cert folder and softlinks + if not os.path.exists('/var/www/22222/logs'): + os.makedirs('/var/www/22222/logs') + + if not os.path.exists('/var/www/22222/cert'): + os.makedirs('/var/www/22222/cert') + + EEFileUtils.create_symlink(self, ['/var/log/nginx/' + '22222.access.log', + '/var/www/22222/' + 'logs/access.log']) + + EEFileUtils.create_symlink(self, ['/var/log/nginx/' + '22222.error.log', + '/var/www/22222/' + 'logs/error.log']) + + EEShellExec.cmd_exec(self, "openssl genrsa -out " + "/var/www/22222/cert/22222.key 2048") + EEShellExec.cmd_exec(self, "openssl req -new -batch -subj " + "/commonName=127.0.0.1/ -key " + "/var/www/22222/cert/22222.key " + "-out /var/www/22222/cert/" + "22222.csr") + + EEFileUtils.mvfile(self, "/var/www/22222/cert/22222.key", + "/var/www/22222/cert/" + "22222.key.org") + + EEShellExec.cmd_exec(self, "openssl rsa -in " + "/var/www/22222/cert/" + "22222.key.org -out " + "/var/www/22222/cert/22222.key") + + EEShellExec.cmd_exec(self, "openssl x509 -req -days 3652 " + "-in /var/www/22222/cert/" + "22222.csr -signkey /var/www/" + "22222/cert/22222.key -out " + "/var/www/22222/cert/22222.crt") + # Nginx Configation into GIT EEGit.add(self, ["/etc/nginx"], msg="Adding Nginx into Git") + EEService.reload_service(self, ['nginx']) if set(EEVariables.ee_php).issubset(set(apt_packages)): # Create log directories @@ -316,6 +384,7 @@ class EEStackController(CementBaseController): " /etc/php5/fpm/pool.d/debug.conf") config.write(confifile) EEGit.add(self, ["/etc/php5"], msg="Adding PHP into Git") + EEService.reload_service(self, ['php5-fpm']) if set(EEVariables.ee_mysql).issubset(set(apt_packages)): # TODO: Currently we are using, we need to remove it in future @@ -340,6 +409,7 @@ class EEStackController(CementBaseController): "/etc/mysql/my.cnf") EEGit.add(self, ["/etc/mysql"], msg="Adding Nginx into Git") + EEService.reload_service(self, ['mysql']) if set(EEVariables.ee_mail).issubset(set(apt_packages)): self.app.log.debug("Executing mail commands") @@ -452,6 +522,7 @@ class EEStackController(CementBaseController): "default.sieve") EEGit.add(self, ["/etc/postfix", "/etc/dovecot"], msg="Installed mail server") + EEService.reload_service(self, ['dovecot', 'postfix']) if set(EEVariables.ee_mailscanner).issubset(set(apt_packages)): # Set up Custom amavis configuration @@ -487,6 +558,8 @@ class EEStackController(CementBaseController): self.app.log.debug("Restarting service clamav-daemon") EEShellExec.cmd_exec(self, "service clamav-daemon restart") EEGit.add(self, ["/etc/amavis"], msg="Adding Amvis into Git") + EEService.reload_service(self, ['dovecot', 'amavis', + 'postfix']) if len(packages): if any('/usr/bin/wp' == x[1] for x in packages): @@ -703,6 +776,8 @@ class EEStackController(CementBaseController): self.app.render((data), '50-user.mustache', out=vm_config) vm_config.close() + EEService.reload_service(self, ['nginx', 'php5-fpm', + 'dovecot']) if any('/tmp/roundcube.tar.gz' == x[1] for x in packages): # Extract RoundCubemail @@ -752,6 +827,41 @@ class EEStackController(CementBaseController): "=4190;\" >> /var/www/roundcubemail" "/htdocs/config/config.inc.php") + data = dict(site_name='webmail', www_domain='webmail', + static=False, + basic=True, wp=False, w3tc=False, wpfc=False, + wpsc=False, multisite=False, wpsubdir=False, + webroot='/var/www', ee_db_name='', + ee_db_user='', ee_db_pass='', ee_db_host='', + rc=True) + + self.app.log.debug('Writting the nginx configration for' + ' RoundCubemail') + ee_rc = open('/etc/nginx/sites-available/webmail.conf', 'w') + self.app.render((data), 'virtualconf.mustache', + out=ee_rc) + ee_rc.close() + + # Create Symbolic link for webmail.conf + EEFileUtils.create_symlink(self, ['/etc/nginx/sites-available' + '/webmail.conf', + '/etc/nginx/sites-enabled/' + 'webmail.conf']) + # Create log folder and softlinks + if not os.path.exists('/var/www/roundcubemail/logs'): + os.makedirs('/var/www/roundcubemail/logs') + + EEFileUtils.create_symlink(self, ['/var/log/nginx/' + 'webmail.access.log', + '/var/www/roundcubemail/' + 'logs/access.log']) + + EEFileUtils.create_symlink(self, ['/var/log/nginx/' + 'webmail.error.log', + '/var/www/roundcubemail/' + 'logs/error.log']) + EEService.reload_service(self, ['nginx']) + @expose() def install(self, packages=[], apt_packages=[]): if self.app.pargs.web: diff --git a/ee/cli/templates/22222.mustache b/ee/cli/templates/22222.mustache new file mode 100644 index 00000000..ab6d6a5c --- /dev/null +++ b/ee/cli/templates/22222.mustache @@ -0,0 +1,61 @@ +# EasyEngine admin NGINX CONFIGURATION + +server { + + listen 22222 default_server ssl spdy; + + access_log /var/log/nginx/22222.access.log rt_cache; + error_log /var/log/nginx/22222.error.log; + + ssl_certificate /var/www/22222/cert/22222.crt; + ssl_certificate_key /var/www/22222/cert/22222.key; + + # Force HTTP to HTTPS + error_page 497 =200 https://$host:22222$request_uri; + + root /var/www/22222/htdocs; + index index.php index.htm index.html; + + # Turn on directory listing + autoindex on; + + location / { + include common/acl.conf; + try_files $uri $uri/ /index.php?$args; + } + + location = /fpm/status/ {} + + location ~ /fpm/status/(.*) { + include fastcgi_params; + fastcgi_param SCRIPT_NAME /status; + fastcgi_pass $1; + } + + location ~ \.php$ { + include common/acl.conf; + try_files $uri =404; + include fastcgi_params; + fastcgi_pass php; + } + + # ViMbAdmin Rules + location = /vimbadmin/ { + return 301 $scheme://$host:22222/vimbadmin/public/; + } + + location ~* \.(js|css|jpg|gif|png)$ { + root /var/www/22222/htdocs/; + } + + location ~* /vimbadmin/public/(.*)/(.*) { + root /var/www/22222/htdocs/vimbadmin/public; + try_files $uri $uri/ /vimbadmin/public/index.php?$args; + } + + location ~* /vimbadmin/public/(.*) { + root /var/www/22222/htdocs/vimbadmin/public; + try_files $uri $uri/ /vimbadmin/public/index.php?$args; + } + +} diff --git a/ee/cli/templates/virtualconf.mustache b/ee/cli/templates/virtualconf.mustache index fa29eb4a..cadb946b 100644 --- a/ee/cli/templates/virtualconf.mustache +++ b/ee/cli/templates/virtualconf.mustache @@ -6,7 +6,7 @@ server { # listen 80 default_server; {{/multisite}} - server_name {{^vma}}{{^rc}}{{site_name}}{{/rc}}{{/vma}} {{#vma}}vma.*{{/vma}} {{#rc}}webmail.*{{/rc}} {{#multisite}}*{{/multisite}}{{^multisite}}www{{/multisite}}.{{^vma}}{{^rc}}{{site_name}}{{/rc}}{{/vma}}; + server_name {{^vma}}{{^rc}}{{site_name}}{{/rc}}{{/vma}} {{#vma}}vma.*{{/vma}} {{#rc}}webmail.*{{/rc}} {{^vma}}{{^rc}}{{#multisite}}*{{/multisite}}{{^multisite}}www{{/multisite}}.{{site_name}}{{/rc}}{{/vma}}; {{#multisite}} # Uncomment the following line for domain mapping diff --git a/ee/core/fileutils.py b/ee/core/fileutils.py index 654970ca..99e3d6f9 100644 --- a/ee/core/fileutils.py +++ b/ee/core/fileutils.py @@ -32,12 +32,15 @@ class EEFileUtils(): def create_symlink(self, paths): src = paths[0] dst = paths[1] - try: - os.symlink(src, dst) - except Exception as e: - self.app.log.error("Unable to create symbolic link ...\n {0} {1}" - .format(e.errno, e.strerror)) - sys.exit(1) + if not os.path.islink(dst): + try: + os.symlink(src, dst) + except Exception as e: + self.app.log.error("Unable to create symbolic link ...\n {0}" + " {1}".format(e.errno, e.strerror)) + sys.exit(1) + else: + self.app.log.debug("Destination: {0} exists".format(dst)) def remove_symlink(self, filepath): try: