forked from Arborator/arborator-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configCheck.cgi
executable file
·92 lines (70 loc) · 2.97 KB
/
configCheck.cgi
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
####
# Copyright (C) 2009-2015 Kim Gerdes
# kim AT gerdes. fr
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This script 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 General Public License (www.gnu.org) for more details.
#
# You can retrieve a copy of the GNU General Public License
# from http://www.gnu.org/. For a copy via US Mail, write to the
# Free Software Foundation, Inc.
# 59 Temple Place - Suite 330,
# Boston, MA 02111-1307
# USA
####
"""
called from configedit.cgi by javascript
checks whether the proposed modification of the configuration is syntactically acceptable
"""
import cgi, sys, cgitb, codecs, os
from lib import config
sys.path.append('modules')
from logintools import isloggedin
cgitb.enable()
form = cgi.FieldStorage()
ct = form.getvalue('config',None).decode("utf-8")
cats = form.getvalue('cats',None).decode("utf-8")
funcs = form.getvalue('funcs',None).decode("utf-8")
projectName = form.getvalue('project',None).decode("utf-8")
test = isloggedin("users/")
if not test:sys.exit()
admin = test[0]["admin"]
if not admin:sys.exit()
#print "Content-Type: text/html\n" # blank line: end of headers
def confToDisk(tmp):
filename=unicode(os.path.join(unicode(os.getcwd()),u"projects",projectName,u"project.cfg"+tmp )).encode("utf-8")
f=codecs.open(filename,"w","utf-8")
f.write(ct)
f.close()
c=config.checkConfigProject(projectName, filename=u"project.cfg"+tmp,readin=False)
filename=os.path.join(os.getcwd(),"projects",projectName.encode("utf-8"),(c["configuration"]["categoriesfilename"]+tmp).encode("utf-8") )
f=codecs.open(filename,"w","utf-8")
f.write(cats)
f.close()
filename=os.path.join(os.getcwd(),"projects",projectName.encode("utf-8"),(c["configuration"]["functionsfilename"]+tmp).encode("utf-8") )
f=codecs.open(filename,"w","utf-8")
f.write(funcs)
f.close()
return config.checkConfigProject(projectName, filename=u"project.cfg"+tmp,readin=True)
def eraseConfig(tmp,c):
os.remove(unicode(os.path.join(unicode(os.getcwd()),u"projects",projectName,u"project.cfg"+tmp )).encode("utf-8"))
os.remove(os.path.join(os.getcwd(),"projects",projectName.encode("utf-8"),(c["configuration"]["categoriesfilename"]+tmp).encode("utf-8") ) )
os.remove(os.path.join(os.getcwd(),"projects",projectName.encode("utf-8"),(c["configuration"]["functionsfilename"]+tmp).encode("utf-8") ) )
# first phase: testing with tmp files, without erasing the old files
c=confToDisk(".tmp")
#erase the tmp config files:
eraseConfig(".tmp",c)
# if here no error all is well. we can save normally
c=confToDisk("")
#and
print "Content-Type: text/json\r\n\r\n"
print '{"answer":"Ok. Saved."}'