|
|
@@ -3,6 +3,7 @@ import models.project |
|
|
from views.utils import get_nav_bar |
|
|
from views.utils import get_nav_bar |
|
|
import cgi, os |
|
|
import cgi, os |
|
|
import cgitb; cgitb.enable() |
|
|
import cgitb; cgitb.enable() |
|
|
|
|
|
from time import sleep |
|
|
|
|
|
|
|
|
# Get html templates |
|
|
# Get html templates |
|
|
render = web.template.render('templates/') |
|
|
render = web.template.render('templates/') |
|
|
@@ -40,15 +41,23 @@ class Project: |
|
|
# Test if the file was uploaded |
|
|
# Test if the file was uploaded |
|
|
if fileitem.filename: |
|
|
if fileitem.filename: |
|
|
data = web.input(projectid=0) |
|
|
data = web.input(projectid=0) |
|
|
# strip leading path from file name to avoid |
|
|
|
|
|
# directory traversal attacks |
|
|
|
|
|
fn = os.path.basename(fileitem.filename) |
|
|
|
|
|
|
|
|
|
|
|
if not os.path.isdir(('static/project' + data.projectid)): |
|
|
|
|
|
command = 'mkdir static/project' + data.projectid |
|
|
|
|
|
|
|
|
fn = fileitem.filename |
|
|
|
|
|
print(data) |
|
|
|
|
|
# Create the project directory if it doesnt exist |
|
|
|
|
|
path = 'static/project' + data.projectid |
|
|
|
|
|
if not os.path.isdir(path): |
|
|
|
|
|
command = 'mkdir ' + path |
|
|
os.popen(command) |
|
|
os.popen(command) |
|
|
|
|
|
|
|
|
open('static/project' + data.projectid + '/' + fn, 'wb').write(fileitem.file.read()) |
|
|
|
|
|
|
|
|
sleep(0.5) |
|
|
|
|
|
path = path + '/task' + data.taskid |
|
|
|
|
|
print(path) |
|
|
|
|
|
if not os.path.isdir(path): |
|
|
|
|
|
print(data.taskid) |
|
|
|
|
|
command = 'mkdir ' + path |
|
|
|
|
|
os.popen(command) |
|
|
|
|
|
sleep(0.5) |
|
|
|
|
|
open(path + '/' + fn, 'wb').write(fileitem.file.read()) |
|
|
message = 'The file "' + fn + '" was uploaded successfully' |
|
|
message = 'The file "' + fn + '" was uploaded successfully' |
|
|
|
|
|
|
|
|
else: |
|
|
else: |
|
|
@@ -56,4 +65,5 @@ class Project: |
|
|
|
|
|
|
|
|
print (message) |
|
|
print (message) |
|
|
|
|
|
|
|
|
raise web.seeother('/project') |
|
|
|
|
|
|
|
|
raise web.seeother(('/project?projectid=' + data.projectid)) |
|
|
|
|
|
|