forked from algas/webprint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.py
More file actions
55 lines (46 loc) · 1.55 KB
/
web.py
File metadata and controls
55 lines (46 loc) · 1.55 KB
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
import os
import sys
from flask import Flask, request, render_template
import cups
import tempfile
from pprint import pformat,pprint
app = Flask(__name__)
@app.route('/ip')
def ip():
return '<center><h1>'+request.remote_addr+'</h1></center>'
@app.route('/', methods=['GET'])
def index():
return render_template('upload.html')
@app.route("/upload", methods=['POST'])
def upload():
conn = cups.Connection()
f = request.files['file'] # Refers to the element "name" attribute of the form
# print("Submitted file: "+f.filename)
with tempfile.NamedTemporaryFile() as fp:
f.save(fp.name)
# print("Saved file as: "+fp.name)
conn.printFile(app.config['printer_name'], fp.name, 'WebPrinter', {})
return render_template("alert.html", msg=f.filename+" sent successfully!")
@app.route('/printers', methods=['GET'])
def printers():
result = "<!DOCTYPE html><html><body><pre>"
con = cups.Connection()
result += pformat(con.getPrinters())
result += "</pre></body></html>"
return result
@app.route('/queues', methods=['GET'])
def queues():
result = "<pre>"
con = cups.Connection()
result += pformat(con.getJobs(which_jobs='all'))
result += "\n\n" + pformat(con.getJobAttributes(44))
result += "</pre>"
return result
if __name__ == '__main__':
debug = False
if (len(sys.argv) > 1):
port = int(sys.argv[1])
if (len(sys.argv) > 2):
debug = bool(sys.argv[2])
app.config['printer_name'] = cups.Connection().getDefault()
app.run(host='0.0.0.0', port=port, debug=debug)