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 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)