From 70ba7cbcc20085e18890e5950b8b1e8c6c5c6ae4 Mon Sep 17 00:00:00 2001 From: harshadyeola Date: Thu, 8 Jan 2015 16:25:59 +0530 Subject: [PATCH] sqlite db for site information --- config/plugins.d/site.conf | 1 + ee/cli/plugins/site.py | 35 ++++++++++++- ee/cli/plugins/sitedb.py | 71 +++++++++++++++++++++++++++ ee/cli/templates/virtualconf.mustache | 6 ++- 4 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 ee/cli/plugins/sitedb.py diff --git a/config/plugins.d/site.conf b/config/plugins.d/site.conf index 2fb468fe..0dad9ff0 100644 --- a/config/plugins.d/site.conf +++ b/config/plugins.d/site.conf @@ -6,3 +6,4 @@ ### `ee.cli.plugins.example` or from the file path ### `/var/lib/ee/plugins/example.py` enable_plugin = true +db_path = sqlite:////var/lib/ee/ee.sqlite diff --git a/ee/cli/plugins/site.py b/ee/cli/plugins/site.py index 11f590a5..eb3fec4f 100644 --- a/ee/cli/plugins/site.py +++ b/ee/cli/plugins/site.py @@ -6,6 +6,7 @@ from ee.core.domainvalidate import ValidateDomain from ee.core.fileutils import EEFileUtils from ee.cli.plugins.site_functions import * from ee.core.services import EEService +from ee.cli.plugins.sitedb import * import sys import os @@ -115,7 +116,7 @@ class EESiteCreateController(CementBaseController): # self.app.render((data), 'default.mustache') # Check domain name validation (ee_domain, - ee_www_domain) = ValidateDomain(self.app.pargs.site_name) + ee_www_domain, ) = ValidateDomain(self.app.pargs.site_name) ee_site_webroot = EEVariables.ee_webroot + ee_domain # Check if doain previously exists or not @@ -135,6 +136,8 @@ class EESiteCreateController(CementBaseController): static=True, basic=False, wp=False, w3tc=False, wpfc=False, wpsc=False, multisite=False, wpsubdir=False, webroot=ee_site_webroot) + stype = 'html' + cache = 'basic' #PHP if (self.app.pargs.php and not (self.app.pargs.html or @@ -145,6 +148,8 @@ class EESiteCreateController(CementBaseController): static=False, basic=True, wp=False, w3tc=False, wpfc=False, wpsc=False, multisite=False, wpsubdir=False, webroot=ee_site_webroot) + stype = 'php' + cache = 'basic' #ySQL if (self.app.pargs.mysql and not (self.app.pargs.html or self.app.pargs.php or self.app.pargs.wp or self.app.pargs.w3tc @@ -156,6 +161,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=False, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'mysql' + cache = 'basic' #WP if ((self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or self.app.pargs.wpsc) and not (self.app.pargs.html or @@ -169,6 +176,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=False, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'wp' + cache = 'basic' if (self.app.pargs.w3tc and not (self.app.pargs.wpfc or self.app.pargs.wpsc)): data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -177,6 +186,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=False, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'wp' + cache = 'w3tc' if (self.app.pargs.wpfc and not (self.app.pargs.wpsc or self.app.pargs.w3tc)): data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -185,6 +196,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=False, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'wp' + cache = 'wpfc' if (self.app.pargs.wpsc and not (self.app.pargs.w3tc or self.app.pargs.wpfc)): data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -193,6 +206,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=False, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'wp' + cache = 'wpsc' #WPSUBDIR if (self.app.pargs.wpsubdir and not (self.app.pargs.html or self.app.pargs.php or self.app.pargs.mysql or @@ -205,6 +220,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=True, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'wpsubdir' + cache = 'basic' if (self.app.pargs.w3tc and not (self.app.pargs.wpfc or self.app.pargs.wpsc)): data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -213,6 +230,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=True, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'wpsubdir' + cache = 'w3tc' if (self.app.pargs.wpfc and not (self.app.pargs.wpsc or self.app.pargs.w3tc)): data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -221,6 +240,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=True, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'wpsubdir' + cache = 'wpfc' if (self.app.pargs.wpsc and not (self.app.pargs.w3tc or self.app.pargs.wpfc)): data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -229,6 +250,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=True, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'wpsubdir' + cache = 'wpsc' #WPSUBDOAIN if (self.app.pargs.wpsubdomain and not (self.app.pargs.html or self.app.pargs.php or self.app.pargs.mysql or @@ -241,6 +264,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=False, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'wpsubdomain' + cache = 'basic' if (self.app.pargs.w3tc and not (self.app.pargs.wpfc or self.app.pargs.wpsc)): data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -249,6 +274,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=False, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'wpsubdomain' + cache = 'w3tc' if (self.app.pargs.wpfc and not (self.app.pargs.wpsc or self.app.pargs.w3tc)): data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -257,6 +284,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=False, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'wpsubdomain' + cache = 'wpfc' if (self.app.pargs.wpsc and not (self.app.pargs.w3tc or self.app.pargs.wpfc)): data = dict(site_name=ee_domain, www_domain=ee_www_domain, @@ -265,6 +294,8 @@ class EESiteCreateController(CementBaseController): wpsubdir=False, webroot=ee_site_webroot, ee_db_name='', ee_db_user='', ee_db_pass='', ee_db_host='') + stype = 'wpsubdomain' + cache = 'wpsc' # setup NGINX configuration, and webroot SetupDomain(self, data) @@ -283,6 +314,7 @@ class EESiteCreateController(CementBaseController): data['ee_db_pass'], data['ee_db_host'])) eedbconfig.close() + stype = mysql except IOError as e: self.app.log.error("Unable to create ee-config.php for " "{2} ({0}): {1}" @@ -300,6 +332,7 @@ class EESiteCreateController(CementBaseController): " {0}".format(ee_wp_creds['wp_user'])+'\033[0m') Log.info(self, "WordPress Admin User Password : {0}" .format(ee_wp_creds['wp_pass'])) + addNewSite(self, ee_www_domain, stype, cache, ee_site_webroot) Log.info(self, "Successfully created site" " http://{0}".format(ee_www_domain)) diff --git a/ee/cli/plugins/sitedb.py b/ee/cli/plugins/sitedb.py new file mode 100644 index 00000000..4fd1a322 --- /dev/null +++ b/ee/cli/plugins/sitedb.py @@ -0,0 +1,71 @@ +from sqlalchemy import Column, DateTime, String, Integer, Boolean +from sqlalchemy import ForeignKey, func +from sqlalchemy.orm import relationship, backref +from sqlalchemy.ext.declarative import declarative_base +from ee.core.logging import Log +import sys + +Base = declarative_base() + + +class SiteDB(Base): + __tablename__ = 'Site' + id = Column(Integer, primary_key=True) + sitename = Column(String, unique=True) + + site_type = Column(String) + cache_type = Column(String) + site_path = Column(String) + + # Use default=func.now() to set the default created time + # of a site to be the current time when a + # Site record was created + + created_on = Column(DateTime, default=func.now()) + site_enabled = Column(Boolean, unique=False, default=True, nullable=False) + is_ssl = Column(Boolean, unique=False, default=False) + storage_fs = Column(String) + storage_db = Column(String) + + # def __init__(self): + # from sqlalchemy import create_engine + # self.engine = create_engine('sqlite:///orm_in_detail.sqlite') + +# if __name__ == "__main__": +# +# from sqlalchemy import create_engine +# engine = create_engine('sqlite:///orm_in_detail.sqlite') +# from sqlalchemy.orm import sessionmaker +# session = sessionmaker() +# session.configure(bind=engine) +# Base.metadata.create_all(engine) +# s = session() +# newRec = SiteDB(sitename='exa.in', site_type='wp', cache_type='basic', + # site_path='/var/www', site_enabled=True, is_ssl=False, storage_fs='ext4', + # storage_db='mysql') +# s.add(newRec) +# s.commit() +# s.flush() + + +def addNewSite(self, site, stype, cache, path, + enabled=True, ssl=False, fs='ext4', db='mysql'): + db_path = self.app.config.get('site', 'db_path') + try: + from sqlalchemy import create_engine + engine = create_engine(db_path) + from sqlalchemy.orm import sessionmaker + session = sessionmaker() + session.configure(bind=engine) + Base.metadata.create_all(engine) + s = session() + newRec = SiteDB(sitename=site, site_type=stype, cache_type=cache, + site_path=path, site_enabled=enabled, is_ssl=ssl, + storage_fs=fs, storage_db=db) + s.add(newRec) + s.commit() + s.flush() + except Exception as e: + Log.error(self, "Unable to add site to database : {0}" + .format(e)) + sys.exit(1) diff --git a/ee/cli/templates/virtualconf.mustache b/ee/cli/templates/virtualconf.mustache index 3f6790fc..fa29eb4a 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 {{site_name}} {{#multisite}}*{{/multisite}}{{^multisite}}www{{/multisite}}.{{site_name}}; + 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}}; {{#multisite}} # Uncomment the following line for domain mapping @@ -15,7 +15,9 @@ server { access_log /var/log/nginx/{{site_name}}.access.log {{^static}}rt_cache{{/static}}; error_log /var/log/nginx/{{site_name}}.error.log; - root {{webroot}}/htdocs; + {{^vma}}{{^rc}}root {{webroot}}/htdocs;{{/rc}}{{/vma}} + {{#vma}}root /var/www/22222/htdocs/vimbadmin/public;{{/vma}} + {{#rc}}root /var/www/roundcubemail/htdocs/;{{/rc}} index {{^static}}index.php{{/static}} index.html index.htm;