User creation automated + server port configurable
* Make sure user input can never contain an invalid character as it might create a shell exploit vulnerability otherwise
This commit is contained in:
parent
c88a1c1c5b
commit
ece785b02e
|
@ -1,3 +1,5 @@
|
||||||
cache/*
|
cache/*
|
||||||
headers/*
|
headers/*
|
||||||
|
db/*
|
||||||
|
scripts/user_create
|
||||||
__pycache__/*
|
__pycache__/*
|
||||||
|
|
23
igmirror.py
23
igmirror.py
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import requests
|
import requests
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import string
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
@ -8,8 +9,26 @@ import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
def add_igaccount(acc_id):
|
def add_igaccount(acc_id):
|
||||||
data = getig_user_data(acc_id)
|
accfile = './db/accounts/{}'.format(acc_id)
|
||||||
print(data)
|
if not os.path.exists(accfile):
|
||||||
|
data = getig_user_data(acc_id)
|
||||||
|
name = data['graphql']['user']['full_name']
|
||||||
|
name = re.sub(r'[^a-zA-Z0-9_\s]', '', name)
|
||||||
|
account = {
|
||||||
|
'name': name,
|
||||||
|
'username': acc_id,
|
||||||
|
'password': random_string()
|
||||||
|
}
|
||||||
|
if os.path.exists('./scripts/user_create'):
|
||||||
|
os.system('./scripts/user_create \'{}\' \'{}\' \'{}\''.format(\
|
||||||
|
account['name'], account['username'], account['password']))
|
||||||
|
w = open(accfile, 'w')
|
||||||
|
w.write(json.dumps(account))
|
||||||
|
w.close()
|
||||||
|
#data = getig_user_data(acc_id)
|
||||||
|
|
||||||
|
def random_string(count=32):
|
||||||
|
return ''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits, k=count))
|
||||||
|
|
||||||
# get all profile data from user:
|
# get all profile data from user:
|
||||||
# - display name
|
# - display name
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
cd /var/www/html
|
||||||
|
php artisan user:create --name="$1" --username="$2" --email="pixelfed.$2@localhost" --password="$3" --confirm_email=1 -q -n
|
13
server.py
13
server.py
|
@ -1,10 +1,8 @@
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
import igmirror
|
import igmirror
|
||||||
|
import sys
|
||||||
import re
|
import re
|
||||||
|
|
||||||
hostName = "localhost"
|
|
||||||
serverPort = 8080
|
|
||||||
|
|
||||||
def update_igaccount(name):
|
def update_igaccount(name):
|
||||||
print(name)
|
print(name)
|
||||||
|
|
||||||
|
@ -24,9 +22,12 @@ class MyServer(BaseHTTPRequestHandler):
|
||||||
update_igaccount(accname)
|
update_igaccount(accname)
|
||||||
self.wfile.write(bytes('OK', "utf-8"))
|
self.wfile.write(bytes('OK', "utf-8"))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
webServer = HTTPServer(('localhost', 8080), MyServer)
|
port = 8080
|
||||||
print("Server started http://%s:%s" % (hostName, serverPort))
|
if len(sys.argv) > 1:
|
||||||
|
port = int(sys.argv[1])
|
||||||
|
webServer = HTTPServer(('0.0.0.0', port), MyServer)
|
||||||
|
print("Server started http://%s:%s" % ('0.0.0.0', port))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
webServer.serve_forever()
|
webServer.serve_forever()
|
||||||
|
|
Loading…
Reference in New Issue