Example #1
0
    def post_install(self, name, path, vars, dbinfo={}):
        # Write a basic index file showing that we are here
        if vars.getvalue('php', '0') == '1':
            php = True
            path = os.path.join(path, 'htdocs')
            os.mkdir(path)
            c = nginx.loadf(os.path.join('/etc/nginx/sites-available', name))
            for x in c.servers:
                if x.filter('Key', 'root'):
                    x.filter('Key', 'root')[0].value = path
            nginx.dumpf(c, os.path.join('/etc/nginx/sites-available', name))
        else:
            php = False
            
        if php:
            phpctl = apis.langassist(self.app).get_interface('PHP')
            phpctl.enable_mod('xcache')
        if php and dbinfo and dbinfo['engine'] == 'MariaDB':
            phpctl.enable_mod('mysql')

        f = open(os.path.join(path, 'index.'+('php' if php is True else 'html')), 'w')
        f.write(
            '<html>\n'
            '<body>\n'
            '<h1>Genesis - Custom Site</h1>\n'
            '<p>Your site is online and available at '+path+'</p>\n'
            '<p>Feel free to paste your site files here</p>\n'
            '</body>\n'
            '</html>\n'
            )
        f.close()

        # Give access to httpd
        shell('chown -R http:http '+path)
Example #2
0
    def post_install(self, name, path, vars, dbinfo={}):
        # Write a basic index file showing that we are here
        if vars.getvalue('php', '0') == '1':
            php = True
            path = os.path.join(path, 'htdocs')
            os.mkdir(path)
            c = nginx.loadf(os.path.join('/etc/nginx/sites-available', name))
            for x in c.servers:
                if x.filter('Key', 'root'):
                    x.filter('Key', 'root')[0].value = path
            nginx.dumpf(c, os.path.join('/etc/nginx/sites-available', name))
        else:
            php = False

        if php:
            phpctl = apis.langassist(self.app).get_interface('PHP')
            phpctl.enable_mod('xcache')
        if php and dbinfo and dbinfo['engine'] == 'MariaDB':
            phpctl.enable_mod('mysql')

        f = open(
            os.path.join(path, 'index.' + ('php' if php is True else 'html')),
            'w')
        f.write('<html>\n'
                '<body>\n'
                '<h1>Genesis - Custom Site</h1>\n'
                '<p>Your site is online and available at ' + path + '</p>\n'
                '<p>Feel free to paste your site files here</p>\n'
                '</body>\n'
                '</html>\n')
        f.close()

        # Give access to httpd
        shell('chown -R http:http ' + path)
Example #3
0
 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()
Example #4
0
    def post_install(self, name, path, vars, dbinfo={}):
        phpctl = apis.langassist(self.app).get_interface('PHP')

        # Create Lychee automatic configuration file
        f = open(os.path.join(path, 'data', 'config.php'), 'w')
        f.write(
            '<?php\n'
            '   if(!defined(\'LYCHEE\')) exit(\'Error: Direct access is allowed!\');\n'
            '   $dbHost = \'localhost\';\n'
            '   $dbUser = \'' + dbinfo['user'] + '\';\n'
            '   $dbPassword = \'' + dbinfo['passwd'] + '\';\n'
            '   $dbName = \'' + dbinfo['name'] + '\';\n'
            '   $dbTablePrefix = \'\';\n'
            '?>\n'
        )
        f.close()

        # Make sure that the correct PHP settings are enabled
        phpctl.enable_mod('mysql', 'mysqli', 'gd', 'zip', 'exif', 'json', 'mbstring')

        # Rename lychee index.html to index.php to make it work with our default nginx config
        os.rename(os.path.join(path, "index.html"), os.path.join(path, "index.php"))

        # Finally, make sure that permissions are set so that Lychee
        # can make adjustments and save plugins when need be.
        shell('chown -R http:http %s' % path)

        return "Lychee has been installed. Login with a blank username and password the first time to set your credentials."
Example #5
0
 def update(self, path, pkg, ver):
     # General update procedure
     nodectl = apis.langassist(self.app).get_interface('NodeJS')
     s = self.app.get_backend(apis.services.IServiceManager)
     out = shell('unzip -o -d %s %s' % (path, pkg), stderr=True)
     shell('chown -R ghost '+path)
     nodectl.install_from_package(path, 'production', {'sqlite': '/usr/bin', 'python': '/usr/bin/python2'})
     s.restart('ghost', 'supervisor')
Example #6
0
 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 = self.app.get_backend(apis.services.IServiceManager)
     s.edit('radicale',
         {
             'stype': 'program',
             'directory': '/etc/radicale',
             'user': '******',
             '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'
         }
     )
     s.enable('radicale', 'supervisor')
     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()
Example #7
0
    def post_install(self, name, path, vars):
        # Write a basic index file showing that we are here
        if vars.getvalue('php', '0') == '1':
            php = True
            path = os.path.join(path, 'htdocs')
            os.mkdir(path)
            c = nginx.loadf(os.path.join('/etc/nginx/sites-available', name))
            for x in c.servers:
                if x.filter('Key', 'root'):
                    x.filter('Key', 'root')[0].value = path
            nginx.dumpf(c, os.path.join('/etc/nginx/sites-available', name))
        else:
            php = False

        # Create a database if the user wants one
        if php:
            phpctl = apis.langassist(self.app).get_interface('PHP')
        if vars.getvalue('ws-dbsel', 'None') != 'None':
            dbtype = vars.getvalue('ws-dbsel', '')
            dbname = vars.getvalue('ws-dbname', '')
            passwd = vars.getvalue('ws-dbpass', '')
            dbase = apis.databases(self.app).get_interface(dbtype)
            if hasattr(dbase, 'connect'):
                conn = apis.databases(self.app).get_dbconn(dbtype)
                dbase.add(dbname, conn)
                dbase.usermod(dbname, 'add', passwd, conn)
                dbase.chperm(dbname, dbname, 'grant', conn)
            else:
                dbase.add(dbname)
                dbase.usermod(dbname, 'add', passwd)
                dbase.chperm(dbname, dbname, 'grant')
            if php:
                phpctl.enable_mod('mysql')

        f = open(
            os.path.join(path, 'index.' + ('php' if php is True else 'html')),
            'w')
        f.write('<html>\n'
                '<body>\n'
                '<h1>Genesis - Custom Site</h1>\n'
                '<p>Your site is online and available at ' + path + '</p>\n'
                '<p>Feel free to paste your site files here</p>\n'
                '</body>\n'
                '</html>\n')
        f.close()

        # Give access to httpd
        shell('chown -R http:http ' + path)

        # Enable xcache if PHP is set
        if php:
            phpctl.enable_mod('xcache')
Example #8
0
    def post_install(self, name, path, vars):
        # Write a basic index file showing that we are here
        if vars.getvalue('php', '0') == '1':
            php = True
            path = os.path.join(path, 'htdocs')
            os.mkdir(path)
            c = nginx.loadf(os.path.join('/etc/nginx/sites-available', name))
            for x in c.servers:
                if x.filter('Key', 'root'):
                    x.filter('Key', 'root')[0].value = path
            nginx.dumpf(c, os.path.join('/etc/nginx/sites-available', name))
        else:
            php = False
            
        # Create a database if the user wants one
        if php:
            phpctl = apis.langassist(self.app).get_interface('PHP')
        if vars.getvalue('ws-dbsel', 'None') != 'None':
            dbtype = vars.getvalue('ws-dbsel', '')
            dbname = vars.getvalue('ws-dbname', '')
            passwd = vars.getvalue('ws-dbpass', '')
            dbase = apis.databases(self.app).get_interface(dbtype)
            if hasattr(dbase, 'connect'):
                conn = apis.databases(self.app).get_dbconn(dbtype)
                dbase.add(dbname, conn)
                dbase.usermod(dbname, 'add', passwd, conn)
                dbase.chperm(dbname, dbname, 'grant', conn)
            else:
                dbase.add(dbname)
                dbase.usermod(dbname, 'add', passwd)
                dbase.chperm(dbname, dbname, 'grant')
            if php:
                phpctl.enable_mod('mysql')

        f = open(os.path.join(path, 'index.'+('php' if php is True else 'html')), 'w')
        f.write(
            '<html>\n'
            '<body>\n'
            '<h1>Genesis - Custom Site</h1>\n'
            '<p>Your site is online and available at '+path+'</p>\n'
            '<p>Feel free to paste your site files here</p>\n'
            '</body>\n'
            '</html>\n'
            )
        f.close()

        # Give access to httpd
        shell('chown -R http:http '+path)

        # Enable xcache if PHP is set
        if php:
            phpctl.enable_mod('xcache')
Example #9
0
	def post_install(self, name, path, vars, dbinfo={}):
		phpctl = apis.langassist(self.app).get_interface('PHP')
		secret_key = hashlib.sha1(str(random.random())).hexdigest()

		# Use the WordPress key generators as first option
		# If connection fails, use the secret_key as fallback
		try:
			keysection = urllib.urlopen('https://api.wordpress.org/secret-key/1.1/salt/').read()
		except:
			keysection = ''
		if not 'define(\'AUTH_KEY' in keysection:
			keysection = (
				'define(\'AUTH_KEY\', \''+secret_key+'\');\n'
				'define(\'SECURE_AUTH_KEY\', \''+secret_key+'\');\n'
				'define(\'LOGGED_IN_KEY\', \''+secret_key+'\');\n'
				'define(\'NONCE_KEY\', \''+secret_key+'\');\n'
				)

		# Write a standard WordPress config file
		f = open(os.path.join(path, 'wp-config.php'), 'w')
		f.write('<?php\n'
				'define(\'DB_NAME\', \''+dbinfo['name']+'\');\n'
				'define(\'DB_USER\', \''+dbinfo['user']+'\');\n'
				'define(\'DB_PASSWORD\', \''+dbinfo['passwd']+'\');\n'
				'define(\'DB_HOST\', \'localhost\');\n'
				'define(\'DB_CHARSET\', \'utf8\');\n'
				'define(\'SECRET_KEY\', \''+secret_key+'\');\n'
				'\n'
				'define(\'WP_CACHE\', true);\n'
				'define(\'FORCE_SSL_ADMIN\', false);\n'
				'\n'
				+keysection+
				'\n'
				'$table_prefix = \'wp_\';\n'
				'\n'
				'/** Absolute path to the WordPress directory. */\n'
				'if ( !defined(\'ABSPATH\') )\n'
				'	define(\'ABSPATH\', dirname(__FILE__) . \'/\');\n'
				'\n'
				'/** Sets up WordPress vars and included files. */\n'
				'require_once(ABSPATH . \'wp-settings.php\');\n'
			)
		f.close()

		# Make sure that the correct PHP settings are enabled
		phpctl.enable_mod('mysql', 'xcache')

		# Finally, make sure that permissions are set so that Wordpress
		# can make adjustments and save plugins when need be.
		shell('chown -R http:http '+path)
Example #10
0
    def post_install(self, name, path, vars, dbinfo={}):
        phpctl = apis.langassist(self.app).get_interface('PHP')
        secret_key = hashlib.sha1(str(random.random())).hexdigest()

        # Use the WordPress key generators as first option
        # If connection fails, use the secret_key as fallback
        try:
            keysection = urllib.urlopen(
                'https://api.wordpress.org/secret-key/1.1/salt/').read()
        except:
            keysection = ''
        if not 'define(\'AUTH_KEY' in keysection:
            keysection = ('define(\'AUTH_KEY\', \'' + secret_key + '\');\n'
                          'define(\'SECURE_AUTH_KEY\', \'' + secret_key +
                          '\');\n'
                          'define(\'LOGGED_IN_KEY\', \'' + secret_key +
                          '\');\n'
                          'define(\'NONCE_KEY\', \'' + secret_key + '\');\n')

        # Write a standard WordPress config file
        f = open(os.path.join(path, 'wp-config.php'), 'w')
        f.write('<?php\n'
                'define(\'DB_NAME\', \'' + dbinfo['name'] + '\');\n'
                'define(\'DB_USER\', \'' + dbinfo['user'] + '\');\n'
                'define(\'DB_PASSWORD\', \'' + dbinfo['passwd'] + '\');\n'
                'define(\'DB_HOST\', \'localhost\');\n'
                'define(\'DB_CHARSET\', \'utf8\');\n'
                'define(\'SECRET_KEY\', \'' + secret_key + '\');\n'
                '\n'
                'define(\'WP_CACHE\', true);\n'
                'define(\'FORCE_SSL_ADMIN\', false);\n'
                '\n' + keysection + '\n'
                '$table_prefix = \'wp_\';\n'
                '\n'
                '/** Absolute path to the WordPress directory. */\n'
                'if ( !defined(\'ABSPATH\') )\n'
                '	define(\'ABSPATH\', dirname(__FILE__) . \'/\');\n'
                '\n'
                '/** Sets up WordPress vars and included files. */\n'
                'require_once(ABSPATH . \'wp-settings.php\');\n')
        f.close()

        # Make sure that the correct PHP settings are enabled
        phpctl.enable_mod('mysql', 'xcache')

        # Finally, make sure that permissions are set so that Wordpress
        # can make adjustments and save plugins when need be.
        shell('chown -R http:http ' + path)
Example #11
0
 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')
     if not pyctl.is_installed('uWSGI'):
         pyctl.install('uwsgi')
     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)
     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 --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('')
     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()
Example #12
0
 def pre_remove(self, site):
     datadir = ''
     if os.path.exists(os.path.join(site.path, 'config', 'config.php')):
         f = open(os.path.join(site.path, 'config', 'config.php'), 'r')
         for line in f.readlines():
             if 'datadirectory' in line:
                 data = line.split("'")[1::2]
                 datadir = data[1]
         f.close()
     elif os.path.exists(os.path.join(site.path, 'config', 'autoconfig.php')):
         f = open(os.path.join(site.path, 'config', 'autoconfig.php'), 'r')
         for line in f.readlines():
             if 'directory' in line:
                 data = line.split('"')[1::2]
                 datadir = data[1]
         f.close()
     if datadir:
         shutil.rmtree(datadir)
         phpctl = apis.langassist(self.app).get_interface('PHP')
         phpctl.open_basedir('del', datadir)
Example #13
0
 def pre_remove(self, site):
     datadir = ''
     if os.path.exists(os.path.join(site.path, 'config', 'config.php')):
         f = open(os.path.join(site.path, 'config', 'config.php'), 'r')
         for line in f.readlines():
             if 'datadirectory' in line:
                 data = line.split("'")[1::2]
                 datadir = data[1]
         f.close()
     elif os.path.exists(os.path.join(site.path, 'config', 'autoconfig.php')):
         f = open(os.path.join(site.path, 'config', 'autoconfig.php'), 'r')
         for line in f.readlines():
             if 'directory' in line:
                 data = line.split('"')[1::2]
                 datadir = data[1]
         f.close()
     if datadir:
         shutil.rmtree(datadir)
         phpctl = apis.langassist(self.app).get_interface('PHP')
         phpctl.open_basedir('del', datadir)
Example #14
0
    def post_install(self, name, path, vars, dbinfo={}):
        nodectl = apis.langassist(self.app).get_interface('NodeJS')
        users = UsersBackend(self.app)

        d = json.loads(open(os.path.join(path, 'config.js'), 'r').read())
        if d["storage"]["type"] == "redis":
            d["storage"]["type"] = "file"
            d["storage"]["path"] = "./data"
            if d["storage"].has_key("host"):
                del d["storage"]["host"]
            if d["storage"].has_key("port"):
                del d["storage"]["port"]
            if d["storage"].has_key("db"):
                del d["storage"]["db"]
            if d["storage"].has_key("expire"):
                del d["storage"]["expire"]
            open(os.path.join(path, 'config.js'), 'w').write(json.dumps(d))

        nodectl.install_from_package(path)
        users.add_user('haste')

        s = self.app.get_backend(apis.services.IServiceManager)
        s.edit('haste',
            {
                'stype': 'program',
                'directory': path,
                'user': '******',
                'command': 'node %s'%os.path.join(path, 'server.js'),
                'autostart': 'true',
                'autorestart': 'true',
                'environment': 'NODE_ENV="production"',
                'stdout_logfile': '/var/log/haste.log',
                'stderr_logfile': '/var/log/haste.log'
            }
        )
        s.enable('haste', 'supervisor')

        # Finally, make sure that permissions are set so that Haste
        # can save its files properly.
        shell('chown -R haste ' + path)
Example #15
0
    def post_install(self, name, path, vars, dbinfo={}):
        UsersBackend(self.app).add_user('etherpad')

        # Create/Edit the config file
        cfg = {
            "title": "Etherpad",
            "favicon": "favicon.ico",
            "ip": "127.0.0.1",
            "port": "2369",
            "sessionKey": hashlib.sha1(str(random.random())).hexdigest(),
            "dbType": "mysql",
            "dbSettings": {
                "user": dbinfo['user'],
                "host": "localhost",
                "password": dbinfo['passwd'],
                "database": dbinfo['name']
            },
            "defaultPadText": (
                "Welcome to Etherpad on arkOS!\n\nThis pad text is "
                "synchronized as you type, so that everyone viewing this page "
                "sees the same text. This allows you to collaborate seamlessly "
                "on documents!\n\nGet involved with Etherpad at "
                "http://etherpad.org, or with arkOS at http://arkos.io\n"
            ),
            "requireSession": False,
            "editOnly": False,
            "minify": True,
            "maxAge": 60 * 60 * 6,
            "abiword": None,
            "requireAuthentication": False,
            "requireAuthorization": False,
            "trustProxy": True,
            "disableIPlogging": False,
            "socketTransportProtocols": [
                "xhr-polling", "jsonp-polling", "htmlfile"
            ],
            "loglevel": "INFO",
            "logconfig": {
                "appenders": [
                    {"type": "console"}
                ]
            },
            "users": {
                vars.getvalue('ether_admin'): {
                    "password": vars.getvalue('ether_pass'),
                    "is_admin": True
                },
            },

        }
        with open(os.path.join(path, 'settings.json'), 'w') as f:
            json.dump(cfg, f, indent=4)

        # Install selected plugins
        mods = list(                            # e.g. "ep_plugin/ep_adminpads"
            str(var).split("/")[1]              #                 ^^^^^^^^^^^^
            for var in vars
            if var.startswith('ep_plugin/') and int(vars.getvalue(var))
        )
        if mods:
            mod_inst_path = os.path.join(path, "node_modules")
            if not os.path.exists(mod_inst_path):
                os.mkdir(mod_inst_path)
            nodectl = apis.langassist(self.app).get_interface('NodeJS')
            nodectl.install(*mods, install_path=mod_inst_path)

        # node-gyp needs the HOME variable to be set
        with open(os.path.join(path, 'bin/installDeps.sh')) as f:
            run_script = f.readlines()
        # this is a hack. supervisor does not kill node when stopping ep.
        run_script.insert(1, 'killall node\n')
        run_script.insert(1, 'export HOME=%s\n' % path)
        with open(os.path.join(path, 'bin/installDeps.sh'), 'w') as f:
            f.writelines(run_script)

        # Change owner of everything in the etherpad path
        shell('chown -R etherpad:etherpad ' + path)

        # Make supervisor entry
        s = self.app.get_backend(apis.services.IServiceManager)
        s.edit('etherpad',
            {
                'stype': 'program',
                'directory': path,
                'user': '******',
                'command': 'bash bin/run.sh',
                'autostart': 'true',
                'autorestart': 'false',
                'stdout_logfile': '/var/log/etherpad.log',
                'stderr_logfile': '/var/log/etherpad.log'
            }
        )
        s.enable('etherpad', 'supervisor')
Example #16
0
    def post_install(self, name, path, vars, dbinfo={}):
        phpctl = apis.langassist(self.app).get_interface('PHP')
        secret_key = hashlib.sha1(str(random.random())).hexdigest()
        dbengine = 'mysql' if dbinfo['engine'] == 'MariaDB' else 'sqlite'

        # Write a standard Wallabag config file
        shutil.copy(os.path.join(path, 'inc/poche/config.inc.default.php'),
            os.path.join(path, 'inc/poche/config.inc.php'))
        ic = open(os.path.join(path, 'inc/poche/config.inc.php'), 'r').readlines()
        f = open(os.path.join(path, 'inc/poche/config.inc.php'), 'w')
        oc = []
        for l in ic:
            if 'define (\'SALT\'' in l:
                l = 'define (\'SALT\', \''+secret_key+'\');\n'
                oc.append(l)
            elif 'define (\'STORAGE\'' in l:
                l = 'define (\'STORAGE\', \''+dbengine+'\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_SQLITE\'' in l and dbengine == 'sqlite':
                l = 'define (\'STORAGE_SQLITE\', \'/var/lib/sqlite3/'+dbinfo['name']+'.db\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_DB\'' in l and dbengine == 'mysql':
                l = 'define (\'STORAGE_DB\', \''+dbinfo['name']+'\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_USER\'' in l and dbengine == 'mysql':
                l = 'define (\'STORAGE_USER\', \''+dbinfo['user']+'\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_PASSWORD\'' in l and dbengine == 'mysql':
                l = 'define (\'STORAGE_PASSWORD\', \''+dbinfo['passwd']+'\');\n'
                oc.append(l)
            else:
                oc.append(l)
        f.writelines(oc)
        f.close()

        # Make sure that the correct PHP settings are enabled
        phpctl.enable_mod('mysql', 'pdo_mysql' if dbengine == 'mysql' else 'pdo_sqlite', 
            'zip', 'tidy', 'xcache', 'openssl')

        # Set up Composer and install the proper modules
        phpctl.composer_install(path)

        # Set up the database then delete the install folder
        if dbengine == 'mysql':
            dbase = apis.databases(self.app).get_interface(dbinfo['engine'])
            conn = apis.databases(self.app).get_dbconn(dbinfo['engine'])
            dbase.execute(dbinfo['name'], 
                open(os.path.join(path, 'install/mysql.sql')).read(), conn)
        else:
            shutil.copy(os.path.join(path, 'install/poche.sqlite'), '/var/lib/sqlite3/%s.db' % dbinfo['name'])
            phpctl.open_basedir('add', '/var/lib/sqlite3')
            shell('chown http:http /var/lib/sqlite3/%s.db' % dbinfo['name'])
            shell('chmod 755 /var/lib/sqlite3/%s.db' % dbinfo['name'])
        shutil.rmtree(os.path.join(path, 'install'))

        # Finally, make sure that permissions are set so that Poche
        # can make adjustments and save plugins when need be.
        shell('chmod -R 755 '+os.path.join(path, 'assets/')+' '
            +os.path.join(path, 'cache/')+' '
            +os.path.join(path, 'db/'))
        shell('chown -R http:http '+path)
Example #17
0
    def post_install(self, name, path, vars, dbinfo={}):
        phpctl = apis.langassist(self.app).get_interface('PHP')
        datadir = ''
        secret_key = hashlib.sha1(str(random.random())).hexdigest()
        username = vars.getvalue('oc-username')
        logpasswd = vars.getvalue('oc-logpasswd')

        # Set ownership as necessary
        if not os.path.exists(os.path.join(path, 'data')):
            os.makedirs(os.path.join(path, 'data'))
        shell('chown -R http:http '+path)

        # If there is a custom path for the data directory, do the magic
        if vars.getvalue('oc-ddir', '') != '':
            datadir = vars.getvalue('oc-ddir')
            if not os.path.exists(os.path.join(datadir if datadir else path, 'data')):
                os.makedirs(os.path.join(datadir if datadir else path, 'data'))
            shell('chown -R http:http '+os.path.join(datadir if datadir else path, 'data'))
            phpctl.open_basedir('add', datadir)

        # Create ownCloud automatic configuration file
        f = open(os.path.join(path, 'config', 'autoconfig.php'), 'w')
        f.write(
            '<?php\n'
            '   $AUTOCONFIG = array(\n'
            '   "adminlogin" => "'+username+'",\n'
            '   "adminpass" => "'+logpasswd+'",\n'
            '   "dbtype" => "mysql",\n'
            '   "dbname" => "'+dbinfo['name']+'",\n'
            '   "dbuser" => "'+dbinfo['user']+'",\n'
            '   "dbpass" => "'+dbinfo['passwd']+'",\n'
            '   "dbhost" => "localhost",\n'
            '   "dbtableprefix" => "",\n'
            '   "directory" => "'+os.path.join(datadir if datadir else path, 'data')+'",\n'
            '   );\n'
            '?>\n'
            )
        f.close()
        shell('chown http:http '+os.path.join(path, 'config', 'autoconfig.php'))

        # Make sure that the correct PHP settings are enabled
        phpctl.enable_mod('mysql', 'pdo_mysql', 'zip', 'gd',
            'iconv', 'openssl', 'xcache')
        
        # Make sure xcache has the correct settings, otherwise ownCloud breaks
        f = open('/etc/php/conf.d/xcache.ini', 'w')
        oc = ['extension=xcache.so\n',
            'xcache.size=64M\n',
            'xcache.var_size=64M\n',
            'xcache.admin.enable_auth = Off\n',
            'xcache.admin.user = "******"\n',
            'xcache.admin.pass = "******"\n']
        f.writelines(oc)
        f.close()

        # Return an explicatory message
        if self.app.board in ['BeagleBone Black,' 'Raspberry Pi']:
            return ('ownCloud takes a long time to set up on this platform. '
            'Once you open the page for the first time, it may take 5-10 '
            'minutes for the content to appear. Please do not refresh the '
            'page.')
Example #18
0
 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')
Example #19
0
	def pre_install(self, name, vars):
		rubyctl = apis.langassist(self.app).get_interface('Ruby')
		rubyctl.install_gem('jekyll', 'rdiscount')
Example #20
0
    def post_install(self, name, path, vars, dbinfo={}):
        phpctl = apis.langassist(self.app).get_interface('PHP')
        secret_key = hashlib.sha1(str(random.random())).hexdigest()
        dbengine = 'mysql' if dbinfo['engine'] == 'MariaDB' else 'sqlite'

        # Write a standard Wallabag config file
        shutil.copy(os.path.join(path, 'inc/poche/config.inc.default.php'),
                    os.path.join(path, 'inc/poche/config.inc.php'))
        ic = open(os.path.join(path, 'inc/poche/config.inc.php'),
                  'r').readlines()
        f = open(os.path.join(path, 'inc/poche/config.inc.php'), 'w')
        oc = []
        for l in ic:
            if 'define (\'SALT\'' in l:
                l = '@define (\'SALT\', \'' + secret_key + '\');\n'
                oc.append(l)
            elif 'define (\'STORAGE\'' in l:
                l = '@define (\'STORAGE\', \'' + dbengine + '\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_SQLITE\'' in l and dbengine == 'sqlite':
                l = '@define (\'STORAGE_SQLITE\', \'/var/lib/sqlite3/' + dbinfo[
                    'name'] + '.db\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_DB\'' in l and dbengine == 'mysql':
                l = '@define (\'STORAGE_DB\', \'' + dbinfo['name'] + '\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_USER\'' in l and dbengine == 'mysql':
                l = '@define (\'STORAGE_USER\', \'' + dbinfo['user'] + '\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_PASSWORD\'' in l and dbengine == 'mysql':
                l = '@define (\'STORAGE_PASSWORD\', \'' + dbinfo[
                    'passwd'] + '\');\n'
                oc.append(l)
            else:
                oc.append(l)
        f.writelines(oc)
        f.close()

        # Make sure that the correct PHP settings are enabled
        phpctl.enable_mod('mysql' if dbengine == 'mysql' else 'sqlite3',
                          'pdo_mysql' if dbengine == 'mysql' else 'pdo_sqlite',
                          'zip', 'tidy', 'xcache', 'openssl')

        # Set up Composer and install the proper modules
        phpctl.composer_install(path)

        # Set up the database then delete the install folder
        if dbengine == 'mysql':
            dbase = apis.databases(self.app).get_interface(dbinfo['engine'])
            conn = apis.databases(self.app).get_dbconn(dbinfo['engine'])
            dbase.execute(dbinfo['name'],
                          open(os.path.join(path, 'install/mysql.sql')).read(),
                          conn)
        else:
            shutil.copy(os.path.join(path, 'install/poche.sqlite'),
                        '/var/lib/sqlite3/%s.db' % dbinfo['name'])
            phpctl.open_basedir('add', '/var/lib/sqlite3')
            shell('chown http:http /var/lib/sqlite3/%s.db' % dbinfo['name'])
            shell('chmod 755 /var/lib/sqlite3/%s.db' % dbinfo['name'])
        shutil.rmtree(os.path.join(path, 'install'))

        # Finally, make sure that permissions are set so that Wallabag
        # can make adjustments and save plugins when need be.
        shell('chmod -R 755 ' + os.path.join(path, 'assets/') + ' ' +
              os.path.join(path, 'cache/') + ' ' + os.path.join(path, 'db/'))
        shell('chown -R http:http ' + path)
Example #21
0
File: main.py Project: tewe/genesis
	def post_install(self, name, path, vars):
		phpctl = apis.langassist(self.app).get_interface('PHP')
		dbase = apis.databases(self.app).get_interface('MariaDB')
		conn = apis.databases(self.app).get_dbconn('MariaDB')
		if vars.getvalue('oc-dbname', '') == '':
			dbname = name
		else:
			dbname = vars.getvalue('oc-dbname')
		secret_key = hashlib.sha1(str(random.random())).hexdigest()
		if vars.getvalue('oc-dbpasswd', '') == '':
			passwd = secret_key[0:8]
		else:
			passwd = vars.getvalue('oc-dbpasswd')
		username = vars.getvalue('oc-username')
		logpasswd = vars.getvalue('oc-logpasswd')

		# Request a database and user to interact with it
		dbase.add(dbname, conn)
		dbase.usermod(dbname, 'add', passwd, conn)
		dbase.chperm(dbname, dbname, 'grant', conn)

		# Set ownership as necessary
		os.makedirs(os.path.join(path, 'data'))
		shell('chown -R http:http '+os.path.join(path, 'apps'))
		shell('chown -R http:http '+os.path.join(path, 'data'))
		shell('chown -R http:http '+os.path.join(path, 'config'))

		# Create ownCloud automatic configuration file
		f = open(os.path.join(path, 'config', 'autoconfig.php'), 'w')
		f.write(
			'<?php\n'
			'	$AUTOCONFIG = array(\n'
			'	"adminlogin" => "'+username+'",\n'
			'	"adminpass" => "'+logpasswd+'",\n'
			'	"dbtype" => "mysql",\n'
			'	"dbname" => "'+dbname+'",\n'
			'	"dbuser" => "'+dbname+'",\n'
			'	"dbpass" => "'+passwd+'",\n'
			'	"dbhost" => "localhost",\n'
			'	"dbtableprefix" => "",\n'
			'	"directory" => "'+os.path.join(path, 'data')+'",\n'
			'	);\n'
			'?>\n'
			)
		f.close()
		shell('chown http:http '+os.path.join(path, 'config', 'autoconfig.php'))

		# Make sure that the correct PHP settings are enabled
		phpctl.enable_mod('mysql', 'pdo_mysql', 'zip', 'gd',
			'iconv', 'openssl', 'xcache')
		
		# Make sure xcache has the correct settings, otherwise ownCloud breaks
		f = open('/etc/php/conf.d/xcache.ini', 'w')
		oc = ['extension=xcache.so\n',
			'xcache.size=64M\n',
			'xcache.var_size=64M\n',
			'xcache.admin.enable_auth = Off\n',
			'xcache.admin.user = "******"\n',
			'xcache.admin.pass = "******"\n']
		f.writelines(oc)
		f.close()

		# Return an explicatory message
		return 'ownCloud takes a long time to set up on the RPi. Once you open the page for the first time, it may take 5-10 minutes for the content to appear. Please do not refresh the page.'
Example #22
0
    def post_install(self, name, path, vars):
        # Get the database object, and determine proper values
        phpctl = apis.langassist(self.app).get_interface('PHP')
        dbase = apis.databases(self.app).get_interface('MariaDB')
        conn = apis.databases(self.app).get_dbconn('MariaDB')
        if vars.getvalue('wp-dbname', '') == '':
            dbname = name
        else:
            dbname = vars.getvalue('wp-dbname')
        secret_key = hashlib.sha1(str(random.random())).hexdigest()
        if vars.getvalue('wp-dbpasswd', '') == '':
            passwd = secret_key[0:8]
        else:
            passwd = vars.getvalue('wp-dbpasswd')

        # Request a database and user to interact with it
        dbase.add(dbname, conn)
        dbase.usermod(dbname, 'add', passwd, conn)
        dbase.chperm(dbname, dbname, 'grant', conn)

        # Use the WordPress key generators as first option
        # If connection fails, use the secret_key as fallback
        try:
            keysection = urllib.urlopen(
                'https://api.wordpress.org/secret-key/1.1/salt/').read()
        except:
            keysection = ''
        if not 'define(\'AUTH_KEY' in keysection:
            keysection = ('define(\'AUTH_KEY\', \'' + secret_key + '\');\n'
                          'define(\'SECURE_AUTH_KEY\', \'' + secret_key +
                          '\');\n'
                          'define(\'LOGGED_IN_KEY\', \'' + secret_key +
                          '\');\n'
                          'define(\'NONCE_KEY\', \'' + secret_key + '\');\n')

        # Write a standard WordPress config file
        f = open(os.path.join(path, 'wp-config.php'), 'w')
        f.write('<?php\n'
                'define(\'DB_NAME\', \'' + dbname + '\');\n'
                'define(\'DB_USER\', \'' + dbname + '\');\n'
                'define(\'DB_PASSWORD\', \'' + passwd + '\');\n'
                'define(\'DB_HOST\', \'localhost\');\n'
                'define(\'DB_CHARSET\', \'utf8\');\n'
                'define(\'SECRET_KEY\', \'' + secret_key + '\');\n'
                '\n'
                'define(\'WP_CACHE\', true);\n'
                'define(\'FORCE_SSL_ADMIN\', false);\n'
                '\n' + keysection + '\n'
                '$table_prefix = \'wp_\';\n'
                '\n'
                '/** Absolute path to the WordPress directory. */\n'
                'if ( !defined(\'ABSPATH\') )\n'
                '	define(\'ABSPATH\', dirname(__FILE__) . \'/\');\n'
                '\n'
                '/** Sets up WordPress vars and included files. */\n'
                'require_once(ABSPATH . \'wp-settings.php\');\n')
        f.close()

        # Make sure that the correct PHP settings are enabled
        phpctl.enable_mod('mysql', 'xcache')

        # Finally, make sure that permissions are set so that Wordpress
        # can make adjustments and save plugins when need be.
        shell('chown -R http:http ' + path)
Example #23
0
    def post_install(self, name, path, vars):
        # Get the database object, and determine proper values
        phpctl = apis.langassist(self.app).get_interface('PHP')
        dbase = apis.databases(self.app).get_interface('MariaDB')
        conn = apis.databases(self.app).get_dbconn('MariaDB')
        if vars.getvalue('wb-dbname', '') == '':
            dbname = name
        else:
            dbname = vars.getvalue('wb-dbname')
        secret_key = hashlib.sha1(str(random.random())).hexdigest()
        if vars.getvalue('wb-dbpasswd', '') == '':
            passwd = secret_key[0:8]
        else:
            passwd = vars.getvalue('wb-dbpasswd')

        # Request a database and user to interact with it
        dbase.add(dbname, conn)
        dbase.usermod(dbname, 'add', passwd, conn)
        dbase.chperm(dbname, dbname, 'grant', conn)

        # Write a standard Wallabag config file
        shutil.copy(os.path.join(path, 'inc/poche/config.inc.php.new'),
            os.path.join(path, 'inc/poche/config.inc.php'))
        ic = open(os.path.join(path, 'inc/poche/config.inc.php'), 'r').readlines()
        f = open(os.path.join(path, 'inc/poche/config.inc.php'), 'w')
        oc = []
        for l in ic:
            if 'define (\'SALT\'' in l:
                l = 'define (\'SALT\', \''+secret_key+'\');\n'
                oc.append(l)
            elif 'define (\'STORAGE\'' in l:
                l = 'define (\'STORAGE\', \'mysql\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_DB\'' in l:
                l = 'define (\'STORAGE_DB\', \''+dbname+'\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_USER\'' in l:
                l = 'define (\'STORAGE_USER\', \''+dbname+'\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_PASSWORD\'' in l:
                l = 'define (\'STORAGE_PASSWORD\', \''+passwd+'\');\n'
                oc.append(l)
            else:
                oc.append(l)
        f.writelines(oc)
        f.close()

        # Make sure that the correct PHP settings are enabled
        phpctl.enable_mod('mysql', 'pdo_mysql', 'zip', 
            'tidy', 'xcache', 'openssl')

        # Set up Composer and install the proper modules
        phpctl.composer_install(path)

        # Finish setting up the database then delete the install folder
        dbase.execute(dbname, 
            open(os.path.join(path, 'install/mysql.sql')).read(), conn)
        shutil.rmtree(os.path.join(path, 'install'))

        # Finally, make sure that permissions are set so that Poche
        # can make adjustments and save plugins when need be.
        shell('chmod -R 755 '+os.path.join(path, 'assets/')+' '
            +os.path.join(path, 'cache/')+' '
            +os.path.join(path, 'db/'))
        shell('chown -R http:http '+path)
Example #24
0
    def pre_install(self, name, vars):
		rubyctl = apis.langassist(self.app).get_interface('Ruby')
		rubyctl.install_gem('gollum', 'redcarpet', 'wikicloth')
Example #25
0
File: main.py Project: tewe/genesis
    def post_install(self, name, path, vars):
        # Get the database object, and determine proper values
        phpctl = apis.langassist(self.app).get_interface('PHP')
        dbase = apis.databases(self.app).get_interface('MariaDB')
        conn = apis.databases(self.app).get_dbconn('MariaDB')
        if vars.getvalue('wb-dbname', '') == '':
            dbname = name
        else:
            dbname = vars.getvalue('wb-dbname')
        secret_key = hashlib.sha1(str(random.random())).hexdigest()
        if vars.getvalue('wb-dbpasswd', '') == '':
            passwd = secret_key[0:8]
        else:
            passwd = vars.getvalue('wb-dbpasswd')

        # Request a database and user to interact with it
        dbase.add(dbname, conn)
        dbase.usermod(dbname, 'add', passwd, conn)
        dbase.chperm(dbname, dbname, 'grant', conn)

        # Write a standard Wallabag config file
        shutil.copy(os.path.join(path, 'inc/poche/config.inc.php.new'),
                    os.path.join(path, 'inc/poche/config.inc.php'))
        ic = open(os.path.join(path, 'inc/poche/config.inc.php'),
                  'r').readlines()
        f = open(os.path.join(path, 'inc/poche/config.inc.php'), 'w')
        oc = []
        for l in ic:
            if 'define (\'SALT\'' in l:
                l = 'define (\'SALT\', \'' + secret_key + '\');\n'
                oc.append(l)
            elif 'define (\'STORAGE\'' in l:
                l = 'define (\'STORAGE\', \'mysql\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_DB\'' in l:
                l = 'define (\'STORAGE_DB\', \'' + dbname + '\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_USER\'' in l:
                l = 'define (\'STORAGE_USER\', \'' + dbname + '\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_PASSWORD\'' in l:
                l = 'define (\'STORAGE_PASSWORD\', \'' + passwd + '\');\n'
                oc.append(l)
            else:
                oc.append(l)
        f.writelines(oc)
        f.close()

        # Make sure that the correct PHP settings are enabled
        phpctl.enable_mod('mysql', 'pdo_mysql', 'zip', 'tidy', 'xcache',
                          'openssl')

        # Set up Composer and install the proper modules
        phpctl.composer_install(path)

        # Finish setting up the database then delete the install folder
        dbase.execute(dbname,
                      open(os.path.join(path, 'install/mysql.sql')).read(),
                      conn)
        shutil.rmtree(os.path.join(path, 'install'))

        # Finally, make sure that permissions are set so that Poche
        # can make adjustments and save plugins when need be.
        shell('chmod -R 755 ' + os.path.join(path, 'assets/') + ' ' +
              os.path.join(path, 'cache/') + ' ' + os.path.join(path, 'db/'))
        shell('chown -R http:http ' + path)
Example #26
0
	def pre_install(self, name, vars):
		rubyctl = apis.langassist(self.app).get_interface('Ruby')
		rubyctl.install_gem('jekyll', 'rdiscount')
Example #27
0
    def post_install(self, name, path, vars, dbinfo={}):
        phpctl = apis.langassist(self.app).get_interface('PHP')
        secret_key = hashlib.sha1(str(random.random())).hexdigest()
        dbengine = 'mysql' if dbinfo['engine'] == 'MariaDB' else 'sqlite'

        username = vars.getvalue("wb-username", "wallabag")
        passwd = vars.getvalue("wb-passwd", "wallabag") + username + secret_key
        passwd = hashlib.sha1(passwd).hexdigest()

        # Write a standard Wallabag config file
        shutil.copy(os.path.join(path, 'inc/poche/config.inc.default.php'),
            os.path.join(path, 'inc/poche/config.inc.php'))
        ic = open(os.path.join(path, 'inc/poche/config.inc.php'), 'r').readlines()
        f = open(os.path.join(path, 'inc/poche/config.inc.php'), 'w')
        oc = []
        for l in ic:
            if 'define (\'SALT\'' in l:
                l = '@define (\'SALT\', \''+secret_key+'\');\n'
                oc.append(l)
            elif 'define (\'STORAGE\'' in l:
                l = '@define (\'STORAGE\', \''+dbengine+'\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_SQLITE\'' in l and dbengine == 'sqlite':
                l = '@define (\'STORAGE_SQLITE\', \'/var/lib/sqlite3/'+dbinfo['name']+'.db\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_DB\'' in l and dbengine == 'mysql':
                l = '@define (\'STORAGE_DB\', \''+dbinfo['name']+'\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_USER\'' in l and dbengine == 'mysql':
                l = '@define (\'STORAGE_USER\', \''+dbinfo['user']+'\');\n'
                oc.append(l)
            elif 'define (\'STORAGE_PASSWORD\'' in l and dbengine == 'mysql':
                l = '@define (\'STORAGE_PASSWORD\', \''+dbinfo['passwd']+'\');\n'
                oc.append(l)
            else:
                oc.append(l)
        f.writelines(oc)
        f.close()

        # Make sure that the correct PHP settings are enabled
        phpctl.enable_mod('mysql' if dbengine == 'mysql' else 'sqlite3', 
            'pdo_mysql' if dbengine == 'mysql' else 'pdo_sqlite', 
            'zip', 'tidy', 'xcache', 'openssl')

        # Set up Composer and install the proper modules
        phpctl.composer_install(path)

        # Set up the database then delete the install folder
        if dbengine == 'mysql':
            dbase = apis.databases(self.app).get_interface(dbinfo['engine'])
            conn = apis.databases(self.app).get_dbconn(dbinfo['engine'])
            dbase.execute(dbinfo['name'], 
                open(os.path.join(path, 'install/mysql.sql')).read(), conn)
            dbase.execute(dbinfo['name'],
                "INSERT INTO users (username, password, name, email) VALUES ('%s', '%s', '%s', '');" % (username, passwd, username),
                conn, commit=True)
            lid = int(conn.insert_id())
            dbase.execute(dbinfo['name'],
                "INSERT INTO users_config (user_id, name, value) VALUES (%s, 'pager', '10');" % lid,
                conn, commit=True)
            dbase.execute(dbinfo['name'],
                "INSERT INTO users_config (user_id, name, value) VALUES (%s, 'language', 'en_EN.UTF8');" % lid,
                conn, commit=True)
        else:
            dbase = apis.databases(self.app).get_interface(dbinfo['engine'])
            dbase.chkpath()
            shutil.copy(os.path.join(path, 'install/poche.sqlite'), '/var/lib/sqlite3/%s.db' % dbinfo['name'])
            phpctl.open_basedir('add', '/var/lib/sqlite3')
            shell('chown :sqlite3 /var/lib/sqlite3/%s.db' % dbinfo['name'])
            dbase.execute(dbinfo['name'],
                "INSERT INTO users (username, password, name, email) VALUES ('%s', '%s', '%s', '');" % (username, passwd, username))
            dbase.execute(dbinfo['name'],
                "INSERT INTO users_config (user_id, name, value) VALUES (1, 'pager', '10');")
            dbase.execute(dbinfo['name'],
                "INSERT INTO users_config (user_id, name, value) VALUES (1, 'language', 'en_EN.UTF8');")
        shutil.rmtree(os.path.join(path, 'install'))

        # Finally, make sure that permissions are set so that Wallabag
        # can make adjustments and save plugins when need be.
        shell('chmod -R 755 '+os.path.join(path, 'assets/')+' '
            +os.path.join(path, 'cache/')+' '
            +os.path.join(path, 'db/'))
        shell('chown -R http:http '+path)
Example #28
0
 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')
Example #29
0
    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)
Example #30
0
    def post_install(self, name, path, vars, dbinfo={}):
        phpctl = apis.langassist(self.app).get_interface('PHP')
        datadir = ''
        secret_key = hashlib.sha1(str(random.random())).hexdigest()
        username = vars.getvalue('oc-username')
        logpasswd = vars.getvalue('oc-logpasswd')

        # Set ownership as necessary
        if not os.path.exists(os.path.join(path, 'data')):
            os.makedirs(os.path.join(path, 'data'))
        shell('chown -R http:http '+path)

        # If there is a custom path for the data directory, do the magic
        if vars.getvalue('oc-ddir', '') != '':
            datadir = vars.getvalue('oc-ddir')
            if not os.path.exists(os.path.join(datadir if datadir else path, 'data')):
                os.makedirs(os.path.join(datadir if datadir else path, 'data'))
            shell('chown -R http:http '+os.path.join(datadir if datadir else path, 'data'))
            phpctl.open_basedir('add', datadir)

        # Create ownCloud automatic configuration file
        f = open(os.path.join(path, 'config', 'autoconfig.php'), 'w')
        f.write(
            '<?php\n'
            '   $AUTOCONFIG = array(\n'
            '   "adminlogin" => "'+username+'",\n'
            '   "adminpass" => "'+logpasswd+'",\n'
            '   "dbtype" => "mysql",\n'
            '   "dbname" => "'+dbinfo['name']+'",\n'
            '   "dbuser" => "'+dbinfo['user']+'",\n'
            '   "dbpass" => "'+dbinfo['passwd']+'",\n'
            '   "dbhost" => "localhost",\n'
            '   "dbtableprefix" => "",\n'
            '   "directory" => "'+os.path.join(datadir if datadir else path, 'data')+'",\n'
            '   );\n'
            '?>\n'
            )
        f.close()
        shell('chown http:http '+os.path.join(path, 'config', 'autoconfig.php'))

        # Make sure that the correct PHP settings are enabled
        phpctl.enable_mod('mysql', 'pdo_mysql', 'zip', 'gd',
            'iconv', 'openssl', 'xcache')
        
        # Make sure xcache has the correct settings, otherwise ownCloud breaks
        f = open('/etc/php/conf.d/xcache.ini', 'w')
        oc = ['extension=xcache.so\n',
            'xcache.size=64M\n',
            'xcache.var_size=64M\n',
            'xcache.admin.enable_auth = Off\n',
            'xcache.admin.user = "******"\n',
            'xcache.admin.pass = "******"\n']
        f.writelines(oc)
        f.close()

        # Return an explicatory message
        if self.app.board in ['BeagleBone Black,' 'Raspberry Pi']:
            return ('ownCloud takes a long time to set up on this platform. '
            'Once you open the page for the first time, it may take 5-10 '
            'minutes for the content to appear. Please do not refresh the '
            'page.')
Example #31
0
    def post_install(self, name, path, vars, dbinfo={}):
        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')

        d = json.loads(open(os.path.join(path, 'package.json'), 'r').read())
        del d['dependencies']['bcryptjs']
        d['dependencies']['bcrypt'] = '0.7.8'
        open(os.path.join(path, 'package.json'), 'w').write(json.dumps(d))
        d = open(os.path.join(path, 'core/server/models/user.js'), 'r').read()
        d = d.replace('bcryptjs', 'bcrypt')
        open(os.path.join(path, 'core/server/models/user.js'), 'w').write(d)

        nodectl.install_from_package(path, 'production', {
            'sqlite': '/usr/bin',
            'python': '/usr/bin/python2'
        })
        users.add_user('ghost')

        s = self.app.get_backend(apis.services.IServiceManager)
        s.edit(
            'ghost', {
                'stype': 'program',
                'directory': path,
                'user': '******',
                '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'
            })
        s.enable('ghost', 'supervisor')

        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)
Example #32
0
    def post_install(self, name, path, vars, dbinfo={}):
        UsersBackend(self.app).add_user('etherpad')

        # Create/Edit the config file
        cfg = {
            "title":
            "Etherpad",
            "favicon":
            "favicon.ico",
            "ip":
            "127.0.0.1",
            "port":
            "2369",
            "sessionKey":
            hashlib.sha1(str(random.random())).hexdigest(),
            "dbType":
            "mysql",
            "dbSettings": {
                "user": dbinfo['user'],
                "host": "localhost",
                "password": dbinfo['passwd'],
                "database": dbinfo['name']
            },
            "defaultPadText":
            ("Welcome to Etherpad on arkOS!\n\nThis pad text is "
             "synchronized as you type, so that everyone viewing this page "
             "sees the same text. This allows you to collaborate seamlessly "
             "on documents!\n\nGet involved with Etherpad at "
             "http://etherpad.org, or with arkOS at http://arkos.io\n"),
            "requireSession":
            False,
            "editOnly":
            False,
            "minify":
            True,
            "maxAge":
            60 * 60 * 6,
            "abiword":
            None,
            "requireAuthentication":
            False,
            "requireAuthorization":
            False,
            "trustProxy":
            True,
            "disableIPlogging":
            False,
            "socketTransportProtocols":
            ["xhr-polling", "jsonp-polling", "htmlfile"],
            "loglevel":
            "INFO",
            "logconfig": {
                "appenders": [{
                    "type": "console"
                }]
            },
            "users": {
                vars.getvalue('ether_admin'): {
                    "password": vars.getvalue('ether_pass'),
                    "is_admin": True
                },
            },
        }
        with open(os.path.join(path, 'settings.json'), 'w') as f:
            json.dump(cfg, f, indent=4)

        # node-gyp needs the HOME variable to be set
        with open(os.path.join(path, 'bin/run.sh')) as f:
            run_script = f.readlines()
        run_script.insert(1, "export HOME=%s" % path)
        with open(os.path.join(path, 'bin/run.sh'), 'w') as f:
            f.writelines(run_script)

        # Install deps right away
        if not shell(os.path.join(path, 'bin/installDeps.sh') + ' || exit 1'):
            raise RuntimeError("Etherpad dependencies could not be installed.")

        # Install selected plugins
        mods = list(  # e.g. "ep_plugin/ep_adminpads"
            str(var).split("/")[1]  #                 ^^^^^^^^^^^^
            for var in vars
            if var.startswith('ep_plugin/') and int(vars.getvalue(var)))
        if mods:
            mod_inst_path = os.path.join(path, "node_modules")
            if not os.path.exists(mod_inst_path):
                os.mkdir(mod_inst_path)
            nodectl = apis.langassist(self.app).get_interface('NodeJS')
            nodectl.install(*mods, install_path=mod_inst_path)

        # Make supervisor entry
        s = self.app.get_backend(apis.services.IServiceManager)
        s.edit(
            'etherpad', {
                'stype': 'program',
                'directory': path,
                'user': '******',
                'command': os.path.join(path, 'bin/run.sh'),
                'autostart': 'true',
                'autorestart': 'true',
                'stdout_logfile': '/var/log/etherpad.log',
                'stderr_logfile': '/var/log/etherpad.log'
            })
        s.enable('etherpad', 'supervisor')

        # Change owner of everything in the etherpad path
        shell('chown -R etherpad ' + path)
Example #33
0
	def post_install(self, name, path, vars):
		# Get the database object, and determine proper values
		phpctl = apis.langassist(self.app).get_interface('PHP')
		dbase = apis.databases(self.app).get_interface('MariaDB')
		conn = apis.databases(self.app).get_dbconn('MariaDB')
		if vars.getvalue('wp-dbname', '') == '':
			dbname = name
		else:
			dbname = vars.getvalue('wp-dbname')
		secret_key = hashlib.sha1(str(random.random())).hexdigest()
		if vars.getvalue('wp-dbpasswd', '') == '':
			passwd = secret_key[0:8]
		else:
			passwd = vars.getvalue('wp-dbpasswd')

		# Request a database and user to interact with it
		dbase.add(dbname, conn)
		dbase.usermod(dbname, 'add', passwd, conn)
		dbase.chperm(dbname, dbname, 'grant', conn)

		# Use the WordPress key generators as first option
		# If connection fails, use the secret_key as fallback
		try:
			keysection = urllib.urlopen('https://api.wordpress.org/secret-key/1.1/salt/').read()
		except:
			keysection = ''
		if not 'define(\'AUTH_KEY' in keysection:
			keysection = (
				'define(\'AUTH_KEY\', \''+secret_key+'\');\n'
				'define(\'SECURE_AUTH_KEY\', \''+secret_key+'\');\n'
				'define(\'LOGGED_IN_KEY\', \''+secret_key+'\');\n'
				'define(\'NONCE_KEY\', \''+secret_key+'\');\n'
				)

		# Write a standard WordPress config file
		f = open(os.path.join(path, 'wp-config.php'), 'w')
		f.write('<?php\n'
				'define(\'DB_NAME\', \''+dbname+'\');\n'
				'define(\'DB_USER\', \''+dbname+'\');\n'
				'define(\'DB_PASSWORD\', \''+passwd+'\');\n'
				'define(\'DB_HOST\', \'localhost\');\n'
				'define(\'DB_CHARSET\', \'utf8\');\n'
				'define(\'SECRET_KEY\', \''+secret_key+'\');\n'
				'\n'
				'define(\'WP_CACHE\', true);\n'
				'define(\'FORCE_SSL_ADMIN\', false);\n'
				'\n'
				+keysection+
				'\n'
				'$table_prefix = \'wp_\';\n'
				'\n'
				'/** Absolute path to the WordPress directory. */\n'
				'if ( !defined(\'ABSPATH\') )\n'
				'	define(\'ABSPATH\', dirname(__FILE__) . \'/\');\n'
				'\n'
				'/** Sets up WordPress vars and included files. */\n'
				'require_once(ABSPATH . \'wp-settings.php\');\n'
			)
		f.close()

		# Make sure that the correct PHP settings are enabled
		phpctl.enable_mod('mysql', 'xcache')

		# Finally, make sure that permissions are set so that Wordpress
		# can make adjustments and save plugins when need be.
		shell('chown -R http:http '+path)
Example #34
0
    def post_install(self, name, path, vars, dbinfo={}):
        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')

        d = json.loads(open(os.path.join(path, 'package.json'), 'r').read())
        del d['dependencies']['bcryptjs']
        d['dependencies']['bcrypt'] = '0.7.8'
        open(os.path.join(path, 'package.json'), 'w').write(json.dumps(d))
        d = open(os.path.join(path, 'core/server/models/user.js'), 'r').read()
        d = d.replace('bcryptjs', 'bcrypt')
        open(os.path.join(path, 'core/server/models/user.js'), 'w').write(d)

        nodectl.install_from_package(path, 'production')
        users.add_user('ghost')

        s = self.app.get_backend(apis.services.IServiceManager)
        s.edit('ghost',
            {
                'stype': 'program',
                'directory': path,
                'user': '******',
                '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'
            }
        )
        s.enable('ghost', 'supervisor')

        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)
Example #35
0
 def pre_install(self, name, vars):
     rubyctl = apis.langassist(self.app).get_interface("Ruby")
     rubyctl.install_gem("jekyll", "rdiscount")