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:
Bofh 2021-02-07 02:56:08 +01:00
parent c88a1c1c5b
commit ece785b02e
4 changed files with 33 additions and 8 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
cache/*
headers/*
db/*
scripts/user_create
__pycache__/*

View File

@ -1,6 +1,7 @@
#!/usr/bin/python3
import requests
import hashlib
import string
import random
import time
import json
@ -8,8 +9,26 @@ import os
import re
def add_igaccount(acc_id):
data = getig_user_data(acc_id)
print(data)
accfile = './db/accounts/{}'.format(acc_id)
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:
# - display name

3
scripts/user_create.example Executable file
View File

@ -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

View File

@ -1,10 +1,8 @@
from http.server import BaseHTTPRequestHandler, HTTPServer
import igmirror
import sys
import re
hostName = "localhost"
serverPort = 8080
def update_igaccount(name):
print(name)
@ -24,9 +22,12 @@ class MyServer(BaseHTTPRequestHandler):
update_igaccount(accname)
self.wfile.write(bytes('OK', "utf-8"))
if __name__ == "__main__":
webServer = HTTPServer(('localhost', 8080), MyServer)
print("Server started http://%s:%s" % (hostName, serverPort))
if __name__ == "__main__":
port = 8080
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:
webServer.serve_forever()