-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenfpm.py
46 lines (38 loc) · 1.43 KB
/
genfpm.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
import os
import config
# PHP-FPM config generator by John Tate (johntate.org)
# licenced under the MIT licence.
# This script gets all the users from the group and makes a php-fpm config for
# that particular user. The config is based on a template where %USER% is repl-
# aced by the users name.
# This script runs on the production system Occulus Omega and works.
# http://occuomegawqtkl6j.onion/
def getUsers():
users = []
f = open(config.systemGroups,'r')
for line in f:
splitted = line.split(':')
if (splitted[0] == "users"):
userline = splitted[3].split(',')
for user in userline:
users.append(user.strip('\n'))
return users
def customConfig(user):
# checks if there is a custom configuration for a user.
if (os.path.isfile(config.customConfigs + user + ".tpl")):
return config.customConfigs + user + ".tpl"
return config.configTemplate
def genConfig(user):
tpl = open(customConfig(user),'r')
out = open(config.outputDir + user + ".conf",'w')
for line in tpl:
out.write(line.replace('%USER%',user))
listConfig = os.listdir(config.outputDir)
for configFile in listConfig:
if (configFile.endswith(".conf")):
print("Removing file: " + config.outputDir + configFile)
os.remove(config.outputDir + configFile)
users = getUsers()
for user in users:
print("Generating fpm config for user: " + user)
genConfig(user)