-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsg2.py.in
63 lines (57 loc) · 1.93 KB
/
csg2.py.in
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
#!/usr/bin/python3 -u
#
# ChlorideSiteGenerator 2
# Copyright (C) 2016 Sebastian "Chloride Cull" Johansson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import sys
import os
import pwd
import subprocess
# Get new user ID
try:
pwdinfo = pwd.getpwnam("@SERVUSERNAME@")
except (KeyError):
# User doesn't exist, create it
subprocess.call([
'@USERADDBIN@',
'--home', '@POSTINSTALLPATH@/share/csg2/',
'--system',
'--shell', '/bin/false',
'@SERVUSERNAME@'
], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
pwdinfo = pwd.getpwnam("@SERVUSERNAME@")
userid = pwdinfo.pw_uid
groupid = pwdinfo.pw_gid
# Create directories if they do not exist
try:
os.stat("/var/log/csg2")
except (FileNotFoundError):
os.mkdir("/var/log/csg2", mode=0o770)
os.chown("/var/log/csg2", userid, groupid)
try:
os.stat("/srv/csg2")
except (FileNotFoundError):
os.mkdir("/srv/csg2", mode=0o775)
os.chown("/srv/csg2", userid, groupid)
# Drop privileges
os.setgid(groupid)
os.setuid(userid)
# Start actual server
sys.path[0] = "@POSTINSTALLPATH@/share/csg2/"
from serve import CSG2Server
csg2themedir = "@POSTINSTALLPATH@/share/csg2/themes"
csg2siteconf = "@POSTINSTALLPATH@/share/csg2/site-template.conf"
CSG2Server(csg2themedir, csg2siteconf)