Beispiel #1
0
 def del_alias(self, addr, forward):
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     dbase.execute(
         'vmail',
         'DELETE FROM `alias` WHERE address = \"%s\" AND goto = \"%s\"' %
         (addr, forward), conn, False)
Beispiel #2
0
 def pre_remove(self, name, path):
     datadir = ''
     dbname = name
     if os.path.exists(os.path.join(path, 'config', 'config.php')):
         f = open(os.path.join(path, 'config', 'config.php'), 'r')
         for line in f.readlines():
             if 'dbname' in line:
                 data = line.split('\'')[1::2]
                 dbname = data[1]
             elif 'datadirectory' in line:
                 data = line.split('\'')[1::2]
                 datadir = data[1]
         f.close()
     elif os.path.exists(os.path.join(path, 'config', 'autoconfig.php')):
         f = open(os.path.join(path, 'config', 'autoconfig.php'), 'r')
         for line in f.readlines():
             if 'dbname' in line:
                 data = line.split('\"')[1::2]
                 dbname = data[1]
             elif 'directory' in line:
                 data = line.split('\'')[1::2]
                 datadir = data[1]
         f.close()
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     dbase.remove(dbname, conn)
     dbase.usermod(dbname, 'del', '', conn)
     if datadir:
         shutil.rmtree(datadir)
         phpctl.open_basedir('del', datadir)
Beispiel #3
0
 def del_mailbox(self, name, dom):
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     dbase.execute(
         'vmail',
         'DELETE FROM `mailbox` WHERE local_part = \"%s\" AND domain = \"%s\"'
         % (name, dom), conn, False)
Beispiel #4
0
 def pre_remove(self, name, path):
     datadir = ''
     dbname = name
     if os.path.exists(os.path.join(path, 'config', 'config.php')):
         f = open(os.path.join(path, 'config', 'config.php'), 'r')
         for line in f.readlines():
             if 'dbname' in line:
                 data = line.split('\'')[1::2]
                 dbname = data[1]
             elif 'datadirectory' in line:
                 data = line.split('\'')[1::2]
                 datadir = data[1]
         f.close()
     elif os.path.exists(os.path.join(path, 'config', 'autoconfig.php')):
         f = open(os.path.join(path, 'config', 'autoconfig.php'), 'r')
         for line in f.readlines():
             if 'dbname' in line:
                 data = line.split('\"')[1::2]
                 dbname = data[1]
             elif 'directory' in line:
                 data = line.split('\'')[1::2]
                 datadir = data[1]
         f.close()
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     dbase.remove(dbname, conn)
     dbase.usermod(dbname, 'del', '', conn)
     if datadir:
         shutil.rmtree(datadir)
         phpctl.open_basedir('del', datadir)
Beispiel #5
0
 def is_setup(self):
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     if 'vmail' not in [x['name'] for x in dbase.get_dbs(conn)] \
     or 'vmail' not in [x['name'] for x in dbase.get_users(conn)]:
         return False
     else:
         return True
Beispiel #6
0
 def is_setup(self):
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     if 'vmail' not in [x['name'] for x in dbase.get_dbs(conn)] \
     or 'vmail' not in [x['name'] for x in dbase.get_users(conn)]:
         return False
     else:
         return True
Beispiel #7
0
 def list_domains(self):
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     try:
         d = dbase.execute('vmail', 
             'SELECT domain FROM domain;', conn, False)
     except _mysql_exceptions.OperationalError, e:
         if e[0] == 1049:
             return []
Beispiel #8
0
 def add_mailbox(self, name, dom, passwd, fullname, quota=False):
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     pwhash = ldap_md5_crypt.encrypt(passwd).split('{CRYPT}')[1]
     dbase.execute('vmail',
         'INSERT INTO `mailbox` VALUES (\"'+name+'@'+dom+'\", '+\
         '\"'+pwhash+'\", \"'+fullname+'\", \"'+name+'@'+dom+'/\", '+\
         (quota if quota else '0')+', \"'+name+'\", \"'+dom+'\", '+\
         'NOW(), 1)', conn, False)
Beispiel #9
0
 def list_domains(self):
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     try:
         d = dbase.execute('vmail', 'SELECT domain FROM domain;', conn,
                           False)
     except _mysql_exceptions.OperationalError, e:
         if e[0] == 1049:
             return []
Beispiel #10
0
 def pre_install(self, name, vars):
     eth_name = vars.getvalue('ether_admin', '')
     eth_pass = vars.getvalue('ether_pass', '')
     if not (eth_name and eth_pass):
         raise Exception('You must enter an admin name AND password'
                         'in the App Settings tab!')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     apis.databases(self.app).get_interface('MariaDB').validate(
         name, name, eth_pass, conn)
Beispiel #11
0
 def add_mailbox(self, name, dom, passwd, fullname, quota=False):
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     pwhash = ldap_md5_crypt.encrypt(passwd).split('{CRYPT}')[1]
     dbase.execute('vmail',
         'INSERT INTO `mailbox` VALUES (\"'+name+'@'+dom+'\", '+\
         '\"'+pwhash+'\", \"'+fullname+'\", \"'+name+'@'+dom+'/\", '+\
         (quota if quota else '0')+', \"'+name+'\", \"'+dom+'\", '+\
         'NOW(), 1)', conn, False)
Beispiel #12
0
 def pre_install(self, name, vars):
     dbname = vars.getvalue('wb-dbname', '')
     dbpasswd = vars.getvalue('wb-dbpasswd', '')
     if dbname and dbpasswd:
         apis.databases(self.app).get_interface('MariaDB').validate(
             dbname, dbname, dbpasswd)
     elif dbname:
         raise Exception('You must enter a database password if you specify a database name!')
     elif dbpasswd:
         raise Exception('You must enter a database name if you specify a database password!')
Beispiel #13
0
 def pre_install(self, name, vars):
     eth_name = vars.getvalue('ether_admin', '')
     eth_pass = vars.getvalue('ether_pass', '')
     if not (eth_name and eth_pass):
         raise Exception('You must enter an admin name AND password'
                         'in the App Settings tab!')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     apis.databases(self.app).get_interface('MariaDB').validate(
         name, name, eth_pass, conn
     )
Beispiel #14
0
 def list_aliases(self, domain):
     r = []
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     d = dbase.execute('vmail', 
         'SELECT address,goto FROM alias WHERE domain = \"%s\";'%domain, 
         conn, False)
     for x in d:
         r.append({'address': x[0], 'forward': x[1], 'domain': domain})
     return r
Beispiel #15
0
 def list_aliases(self, domain):
     r = []
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     d = dbase.execute(
         'vmail',
         'SELECT address,goto FROM alias WHERE domain = \"%s\";' % domain,
         conn, False)
     for x in d:
         r.append({'address': x[0], 'forward': x[1], 'domain': domain})
     return r
Beispiel #16
0
 def list_mailboxes(self, domain):
     r = []
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     d = dbase.execute('vmail', 
         'SELECT local_part,name,quota FROM mailbox WHERE domain = \"%s\"'%domain, 
         conn, False)
     for x in d:
         r.append({'username': x[0], 'name': x[1], 'quota': x[2],
             'domain': domain})
     return r
Beispiel #17
0
 def pre_remove(self, name, path):
     f = open(os.path.join(path, 'inc/poche/config.inc.php'), 'r')
     for line in f.readlines():
         if 'STORAGE_DB' in line:
             data = line.split('\'')[1::2]
             dbname = data[1]
             break
     f.close()
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     dbase.remove(dbname, conn)
     dbase.usermod(dbname, 'del', '', conn)
Beispiel #18
0
 def pre_remove(self, name, path):
     f = open(os.path.join(path, 'wp-config.php'), 'r')
     for line in f.readlines():
         if 'DB_NAME' in line:
             data = line.split('\'')[1::2]
             dbname = data[1]
             break
     f.close()
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     dbase.remove(dbname, conn)
     dbase.usermod(dbname, 'del', '', conn)
Beispiel #19
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')
Beispiel #20
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')
Beispiel #21
0
 def pre_install(self, name, vars):
     dbname = vars.getvalue("oc-dbname", "")
     dbpasswd = vars.getvalue("oc-dbpasswd", "")
     if dbname and dbpasswd:
         apis.databases(self.app).get_interface("MariaDB").validate(dbname, dbname, dbpasswd)
     elif dbname:
         raise Exception("You must enter a database password if you specify a database name!")
     elif dbpasswd:
         raise Exception("You must enter a database name if you specify a database password!")
     if vars.getvalue("oc-username", "") == "":
         raise Exception("Must choose an ownCloud username")
     elif vars.getvalue("oc-logpasswd", "") == "":
         raise Exception("Must choose an ownCloud password")
Beispiel #22
0
 def edit(self, name, dom, quota, passwd):
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     if passwd:
         pwhash = ldap_md5_crypt.encrypt(passwd).split('{CRYPT}')[1]
     if passwd and quota:
         dbase.execute('vmail',
             'UPDATE mailbox SET quota = %s, password = \"%s\" WHERE local_part = \"%s\" AND domain = \"%s\"'%(quota,pwhash,name,dom), conn, False)
     elif passwd:
         dbase.execute('vmail',
             'UPDATE mailbox SET password = \"%s\" WHERE local_part = \"%s\" AND domain = \"%s\"'%(pwhash,name,dom), conn, False)
     elif quota:
         dbase.execute('vmail',
             'UPDATE mailbox SET quota = %s WHERE local_part = \"%s\" AND domain = \"%s\"'%(quota,name,dom), conn, False)
Beispiel #23
0
	def pre_install(self, name, vars):
		dbname = vars.getvalue('oc-dbname', '')
		dbpasswd = vars.getvalue('oc-dbpasswd', '')
		if dbname and dbpasswd:
			apis.databases(self.app).get_interface('MariaDB').validate(
				dbname, dbname, dbpasswd)
		elif dbname:
			raise Exception('You must enter a database password if you specify a database name!')
		elif dbpasswd:
			raise Exception('You must enter a database name if you specify a database password!')
		if vars.getvalue('oc-username', '') == '':
			raise Exception('Must choose an ownCloud username')
		elif vars.getvalue('oc-logpasswd', '') == '':
			raise Exception('Must choose an ownCloud password')
Beispiel #24
0
 def pre_install(self, name, vars):
     dbname = vars.getvalue('wp-dbname', '')
     dbpasswd = vars.getvalue('wp-dbpasswd', '')
     if dbname and dbpasswd:
         apis.databases(self.app).get_interface('MariaDB').validate(
             dbname, dbname, dbpasswd)
     elif dbname:
         raise Exception(
             'You must enter a database password if you specify a database name!'
         )
     elif dbpasswd:
         raise Exception(
             'You must enter a database name if you specify a database password!'
         )
Beispiel #25
0
 def list_mailboxes(self, domain):
     r = []
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     d = dbase.execute(
         'vmail',
         'SELECT local_part,name,quota FROM mailbox WHERE domain = \"%s\"' %
         domain, conn, False)
     for x in d:
         r.append({
             'username': x[0],
             'name': x[1],
             'quota': x[2],
             'domain': domain
         })
     return r
Beispiel #26
0
	def on_init(self):
		self.dbops = apis.databases(self.app)
		self.dbs = sorted(self.dbops.get_databases(), 
			key=lambda db: db['name'])
		self.users = sorted(self.dbops.get_users(), 
			key=lambda db: db['name'])
		self.dbtypes = sorted(self.dbops.get_dbtypes())
Beispiel #27
0
    def post_install(self, name, path, vars):
        # Create a database if the user wants one
        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)
            dbase.add(dbname)
            dbase.usermod(dbname, "add", passwd)
            dbase.chperm(dbname, dbname, "grant")

            # Write a basic index file showing that we are here
        if vars.getvalue("php", "0") == "1":
            php = True
        else:
            php = False
        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)
Beispiel #28
0
	def post_install(self, name, path, vars):
		# Create a database if the user wants one
		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)
			dbase.add(dbname)
			dbase.usermod(dbname, 'add', passwd)
			dbase.chperm(dbname, dbname, 'grant')
			shell('sed -i s/\;extension=mysql.so/extension=mysql.so/g /etc/php/php.ini')

		# Write a basic index file showing that we are here
		if vars.getvalue('php', '0') == '1':
			php = True
		else:
			php = False
		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:
			shell('sed -i s/\;extension=xcache.so/extension=xcache.so/g /etc/php/conf.d/xcache.ini')
Beispiel #29
0
 def list_aliases(self, domain):
     r = []
     dbase = apis.databases(self.app).get_interface('SQLite3')
     d = dbase.execute('vmail', 
         'SELECT address,goto FROM alias WHERE domain = "%s";'%domain)
     for x in d:
         r.append({'address': x[0], 'forward': x[1], 'domain': domain})
     return r
Beispiel #30
0
 def list_aliases(self, domain):
     r = []
     dbase = apis.databases(self.app).get_interface('SQLite3')
     d = dbase.execute(
         'vmail',
         'SELECT address,goto FROM alias WHERE domain = "%s";' % domain)
     for x in d:
         r.append({'address': x[0], 'forward': x[1], 'domain': domain})
     return r
Beispiel #31
0
 def list_mailboxes(self, domain):
     r = []
     dbase = apis.databases(self.app).get_interface('SQLite3')
     d = dbase.execute('vmail', 
         'SELECT local_part,name,quota FROM mailbox WHERE domain = "%s"'%domain)
     for x in d:
         r.append({'username': x[0], 'name': x[1], 'quota': x[2],
             'domain': domain})
     return r
Beispiel #32
0
    def post_install(self, name, path, vars):
        # Get the database object, and determine proper values
        dbase = apis.databases(self.app).get_interface('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)
        dbase.usermod(dbname, 'add', passwd)
        dbase.chperm(dbname, dbname, 'grant')

        # 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'
                '\n'
                '/*\n'
                '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'
                '*/'
                '\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
        shell(
            'sed -i s/;extension=mysql.so/extension=mysql.so/g /etc/php/php.ini'
        )

        # 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)
Beispiel #33
0
	def post_install(self, name, path, vars):
		dbase = apis.databases(self.app).get_interface('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)
		dbase.usermod(dbname, 'add', passwd)
		dbase.chperm(dbname, dbname, 'grant')

		# 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
		shell('sed -i s/\;extension=mysql.so/extension=mysql.so/g /etc/php/php.ini')
		shell('sed -i s/\;extension=zip.so/extension=zip.so/g /etc/php/php.ini')
		shell('sed -i s/\;extension=gd.so/extension=gd.so/g /etc/php/php.ini')
		shell('sed -i s/\;extension=iconv.so/extension=iconv.so/g /etc/php/php.ini')
		shell('sed -i s/\;extension=openssl.so/extension=openssl.so/g /etc/php/php.ini')
		shell('sed -i s/\;extension=apc.so/extension=apc.so/g /etc/php/conf.d/apc.ini')

		# 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.'
Beispiel #34
0
 def edit(self, name, dom, quota, passwd):
     dbase = apis.databases(self.app).get_interface('MariaDB')
     conn = apis.databases(self.app).get_dbconn('MariaDB')
     if passwd:
         pwhash = ldap_md5_crypt.encrypt(passwd).split('{CRYPT}')[1]
     if passwd and quota:
         dbase.execute(
             'vmail',
             'UPDATE mailbox SET quota = %s, password = \"%s\" WHERE local_part = \"%s\" AND domain = \"%s\"'
             % (quota, pwhash, name, dom), conn, False)
     elif passwd:
         dbase.execute(
             'vmail',
             'UPDATE mailbox SET password = \"%s\" WHERE local_part = \"%s\" AND domain = \"%s\"'
             % (pwhash, name, dom), conn, False)
     elif quota:
         dbase.execute(
             'vmail',
             'UPDATE mailbox SET quota = %s WHERE local_part = \"%s\" AND domain = \"%s\"'
             % (quota, name, dom), conn, False)
Beispiel #35
0
	def pre_remove(self, name, path):
		f = open(os.path.join(path, 'wp-config.php'), 'r')
		for line in f.readlines():
			if 'DB_NAME' in line:
				data = line.split('\'')[1::2]
				dbname = data[1]
				break
		f.close()
		dbase = apis.databases(self.app).get_interface('MariaDB')
		dbase.remove(dbname)
		dbase.usermod(dbname, 'del', '')
Beispiel #36
0
	def post_install(self, name, path, vars):
		# Get the database object, and determine proper values
		dbase = apis.databases(self.app).get_interface('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)
		dbase.usermod(dbname, 'add', passwd)
		dbase.chperm(dbname, dbname, 'grant')

		# 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'
				'\n'
				'/*\n'
				'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'
				'*/'
				'\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
		shell('sed -i s/;extension=mysql.so/extension=mysql.so/g /etc/php/php.ini')

		# 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)
Beispiel #37
0
 def download(self, req, start_response):
     params = req['PATH_INFO'].split('/')[3:]
     iface = apis.databases(self.app).get_interface(params[0])
     if iface.plugin_info.requires_conn:
         d = iface.dump(params[1], self.app.session['dbconns'][params[0]])
     else:
         d = iface.dump(params[1])
     start_response('200 OK',
                    [('Content-length', str(len(d.encode('utf-8')))),
                     ('Content-Disposition',
                      'attachment; filename=%s' % params[1] + '.sql')])
     return d
Beispiel #38
0
 def download(self, req, start_response):
     params = req['PATH_INFO'].split('/')[3:]
     iface = apis.databases(self.app).get_interface(params[0])
     if iface.plugin_info.requires_conn:
         d = iface.dump(params[1], self.app.session['dbconns'][params[0]])
     else:
         d = iface.dump(params[1])
     start_response('200 OK', [
         ('Content-length', str(len(d.encode('utf-8')))),
         ('Content-Disposition', 'attachment; filename=%s'%params[1]+'.sql')
     ])
     return d
Beispiel #39
0
 def pre_remove(self, name, path):
     dbname = name
     if os.path.exists(os.path.join(path, "config", "config.php")):
         f = open(os.path.join(path, "config", "config.php"), "r")
         for line in f.readlines():
             if "dbname" in line:
                 data = line.split("'")[1::2]
                 dbname = data[1]
                 break
         f.close()
     elif os.path.exists(os.path.join(path, "config", "autoconfig.php")):
         f = open(os.path.join(path, "config", "autoconfig.php"), "r")
         for line in f.readlines():
             if "dbname" in line:
                 data = line.split('"')[1::2]
                 dbname = data[1]
                 break
         f.close()
     dbase = apis.databases(self.app).get_interface("MariaDB")
     conn = apis.databases(self.app).get_dbconn("MariaDB")
     dbase.remove(dbname, conn)
     dbase.usermod(dbname, "del", "", conn)
Beispiel #40
0
	def pre_remove(self, name, path):
		dbname = name
		if os.path.exists(os.path.join(path, 'config', 'config.php')):
			f = open(os.path.join(path, 'config', 'config.php'), 'r')
			for line in f.readlines():
				if 'dbname' in line:
					data = line.split('\'')[1::2]
					dbname = data[1]
					break
			f.close()
		elif os.path.exists(os.path.join(path, 'config', 'autoconfig.php')):
			f = open(os.path.join(path, 'config', 'autoconfig.php'), 'r')
			for line in f.readlines():
				if 'dbname' in line:
					data = line.split('\"')[1::2]
					dbname = data[1]
					break
			f.close()
		dbase = apis.databases(self.app).get_interface('MariaDB')
		conn = apis.databases(self.app).get_dbconn('MariaDB')
		dbase.remove(dbname, conn)
		dbase.usermod(dbname, 'del', '', conn)
Beispiel #41
0
	def on_init(self):
		if self._relsec != None:
			if self._relsec[0] == 'add':
				apis.networkcontrol(self.app).add_webapp(self._relsec[1])
				self._relsec = None
			elif self._relsec[0] == 'del':
				apis.networkcontrol(self.app).remove_webapp(self._relsec[1])
			self._relsec = None
		self.services = []
		self.apiops = apis.webapps(self.app)
		self.dbops = apis.databases(self.app)
		self.mgr = WebappControl(self.app)
		self.sites = sorted(self.apiops.get_sites(), 
			key=lambda st: st.name)
		ats = sorted([x.plugin_info for x in self.apiops.get_apptypes()], key=lambda x: x.name.lower())
		self.apptypes = sorted(ats, key=lambda x: (hasattr(x, 'sort')))
		if len(self.sites) != 0:
			self.services.append(
				{
					"name": 'Web Server',
					"binary": 'nginx',
					"ports": []
				}
			)
			for x in self.sites:
				if x.php:
					self.services.append(
						{
							"name": 'PHP FastCGI',
							"binary": 'php-fpm',
							"ports": []
						}
					)
					break
		if not self._current:
			self._current = self.apptypes[0] if len(self.apptypes) else None
		for apptype in self.apptypes:
			ok = False
			for site in self.sites:
				if site.stype == apptype.wa_plugin:
					ok = True
			if ok == False:
				continue
			if hasattr(apptype, 'services'):
				for dep in apptype.services:
					post = True
					for svc in self.services:
						if svc['binary'] == dep['binary']:
							post = False
					if post == True:
						self.services.append({"name": dep['name'], "binary": dep['binary'], "ports": []})
Beispiel #42
0
 def on_init(self):
     if self._relsec != None:
         if self._relsec[0] == 'add':
             apis.networkcontrol(self.app).add_webapp(self._relsec[1])
             self._relsec = None
         elif self._relsec[0] == 'del':
             apis.networkcontrol(self.app).remove_webapp(self._relsec[1])
         self._relsec = None
     self.services = []
     self.apiops = apis.webapps(self.app)
     self.dbops = apis.databases(self.app)
     self.mgr = WebappControl(self.app)
     self.sites = sorted(self.apiops.get_sites(), key=lambda st: st.name)
     ats = sorted([x.plugin_info for x in self.apiops.get_apptypes()],
                  key=lambda x: x.name.lower())
     self.apptypes = sorted(ats, key=lambda x: (hasattr(x, 'sort')))
     if len(self.sites) != 0:
         self.services.append({
             "name": 'Web Server',
             "binary": 'nginx',
             "ports": []
         })
         for x in self.sites:
             if x.php:
                 self.services.append({
                     "name": 'PHP FastCGI',
                     "binary": 'php-fpm',
                     "ports": []
                 })
                 break
     if not self._current:
         self._current = self.apptypes[0] if len(self.apptypes) else None
     for apptype in self.apptypes:
         ok = False
         for site in self.sites:
             if site.stype == apptype.wa_plugin:
                 ok = True
         if ok == False:
             continue
         if hasattr(apptype, 'services'):
             for dep in apptype.services:
                 post = True
                 for svc in self.services:
                     if svc['binary'] == dep['binary']:
                         post = False
                 if post == True:
                     self.services.append({
                         "name": dep['name'],
                         "binary": dep['binary'],
                         "ports": []
                     })
Beispiel #43
0
 def list_mailboxes(self, domain):
     r = []
     dbase = apis.databases(self.app).get_interface('SQLite3')
     d = dbase.execute(
         'vmail',
         'SELECT local_part,name,quota FROM mailbox WHERE domain = "%s"' %
         domain)
     for x in d:
         r.append({
             'username': x[0],
             'name': x[1],
             'quota': x[2],
             'domain': domain
         })
     return r
Beispiel #44
0
 def edit(self, name, dom, quota, passwd):
     dbase = apis.databases(self.app).get_interface('SQLite3')
     if passwd:
         pwhash = ldap_md5_crypt.encrypt(passwd).split('{CRYPT}')[1]
     if passwd and quota:
         dbase.execute('vmail',
             'UPDATE mailbox SET quota = %s, password = "******" WHERE local_part = "%s" AND domain = "%s"' \
             %(quota,pwhash,name,dom))
     elif passwd:
         dbase.execute('vmail',
             'UPDATE mailbox SET password = "******" WHERE local_part = "%s\" AND domain = "%s"' \
             %(pwhash,name,dom))
     elif quota:
         dbase.execute('vmail',
             'UPDATE mailbox SET quota = %s WHERE local_part = "%s" AND domain = "%s"' \
             %(quota,name,dom))
Beispiel #45
0
 def edit(self, name, dom, quota, passwd):
     dbase = apis.databases(self.app).get_interface('SQLite3')
     if passwd:
         pwhash = ldap_md5_crypt.encrypt(passwd).split('{CRYPT}')[1]
     if passwd and quota:
         dbase.execute('vmail',
             'UPDATE mailbox SET quota = %s, password = "******" WHERE local_part = "%s" AND domain = "%s"' \
             %(quota,pwhash,name,dom))
     elif passwd:
         dbase.execute('vmail',
             'UPDATE mailbox SET password = "******" WHERE local_part = "%s\" AND domain = "%s"' \
             %(pwhash,name,dom))
     elif quota:
         dbase.execute('vmail',
             'UPDATE mailbox SET quota = %s WHERE local_part = "%s" AND domain = "%s"' \
             %(quota,name,dom))
Beispiel #46
0
	def on_init(self):
		self.dbops = apis.databases(self.app)
		self.dbs = sorted(self.dbops.get_databases(), 
			key=lambda db: db['name'])
		self.users = sorted(self.dbops.get_users(), 
			key=lambda db: db['name'])
		self.dbtypes = sorted(self.dbops.get_dbtypes(), 
			key=lambda db: db[0])
		for dbtype in self.dbtypes:
			ok = True
			if dbtype[1] == '':
				ok = False
			for svc in self.services:
				if svc[1] == dbtype[1]:
					ok = False
			if ok == True:	
				self.services.append((dbtype[0], dbtype[1]))
Beispiel #47
0
 def on_init(self):
     self.dbops = apis.databases(self.app)
     self.dbs = sorted(self.dbops.get_databases(),
                       key=lambda db: db['name'])
     self.users = sorted(self.dbops.get_users(), key=lambda db: db['name'])
     self.dbtypes = sorted(self.dbops.get_dbtypes(), key=lambda db: db[0])
     for dbtype in self.dbtypes:
         ok = True
         if not dbtype[1]:
             ok = False
         for svc in self.services:
             if svc['binary'] == dbtype[1]:
                 ok = False
         if ok == True:
             self.services.append({
                 "name": dbtype[0],
                 "binary": dbtype[1],
                 "ports": []
             })
Beispiel #48
0
 def pre_remove(self, name, path):
     dbname = name
     if os.path.exists(os.path.join(path, 'config', 'config.php')):
         f = open(os.path.join(path, 'config', 'config.php'), 'r')
         for line in f.readlines():
             if 'dbname' in line:
                 data = line.split('\'')[1::2]
                 dbname = data[1]
                 break
         f.close()
     elif os.path.exists(os.path.join(path, 'config', 'autoconfig.php')):
         f = open(os.path.join(path, 'config', 'autoconfig.php'), 'r')
         for line in f.readlines():
             if 'dbname' in line:
                 data = line.split('\"')[1::2]
                 dbname = data[1]
                 break
         f.close()
     dbase = apis.databases(self.app).get_interface('MariaDB')
     dbase.remove(dbname)
     dbase.usermod(dbname, 'del', '')
Beispiel #49
0
class WebappControl(Plugin):
	def add(self, cat, wa, vars, dbinfo={}, enable=True):
		specialmsg = ''
		name = vars.getvalue('name', '').lower()
		webapp = apis.webapps(self.app).get_interface(wa.wa_plugin)

		if not wa.dpath:
			ending = ''
		elif wa.dpath.endswith('.tar.gz'):
			ending = '.tar.gz'
		elif wa.dpath.endswith('.tar.bz2'):
			ending = '.tar.bz2'
		elif wa.dpath.endswith('.zip'):
			ending = '.zip'
		elif wa.dpath.endswith('.git'):
			ending = '.git'
		else:
			raise InstallError('Only GIT repos, gzip, bzip, and zip packages supported for now')

		# Run webapp preconfig, if any
		try:
			cat.statusmsg('Running pre-install configuration...')
			webapp.pre_install(name, vars)
		except Exception, e:
			raise InstallError('Webapp config - '+str(e))

		if dbinfo:
			pwd = hashlib.sha1(str(random.random())).hexdigest()[0:16]
			dbinfo['name'] = dbinfo['name'] if dbinfo['name'] else name
			dbinfo['user'] = dbinfo['user'] if dbinfo['user'] else name
			dbinfo['passwd'] = dbinfo['passwd'] if dbinfo['passwd'] else pwd
			try:
				db = apis.databases(cat.app)
				dbase = db.get_interface(dbinfo['engine'])
				conn = db.get_dbconn(dbinfo['engine'])
				dbase.add(dbinfo['name'], conn)
				dbase.usermod(dbinfo['user'], 'add', dbinfo['passwd'], conn)
				dbase.chperm(dbinfo['name'], dbinfo['user'], 'grant', conn)
			except Exception, e:
				raise InstallError('Databases could not be created - %s' % str(e))
Beispiel #50
0
    def post_install(self, name, path, vars):
        # Create a database if the user wants one
        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)
            dbase.add(dbname)
            dbase.usermod(dbname, 'add', passwd)
            dbase.chperm(dbname, dbname, 'grant')
            shell(
                'sed -i s/\;extension=mysql.so/extension=mysql.so/g /etc/php/php.ini'
            )

        # Write a basic index file showing that we are here
        if vars.getvalue('php', '0') == '1':
            php = True
        else:
            php = False
        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:
            shell(
                'sed -i s/\;extension=xcache.so/extension=xcache.so/g /etc/php/conf.d/xcache.ini'
            )
Beispiel #51
0
	def remove(self, cat, site):
		if site.sclass != '' and site.stype != 'ReverseProxy':
			cat.statusmsg('Preparing for removal...')
			site.sclass.pre_remove(site)
		cat.statusmsg('Removing website...')
		if site.path.endswith('_site'):
			shutil.rmtree(site.path.split('/_site')[0])
		elif site.path.endswith('htdocs'):
			shutil.rmtree(site.path.split('/htdocs')[0])
		elif os.path.islink(site.path):
			os.unlink(site.path)
		else:
			shutil.rmtree(site.path)
		if hasattr(site, 'dbengine') and site.dbengine:
			try:
				db = apis.databases(cat.app)
				dbase = db.get_interface(site.dbengine)
				conn = db.get_dbconn(site.dbengine)
				dbase.remove(site.dbname, conn)
				dbase.usermod(site.dbuser, 'del', '', conn)
			except Exception, e:
				cat.put_message('warn', 'Databases could not be removed - maybe they are gone already? Please check manually.')
Beispiel #52
0
 def on_init(self):
     self.dbops = apis.databases(self.app)
     self.dbs = sorted(self.dbops.get_databases(), 
         key=lambda db: db['name'])
     self.users = sorted(self.dbops.get_users(), 
         key=lambda db: db['name'])
     self.dbtypes = sorted(self.dbops.get_dbtypes(), 
         key=lambda db: db[0])
     for dbtype in self.dbtypes:
         ok = True
         if not dbtype[1]:
             ok = False
         for svc in self.services:
             if svc['binary'] == dbtype[1]:
                 ok = False
         if ok == True:
             self.services.append(
                 {
                     "name": dbtype[0], 
                     "binary": dbtype[1],
                     "ports": []
                 }
             )
Beispiel #53
0
 def del_domain(self, name):
     dbase = apis.databases(self.app).get_interface('SQLite3')
     dbase.execute('vmail', 'DELETE FROM domain WHERE domain = "%s"' % name)
Beispiel #54
0
 def show_opts_add(self, ui):
     type_sel = [UI.SelectOption(text='None', value='None')]
     for x in sorted(apis.databases(self.app).get_dbtypes()):
         type_sel.append(UI.SelectOption(text=x[0], value=x[0]))
     ui.appendAll('ws-dbsel', *type_sel)
Beispiel #55
0
    def post_install(self, name, path, vars):
        dbase = apis.databases(self.app).get_interface('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)
        dbase.usermod(dbname, 'add', passwd)
        dbase.chperm(dbname, dbname, 'grant')

        # 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
        shell(
            'sed -i s/\;extension=mysql.so/extension=mysql.so/g /etc/php/php.ini'
        )
        shell(
            'sed -i s/\;extension=zip.so/extension=zip.so/g /etc/php/php.ini')
        shell('sed -i s/\;extension=gd.so/extension=gd.so/g /etc/php/php.ini')
        shell(
            'sed -i s/\;extension=iconv.so/extension=iconv.so/g /etc/php/php.ini'
        )
        shell(
            'sed -i s/\;extension=openssl.so/extension=openssl.so/g /etc/php/php.ini'
        )

        # 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.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.'
Beispiel #56
0
 def add_domain(self, name):
     dbase = apis.databases(self.app).get_interface('SQLite3')
     dbase.execute('vmail',
         'INSERT INTO domain VALUES ("%s", "virtual", 0, datetime(), 1)' \
         % name)