-
Notifications
You must be signed in to change notification settings - Fork 6
/
query.php
47 lines (39 loc) · 1.62 KB
/
query.php
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
<?php
// PHP wrapper for running the web query API for printer setup tools
// http://www.linuxfoundation.org/en/OpenPrinting/Database/Query
// The output of the called program "query" should not be modified, to
// keep the web query API compatible to the former site.
// PHP Code for access statistics, logging, ... can be added though.
// To be compatible with the former query.cgi the line
// RewriteRule ^query.cgi/?$ query.php [L]
// needs to be added to .htaccess
if (isset($_GET['papps']) && $_GET['papps'] == "true") {
header("Content-Type: text/plain; name=query.txt; charset=UTF-8");
header("Content-Disposition: inline; filename=\"query.txt\"");
// Printer apps are stored in priority order in snap/printer-apps.txt
$papp_args = "";
foreach($_GET as $k => $v) {
$wrappedk = escapeshellarg(htmlspecialchars($k));
$wrappedv = escapeshellarg(htmlspecialchars($v));
$papp_args .= " " . $wrappedk . "=" . $wrappedv;
}
$querycmdline = "sudo /var/www/openprinting.org/openprinting/query.sh" . $papp_args;
passthru($querycmdline);
} else {
if ($_GET['format'] == "xml") {
header("Content-Type: text/xml; name=query.xml; charset=UTF-8");
header("Content-Disposition: inline; filename=\"query.xml\"");
} else {
header("Content-Type: text/plain; name=query.txt; charset=UTF-8");
header("Content-Disposition: inline; filename=\"query.txt\"");
}
$dir = getcwd();
$querycmdline = "/usr/bin/perl ./query";
foreach($_GET as $k => $v) {
$querycmdline .= " " . escapeshellarg($k) . "=" . escapeshellarg($v);
}
chdir('foomatic');
passthru($querycmdline);
chdir($dir);
}
?>