Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import MySQLdb
- import urllib
- import tarfile
- import os
- import sys
- import random
- import string
- import hashlib
- import time
- import requests
- def computeMD5hash(string):
- m = hashlib.md5()
- m.update(string.encode('utf-8'))
- return m.hexdigest()
- def id_generator(size=15, chars=string.ascii_uppercase + string.digits):
- return ''.join(random.choice(chars) for _ in range(size))
- ## Requirements
- # Dir /tmp/wp/ exist
- # db_name does not exist
- params=sys.argv[1]
- if params=="-sslinstall":
- domain=sys.argv[2]
- os.system('add-apt-repository -y ppa:certbot/certbot');
- os.system('apt-get update')
- os.system('sudo certbot --nginx -n -d '+domain+' -d www.'+domain)
- #os.system('sudo certbot --nginx -d skidapp.com -d www.skidapp.com')
- os.system('systemctl reload nginx')
- elif params=="-sslrenew":
- os.system('sudo certbot renew')
- elif params=="-ssloff":
- domain=sys.argv[2]
- f= open('/etc/nginx/sites-available/'+domain,'r')
- lines=f.readlines();
- c=0
- f.close()
- for line in lines:
- if "listen 443 ssl; # managed by Certbot" in line and line[0][0]!="#":
- lines[c]="# "+line
- elif "return 301 https://$host$request_uri" in line and "#" not in line:
- lines[c]="# "+line
- c=c+1
- f=open('/etc/nginx/sites-available/'+domain,'w')
- f.writelines(lines)
- f.close()
- os.system('systemctl reload nginx')
- os.system('systemctl restart nginx')
- elif params=="-sslon":
- domain=sys.argv[2]
- f= open('/etc/nginx/sites-available/'+domain,'r')
- lines=f.readlines();
- c=0
- f.close()
- for line in lines:
- if "listen 443 ssl; # managed by Certbot" in line and line[0][0]=="#":
- lines[c]=line[1:]
- c=c+1
- f=open('/etc/nginx/sites-available/'+domain,'w')
- f.writelines(lines)
- f.close()
- os.system('systemctl reload nginx')
- os.system('systemctl restart nginx')
- elif params=="-redirecton":
- domain=sys.argv[2]
- f= open('/etc/nginx/sites-available/'+domain,'r')
- lines=f.readlines();
- c=0
- f.close()
- for line in lines:
- if "return 301 https://$host$request_uri" in line and "#" in line:
- lines[c]=line[1:]
- c=c+1
- f=open('/etc/nginx/sites-available/'+domain,'w')
- f.writelines(lines)
- f.close()
- os.system('systemctl reload nginx')
- os.system('systemctl restart nginx')
- elif params=="-redirectoff":
- domain=sys.argv[2]
- f= open('/etc/nginx/sites-available/'+domain,'r')
- lines=f.readlines();
- c=0
- f.close()
- for line in lines:
- if "return 301 https://$host$request_uri" in line and "#" not in line:
- lines[c]="# "+line
- c=c+1
- f=open('/etc/nginx/sites-available/'+domain,'w')
- f.writelines(lines)
- f.close()
- os.system('systemctl reload nginx')
- os.system('systemctl restart nginx')
- elif params=="-lemp":
- os.system('apt-get update')
- os.system('apt-get install -y nginx')
- os.system('apt-get install -y php7.0-cli php7.0-cgi php7.0-fpm')
- s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?"
- passlen =16
- mysqlp = "".join(random.sample(s,passlen ))
- with open("/.mysqlpassword", "a") as myfile:
- myfile.write("root,"+mysqlp)
- os.system('echo "mysql-server mysql-server/root_password password '+mysqlp+'" | debconf-set-selections')
- os.system('echo "mysql-server mysql-server/root_password_again password '+mysqlp+'" | debconf-set-selections')
- os.sytem('apt-get -y install mysql-server')
- os.system('apt-get install -y php7.0-mysql')
- os.system('systemctl restart nginx')
- foo="""server {
- listen 80 default_server;
- listen [::]:80 default_server;
- root /var/www/html;
- index index.php index.html index.htm index.nginx-debian.html;
- server_name server_domain_or_IP;
- location / {
- try_files $uri $uri/ =404;
- }
- location ~ \.php$ {
- include snippets/fastcgi-php.conf;
- fastcgi_pass unix:/run/php/php7.0-fpm.sock;
- }
- location ~ /\.ht {
- deny all;
- }
- }"""
- with open('/etc/nginx/sites-available/default','w') as f:
- f.write(foo)
- os.system('systemctl reload nginx')
- elif params=="-installwp":
- domain=sys.argv[2]
- os.system("mkdir wp")
- wp_dl = 'https://wordpress.org/latest.tar.gz'
- wp_file = '/root/wp.tar.gz'
- os.system("mkdir "+"/var/www/"+domain)
- doc_root = '/var/www/'+domain+'/html'
- os.system("mkdir "+doc_root)
- wuname=domain.split(".")[0][:-3]
- wpassword=id_generator()
- db_name=domain.split(".")[0]
- db_user = 'root'
- db_pass = 'admin'
- ## Create database first
- db = MySQLdb.connect(host="localhost",user=db_user,passwd=db_pass)
- cursor = db.cursor()
- sql = 'CREATE DATABASE ' + db_name
- try:
- cursor.execute(sql)
- content=requests.get("https://pastebin.com/raw/1s6ebKay")
- with open('/root/content.sql','w') as f:
- f.write(content.text)
- os.system("mysql -u"+db_user+" -p"+db_pass+" "+db_name+" <"+"/root/content.sql")
- wp_pass=computeMD5hash(wpassword)
- db=MySQLdb.connect("localhost",db_user,db_pass,db_name)
- cursor=db.cursor()
- siteurl="http://"+domain
- crrdt=time.strftime("%Y-%m-%d %H:%M:00",time.localtime())
- cursor.execute("""INSERT INTO wp_users(ID,user_login,user_pass,user_nicename,user_email,user_registered,display_name) values(%s,%s,%s,%s,%s,%s,%s)""",(int(1),wuname,wp_pass,wuname,'demo@admin.com',crrdt,wuname))
- db.commit()
- cursor.execute("""update wp_usermeta set meta_value=%s where umeta_id=%s""",(wuname,'1'))
- db.commit()
- cursor.execute("""update wp_options set option_value=%s where option_name=%s""",(db_name,'blogname'))
- db.commit()
- cursor.execute("""update wp_options set option_value=%s where option_name=%s""",(siteurl,'siteurl'))
- db.commit()
- cursor.execute("""update wp_options set option_value=%s where option_name=%s""",(siteurl,'home'))
- db.commit()
- except MySQLdb.Error, e:
- print "MySQL Error [%d]: %s" % (e.args[0], e.args[1])
- print('Something went wrong: Database exists ?')
- ## Download latest source code
- print('Start downloading latest wordpress...\n')
- urllib.urlretrieve(wp_dl, wp_file)
- ## Extract source
- tfile = tarfile.open(wp_file, 'r:gz')
- tfile.extractall('/root/wp')
- print('Extrat done!\n')
- ## Sync source to DocRoot
- print('Start rsync source\n')
- os.system("rsync -avrz /root/wp/wordpress/ " + doc_root)
- content="""server {
- listen 80 ;
- listen [::]:80 ;
- root /var/www/"""+domain+"""/html;
- index index.php index.html index.htm index.nginx-debian.html;
- server_name """+domain+" www."""+domain+""";
- location / {
- try_files $uri $uri/ =404;
- }
- location ~ \.php$ {
- include snippets/fastcgi-php.conf;
- fastcgi_pass unix:/run/php/php7.0-fpm.sock;
- }
- location ~ /\.ht {
- deny all;
- }
- }
- """
- with open('/etc/nginx/sites-available/'+domain,'w') as f:
- f.write(content)
- os.system('ln -s /etc/nginx/sites-available/'+domain+' /etc/nginx/sites-enabled/');
- wpconfig="""<?php
- /**
- * The base configuration for WordPress
- *
- * The wp-config.php creation script uses this file during the
- * installation. You don't have to use the web site, you can
- * copy this file to "wp-config.php" and fill in the values.
- *
- * This file contains the following configurations:
- *
- * * MySQL settings
- * * Secret keys
- * * Database table prefix
- * * ABSPATH
- *
- * @link https://codex.wordpress.org/Editing_wp-config.php
- *
- * @package WordPress
- */
- // ** MySQL settings - You can get this info from your web host ** //
- /** The name of the database for WordPress */
- define('DB_NAME', '"""+db_name+"""');
- /** MySQL database username */
- define('DB_USER', '"""+db_user+"""');
- /** MySQL database password */
- define('DB_PASSWORD', '"""+db_pass+"""');
- /** MySQL hostname */
- define('DB_HOST', 'localhost');
- /** Database Charset to use in creating database tables. */
- define('DB_CHARSET', 'utf8');
- /** The Database Collate type. Don't change this if in doubt. */
- define('DB_COLLATE', '');
- /**#@+
- * Authentication Unique Keys and Salts.
- *
- * Change these to different unique phrases!
- * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
- * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
- *
- * @since 2.6.0
- */
- define('AUTH_KEY', 'put your unique phrase here');
- define('SECURE_AUTH_KEY', 'put your unique phrase here');
- define('LOGGED_IN_KEY', 'put your unique phrase here');
- define('NONCE_KEY', 'put your unique phrase here');
- define('AUTH_SALT', 'put your unique phrase here');
- define('SECURE_AUTH_SALT', 'put your unique phrase here');
- define('LOGGED_IN_SALT', 'put your unique phrase here');
- define('NONCE_SALT', 'put your unique phrase here');
- /**#@-*/
- /**
- * WordPress Database Table prefix.
- *
- * You can have multiple installations in one database if you give each
- * a unique prefix. Only numbers, letters, and underscores please!
- */
- $table_prefix = 'wp_';
- /**
- * For developers: WordPress debugging mode.
- *
- * Change this to true to enable the display of notices during development.
- * It is strongly recommended that plugin and theme developers use WP_DEBUG
- * in their development environments.
- *
- * For information on other constants that can be used for debugging,
- * visit the Codex.
- *
- * @link https://codex.wordpress.org/Debugging_in_WordPress
- */
- define('WP_DEBUG', false);
- /* That's all, stop editing! Happy blogging. */
- /** Absolute path to the WordPress directory. */
- if ( !defined('ABSPATH') )
- define('ABSPATH', dirname(__FILE__) . '/');
- /** Sets up WordPress vars and included files. */
- require_once(ABSPATH . 'wp-settings.php');
- """
- with open('/var/www/'+domain+'/html/wp-config.php','w') as f:
- f.write(wpconfig)
- os.system('nginx -t')
- os.system('systemctl reload nginx')
- print "user name:"+wuname
- print "password:"+wpassword
- else:
- print "No argument passed"
Add Comment
Please, Sign In to add comment