]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
7e86f2f6 | 2 | * Job status CGI for CUPS. |
ef416fc2 | 3 | * |
7e86f2f6 MS |
4 | * Copyright 2007-2014 by Apple Inc. |
5 | * Copyright 1997-2006 by Easy Software Products. | |
ef416fc2 | 6 | * |
7e86f2f6 MS |
7 | * These coded instructions, statements, and computer programs are the |
8 | * property of Apple Inc. and are protected by Federal copyright | |
9 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
10 | * which should have been included with this file. If this file is | |
57b7b66b | 11 | * missing or damaged, see the license at "http://www.cups.org/". |
ef416fc2 | 12 | */ |
13 | ||
14 | /* | |
15 | * Include necessary headers... | |
16 | */ | |
17 | ||
18 | #include "cgi-private.h" | |
19 | ||
20 | ||
21 | /* | |
22 | * Local functions... | |
23 | */ | |
24 | ||
fa73b229 | 25 | static void do_job_op(http_t *http, int job_id, ipp_op_t op); |
ef416fc2 | 26 | |
27 | ||
28 | /* | |
29 | * 'main()' - Main entry for CGI. | |
30 | */ | |
31 | ||
32 | int /* O - Exit status */ | |
7e86f2f6 | 33 | main(void) |
ef416fc2 | 34 | { |
ef416fc2 | 35 | http_t *http; /* Connection to the server */ |
36 | const char *op; /* Operation name */ | |
fa73b229 | 37 | const char *job_id_var; /* Job ID form variable */ |
38 | int job_id; /* Job ID */ | |
39 | ||
ef416fc2 | 40 | |
41 | /* | |
42 | * Get any form variables... | |
43 | */ | |
44 | ||
45 | cgiInitialize(); | |
46 | ||
47 | /* | |
48 | * Set the web interface section... | |
49 | */ | |
50 | ||
51 | cgiSetVariable("SECTION", "jobs"); | |
ef55b745 | 52 | cgiSetVariable("REFRESH_PAGE", ""); |
ef416fc2 | 53 | |
ef416fc2 | 54 | /* |
55 | * Connect to the HTTP server... | |
56 | */ | |
57 | ||
58 | http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption()); | |
59 | ||
60 | /* | |
fa73b229 | 61 | * Get the job ID, if any... |
ef416fc2 | 62 | */ |
63 | ||
fa73b229 | 64 | if ((job_id_var = cgiGetVariable("JOB_ID")) != NULL) |
65 | job_id = atoi(job_id_var); | |
66 | else | |
67 | job_id = 0; | |
ef416fc2 | 68 | |
69 | /* | |
fa73b229 | 70 | * Do the operation... |
ef416fc2 | 71 | */ |
72 | ||
2e4ff8af | 73 | if ((op = cgiGetVariable("OP")) != NULL && job_id > 0 && cgiIsPOST()) |
ef416fc2 | 74 | { |
75 | /* | |
76 | * Do the operation... | |
77 | */ | |
78 | ||
79 | if (!strcmp(op, "cancel-job")) | |
fa73b229 | 80 | do_job_op(http, job_id, IPP_CANCEL_JOB); |
ef416fc2 | 81 | else if (!strcmp(op, "hold-job")) |
fa73b229 | 82 | do_job_op(http, job_id, IPP_HOLD_JOB); |
83 | else if (!strcmp(op, "move-job")) | |
84 | cgiMoveJobs(http, NULL, job_id); | |
ef416fc2 | 85 | else if (!strcmp(op, "release-job")) |
fa73b229 | 86 | do_job_op(http, job_id, IPP_RELEASE_JOB); |
ef416fc2 | 87 | else if (!strcmp(op, "restart-job")) |
fa73b229 | 88 | do_job_op(http, job_id, IPP_RESTART_JOB); |
ef416fc2 | 89 | else |
90 | { | |
91 | /* | |
92 | * Bad operation code... Display an error... | |
93 | */ | |
94 | ||
fa73b229 | 95 | cgiStartHTML(cgiText(_("Jobs"))); |
96 | cgiCopyTemplateLang("error-op.tmpl"); | |
97 | cgiEndHTML(); | |
ef416fc2 | 98 | } |
99 | } | |
100 | else | |
101 | { | |
102 | /* | |
103 | * Show a list of jobs... | |
104 | */ | |
105 | ||
fa73b229 | 106 | cgiStartHTML(cgiText(_("Jobs"))); |
ef416fc2 | 107 | cgiShowJobs(http, NULL); |
fa73b229 | 108 | cgiEndHTML(); |
ef416fc2 | 109 | } |
110 | ||
ef416fc2 | 111 | /* |
112 | * Close the HTTP server connection... | |
113 | */ | |
114 | ||
115 | httpClose(http); | |
ef416fc2 | 116 | |
117 | /* | |
118 | * Return with no errors... | |
119 | */ | |
120 | ||
121 | return (0); | |
122 | } | |
123 | ||
124 | ||
125 | /* | |
126 | * 'do_job_op()' - Do a job operation. | |
127 | */ | |
128 | ||
129 | static void | |
130 | do_job_op(http_t *http, /* I - HTTP connection */ | |
fa73b229 | 131 | int job_id, /* I - Job ID */ |
ef416fc2 | 132 | ipp_op_t op) /* I - Operation to perform */ |
133 | { | |
fa73b229 | 134 | ipp_t *request; /* IPP request */ |
ef416fc2 | 135 | char uri[HTTP_MAX_URI]; /* Job URI */ |
fa73b229 | 136 | const char *user; /* Username */ |
ef416fc2 | 137 | |
ef416fc2 | 138 | |
139 | /* | |
140 | * Build a job request, which requires the following | |
141 | * attributes: | |
142 | * | |
143 | * attributes-charset | |
144 | * attributes-natural-language | |
145 | * job-uri or printer-uri (purge-jobs) | |
146 | * requesting-user-name | |
147 | */ | |
148 | ||
fa73b229 | 149 | request = ippNewRequest(op); |
ef416fc2 | 150 | |
bd7854cb | 151 | snprintf(uri, sizeof(uri), "ipp://localhost/jobs/%d", job_id); |
152 | ||
ef416fc2 | 153 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", |
154 | NULL, uri); | |
155 | ||
fa73b229 | 156 | if ((user = getenv("REMOTE_USER")) == NULL) |
157 | user = "guest"; | |
158 | ||
159 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, | |
160 | "requesting-user-name", NULL, user); | |
ef416fc2 | 161 | |
162 | /* | |
163 | * Do the request and get back a response... | |
164 | */ | |
165 | ||
fa73b229 | 166 | ippDelete(cupsDoRequest(http, request, "/jobs")); |
ef416fc2 | 167 | |
f7deaa1a | 168 | if (cupsLastError() <= IPP_OK_CONFLICT && getenv("HTTP_REFERER")) |
169 | { | |
170 | /* | |
171 | * Redirect successful updates back to the parent page... | |
172 | */ | |
173 | ||
174 | char url[1024]; /* Encoded URL */ | |
175 | ||
176 | ||
5a9febac | 177 | strlcpy(url, "5;URL=", sizeof(url)); |
f7deaa1a | 178 | cgiFormEncode(url + 6, getenv("HTTP_REFERER"), sizeof(url) - 6); |
179 | cgiSetVariable("refresh_page", url); | |
180 | } | |
5bd77a73 MS |
181 | else if (cupsLastError() == IPP_NOT_AUTHORIZED) |
182 | { | |
183 | puts("Status: 401\n"); | |
184 | exit(0); | |
185 | } | |
f7deaa1a | 186 | |
fa73b229 | 187 | cgiStartHTML(cgiText(_("Jobs"))); |
ef416fc2 | 188 | |
fa73b229 | 189 | if (cupsLastError() > IPP_OK_CONFLICT) |
f3c17241 | 190 | cgiShowIPPError(_("Job operation failed")); |
ef416fc2 | 191 | else if (op == IPP_CANCEL_JOB) |
192 | cgiCopyTemplateLang("job-cancel.tmpl"); | |
193 | else if (op == IPP_HOLD_JOB) | |
194 | cgiCopyTemplateLang("job-hold.tmpl"); | |
195 | else if (op == IPP_RELEASE_JOB) | |
196 | cgiCopyTemplateLang("job-release.tmpl"); | |
197 | else if (op == IPP_RESTART_JOB) | |
198 | cgiCopyTemplateLang("job-restart.tmpl"); | |
fa73b229 | 199 | |
200 | cgiEndHTML(); | |
ef416fc2 | 201 | } |