This repository has been archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
146 lines (135 loc) · 4.46 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import os, json
from time import sleep
with open('container/data.json', 'r') as config:
config = json.load(config)
def clearTerminal():
try:
os.system("clear")
except:
os.system("cls")
clearTerminal()
print("\nHELLO THERE :)")
sleep(5)
clearTerminal()
print("\nGetting things ready for you...")
sleep(5)
clearTerminal()
print("\nChecking for updates...")
sleep(2)
os.system('sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED')
os.system('sudo apt update -y')
clearTerminal()
print("\nInstalling requirements...")
sleep(2)
os.system("sudo pip3 install flask")
clearTerminal()
print("\nInstalling requirements...")
sleep(2)
os.system("sudo pip3 install waitress")
os.system("sudo pip3 install psutil")
clearTerminal()
print("\nInstalling Nginx...")
sleep(2)
os.system("sudo apt install nginx -y")
clearTerminal()
print("\nGranting access for Nginx...")
sleep(2)
os.system("sudo ufw allow 'Nginx Full'")
clearTerminal()
print("\nInstalling MySQL Server...")
sleep(2)
os.system("sudo apt install mysql-server -y")
clearTerminal()
print("\nInstalling Php...")
sleep(2)
os.system("sudo apt install php8.1-fpm php-mysql -y")
os.system("mysql -u 'root' -e \"create database flask_panel\"")
os.system("mysql -u 'root' -e \"create user 'fpanel'@'localhost' identified with mysql_native_password by '@Fpanel123'\"")
os.system("mysql -u 'root' -e \"grant all privileges on flask_panel.* to 'fpanel'@'localhost'\"")
clearTerminal()
print("\nInstalling Php...")
sleep(2)
os.system("sudo apt install php-fpm php-mysql -y")
clearTerminal()
print("\nYou need to do something :)")
config['username'] = input("Enter username for admin access : ")
config['password'] = input("Enter password for admin access : ")
container_host = input("Enter container domain : ")
database_host = input("Enter database domain : ")
config['phpmyadmin'] = "https://{}/phpmyadmin".format(database_host)
clearTerminal()
print("Checking....")
sleep(2)
if config['username'] == "":
print("Installation failed : username can not be empty")
elif config['password'] == "":
print("Installation failed : password can not be empty")
elif container_host == "":
print("Installation failed : container domain can not be empty")
elif database_host == "":
print("Installation failed : database domain can not be empty")
else:
with open('container/data.json','w') as wconf:
json.dump(config, wconf, indent=4)
clearTerminal()
print('\nBuilding server block...')
container_block = """server {
listen 80;
server_name """+container_host+""";
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}"""
with open('/etc/nginx/sites-enabled/container', 'w') as ww:
ww.write(container_block)
sleep(2)
clearTerminal()
print("\nInstalling certbot...")
sleep(1)
os.system("sudo apt install certbot python3-certbot-nginx -y")
clearTerminal()
print("\nApplying SSL to container...")
sleep(1)
os.system("sudo certbot --nginx -d {}".format(container_host))
clearTerminal()
print("\nInstalling PhpMyAdmin...")
sleep(1)
os.system("sudo apt install phpmyadmin -y")
os.system("sudo mkdir /var/www/database")
os.system("sudo chown -R $USER:$USER /var/www/database")
os.system("sudo ln -s /usr/share/phpmyadmin /var/www/database/phpmyadmin")
clearTerminal()
print("\nBuilding server block...")
tt = """
server {
listen 80;
server_name """+database_host+""";
root /var/www/database;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
"""
with open('/etc/nginx/sites-available/database', 'w') as ww:
ww.write(tt)
os.system("sudo ln -s /etc/nginx/sites-available/database /etc/nginx/sites-enabled/")
clearTerminal()
print("\nApplying SSL to database...")
os.system("sudo certbot --nginx -d {}".format(database_host))
clearTerminal()
print("\nRestarting Nginx...")
os.system("sudo systemctl restart nginx")
clearTerminal()
print("\nAll things DONE... Please wait...")
sleep(5)
os.system("cd container && python3 app.py")