-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilefix.py
executable file
·69 lines (61 loc) · 1.79 KB
/
filefix.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
62
63
64
65
66
67
68
69
#!/usr/bin/python
# File uploader
# Copyright Mike Zamansky, January 2004
#
import cgi
import stat
import os
import sys
import crypt
import nis
import string
import re
import time
import xmlrpclib
import curses.ascii
#import cgitb
#cgitb.enable()
tempdir = '/tmp/filefix/'
def process(f):
upload = f['filename']
data = upload.file.read()
data = data.replace('\r\n', '\n')
s = 'Content-type: unknown\nContent-Disposition: attachment; filename="' + upload.filename + '"\n'
print s
print data
form = cgi.FieldStorage()
if form.has_key("SUBMIT") and form["SUBMIT"].value == "SUBMIT":
process(form)
else:
html='''
<html>
<head><title>File Fix</title>
<link rel="stylesheet"
type="text/css"
href="style.css" />
</head>
<body>
<h1>Fix Windows Newline Problems</h1>
<ol>
<li>Click Choose File below and select your file.</li>
<li>Click Submit</li>
<li>Your browser will either automatically download the file or ask you where to save the file
<ul>
<li>SUPER IMPORTANT NOTE: DO NOT CHOSE TO OPEN THE FILE!</li>
<li>If you open the file, windows will then add those pesky \rs back!</li>
</ul></li>
<li>You should then use the downloaded file to ftp back to your class webserver</li>
</ol>
<center>
<FORM METHOD="POST" ENCTYPE="multipart/form-data">
<table>
<tr><td>File:</td><td><input type="FILE" name="filename"></td></tr>
</table>
<input type="SUBMIT" NAME="SUBMIT" VALUE="SUBMIT">
<input type="SUBMIT" NAME="SUBMIT" VALUE="CANCEL">
</form>
</center>
</body>
</html>'''
print 'Content-type: text/html\n'
print html