Browse Source

Done changes in stack_services.py and secure.py

bugfixes
shital.rtcamp 10 years ago
parent
commit
12967f5793
  1. 97
      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

97
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)])
username = input("Provide HTTP authentication user " if not self.app.pargs.user_input:
"name [{0}] :".format(EEVariables.ee_user)) username = input("Provide HTTP authentication user "
password = input("Provide HTTP authentication " "name [{0}] :".format(EEVariables.ee_user))
"password [{0}]".format(passwd)) self.app.pargs.user_input = username
if username == "": if username == "":
username = EEVariables.ee_user self.app.pargs.user_input = EEVariables.ee_user
Log.info(self, "HTTP authentication username:{username}" if not self.app.pargs.user_pass:
.format(username=username)) password = input("Provide HTTP authentication "
if password == "": "password [{0}]".format(passwd))
password = passwd self.app.pargs.user_pass = password
Log.info(self, "HTTP authentication password:{password}" if password == "":
.format(password=password)) self.app.pargs.user_pass = passwd
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):
port = input("EasyEngine admin port [22222]:") while not self.app.pargs.user_input.isdigit():
if port == "": Log.info(self, "Please Enter valid port number ")
port = 22222 self.app.pargs.user_input = input("EasyEngine admin port [22222]:")
if not self.app.pargs.user_input:
port = input("EasyEngine admin port [22222]:")
if port == "":
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 = []
ip = input("Enter the comma separated IP addresses " if not self.app.pargs.user_input:
"to white list [127.0.0.1]:") ip = input("Enter the comma separated IP addresses "
"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 " /etc/nginx/common/acl.conf"
if len(newlist) != 0: .format(whitelist_adre=ip_addr))
EEShellExec.cmd_exec(self, "sed -i \"/allow.*/d\" /etc/nginx" Log.info(self, "Successfully added IP address in acl.conf file")
"/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"
.format(whitelist_adre=whitelist_adre))
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