['help', 'pass='******'email=']) except getopt.GetoptError, e: usage(e) email = "" password = "" for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt == '--pass': password = val elif opt == '--email': email = val if not password: d = Dialog('TurnKey Linux - First boot configuration') password = d.get_password( "GNU social Password", "Enter new password for the GNU Social 'administrator' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "GNU social Email", "Please enter email address for the GNU Social 'administrator' account.", "*****@*****.**") inithooks_cache.write('APP_EMAIL', email)
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], 'h', ['help', 'gameserver-repo=', 'gameserver-branch=']) except getopt.GetoptError as e: usage(e) default_gameserver_repo = 'https://github.com/jesinmat/linux-gameservers.git' default_gameserver_branch = 'master' gameserver_repo = "" gameserver_branch = "" for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt == '--gameserver-repo': gameserver_repo = val elif opt == '--gameserver-branch': gameserver_branch = val dialog = Dialog('TurnKey Linux - First boot configuration') if not gameserver_repo or not gameserver_branch: choose_gameserver_upstream = dialog.yesno( 'TKL Gameserver', 'Do you want to choose a custom repo?') if choose_gameserver_upstream: if not gameserver_repo: ok, gameserver_repo = dialog.inputbox( 'TKL Gameserver', 'Choose gameserver repo url', default_gameserver_repo) if not ok: gameserver_repo = default_gameserver_repo if not gameserver_branch: ok, gameserver_branch = dialog.inputbox( 'TKL Gameserver', 'Choose gameserver branch', default_gameserver_branch) if not ok: gameserver_branch = default_gameserver_branch else: gameserver_repo = default_gameserver_repo gameserver_branch = default_gameserver_branch needs_pull = False old_dir = os.getcwd() if gameserver_repo != default_gameserver_repo: os.chdir('/root/gameservers') subprocess.run([ 'git', 'remote', 'set-url', 'origin', gameserver_repo ]) needs_pull = True if gameserver_branch != default_gameserver_branch: os.chdir('/root/gameservers') subprocess.run([ 'git', 'fetch' ]) subprocess.run([ 'git', 'checkout', '--track', f'origin/{gameserver_branch}', ]) needs_pull = True if needs_pull: os.chdir('/root/gameservers') subprocess.run([ 'git', 'pull' ]) os.chdir(old_dir)
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", [ 'help', 'profile=', 'key-email=', 'public-address=', 'virtual-subnet=', 'private-subnet=' ]) except getopt.GetoptError as e: usage(e) profile = "" key_email = "" public_address = "" virtual_subnet = "" private_subnet = "" redirect_client_gateway = "" for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt == '--profile': profile = val elif opt == '--key-email': key_email = val elif opt == '--public-address': public_address = val elif opt == '--virtual-subnet': virtual_subnet = val elif opt == '--private-subnet': private_subnet = val dialog = Dialog('TurnKey Linux - First boot configuration') if not profile: profile = dialog.menu( "OpenVPN Profile", "Choose a profile for this server.\n\n* Gateway: clients will be configured to route all\n their traffic through the VPN.", [('server', 'Accept VPN connections from clients'), ('gateway', 'Accept VPN connections from clients*'), ('client', 'Initiate VPN connections to a server')]) if not profile in ('server', 'gateway', 'client'): fatal('invalid profile: %s' % profile) if profile == "client": return if not key_email: key_email = dialog.get_email( "OpenVPN Email", "Enter email address for the OpenVPN server key.", "*****@*****.**") inithooks_cache.write('APP_EMAIL', key_email) if not public_address: public_address = dialog.get_input( "OpenVPN Public Address", "Enter FQDN or IP address of server reachable by clients", "vpn.example.com") auto_virtual_subnet = "10.%d.%d.0/24" % (r(2, 254), r(2, 254)) if not virtual_subnet: virtual_subnet = dialog.get_input( "OpenVPN Virtual Subnet", "Enter CIDR subnet address pool to allocate to clients. This server will be configured with x.x.x.1. The CIDR must not be in-use on your network.", auto_virtual_subnet) if virtual_subnet.upper() == "AUTO": virtual_subnet = auto_virtual_subnet if profile == "server": if not private_subnet: retcode, private_subnet = dialog.inputbox( "OpenVPN Private Subnet", "Enter CIDR subnet behind server for clients to reach.", "10.0.1.0/24", "Apply", "Skip") if private_subnet.upper() == "SKIP": private_subnet = "" cmd = os.path.join(os.path.dirname(__file__), 'openvpn-server-init.sh') subprocess.run([cmd, key_email, public_address, virtual_subnet]) if profile == "gateway": fh = open("/etc/openvpn/server.conf", "a") fh.write( "# configure clients to route all their traffic through the vpn\n") fh.write("push \"redirect-gateway def1 bypass-dhcp\"\n\n") fh.close() if private_subnet: fh = open("/etc/openvpn/server.conf", "a") fh.write( "# push routes to clients to allow them to reach private subnets\n" ) for _private_subnet in private_subnet.split(','): fh.write("push \"route %s\"\n" % expand_cidr(_private_subnet)) fh.close() subprocess.run(['systemctl', 'start', 'openvpn@server'])
email = "" email_placeholder = "" for opt, val in opts: if opt in ("-h", "--help"): usage() elif opt == "--email": email = val elif opt == "--email-placeholder": email_placeholder = val if email and not email_re.match(email): fatal("email is not valid") if not email: d = Dialog("TurnKey Linux - First boot configuration") email = email_placeholder while 1: retcode, email = d.inputbox( TITLE, TEXT, email, "Enable", "Skip") if retcode == 1: email = "" break if not email_re.match(email): d.error('Email is not valid')
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'email=', 'domain=']) except getopt.GetoptError as e: usage(e) password = "" email = "" domain = "" for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt == '--pass': password = val elif opt == '--email': email = val elif opt == '--domain': domain = val if not password: d = Dialog('TurnKey Linux - First boot configuration') password = d.get_password( "Drupal8 Password", "Enter new password for the Drupal8 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "Drupal8 Email", "Enter email address for the Drupal8 'admin' account.", "*****@*****.**") inithooks_cache.write('APP_EMAIL', email) if not domain: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') domain = d.get_input("Drupal8 Domain", "Enter the domain to serve Drupal8.", DEFAULT_DOMAIN) if domain == "DEFAULT": domain = DEFAULT_DOMAIN inithooks_cache.write('APP_DOMAIN', domain) print("Progress...") m = MySQL() m.execute( 'UPDATE drupal8.users_field_data SET mail=%s WHERE name=\"admin\";', (email, )) m.execute( 'UPDATE drupal8.users_field_data SET init=%s WHERE name=\"admin\";', (email, )) domain = domain.replace('.', '\\\\\.') subprocess.run([ '/usr/lib/inithooks/bin/drupalconf.sh', '-e', email, '-p', password, '-d', domain ])
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'email=', 'domain=']) except getopt.GetoptError as e: usage(e) password = "" email = "" domain = "" for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt == '--pass': password = val elif opt == '--email': email = val elif opt == '--domain': domain = val if not password: d = Dialog('TurnKey Linux - First boot configuration') password = d.get_password( "Mattermost Admin Password", "Enter new password for Mattermost 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "Mattermost Administrator's Email", "Enter email address for Mattermost 'admin' account.", "*****@*****.**") inithooks_cache.write('APP_EMAIL', email) if not domain: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') domain = d.get_input("Mattermost domain", "Enter domain to serve Mattermost", DEFAULT_DOMAIN) if domain == "DEFAULT": domain = DEFAULT_DOMAIN inithooks_cache.write('APP_DOMAIN', domain) if not domain.startswith('https://') and not domain.startswith('http://'): domain = 'https://' + domain subprocess.run([ 'sed', '-i', "/SiteURL/ s|\":.*|\": \\\"%s\\\",|" % domain, '/opt/mattermost/config/config.json' ]) salt = bcrypt.gensalt() hashpass = bcrypt.hashpw(password.encode('utf8'), salt).decode('utf8') p = PostgreSQL(database='mattermost') p.execute( ("UPDATE users SET password='******', email='%s' WHERE username='******';" % (hashpass, email)).encode('utf8'))
print >> sys.stderr, "Error:", s print >> sys.stderr, "Syntax: %s [options]" % sys.argv[0] print >> sys.stderr, __doc__ sys.exit(1) def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help']) except getopt.GetoptError, e: usage(e) for opt, val in opts: if opt in ('-h', '--help'): usage() d = Dialog("Insta-Snorby - First boot configuration") install = d.yesno("Security updates", TEXT, "Install", "Skip") if not install: sys.exit(1) try: getoutput("host -W 2 archive.turnkeylinux.org") except ExecError, e: d.error(CONNECTIVITY_ERROR) sys.exit(1) if __name__ == "__main__": main()
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'domain=']) except getopt.GetoptError as e: usage(e) domain = '' password = "" for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt == '--pass': password = val elif opt == '--domain': domain = val if not password: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') password = d.get_password( "EspoCRM password", "Enter new password for the EspoCRM 'admin' account.") if not domain: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') domain = d.get_input("EspoCRM Domain", "Enter the domain to serve EspoCRM.", DEFAULT_DOMAIN) if domain == "DEFAULT": domain = DEFAULT_DOMAIN inithooks_cache.write('APP_DOMAIN', domain) conf = "/var/www/espocrm/data/config.php" lines = [] with open(conf, 'r') as fob: for line in fob: match = re.search("'passwordSalt' => '([^']*)',", line) if match != None: normSalt = ('$6$%s$' % match.group(1)) hashed = crypt.crypt( hashlib.md5(password.encode('utf8')).hexdigest(), normSalt).replace(normSalt, '') m = MySQL() m.execute( 'UPDATE espocrm.user SET password=%s WHERE user_name=\"admin\"', (hashed)) if 'siteUrl' in line: line = re.sub("=> '([^']*)'", f"=> 'https://{domain}'", line) lines.append(line) with open(conf, 'w') as fob: fob.writelines(lines)
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'email=', 'domain=']) except getopt.GetoptError as e: usage(e) password = "" email = "" domain = "" for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt == '--pass': password = val elif opt == '--email': email = val elif opt == '--domain': domain = val if not password: d = Dialog('TurnKey Linux - First boot configuration') password = d.get_password( "OpenCart Password", "Enter new password for the OpenCart 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "OpenCart Email", "Enter email address for the OpenCart 'admin' account.", "*****@*****.**") inithooks_cache.write('APP_EMAIL', email) if not domain: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') domain = d.get_input( "OpenCart domain", "Enter domain to serve OpenCart", DEFAULT_DOMAIN) if domain == "DEFAULT": domain = DEFAULT_DOMAIN inithooks_cache.write('APP_DOMAIN', domain) def php_uniqid(prefix=''): return prefix + hex(int(time.time()))[2:10] + hex(int(time.time() * 1000000) % 0x100000)[2:7] subprocess.run(["sed", "-ri", "s|('HTTP(S?)_SERVER',) '.*'|\\1 'http\\L\\2://%s/'|g" % domain, "/var/www/opencart/config.php"]) subprocess.run(["sed", "-ri", "s|('HTTP(S?)_SERVER',) '.*'|\\1 'http\\L\\2://%s/admin/'|g" % domain, "/var/www/opencart/admin/config.php"]) subprocess.run(["sed", "-ri", "s|('HTTP(S?)_CATALOG',) '.*'|\\1 'http\\L\\2://%s/'|g" % domain, "/var/www/opencart/admin/config.php"]) salt = hashlib.md5(php_uniqid(str(randint(100000000, 999999999))).encode('utf8')).hexdigest()[:9] apache_conf = "/etc/apache2/sites-available/opencart.conf" subprocess.run(["sed", "-i", "\|RewriteRule|s|https://.*|https://%s/\$1 [R,L]|" % domain, apache_conf]) subprocess.run(["sed", "-i", "\|RewriteCond|s|!^.*|!^%s$|" % domain, apache_conf]) subprocess.run(["service", "apache2", "restart"]) password_hash = hashlib.sha1(password.encode('utf8')).hexdigest() password_hash = hashlib.sha1((salt + password_hash).encode('utf8')).hexdigest() password_hash = hashlib.sha1((salt + password_hash).encode('utf8')).hexdigest() m = MySQL() m.execute('UPDATE opencart.oc_user SET email=%s WHERE username="******"', (email,)) m.execute('UPDATE opencart.oc_user SET password=%s WHERE username="******"', (password_hash,)) m.execute('UPDATE opencart.oc_user SET salt=%s WHERE username="******"', (salt,))
def main(): signal.signal(signal.SIGINT, signal.SIG_IGN) try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'apikey=', 'fqdn=']) except getopt.GetoptError as e: usage(e) apikey = "" fqdn = "" for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt == '--apikey': apikey = val elif opt == '--fqdn': fqdn = val if apikey: system('tklbam-init', apikey) if fqdn: system('hubdns-init', apikey, fqdn) system('hubdns-update') return initialized_tklbam = False d = Dialog('TurnKey GNU/Linux - First boot configuration') while 1: retcode, apikey = d.inputbox("Initialize Hub services", TEXT_SERVICES, apikey, "Apply", "Skip") if not apikey or retcode == 1: break d.infobox("Linking TKLBAM to the TurnKey Hub...") try: check_output(["host", "-W", "2", "hub.turnkeylinux.org"]) except CalledProcessError as e: d.error(CONNECTIVITY_ERROR) break try: check_output(['tklbam-init', apikey]) d.msgbox('Success! Linked TKLBAM to Hub', SUCCESS_TKLBAM) initialized_tklbam = True break except CalledProcessError as e: d.msgbox('Failure', e.output) continue if initialized_tklbam: while 1: retcode, fqdn = d.inputbox("Assign TurnKey DNS hostname", TEXT_HUBDNS, fqdn, "Apply", "Skip") if not fqdn or retcode == 1: break d.infobox("Linking HubDNS to the TurnKey Hub...") try: check_output(['hubdns-init', apikey, fqdn]) check_output(['hubdns-update']) d.msgbox('Success! Assigned %s' % fqdn, SUCCESS_HUBDNS) break except CalledProcessError as e: d.msgbox('Failure', e.output) continue
For maximum protection, we recommend rebooting now. """ def usage(s=None): if s: print >> sys.stderr, "Error:", s print >> sys.stderr, "Syntax: %s [options]" % sys.argv[0] print >> sys.stderr, __doc__ sys.exit(1) def main(): signal.signal(signal.SIGINT, signal.SIG_IGN) try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help']) except getopt.GetoptError, e: usage(e) for opt, val in opts: if opt in ('-h', '--help'): usage() d = Dialog("TurnKey GNU/Linux - Reboot after kernel update") reboot = d.yesno("Reboot now?", TEXT, "Reboot", "Skip") if not reboot: sys.exit(1) if __name__ == "__main__": main()
def main(): DEFAULT_REALM = "DOMAIN.LAN" DEFAULT_DOMAIN = "DOMAIN" DEFAULT_NS = "" try: opts, args = getopt.gnu_getopt( sys.argv[1:], "h", ['help', 'pass='******'domain=', 'realm=', 'join_ns=']) except getopt.GetoptError as e: usage(e) interactive = False domain = "" realm = "" admin_password = "" join_nameserver = "" for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt == '--pass': admin_password = val elif opt == '--realm': realm = val elif opt == '--domain': domain = val elif opt == '--join_ns': join_nameserver = val DEFAULT_NS = join_nameserver if ((not (realm and domain and admin_password)) or (join_nameserver and not valid_ip(join_nameserver)) or TURNKEY_INIT): interactive = True if join_nameserver: create = True elif realm and domain and admin_password and join_nameserver: join_nameserver = valid_ip(join_nameserver) create = False elif realm and domain and admin_password and not join_nameserver: create = True while True: if TURNKEY_INIT: d = Dialog('Turnkey Linux - First boot configuration') do_it = d.yesno( "Reconfigure Samba?", "Existing Samba config will be removed.\n\n" "Cancelling will leave existing config in place.\n" "\nContinue?", "Reconfigure", "Cancel") if not do_it: sys.exit(0) if interactive and not join_nameserver: d = Dialog('Turnkey Linux - First boot configuration') create = d.yesno( "Create new AD or join existing?", "You can create new Active Directory or join existing one.", "Create", "Join") if create: create = True if not realm: while True: d = Dialog('Turnkey Linux - First boot configuration') realm = d.get_input( "Samba Kerberos Realm / AD DNS zone", "Kerberos Realm should be 2 or more groups of 63 or less" " ASCII characters, separated by dot(s). Kerberos realm" " will be stored as uppercase; DNS zone as" " lowercase\n\n" "Enter the Realm / DNS zone you would like to use.", DEFAULT_REALM) realm = validate_realm(realm, interactive) if realm[0]: break else: d.error(realm[1]) continue else: realm = validate_realm(realm, interactive) if not domain: while True: d = Dialog('TurnKey Linux - First boot configuration') domain = d.get_input( "Samba NetBIOS Domain (aka workgroup)", "The NetBIOS domain (aka workgroup) should be 15 or less" " ASCII characters.\n\n" "Enter NetBIOS domain (aka 'WORKGROUP') to use.", DEFAULT_DOMAIN) domain = validate_netbios(domain, interactive) if domain[0]: break else: d.error(domain[1]) continue else: domain = validate_netbios(domain, interactive) if not admin_password: d = Dialog('TurnKey Linux - First boot configuration') admin_password = d.get_password( "Samba Password", "Enter password for the samba 'Administrator' account.", pass_req=8, min_complexity=3, blacklist=['(', ')']) if interactive and not create: d = Dialog('Turnkey Linux - First boot configuration') while True: join_nameserver = d.get_input( "Add nameserver", "Set DNS server IPv4 for existing AD domain DNS server", DEFAULT_NS) if not valid_ip(join_nameserver): d.error("IP: '{}' is not valid.".format(join_nameserver)) join_nameserver = "" continue else: break # Stop any Samba services services = ['samba', 'samba-ad-dc', 'smbd', 'nmbd'] for service in services: subprocess.run(['systemctl', 'stop', service], stderr=PIPE) # Remove Samba & Kerberos conf rm_f('/etc/samba/smb.conf') rm_f('/etc/krb5.conf') # Remove Samba DBs dirs = [ '/var/run/samba', '/var/lib/samba', '/var/cache/samba', '/var/lib/samba/private' ] for _dir in dirs: for _db_file in ['*.tdb', '*.ldb']: rm_glob('/'.join([_dir, _db_file])) if create: samba_domain = [ 'samba-tool', 'domain', 'provision', '--server-role=dc', '--use-rfc2307', '--dns-backend=SAMBA_INTERNAL', '--realm={}'.format(realm), '--domain={}'.format(domain), '--adminpass={}'.format(admin_password), '--option=dns forwarder=8.8.8.8', '--option=interfaces=127.0.0.1 {}'.format(NET_IP) ] else: # join samba_domain = [ 'samba-tool', 'domain', 'join', realm, 'DC', '-U"{}\\Administrator"'.format(domain), '--password={}'.format(admin_password), '--option=idmap_ldb:use rfc2307 = yes' ] set_expiry = [ 'samba-tool', 'user', 'setexpiry', ADMIN_USER, '--noexpiry' ] export_krb = [ 'samba-tool', 'domain', 'exportkeytab', '/etc/krb5.keytab' ] finalize = False for samba_command in [samba_domain, set_expiry, export_krb]: samba_run_code, samba_run_out = run_command(samba_command) if samba_run_code != 0: if interactive: d = Dialog('Turnkey Linux - First boot configuration') retry = d.error("{}\n\n".format(samba_run_out)) finalize = False DEFAULT_REALM = realm realm = "" DEFAULT_DOMAIN = domain domain = "" admin_password = "" DEFAULT_NS = join_nameserver join_nameserver = "" break else: fatal("Errors in processing domain-controller inithook" " data.") else: finalize = True if finalize: os.chown('/etc/krb5.keytab', 0, 0) os.chmod('/etc/krb5.keytab', 0o600) shutil.copy2('/var/lib/samba/private/krb5.conf', '/etc/krb5.conf') update_resolvconf(realm.lower()) subprocess.run(['systemctl', 'restart', 'resolvconf.service']) update_hosts(NET_IP, HOSTNAME.lower(), realm.lower()) subprocess.run(['systemctl', 'start', 'samba-ad-dc']) while subprocess.run([ 'systemctl', 'is-active', '--quiet', 'samba-ad-dc' ]).returncode != 0: time.sleep(1) subprocess.check_output(['kinit', ADMIN_USER], encoding='utf-8', input=admin_password) msg = "\nPlease ensure that you have set a static IP. If you" \ " haven't already, please ensure that you do that ASAP," \ " and update IP addresses in DNS and hosts file (please" \ " see docs for more info)." if interactive: d = Dialog('Turnkey Linux - First boot configuration') d.infobox(msg) else: print(msg) break
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'email=', 'domain=']) except getopt.GetoptError as e: usage(e) password = "" email = "" domain = "" for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt == '--pass': password = val elif opt == '--email': email = val elif opt == '--domain': domain = val if not password: d = Dialog('TurnKey Linux - First boot configuration') password = d.get_password( "AVideo Password", "Enter new password for the AVideo 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "AVideo Email", "Please enter email address for the AVideo 'admin' account.", "*****@*****.**") inithooks_cache.write('APP_EMAIL', email) if not domain: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') domain = d.get_input( "AVideo Domain", "Please enter the Domain or IP address for AVideo.", DEFAULT_DOMAIN) if domain == "DEFAULT": domain = DEFAULT_DOMAIN inithooks_cache.write('APP_DOMAIN', domain) apache_conf = "/etc/apache2/sites-available/avideo.conf" subprocess.run(["sed", "-i", "0,\|RewriteRule|! {\|RewriteRule|s|https://.*|https://%s/\$1 [R,L]|}" % domain, apache_conf]) subprocess.run(["sed", "-i", "\|RewriteCond|s|!^.*|!^%s$|" % domain, apache_conf]) hashpass = hashlib.md5(password.encode('utf8')).hexdigest() m = MySQL() m.execute('UPDATE avideo.configurations SET contactEmail=%s WHERE users_id="1";', (email,)) m.execute('UPDATE avideo.users SET email=%s WHERE user="******";', (email,)) m.execute('UPDATE avideo.users SET password=%s WHERE user="******";', (hashpass,)) """Set password details in AVideo-Encoder Database (Clear and Encrypted)""" m.execute('UPDATE avideo_encoder.streamers SET pass=%s WHERE id=1;', (password,)) m.execute('UPDATE avideo_encoder.streamers SET pass=%s WHERE id=2;', (hashpass,)) domain = domain + '/' url = 'https://' + domain enc = url + 'encoder/' """Set Streamer Site Configuration in Encoder""" m.execute('UPDATE avideo_encoder.streamers SET siteURL=%s WHERE id=1;', (url,)) m.execute('UPDATE avideo_encoder.streamers SET siteURL=%s WHERE id=2;', (url,)) """Configure AVideo To Use Local Encoder""" m.execute('UPDATE avideo.configurations SET encoderURL=%s WHERE id=1;', (enc,)) """Lock Down Encoder To Specified Streamer Domain""" m.execute('UPDATE avideo_encoder.configurations SET allowedStreamersURL=%s WHERE id=1;', (url,)) """Replace URL in Config Files""" conf_path = '/var/www/{}/videos/configuration.php' for _config, _url in ( (conf_path.format('avideo'), url), (conf_path.format('avideo-encoder'), enc)): with open(_config, 'r') as fob: lines = [] for line in fob.readlines(): if "$global['webSiteRootURL'] = 'http" in line: line = line.split('=') url_prt = line[1].split("'") url_prt[1] = _url line[1] = "'".join(url_prt) line = '='.join(line) lines.append(line) with open(_config, 'w') as fob: fob.writelines(lines) """Restart Apache""" subprocess.run(['systemctl', 'restart', 'apache2.service']) """Restart nginx""" subprocess.run(['systemctl', 'restart', 'nginx.service'])
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'email=', 'domain=']) except getopt.GetoptError as e: usage(e) email = "" domain = "" password = "" for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt == '--pass': password = val elif opt == '--email': email = val elif opt == '--domain': domain = val if not password: d = Dialog('TurnKey Linux - First boot configuration') password = d.get_password( "Snipe-IT Password", "Enter new password for the Snipe-IT 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "Snipe-IT Email", "Enter email address for the Snipe-IT 'admin' account.", "*****@*****.**") inithooks_cache.write('APP_EMAIL', email) if not domain: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') domain = d.get_input( "Snipe-IT Domain", "Enter the domain to serve Snipe-IT.", DEFAULT_DOMAIN) if domain == "DEFAULT": domain = DEFAULT_DOMAIN inithooks_cache.write('APP_DOMAIN', domain) CONF = '/var/www/snipe-it/.env' # read .env lines with open(CONF, 'r') as fob: conf_lines = fob.readlines() # find APP_URL and set it to domain for i in range(len(conf_lines)): line = conf_lines[i].strip() if '=' not in line: continue key, value = line.split('=', 1) if key == 'APP_URL': line = f'APP_URL={domain}' conf_lines[i] = line + '\n' # write .env lines with open(CONF, 'w') as fob: fob.writelines(conf_lines) salt = bcrypt.gensalt() hashpass = bcrypt.hashpw(password.encode('utf8'), salt).decode('utf8') m = MySQL() m.execute('UPDATE snipeit.users SET password=%s WHERE id=1;', (hashpass,)) m.execute('UPDATE snipeit.users SET email=%s WHERE id=1;', (email,))