def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'-h', '--help'): usage() elif opt == '--pass': password = val if not password: d = Dialog('TurnKey Linux - First boot configuration') password = d.get_password( "Moodle Password", "Enter new password for the Moodle 'admin' account.") salt = _get_passwordsalt() hashpass = hashlib.md5((password + salt).encode('utf8')).hexdigest() m = MySQL() m.execute('UPDATE moodle.user SET password=%s WHERE username=\"admin\";', (hashpass, ))
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( "PHPlist Password", "Enter new password for the PHPlist 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "PHPlist Email", "Enter email address for the PHPlist '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( "PHPlist Domain", "Enter the domain to serve PHPlist.", DEFAULT_DOMAIN) if domain == "DEFAULT": domain = DEFAULT_DOMAIN inithooks_cache.write('APP_DOMAIN', domain) m = MySQL() m.execute('UPDATE phplist.admin SET password=%s WHERE loginname=\"admin\";', (password,)) m.execute('UPDATE phplist.admin SET email=%s WHERE loginname=\"admin\";', (email,)) m.execute('UPDATE phplist.config SET value=%s WHERE item=\"website\";', (domain,))
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'email=']) except getopt.GetoptError as e: usage(e) password = "" email = "" 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( "Redmine Password", "Enter new password for the Redmine 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "Redmine Email", "Enter email address for the Redmine 'admin' account.", "*****@*****.**") inithooks_cache.write('APP_EMAIL', email) salt = "".join(random.choice(string.ascii_letters) for line in range(16)) pw_with_salt = salt + hashlib.sha1(password.encode('utf-8')).hexdigest() hashpass = hashlib.sha1(pw_with_salt.encode('utf-8')).hexdigest() user_id = 1 m = MySQL() m.execute( 'UPDATE redmine_production.email_addresses SET address=\"%s\" WHERE user_id=%i;' % (email, user_id)) m.execute( 'UPDATE redmine_production.users SET salt=\"%s\" WHERE login=\"admin\" AND id=%i;' % (salt, user_id)) m.execute( 'UPDATE redmine_production.users SET hashed_password=\"%s\" WHERE login=\"admin\" AND id = %i;' % (hashpass, user_id))
def main(): signal.signal(signal.SIGINT, signal.SIG_IGN) try: opts, args = getopt.gnu_getopt(sys.argv[1:], "hp:", ['help', 'pass='******'-h', '--help'): usage() elif opt in ('-p', '--pass'): password = val if not password: d = Dialog('TurnKey Linux - First boot configuration') password = d.get_password( "%s Password" % username.capitalize(), "Please enter new password for the %s user account. This password" " will also be used for the Sempahore 'admin' user." % username) command = ["chpasswd"] input = ":".join([username, password]) salt = bcrypt.gensalt() hashpass = bcrypt.hashpw(password.encode('utf8'), salt).decode('utf8') m = MySQL() m.execute('UPDATE semaphore.user SET password=%s WHERE id=1;', (hashpass, )) p = subprocess.Popen(command, stdin=PIPE, shell=False) p.stdin.write(input.encode()) p.stdin.close() err = p.wait() if err: fatal(err) """use ssh-keygen to create an rsa key pair using the same password""" subprocess.call([ 'su', username, '-c', 'ssh-keygen -q -b 4096 -t rsa -f $HOME/.ssh/id_rsa -N %s' % pipes.quote(password) ]) if err: fatal(err)
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'email=']) except getopt.GetoptError as e: usage(e) password = "" email = "" 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( "Joomla Password", "Enter new password for the Joomla 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "Joomla Email", "Enter email address for the Joomla 'admin' account.", "*****@*****.**") inithooks_cache.write('APP_EMAIL', email) salt_chars = string.ascii_letters + string.digits salt = "".join(random.choice(salt_chars) for c in range(32)) cryptpass = "******" % (hashlib.md5( (password + salt).encode('utf8')).hexdigest(), salt) m = MySQL() m.execute('UPDATE joomla.jos_users SET email=%s WHERE username=\"admin\";', (email, )) m.execute( 'UPDATE joomla.jos_users SET password=%s WHERE username=\"admin\";', (cryptpass, ))
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'domain=']) except getopt.GetoptError as e: usage(e) password = "" domain = "" for opt, val in opts: if opt in ('-h', '--help'): usage() elif opt == '--pass': password = val elif opt == '--domain': domain = val if not password: d = Dialog('TurnKey Linux - First boot configuration') password = d.get_password( "SuiteCRM Password", "Enter new password for the SuiteCRM 'admin' account.") if not domain: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') domain = d.get_input( "SuiteCRM Domain", "Enter the domain to serve SuiteCRM.", DEFAULT_DOMAIN) if domain == "DEFAULT": domain = DEFAULT_DOMAIN with open('/var/www/suitecrm/config.php', 'r') as fob: filedata = fob.read() filedata = filedata.replace('http://127.0.0.1', domain) with open('/var/www/suitecrm/config.php', 'w') as fob: fob.write(filedata) hash_pass = hashlib.md5(password.encode('utf8')).hexdigest() m = MySQL() m.execute('UPDATE suitecrm.users SET user_hash=%s WHERE user_name=\"admin\";', (hash_pass,))
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'email=']) except getopt.GetoptError as 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) hashpass = crypt.crypt(password, crypt.METHOD_SHA512) m = MySQL() m.execute( 'UPDATE gnusocial.user SET email=%s WHERE nickname=\"administrator\";', (email, )) m.execute( 'UPDATE gnusocial.user SET password=%s WHERE nickname=\"administrator\";', (hashpass, ))
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'email=']) except getopt.GetoptError as e: usage(e) password = "" email = "" 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( "Mantis Password", "Enter new password for the Mantis 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "Mantis Email", "Enter email address for the Mantis 'admin' account.", "*****@*****.**") hashpass = hashlib.md5(password.encode('utf8')).hexdigest() m = MySQL() m.execute( 'UPDATE mantis.mantis_user_table SET email=%s WHERE username=\"admin\";', (email, )) m.execute( 'UPDATE mantis.mantis_user_table SET password=%s WHERE username=\"admin\";', (hashpass, ))
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'email=']) except getopt.GetoptError as 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( "Bagisto Password", "Enter new password for the Bagisto 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "Bagisto Email", "Enter email address for the Bagisto 'admin' account.", "*****@*****.**") inithooks_cache.write('APP_EMAIL', email) salt = bcrypt.gensalt() hashpass = bcrypt.hashpw(password.encode('utf8'), salt).decode('utf8') m = MySQL() m.execute('UPDATE bagisto.admins SET password=%s WHERE id=1;', (hashpass, )) m.execute('UPDATE bagisto.admins SET email=%s WHERE id=1;', (email, ))
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'email=']) except getopt.GetoptError as e: usage(e) password = "" email = "" 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( "Wordpress Password", "Enter new password for the Wordpress 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "Wordpress Email", "Please enter email address for the Wordpress 'admin' account.", "*****@*****.**") inithooks_cache.write('APP_EMAIL', email) hashpass = hashlib.md5(password.encode('utf8')).hexdigest() m = MySQL() m.execute('UPDATE wordpress.wp_users SET user_email=\"%s\" WHERE user_nicename=\"admin\";' % email) m.execute('UPDATE wordpress.wp_users SET user_pass=\"%s\" WHERE user_nicename=\"admin\";' % hashpass)
def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], "h", ['help', 'pass='******'-h', '--help'): usage() elif opt == '--pass': password = val if not password: d = Dialog('TurnKey Linux - First boot configuration') password = d.get_password( "Zoneminder Password", "Enter new password for the Zoneminder 'admin' account.") m = MySQL() m.execute( 'UPDATE zm.Users SET Password=PASSWORD(%s) WHERE Username=\"admin\";', (password, ))
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( "Gitea Password", "Enter new password for the Gitea 'admin' account.", pass_req=8, min_complexity=4) if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "Gitea Email", "Enter email address for the Gitea '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("Gitea Domain", "Enter the domain to serve Gitea.", DEFAULT_DOMAIN) if domain == "DEFAULT": domain = DEFAULT_DOMAIN inithooks_cache.write('APP_DOMAIN', domain) config = "/etc/gitea/app.ini" subprocess.run([ "su", "git", "-c", "cd /home/git && ./gitea admin change-password -u gitea -p %s" % password ]) subprocess.run(['sed', '-i', "\|DOMAIN|s|=.*|= %s|" % domain, config]) subprocess.run( ['sed', '-i', "\|ROOT_URL|s|=.*|= https://%s/|" % domain, config]) subprocess.run(['sed', '-i', "\|FROM|s|=.*|= %s|" % email, config]) m = MySQL() m.execute("UPDATE gitea.user SET email='%s' WHERE id=1;" % (email, )) subprocess.run(["systemctl", "restart", "gitea"])
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( "Elgg Password", "Enter new password for the Elgg 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "Elgg Email", "Enter email address for the Elgg '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( "Elgg Domain", "Enter the domain to serve Elgg. Note: Elgg does not support http without further configuration, domain will default to https.", DEFAULT_DOMAIN) if domain == "DEFAULT": domain = DEFAULT_DOMAIN fqdn = re.compile(r"https?://") fqdn = fqdn.sub('', domain).strip('/') domain = ("https://%s/" % fqdn) inithooks_cache.write('APP_DOMAIN', fqdn) salt = bcrypt.gensalt(10) hashpass = bcrypt.hashpw(password.encode('utf8'), salt) m = MySQL() try: with m.connection.cursor() as cursor: cursor.execute( 'SELECT guid FROM elgg.elgg_entities WHERE type="user" AND owner_guid="0"' ) admin_guid = cursor.fetchone()['guid'] cursor.execute( 'SELECT name FROM elgg.elgg_metadata WHERE entity_guid=%s', (admin_guid, )) assert (cursor.fetchone()['name']) # sanity check, if this fails, look at the database. You'll probably need to update # all of this database stuff cursor.execute( 'UPDATE elgg.elgg_metadata SET value=%s WHERE entity_guid=%s AND name="password_hash"', ( hashpass, admin_guid, )) cursor.execute( 'UPDATE elgg.elgg_metadata SET value=%s WHERE entity_guid=%s AND name="email"', ( email, admin_guid, )) cursor.execute( 'UPDATE elgg.elgg_metadata SET value=%s WHERE entity_guid=1 AND name="email"', (email, )) m.connection.commit() finally: m.connection.close() with open('/etc/cron.d/elgg', 'r') as fob: contents = fob.read() contents = re.sub("ELGG='.*'", "ELGG='%s'" % domain, contents) with open('/etc/cron.d/elgg', 'w') as fob: fob.write(contents) elgg_conf = "/var/www/elgg/elgg-config/settings.php" subprocess.run([ "sed", "-i", '\|^\$CONFIG->wwwroot|s|=.*|= "%s";|' % domain.strip('/'), elgg_conf ]) apache_conf = "/etc/apache2/sites-available/elgg.conf" subprocess.run([ "sed", "-i", "\|RewriteRule|s|https://.*|https://%s/\$1 [R,L]|" % fqdn, apache_conf ]) subprocess.run( ["sed", "-i", "\|RewriteCond|s|!^.*|!^%s$|" % fqdn, apache_conf]) subprocess.run(["service", "apache2", "restart"])
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( "Drupal9 Password", "Enter new password for the Drupal9 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email( "Drupal9 Email", "Enter email address for the Drupal9 '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("Drupal9 Domain", "Enter the domain to serve Drupal9.", DEFAULT_DOMAIN) if domain == "DEFAULT": domain = DEFAULT_DOMAIN inithooks_cache.write('APP_DOMAIN', domain) print("Progress...") m = MySQL() m.execute( 'UPDATE drupal9.users_field_data SET mail=%s WHERE name=\"admin\";', (email, )) m.execute( 'UPDATE drupal9.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='******'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)
if not domain.startswith('https://') and not domain.startswith( 'http://'): domain = 'https://' + domain with open('/opt/ghost/config.production.json', 'r') as fob: all_config = fob.read() current_url = re.findall(r'(https?://\S+)', all_config)[0] # third occurance in file current_url = current_url.translate(None, "\",") all_config = all_config.replace(current_url, domain) with open('/opt/ghost/config.production.json', 'w') as fob: fob.write(all_config) hashed_pw = bcrypt.hashpw(password, bcrypt.gensalt()) cur = MySQL() cur.execute('UPDATE ghost.users SET password=\"%s\" WHERE id="1";' % hashed_pw) cur.execute('UPDATE ghost.users SET name=\"%s\" WHERE id="1";' % uname) cur.execute('UPDATE ghost.users SET email=\"%s\" WHERE id="1";' % email) cur.execute('UPDATE ghost.users SET status=\"active\" WHERE id="1";') os.system("service ghost_localhost restart") if __name__ == '__main__': main()
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, ))
"TomatoCart Password", "Enter new password for the 'admin' account.") if not email: if 'd' not in locals(): d = Dialog('TurnKey Linux - First boot configuration') email = d.get_email("TomatoCart Email", "Enter email address for the 'admin' account.", "*****@*****.**") salt = ''.join( (random.choice(string.letters + string.digits) for x in range(2))) hash = ':'.join([hashlib.md5(salt + password).hexdigest(), salt]) m = MySQL() m.execute( 'UPDATE tomatocart.administrators SET user_password=\"%s\",email_address=\"%s\" WHERE user_name=\"admin\";' % (hash, email)) m.execute( 'UPDATE tomatocart.configuration SET configuration_value=\"%s\" WHERE configuration_key=\"STORE_OWNER_EMAIL_ADDRESS\";' % email) m.execute( 'UPDATE tomatocart.configuration SET configuration_value=\"\\"Store Owner\\" <%s>\" WHERE configuration_key=\"EMAIL_FROM\";' % email) # delete cache system("rm -f /var/cache/tomatocart/*")
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,))