-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.py
61 lines (51 loc) · 1.8 KB
/
functions.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
#!/usr/bin/python
from os import path, system, sys, setuid
from time import sleep
from sys import exit
from subprocess import Popen, PIPE
kill = ['cbin', 'c.py',
'cpbin', 'cpp.py',
'python.py',
'scilex', 'scilab.py']
remove = ['/tmp/1.c', '/tmp/cerror', '/tmp/cbin',
'/tmp/1.cpp', '/tmp/cperror', '/tmp/cpbin',
'/tmp/1.py',
'/var/www/html/scilab/tmp/1.cde', '/var/www/html/scilab/tmp/1.err',
'/var/www/html/scilab/tmp/plot.cde',
'/var/www/html/flag']
def killnRemoveExcept(presentCGI):
kill.remove(presentCGI)
for each in kill:
system("killall %s" %(each))
for each in remove:
system("rm %s" %(each))
def writeCode(sourceFile,code):
f = open(sourceFile,'w')
f.write(code)
f.close()
def writeNoGUIcode(code,sourceFile):
f = open(sourceFile,'w')
f.write("mode(-1);\nlines(0);\nmode(-1);\ntry\nmode(2);\n")
f.write(code)
f.write("\nmode(-1);\nexit();\ncatch\nmode(-1);\ndisp(lasterror());\nexit();")
f.close()
def writeGUIcode(code,sourceFilePlot):
f = open(sourceFilePlot,'w')
f.write("mode(-1);\ntry\nscf(0);\n")
f.write(code)
f.write("\nmode(-1);\nxs2gif(0,\'/var/www/html/scilab/tmp/1.gif\');")
f.write("\nexit();\ncatch\n[error_message,error_number]=lasterror(%t);\n")
f.write("ukm=file(\'open\',\'/var/www/html/scilab/tmp/1.err\');")
f.write("\nwrite(ukm,error_message);\nfile(\'close\',ukm);\n")
f.write("xdel(winsid());\nend;\nexit();")
f.close()
def SaveCode(code,source,request):
"""
writes CM's content to file and copies it to SDCARD
"""
f = open(source,'w')
f.write(code)
f.close()
system("cp %s /tmp/scisave/%s.cde" %(source,request))
system("touch /var/www/html/saveflag")
system("rm %s" %(source))