def add_reverse_proxy(self, name, path, addr, port, block): w = Webapp() w.name = name w.stype = 'ReverseProxy' w.path = path w.addr = addr w.port = port w.dbengine = None w.dbname = None w.dbuser = None if not block: block = [ nginx.Location('/admin/media/', nginx.Key('root', '/usr/lib/python2.7/site-packages/django/contrib') ), nginx.Location('/', nginx.Key('proxy_set_header', 'X-Forwarded-For $proxy_add_x_forwarded_for'), nginx.Key('proxy_set_header', 'Host $http_host'), nginx.Key('proxy_redirect', 'off'), nginx.If('(!-f $request_filename)', nginx.Key('proxy_pass', 'unix:%s'%os.path.join(path, 'gunicorn.sock')), nginx.Key('break', '') ) ) ] self.nginx_add(w, block) self.nginx_enable(w)
def on_submit(self, event, params, vars = None): if params[0] == 'dlgAdd': if vars.getvalue('action', '') == 'OK': self._setup = self._current self._add = None if params[0] == 'dlgEdit': if vars.getvalue('action', '') == 'OK': name = vars.getvalue('cfgname', '') addr = vars.getvalue('cfgaddr', '') port = vars.getvalue('cfgport', '') vaddr = True for site in self.sites: if addr == site.addr and port == site.port: vaddr = False if name == '': self.put_message('err', 'Must choose a name') elif re.search('\.|-|`|\\\\|\/|^test$|[ ]', name): self.put_message('err', 'Site name must not contain spaces, dots, dashes or special characters') elif addr == '': self.put_message('err', 'Must choose an address') elif port == '': self.put_message('err', 'Must choose a port (default 80)') elif port == self.app.gconfig.get('genesis', 'bind_port', ''): self.put_message('err', 'Can\'t use the same port number as Genesis') elif not vaddr: self.put_message('err', 'Site must have either a different domain/subdomain or a different port') elif self._edit.ssl and port == '80': self.put_message('err', 'Cannot set an HTTPS site to port 80') elif not self._edit.ssl and port == '443': self.put_message('err', 'Cannot set an HTTP-only site to port 443') else: w = Webapp() w.name = name w.stype = self._edit.stype w.path = self._edit.path w.addr = addr w.port = port w.ssl = self._edit.ssl w.php = self._edit.php self.mgr.nginx_edit(self._edit, w) self.ncops.change_webapp(self._edit, w) self.put_message('success', 'Site edited successfully') self._edit = None if params[0] == 'dlgSetup': if vars.getvalue('action', '') == 'OK': name = vars.getvalue('name', '').lower() addr = vars.getvalue('addr', '') port = vars.getvalue('port', '80') vname, vaddr = True, True for site in self.sites: if name == site.name: vname = False if addr == site.addr and port == site.port: vaddr = False if not name or not self._setup: self.put_message('err', 'Name or type not selected') elif re.search('\.|-|`|\\\\|\/|^test$|[ ]', name): self.put_message('err', 'Site name must not contain spaces, dots, dashes or special characters') elif addr == '': self.put_message('err', 'Must choose an address') elif port == '': self.put_message('err', 'Must choose a port (default 80)') elif port == self.app.gconfig.get('genesis', 'bind_port', ''): self.put_message('err', 'Can\'t use the same port number as Genesis') elif not vaddr: self.put_message('err', 'Site must have either a different domain/subdomain or a different port') elif not vname: self.put_message('err', 'A site with this name already exists') elif (not hasattr(self._setup, 'dbengines') or not self._setup.dbengines) \ or (vars.has_key('dbtype') and vars.getvalue('dbtype', '') in ['', 'None']): self.addsite(self._setup, vars, {}, True) self._setup = None elif hasattr(self._setup, 'dbengines') and self._setup.dbengines: if vars.getvalue('dbtype', ''): self._setup.selected_dbengine = vars.getvalue('dbtype', '') elif not hasattr(self._setup, 'selected_dbengine'): self._setup.selected_dbengine = self._setup.dbengines[0] dbengine = self._setup.selected_dbengine on = False for dbtype in self.dbops.get_dbtypes(): if dbengine == dbtype[0] and dbtype[2] == True: on = True elif dbengine == dbtype[0] and dbtype[2] == None: on = True if on: if self.dbops.get_info(dbengine).requires_conn and \ not self.dbops.get_dbconn(dbengine): self._dbauth = ('add', dbengine, self._setup, vars) self._setup = None else: if vars.getvalue('dbname') and vars.getvalue('dbpass'): try: self.dbops.get_interface('MariaDB').validate( vars.getvalue('dbname'), vars.getvalue('dbname'), vars.getvalue('dbpass'), self.dbops.get_dbconn(dbengine)) except Exception, e: self.put_message('err', str(e)) return elif vars.getvalue('dbname'): self.put_message('err', 'You must enter a database password if you specify a database name!') return elif vars.getvalue('dbpass'): self.put_message('err', 'You must enter a database name if you specify a database password!') return self.addsite(self._setup, vars, {'engine': dbengine, 'name': vars.getvalue('dbname', vars.getvalue('name')), 'user': vars.getvalue('dbname', vars.getvalue('name')), 'passwd': vars.getvalue('dbpass', '')}, True) self._setup = None else: self.put_message('err', 'The database engine for %s is not running. Please start it via the Status button.' % dbengine) self._setup = None
php = vars.getvalue('php', '') addtoblock = vars.getvalue('addtoblock', '') if addtoblock: addtoblock = nginx.loads(addtoblock, False) else: addtoblock = [] if wa.wa_plugin == 'Website' and php == '1' and addtoblock: addtoblock.extend(x for x in webapp.phpblock) elif wa.wa_plugin == 'Website' and php == '1': addtoblock = webapp.phpblock # Setup the webapp and create an nginx serverblock try: w = Webapp() w.name = name w.stype = wa.wa_plugin w.path = target_path w.addr = vars.getvalue('addr', 'localhost') w.port = vars.getvalue('port', '80') w.php = True if wa.php is True or php is '1' else False self.nginx_add(site=w, add=addtoblock if addtoblock else webapp.addtoblock, ) except Exception, e: raise PartialError('nginx serverblock couldn\'t be written - '+str(e)) try: cat.put_statusmsg('Running post-install configuration...') specialmsg = webapp.post_install(name, target_path, vars)
def on_submit(self, event, params, vars = None): if params[0] == 'dlgSettings': if vars.getvalue('action', '') == 'OK': size = vars.getvalue('uplsize', '10') snhash = vars.getvalue('snhash', '32') f = open('/etc/nginx/nginx.conf', 'r') data = f.readlines() f.close() if 'client_max_body_size' in ''.join(data): for x in enumerate(data): if "client_max_body_size" in x[1]: data[x[0]] = "\tclient_max_body_size %sM;\n" % size else: for x in enumerate(data): if 'http {' in x[1]: data.insert(x[0]+1, '\tclient_max_body_size %sM;\n' % size) if 'server_names_hash_bucket_size' in ''.join(data): for x in enumerate(data): if "server_names_hash_bucket_size" in x[1]: data[x[0]] = "\tserver_names_hash_bucket_size %s;\n" % snhash else: for x in enumerate(data): if 'http {' in x[1]: data.insert(x[0]+1, '\tserver_names_hash_bucket_size %s;\n' % snhash) phpctl = apis.langassist(self.app).get_interface('PHP') if phpctl: phpctl.upload_size(size) open('/etc/nginx/nginx.conf', 'w').writelines(data) self.mgr.nginx_reload() self.put_message("success", "Settings saved successfully") self._settings = None if params[0] == 'dlgAdd': if vars.getvalue('action', '') == 'OK': self._setup = self._current self._add = None if params[0] == 'dlgEdit': if vars.getvalue('action', '') == 'OK': name = vars.getvalue('cfgname', '') addr = vars.getvalue('cfgaddr', '') port = vars.getvalue('cfgport', '') vaddr = True for site in self.sites: if addr == site.addr and port == site.port: vaddr = False if name == '': self.put_message('err', 'Must choose a name') elif re.search('\.|-|`|\\\\|\/|^test$|[ ]', name): self.put_message('err', 'Site name must not contain spaces, dots, dashes or special characters') elif addr == '': self.put_message('err', 'Must choose an address') elif port == '': self.put_message('err', 'Must choose a port (default 80)') elif port == self.app.gconfig.get('genesis', 'bind_port', ''): self.put_message('err', 'Can\'t use the same port number as Genesis') elif not vaddr and (self._edit.addr != addr or self._edit.port != port): self.put_message('err', 'Site must have either a different domain/subdomain or a different port') elif self._edit.ssl and port == '80': self.put_message('err', 'Cannot set an HTTPS site to port 80') elif not self._edit.ssl and port == '443': self.put_message('err', 'Cannot set an HTTP-only site to port 443') else: w = Webapp() w.name = name w.stype = self._edit.stype w.path = self._edit.path w.addr = addr w.port = port w.ssl = self._edit.ssl w.php = self._edit.php try: self.mgr.nginx_edit(self._edit, w) except ReloadError, e: self.put_message("warn", str(e)) else: self.ncops.change_webapp(self._edit, w) self.put_message('success', 'Site edited successfully')
def on_submit(self, event, params, vars=None): if params[0] == 'dlgAdd': if vars.getvalue('action', '') == 'OK': if hasattr(self._current, 'dbengine') and self._current.dbengine: on = False for dbtype in self.dbops.get_dbtypes(): if self._current.dbengine == dbtype[0] and dbtype[ 2] == True: on = True elif self._current.dbengine == dbtype[0] and dbtype[ 2] == None: on = True if on: if self.dbops.get_info(self._current.dbengine).requires_conn and \ not self.dbops.get_dbconn(self._current.dbengine): self._dbauth = (self._current.dbengine, '', 'add') else: self._setup = self._current else: self.put_message( 'err', 'The database engine for %s is not running. Please start it via the Status button.' % self._current.dbengine) else: self._setup = self._current self._add = None if params[0] == 'dlgEdit': if vars.getvalue('action', '') == 'OK': name = vars.getvalue('cfgname', '') addr = vars.getvalue('cfgaddr', '') port = vars.getvalue('cfgport', '') vaddr = True for site in self.sites: if addr == site.addr and port == site.port: vaddr = False if name == '': self.put_message('err', 'Must choose a name') elif re.search('\.|-|`|\\\\|\/|^test$|[ ]', name): self.put_message( 'err', 'Site name must not contain spaces, dots, dashes or special characters' ) elif addr == '': self.put_message('err', 'Must choose an address') elif port == '': self.put_message('err', 'Must choose a port (default 80)') elif port == self.app.gconfig.get('genesis', 'bind_port', ''): self.put_message( 'err', 'Can\'t use the same port number as Genesis') elif not vaddr: self.put_message( 'err', 'Site must have either a different domain/subdomain or a different port' ) else: w = Webapp() w.name = name w.stype = self._edit.stype w.path = self._edit.path w.addr = addr w.port = port w.ssl = self._edit.ssl w.php = self._edit.php self.mgr.nginx_edit(self._edit, w) apis.networkcontrol(self.app).change_webapp(self._edit, w) self._edit = None if params[0] == 'dlgSetup': if vars.getvalue('action', '') == 'OK': name = vars.getvalue('name', '').lower() addr = vars.getvalue('addr', '') port = vars.getvalue('port', '80') vname, vaddr = True, True for site in self.sites: if name == site.name: vname = False if addr == site.addr and port == site.port: vaddr = False if not name or not self._setup: self.put_message('err', 'Name or type not selected') elif re.search('\.|-|`|\\\\|\/|^test$|[ ]', name): self.put_message( 'err', 'Site name must not contain spaces, dots, dashes or special characters' ) elif addr == '': self.put_message('err', 'Must choose an address') elif port == '': self.put_message('err', 'Must choose a port (default 80)') elif port == self.app.gconfig.get('genesis', 'bind_port', ''): self.put_message( 'err', 'Can\'t use the same port number as Genesis') elif not vaddr: self.put_message( 'err', 'Site must have either a different domain/subdomain or a different port' ) elif not vname: self.put_message('err', 'A site with this name already exists') else: w = WAWorker(self, 'add', name, self._current, vars) w.start() self._setup = None if params[0].startswith('dlgAuth'): dbtype = params[0].split('dlgAuth')[1] if vars.getvalue('action', '') == 'OK': login = vars.getvalue('value', '') try: dbauth = self._dbauth self._dbauth = ('', '', '') self.dbops.get_interface(dbtype).connect( store=self.app.session['dbconns'], passwd=login) if dbauth[2] == 'drop': w = WAWorker(self, 'drop', dbauth[1]) w.start() elif dbauth[2] == 'add': self._setup = self._current except DBAuthFail, e: self.put_message('err', str(e)) else: self.put_message('info', 'Website %s cancelled' % self._dbauth[2]) self._dbauth = ('', '', '')
def on_submit(self, event, params, vars = None): if params[0] == 'dlgSettings': if vars.getvalue('action', '') == 'OK': size = vars.getvalue('uplsize', '10') f = open('/etc/nginx/nginx.conf', 'r') data = f.readlines() f.close() if 'client_max_body_size' in ''.join(data): for x in enumerate(data): if "client_max_body_size" in x[1]: data[x[0]] = "\tclient_max_body_size %sM;\n" % size else: for x in enumerate(data): if 'http {' in x[1]: data.insert(x[0]+1, '\tclient_max_body_size %sM;\n' % size) phpctl = apis.langassist(self.app).get_interface('PHP') if phpctl: phpctl.upload_size(size) open('/etc/nginx/nginx.conf', 'w').writelines(data) self.mgr.nginx_reload() self.put_message("success", "Settings saved successfully") self._settings = None if params[0] == 'dlgAdd': if vars.getvalue('action', '') == 'OK': self._setup = self._current self._add = None if params[0] == 'dlgEdit': if vars.getvalue('action', '') == 'OK': name = vars.getvalue('cfgname', '') addr = vars.getvalue('cfgaddr', '') port = vars.getvalue('cfgport', '') vaddr = True for site in self.sites: if addr == site.addr and port == site.port: vaddr = False if name == '': self.put_message('err', 'Must choose a name') elif re.search('\.|-|`|\\\\|\/|^test$|[ ]', name): self.put_message('err', 'Site name must not contain spaces, dots, dashes or special characters') elif addr == '': self.put_message('err', 'Must choose an address') elif port == '': self.put_message('err', 'Must choose a port (default 80)') elif port == self.app.gconfig.get('genesis', 'bind_port', ''): self.put_message('err', 'Can\'t use the same port number as Genesis') elif not vaddr: self.put_message('err', 'Site must have either a different domain/subdomain or a different port') elif self._edit.ssl and port == '80': self.put_message('err', 'Cannot set an HTTPS site to port 80') elif not self._edit.ssl and port == '443': self.put_message('err', 'Cannot set an HTTP-only site to port 443') else: w = Webapp() w.name = name w.stype = self._edit.stype w.path = self._edit.path w.addr = addr w.port = port w.ssl = self._edit.ssl w.php = self._edit.php try: self.mgr.nginx_edit(self._edit, w) except ReloadError, e: self.put_message("warn", str(e)) else: self.ncops.change_webapp(self._edit, w) self.put_message('success', 'Site edited successfully')
php = vars.getvalue('php', '') addtoblock = vars.getvalue('addtoblock', '') if addtoblock: addtoblock = nginx.loads(addtoblock, False) else: addtoblock = [] if wa.wa_plugin == 'Website' and php == '1' and addtoblock: addtoblock.extend(x for x in webapp.phpblock) elif wa.wa_plugin == 'Website' and php == '1': addtoblock = webapp.phpblock # Setup the webapp and create an nginx serverblock try: w = Webapp() w.name = name w.stype = wa.wa_plugin w.path = target_path w.addr = vars.getvalue('addr', 'localhost') w.port = vars.getvalue('port', '80') w.php = True if wa.php is True or php is '1' else False w.version = wa.version.rsplit('-', 1)[0] if wa.website_updates else None w.dbengine = dbinfo['engine'] if dbinfo else None w.dbname = dbinfo['name'] if dbinfo else None w.dbuser = dbinfo['user'] if dbinfo else None self.nginx_add(site=w, add=addtoblock if addtoblock else webapp.addtoblock, ) except Exception, e: raise PartialError('nginx serverblock couldn\'t be written - '+str(e))
def on_submit(self, event, params, vars = None): if params[0] == 'dlgAdd': if vars.getvalue('action', '') == 'OK': if hasattr(self._current, 'dbengine') and self._current.dbengine: on = False for dbtype in self.dbops.get_dbtypes(): if self._current.dbengine == dbtype[0] and dbtype[2] == True: on = True elif self._current.dbengine == dbtype[0] and dbtype[2] == None: on = True if on: if self.dbops.get_info(self._current.dbengine).requires_conn and \ not self.dbops.get_dbconn(self._current.dbengine): self._dbauth = (self._current.dbengine, '', 'add') else: self._setup = self._current else: self.put_message('err', 'The database engine for %s is not running. Please start it via the Status button.' % self._current.dbengine) else: self._setup = self._current self._add = None if params[0] == 'dlgEdit': if vars.getvalue('action', '') == 'OK': name = vars.getvalue('cfgname', '') addr = vars.getvalue('cfgaddr', '') port = vars.getvalue('cfgport', '') vaddr = True for site in self.sites: if addr == site.addr and port == site.port: vaddr = False if name == '': self.put_message('err', 'Must choose a name') elif re.search('\.|-|`|\\\\|\/|^test$|[ ]', name): self.put_message('err', 'Site name must not contain spaces, dots, dashes or special characters') elif addr == '': self.put_message('err', 'Must choose an address') elif port == '': self.put_message('err', 'Must choose a port (default 80)') elif port == self.app.gconfig.get('genesis', 'bind_port', ''): self.put_message('err', 'Can\'t use the same port number as Genesis') elif not vaddr: self.put_message('err', 'Site must have either a different domain/subdomain or a different port') else: w = Webapp() w.name = name w.stype = self._edit.stype w.path = self._edit.path w.addr = addr w.port = port w.ssl = self._edit.ssl w.php = self._edit.php self.mgr.nginx_edit(self._edit, w) apis.networkcontrol(self.app).change_webapp(self._edit, w) self._edit = None if params[0] == 'dlgSetup': if vars.getvalue('action', '') == 'OK': name = vars.getvalue('name', '').lower() addr = vars.getvalue('addr', '') port = vars.getvalue('port', '80') vname, vaddr = True, True for site in self.sites: if name == site.name: vname = False if addr == site.addr and port == site.port: vaddr = False if not name or not self._setup: self.put_message('err', 'Name or type not selected') elif re.search('\.|-|`|\\\\|\/|^test$|[ ]', name): self.put_message('err', 'Site name must not contain spaces, dots, dashes or special characters') elif addr == '': self.put_message('err', 'Must choose an address') elif port == '': self.put_message('err', 'Must choose a port (default 80)') elif port == self.app.gconfig.get('genesis', 'bind_port', ''): self.put_message('err', 'Can\'t use the same port number as Genesis') elif not vaddr: self.put_message('err', 'Site must have either a different domain/subdomain or a different port') elif not vname: self.put_message('err', 'A site with this name already exists') else: w = WAWorker(self, 'add', name, self._current, vars) w.start() self._setup = None if params[0].startswith('dlgAuth'): dbtype = params[0].split('dlgAuth')[1] if vars.getvalue('action', '') == 'OK': login = vars.getvalue('value', '') try: dbauth = self._dbauth self._dbauth = ('','','') self.dbops.get_interface(dbtype).connect( store=self.app.session['dbconns'], passwd=login) if dbauth[2] == 'drop': w = WAWorker(self, 'drop', dbauth[1]) w.start() elif dbauth[2] == 'add': self._setup = self._current except DBAuthFail, e: self.put_message('err', str(e)) else: self.put_message('info', 'Website %s cancelled' % self._dbauth[2]) self._dbauth = ('','','')
php = vars.getvalue('php', '') addtoblock = vars.getvalue('addtoblock', '') if addtoblock: addtoblock = nginx.loads(addtoblock, False) else: addtoblock = [] if wa.wa_plugin == 'Website' and php == '1' and addtoblock: addtoblock.extend(x for x in webapp.phpblock) elif wa.wa_plugin == 'Website' and php == '1': addtoblock = webapp.phpblock # Setup the webapp and create an nginx serverblock try: w = Webapp() w.name = name w.stype = wa.wa_plugin w.path = target_path w.addr = vars.getvalue('addr', 'localhost') w.port = vars.getvalue('port', '80') w.php = True if wa.php is True or php is '1' else False self.nginx_add( site=w, add=addtoblock if addtoblock else webapp.addtoblock, ) except Exception, e: raise PartialError('nginx serverblock couldn\'t be written - ' + str(e)) try: