#!/usr/bin/env python3 from libsw import input_util, command_index def _help(): print('sw clamav offline-update # Temporarily stop ClamAV daemon and update definitions') print('sw clamav offline # Use offline-update in a cron job once a day instead of using the update damon to update clamav') print('sw clamav daemon # Use the update damon instead of a cron job to update clamav') index = command_index.CategoryIndex('clamav', _help) def _update(): from libsw import clamav, logger log = logger.Log() clamav.offline_update(log) index.register_command('offline-update', _update) index.register_command('offlineupdate', _update) def _offline(): from libsw import clamav, logger log = logger.Log() clamav.use_offline_update(log) index.register_command('offline', _offline) def _daemon(): from libsw import clamav, logger log = logger.Log() clamav.use_daemon_update(log) index.register_command('daemon', _daemon)
from libsw import command_index def _help(): print( 'sw ssh list [`example_username`] # List all enabled SSH keys with access to the system; however, if a user is given, disabled keys are shown as well' ) print('sw ssh import [example_username] # Import an SSH key') print('sw ssh disable [example_username [key]] # Disable an SSH key') print( 'sw ssh enable [example_username [key]] # Enable a disabled SSH key') print( 'sw ssh (delete|remove) [example_username [key]] # Remove an SSH key') index = command_index.CategoryIndex('ssh', _help) def _import(username): from libsw import ssh, user if not username or not user.exists(username): username = user.select_user(True) print( 'If you are using Unix or a Unix-like system such as Linux or OSX, you can copy this code into your local terminal to get your SSH key including the decorators you need for this command:' ) print( '''mkdir -p ~/.ssh; if [ ! -f ~/.ssh/id_rsa ]; then ssh-keygen -N "" -f ~/.ssh/id_rsa >/dev/null; fi; echo "Your full public key:"; cat ~/.ssh/id_rsa.pub''' ) print() key = input( 'Enter the full public key lines as it appears in id_rsa.pub (or similar): '
#!/usr/bin/env python3 from libsw import input_util, command_index def _help(): from libsw import bind print('sw dns list # List domains with a dedicated zone file') print('sw dns (add|create) [example.com] # Add a new domain to the DNS system, reindexes zones, and restart bind') print('sw dns edit [example.com] # Edit a DNS zone file and if modified, inrement the SOA and restart bind') print('sw dns reindex # Reindex dns zone files (Only needed after you modify zone files outside Site Wrangler)') print('sw dns soa [`example.com`] [`' + bind.get_todays_soa() + '`] # Updates the SOA for selected domain (for all domains if no domain is given)') print('sw dns checkexpire [`emailadmin`] # Check for soon to expire domains in the DNS system') print('sw dns disable [example.com] # Disable a zone record for a domain') print('sw dns enable [example.com] # Enable a disabled zone record for a domain') print('sw dns (delete|remove) [example.com] # Delete the zone record for a domain') index = command_index.CategoryIndex('dns', _help) def _soa(tertiary, more): from libsw import bind domain = False soa = False if tertiary != False: if input_util.is_domain(tertiary): domain = tertiary if more != False: soa = more[0] else: soa = tertiary if more != False: if input_util.is_domain(more[0]): domain = more[0]
) print( 'sw php change [example.com [7.3]] # Change the PHP version of a site, optionally specifying domain, and PHP version' ) print('sw php disable [example.com] # Disable a PHP vhost') print('sw php enable [example.com] # Enable a PHP vhost') print( 'sw php edit [example.com] # Edit a PHP vhost and restart the appropriate PHP version upon exit' ) print('sw php (delete|remove) [example.com] # Delete a PHP vhost') print( 'sw php status # Get the service status output for all enabled PHP versions' ) index = command_index.CategoryIndex('php', _help) def _add(domain, more): from libsw import php if not domain: domain = input_util.input_domain() sys_user = False php_version = False if more: sys_user = more[0] if len(more) > 1: php_version = more[1] else: php_version = php.select_version() else:
def _help(): print('sw email (list|listdomain[s]) # List domains registered in the email system and their associated system users') print('sw email listuser[s] # List all email accounts') print('sw email (add|create) [[email protected]] # Add an email account') print('sw email setpass[word] [[email protected]] # Change an email account password') print('sw email checkpass[word] [[email protected]] # Check an email account password') print('sw email setdomain [example.com [example_username]] # Associate a domain with a system account in the email system') print('sw email unsetdomain [example.com] # Remove a domain from the email system') print('sw email (delete|remove) [[email protected] [`dropfiles`]] # Delete an email account and optionally it\'s files') print('sw email dkim [example.com] # Generates a new dkim pair and installs them') print('sw email sastatus [[user@]example.com] # Check if SpamAssassin is enabled for a domain or email address') print('sw email enablesa [[user@]example.com] # Enable SpamAssassin for a domain or email address') print('sw email disablesa [[user@]example.com] # Disable SpamAssassin for a domain or email address') print('sw email status # Get the service status output for all mail-related services') index = command_index.CategoryIndex('email', _help) def _add(address): from libsw import email from getpass import getpass user = False domain = False if address != False: user, domain = address.split('@') if domain == False: domain = email.select_domain() if user == False: user = input('Enter email name without "@' + dom + '": ') email.create_account(user, domain) password = email.hash_password( getpass('Email Password: '******'@' + domain, password).run():
#!/usr/bin/env python3 from libsw import input_util, command_index def _help(): print('sw cert list # List all Let\'s Encrypt certificates indicating their expiration and if they are used in email') print('sw cert (add|create) [example.com [example_username] [`nomail`]] # Get an SSL certificate for a domain') print('sw cert deploylocal [example.com] # Deploy a copy of new certificaets into the user\'s "ssl" folder') print('sw cert nolocal [example.com [`dropfiles`]] # Stop deploying certificates into the users home directory and optinally delete the ones there') print('sw cert deployexim [example.com] # Copy SSL certificates from Let\'s Encrypt to exim') print('sw cert update # Run a check to make sure all certificates are up-to-date') print('sw cert (delete|remove) [example.com [`dropfiles`]] # Remove a domain from certificate updates and deployments and optionally the certificate files') index = command_index.CategoryIndex('cert', _help) def _add(domain, more): from libsw import cert, user, nginx, email sys_user = False nomail = False if domain == False: domain = input_util.input_domain() if more != False: if user.exists(more[0]): sys_user = more[0] if len(more) > 1 and more[1].lower() == 'nomail': nomail = True elif sys_user.lower() == 'nomail': sys_user = False nomail = True if sys_user == False: sys_user = nginx.user_from_domain(domain) if sys_user == False:
#!/usr/bin/env python3 from libsw import input_util, command_index def _help(): print('sw deploy update [force] # Install locally built packages on all production servers that do not use the same package version') print('sw deploy checkupdate # Check locally built packages against all production servers and list those that do not use the same package version') print('sw deploy (add|create) [ip_addr] # Register an IP address as a production server (be sure to authenticate SSH keys first)') print('sw deploy (delete|remove) [ip_addr] # Unregister an IP address as a production server') print('sw deploy list # List all servers set for remote package deployment') # print("sw deploy run [example] # Install one locally built (and it's dependencies) package on all production servers that do not use the same package version") index = command_index.CategoryIndex('deploy', _help) def _update(force): if force: force = force.lower() if force != 'force': force = False from libsw import deploy deploy.deploy(force) index.register_command('update', _update) index.register_command('upgrade', _update) # for yum/dnf habits :) def _checkupdate(): from libsw import deploy deploy.check_deploy() index.register_command('checkupdate', _checkupdate) index.register_command('check-update', _checkupdate) # for apt habits :) # def _run(first, more): # from libsw import build_queue, build_index
#!/usr/bin/env python3 from libsw import input_util, command_index def _help(): print('sw user list # List system users along with domains associated with them') print('sw user (add|create) [example_username] # Create a system user') print('sw user (delete|remove) [example_username [`dropfiles`]] # Delete a system user and optionally it\'s files') index = command_index.CategoryIndex('user', _help) def _add(sys_user): from libsw import user if sys_user: if user.exists(sys_user): print('Error. ' + sys_user + ' already exists.') return else: sys_user = user.select_new_username() user.make_user(sys_user) index.register_command('add', _add) index.register_command('create', _add) def _remove(sys_user, more): from libsw import user deletefiles = False if more != False and more[0].lower() == 'dropfiles': deletefiles = True if sys_user == False: sys_user = user.select_user() user.remove_user(sys_user, deletefiles) #TODO remove mail domain associations for user
print( 'sw build run [example] # Rebuild a given (list of) software slug(s) and other software that depends on it' ) print( 'sw build log [example] # Show the build log for the given software slug' ) print( 'sw build freeze [slug] # Prevent a software package from updating to a newer version' ) print( 'sw build (unfreeze|thaw) [slug] # Allow a software package to update to a newer version' ) print('sw build list(freeze|frozen) # List software set to not update') index = command_index.CategoryIndex('build', _help) def _update(force): if force: force = force.lower() if force != 'force': force = False from libsw import build_queue, build_index queue = build_queue.new_queue(force) build_index.populate_enabled(queue) build_index.populate_dependant_builders(queue) if queue.failed(): print("One or more builds failed.") elif queue.run() == 0: print("All software is already up-to-date.")
#!/usr/bin/env python3 from libsw import input_util, command_index def _help(): print('sw firewall writepignore # Update the ignored processes in the firewall and reload the firewall rules') print('sw firewall denyreport # Print a report on which IP blocks have the most denied IPs') index = command_index.CategoryIndex('firewall', _help) def _writepignore(force): from libsw import firewall firewall.writepignore() firewall.reload() index.register_command('writepignore', _writepignore) def _print_deny_report(): from libsw import firewall print(firewall.get_printed_ip_report()) index.register_command('deny-report', _print_deny_report) index.register_command('denyreport', _print_deny_report)
print( 'sw nginx edit [example.com] # Edit an nginx vhost and reload the nginx configuration upon exit' ) print('sw nginx (delete|remove) [example.com] # Delete an nginx vhost') print( 'sw nginx bypass[modsec] [example.com [0000]] # Bypass a ModSecurity rule id' ) print( 'sw nginx unbypass[modsec] [example.com [0000]] # Remove a bypass for a ModSecurity rule id' ) print( 'sw nginx listbypass[modsec] [example.com] # List the rules bypassed for a given domain' ) index = command_index.CategoryIndex('nginx', _help) def _enable(domain): from libsw import nginx if domain == False: domain = nginx.select_disabled_conf('Select domain to enable') if nginx.enable_vhost(domain): print(domain + ' enabled') else: print('Unable to find disabled vhost file for ' + domain) index.register_command('enable', _enable)