|
Lines 39-45
import subprocess
Link Here
|
| 39 |
|
39 |
|
| 40 |
from univention.lib.i18n import Translation |
40 |
from univention.lib.i18n import Translation |
| 41 |
|
41 |
|
| 42 |
from univention.management.console.modules import UMC_OptionTypeError, UMC_Error |
42 |
from univention.management.console.modules import UMC_Error |
| 43 |
from univention.management.console.modules.decorators import simple_response, sanitize |
43 |
from univention.management.console.modules.decorators import simple_response, sanitize |
| 44 |
from univention.management.console.modules.sanitizers import StringSanitizer |
44 |
from univention.management.console.modules.sanitizers import StringSanitizer |
| 45 |
from univention.management.console.log import MODULE |
45 |
from univention.management.console.log import MODULE |
|
Lines 85-91
class Instance(SchoolBaseModule):
Link Here
|
| 85 |
username = username.replace('/', '') |
85 |
username = username.replace('/', '') |
| 86 |
path = os.path.join(CUPSPDF_DIR, username, CUPSPDF_USERSUBDIR, printjob) |
86 |
path = os.path.join(CUPSPDF_DIR, username, CUPSPDF_USERSUBDIR, printjob) |
| 87 |
if not os.path.realpath(path).startswith(os.path.realpath(CUPSPDF_DIR)): |
87 |
if not os.path.realpath(path).startswith(os.path.realpath(CUPSPDF_DIR)): |
| 88 |
raise UMC_OptionTypeError('Invalid file') |
88 |
raise UMC_Error('Invalid file') |
| 89 |
return path |
89 |
return path |
| 90 |
|
90 |
|
| 91 |
def _get_all_username_variants(self, username): |
91 |
def _get_all_username_variants(self, username): |
|
Lines 164-170
class Instance(SchoolBaseModule):
Link Here
|
| 164 |
path = self._get_path(request.options['username'], request.options['printjob']) |
164 |
path = self._get_path(request.options['username'], request.options['printjob']) |
| 165 |
|
165 |
|
| 166 |
if not os.path.exists(path): |
166 |
if not os.path.exists(path): |
| 167 |
raise UMC_OptionTypeError('Invalid file') |
167 |
raise UMC_Error('Invalid file') |
| 168 |
|
168 |
|
| 169 |
with open(path) as fd: |
169 |
with open(path) as fd: |
| 170 |
self.finished(request.id, fd.read(), mimetype='application/pdf') |
170 |
self.finished(request.id, fd.read(), mimetype='application/pdf') |
|
Lines 217-229
class Instance(SchoolBaseModule):
Link Here
|
| 217 |
try: |
217 |
try: |
| 218 |
spoolhost, printer = printer.split('://', 1) |
218 |
spoolhost, printer = printer.split('://', 1) |
| 219 |
except ValueError: |
219 |
except ValueError: |
| 220 |
raise UMC_OptionTypeError('Invalid printer URI') |
220 |
raise UMC_Error('Invalid printer URI') |
| 221 |
|
221 |
|
| 222 |
if spoolhost == self.fqdn: |
222 |
if spoolhost == self.fqdn: |
| 223 |
spoolhost = None |
223 |
spoolhost = None |
| 224 |
|
224 |
|
| 225 |
if not os.path.exists(path): |
225 |
if not os.path.exists(path): |
| 226 |
raise UMC_Error('File %s doesnt exists' % path) |
226 |
raise UMC_Error(_('File %r could not be printed as it does not exists (anymore).') % (printjob,)) |
| 227 |
|
227 |
|
| 228 |
MODULE.info('Deleting print job %r' % (path,)) |
228 |
MODULE.info('Deleting print job %r' % (path,)) |
| 229 |
cmd = [ |
229 |
cmd = [ |
|
Lines 240-246
class Instance(SchoolBaseModule):
Link Here
|
| 240 |
path, |
240 |
path, |
| 241 |
] |
241 |
] |
| 242 |
if spoolhost: |
242 |
if spoolhost: |
| 243 |
cmd.extend([ |
243 |
cmd.extend([ |
| 244 |
# spool host |
244 |
# spool host |
| 245 |
'-H', spoolhost |
245 |
'-H', spoolhost |
| 246 |
]) |
246 |
]) |
|
Lines 249-255
class Instance(SchoolBaseModule):
Link Here
|
| 249 |
lpr = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
249 |
lpr = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 250 |
(stdout, stderr) = lpr.communicate() |
250 |
(stdout, stderr) = lpr.communicate() |
| 251 |
if lpr.returncode != 0: |
251 |
if lpr.returncode != 0: |
| 252 |
raise UMC_Error(_('Failed to print on %s: %s' % (printer, stderr))) |
252 |
raise UMC_Error(_('Failed to print on %s: %s') % (printer, stderr)) |
| 253 |
|
253 |
|
| 254 |
return True |
254 |
return True |
| 255 |
|
255 |
|