Browse Source

Fixed ViMbadmin conmfiguration issue

bugfixes
gau1991 10 years ago
parent
commit
0ad796b39c
  1. 81
      ee/cli/plugins/stack.py
  2. 24
      ee/core/mysql.py
  3. 1
      ee/core/shellexec.py

81
ee/cli/plugins/stack.py

@ -212,9 +212,9 @@ class EEStackController(CementBaseController):
# Custom Postfix configuration needed with Dovecot # Custom Postfix configuration needed with Dovecot
# Changes in master.cf # Changes in master.cf
# TODO: Find alternative for sed in Python # TODO: Find alternative for sed in Python
EEShellExec.cmd_exec("sed -i 's/#submission/submission/'" EEShellExec.cmd_exec("sed -i \'s/#submission/submission/\'"
"/etc/postfix/master.cf") " /etc/postfix/master.cf")
EEShellExec.cmd_exec("sed -i 's/#smtps/smtps/'" EEShellExec.cmd_exec("sed -i \'s/#smtps/smtps/\'"
" /etc/postfix/master.cf") " /etc/postfix/master.cf")
EEShellExec.cmd_exec("postconf -e \"smtpd_sasl_type = " EEShellExec.cmd_exec("postconf -e \"smtpd_sasl_type = "
@ -242,7 +242,7 @@ class EEStackController(CementBaseController):
EEShellExec.cmd_exec("postconf -e \"virtual_uid_maps " EEShellExec.cmd_exec("postconf -e \"virtual_uid_maps "
"= static:5000\"") "= static:5000\"")
EEShellExec.cmd_exec("postconf -e \"virtual_gid_maps " EEShellExec.cmd_exec("postconf -e \"virtual_gid_maps "
"= static:500\"") "= static:5000\"")
EEShellExec.cmd_exec("postconf -e \"virtual_mailbox_domains = " EEShellExec.cmd_exec("postconf -e \"virtual_mailbox_domains = "
"mysql:/etc/postfix/mysql/virtual_" "mysql:/etc/postfix/mysql/virtual_"
"domains_maps.cf\"") "domains_maps.cf\"")
@ -259,10 +259,10 @@ class EEStackController(CementBaseController):
.format(HOSTNAME=EEVariables.ee_fqdn, .format(HOSTNAME=EEVariables.ee_fqdn,
EMAIL=EEVariables.ee_email)) EMAIL=EEVariables.ee_email))
EEShellExec.cmd_exec("chmod 0600 /etc/ssl/private/postfix.pem") EEShellExec.cmd_exec("chmod 0600 /etc/ssl/private/postfix.pem")
EEShellExec.cmd_exec("postconf -e smtpd_tls_cert_file = " EEShellExec.cmd_exec("postconf -e \"smtpd_tls_cert_file = "
"/etc/ssl/certs/postfix.pem") "/etc/ssl/certs/postfix.pem\"")
EEShellExec.cmd_exec("postconf -e smtpd_tls_key_file = " EEShellExec.cmd_exec("postconf -e \"smtpd_tls_key_file = "
"/etc/ssl/private/postfix.pem") "/etc/ssl/private/postfix.pem\"")
if len(packages): if len(packages):
if any('/usr/bin/wp' == x[1] for x in packages): if any('/usr/bin/wp' == x[1] for x in packages):
@ -301,15 +301,14 @@ class EEStackController(CementBaseController):
shutil.move('/tmp/Anemometer-master', shutil.move('/tmp/Anemometer-master',
'/var/www/22222/htdocs/db/anemometer') '/var/www/22222/htdocs/db/anemometer')
chars = ''.join(random.sample(string.ascii_letters, 8)) chars = ''.join(random.sample(string.ascii_letters, 8))
anemometer_db = EEMysql()
EEShellExec.cmd_exec('mysql < /var/www/22222/htdocs/db' EEShellExec.cmd_exec('mysql < /var/www/22222/htdocs/db'
'/anemometer/install.sql') '/anemometer/install.sql')
anemometer_db.execute('grant select on *.* to \'anemometer\'' EEMysql.execute('grant select on *.* to \'anemometer\''
'@\'localhost\'') '@\'localhost\'')
anemometer_db.execute('grant all on slow_query_log.* to' EEMysql.execute('grant all on slow_query_log.* to'
'\'anemometer\'@\'localhost\' IDENTIFIED' '\'anemometer\'@\'localhost\' IDENTIFIED'
' BY \''+chars+'\'') ' BY \''+chars+'\'')
anemometer_db.close()
# Custom Anemometer configuration # Custom Anemometer configuration
data = dict(host='localhost', port='3306', user='anemometer', data = dict(host='localhost', port='3306', user='anemometer',
password=chars) password=chars)
@ -336,28 +335,29 @@ class EEStackController(CementBaseController):
EEShellExec.cmd_exec("cd /var/www/22222/htdocs/vimbadmin; curl" EEShellExec.cmd_exec("cd /var/www/22222/htdocs/vimbadmin; curl"
" -sS https://getcomposer.org/installer |" " -sS https://getcomposer.org/installer |"
" php") " php")
EEShellExec.cmd_exec("php composer.phar install --prefer-dist" EEShellExec.cmd_exec("cd /var/www/22222/htdocs/vimbadmin;"
"php composer.phar install --prefer-dist"
" --no-dev; rm -f /var/www/22222/htdocs" " --no-dev; rm -f /var/www/22222/htdocs"
"/vimbadmin/composer.phar") "/vimbadmin/composer.phar")
# Configure vimbadmin database # Configure vimbadmin database
vm_passwd = ''.join(random.sample(string.ascii_letters, 64)) vm_passwd = ''.join(random.sample(string.ascii_letters, 8))
vm_mysql = EEMysql()
vm_mysql.execute("create database \`vimbadmin\`") EEMysql.execute("create database if not exists vimbadmin")
vm_mysql.execute("grant all privileges on vimbadmin.* to" EEMysql.execute("grant all privileges on vimbadmin.* to"
" vimbadmin@localhost IDENTIFIED BY" " vimbadmin@localhost IDENTIFIED BY"
" {password}".format(password=vm_passwd)) " '{password}'".format(password=vm_passwd))
# Configure ViMbAdmin settings # Configure ViMbAdmin settings
config = configparser.ConfigParser() config = configparser.ConfigParser(strict=False)
config.read('/var/www/22222/htdocs/vimbadmin/application/' config.read('/var/www/22222/htdocs/vimbadmin/application/'
'configs/application.ini.dist') 'configs/application.ini.dist')
config['user']['defaults.mailbox.uid'] = 5000 config['user']['defaults.mailbox.uid'] = '5000'
config['user']['defaults.mailbox.gid'] = 5000 config['user']['defaults.mailbox.gid'] = '5000'
config['user']['defaults.mailbox.maildir'] = ("maildir:/var/" config['user']['defaults.mailbox.maildir'] = ("maildir:/var/v"
"vmail/%d/%u") + "mail/%%d/%%u")
config['user']['defaults.mailbox.homedir'] = "/srv/vmail/%d/%u" config['user']['defaults.mailbox.homedir'] = ("/srv/vmail/"
+ "%%d/%%u")
config['user']['resources.doctrine2.connection.' config['user']['resources.doctrine2.connection.'
'options.driver'] = 'mysqli' 'options.driver'] = 'mysqli'
config['user']['resources.doctrine2.connection.' config['user']['resources.doctrine2.connection.'
@ -365,20 +365,22 @@ class EEStackController(CementBaseController):
config['user']['resources.doctrine2.connection.' config['user']['resources.doctrine2.connection.'
'options.host'] = 'localhost' 'options.host'] = 'localhost'
config['user']['defaults.mailbox.password_scheme'] = 'md5' config['user']['defaults.mailbox.password_scheme'] = 'md5'
config['user']['securitysalt'] = ('' config['user']['securitysalt'] = (''.join(random.sample
.join(random (string.ascii_letters
.sample(string. + string.ascii_letters,
ascii_letters, 64)))
64)))
config['user']['resources.auth.' config['user']['resources.auth.'
'oss.rememberme.salt'] = (''.join(random.sample 'oss.rememberme.salt'] = (''.join(random.sample
(string.ascii_letters, (string.ascii_letters
+ string.
ascii_letters,
64))) 64)))
config['user']['defaults.mailbox.' config['user']['defaults.mailbox.'
'password_salt'] = (''.join(random.sample 'password_salt'] = (''.join(random.sample
(string.ascii_letters, (string.ascii_letters
+ string.ascii_letters,
64))) 64)))
with open('var/www/22222/htdocs/vimbadmin/application' with open('/var/www/22222/htdocs/vimbadmin/application'
'/configs/application.ini', 'w') as configfile: '/configs/application.ini', 'w') as configfile:
config.write(configfile) config.write(configfile)
@ -427,13 +429,16 @@ class EEStackController(CementBaseController):
if self.app.pargs.web: if self.app.pargs.web:
apt_packages = (apt_packages + EEVariables.ee_nginx + apt_packages = (apt_packages + EEVariables.ee_nginx +
EEVariables.ee_php + EEVariables.ee_mysql) EEVariables.ee_php + EEVariables.ee_mysql)
packages = [["https://github.com/opensolutions/ViMbAdmin/archive/"
"3.0.10.tar.gz", "/tmp/vimbadmin.tar.gz"]]
if self.app.pargs.admin: if self.app.pargs.admin:
pass pass
# apt_packages = apt_packages + EEVariables.ee_nginx # apt_packages = apt_packages + EEVariables.ee_nginx
if self.app.pargs.mail: if self.app.pargs.mail:
apt_packages = apt_packages + EEVariables.ee_mail apt_packages = apt_packages + EEVariables.ee_mail
packages = packages + [["https://github.com/opensolutions/ViMbAdmi"
"n/archive/3.0.10.tar.gz", "/tmp/vimbadmin"
".tar.gz"]]
if self.app.pargs.nginx: if self.app.pargs.nginx:
apt_packages = apt_packages + EEVariables.ee_nginx apt_packages = apt_packages + EEVariables.ee_nginx
if self.app.pargs.php: if self.app.pargs.php:

24
ee/core/mysql.py

@ -7,7 +7,7 @@ from os.path import expanduser
class EEMysql(): class EEMysql():
"""Method for MySQL connection""" """Method for MySQL connection"""
def __init__(self): def execute(statement):
config = configparser.RawConfigParser() config = configparser.RawConfigParser()
cnfpath = expanduser("~")+"/.my.cnf" cnfpath = expanduser("~")+"/.my.cnf"
if [cnfpath] == config.read(cnfpath): if [cnfpath] == config.read(cnfpath):
@ -24,22 +24,24 @@ class EEMysql():
port = '3306' port = '3306'
try: try:
self.conn = pymysql.connect(host=host, port=int(port), conn = pymysql.connect(host=host, port=int(port),
user=user, passwd=passwd) user=user, passwd=passwd)
self.cur = self.conn.cursor() cur = conn.cursor()
except Exception as e: except Exception as e:
print("Unable to connect to database") print("Unable to connect to database")
return False return False
def execute(self, statement):
try: try:
self.cur.execute(statement) cur.execute(statement)
return True
except Exception as e: except Exception as e:
print("Error occured while executing "+statement) print("Error occured while executing "+statement)
cur.close()
conn.close()
return False return False
def close(self): cur.close()
self.cur.close() conn.close()
self.conn.close()
# def __del__(self):
# self.cur.close()
# self.conn.close()

1
ee/core/shellexec.py

@ -16,6 +16,7 @@ class EEShellExec():
if retcode[0] == 0: if retcode[0] == 0:
return True return True
else: else:
print(retcode[1])
return False return False
except OSError as e: except OSError as e:
print(e) print(e)

Loading…
Cancel
Save