Browse Source

Done changes in stack_services.py and secure.py

bugfixes
shital.rtcamp 10 years ago
parent
commit
12967f5793
  1. 75
      ee/cli/plugins/secure.py
  2. 2
      ee/cli/plugins/stack_services.py
  3. 16
      tests/cli/94_test_site_edit.py
  4. 6
      tests/cli/test_site_delete.py

75
ee/cli/plugins/secure.py

@ -27,8 +27,11 @@ class EESecureController(CementBaseController):
(['--port'], (['--port'],
dict(help='secure port', action='store_true')), dict(help='secure port', action='store_true')),
(['--ip'], (['--ip'],
dict(help='secure ip', action='store_true')) dict(help='secure ip', action='store_true')),
] (['user_input'],
dict(help='user input', nargs='?', default=None)),
(['user_pass'],
dict(help='user pass', nargs='?', default=None))]
@expose(hide=True) @expose(hide=True)
def default(self): def default(self):
@ -44,65 +47,77 @@ class EESecureController(CementBaseController):
passwd = ''.join([random.choice passwd = ''.join([random.choice
(string.ascii_letters + string.digits) (string.ascii_letters + string.digits)
for n in range(6)]) for n in range(6)])
if not self.app.pargs.user_input:
username = input("Provide HTTP authentication user " username = input("Provide HTTP authentication user "
"name [{0}] :".format(EEVariables.ee_user)) "name [{0}] :".format(EEVariables.ee_user))
self.app.pargs.user_input = username
if username == "":
self.app.pargs.user_input = EEVariables.ee_user
if not self.app.pargs.user_pass:
password = input("Provide HTTP authentication " password = input("Provide HTTP authentication "
"password [{0}]".format(passwd)) "password [{0}]".format(passwd))
if username == "": self.app.pargs.user_pass = password
username = EEVariables.ee_user
Log.info(self, "HTTP authentication username:{username}"
.format(username=username))
if password == "": if password == "":
password = passwd self.app.pargs.user_pass = passwd
Log.info(self, "HTTP authentication password:{password}"
.format(password=password))
EEShellExec.cmd_exec(self, "printf \"{username}:" EEShellExec.cmd_exec(self, "printf \"{username}:"
"$(openssl passwd -crypt " "$(openssl passwd -crypt "
"{password} 2> /dev/null)\n\"" "{password} 2> /dev/null)\n\""
"> /etc/nginx/htpasswd-ee 2>/dev/null" "> /etc/nginx/htpasswd-ee 2>/dev/null"
.format(username=username, .format(username=self.app.pargs.user_input,
password=password)) password=self.app.pargs.user_pass))
Log.info(self, "Successfully changed HTTP authentication"
" username:{username}"
.format(username=self.app.pargs.user_input))
Log.info(self, "Successfully changed HTTP authentication"
" password:{password}"
.format(password=self.app.pargs.user_pass))
@expose(hide=True) @expose(hide=True)
def secure_port(self): def secure_port(self):
while not self.app.pargs.user_input.isdigit():
Log.info(self, "Please Enter valid port number ")
self.app.pargs.user_input = input("EasyEngine admin port [22222]:")
if not self.app.pargs.user_input:
port = input("EasyEngine admin port [22222]:") port = input("EasyEngine admin port [22222]:")
if port == "": if port == "":
port = 22222 self.app.pargs.user_input = 22222
while not port.isdigit() and port != "":
Log.info(self, "Please Enter valid port number :")
port = input("EasyEngine admin port [22222]:")
self.app.pargs.user_input = port
if EEVariables.ee_platform_distro == 'Ubuntu': if EEVariables.ee_platform_distro == 'Ubuntu':
EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen " EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen "
"{port} default_server ssl spdy;/\" " "{port} default_server ssl spdy;/\" "
"/etc/nginx/sites-available/22222.conf" "/etc/nginx/sites-available/22222.conf"
.format(port=port)) .format(port=self.app.pargs.user_input))
if EEVariables.ee_platform_distro == 'Debian': if EEVariables.ee_platform_distro == 'Debian':
EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen " EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen "
"{port} default_server ssl;/\" " "{port} default_server ssl;/\" "
"/etc/nginx/sites-available/22222" "/etc/nginx/sites-available/22222.conf"
.format(port=port)) .format(port=self.app.pargs.user_input))
Log.info(self, "Successfully port changed {port}"
.format(port=self.app.pargs.user_input))
@expose(hide=True) @expose(hide=True)
def secure_ip(self): def secure_ip(self):
# TODO:remaining with ee.conf updation in file # TODO:remaining with ee.conf updation in file
newlist = [] newlist = []
if not self.app.pargs.user_input:
ip = input("Enter the comma separated IP addresses " ip = input("Enter the comma separated IP addresses "
"to white list [127.0.0.1]:") "to white list [127.0.0.1]:")
self.app.pargs.user_input = ip
try: try:
user_list_ip = ip.split(',') user_ip = self.app.pargs.user_input.split(',')
except Exception as e: except Exception as e:
ip = ['127.0.0.1'] user_ip = ['127.0.0.1']
self.app.config.set('mysql', 'grant-host', "hello") for ip_addr in user_ip:
exist_ip_list = self.app.config.get('stack', 'ip-address').split() if not ("exist_ip_address "+ip_addr in open('/etc/nginx/common/'
for check_ip in user_list_ip: 'acl.conf').read()):
if check_ip not in exist_ip_list: EEShellExec.cmd_exec(self, "sed -i "
newlist.extend(exist_ip_list) "\"/deny/i allow {whitelist_adre}\;\""
# changes in acl.conf file
if len(newlist) != 0:
EEShellExec.cmd_exec(self, "sed -i \"/allow.*/d\" /etc/nginx"
"/common/acl.conf")
for whitelist_adre in newlist:
EEShellExec.cmd_exec(self, "sed -i \"/deny/i "
"echo allow {whitelist_adre}\\;\" "
" /etc/nginx/common/acl.conf" " /etc/nginx/common/acl.conf"
.format(whitelist_adre=whitelist_adre)) .format(whitelist_adre=ip_addr))
Log.info(self, "Successfully added IP address in acl.conf file")
def load(app): def load(app):

2
ee/cli/plugins/stack_services.py

@ -12,7 +12,7 @@ class EEStackStatusController(CementBaseController):
description = 'Get status of stack' description = 'Get status of stack'
arguments = [ arguments = [
(['--memcache'], (['--memcache'],
dict(help='start/stop/restart stack', action='store_true')), dict(help='start/stop/restart memcache', action='store_true')),
(['--dovecot'], (['--dovecot'],
dict(help='start/stop/restart dovecot', action='store_true')), dict(help='start/stop/restart dovecot', action='store_true')),
] ]

16
tests/cli/94_test_site_edit.py

@ -1,16 +0,0 @@
from ee.utils import test
from ee.cli.main import get_test_app
class CliTestCaseSite(test.EETestCase):
def test_ee_cli(self):
self.app.setup()
self.app.run()
self.app.close()
def test_ee_cli_site_edit(self):
self.app = get_test_app(argv=['site', 'edit', 'example1.com'])
self.app.setup()
self.app.run()
self.app.close()

6
tests/cli/test_site_delete.py

@ -18,21 +18,21 @@ class CliTestCaseSite(test.EETestCase):
def test_ee_cli_site_detele_all(self): def test_ee_cli_site_detele_all(self):
self.app = get_test_app(argv=['site', 'delete', 'example2.com', self.app = get_test_app(argv=['site', 'delete', 'example2.com',
'--all']) '--all', '--no-prompt'])
self.app.setup() self.app.setup()
self.app.run() self.app.run()
self.app.close() self.app.close()
def test_ee_cli_site_detele_db(self): def test_ee_cli_site_detele_db(self):
self.app = get_test_app(argv=['site', 'delete', 'example3.com', self.app = get_test_app(argv=['site', 'delete', 'example3.com',
'--db']) '--db', '--no-prompt'])
self.app.setup() self.app.setup()
self.app.run() self.app.run()
self.app.close() self.app.close()
def test_ee_cli_site_detele_files(self): def test_ee_cli_site_detele_files(self):
self.app = get_test_app(argv=['site', 'delete', 'example4.com', self.app = get_test_app(argv=['site', 'delete', 'example4.com',
'--files']) '--files', '--no-prompt'])
self.app.setup() self.app.setup()
self.app.run() self.app.run()
self.app.close() self.app.close()

Loading…
Cancel
Save