2 * Administration CGI for CUPS.
4 * Copyright 2007-2015 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products.
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
11 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
18 #include "cgi-private.h"
19 #include <cups/http-private.h>
20 #include <cups/ppd-private.h>
21 #include <cups/adminutil.h>
34 static int current_device
= 0; /* Current device shown */
41 static void choose_device_cb(const char *device_class
, const char *device_id
, const char *device_info
, const char *device_make_and_model
, const char *device_uri
, const char *device_location
, const char *title
);
42 static void do_add_rss_subscription(http_t
*http
);
43 static void do_am_class(http_t
*http
, int modify
);
44 static void do_am_printer(http_t
*http
, int modify
);
45 static void do_cancel_subscription(http_t
*http
);
46 static void do_config_server(http_t
*http
);
47 static void do_delete_class(http_t
*http
);
48 static void do_delete_printer(http_t
*http
);
49 static void do_export(http_t
*http
);
50 static void do_list_printers(http_t
*http
);
51 static void do_menu(http_t
*http
);
52 static void do_set_allowed_users(http_t
*http
);
53 static void do_set_default(http_t
*http
);
54 static void do_set_options(http_t
*http
, int is_class
);
55 static void do_set_sharing(http_t
*http
);
56 static char *get_option_value(ppd_file_t
*ppd
, const char *name
,
57 char *buffer
, size_t bufsize
);
58 static double get_points(double number
, const char *uval
);
59 static char *get_printer_ppd(const char *uri
, char *buffer
, size_t bufsize
);
63 * 'main()' - Main entry for CGI.
66 int /* O - Exit status */
69 http_t
*http
; /* Connection to the server */
70 const char *op
; /* Operation name */
74 * Connect to the HTTP server...
77 fputs("DEBUG: admin.cgi started...\n", stderr
);
79 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
83 perror("ERROR: Unable to connect to cupsd");
84 fprintf(stderr
, "DEBUG: cupsServer()=\"%s\"\n",
85 cupsServer() ? cupsServer() : "(null)");
86 fprintf(stderr
, "DEBUG: ippPort()=%d\n", ippPort());
87 fprintf(stderr
, "DEBUG: cupsEncryption()=%d\n", cupsEncryption());
91 fprintf(stderr
, "DEBUG: http=%p\n", http
);
94 * Set the web interface section...
97 cgiSetVariable("SECTION", "admin");
98 cgiSetVariable("REFRESH_PAGE", "");
101 * See if we have form data...
104 if (!cgiInitialize() || !cgiGetVariable("OP"))
107 * Nope, send the administration menu...
110 fputs("DEBUG: No form data, showing main menu...\n", stderr
);
114 else if ((op
= cgiGetVariable("OP")) != NULL
&& cgiIsPOST())
117 * Do the operation...
120 fprintf(stderr
, "DEBUG: op=\"%s\"...\n", op
);
124 const char *printer
= getenv("PRINTER_NAME"),
125 /* Printer or class name */
126 *server_port
= getenv("SERVER_PORT");
127 /* Port number string */
128 int port
= atoi(server_port
? server_port
: "0");
130 char uri
[1024]; /* URL */
133 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
),
134 getenv("HTTPS") ? "https" : "http", NULL
,
135 getenv("SERVER_NAME"), port
, "/%s/%s",
136 cgiGetVariable("IS_CLASS") ? "classes" : "printers",
139 httpAssembleURI(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
),
140 getenv("HTTPS") ? "https" : "http", NULL
,
141 getenv("SERVER_NAME"), port
, "/admin");
143 printf("Location: %s\n\n", uri
);
145 else if (!strcmp(op
, "set-allowed-users"))
146 do_set_allowed_users(http
);
147 else if (!strcmp(op
, "set-as-default"))
148 do_set_default(http
);
149 else if (!strcmp(op
, "set-sharing"))
150 do_set_sharing(http
);
151 else if (!strcmp(op
, "find-new-printers") ||
152 !strcmp(op
, "list-available-printers"))
153 do_list_printers(http
);
154 else if (!strcmp(op
, "add-class"))
155 do_am_class(http
, 0);
156 else if (!strcmp(op
, "add-printer"))
157 do_am_printer(http
, 0);
158 else if (!strcmp(op
, "modify-class"))
159 do_am_class(http
, 1);
160 else if (!strcmp(op
, "modify-printer"))
161 do_am_printer(http
, 1);
162 else if (!strcmp(op
, "delete-class"))
163 do_delete_class(http
);
164 else if (!strcmp(op
, "delete-printer"))
165 do_delete_printer(http
);
166 else if (!strcmp(op
, "set-class-options"))
167 do_set_options(http
, 1);
168 else if (!strcmp(op
, "set-printer-options"))
169 do_set_options(http
, 0);
170 else if (!strcmp(op
, "config-server"))
171 do_config_server(http
);
172 else if (!strcmp(op
, "export-samba"))
174 else if (!strcmp(op
, "add-rss-subscription"))
175 do_add_rss_subscription(http
);
176 else if (!strcmp(op
, "cancel-subscription"))
177 do_cancel_subscription(http
);
181 * Bad operation code - display an error...
184 cgiStartHTML(cgiText(_("Administration")));
185 cgiCopyTemplateLang("error-op.tmpl");
189 else if (op
&& !strcmp(op
, "redirect"))
191 const char *url
; /* Redirection URL... */
192 char prefix
[1024]; /* URL prefix */
196 snprintf(prefix
, sizeof(prefix
), "https://%s:%s",
197 getenv("SERVER_NAME"), getenv("SERVER_PORT"));
199 snprintf(prefix
, sizeof(prefix
), "http://%s:%s",
200 getenv("SERVER_NAME"), getenv("SERVER_PORT"));
202 fprintf(stderr
, "DEBUG: redirecting with prefix %s!\n", prefix
);
204 if ((url
= cgiGetVariable("URL")) != NULL
)
206 char encoded
[1024], /* Encoded URL string */
207 *ptr
; /* Pointer into encoded string */
214 for (; *url
&& ptr
< (encoded
+ sizeof(encoded
) - 4); url
++)
216 if (strchr("%@&+ <>#=", *url
) || *url
< ' ' || *url
& 128)
219 * Percent-encode this character; safe because we have at least 4
220 * bytes left in the array...
223 sprintf(ptr
, "%%%02X", *url
& 255);
235 * URL was too long, just redirect to the admin page...
238 printf("Location: %s/admin\n\n", prefix
);
243 * URL is OK, redirect there...
246 printf("Location: %s%s\n\n", prefix
, encoded
);
250 printf("Location: %s/admin\n\n", prefix
);
255 * Form data but no operation code - display an error...
258 cgiStartHTML(cgiText(_("Administration")));
259 cgiCopyTemplateLang("error-op.tmpl");
264 * Close the HTTP server connection...
270 * Return with no errors...
278 * 'choose_device_cb()' - Add a device to the device selection page.
283 const char *device_class
, /* I - Class */
284 const char *device_id
, /* I - 1284 device ID */
285 const char *device_info
, /* I - Description */
286 const char *device_make_and_model
, /* I - Make and model */
287 const char *device_uri
, /* I - Device URI */
288 const char *device_location
, /* I - Location */
289 const char *title
) /* I - Page title */
292 * For modern browsers, start a multi-part page so we can show that something
293 * is happening. Non-modern browsers just get everything at the end...
296 if (current_device
== 0 && cgiSupportsMultipart())
300 cgiCopyTemplateLang("choose-device.tmpl");
307 * Add the device to the array...
310 cgiSetArray("device_class", current_device
, device_class
);
311 cgiSetArray("device_id", current_device
, device_id
);
312 cgiSetArray("device_info", current_device
, device_info
);
313 cgiSetArray("device_make_and_model", current_device
, device_make_and_model
);
314 cgiSetArray("device_uri", current_device
, device_uri
);
315 cgiSetArray("device_location", current_device
, device_location
);
322 * 'do_add_rss_subscription()' - Add a RSS subscription.
326 do_add_rss_subscription(http_t
*http
) /* I - HTTP connection */
328 ipp_t
*request
, /* IPP request data */
329 *response
; /* IPP response data */
330 char rss_uri
[1024]; /* RSS notify-recipient URI */
331 int num_events
; /* Number of events */
332 const char *events
[12], /* Subscribed events */
333 *subscription_name
, /* Subscription name */
334 *printer_uri
, /* Printer URI */
335 *ptr
, /* Pointer into name */
336 *user
; /* Username */
337 int max_events
; /* Maximum number of events */
341 * See if we have all of the required information...
344 subscription_name
= cgiGetVariable("SUBSCRIPTION_NAME");
345 printer_uri
= cgiGetVariable("PRINTER_URI");
348 if (cgiGetVariable("EVENT_JOB_CREATED"))
349 events
[num_events
++] = "job-created";
350 if (cgiGetVariable("EVENT_JOB_COMPLETED"))
351 events
[num_events
++] = "job-completed";
352 if (cgiGetVariable("EVENT_JOB_STOPPED"))
353 events
[num_events
++] = "job-stopped";
354 if (cgiGetVariable("EVENT_JOB_CONFIG_CHANGED"))
355 events
[num_events
++] = "job-config-changed";
356 if (cgiGetVariable("EVENT_PRINTER_STOPPED"))
357 events
[num_events
++] = "printer-stopped";
358 if (cgiGetVariable("EVENT_PRINTER_ADDED"))
359 events
[num_events
++] = "printer-added";
360 if (cgiGetVariable("EVENT_PRINTER_MODIFIED"))
361 events
[num_events
++] = "printer-modified";
362 if (cgiGetVariable("EVENT_PRINTER_DELETED"))
363 events
[num_events
++] = "printer-deleted";
364 if (cgiGetVariable("EVENT_SERVER_STARTED"))
365 events
[num_events
++] = "server-started";
366 if (cgiGetVariable("EVENT_SERVER_STOPPED"))
367 events
[num_events
++] = "server-stopped";
368 if (cgiGetVariable("EVENT_SERVER_RESTARTED"))
369 events
[num_events
++] = "server-restarted";
370 if (cgiGetVariable("EVENT_SERVER_AUDIT"))
371 events
[num_events
++] = "server-audit";
373 if ((ptr
= cgiGetVariable("MAX_EVENTS")) != NULL
)
374 max_events
= atoi(ptr
);
378 if (!subscription_name
|| !printer_uri
|| !num_events
||
379 max_events
<= 0 || max_events
> 9999)
382 * Don't have everything we need, so get the available printers
383 * and classes and (re)show the add page...
386 if (cgiGetVariable("EVENT_JOB_CREATED"))
387 cgiSetVariable("EVENT_JOB_CREATED", "CHECKED");
388 if (cgiGetVariable("EVENT_JOB_COMPLETED"))
389 cgiSetVariable("EVENT_JOB_COMPLETED", "CHECKED");
390 if (cgiGetVariable("EVENT_JOB_STOPPED"))
391 cgiSetVariable("EVENT_JOB_STOPPED", "CHECKED");
392 if (cgiGetVariable("EVENT_JOB_CONFIG_CHANGED"))
393 cgiSetVariable("EVENT_JOB_CONFIG_CHANGED", "CHECKED");
394 if (cgiGetVariable("EVENT_PRINTER_STOPPED"))
395 cgiSetVariable("EVENT_PRINTER_STOPPED", "CHECKED");
396 if (cgiGetVariable("EVENT_PRINTER_ADDED"))
397 cgiSetVariable("EVENT_PRINTER_ADDED", "CHECKED");
398 if (cgiGetVariable("EVENT_PRINTER_MODIFIED"))
399 cgiSetVariable("EVENT_PRINTER_MODIFIED", "CHECKED");
400 if (cgiGetVariable("EVENT_PRINTER_DELETED"))
401 cgiSetVariable("EVENT_PRINTER_DELETED", "CHECKED");
402 if (cgiGetVariable("EVENT_SERVER_STARTED"))
403 cgiSetVariable("EVENT_SERVER_STARTED", "CHECKED");
404 if (cgiGetVariable("EVENT_SERVER_STOPPED"))
405 cgiSetVariable("EVENT_SERVER_STOPPED", "CHECKED");
406 if (cgiGetVariable("EVENT_SERVER_RESTARTED"))
407 cgiSetVariable("EVENT_SERVER_RESTARTED", "CHECKED");
408 if (cgiGetVariable("EVENT_SERVER_AUDIT"))
409 cgiSetVariable("EVENT_SERVER_AUDIT", "CHECKED");
411 request
= ippNewRequest(CUPS_GET_PRINTERS
);
412 response
= cupsDoRequest(http
, request
, "/");
414 cgiSetIPPVars(response
, NULL
, NULL
, NULL
, 0);
418 cgiStartHTML(cgiText(_("Add RSS Subscription")));
420 cgiCopyTemplateLang("add-rss-subscription.tmpl");
427 * Make sure we have a username...
430 if ((user
= getenv("REMOTE_USER")) == NULL
)
432 puts("Status: 401\n");
437 * Validate the subscription name...
440 for (ptr
= subscription_name
; *ptr
; ptr
++)
441 if ((*ptr
>= 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' ||
442 *ptr
== '?' || *ptr
== '#')
447 cgiSetVariable("ERROR",
448 cgiText(_("The subscription name may not "
449 "contain spaces, slashes (/), question marks (?), "
450 "or the pound sign (#).")));
451 cgiStartHTML(_("Add RSS Subscription"));
452 cgiCopyTemplateLang("error.tmpl");
458 * Add the subscription...
461 ptr
= subscription_name
+ strlen(subscription_name
) - 4;
462 if (ptr
< subscription_name
|| strcmp(ptr
, ".rss"))
463 httpAssembleURIf(HTTP_URI_CODING_ALL
, rss_uri
, sizeof(rss_uri
), "rss",
464 NULL
, NULL
, 0, "/%s.rss?max_events=%d", subscription_name
,
467 httpAssembleURIf(HTTP_URI_CODING_ALL
, rss_uri
, sizeof(rss_uri
), "rss",
468 NULL
, NULL
, 0, "/%s?max_events=%d", subscription_name
,
471 request
= ippNewRequest(IPP_CREATE_PRINTER_SUBSCRIPTION
);
473 if (!_cups_strcasecmp(printer_uri
, "#ALL#"))
474 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
475 NULL
, "ipp://localhost/");
477 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
480 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
483 ippAddString(request
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_URI
,
484 "notify-recipient-uri", NULL
, rss_uri
);
485 ippAddStrings(request
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_KEYWORD
, "notify-events",
486 num_events
, NULL
, events
);
487 ippAddInteger(request
, IPP_TAG_SUBSCRIPTION
, IPP_TAG_INTEGER
,
488 "notify-lease-duration", 0);
490 ippDelete(cupsDoRequest(http
, request
, "/"));
492 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
494 puts("Status: 401\n");
497 else if (cupsLastError() > IPP_OK_CONFLICT
)
499 cgiStartHTML(_("Add RSS Subscription"));
500 cgiShowIPPError(_("Unable to add RSS subscription"));
505 * Redirect successful updates back to the admin page...
508 cgiSetVariable("refresh_page", "5;URL=/admin");
509 cgiStartHTML(_("Add RSS Subscription"));
510 cgiCopyTemplateLang("subscription-added.tmpl");
518 * 'do_am_class()' - Add or modify a class.
522 do_am_class(http_t
*http
, /* I - HTTP connection */
523 int modify
) /* I - Modify the printer? */
525 int i
, j
; /* Looping vars */
526 int element
; /* Element number */
527 int num_printers
; /* Number of printers */
528 ipp_t
*request
, /* IPP request */
529 *response
; /* IPP response */
530 ipp_attribute_t
*attr
; /* member-uris attribute */
531 char uri
[HTTP_MAX_URI
]; /* Device or printer URI */
532 const char *name
, /* Pointer to class name */
533 *op
, /* Operation name */
534 *ptr
; /* Pointer to CGI variable */
535 const char *title
; /* Title of page */
536 static const char * const pattrs
[] = /* Requested printer attributes */
544 title
= cgiText(modify
? _("Modify Class") : _("Add Class"));
545 op
= cgiGetVariable("OP");
546 name
= cgiGetVariable("PRINTER_NAME");
548 if (cgiGetVariable("PRINTER_LOCATION") == NULL
)
551 * Build a CUPS_GET_PRINTERS request, which requires the
552 * following attributes:
555 * attributes-natural-language
558 request
= ippNewRequest(CUPS_GET_PRINTERS
);
560 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_ENUM
, "printer-type",
562 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_ENUM
, "printer-type-mask",
563 CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
566 * Do the request and get back a response...
571 cgiSetVariable("OP", op
);
573 cgiSetVariable("PRINTER_NAME", name
);
575 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
578 * Create MEMBER_URIS and MEMBER_NAMES arrays...
581 for (element
= 0, attr
= response
->attrs
;
584 if (attr
->name
&& !strcmp(attr
->name
, "printer-uri-supported"))
586 if ((ptr
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
&&
587 (!name
|| _cups_strcasecmp(name
, ptr
+ 1)))
590 * Don't show the current class...
593 cgiSetArray("MEMBER_URIS", element
, attr
->values
[0].string
.text
);
598 for (element
= 0, attr
= response
->attrs
;
601 if (attr
->name
&& !strcmp(attr
->name
, "printer-name"))
603 if (!name
|| _cups_strcasecmp(name
, attr
->values
[0].string
.text
))
606 * Don't show the current class...
609 cgiSetArray("MEMBER_NAMES", element
, attr
->values
[0].string
.text
);
614 num_printers
= cgiGetSize("MEMBER_URIS");
624 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
625 * following attributes:
628 * attributes-natural-language
632 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
634 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
635 "localhost", 0, "/classes/%s", name
);
636 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
639 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
640 "requested-attributes",
641 (int)(sizeof(pattrs
) / sizeof(pattrs
[0])),
645 * Do the request and get back a response...
648 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
650 if ((attr
= ippFindAttribute(response
, "member-names",
651 IPP_TAG_NAME
)) != NULL
)
654 * Mark any current members in the class...
657 for (j
= 0; j
< num_printers
; j
++)
658 cgiSetArray("MEMBER_SELECTED", j
, "");
660 for (i
= 0; i
< attr
->num_values
; i
++)
662 for (j
= 0; j
< num_printers
; j
++)
664 if (!_cups_strcasecmp(attr
->values
[i
].string
.text
,
665 cgiGetArray("MEMBER_NAMES", j
)))
667 cgiSetArray("MEMBER_SELECTED", j
, "SELECTED");
674 if ((attr
= ippFindAttribute(response
, "printer-info",
675 IPP_TAG_TEXT
)) != NULL
)
676 cgiSetVariable("PRINTER_INFO", attr
->values
[0].string
.text
);
678 if ((attr
= ippFindAttribute(response
, "printer-location",
679 IPP_TAG_TEXT
)) != NULL
)
680 cgiSetVariable("PRINTER_LOCATION", attr
->values
[0].string
.text
);
686 * Update the location and description of an existing printer...
690 cgiCopyTemplateLang("modify-class.tmpl");
695 * Get the name, location, and description for a new printer...
699 cgiCopyTemplateLang("add-class.tmpl");
710 cgiSetVariable("ERROR", cgiText(_("Missing form variable")));
711 cgiCopyTemplateLang("error.tmpl");
716 for (ptr
= name
; *ptr
; ptr
++)
717 if ((*ptr
>= 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
720 if (*ptr
|| ptr
== name
|| strlen(name
) > 127)
722 cgiSetVariable("ERROR",
723 cgiText(_("The class name may only contain up to "
724 "127 printable characters and may not "
725 "contain spaces, slashes (/), or the "
726 "pound sign (#).")));
728 cgiCopyTemplateLang("error.tmpl");
734 * Build a CUPS_ADD_CLASS request, which requires the following
738 * attributes-natural-language
742 * printer-is-accepting-jobs
747 request
= ippNewRequest(CUPS_ADD_CLASS
);
749 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
750 "localhost", 0, "/classes/%s", name
);
751 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
754 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
755 NULL
, cgiGetVariable("PRINTER_LOCATION"));
757 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
758 NULL
, cgiGetVariable("PRINTER_INFO"));
760 ippAddBoolean(request
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", 1);
762 ippAddInteger(request
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
765 if ((num_printers
= cgiGetSize("MEMBER_URIS")) > 0)
767 attr
= ippAddStrings(request
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "member-uris",
768 num_printers
, NULL
, NULL
);
769 for (i
= 0; i
< num_printers
; i
++)
770 attr
->values
[i
].string
.text
= _cupsStrAlloc(cgiGetArray("MEMBER_URIS", i
));
774 * Do the request and get back a response...
777 ippDelete(cupsDoRequest(http
, request
, "/admin/"));
779 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
781 puts("Status: 401\n");
784 else if (cupsLastError() > IPP_OK_CONFLICT
)
787 cgiShowIPPError(modify
? _("Unable to modify class") :
788 _("Unable to add class"));
793 * Redirect successful updates back to the class page...
796 char refresh
[1024]; /* Refresh URL */
798 cgiFormEncode(uri
, name
, sizeof(uri
));
799 snprintf(refresh
, sizeof(refresh
), "5;URL=/admin/?OP=redirect&URL=/classes/%s",
801 cgiSetVariable("refresh_page", refresh
);
806 cgiCopyTemplateLang("class-modified.tmpl");
808 cgiCopyTemplateLang("class-added.tmpl");
816 * 'do_am_printer()' - Add or modify a printer.
820 do_am_printer(http_t
*http
, /* I - HTTP connection */
821 int modify
) /* I - Modify the printer? */
823 int i
; /* Looping var */
824 ipp_attribute_t
*attr
; /* Current attribute */
825 ipp_t
*request
, /* IPP request */
826 *response
, /* IPP response */
827 *oldinfo
; /* Old printer information */
828 const cgi_file_t
*file
; /* Uploaded file, if any */
829 const char *var
; /* CGI variable */
830 char uri
[HTTP_MAX_URI
], /* Device or printer URI */
831 *uriptr
, /* Pointer into URI */
832 evefile
[1024] = ""; /* IPP Everywhere PPD file */
833 int maxrate
; /* Maximum baud rate */
834 char baudrate
[255]; /* Baud rate string */
835 const char *name
, /* Pointer to class name */
836 *ptr
; /* Pointer to CGI variable */
837 const char *title
; /* Title of page */
838 static int baudrates
[] = /* Baud rates */
853 ptr
= cgiGetVariable("DEVICE_URI");
854 fprintf(stderr
, "DEBUG: do_am_printer: DEVICE_URI=\"%s\"\n",
855 ptr
? ptr
: "(null)");
857 title
= cgiText(modify
? _("Modify Printer") : _("Add Printer"));
862 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
863 * following attributes:
866 * attributes-natural-language
870 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
872 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
873 "localhost", 0, "/printers/%s",
874 cgiGetVariable("PRINTER_NAME"));
875 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
879 * Do the request and get back a response...
882 oldinfo
= cupsDoRequest(http
, request
, "/");
891 fprintf(stderr
, "DEBUG: file->tempfile=%s\n", file
->tempfile
);
892 fprintf(stderr
, "DEBUG: file->name=%s\n", file
->name
);
893 fprintf(stderr
, "DEBUG: file->filename=%s\n", file
->filename
);
894 fprintf(stderr
, "DEBUG: file->mimetype=%s\n", file
->mimetype
);
897 if ((name
= cgiGetVariable("PRINTER_NAME")) != NULL
)
899 for (ptr
= name
; *ptr
; ptr
++)
900 if ((*ptr
>= 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' || *ptr
== '#')
903 if (*ptr
|| ptr
== name
|| strlen(name
) > 127)
905 cgiSetVariable("ERROR",
906 cgiText(_("The printer name may only contain up to "
907 "127 printable characters and may not "
908 "contain spaces, slashes (/), or the "
909 "pound sign (#).")));
911 cgiCopyTemplateLang("error.tmpl");
917 if ((var
= cgiGetVariable("DEVICE_URI")) != NULL
)
919 if ((uriptr
= strrchr(var
, '|')) != NULL
)
922 * Extract make and make/model from device URI string...
925 char make
[1024], /* Make string */
926 *makeptr
; /* Pointer into make */
931 strlcpy(make
, uriptr
, sizeof(make
));
933 if ((makeptr
= strchr(make
, ' ')) != NULL
)
935 else if ((makeptr
= strchr(make
, '-')) != NULL
)
937 else if (!_cups_strncasecmp(make
, "laserjet", 8) ||
938 !_cups_strncasecmp(make
, "deskjet", 7) ||
939 !_cups_strncasecmp(make
, "designjet", 9))
940 strlcpy(make
, "HP", sizeof(make
));
941 else if (!_cups_strncasecmp(make
, "phaser", 6))
942 strlcpy(make
, "Xerox", sizeof(make
));
943 else if (!_cups_strncasecmp(make
, "stylus", 6))
944 strlcpy(make
, "Epson", sizeof(make
));
946 strlcpy(make
, "Generic", sizeof(make
));
948 if (!cgiGetVariable("CURRENT_MAKE"))
949 cgiSetVariable("CURRENT_MAKE", make
);
951 if (!cgiGetVariable("CURRENT_MAKE_AND_MODEL"))
952 cgiSetVariable("CURRENT_MAKE_AND_MODEL", uriptr
);
956 char template[128], /* Template name */
957 *tptr
; /* Pointer into template name */
959 cgiSetVariable("PRINTER_INFO", uriptr
);
961 for (tptr
= template;
962 tptr
< (template + sizeof(template) - 1) && *uriptr
;
964 if (isalnum(*uriptr
& 255) || *uriptr
== '_' || *uriptr
== '-' ||
967 else if ((*uriptr
== ' ' || *uriptr
== '/') && tptr
> template &&
970 else if (*uriptr
== '?' || *uriptr
== '(')
975 cgiSetVariable("TEMPLATE_NAME", template);
983 * Look for devices so the user can pick something...
986 if ((attr
= ippFindAttribute(oldinfo
, "device-uri", IPP_TAG_URI
)) != NULL
)
988 strlcpy(uri
, attr
->values
[0].string
.text
, sizeof(uri
));
989 if ((uriptr
= strchr(uri
, ':')) != NULL
&& strncmp(uriptr
, "://", 3) == 0)
992 cgiSetVariable("CURRENT_DEVICE_URI", attr
->values
[0].string
.text
);
993 cgiSetVariable("CURRENT_DEVICE_SCHEME", uri
);
997 * Scan for devices for up to 30 seconds...
1000 fputs("DEBUG: Getting list of devices...\n", stderr
);
1003 if (cupsGetDevices(http
, 5, CUPS_INCLUDE_ALL
, CUPS_EXCLUDE_NONE
,
1004 (cups_device_cb_t
)choose_device_cb
,
1005 (void *)title
) == IPP_OK
)
1007 fputs("DEBUG: Got device list!\n", stderr
);
1009 if (cgiSupportsMultipart())
1010 cgiStartMultipart();
1012 cgiSetVariable("CUPS_GET_DEVICES_DONE", "1");
1013 cgiStartHTML(title
);
1014 cgiCopyTemplateLang("choose-device.tmpl");
1017 if (cgiSupportsMultipart())
1023 "ERROR: CUPS-Get-Devices request failed with status %x: %s\n",
1024 cupsLastError(), cupsLastErrorString());
1025 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
1027 puts("Status: 401\n");
1032 cgiStartHTML(title
);
1033 cgiShowIPPError(modify
? _("Unable to modify printer") :
1034 _("Unable to add printer"));
1040 else if (!strchr(var
, '/') ||
1041 (!strncmp(var
, "lpd://", 6) && !strchr(var
+ 6, '/')))
1043 if ((attr
= ippFindAttribute(oldinfo
, "device-uri", IPP_TAG_URI
)) != NULL
)
1046 * Set the current device URI for the form to the old one...
1049 if (strncmp(attr
->values
[0].string
.text
, var
, strlen(var
)) == 0)
1050 cgiSetVariable("CURRENT_DEVICE_URI", attr
->values
[0].string
.text
);
1054 * User needs to set the full URI...
1057 cgiStartHTML(title
);
1058 cgiCopyTemplateLang("choose-uri.tmpl");
1061 else if (!strncmp(var
, "serial:", 7) && !cgiGetVariable("BAUDRATE"))
1064 * Need baud rate, parity, etc.
1067 if ((var
= strchr(var
, '?')) != NULL
&&
1068 strncmp(var
, "?baud=", 6) == 0)
1069 maxrate
= atoi(var
+ 6);
1073 for (i
= 0; i
< 10; i
++)
1074 if (baudrates
[i
] > maxrate
)
1078 sprintf(baudrate
, "%d", baudrates
[i
]);
1079 cgiSetArray("BAUDRATES", i
, baudrate
);
1082 cgiStartHTML(title
);
1083 cgiCopyTemplateLang("choose-serial.tmpl");
1086 else if (!name
|| !cgiGetVariable("PRINTER_LOCATION"))
1088 cgiStartHTML(title
);
1093 * Update the location and description of an existing printer...
1098 if ((attr
= ippFindAttribute(oldinfo
, "printer-info",
1099 IPP_TAG_TEXT
)) != NULL
)
1100 cgiSetVariable("PRINTER_INFO", attr
->values
[0].string
.text
);
1102 if ((attr
= ippFindAttribute(oldinfo
, "printer-location",
1103 IPP_TAG_TEXT
)) != NULL
)
1104 cgiSetVariable("PRINTER_LOCATION", attr
->values
[0].string
.text
);
1106 if ((attr
= ippFindAttribute(oldinfo
, "printer-is-shared",
1107 IPP_TAG_BOOLEAN
)) != NULL
)
1108 cgiSetVariable("PRINTER_IS_SHARED",
1109 attr
->values
[0].boolean
? "1" : "0");
1112 cgiCopyTemplateLang("modify-printer.tmpl");
1117 * Get the name, location, and description for a new printer...
1121 if (!strncmp(var
, "usb:", 4))
1122 cgiSetVariable("printer_is_shared", "1");
1124 #endif /* __APPLE__ */
1125 cgiSetVariable("printer_is_shared", "0");
1127 cgiCopyTemplateLang("add-printer.tmpl");
1138 (!cgiGetVariable("PPD_NAME") || cgiGetVariable("SELECT_MAKE")))
1140 if (modify
&& !cgiGetVariable("SELECT_MAKE"))
1143 * Get the PPD file...
1146 int fd
; /* PPD file */
1147 char filename
[1024]; /* PPD filename */
1148 ppd_file_t
*ppd
; /* PPD information */
1149 char buffer
[1024]; /* Buffer */
1150 ssize_t bytes
; /* Number of bytes */
1151 http_status_t get_status
; /* Status of GET */
1154 /* TODO: Use cupsGetFile() API... */
1155 snprintf(uri
, sizeof(uri
), "/printers/%s.ppd", name
);
1157 if (httpGet(http
, uri
))
1160 while ((get_status
= httpUpdate(http
)) == HTTP_CONTINUE
);
1162 if (get_status
!= HTTP_OK
)
1166 fprintf(stderr
, "ERROR: Unable to get PPD file %s: %d - %s\n",
1167 uri
, get_status
, httpStatus(get_status
));
1169 else if ((fd
= cupsTempFd(filename
, sizeof(filename
))) >= 0)
1171 while ((bytes
= httpRead2(http
, buffer
, sizeof(buffer
))) > 0)
1172 write(fd
, buffer
, (size_t)bytes
);
1176 if ((ppd
= ppdOpenFile(filename
)) != NULL
)
1178 if (ppd
->manufacturer
)
1179 cgiSetVariable("CURRENT_MAKE", ppd
->manufacturer
);
1182 cgiSetVariable("CURRENT_MAKE_AND_MODEL", ppd
->nickname
);
1189 int linenum
; /* Line number */
1191 fprintf(stderr
, "ERROR: Unable to open PPD file %s: %s\n",
1192 filename
, ppdErrorString(ppdLastError(&linenum
)));
1200 "ERROR: Unable to create temporary file for PPD file: %s\n",
1206 * Build a CUPS_GET_PPDS request, which requires the following
1209 * attributes-charset
1210 * attributes-natural-language
1214 request
= ippNewRequest(CUPS_GET_PPDS
);
1216 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
1217 NULL
, "ipp://localhost/printers/");
1219 if ((var
= cgiGetVariable("PPD_MAKE")) == NULL
)
1220 var
= cgiGetVariable("CURRENT_MAKE");
1221 if (var
&& !cgiGetVariable("SELECT_MAKE"))
1223 const char *make_model
; /* Make and model */
1226 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
1227 "ppd-make", NULL
, var
);
1229 if ((make_model
= cgiGetVariable("CURRENT_MAKE_AND_MODEL")) != NULL
)
1230 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_TEXT
,
1231 "ppd-make-and-model", NULL
, make_model
);
1234 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1235 "requested-attributes", NULL
, "ppd-make");
1238 * Do the request and get back a response...
1241 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1244 * Got the list of PPDs, see if the user has selected a make...
1247 if (cgiSetIPPVars(response
, NULL
, NULL
, NULL
, 0) == 0 && !modify
)
1250 * No PPD files with this make, try again with all makes...
1253 ippDelete(response
);
1255 request
= ippNewRequest(CUPS_GET_PPDS
);
1257 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
1258 NULL
, "ipp://localhost/printers/");
1260 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1261 "requested-attributes", NULL
, "ppd-make");
1263 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1264 cgiSetIPPVars(response
, NULL
, NULL
, NULL
, 0);
1266 cgiStartHTML(title
);
1267 cgiCopyTemplateLang("choose-make.tmpl");
1270 else if (!var
|| cgiGetVariable("SELECT_MAKE"))
1272 cgiStartHTML(title
);
1273 cgiCopyTemplateLang("choose-make.tmpl");
1279 * Let the user choose a model...
1282 cgiStartHTML(title
);
1283 if (!cgiGetVariable("PPD_MAKE"))
1284 cgiSetVariable("PPD_MAKE", cgiGetVariable("CURRENT_MAKE"));
1286 cgiSetVariable("CURRENT_MAKE_AND_MODEL",
1287 cgiGetArray("PPD_MAKE_AND_MODEL", 0));
1288 cgiCopyTemplateLang("choose-model.tmpl");
1292 ippDelete(response
);
1296 cgiStartHTML(title
);
1297 cgiShowIPPError(_("Unable to get list of printer drivers"));
1298 cgiCopyTemplateLang("error.tmpl");
1305 * Build a CUPS_ADD_PRINTER request, which requires the following
1308 * attributes-charset
1309 * attributes-natural-language
1315 * printer-is-accepting-jobs
1320 request
= ippNewRequest(CUPS_ADD_PRINTER
);
1322 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
1323 "localhost", 0, "/printers/%s",
1324 cgiGetVariable("PRINTER_NAME"));
1325 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
1330 var
= cgiGetVariable("PPD_NAME");
1331 if (!strcmp(var
, "everywhere"))
1332 get_printer_ppd(cgiGetVariable("DEVICE_URI"), evefile
, sizeof(evefile
));
1333 else if (strcmp(var
, "__no_change__"))
1334 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "ppd-name",
1338 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location",
1339 NULL
, cgiGetVariable("PRINTER_LOCATION"));
1341 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info",
1342 NULL
, cgiGetVariable("PRINTER_INFO"));
1344 strlcpy(uri
, cgiGetVariable("DEVICE_URI"), sizeof(uri
));
1347 * Strip make and model from URI...
1350 if ((uriptr
= strrchr(uri
, '|')) != NULL
)
1353 if (!strncmp(uri
, "serial:", 7))
1356 * Update serial port URI to include baud rate, etc.
1359 if ((uriptr
= strchr(uri
, '?')) == NULL
)
1360 uriptr
= uri
+ strlen(uri
);
1362 snprintf(uriptr
, sizeof(uri
) - (size_t)(uriptr
- uri
),
1363 "?baud=%s+bits=%s+parity=%s+flow=%s",
1364 cgiGetVariable("BAUDRATE"), cgiGetVariable("BITS"),
1365 cgiGetVariable("PARITY"), cgiGetVariable("FLOW"));
1368 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri",
1371 ippAddBoolean(request
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", 1);
1373 var
= cgiGetVariable("printer_is_shared");
1374 ippAddBoolean(request
, IPP_TAG_PRINTER
, "printer-is-shared",
1375 var
&& (!strcmp(var
, "1") || !strcmp(var
, "on")));
1377 ippAddInteger(request
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
1381 * Do the request and get back a response...
1385 ippDelete(cupsDoFileRequest(http
, request
, "/admin/", file
->tempfile
));
1386 else if (evefile
[0])
1388 ippDelete(cupsDoFileRequest(http
, request
, "/admin/", evefile
));
1392 ippDelete(cupsDoRequest(http
, request
, "/admin/"));
1394 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
1396 puts("Status: 401\n");
1399 else if (cupsLastError() > IPP_OK_CONFLICT
)
1401 cgiStartHTML(title
);
1402 cgiShowIPPError(modify
? _("Unable to modify printer") :
1403 _("Unable to add printer"));
1408 * Redirect successful updates back to the printer page...
1411 char refresh
[1024]; /* Refresh URL */
1414 cgiFormEncode(uri
, name
, sizeof(uri
));
1416 snprintf(refresh
, sizeof(refresh
),
1417 "5;/admin/?OP=redirect&URL=/printers/%s", uri
);
1419 cgiSetVariable("refresh_page", refresh
);
1421 cgiStartHTML(title
);
1423 cgiCopyTemplateLang("printer-modified.tmpl");
1428 * Set the printer options...
1431 cgiSetVariable("OP", "set-printer-options");
1432 do_set_options(http
, 0);
1445 * 'do_cancel_subscription()' - Cancel a subscription.
1449 do_cancel_subscription(http_t
*http
)/* I - HTTP connection */
1451 ipp_t
*request
; /* IPP request data */
1452 const char *var
, /* Form variable */
1453 *user
; /* Username */
1454 int id
; /* Subscription ID */
1458 * See if we have all of the required information...
1461 if ((var
= cgiGetVariable("NOTIFY_SUBSCRIPTION_ID")) != NULL
)
1468 cgiSetVariable("ERROR", cgiText(_("Bad subscription ID")));
1469 cgiStartHTML(_("Cancel RSS Subscription"));
1470 cgiCopyTemplateLang("error.tmpl");
1476 * Require a username...
1479 if ((user
= getenv("REMOTE_USER")) == NULL
)
1481 puts("Status: 401\n");
1486 * Cancel the subscription...
1489 request
= ippNewRequest(IPP_CANCEL_SUBSCRIPTION
);
1491 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
1492 NULL
, "ipp://localhost/");
1493 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
,
1494 "notify-subscription-id", id
);
1496 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1499 ippDelete(cupsDoRequest(http
, request
, "/"));
1501 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
1503 puts("Status: 401\n");
1506 else if (cupsLastError() > IPP_OK_CONFLICT
)
1508 cgiStartHTML(_("Cancel RSS Subscription"));
1509 cgiShowIPPError(_("Unable to cancel RSS subscription"));
1514 * Redirect successful updates back to the admin page...
1517 cgiSetVariable("refresh_page", "5;URL=/admin");
1518 cgiStartHTML(_("Cancel RSS Subscription"));
1519 cgiCopyTemplateLang("subscription-canceled.tmpl");
1527 * 'do_config_server()' - Configure server settings.
1531 do_config_server(http_t
*http
) /* I - HTTP connection */
1533 if (cgiGetVariable("CHANGESETTINGS"))
1536 * Save basic setting changes...
1539 int num_settings
; /* Number of server settings */
1540 cups_option_t
*settings
; /* Server settings */
1541 int advanced
, /* Advanced settings shown? */
1542 changed
; /* Have settings changed? */
1543 const char *debug_logging
, /* DEBUG_LOGGING value */
1544 *preserve_jobs
= NULL
,
1545 /* PRESERVE_JOBS value */
1546 *remote_admin
, /* REMOTE_ADMIN value */
1547 *remote_any
, /* REMOTE_ANY value */
1548 *share_printers
,/* SHARE_PRINTERS value */
1550 /* USER_CANCEL_ANY value */
1551 *browse_web_if
= NULL
,
1552 /* BrowseWebIF value */
1553 *preserve_job_history
= NULL
,
1554 /* PreserveJobHistory value */
1555 *preserve_job_files
= NULL
,
1556 /* PreserveJobFiles value */
1557 *max_clients
= NULL
,
1558 /* MaxClients value */
1561 *max_log_size
= NULL
;
1562 /* MaxLogSize value */
1563 const char *current_browse_web_if
,
1564 /* BrowseWebIF value */
1565 *current_preserve_job_history
,
1566 /* PreserveJobHistory value */
1567 *current_preserve_job_files
,
1568 /* PreserveJobFiles value */
1569 *current_max_clients
,
1570 /* MaxClients value */
1573 *current_max_log_size
;
1574 /* MaxLogSize value */
1576 char default_auth_type
[255];
1577 /* DefaultAuthType value */
1578 const char *val
; /* Setting value */
1579 #endif /* HAVE_GSSAPI */
1583 * Get the checkbox values from the form...
1586 debug_logging
= cgiGetVariable("DEBUG_LOGGING") ? "1" : "0";
1587 remote_admin
= cgiGetVariable("REMOTE_ADMIN") ? "1" : "0";
1588 remote_any
= cgiGetVariable("REMOTE_ANY") ? "1" : "0";
1589 share_printers
= cgiGetVariable("SHARE_PRINTERS") ? "1" : "0";
1590 user_cancel_any
= cgiGetVariable("USER_CANCEL_ANY") ? "1" : "0";
1592 advanced
= cgiGetVariable("ADVANCEDSETTINGS") != NULL
;
1596 * Get advanced settings...
1599 browse_web_if
= cgiGetVariable("BROWSE_WEB_IF") ? "Yes" : "No";
1600 max_clients
= cgiGetVariable("MAX_CLIENTS");
1601 max_log_size
= cgiGetVariable("MAX_LOG_SIZE");
1602 preserve_jobs
= cgiGetVariable("PRESERVE_JOBS");
1606 max_jobs
= cgiGetVariable("MAX_JOBS");
1607 preserve_job_history
= cgiGetVariable("PRESERVE_JOB_HISTORY");
1608 preserve_job_files
= cgiGetVariable("PRESERVE_JOB_FILES");
1610 if (!max_jobs
|| atoi(max_jobs
) < 0)
1613 if (!preserve_job_history
)
1614 preserve_job_history
= "On";
1616 if (!preserve_job_files
)
1617 preserve_job_files
= "1d";
1622 preserve_job_history
= "No";
1623 preserve_job_files
= "No";
1626 if (!max_clients
|| atoi(max_clients
) <= 0)
1627 max_clients
= "100";
1629 if (!max_log_size
|| atoi(max_log_size
) <= 0.0)
1630 max_log_size
= "1m";
1634 * Get the current server settings...
1637 if (!cupsAdminGetServerSettings(http
, &num_settings
, &settings
))
1639 cgiStartHTML(cgiText(_("Change Settings")));
1640 cgiSetVariable("MESSAGE",
1641 cgiText(_("Unable to change server settings")));
1642 cgiSetVariable("ERROR", cupsLastErrorString());
1643 cgiCopyTemplateLang("error.tmpl");
1650 * Get authentication settings...
1653 if (cgiGetVariable("KERBEROS"))
1654 strlcpy(default_auth_type
, "Negotiate", sizeof(default_auth_type
));
1657 val
= cupsGetOption("DefaultAuthType", num_settings
, settings
);
1659 if (!val
|| !_cups_strcasecmp(val
, "Negotiate"))
1660 strlcpy(default_auth_type
, "Basic", sizeof(default_auth_type
));
1662 strlcpy(default_auth_type
, val
, sizeof(default_auth_type
));
1665 fprintf(stderr
, "DEBUG: DefaultAuthType %s\n", default_auth_type
);
1666 #endif /* HAVE_GSSAPI */
1668 if ((current_browse_web_if
= cupsGetOption("BrowseWebIF", num_settings
,
1670 current_browse_web_if
= "No";
1672 if ((current_preserve_job_history
= cupsGetOption("PreserveJobHistory",
1675 current_preserve_job_history
= "Yes";
1677 if ((current_preserve_job_files
= cupsGetOption("PreserveJobFiles",
1680 current_preserve_job_files
= "1d";
1682 if ((current_max_clients
= cupsGetOption("MaxClients", num_settings
,
1684 current_max_clients
= "100";
1686 if ((current_max_jobs
= cupsGetOption("MaxJobs", num_settings
,
1688 current_max_jobs
= "500";
1690 if ((current_max_log_size
= cupsGetOption("MaxLogSize", num_settings
,
1692 current_max_log_size
= "1m";
1695 * See if the settings have changed...
1698 changed
= strcmp(debug_logging
, cupsGetOption(CUPS_SERVER_DEBUG_LOGGING
,
1699 num_settings
, settings
)) ||
1700 strcmp(remote_admin
, cupsGetOption(CUPS_SERVER_REMOTE_ADMIN
,
1701 num_settings
, settings
)) ||
1702 strcmp(remote_any
, cupsGetOption(CUPS_SERVER_REMOTE_ANY
,
1703 num_settings
, settings
)) ||
1704 strcmp(share_printers
, cupsGetOption(CUPS_SERVER_SHARE_PRINTERS
,
1705 num_settings
, settings
)) ||
1707 !cupsGetOption("DefaultAuthType", num_settings
, settings
) ||
1708 strcmp(default_auth_type
, cupsGetOption("DefaultAuthType",
1709 num_settings
, settings
)) ||
1710 #endif /* HAVE_GSSAPI */
1711 strcmp(user_cancel_any
, cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY
,
1712 num_settings
, settings
));
1714 if (advanced
&& !changed
)
1715 changed
= _cups_strcasecmp(browse_web_if
, current_browse_web_if
) ||
1716 _cups_strcasecmp(preserve_job_history
, current_preserve_job_history
) ||
1717 _cups_strcasecmp(preserve_job_files
, current_preserve_job_files
) ||
1718 _cups_strcasecmp(max_clients
, current_max_clients
) ||
1719 _cups_strcasecmp(max_jobs
, current_max_jobs
) ||
1720 _cups_strcasecmp(max_log_size
, current_max_log_size
);
1725 * Settings *have* changed, so save the changes...
1728 cupsFreeOptions(num_settings
, settings
);
1731 num_settings
= cupsAddOption(CUPS_SERVER_DEBUG_LOGGING
,
1732 debug_logging
, num_settings
, &settings
);
1733 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ADMIN
,
1734 remote_admin
, num_settings
, &settings
);
1735 num_settings
= cupsAddOption(CUPS_SERVER_REMOTE_ANY
,
1736 remote_any
, num_settings
, &settings
);
1737 num_settings
= cupsAddOption(CUPS_SERVER_SHARE_PRINTERS
,
1738 share_printers
, num_settings
, &settings
);
1739 num_settings
= cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY
,
1740 user_cancel_any
, num_settings
, &settings
);
1742 num_settings
= cupsAddOption("DefaultAuthType", default_auth_type
,
1743 num_settings
, &settings
);
1744 #endif /* HAVE_GSSAPI */
1749 * Add advanced settings...
1752 if (_cups_strcasecmp(browse_web_if
, current_browse_web_if
))
1753 num_settings
= cupsAddOption("BrowseWebIF", browse_web_if
,
1754 num_settings
, &settings
);
1755 if (_cups_strcasecmp(preserve_job_history
, current_preserve_job_history
))
1756 num_settings
= cupsAddOption("PreserveJobHistory",
1757 preserve_job_history
, num_settings
,
1759 if (_cups_strcasecmp(preserve_job_files
, current_preserve_job_files
))
1760 num_settings
= cupsAddOption("PreserveJobFiles", preserve_job_files
,
1761 num_settings
, &settings
);
1762 if (_cups_strcasecmp(max_clients
, current_max_clients
))
1763 num_settings
= cupsAddOption("MaxClients", max_clients
, num_settings
,
1765 if (_cups_strcasecmp(max_jobs
, current_max_jobs
))
1766 num_settings
= cupsAddOption("MaxJobs", max_jobs
, num_settings
,
1768 if (_cups_strcasecmp(max_log_size
, current_max_log_size
))
1769 num_settings
= cupsAddOption("MaxLogSize", max_log_size
, num_settings
,
1773 if (!cupsAdminSetServerSettings(http
, num_settings
, settings
))
1775 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
1777 puts("Status: 401\n");
1781 cgiStartHTML(cgiText(_("Change Settings")));
1782 cgiSetVariable("MESSAGE",
1783 cgiText(_("Unable to change server settings")));
1784 cgiSetVariable("ERROR", cupsLastErrorString());
1785 cgiCopyTemplateLang("error.tmpl");
1790 cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect&"
1791 "URL=/admin/?ADVANCEDSETTINGS=YES");
1793 cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect");
1794 cgiStartHTML(cgiText(_("Change Settings")));
1795 cgiCopyTemplateLang("restart.tmpl");
1804 cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect");
1805 cgiStartHTML(cgiText(_("Change Settings")));
1806 cgiCopyTemplateLang("norestart.tmpl");
1809 cupsFreeOptions(num_settings
, settings
);
1813 else if (cgiGetVariable("SAVECHANGES") && cgiGetVariable("CUPSDCONF"))
1816 * Save hand-edited config file...
1819 http_status_t status
; /* PUT status */
1820 char tempfile
[1024]; /* Temporary new cupsd.conf */
1821 int tempfd
; /* Temporary file descriptor */
1822 cups_file_t
*temp
; /* Temporary file */
1823 const char *start
, /* Start of line */
1824 *end
; /* End of line */
1828 * Create a temporary file for the new cupsd.conf file...
1831 if ((tempfd
= cupsTempFd(tempfile
, sizeof(tempfile
))) < 0)
1833 cgiStartHTML(cgiText(_("Edit Configuration File")));
1834 cgiSetVariable("MESSAGE", cgiText(_("Unable to create temporary file")));
1835 cgiSetVariable("ERROR", strerror(errno
));
1836 cgiCopyTemplateLang("error.tmpl");
1843 if ((temp
= cupsFileOpenFd(tempfd
, "w")) == NULL
)
1845 cgiStartHTML(cgiText(_("Edit Configuration File")));
1846 cgiSetVariable("MESSAGE", cgiText(_("Unable to create temporary file")));
1847 cgiSetVariable("ERROR", strerror(errno
));
1848 cgiCopyTemplateLang("error.tmpl");
1858 * Copy the cupsd.conf text from the form variable...
1861 start
= cgiGetVariable("CUPSDCONF");
1864 if ((end
= strstr(start
, "\r\n")) == NULL
)
1865 if ((end
= strstr(start
, "\n")) == NULL
)
1866 end
= start
+ strlen(start
);
1868 cupsFileWrite(temp
, start
, (size_t)(end
- start
));
1869 cupsFilePutChar(temp
, '\n');
1873 else if (*end
== '\n')
1879 cupsFileClose(temp
);
1882 * Upload the configuration file to the server...
1885 status
= cupsPutFile(http
, "/admin/conf/cupsd.conf", tempfile
);
1887 if (status
== HTTP_UNAUTHORIZED
)
1889 puts("Status: 401\n");
1893 else if (status
!= HTTP_CREATED
)
1895 cgiSetVariable("MESSAGE",
1896 cgiText(_("Unable to upload cupsd.conf file")));
1897 cgiSetVariable("ERROR", httpStatus(status
));
1899 cgiStartHTML(cgiText(_("Edit Configuration File")));
1900 cgiCopyTemplateLang("error.tmpl");
1904 cgiSetVariable("refresh_page", "5;URL=/admin/");
1906 cgiStartHTML(cgiText(_("Edit Configuration File")));
1907 cgiCopyTemplateLang("restart.tmpl");
1916 struct stat info
; /* cupsd.conf information */
1917 cups_file_t
*cupsd
; /* cupsd.conf file */
1918 char *buffer
, /* Buffer for entire file */
1919 *bufptr
, /* Pointer into buffer */
1920 *bufend
; /* End of buffer */
1921 int ch
; /* Character from file */
1922 char filename
[1024]; /* Filename */
1923 const char *server_root
; /* Location of config files */
1927 * Locate the cupsd.conf file...
1930 if ((server_root
= getenv("CUPS_SERVERROOT")) == NULL
)
1931 server_root
= CUPS_SERVERROOT
;
1933 snprintf(filename
, sizeof(filename
), "%s/cupsd.conf", server_root
);
1936 * Figure out the size...
1939 if (stat(filename
, &info
))
1941 cgiStartHTML(cgiText(_("Edit Configuration File")));
1942 cgiSetVariable("MESSAGE",
1943 cgiText(_("Unable to access cupsd.conf file")));
1944 cgiSetVariable("ERROR", strerror(errno
));
1945 cgiCopyTemplateLang("error.tmpl");
1952 if (info
.st_size
> (1024 * 1024))
1954 cgiStartHTML(cgiText(_("Edit Configuration File")));
1955 cgiSetVariable("MESSAGE",
1956 cgiText(_("Unable to access cupsd.conf file")));
1957 cgiSetVariable("ERROR",
1958 cgiText(_("Unable to edit cupsd.conf files larger than "
1960 cgiCopyTemplateLang("error.tmpl");
1963 fprintf(stderr
, "ERROR: \"%s\" too large (%ld) to edit!\n", filename
,
1964 (long)info
.st_size
);
1969 * Open the cupsd.conf file...
1972 if ((cupsd
= cupsFileOpen(filename
, "r")) == NULL
)
1975 * Unable to open - log an error...
1978 cgiStartHTML(cgiText(_("Edit Configuration File")));
1979 cgiSetVariable("MESSAGE",
1980 cgiText(_("Unable to access cupsd.conf file")));
1981 cgiSetVariable("ERROR", strerror(errno
));
1982 cgiCopyTemplateLang("error.tmpl");
1990 * Allocate memory and load the file into a string buffer...
1993 if ((buffer
= calloc(1, (size_t)info
.st_size
+ 1)) != NULL
)
1995 cupsFileRead(cupsd
, buffer
, (size_t)info
.st_size
);
1996 cgiSetVariable("CUPSDCONF", buffer
);
2000 cupsFileClose(cupsd
);
2003 * Then get the default cupsd.conf file and put that into a string as
2007 strlcat(filename
, ".default", sizeof(filename
));
2009 if (!stat(filename
, &info
) && info
.st_size
< (1024 * 1024) &&
2010 (cupsd
= cupsFileOpen(filename
, "r")) != NULL
)
2012 if ((buffer
= calloc(1, 2 * (size_t)info
.st_size
+ 1)) != NULL
)
2014 bufend
= buffer
+ 2 * info
.st_size
- 1;
2016 for (bufptr
= buffer
;
2017 bufptr
< bufend
&& (ch
= cupsFileGetChar(cupsd
)) != EOF
;)
2019 if (ch
== '\\' || ch
== '\"')
2022 *bufptr
++ = (char)ch
;
2024 else if (ch
== '\n')
2029 else if (ch
== '\t')
2035 *bufptr
++ = (char)ch
;
2040 cgiSetVariable("CUPSDCONF_DEFAULT", buffer
);
2044 cupsFileClose(cupsd
);
2048 * Show the current config file...
2051 cgiStartHTML(cgiText(_("Edit Configuration File")));
2053 cgiCopyTemplateLang("edit-config.tmpl");
2061 * 'do_delete_class()' - Delete a class.
2065 do_delete_class(http_t
*http
) /* I - HTTP connection */
2067 ipp_t
*request
; /* IPP request */
2068 char uri
[HTTP_MAX_URI
]; /* Job URI */
2069 const char *pclass
; /* Printer class name */
2073 * Get form variables...
2076 if (cgiGetVariable("CONFIRM") == NULL
)
2078 cgiStartHTML(cgiText(_("Delete Class")));
2079 cgiCopyTemplateLang("class-confirm.tmpl");
2084 if ((pclass
= cgiGetVariable("PRINTER_NAME")) != NULL
)
2085 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
2086 "localhost", 0, "/classes/%s", pclass
);
2089 cgiStartHTML(cgiText(_("Delete Class")));
2090 cgiSetVariable("ERROR", cgiText(_("Missing form variable")));
2091 cgiCopyTemplateLang("error.tmpl");
2097 * Build a CUPS_DELETE_CLASS request, which requires the following
2100 * attributes-charset
2101 * attributes-natural-language
2105 request
= ippNewRequest(CUPS_DELETE_CLASS
);
2107 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
2111 * Do the request and get back a response...
2114 ippDelete(cupsDoRequest(http
, request
, "/admin/"));
2117 * Show the results...
2120 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
2122 puts("Status: 401\n");
2125 else if (cupsLastError() <= IPP_OK_CONFLICT
)
2128 * Redirect successful updates back to the classes page...
2131 cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect&URL=/classes");
2134 cgiStartHTML(cgiText(_("Delete Class")));
2136 if (cupsLastError() > IPP_OK_CONFLICT
)
2137 cgiShowIPPError(_("Unable to delete class"));
2139 cgiCopyTemplateLang("class-deleted.tmpl");
2146 * 'do_delete_printer()' - Delete a printer.
2150 do_delete_printer(http_t
*http
) /* I - HTTP connection */
2152 ipp_t
*request
; /* IPP request */
2153 char uri
[HTTP_MAX_URI
]; /* Job URI */
2154 const char *printer
; /* Printer printer name */
2158 * Get form variables...
2161 if (cgiGetVariable("CONFIRM") == NULL
)
2163 cgiStartHTML(cgiText(_("Delete Printer")));
2164 cgiCopyTemplateLang("printer-confirm.tmpl");
2169 if ((printer
= cgiGetVariable("PRINTER_NAME")) != NULL
)
2170 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
2171 "localhost", 0, "/printers/%s", printer
);
2174 cgiStartHTML(cgiText(_("Delete Printer")));
2175 cgiSetVariable("ERROR", cgiText(_("Missing form variable")));
2176 cgiCopyTemplateLang("error.tmpl");
2182 * Build a CUPS_DELETE_PRINTER request, which requires the following
2185 * attributes-charset
2186 * attributes-natural-language
2190 request
= ippNewRequest(CUPS_DELETE_PRINTER
);
2192 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
2196 * Do the request and get back a response...
2199 ippDelete(cupsDoRequest(http
, request
, "/admin/"));
2202 * Show the results...
2205 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
2207 puts("Status: 401\n");
2210 else if (cupsLastError() <= IPP_OK_CONFLICT
)
2213 * Redirect successful updates back to the printers page...
2216 cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect&URL=/printers");
2219 cgiStartHTML(cgiText(_("Delete Printer")));
2221 if (cupsLastError() > IPP_OK_CONFLICT
)
2222 cgiShowIPPError(_("Unable to delete printer"));
2224 cgiCopyTemplateLang("printer-deleted.tmpl");
2231 * 'do_export()' - Export printers to Samba.
2235 do_export(http_t
*http
) /* I - HTTP connection */
2237 int i
, j
; /* Looping vars */
2238 ipp_t
*request
, /* IPP request */
2239 *response
; /* IPP response */
2240 const char *username
, /* Samba username */
2241 *password
, /* Samba password */
2242 *export_all
; /* Export all printers? */
2243 int export_count
, /* Number of printers to export */
2244 printer_count
; /* Number of available printers */
2245 const char *name
, /* What name to pull */
2246 *dest
; /* Current destination */
2247 char ppd
[1024]; /* PPD file */
2254 username
= cgiGetVariable("USERNAME");
2255 password
= cgiGetVariable("PASSWORD");
2256 export_all
= cgiGetVariable("EXPORT_ALL");
2257 export_count
= cgiGetSize("EXPORT_NAME");
2260 * Get list of available printers...
2263 cgiSetSize("PRINTER_NAME", 0);
2264 cgiSetSize("PRINTER_EXPORT", 0);
2266 request
= ippNewRequest(CUPS_GET_PRINTERS
);
2268 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_ENUM
,
2271 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_ENUM
,
2272 "printer-type-mask", CUPS_PRINTER_CLASS
| CUPS_PRINTER_REMOTE
);
2274 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
2275 "requested-attributes", NULL
, "printer-name");
2277 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
2279 cgiSetIPPVars(response
, NULL
, NULL
, NULL
, 0);
2280 ippDelete(response
);
2284 printer_count
= cgiGetSize("PRINTER_NAME");
2286 for (i
= 0; i
< printer_count
; i
++)
2288 dest
= cgiGetArray("PRINTER_NAME", i
);
2290 for (j
= 0; j
< export_count
; j
++)
2291 if (!_cups_strcasecmp(dest
, cgiGetArray("EXPORT_NAME", j
)))
2294 cgiSetArray("PRINTER_EXPORT", i
, j
< export_count
? "Y" : "");
2300 * Export or get the printers to export...
2303 if (username
&& *username
&& password
&& *password
&&
2304 (export_all
|| export_count
> 0))
2310 fputs("DEBUG: Export printers...\n", stderr
);
2314 name
= "PRINTER_NAME";
2315 export_count
= cgiGetSize("PRINTER_NAME");
2318 name
= "EXPORT_NAME";
2320 for (i
= 0; i
< export_count
; i
++)
2322 dest
= cgiGetArray(name
, i
);
2324 if (!cupsAdminCreateWindowsPPD(http
, dest
, ppd
, sizeof(ppd
)))
2327 j
= cupsAdminExportSamba(dest
, ppd
, "localhost", username
, password
,
2336 if (i
< export_count
)
2337 cgiSetVariable("ERROR", cupsLastErrorString());
2340 cgiStartHTML(cgiText(_("Export Printers to Samba")));
2341 cgiCopyTemplateLang("samba-exported.tmpl");
2346 else if (username
&& !*username
)
2347 cgiSetVariable("ERROR",
2348 cgiText(_("A Samba username is required to export "
2349 "printer drivers")));
2350 else if (username
&& (!password
|| !*password
))
2351 cgiSetVariable("ERROR",
2352 cgiText(_("A Samba password is required to export "
2353 "printer drivers")));
2359 cgiStartHTML(cgiText(_("Export Printers to Samba")));
2360 cgiCopyTemplateLang("samba-export.tmpl");
2366 * 'do_list_printers()' - List available printers.
2370 do_list_printers(http_t
*http
) /* I - HTTP connection */
2372 ipp_t
*request
, /* IPP request */
2373 *response
; /* IPP response */
2374 ipp_attribute_t
*attr
; /* IPP attribute */
2377 cgiStartHTML(cgiText(_("List Available Printers")));
2381 * Get the list of printers and their devices...
2384 request
= ippNewRequest(CUPS_GET_PRINTERS
);
2386 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
2387 "requested-attributes", NULL
, "device-uri");
2389 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_ENUM
, "printer-type",
2390 CUPS_PRINTER_LOCAL
);
2391 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_ENUM
, "printer-type-mask",
2392 CUPS_PRINTER_LOCAL
);
2394 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
2397 * Got the printer list, now load the devices...
2400 int i
; /* Looping var */
2401 cups_array_t
*printer_devices
; /* Printer devices for local printers */
2402 char *printer_device
; /* Current printer device */
2406 * Allocate an array and copy the device strings...
2409 printer_devices
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
2411 for (attr
= ippFindAttribute(response
, "device-uri", IPP_TAG_URI
);
2413 attr
= ippFindNextAttribute(response
, "device-uri", IPP_TAG_URI
))
2415 cupsArrayAdd(printer_devices
, _cupsStrAlloc(attr
->values
[0].string
.text
));
2419 * Free the printer list and get the device list...
2422 ippDelete(response
);
2424 request
= ippNewRequest(CUPS_GET_DEVICES
);
2426 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
2429 * Got the device list, let's parse it...
2432 const char *device_uri
, /* device-uri attribute value */
2433 *device_make_and_model
, /* device-make-and-model value */
2434 *device_info
; /* device-info value */
2437 for (i
= 0, attr
= response
->attrs
; attr
; attr
= attr
->next
)
2440 * Skip leading attributes until we hit a device...
2443 while (attr
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
2450 * Pull the needed attributes from this device...
2454 device_make_and_model
= NULL
;
2457 while (attr
&& attr
->group_tag
== IPP_TAG_PRINTER
)
2459 if (!strcmp(attr
->name
, "device-info") &&
2460 attr
->value_tag
== IPP_TAG_TEXT
)
2461 device_info
= attr
->values
[0].string
.text
;
2463 if (!strcmp(attr
->name
, "device-make-and-model") &&
2464 attr
->value_tag
== IPP_TAG_TEXT
)
2465 device_make_and_model
= attr
->values
[0].string
.text
;
2467 if (!strcmp(attr
->name
, "device-uri") &&
2468 attr
->value_tag
== IPP_TAG_URI
)
2469 device_uri
= attr
->values
[0].string
.text
;
2475 * See if we have everything needed...
2478 if (device_info
&& device_make_and_model
&& device_uri
&&
2479 _cups_strcasecmp(device_make_and_model
, "unknown") &&
2480 strchr(device_uri
, ':'))
2483 * Yes, now see if there is already a printer for this
2487 if (!cupsArrayFind(printer_devices
, (void *)device_uri
))
2490 * Not found, so it must be a new printer...
2493 char option
[1024], /* Form variables for this device */
2494 *option_ptr
; /* Pointer into string */
2495 const char *ptr
; /* Pointer into device string */
2499 * Format the printer name variable for this device...
2501 * We use the device-info string first, then device-uri,
2502 * and finally device-make-and-model to come up with a
2506 if (_cups_strncasecmp(device_info
, "unknown", 7))
2508 else if ((ptr
= strstr(device_uri
, "://")) != NULL
)
2511 ptr
= device_make_and_model
;
2513 for (option_ptr
= option
;
2514 option_ptr
< (option
+ sizeof(option
) - 1) && *ptr
;
2516 if (isalnum(*ptr
& 255) || *ptr
== '_' || *ptr
== '-' ||
2518 *option_ptr
++ = *ptr
;
2519 else if ((*ptr
== ' ' || *ptr
== '/') && option_ptr
> option
&&
2520 option_ptr
[-1] != '_')
2521 *option_ptr
++ = '_';
2522 else if (*ptr
== '?' || *ptr
== '(')
2527 cgiSetArray("TEMPLATE_NAME", i
, option
);
2530 * Finally, set the form variables for this printer...
2533 cgiSetArray("device_info", i
, device_info
);
2534 cgiSetArray("device_make_and_model", i
, device_make_and_model
);
2535 cgiSetArray("device_uri", i
, device_uri
);
2544 ippDelete(response
);
2547 * Free the device list...
2550 for (printer_device
= (char *)cupsArrayFirst(printer_devices
);
2552 printer_device
= (char *)cupsArrayNext(printer_devices
))
2553 _cupsStrFree(printer_device
);
2555 cupsArrayDelete(printer_devices
);
2560 * Finally, show the printer list...
2563 cgiCopyTemplateLang("list-available-printers.tmpl");
2570 * 'do_menu()' - Show the main menu.
2574 do_menu(http_t
*http
) /* I - HTTP connection */
2576 int num_settings
; /* Number of server settings */
2577 cups_option_t
*settings
; /* Server settings */
2578 const char *val
; /* Setting value */
2579 char filename
[1024]; /* Temporary filename */
2580 const char *datadir
; /* Location of data files */
2581 ipp_t
*request
, /* IPP request */
2582 *response
; /* IPP response */
2586 * Get the current server settings...
2589 if (!cupsAdminGetServerSettings(http
, &num_settings
, &settings
))
2591 cgiSetVariable("SETTINGS_MESSAGE",
2592 cgiText(_("Unable to open cupsd.conf file:")));
2593 cgiSetVariable("SETTINGS_ERROR", cupsLastErrorString());
2596 if ((val
= cupsGetOption(CUPS_SERVER_DEBUG_LOGGING
, num_settings
,
2597 settings
)) != NULL
&& atoi(val
))
2598 cgiSetVariable("DEBUG_LOGGING", "CHECKED");
2600 if ((val
= cupsGetOption(CUPS_SERVER_REMOTE_ADMIN
, num_settings
,
2601 settings
)) != NULL
&& atoi(val
))
2602 cgiSetVariable("REMOTE_ADMIN", "CHECKED");
2604 if ((val
= cupsGetOption(CUPS_SERVER_REMOTE_ANY
, num_settings
,
2605 settings
)) != NULL
&& atoi(val
))
2606 cgiSetVariable("REMOTE_ANY", "CHECKED");
2608 if ((val
= cupsGetOption(CUPS_SERVER_SHARE_PRINTERS
, num_settings
,
2609 settings
)) != NULL
&& atoi(val
))
2610 cgiSetVariable("SHARE_PRINTERS", "CHECKED");
2612 if ((val
= cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY
, num_settings
,
2613 settings
)) != NULL
&& atoi(val
))
2614 cgiSetVariable("USER_CANCEL_ANY", "CHECKED");
2617 cgiSetVariable("HAVE_GSSAPI", "1");
2619 if ((val
= cupsGetOption("DefaultAuthType", num_settings
,
2620 settings
)) != NULL
&& !_cups_strcasecmp(val
, "Negotiate"))
2621 cgiSetVariable("KERBEROS", "CHECKED");
2623 #endif /* HAVE_GSSAPI */
2624 cgiSetVariable("KERBEROS", "");
2626 if ((val
= cupsGetOption("BrowseWebIF", num_settings
,
2630 if (!_cups_strcasecmp(val
, "yes") || !_cups_strcasecmp(val
, "on") ||
2631 !_cups_strcasecmp(val
, "true"))
2632 cgiSetVariable("BROWSE_WEB_IF", "CHECKED");
2634 if ((val
= cupsGetOption("PreserveJobHistory", num_settings
,
2639 (!_cups_strcasecmp(val
, "0") || !_cups_strcasecmp(val
, "no") ||
2640 !_cups_strcasecmp(val
, "off") || !_cups_strcasecmp(val
, "false") ||
2641 !_cups_strcasecmp(val
, "disabled")))
2643 cgiSetVariable("PRESERVE_JOB_HISTORY", "0");
2644 cgiSetVariable("PRESERVE_JOB_FILES", "0");
2648 cgiSetVariable("PRESERVE_JOBS", "CHECKED");
2649 cgiSetVariable("PRESERVE_JOB_HISTORY", val
);
2651 if ((val
= cupsGetOption("PreserveJobFiles", num_settings
,
2655 cgiSetVariable("PRESERVE_JOB_FILES", val
);
2659 if ((val
= cupsGetOption("MaxClients", num_settings
, settings
)) == NULL
)
2662 cgiSetVariable("MAX_CLIENTS", val
);
2664 if ((val
= cupsGetOption("MaxJobs", num_settings
, settings
)) == NULL
)
2667 cgiSetVariable("MAX_JOBS", val
);
2669 if ((val
= cupsGetOption("MaxLogSize", num_settings
, settings
)) == NULL
)
2672 cgiSetVariable("MAX_LOG_SIZE", val
);
2674 cupsFreeOptions(num_settings
, settings
);
2677 * See if Samba and the Windows drivers are installed...
2680 if ((datadir
= getenv("CUPS_DATADIR")) == NULL
)
2681 datadir
= CUPS_DATADIR
;
2683 snprintf(filename
, sizeof(filename
), "%s/drivers/pscript5.dll", datadir
);
2684 if (!access(filename
, R_OK
))
2687 * Found Windows 2000 driver file, see if we have smbclient and
2691 if (cupsFileFind("smbclient", getenv("PATH"), 1, filename
,
2692 sizeof(filename
)) &&
2693 cupsFileFind("rpcclient", getenv("PATH"), 1, filename
,
2695 cgiSetVariable("HAVE_SAMBA", "Y");
2698 if (!cupsFileFind("smbclient", getenv("PATH"), 1, filename
,
2700 fputs("ERROR: smbclient not found!\n", stderr
);
2702 if (!cupsFileFind("rpcclient", getenv("PATH"), 1, filename
,
2704 fputs("ERROR: rpcclient not found!\n", stderr
);
2714 request
= ippNewRequest(IPP_GET_SUBSCRIPTIONS
);
2716 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
2717 NULL
, "ipp://localhost/");
2719 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
2721 cgiSetIPPVars(response
, NULL
, NULL
, NULL
, 0);
2722 ippDelete(response
);
2726 * Finally, show the main menu template...
2729 cgiStartHTML(cgiText(_("Administration")));
2731 cgiCopyTemplateLang("admin.tmpl");
2738 * 'do_set_allowed_users()' - Set the allowed/denied users for a queue.
2742 do_set_allowed_users(http_t
*http
) /* I - HTTP connection */
2744 int i
; /* Looping var */
2745 ipp_t
*request
, /* IPP request */
2746 *response
; /* IPP response */
2747 char uri
[HTTP_MAX_URI
]; /* Printer URI */
2748 const char *printer
, /* Printer name (purge-jobs) */
2749 *is_class
, /* Is a class? */
2750 *users
, /* List of users or groups */
2751 *type
; /* Allow/deny type */
2752 int num_users
; /* Number of users */
2753 char *ptr
, /* Pointer into users string */
2754 *end
, /* Pointer to end of users string */
2755 quote
; /* Quote character */
2756 ipp_attribute_t
*attr
; /* Attribute */
2757 static const char * const attrs
[] = /* Requested attributes */
2759 "requesting-user-name-allowed",
2760 "requesting-user-name-denied"
2764 is_class
= cgiGetVariable("IS_CLASS");
2765 printer
= cgiGetVariable("PRINTER_NAME");
2769 cgiSetVariable("ERROR", cgiText(_("Missing form variable")));
2770 cgiStartHTML(cgiText(_("Set Allowed Users")));
2771 cgiCopyTemplateLang("error.tmpl");
2776 users
= cgiGetVariable("users");
2777 type
= cgiGetVariable("type");
2779 if (!users
|| !type
||
2780 (strcmp(type
, "requesting-user-name-allowed") &&
2781 strcmp(type
, "requesting-user-name-denied")))
2784 * Build a Get-Printer-Attributes request, which requires the following
2787 * attributes-charset
2788 * attributes-natural-language
2790 * requested-attributes
2793 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
2795 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
2796 "localhost", 0, is_class
? "/classes/%s" : "/printers/%s",
2798 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
2801 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
2802 "requested-attributes",
2803 (int)(sizeof(attrs
) / sizeof(attrs
[0])), NULL
, attrs
);
2806 * Do the request and get back a response...
2809 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
2811 cgiSetIPPVars(response
, NULL
, NULL
, NULL
, 0);
2813 ippDelete(response
);
2816 cgiStartHTML(cgiText(_("Set Allowed Users")));
2818 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
2820 puts("Status: 401\n");
2823 else if (cupsLastError() > IPP_OK_CONFLICT
)
2824 cgiShowIPPError(_("Unable to get printer attributes"));
2826 cgiCopyTemplateLang("users.tmpl");
2833 * Save the changes...
2836 for (num_users
= 0, ptr
= (char *)users
; *ptr
; num_users
++)
2839 * Skip whitespace and commas...
2842 while (*ptr
== ',' || isspace(*ptr
& 255))
2848 if (*ptr
== '\'' || *ptr
== '\"')
2851 * Scan quoted name...
2856 for (end
= ptr
; *end
; end
++)
2863 * Scan space or comma-delimited name...
2866 for (end
= ptr
; *end
; end
++)
2867 if (isspace(*end
& 255) || *end
== ',')
2872 * Advance to the next name...
2879 * Build a CUPS-Add-Printer/Class request, which requires the following
2882 * attributes-charset
2883 * attributes-natural-language
2885 * requesting-user-name-{allowed,denied}
2888 request
= ippNewRequest(is_class
? CUPS_ADD_CLASS
: CUPS_ADD_PRINTER
);
2890 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
2891 "localhost", 0, is_class
? "/classes/%s" : "/printers/%s",
2893 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
2897 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2898 "requesting-user-name-allowed", NULL
, "all");
2901 attr
= ippAddStrings(request
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
2902 type
, num_users
, NULL
, NULL
);
2904 for (i
= 0, ptr
= (char *)users
; *ptr
; i
++)
2907 * Skip whitespace and commas...
2910 while (*ptr
== ',' || isspace(*ptr
& 255))
2916 if (*ptr
== '\'' || *ptr
== '\"')
2919 * Scan quoted name...
2924 for (end
= ptr
; *end
; end
++)
2931 * Scan space or comma-delimited name...
2934 for (end
= ptr
; *end
; end
++)
2935 if (isspace(*end
& 255) || *end
== ',')
2940 * Terminate the name...
2950 attr
->values
[i
].string
.text
= _cupsStrAlloc(ptr
);
2953 * Advance to the next name...
2961 * Do the request and get back a response...
2964 ippDelete(cupsDoRequest(http
, request
, "/admin/"));
2966 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
2968 puts("Status: 401\n");
2971 else if (cupsLastError() > IPP_OK_CONFLICT
)
2973 cgiStartHTML(cgiText(_("Set Allowed Users")));
2974 cgiShowIPPError(_("Unable to change printer"));
2979 * Redirect successful updates back to the printer page...
2982 char url
[1024], /* Printer/class URL */
2983 refresh
[1024]; /* Refresh URL */
2986 cgiRewriteURL(uri
, url
, sizeof(url
), NULL
);
2987 cgiFormEncode(uri
, url
, sizeof(uri
));
2988 snprintf(refresh
, sizeof(refresh
), "5;URL=/admin/?OP=redirect&URL=%s",
2990 cgiSetVariable("refresh_page", refresh
);
2992 cgiStartHTML(cgiText(_("Set Allowed Users")));
2994 cgiCopyTemplateLang(is_class
? "class-modified.tmpl" :
2995 "printer-modified.tmpl");
3004 * 'do_set_default()' - Set the server default printer/class.
3008 do_set_default(http_t
*http
) /* I - HTTP connection */
3010 const char *title
; /* Page title */
3011 ipp_t
*request
; /* IPP request */
3012 char uri
[HTTP_MAX_URI
]; /* Printer URI */
3013 const char *printer
, /* Printer name (purge-jobs) */
3014 *is_class
; /* Is a class? */
3017 is_class
= cgiGetVariable("IS_CLASS");
3018 printer
= cgiGetVariable("PRINTER_NAME");
3019 title
= cgiText(_("Set As Server Default"));
3023 cgiSetVariable("ERROR", cgiText(_("Missing form variable")));
3024 cgiStartHTML(title
);
3025 cgiCopyTemplateLang("error.tmpl");
3031 * Build a printer request, which requires the following
3034 * attributes-charset
3035 * attributes-natural-language
3039 request
= ippNewRequest(CUPS_SET_DEFAULT
);
3041 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
3042 "localhost", 0, is_class
? "/classes/%s" : "/printers/%s",
3044 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
3048 * Do the request and get back a response...
3051 ippDelete(cupsDoRequest(http
, request
, "/admin/"));
3053 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
3055 puts("Status: 401\n");
3058 else if (cupsLastError() > IPP_OK_CONFLICT
)
3060 cgiStartHTML(title
);
3061 cgiShowIPPError(_("Unable to set server default"));
3066 * Redirect successful updates back to the printer page...
3069 char url
[1024], /* Printer/class URL */
3070 refresh
[1024]; /* Refresh URL */
3073 cgiRewriteURL(uri
, url
, sizeof(url
), NULL
);
3074 cgiFormEncode(uri
, url
, sizeof(uri
));
3075 snprintf(refresh
, sizeof(refresh
), "5;URL=/admin/?OP=redirect&URL=%s", uri
);
3076 cgiSetVariable("refresh_page", refresh
);
3078 cgiStartHTML(title
);
3079 cgiCopyTemplateLang("printer-default.tmpl");
3087 * 'do_set_options()' - Configure the default options for a queue.
3091 do_set_options(http_t
*http
, /* I - HTTP connection */
3092 int is_class
) /* I - Set options for class? */
3094 int i
, j
, k
, m
; /* Looping vars */
3095 int have_options
; /* Have options? */
3096 ipp_t
*request
, /* IPP request */
3097 *response
; /* IPP response */
3098 ipp_attribute_t
*attr
; /* IPP attribute */
3099 char uri
[HTTP_MAX_URI
]; /* Job URI */
3100 const char *var
; /* Variable value */
3101 const char *printer
; /* Printer printer name */
3102 const char *filename
; /* PPD filename */
3103 char tempfile
[1024]; /* Temporary filename */
3104 cups_file_t
*in
, /* Input file */
3105 *out
; /* Output file */
3106 char line
[1024], /* Line from PPD file */
3107 value
[1024], /* Option value */
3108 keyword
[1024], /* Keyword from Default line */
3109 *keyptr
; /* Pointer into keyword... */
3110 ppd_file_t
*ppd
; /* PPD file */
3111 ppd_group_t
*group
; /* Option group */
3112 ppd_option_t
*option
; /* Option */
3113 ppd_coption_t
*coption
; /* Custom option */
3114 ppd_cparam_t
*cparam
; /* Custom parameter */
3115 ppd_attr_t
*ppdattr
; /* PPD attribute */
3116 const char *title
; /* Page title */
3119 title
= cgiText(is_class
? _("Set Class Options") : _("Set Printer Options"));
3121 fprintf(stderr
, "DEBUG: do_set_options(http=%p, is_class=%d)\n", http
,
3125 * Get the printer name...
3128 if ((printer
= cgiGetVariable("PRINTER_NAME")) != NULL
)
3129 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
3130 "localhost", 0, is_class
? "/classes/%s" : "/printers/%s",
3134 cgiSetVariable("ERROR", cgiText(_("Missing form variable")));
3135 cgiStartHTML(title
);
3136 cgiCopyTemplateLang("error.tmpl");
3141 fprintf(stderr
, "DEBUG: printer=\"%s\", uri=\"%s\"...\n", printer
, uri
);
3144 * If the user clicks on the Auto-Configure button, send an AutoConfigure
3145 * command file to the printer...
3148 if (cgiGetVariable("AUTOCONFIGURE"))
3150 cgiPrintCommand(http
, printer
, "AutoConfigure", "Set Default Options");
3155 * Get the PPD file...
3161 filename
= cupsGetPPD2(http
, printer
);
3165 fprintf(stderr
, "DEBUG: Got PPD file: \"%s\"\n", filename
);
3167 if ((ppd
= ppdOpenFile(filename
)) == NULL
)
3169 cgiSetVariable("ERROR", ppdErrorString(ppdLastError(&i
)));
3170 cgiSetVariable("MESSAGE", cgiText(_("Unable to open PPD file")));
3171 cgiStartHTML(title
);
3172 cgiCopyTemplateLang("error.tmpl");
3179 fputs("DEBUG: No PPD file\n", stderr
);
3183 if (cgiGetVariable("job_sheets_start") != NULL
||
3184 cgiGetVariable("job_sheets_end") != NULL
)
3191 ppdMarkDefaults(ppd
);
3193 for (option
= ppdFirstOption(ppd
);
3195 option
= ppdNextOption(ppd
))
3197 if ((var
= cgiGetVariable(option
->keyword
)) != NULL
)
3200 ppdMarkOption(ppd
, option
->keyword
, var
);
3201 fprintf(stderr
, "DEBUG: Set %s to %s...\n", option
->keyword
, var
);
3204 fprintf(stderr
, "DEBUG: Didn't find %s...\n", option
->keyword
);
3208 if (!have_options
|| ppdConflicts(ppd
))
3211 * Show the options to the user...
3214 fputs("DEBUG: Showing options...\n", stderr
);
3217 * Show auto-configure button if supported...
3222 if (ppd
->num_filters
== 0 ||
3223 ((ppdattr
= ppdFindAttr(ppd
, "cupsCommands", NULL
)) != NULL
&&
3224 ppdattr
->value
&& strstr(ppdattr
->value
, "AutoConfigure")))
3225 cgiSetVariable("HAVE_AUTOCONFIGURE", "YES");
3228 for (i
= 0; i
< ppd
->num_filters
; i
++)
3229 if (!strncmp(ppd
->filters
[i
], "application/vnd.cups-postscript", 31))
3231 cgiSetVariable("HAVE_AUTOCONFIGURE", "YES");
3238 * Get the printer attributes...
3241 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
3243 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
3244 "localhost", 0, "/printers/%s", printer
);
3245 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
3248 response
= cupsDoRequest(http
, request
, "/");
3251 * List the groups used as "tabs"...
3258 for (group
= ppd
->groups
;
3259 i
< ppd
->num_groups
;
3262 cgiSetArray("GROUP_ID", i
, group
->name
);
3264 if (!strcmp(group
->name
, "InstallableOptions"))
3265 cgiSetArray("GROUP", i
, cgiText(_("Options Installed")));
3267 cgiSetArray("GROUP", i
, group
->text
);
3271 if (ippFindAttribute(response
, "job-sheets-supported", IPP_TAG_ZERO
))
3273 cgiSetArray("GROUP_ID", i
, "CUPS_BANNERS");
3274 cgiSetArray("GROUP", i
++, cgiText(_("Banners")));
3277 if (ippFindAttribute(response
, "printer-error-policy-supported",
3279 ippFindAttribute(response
, "printer-op-policy-supported",
3282 cgiSetArray("GROUP_ID", i
, "CUPS_POLICIES");
3283 cgiSetArray("GROUP", i
++, cgiText(_("Policies")));
3286 if ((attr
= ippFindAttribute(response
, "port-monitor-supported",
3287 IPP_TAG_NAME
)) != NULL
&& attr
->num_values
> 1)
3289 cgiSetArray("GROUP_ID", i
, "CUPS_PORT_MONITOR");
3290 cgiSetArray("GROUP", i
, cgiText(_("Port Monitor")));
3293 cgiStartHTML(cgiText(_("Set Printer Options")));
3294 cgiCopyTemplateLang("set-printer-options-header.tmpl");
3300 if (ppdConflicts(ppd
))
3302 for (i
= ppd
->num_groups
, k
= 0, group
= ppd
->groups
;
3305 for (j
= group
->num_options
, option
= group
->options
;
3308 if (option
->conflicted
)
3310 cgiSetArray("ckeyword", k
, option
->keyword
);
3311 cgiSetArray("ckeytext", k
, option
->text
);
3313 for (m
= 0; m
< option
->num_choices
; m
++)
3315 if (option
->choices
[m
].marked
)
3317 cgiSetArray("cchoice", k
, option
->choices
[m
].text
);
3325 cgiCopyTemplateLang("option-conflict.tmpl");
3328 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
3332 for (j
= group
->num_options
, option
= group
->options
;
3336 if (!strcmp(option
->keyword
, "PageRegion"))
3339 if (option
->num_choices
> 1)
3346 cgiSetVariable("GROUP_ID", group
->name
);
3348 if (!strcmp(group
->name
, "InstallableOptions"))
3349 cgiSetVariable("GROUP", cgiText(_("Options Installed")));
3351 cgiSetVariable("GROUP", group
->text
);
3353 cgiCopyTemplateLang("option-header.tmpl");
3355 for (j
= group
->num_options
, option
= group
->options
;
3359 if (!strcmp(option
->keyword
, "PageRegion") || option
->num_choices
< 2)
3362 cgiSetVariable("KEYWORD", option
->keyword
);
3363 cgiSetVariable("KEYTEXT", option
->text
);
3365 if (option
->conflicted
)
3366 cgiSetVariable("CONFLICTED", "1");
3368 cgiSetVariable("CONFLICTED", "0");
3370 cgiSetSize("CHOICES", 0);
3371 cgiSetSize("TEXT", 0);
3372 for (k
= 0, m
= 0; k
< option
->num_choices
; k
++)
3374 cgiSetArray("CHOICES", m
, option
->choices
[k
].choice
);
3375 cgiSetArray("TEXT", m
, option
->choices
[k
].text
);
3379 if (option
->choices
[k
].marked
)
3380 cgiSetVariable("DEFCHOICE", option
->choices
[k
].choice
);
3383 cgiSetSize("PARAMS", 0);
3384 cgiSetSize("PARAMTEXT", 0);
3385 cgiSetSize("PARAMVALUE", 0);
3386 cgiSetSize("INPUTTYPE", 0);
3388 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)))
3390 const char *units
= NULL
; /* Units value, if any */
3392 cgiSetVariable("ISCUSTOM", "1");
3394 for (cparam
= ppdFirstCustomParam(coption
), m
= 0;
3396 cparam
= ppdNextCustomParam(coption
), m
++)
3398 if (!_cups_strcasecmp(option
->keyword
, "PageSize") &&
3399 _cups_strcasecmp(cparam
->name
, "Width") &&
3400 _cups_strcasecmp(cparam
->name
, "Height"))
3406 cgiSetArray("PARAMS", m
, cparam
->name
);
3407 cgiSetArray("PARAMTEXT", m
, cparam
->text
);
3408 cgiSetArray("INPUTTYPE", m
, "text");
3410 switch (cparam
->type
)
3412 case PPD_CUSTOM_POINTS
:
3413 if (!_cups_strncasecmp(option
->defchoice
, "Custom.", 7))
3415 units
= option
->defchoice
+ strlen(option
->defchoice
) - 2;
3417 if (strcmp(units
, "mm") && strcmp(units
, "cm") &&
3418 strcmp(units
, "in") && strcmp(units
, "ft"))
3420 if (units
[1] == 'm')
3429 if (!strcmp(units
, "mm"))
3430 snprintf(value
, sizeof(value
), "%g",
3431 cparam
->current
.custom_points
/ 72.0 * 25.4);
3432 else if (!strcmp(units
, "cm"))
3433 snprintf(value
, sizeof(value
), "%g",
3434 cparam
->current
.custom_points
/ 72.0 * 2.54);
3435 else if (!strcmp(units
, "in"))
3436 snprintf(value
, sizeof(value
), "%g",
3437 cparam
->current
.custom_points
/ 72.0);
3438 else if (!strcmp(units
, "ft"))
3439 snprintf(value
, sizeof(value
), "%g",
3440 cparam
->current
.custom_points
/ 72.0 / 12.0);
3441 else if (!strcmp(units
, "m"))
3442 snprintf(value
, sizeof(value
), "%g",
3443 cparam
->current
.custom_points
/ 72.0 * 0.0254);
3445 snprintf(value
, sizeof(value
), "%g",
3446 cparam
->current
.custom_points
);
3447 cgiSetArray("PARAMVALUE", m
, value
);
3450 case PPD_CUSTOM_CURVE
:
3451 case PPD_CUSTOM_INVCURVE
:
3452 case PPD_CUSTOM_REAL
:
3453 snprintf(value
, sizeof(value
), "%g",
3454 cparam
->current
.custom_real
);
3455 cgiSetArray("PARAMVALUE", m
, value
);
3458 case PPD_CUSTOM_INT
:
3459 snprintf(value
, sizeof(value
), "%d",
3460 cparam
->current
.custom_int
);
3461 cgiSetArray("PARAMVALUE", m
, value
);
3464 case PPD_CUSTOM_PASSCODE
:
3465 case PPD_CUSTOM_PASSWORD
:
3466 if (cparam
->current
.custom_password
)
3467 cgiSetArray("PARAMVALUE", m
,
3468 cparam
->current
.custom_password
);
3470 cgiSetArray("PARAMVALUE", m
, "");
3471 cgiSetArray("INPUTTYPE", m
, "password");
3474 case PPD_CUSTOM_STRING
:
3475 if (cparam
->current
.custom_string
)
3476 cgiSetArray("PARAMVALUE", m
,
3477 cparam
->current
.custom_string
);
3479 cgiSetArray("PARAMVALUE", m
, "");
3486 cgiSetArray("PARAMS", m
, "Units");
3487 cgiSetArray("PARAMTEXT", m
, cgiText(_("Units")));
3488 cgiSetArray("PARAMVALUE", m
, units
);
3492 cgiSetVariable("ISCUSTOM", "0");
3496 case PPD_UI_BOOLEAN
:
3497 cgiCopyTemplateLang("option-boolean.tmpl");
3499 case PPD_UI_PICKONE
:
3500 cgiCopyTemplateLang("option-pickone.tmpl");
3502 case PPD_UI_PICKMANY
:
3503 cgiCopyTemplateLang("option-pickmany.tmpl");
3508 cgiCopyTemplateLang("option-trailer.tmpl");
3512 if ((attr
= ippFindAttribute(response
, "job-sheets-supported",
3513 IPP_TAG_ZERO
)) != NULL
)
3516 * Add the job sheets options...
3519 cgiSetVariable("GROUP_ID", "CUPS_BANNERS");
3520 cgiSetVariable("GROUP", cgiText(_("Banners")));
3521 cgiCopyTemplateLang("option-header.tmpl");
3523 cgiSetSize("CHOICES", attr
->num_values
);
3524 cgiSetSize("TEXT", attr
->num_values
);
3525 for (k
= 0; k
< attr
->num_values
; k
++)
3527 cgiSetArray("CHOICES", k
, attr
->values
[k
].string
.text
);
3528 cgiSetArray("TEXT", k
, attr
->values
[k
].string
.text
);
3531 attr
= ippFindAttribute(response
, "job-sheets-default", IPP_TAG_ZERO
);
3533 cgiSetVariable("KEYWORD", "job_sheets_start");
3534 cgiSetVariable("KEYTEXT",
3535 /* TRANSLATORS: Banner/cover sheet before the print job. */
3536 cgiText(_("Starting Banner")));
3537 cgiSetVariable("DEFCHOICE", attr
!= NULL
?
3538 attr
->values
[0].string
.text
: "");
3540 cgiCopyTemplateLang("option-pickone.tmpl");
3542 cgiSetVariable("KEYWORD", "job_sheets_end");
3543 cgiSetVariable("KEYTEXT",
3544 /* TRANSLATORS: Banner/cover sheet after the print job. */
3545 cgiText(_("Ending Banner")));
3546 cgiSetVariable("DEFCHOICE", attr
!= NULL
&& attr
->num_values
> 1 ?
3547 attr
->values
[1].string
.text
: "");
3549 cgiCopyTemplateLang("option-pickone.tmpl");
3551 cgiCopyTemplateLang("option-trailer.tmpl");
3554 if (ippFindAttribute(response
, "printer-error-policy-supported",
3556 ippFindAttribute(response
, "printer-op-policy-supported",
3560 * Add the error and operation policy options...
3563 cgiSetVariable("GROUP_ID", "CUPS_POLICIES");
3564 cgiSetVariable("GROUP", cgiText(_("Policies")));
3565 cgiCopyTemplateLang("option-header.tmpl");
3571 attr
= ippFindAttribute(response
, "printer-error-policy-supported",
3576 cgiSetSize("CHOICES", attr
->num_values
);
3577 cgiSetSize("TEXT", attr
->num_values
);
3578 for (k
= 0; k
< attr
->num_values
; k
++)
3580 cgiSetArray("CHOICES", k
, attr
->values
[k
].string
.text
);
3581 cgiSetArray("TEXT", k
, attr
->values
[k
].string
.text
);
3584 attr
= ippFindAttribute(response
, "printer-error-policy",
3587 cgiSetVariable("KEYWORD", "printer_error_policy");
3588 cgiSetVariable("KEYTEXT", cgiText(_("Error Policy")));
3589 cgiSetVariable("DEFCHOICE", attr
== NULL
?
3590 "" : attr
->values
[0].string
.text
);
3593 cgiCopyTemplateLang("option-pickone.tmpl");
3596 * Operation policy...
3599 attr
= ippFindAttribute(response
, "printer-op-policy-supported",
3604 cgiSetSize("CHOICES", attr
->num_values
);
3605 cgiSetSize("TEXT", attr
->num_values
);
3606 for (k
= 0; k
< attr
->num_values
; k
++)
3608 cgiSetArray("CHOICES", k
, attr
->values
[k
].string
.text
);
3609 cgiSetArray("TEXT", k
, attr
->values
[k
].string
.text
);
3612 attr
= ippFindAttribute(response
, "printer-op-policy", IPP_TAG_ZERO
);
3614 cgiSetVariable("KEYWORD", "printer_op_policy");
3615 cgiSetVariable("KEYTEXT", cgiText(_("Operation Policy")));
3616 cgiSetVariable("DEFCHOICE", attr
== NULL
?
3617 "" : attr
->values
[0].string
.text
);
3619 cgiCopyTemplateLang("option-pickone.tmpl");
3622 cgiCopyTemplateLang("option-trailer.tmpl");
3626 * Binary protocol support...
3629 if ((attr
= ippFindAttribute(response
, "port-monitor-supported",
3630 IPP_TAG_NAME
)) != NULL
&& attr
->num_values
> 1)
3632 cgiSetVariable("GROUP_ID", "CUPS_PORT_MONITOR");
3633 cgiSetVariable("GROUP", cgiText(_("Port Monitor")));
3635 cgiSetSize("CHOICES", attr
->num_values
);
3636 cgiSetSize("TEXT", attr
->num_values
);
3638 for (i
= 0; i
< attr
->num_values
; i
++)
3640 cgiSetArray("CHOICES", i
, attr
->values
[i
].string
.text
);
3641 cgiSetArray("TEXT", i
, attr
->values
[i
].string
.text
);
3644 attr
= ippFindAttribute(response
, "port-monitor", IPP_TAG_NAME
);
3645 cgiSetVariable("KEYWORD", "port_monitor");
3646 cgiSetVariable("KEYTEXT", cgiText(_("Port Monitor")));
3647 cgiSetVariable("DEFCHOICE", attr
? attr
->values
[0].string
.text
: "none");
3649 cgiCopyTemplateLang("option-header.tmpl");
3650 cgiCopyTemplateLang("option-pickone.tmpl");
3651 cgiCopyTemplateLang("option-trailer.tmpl");
3654 cgiCopyTemplateLang("set-printer-options-trailer.tmpl");
3657 ippDelete(response
);
3662 * Set default options...
3665 fputs("DEBUG: Setting options...\n", stderr
);
3669 out
= cupsTempFile2(tempfile
, sizeof(tempfile
));
3670 in
= cupsFileOpen(filename
, "r");
3674 cgiSetVariable("ERROR", strerror(errno
));
3675 cgiStartHTML(cgiText(_("Set Printer Options")));
3676 cgiCopyTemplateLang("error.tmpl");
3692 while (cupsFileGets(in
, line
, sizeof(line
)))
3694 if (!strncmp(line
, "*cupsProtocol:", 14))
3696 else if (strncmp(line
, "*Default", 8))
3697 cupsFilePrintf(out
, "%s\n", line
);
3701 * Get default option name...
3704 strlcpy(keyword
, line
+ 8, sizeof(keyword
));
3706 for (keyptr
= keyword
; *keyptr
; keyptr
++)
3707 if (*keyptr
== ':' || isspace(*keyptr
& 255))
3712 if (!strcmp(keyword
, "PageRegion") ||
3713 !strcmp(keyword
, "PaperDimension") ||
3714 !strcmp(keyword
, "ImageableArea"))
3715 var
= get_option_value(ppd
, "PageSize", value
, sizeof(value
));
3717 var
= get_option_value(ppd
, keyword
, value
, sizeof(value
));
3720 cupsFilePrintf(out
, "%s\n", line
);
3722 cupsFilePrintf(out
, "*Default%s: %s\n", keyword
, var
);
3732 * Make sure temporary filename is cleared when there is no PPD...
3739 * Build a CUPS_ADD_MODIFY_CLASS/PRINTER request, which requires the
3740 * following attributes:
3742 * attributes-charset
3743 * attributes-natural-language
3745 * job-sheets-default
3746 * printer-error-policy
3751 request
= ippNewRequest(is_class
? CUPS_ADD_MODIFY_CLASS
:
3752 CUPS_ADD_MODIFY_PRINTER
);
3754 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
3757 attr
= ippAddStrings(request
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
3758 "job-sheets-default", 2, NULL
, NULL
);
3759 attr
->values
[0].string
.text
= _cupsStrAlloc(cgiGetVariable("job_sheets_start"));
3760 attr
->values
[1].string
.text
= _cupsStrAlloc(cgiGetVariable("job_sheets_end"));
3762 if ((var
= cgiGetVariable("printer_error_policy")) != NULL
)
3763 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
3764 "printer-error-policy", NULL
, var
);
3766 if ((var
= cgiGetVariable("printer_op_policy")) != NULL
)
3767 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
3768 "printer-op-policy", NULL
, var
);
3770 if ((var
= cgiGetVariable("port_monitor")) != NULL
)
3771 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_NAME
,
3772 "port-monitor", NULL
, var
);
3775 * Do the request and get back a response...
3779 ippDelete(cupsDoFileRequest(http
, request
, "/admin/", tempfile
));
3781 ippDelete(cupsDoRequest(http
, request
, "/admin/"));
3783 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
3785 puts("Status: 401\n");
3788 else if (cupsLastError() > IPP_OK_CONFLICT
)
3790 cgiStartHTML(title
);
3791 cgiShowIPPError(_("Unable to set options"));
3796 * Redirect successful updates back to the printer page...
3799 char refresh
[1024]; /* Refresh URL */
3802 cgiFormEncode(uri
, printer
, sizeof(uri
));
3803 snprintf(refresh
, sizeof(refresh
), "5;URL=/admin/?OP=redirect&URL=/%s/%s",
3804 is_class
? "classes" : "printers", uri
);
3805 cgiSetVariable("refresh_page", refresh
);
3807 cgiStartHTML(title
);
3809 cgiCopyTemplateLang("printer-configured.tmpl");
3824 * 'do_set_sharing()' - Set printer-is-shared value.
3828 do_set_sharing(http_t
*http
) /* I - HTTP connection */
3830 ipp_t
*request
, /* IPP request */
3831 *response
; /* IPP response */
3832 char uri
[HTTP_MAX_URI
]; /* Printer URI */
3833 const char *printer
, /* Printer name */
3834 *is_class
, /* Is a class? */
3835 *shared
; /* Sharing value */
3838 is_class
= cgiGetVariable("IS_CLASS");
3839 printer
= cgiGetVariable("PRINTER_NAME");
3840 shared
= cgiGetVariable("SHARED");
3842 if (!printer
|| !shared
)
3844 cgiSetVariable("ERROR", cgiText(_("Missing form variable")));
3845 cgiStartHTML(cgiText(_("Set Publishing")));
3846 cgiCopyTemplateLang("error.tmpl");
3852 * Build a CUPS-Add-Printer/CUPS-Add-Class request, which requires the
3853 * following attributes:
3855 * attributes-charset
3856 * attributes-natural-language
3861 request
= ippNewRequest(is_class
? CUPS_ADD_CLASS
: CUPS_ADD_PRINTER
);
3863 httpAssembleURIf(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), "ipp", NULL
,
3864 "localhost", 0, is_class
? "/classes/%s" : "/printers/%s",
3866 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
3869 ippAddBoolean(request
, IPP_TAG_OPERATION
, "printer-is-shared", (char)atoi(shared
));
3872 * Do the request and get back a response...
3875 if ((response
= cupsDoRequest(http
, request
, "/admin/")) != NULL
)
3877 cgiSetIPPVars(response
, NULL
, NULL
, NULL
, 0);
3879 ippDelete(response
);
3882 if (cupsLastError() == IPP_NOT_AUTHORIZED
)
3884 puts("Status: 401\n");
3887 else if (cupsLastError() > IPP_OK_CONFLICT
)
3889 cgiStartHTML(cgiText(_("Set Publishing")));
3890 cgiShowIPPError(_("Unable to change printer-is-shared attribute"));
3895 * Redirect successful updates back to the printer page...
3898 char url
[1024], /* Printer/class URL */
3899 refresh
[1024]; /* Refresh URL */
3902 cgiRewriteURL(uri
, url
, sizeof(url
), NULL
);
3903 cgiFormEncode(uri
, url
, sizeof(uri
));
3904 snprintf(refresh
, sizeof(refresh
), "5;URL=/admin/?OP=redirect&URL=%s", uri
);
3905 cgiSetVariable("refresh_page", refresh
);
3907 cgiStartHTML(cgiText(_("Set Publishing")));
3908 cgiCopyTemplateLang(is_class
? "class-modified.tmpl" :
3909 "printer-modified.tmpl");
3917 * 'get_option_value()' - Return the value of an option.
3919 * This function also handles generation of custom option values.
3922 static char * /* O - Value string or NULL on error */
3924 ppd_file_t
*ppd
, /* I - PPD file */
3925 const char *name
, /* I - Option name */
3926 char *buffer
, /* I - String buffer */
3927 size_t bufsize
) /* I - Size of buffer */
3929 char *bufptr
, /* Pointer into buffer */
3930 *bufend
; /* End of buffer */
3931 ppd_coption_t
*coption
; /* Custom option */
3932 ppd_cparam_t
*cparam
; /* Current custom parameter */
3933 char keyword
[256]; /* Parameter name */
3934 const char *val
, /* Parameter value */
3935 *uval
; /* Units value */
3936 long integer
; /* Integer value */
3937 double number
, /* Number value */
3938 number_points
; /* Number in points */
3942 * See if we have a custom option choice...
3945 if ((val
= cgiGetVariable(name
)) == NULL
)
3953 else if (_cups_strcasecmp(val
, "Custom") ||
3954 (coption
= ppdFindCustomOption(ppd
, name
)) == NULL
)
3957 * Not a custom choice...
3960 strlcpy(buffer
, val
, bufsize
);
3965 * OK, we have a custom option choice, format it...
3970 if (!strcmp(coption
->keyword
, "PageSize"))
3972 const char *lval
; /* Length string value */
3973 double width
, /* Width value */
3974 width_points
, /* Width in points */
3975 length
, /* Length value */
3976 length_points
; /* Length in points */
3979 val
= cgiGetVariable("PageSize.Width");
3980 lval
= cgiGetVariable("PageSize.Height");
3981 uval
= cgiGetVariable("PageSize.Units");
3983 if (!val
|| !lval
|| !uval
||
3984 (width
= strtod(val
, NULL
)) == 0.0 ||
3985 (length
= strtod(lval
, NULL
)) == 0.0 ||
3986 (strcmp(uval
, "pt") && strcmp(uval
, "in") && strcmp(uval
, "ft") &&
3987 strcmp(uval
, "cm") && strcmp(uval
, "mm") && strcmp(uval
, "m")))
3990 width_points
= get_points(width
, uval
);
3991 length_points
= get_points(length
, uval
);
3993 if (width_points
< ppd
->custom_min
[0] ||
3994 width_points
> ppd
->custom_max
[0] ||
3995 length_points
< ppd
->custom_min
[1] ||
3996 length_points
> ppd
->custom_max
[1])
3999 snprintf(buffer
, bufsize
, "Custom.%gx%g%s", width
, length
, uval
);
4001 else if (cupsArrayCount(coption
->params
) == 1)
4003 cparam
= ppdFirstCustomParam(coption
);
4004 snprintf(keyword
, sizeof(keyword
), "%s.%s", coption
->keyword
, cparam
->name
);
4006 if ((val
= cgiGetVariable(keyword
)) == NULL
)
4009 switch (cparam
->type
)
4011 case PPD_CUSTOM_CURVE
:
4012 case PPD_CUSTOM_INVCURVE
:
4013 case PPD_CUSTOM_REAL
:
4014 if ((number
= strtod(val
, NULL
)) == 0.0 ||
4015 number
< cparam
->minimum
.custom_real
||
4016 number
> cparam
->maximum
.custom_real
)
4019 snprintf(buffer
, bufsize
, "Custom.%g", number
);
4022 case PPD_CUSTOM_INT
:
4023 if (!*val
|| (integer
= strtol(val
, NULL
, 10)) == LONG_MIN
||
4024 integer
== LONG_MAX
||
4025 integer
< cparam
->minimum
.custom_int
||
4026 integer
> cparam
->maximum
.custom_int
)
4029 snprintf(buffer
, bufsize
, "Custom.%ld", integer
);
4032 case PPD_CUSTOM_POINTS
:
4033 snprintf(keyword
, sizeof(keyword
), "%s.Units", coption
->keyword
);
4035 if ((number
= strtod(val
, NULL
)) == 0.0 ||
4036 (uval
= cgiGetVariable(keyword
)) == NULL
||
4037 (strcmp(uval
, "pt") && strcmp(uval
, "in") && strcmp(uval
, "ft") &&
4038 strcmp(uval
, "cm") && strcmp(uval
, "mm") && strcmp(uval
, "m")))
4041 number_points
= get_points(number
, uval
);
4042 if (number_points
< cparam
->minimum
.custom_points
||
4043 number_points
> cparam
->maximum
.custom_points
)
4046 snprintf(buffer
, bufsize
, "Custom.%g%s", number
, uval
);
4049 case PPD_CUSTOM_PASSCODE
:
4050 for (uval
= val
; *uval
; uval
++)
4051 if (!isdigit(*uval
& 255))
4054 case PPD_CUSTOM_PASSWORD
:
4055 case PPD_CUSTOM_STRING
:
4056 integer
= (long)strlen(val
);
4057 if (integer
< cparam
->minimum
.custom_string
||
4058 integer
> cparam
->maximum
.custom_string
)
4061 snprintf(buffer
, bufsize
, "Custom.%s", val
);
4067 const char *prefix
= "{"; /* Prefix string */
4071 bufend
= buffer
+ bufsize
;
4073 for (cparam
= ppdFirstCustomParam(coption
);
4075 cparam
= ppdNextCustomParam(coption
))
4077 snprintf(keyword
, sizeof(keyword
), "%s.%s", coption
->keyword
,
4080 if ((val
= cgiGetVariable(keyword
)) == NULL
)
4083 snprintf(bufptr
, (size_t)(bufend
- bufptr
), "%s%s=", prefix
, cparam
->name
);
4084 bufptr
+= strlen(bufptr
);
4087 switch (cparam
->type
)
4089 case PPD_CUSTOM_CURVE
:
4090 case PPD_CUSTOM_INVCURVE
:
4091 case PPD_CUSTOM_REAL
:
4092 if ((number
= strtod(val
, NULL
)) == 0.0 ||
4093 number
< cparam
->minimum
.custom_real
||
4094 number
> cparam
->maximum
.custom_real
)
4097 snprintf(bufptr
, (size_t)(bufend
- bufptr
), "%g", number
);
4100 case PPD_CUSTOM_INT
:
4101 if (!*val
|| (integer
= strtol(val
, NULL
, 10)) == LONG_MIN
||
4102 integer
== LONG_MAX
||
4103 integer
< cparam
->minimum
.custom_int
||
4104 integer
> cparam
->maximum
.custom_int
)
4107 snprintf(bufptr
, (size_t)(bufend
- bufptr
), "%ld", integer
);
4110 case PPD_CUSTOM_POINTS
:
4111 snprintf(keyword
, sizeof(keyword
), "%s.Units", coption
->keyword
);
4113 if ((number
= strtod(val
, NULL
)) == 0.0 ||
4114 (uval
= cgiGetVariable(keyword
)) == NULL
||
4115 (strcmp(uval
, "pt") && strcmp(uval
, "in") &&
4116 strcmp(uval
, "ft") && strcmp(uval
, "cm") &&
4117 strcmp(uval
, "mm") && strcmp(uval
, "m")))
4120 number_points
= get_points(number
, uval
);
4121 if (number_points
< cparam
->minimum
.custom_points
||
4122 number_points
> cparam
->maximum
.custom_points
)
4125 snprintf(bufptr
, (size_t)(bufend
- bufptr
), "%g%s", number
, uval
);
4128 case PPD_CUSTOM_PASSCODE
:
4129 for (uval
= val
; *uval
; uval
++)
4130 if (!isdigit(*uval
& 255))
4133 case PPD_CUSTOM_PASSWORD
:
4134 case PPD_CUSTOM_STRING
:
4135 integer
= (long)strlen(val
);
4136 if (integer
< cparam
->minimum
.custom_string
||
4137 integer
> cparam
->maximum
.custom_string
)
4140 if ((bufptr
+ 2) > bufend
)
4146 while (*val
&& bufptr
< bufend
)
4148 if (*val
== '\\' || *val
== '\"')
4150 if ((bufptr
+ 1) >= bufend
)
4159 if (bufptr
>= bufend
)
4168 bufptr
+= strlen(bufptr
);
4171 if (bufptr
== buffer
|| (bufend
- bufptr
) < 2)
4174 memcpy(bufptr
, "}", 2);
4182 * 'get_points()' - Get a value in points.
4185 static double /* O - Number in points */
4186 get_points(double number
, /* I - Original number */
4187 const char *uval
) /* I - Units */
4189 if (!strcmp(uval
, "mm")) /* Millimeters */
4190 return (number
* 72.0 / 25.4);
4191 else if (!strcmp(uval
, "cm")) /* Centimeters */
4192 return (number
* 72.0 / 2.54);
4193 else if (!strcmp(uval
, "in")) /* Inches */
4194 return (number
* 72.0);
4195 else if (!strcmp(uval
, "ft")) /* Feet */
4196 return (number
* 72.0 * 12.0);
4197 else if (!strcmp(uval
, "m")) /* Meters */
4198 return (number
* 72.0 / 0.0254);
4205 * 'get_printer_ppd()' - Get an IPP Everywhere PPD file for the given URI.
4208 static char * /* O - Filename or NULL */
4209 get_printer_ppd(const char *uri
, /* I - Printer URI */
4210 char *buffer
, /* I - Filename buffer */
4211 size_t bufsize
) /* I - Size of filename buffer */
4213 http_t
*http
; /* Connection to printer */
4214 ipp_t
*request
, /* Get-Printer-Attributes request */
4215 *response
; /* Get-Printer-Attributes response */
4216 char resolved
[1024], /* Resolved URI */
4217 scheme
[32], /* URI scheme */
4218 userpass
[256], /* Username:password */
4219 host
[256], /* Hostname */
4220 resource
[256]; /* Resource path */
4221 int port
; /* Port number */
4225 * Connect to the printer...
4228 if (strstr(uri
, "._tcp"))
4234 if (!_httpResolveURI(uri
, resolved
, sizeof(resolved
), _HTTP_RESOLVE_DEFAULT
, NULL
, NULL
))
4236 fprintf(stderr
, "ERROR: Unable to resolve \"%s\".\n", uri
);
4243 if (httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), host
, sizeof(host
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
4245 fprintf(stderr
, "ERROR: Bad printer URI \"%s\".\n", uri
);
4249 http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, !strcmp(scheme
, "ipps") ? HTTP_ENCRYPTION_ALWAYS
: HTTP_ENCRYPTION_IF_REQUESTED
, 1, 30000, NULL
);
4252 fprintf(stderr
, "ERROR: Unable to connect to \"%s:%d\": %s\n", host
, port
, cupsLastErrorString());
4257 * Send a Get-Printer-Attributes request...
4260 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
4261 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, uri
);
4262 response
= cupsDoRequest(http
, request
, resource
);
4264 if (!_ppdCreateFromIPP(buffer
, bufsize
, response
))
4265 fprintf(stderr
, "ERROR: Unable to create PPD file: %s\n", strerror(errno
));
4267 ippDelete(response
);