def __init__(self): InstallCommand.__init__(self) self.cron_acl_sudo = "#!/bin/sh" with open(files.get_rel_path("data/cron_acl.tpl")) as f: cron_acl_tpl = Template(f.read()) self.cron_acl_sudo = cron_acl_tpl.safe_substitute(group="sudo", site_path="/data/www") self.cron_acl_dev_team = "#!/bin/sh" if CONFIG.is_set('site','ldap_dev_team'): with open(files.get_rel_path("data/cron_dev_team.tpl")) as f: cron_acl_tpl = Template(f.read()) self.cron_acl_dev_team = cron_acl_tpl.safe_substitute(group=CONF_MAP('site','ldap_dev_team')) self.packages = "acl" self.add_package(self.packages) self.add_folder('/etc/cron.acl') self.add_file('/etc/crontab', ck_func=self.check_acl_crontab, fix_func=self.fix_acl_crontab) self.add_file('/etc/cron.acl/sudo', ck_func=self.check_perm_cron, fix_func=self.fix_perm_cron, perm={'u':'rx', 'g':'rx', 'o':'rx'}) self.add_file('/etc/cron.acl/ldap_dev_team', ck_func=self.check_perm_dev_team, fix_func=self.fix_perm_dev_team, perm={'u':'rx', 'g':'rx', 'o':'rx'})
def to_dev(self, args): completed = False args.remove("todev") site_name = self.ask_site_name(self.get_next_arg(args)) if not self.is_conf_exists(site_name): completed = True print t("Sorry, the site '%s' does not exists.") % site_name return completed self.load(site_name) site_path, root_path, log_path, upload_tmp_path = self.generate_dir() errors = False if self.conf.get("mysql", "enabled"): schema = self.conf.get("mysql", "schema") # user = self.conf.get('mysql', 'user') # password = self.conf.get('mysql', 'pass') if inputs.get_input_yesno(t("The schema '%s' will be converted. Continue?") % schema): filename = "/tmp/site_convert_todev_%s" % uuid.uuid4() if not (self.dump_bd(filename) and self.schema_todev(filename) and self.restore_bd(filename)): L.error(t("Fail to convert schema")) errors = True files.rm(filename) if errors and not inputs.get_input_yesno(t("There was some errors. Continue?")): completed = False return completed if inputs.get_input_yesno(t("The files under %s will be converted. Continue??") % root_path): site_name = self.conf.get("main", "site_name") site_dev_name = self.conf.get("main", "site_dev_name") site_name_escape = site_name.replace(".", "\.") file_list = self.get_file_list(root_path) for f in file_list: print t("Converting file %s") % f files.re_replace_in(f, site_name_escape, site_dev_name) files.re_replace_in(f, "(dev\.)*%s" % site_name_escape, site_dev_name) robot = root_path + "/robots.txt" prodrobot = root_path + "/robots.txt.prod" if files.exists(robot): self.show_file(t("------- ROBOTS.TXT --------"), robot) if files.exists(prodrobot): self.show_file(t("------- ROBOTS.TXT.PROD --------"), prodrobot) if files.exists(robot) and inputs.get_input_yesno( t("Do you want to backup current robots.txt to robots.txt.prod?") ): if not files.exists(prodrobot) or ( files.exists(prodrobot) and inputs.get_input_noyes(t("The robots.txt.prod exists. Overwrite?")) ): files.cp(robot, prodrobot) if inputs.get_input_yesno(t("Do you want create a dev robots.txt that disallow all?")): with open(files.get_rel_path("data/dev.robots.txt")) as devbot_tpl: files.create(robot, devbot_tpl.read()) completed = True return completed
def fix_uwsa_conf(self, element): with open(files.get_rel_path("data/uwsa.conf.tpl")) as f: files.create(element["name"], f.read()) core.CONFIG.load(element["name"]) core.CONFIG.save_to_file(element["name"])
def __init__(self): InstallCommand.__init__(self) self.cron_acl = "#!/bin/sh" with open(files.get_rel_path("data/cron_acl_apache.tpl")) as f: self.cron_acl = f.read() self.root_directive = str("" "<Directory />\n" " AllowOverride None\n" " Order Deny,Allow\n" " Deny from all\n" "</Directory>\n") self.add_prerequisite(InstallACLCommand.NAME, obj=InstallACLCommand()) self.add_package('apache2') self.add_folder('/data/www', ck_func=self.check_moved, fix_func=self.fix_moved) self.add_file('/etc/cron.acl/apache', ck_func=self.check_perm_cron, fix_func=self.fix_perm_cron, perm={'u':'rx', 'g':'rx', 'o':'rx'}) self.add_file('/etc/apache2/conf.d/security', ck_func=self.check_secure, fix_func=self.fix_secure) self.add_folder('/var/www/default',perm={'u':'rwx', 'g':'rwx', 'o':'rx'}) self.add_file('/var/www/default/index.html', fix_func=self.fix_default_index, perm={'u':'rw', 'g':'rw', 'o':'r'}) self.add_file('/etc/apache2/sites-available/default', ck_func=self.check_vh_default, fix_func=self.fix_vh_default) self.add_file('/etc/apache2/sites-available/default-ssl', ck_func=self.check_vh_default_ssl, fix_func=self.fix_vh_default_ssl)
def load(self, site_name): safe_site_name = self.get_safe_name(site_name) if self.is_conf_exists(safe_site_name): conf_path = "%s/%s" % (CONF_MAP('site','conf_path'), safe_site_name) self.conf = UWSAConfiguration(conf_file=conf_path, template=files.get_rel_path("data/site.conf.tpl"), exclude=self.exclude) self.set_name(site_name, self.conf.get('vhost','redirect'))
def generate_acl(self, group): cron_acl = "" site_path, root_path, log_path, upload_tmp_path = self.generate_dir() with open(files.get_rel_path("data/cron_acl.tpl")) as f: cron_acl_tpl = Template(f.read()) cron_acl = cron_acl_tpl.safe_substitute(group=group, site_path=site_path) return cron_acl
def generate_virtualhost(self): site_name = self.conf.get('main','site_name') site_dev_name = self.conf.get('main', 'site_dev_name') safe_site_name = self.get_safe_name(site_name) site_short_name = site_name.replace('www.','',1) admin_mail = CONF_MAP('mail','admin_mail') server_name = self.t + "ServerName %s\n" % site_name server_alias = self.t + "ServerAlias %s\n" % site_dev_name rewrite_cond = "" site_path, root_path, log_path, upload_tmp_path = self.generate_dir() options = self.conf.get('vhost','options') allow_override = self.conf.get('vhost','allow_override') php_extra = self.tt if str(self.conf.get('php','php_engine')).lower() != 'on': php_extra += "php_admin_value engine off" if self.conf.get('vhost','redirect'): server_alias += self.t + "ServerAlias %s\n" % site_short_name rewrite_cond = str("" "%(tab)sRewriteEngine on\n" "%(tab)sRewriteCond %(http_post)s ^%(site_rewrite_cond)s$ [NC]\n" "%(tab)sRewriteRule ^(.*)$ http://%(site_name)s$1 [R=301,L]\n" % { "http_post":"%{HTTP_HOST}", "site_rewrite_cond":site_short_name.replace(".","\."), "site_name":site_name, "tab":self.t, }) vhost = "" with open(files.get_rel_path("data/virtualhost.tpl")) as f: vhost_tpl = Template(f.read()) vhost = vhost_tpl.safe_substitute( admin_mail=admin_mail, server_name=server_name.strip(), server_alias=server_alias.strip(), root_path=root_path, site_path=site_path, rewrite_cond=rewrite_cond.strip(), options=options, allow_override=allow_override, php_extra=php_extra.strip(), safe_site_name=safe_site_name, log_path=log_path, upload_tmp_path=upload_tmp_path, ) return vhost
def __init__(self): AbstractCommand.__init__(self) self.exclude = { 'access':[ 'unix_pass', 'ldap_pass', 'ldap_to_apply', ], 'mysql':[ 'mysql_apply', ], } self.conf = UWSAConfiguration(template=files.get_rel_path("data/site.conf.tpl"),exclude=self.exclude) self.t = ' ' self.tt = self.t + self.t self.domain_admin_user = None self.domain_admin_pass = None
def generate_auto_mount(self): auto_mount = "" safe_site_name = self.get_safe_name(self.conf.get('main','site_name')) site_path, root_path, log_path, upload_tmp_path = self.generate_dir() unix_group = self.conf.get('access','unix_group') ldap_group = self.conf.get('access','ldap_group') with open(files.get_rel_path("data/auto_mount.tpl.py")) as f: auto_mount_tpl = Template(f.read()) auto_mount = auto_mount_tpl.safe_substitute( site_name=safe_site_name, site_path=site_path, ldap_group=ldap_group, unix_group=unix_group, ) return auto_mount
def __init__(self): InstallCommand.__init__(self) self.cron_acl_domainadmins = "#!/bin/sh" with open(files.get_rel_path("data/cron_acl.tpl")) as f: cron_acl_tpl = Template(f.read()) self.cron_acl_domainadmins = cron_acl_tpl.safe_substitute(group="domain\\ admins", site_path="/data/www") self.add_prerequisite(InstallACLCommand.NAME, obj=InstallACLCommand()) self.add_package("centrifydc", fix_func=self.fix_centrifydc) self.add_file('/etc/centrifydc/centrifydc.conf', ck_func=self.check_centrify_conf, fix_func=self.fix_centrify_conf) self.add_file('/etc/centrifydc/users.allow',fix_func=self.fix_user_allow) self.add_file('/etc/centrifydc/groups.allow', ck_func=self.check_group_allow, fix_func=self.fix_group_allow) self.add_file('/etc/sudoers.d/centrify_uwsa', ck_func=self.check_sudoers, fix_func=self.fix_sudoers, perm={'u':'r', 'g':'r', 'o':''}) self.add_file('/etc/cron.acl/domainadmins', ck_func=self.check_perm_cron, fix_func=self.fix_perm_cron, perm={'u':'rx', 'g':'rx', 'o':'rx'})
# Send the email (this example assumes SMTP authentication is required) import smtplib smtp = smtplib.SMTP(smtp_server) #smtp.connect(smtp,25) #smtp.login('exampleuser', 'examplepass') smtp.sendmail(strFrom, strTo, msgRoot.as_string()) smtp.quit() ## end of http://code.activestate.com/recipes/473810/ }}} #--------------------------------------------------------------------------------------------------# # Global initialisation #--------------------------------------------------------------------------------------------------# CONFIG = UWSAConfiguration(conf_file='/etc/uwsa/uwsa.conf', template=files.get_rel_path("data/uwsa.conf.tpl"), exclude = { 'core':['tool_name',], }) CONFIG.mod('core','tool_name','uwsa') CONF_MAP = CONFIG.get hi = get_host_info() CONFIG.mod('mail','hostname',hi['hostname']) CONFIG.mod('mail','ip',hi['ip']) L = Logger() #--------------------------------------------------------------------------------------------------# # Main #--------------------------------------------------------------------------------------------------# if __name__ == 'uwsa.core':
def check_vh_default_ssl(self, element): is_ok = True with open(files.get_rel_path("data/virtualhost_def_ssl.tpl")) as index: is_ok &= files.contains(element['name'], index.read()) return is_ok
def fix_logrotate(self, element): logrotate_template = Template(open(files.get_rel_path("data/logrotate_uwsa.tpl")).read()) files.create(element["name"], logrotate_template.safe_substitute())
def fix_vh_default_ssl(self, element): with open(files.get_rel_path("data/virtualhost_def_ssl.tpl")) as index: files.create(element['name'], index.read()) self.graceful(element['name'])
def check_ses_open(self, element): is_ok = True with open(files.get_rel_path("data/pam_script_ses_open.py")) as f: is_ok &= files.contains(element['name'], f.read()) return is_ok
def fix_ses_open(self, element): with open(files.get_rel_path("data/pam_script_ses_open.py")) as f: content = f.read() if not files.contains(element['name'], content): files.create(element['name'], content)
def fix_default_index(self, element): with open(files.get_rel_path("data/default.html.tpl")) as index: files.create(element['name'], index.read())