def setup(self, addr, port): # Make sure Radicale is installed and ready pyctl = apis.langassist(self.app).get_interface('Python') users = UsersBackend(self.app) if not pyctl.is_installed('Radicale'): pyctl.install('radicale') # due to packaging bugs, make extra sure perms are readable st = os.stat('/usr/lib/python2.7/site-packages/radicale') for r, d, f in os.walk('/usr/lib/python2.7/site-packages/radicale'): for x in d: os.chmod(os.path.join(r, x), st.st_mode & stat.S_IROTH & stat.S_IRGRP) for x in f: os.chmod(os.path.join(r, x), st.st_mode & stat.S_IROTH & stat.S_IRGRP) if not os.path.exists('/etc/radicale/config'): if not os.path.isdir('/etc/radicale'): os.mkdir('/etc/radicale') open('/etc/radicale/config', 'w').write(self.default_config) if not os.path.isdir('/usr/lib/radicale'): os.mkdir('/usr/lib/radicale') # Add the site process users.add_user('radicale') users.add_group('radicale') users.add_to_group('radicale', 'radicale') wsgi_file = 'import radicale\n' wsgi_file += 'radicale.log.start()\n' wsgi_file += 'application = radicale.Application()\n' open('/etc/radicale/radicale.wsgi', 'w').write(wsgi_file) os.chmod('/etc/radicale/radicale.wsgi', 0766) s = apis.orders(self.app).get_interface('supervisor') if s: s[0].order('new', 'radicale', 'program', [ ('directory', '/etc/radicale'), ('user', 'radicale'), ('command', 'uwsgi -s /tmp/radicale.sock -C --plugin python2 --wsgi-file radicale.wsgi' ), ('stdout_logfile', '/var/log/radicale.log'), ('stderr_logfile', '/var/log/radicale.log') ]) block = [ nginx.Location( '/', nginx.Key('auth_basic', '"Genesis Calendar Server (Radicale)"'), nginx.Key('auth_basic_user_file', '/etc/radicale/users'), nginx.Key('include', 'uwsgi_params'), nginx.Key('uwsgi_pass', 'unix:///tmp/radicale.sock'), ) ] if not os.path.exists('/etc/radicale/users'): open('/etc/radicale/users', 'w').write('') os.chmod('/etc/radicale/users', 0766) WebappControl(self.app).add_reverse_proxy('radicale', '/usr/lib/radicale', addr, port, block) apis.networkcontrol(self.app).add_webapp( ('radicale', 'ReverseProxy', port)) c = self.app.get_config(RadicaleConfig(self.app)) c.first_run_complete = True c.save()
def setup(self, addr, port): # Make sure Radicale is installed and ready pyctl = apis.langassist(self.app).get_interface('Python') users = UsersBackend(self.app) if not pyctl.is_installed('Radicale'): pyctl.install('radicale') # due to packaging bugs, make extra sure perms are readable st = os.stat('/usr/lib/python2.7/site-packages/radicale') for r, d, f in os.walk('/usr/lib/python2.7/site-packages/radicale'): for x in d: os.chmod(os.path.join(r, x), st.st_mode | stat.S_IROTH | stat.S_IRGRP) for x in f: os.chmod(os.path.join(r, x), st.st_mode | stat.S_IROTH | stat.S_IRGRP) if not os.path.exists('/etc/radicale/config'): if not os.path.isdir('/etc/radicale'): os.mkdir('/etc/radicale') open('/etc/radicale/config', 'w').write(self.default_config) if not os.path.isdir('/usr/lib/radicale'): os.mkdir('/usr/lib/radicale') # Add the site process users.add_user('radicale') users.add_group('radicale') users.add_to_group('radicale', 'radicale') wsgi_file = 'import radicale\n' wsgi_file += 'radicale.log.start()\n' wsgi_file += 'application = radicale.Application()\n' open('/etc/radicale/radicale.wsgi', 'w').write(wsgi_file) os.chmod('/etc/radicale/radicale.wsgi', 0766) s = apis.orders(self.app).get_interface('supervisor') if s: s[0].order('new', 'radicale', 'program', [('directory', '/etc/radicale'), ('user', 'radicale'), ('command', 'uwsgi -s /tmp/radicale.sock -C --plugin python2 --wsgi-file radicale.wsgi'), ('stdout_logfile', '/var/log/radicale.log'), ('stderr_logfile', '/var/log/radicale.log')]) block = [ nginx.Location('/', nginx.Key('auth_basic', '"Genesis Calendar Server (Radicale)"'), nginx.Key('auth_basic_user_file', '/etc/radicale/users'), nginx.Key('include', 'uwsgi_params'), nginx.Key('uwsgi_pass', 'unix:///tmp/radicale.sock'), ) ] if not os.path.exists('/etc/radicale/users'): open('/etc/radicale/users', 'w').write('') os.chmod('/etc/radicale/users', 0766) WebappControl(self.app).add_reverse_proxy('radicale', '/usr/lib/radicale', addr, port, block) apis.networkcontrol(self.app).add_webapp(('radicale', 'ReverseProxy', port)) c = self.app.get_config(RadicaleConfig(self.app)) c.first_run_complete = True c.save()
def ssl_disable(self, path): name = os.path.basename(path) n = nginx.loadf('/etc/nginx/sites-available/%s'%name) for x in n.servers: if x.filter('Location', '/'): x.remove(x.filter('Location', '/')[0]) x.add(self.addtoblock[0]) nginx.dumpf(n, '/etc/nginx/sites-available/%s'%name) f = open(os.path.join(path, 'config.js'), 'r').read() with open(os.path.join(path, 'config.js'), 'w') as config_file: f = f.replace('production: {\n url: \'https://', 'production: {\n url: \'http://') config_file.write(f) config_file.close() s = apis.orders(self.app).get_interface('supervisor') if s: s[0].order('rel', 'ghost')
def post_remove(self, name): users = UsersBackend(self.app) users.del_user('ghost') s = apis.orders(self.app).get_interface('supervisor') if s: s[0].order('del', 'ghost')
def post_install(self, name, path, vars): nodectl = apis.langassist(self.app).get_interface('NodeJS') users = UsersBackend(self.app) if not os.path.exists('/usr/bin/python') and os.path.exists('/usr/bin/python'): os.symlink('/usr/bin/python2', '/usr/bin/python') # A bug in 0.4.1 prevents [email protected] from installing properly. # Fallback to 2.1.15 d = json.loads(open(os.path.join(path, 'package.json'), 'r').read()) d['dependencies']['sqlite3'] = '2.1.15' open(os.path.join(path, 'package.json'), 'w').write(json.dumps(d)) nodectl.install_from_package(path, 'production') users.add_user('ghost') s = apis.orders(self.app).get_interface('supervisor') if s: s[0].order('new', 'ghost', 'program', [('directory', path), ('user', 'ghost'), ('command', 'node %s'%os.path.join(path, 'index.js')), ('autostart', 'true'), ('autorestart', 'true'), ('environment', 'NODE_ENV="production"'), ('stdout_logfile', '/var/log/ghost.log'), ('stderr_logfile', '/var/log/ghost.log')]) addr = vars.getvalue('addr', 'localhost') port = vars.getvalue('port', '80') # Get Mail settings mail_settings = { 'transport' : vars.getvalue('ghost-transport', ''), 'service' : vars.getvalue('ghost-service', ''), 'mail_user' : vars.getvalue('ghost-mail-user', ''), 'mail_pass' : vars.getvalue('ghost-mail-pass', ''), 'from_address' : vars.getvalue('ghost-from-address', '') } # Create/Edit the Ghost config file f = open(os.path.join(path, 'config.example.js'), 'r').read() with open(os.path.join(path, 'config.js'), 'w') as config_file: f = f.replace('http://my-ghost-blog.com', 'http://'+addr+(':'+port if port != '80' else'')) if len(set(mail_settings.values())) != 1 and\ mail_settings['transport'] != '': # If the mail settings exist, add them f = f.replace( "mail: {},",\ 'mail: {\n' "\tfromaddress: '" + mail_settings['from_address'] + "',\n" "\ttransport: '" + mail_settings['transport'] + "',\n" "\t\toptions: {\n" "\t\t\tservice: '" + mail_settings['service'] + "',\n" "\t\t\tauth: {\n" "\t\t\t\tuser: '******'mail_user'] + "',\n" "\t\t\t\tpass: '******'mail_pass'] + "'\n" "\t\t\t}\n" "\t\t}\n" "},\n" ) config_file.write(f) config_file.close() # Finally, make sure that permissions are set so that Ghost # can make adjustments and save plugins when need be. shell('chown -R ghost ' + path)