def start(): base = misc.onyx_base path = base + 'etc/cfg/services/' if not os.path.exists(path): os.makedirs(path) # Setup NGINX if len(step()) < 1: print(' Setting up Nginx HTTP Server') if not os.path.exists(path + '_backups/nginx.conf'): misc.copy_to('/etc/nginx/nginx.conf', path + '_backups/nginx.conf') misc.copy_to(path + 'nginx/', '/etc/nginx/') misc.cmd(['systemctl', 'enable', 'nginx']) misc.cmd(['systemctl', 'start', 'nginx']) step_save(step()) # Setup PHP if len(step()) < 2: print(' Setting up PHP') if not os.path.exists(path + '_backups/php.ini'): misc.copy_to('/etc/php/php.ini', path + '_backups/php.ini') misc.copy_to('/etc/php/php-fpm.d', path + '_backups/php-fpm.d') misc.copy_to(path + 'php/', '/etc/php/') misc.cmd(['systemctl', 'enable', 'php-fpm']) misc.cmd(['systemctl', 'start', 'php-fpm']) step_save(step()) # Setup PHP-MY-ADMIN if len(step()) < 3: print(' Setting up phpMyAdmin') if not os.path.exists(base + 'etc/web/api/phpmyadmin'): os.symlink('/usr/share/webapps/phpMyAdmin', base + 'etc/web/api/phpmyadmin') step_save(step())
def rmv(username): if username is True: username = misc.question(" What's the name of the user?") else: username = username[0] code = misc.cmd(["userdel", "-fr", username]) if code == 0: misc.cmd(["gpasswd", "-d", "http", username]) exit(" Successfully removed user: "******" User %s doesn't exist." % username) elif code == 12: exit(" Couldn't remove user's home directory.") else: exit(" --userdel returned error code: " + str(code))
def add(cmd): if misc.arg_range(cmd): exit(' Error! Usage: onyx-api --webadd user domain') user = cmd[0] domain = cmd[1] if misc.user_chk(user): base = '/home/' + user + '/web/' + domain # Create domain dirs if missing if not os.path.exists(base): os.makedirs(base + '/logs/') misc.copy_to('/opt/onyx/etc/web/usr/public_html/', base + '/public_html/') misc.copy_to('/opt/onyx/etc/web/usr/nginx/', base + '/nginx/') # Update user nginx template with correct values for line in fileinput.input([base + '/nginx/default.conf', base + '/nginx/default_s.conf'], inplace=True): line = line.replace('%web_port%', '80') line = line.replace('%web_ssl_port%', '443') line = line.replace('%proxy_port%', '8080') line = line.replace('%proxy_ssl_port%', '8443') line = line.replace('%user%', user) line = line.replace('%domain_idn%', domain) line = line.replace('%alias_idn%', 'www.' + domain) line = line.replace('%docroot%', base + '/public_html/') line = line.replace('%sdocroot%', base + '/public_html/') sys.stdout.write(line) # Update user html template with correct values for line in fileinput.input([base + '/public_html/50x.html', base + '/public_html/403.html', base + '/public_html/404.html', base + '/public_html/index.html'], inplace=True): line = line.replace('%domain%', domain) sys.stdout.write(line) # Set user as owner of dirs and files misc.cmd(['chown', '-R', user + ':' + user, '/home/' + user]) exit(' %s was added successfully.' % domain) else: exit(' %s already exists.' % domain)
def add(username=misc.user_gen(), password=misc.pass_gen()): i = 1 code = 9 while code == 9: code = misc.cmd(["useradd", username, "-p", password, "-s", "/sbin/nologin", "-md", "/home/" + username]) if code == 0: misc.cmd(["chown", "750", "-Rf", "/home/" + username]) misc.cmd(["gpasswd", "-a", "http", username]) exit(" Successfully added user: %s with password: %s" % (username, password)) elif code == 9: if i >= 100: exit(" --useradd has timed-out after 100 attempts to generate a username.") i += 1 elif code == 12: exit(" Couldn't create user's home directory.") else: exit(" --useradd returned error code: " + str(code))
def ctl(cmd): swt_list = ['start', 'stop', 'restart'] srv_list = ['mariadb', 'nginx', 'php-fpm', 'vsftpd'] switch = cmd[0] services = [cmd[1]] if len(cmd) >= 2 else srv_list if cmd[0] not in swt_list or cmd[1] not in srv_list: exit(str(' Usage: onyx-api --services %s %s' % (swt_list, srv_list)).replace("'", '')) for service in services: code = misc.cmd(['systemctl', switch, service]) if code == 0: print(' %s [%s] ' % (service, switch)) else: print(' %s didn\'t %s properly. For details run: systemctl status %s' % (service, switch, service))