/*
- * "$Id: admin.c 6378 2007-03-21 07:18:18Z mike $"
+ * "$Id: admin.c 6440 2007-04-03 23:17:17Z mike $"
*
* Administration CGI for the Common UNIX Printing System (CUPS).
*
* do_am_class() - Add or modify a class.
* do_am_printer() - Add or modify a printer.
* do_cancel_subscription() - Cancel a subscription.
- * do_config_printer() - Configure the default options for a printer.
* do_config_server() - Configure server settings.
* do_delete_class() - Delete a class...
* do_delete_printer() - Delete a printer...
* do_export() - Export printers to Samba...
+ * do_list_printers() - List available printers...
* do_menu() - Show the main menu...
* do_printer_op() - Do a printer operation.
* do_set_allowed_users() - Set the allowed/denied users for a queue.
+ * do_set_options() - Configure the default options for a queue.
* do_set_sharing() - Set printer-is-shared value...
* match_string() - Return the number of matching characters.
*/
static void do_am_class(http_t *http, int modify);
static void do_am_printer(http_t *http, int modify);
static void do_cancel_subscription(http_t *http);
-static void do_config_printer(http_t *http);
+static void do_set_options(http_t *http, int is_class);
static void do_config_server(http_t *http);
static void do_delete_class(http_t *http);
static void do_delete_printer(http_t *http);
static void do_export(http_t *http);
+static void do_list_printers(http_t *http);
static void do_menu(http_t *http);
static void do_printer_op(http_t *http,
ipp_op_t op, const char *title);
do_printer_op(http, CUPS_SET_DEFAULT, cgiText(_("Set As Default")));
else if (!strcmp(op, "set-sharing"))
do_set_sharing(http);
+ else if (!strcmp(op, "list-available-printers"))
+ do_list_printers(http);
else if (!strcmp(op, "add-class"))
do_am_class(http, 0);
else if (!strcmp(op, "add-printer"))
do_delete_class(http);
else if (!strcmp(op, "delete-printer"))
do_delete_printer(http);
+ else if (!strcmp(op, "set-class-options"))
+ do_set_options(http, 1);
else if (!strcmp(op, "set-printer-options"))
- do_config_printer(http);
+ do_set_options(http, 0);
else if (!strcmp(op, "config-server"))
do_config_server(http);
else if (!strcmp(op, "export-samba"))
/*
- * 'do_config_printer()' - Configure the default options for a printer.
+ * 'do_config_server()' - Configure server settings.
*/
static void
-do_config_printer(http_t *http) /* I - HTTP connection */
+do_config_server(http_t *http) /* I - HTTP connection */
{
- int i, j, k, m; /* Looping vars */
- int have_options; /* Have options? */
- ipp_t *request, /* IPP request */
- *response; /* IPP response */
- ipp_attribute_t *attr; /* IPP attribute */
- char uri[HTTP_MAX_URI]; /* Job URI */
- const char *var; /* Variable value */
- const char *printer; /* Printer printer name */
- const char *filename; /* PPD filename */
- char tempfile[1024]; /* Temporary filename */
- cups_file_t *in, /* Input file */
- *out; /* Output file */
- char line[1024]; /* Line from PPD file */
- char keyword[1024], /* Keyword from Default line */
- *keyptr; /* Pointer into keyword... */
- ppd_file_t *ppd; /* PPD file */
- ppd_group_t *group; /* Option group */
- ppd_option_t *option; /* Option */
- ppd_attr_t *protocol; /* cupsProtocol attribute */
- const char *title; /* Page title */
-
-
- title = cgiText(_("Set Printer Options"));
-
- fprintf(stderr, "DEBUG: do_config_printer(http=%p)\n", http);
-
- /*
- * Get the printer name...
- */
-
- if ((printer = cgiGetVariable("PRINTER_NAME")) != NULL)
- httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
- "localhost", 0, "/printers/%s", printer);
- else
+ if (cgiIsPOST() && !cgiGetVariable("CUPSDCONF"))
{
- cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
- cgiStartHTML(title);
- cgiCopyTemplateLang("error.tmpl");
- cgiEndHTML();
- return;
- }
+ /*
+ * Save basic setting changes...
+ */
- fprintf(stderr, "DEBUG: printer=\"%s\", uri=\"%s\"...\n", printer, uri);
+ int num_settings; /* Number of server settings */
+ cups_option_t *settings; /* Server settings */
+ const char *debug_logging, /* DEBUG_LOGGING value */
+ *remote_admin, /* REMOTE_ADMIN value */
+ *remote_any, /* REMOTE_ANY value */
+ *remote_printers,
+ /* REMOTE_PRINTERS value */
+ *share_printers,/* SHARE_PRINTERS value */
+#ifdef HAVE_GSSAPI
+ *default_auth_type,
+ /* DefaultAuthType value */
+#endif /* HAVE_GSSAPI */
+ *user_cancel_any;
+ /* USER_CANCEL_ANY value */
- /*
- * Get the PPD file...
- */
- if ((filename = cupsGetPPD2(http, printer)) == NULL)
- {
- fputs("DEBUG: No PPD file!?!\n", stderr);
+ /*
+ * Get the checkbox values from the form...
+ */
- cgiStartHTML(title);
- cgiShowIPPError(_("Unable to get PPD file!"));
- cgiEndHTML();
- return;
- }
+ debug_logging = cgiGetVariable("DEBUG_LOGGING") ? "1" : "0";
+ remote_admin = cgiGetVariable("REMOTE_ADMIN") ? "1" : "0";
+ remote_any = cgiGetVariable("REMOTE_ANY") ? "1" : "0";
+ remote_printers = cgiGetVariable("REMOTE_PRINTERS") ? "1" : "0";
+ share_printers = cgiGetVariable("SHARE_PRINTERS") ? "1" : "0";
+ user_cancel_any = cgiGetVariable("USER_CANCEL_ANY") ? "1" : "0";
+#ifdef HAVE_GSSAPI
+ default_auth_type = cgiGetVariable("KERBEROS") ? "Negotiate" : "Basic";
- fprintf(stderr, "DEBUG: Got PPD file: \"%s\"\n", filename);
+ fprintf(stderr, "DEBUG: DefaultAuthType %s\n", default_auth_type);
+#endif /* HAVE_GSSAPI */
- if ((ppd = ppdOpenFile(filename)) == NULL)
- {
- cgiSetVariable("ERROR", ppdErrorString(ppdLastError(&i)));
- cgiSetVariable("MESSAGE", cgiText(_("Unable to open PPD file:")));
- cgiStartHTML(title);
- cgiCopyTemplateLang("error.tmpl");
- cgiEndHTML();
- return;
- }
+ /*
+ * Get the current server settings...
+ */
- if (cgiGetVariable("job_sheets_start") != NULL ||
- cgiGetVariable("job_sheets_end") != NULL)
- have_options = 1;
- else
- have_options = 0;
+ if (!cupsAdminGetServerSettings(http, &num_settings, &settings))
+ {
+ cgiStartHTML(cgiText(_("Change Settings")));
+ cgiSetVariable("MESSAGE",
+ cgiText(_("Unable to change server settings:")));
+ cgiSetVariable("ERROR", cupsLastErrorString());
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
+ return;
+ }
- ppdMarkDefaults(ppd);
+ /*
+ * See if the settings have changed...
+ */
+
+ if (strcmp(debug_logging, cupsGetOption(CUPS_SERVER_DEBUG_LOGGING,
+ num_settings, settings)) ||
+ strcmp(remote_admin, cupsGetOption(CUPS_SERVER_REMOTE_ADMIN,
+ num_settings, settings)) ||
+ strcmp(remote_any, cupsGetOption(CUPS_SERVER_REMOTE_ANY,
+ num_settings, settings)) ||
+ strcmp(remote_printers, cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS,
+ num_settings, settings)) ||
+ strcmp(share_printers, cupsGetOption(CUPS_SERVER_SHARE_PRINTERS,
+ num_settings, settings)) ||
+#ifdef HAVE_GSSAPI
+ !cupsGetOption("DefaultAuthType", num_settings, settings) ||
+ strcmp(default_auth_type, cupsGetOption("DefaultAuthType",
+ num_settings, settings)) ||
+#endif /* HAVE_GSSAPI */
+ strcmp(user_cancel_any, cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY,
+ num_settings, settings)))
+ {
+ /*
+ * Settings *have* changed, so save the changes...
+ */
- DEBUG_printf(("<P>ppd->num_groups = %d\n"
- "<UL>\n", ppd->num_groups));
+ cupsFreeOptions(num_settings, settings);
- for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
- {
- DEBUG_printf(("<LI>%s<UL>\n", group->text));
+ num_settings = 0;
+ num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING,
+ debug_logging, num_settings, &settings);
+ num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN,
+ remote_admin, num_settings, &settings);
+ num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ANY,
+ remote_any, num_settings, &settings);
+ num_settings = cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS,
+ remote_printers, num_settings, &settings);
+ num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS,
+ share_printers, num_settings, &settings);
+ num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY,
+ user_cancel_any, num_settings, &settings);
+#ifdef HAVE_GSSAPI
+ num_settings = cupsAddOption("DefaultAuthType", default_auth_type,
+ num_settings, &settings);
+#endif /* HAVE_GSSAPI */
- for (j = group->num_options, option = group->options;
- j > 0;
- j --, option ++)
- if ((var = cgiGetVariable(option->keyword)) != NULL)
+ if (!cupsAdminSetServerSettings(http, num_settings, settings))
{
- DEBUG_printf(("<LI>%s = \"%s\"</LI>\n", option->keyword, var));
- have_options = 1;
- ppdMarkOption(ppd, option->keyword, var);
+ cgiStartHTML(cgiText(_("Change Settings")));
+ cgiSetVariable("MESSAGE",
+ cgiText(_("Unable to change server settings:")));
+ cgiSetVariable("ERROR", cupsLastErrorString());
+ cgiCopyTemplateLang("error.tmpl");
}
-#ifdef DEBUG
else
- printf("<LI>%s not defined!</LI>\n", option->keyword);
-#endif /* DEBUG */
+ {
+ cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect");
+ cgiStartHTML(cgiText(_("Change Settings")));
+ cgiCopyTemplateLang("restart.tmpl");
+ }
+ }
+ else
+ {
+ /*
+ * No changes...
+ */
- DEBUG_puts("</UL></LI>");
- }
+ cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect");
+ cgiStartHTML(cgiText(_("Change Settings")));
+ cgiCopyTemplateLang("norestart.tmpl");
+ }
- DEBUG_printf(("</UL>\n"
- "<P>ppdConflicts(ppd) = %d\n", ppdConflicts(ppd)));
+ cupsFreeOptions(num_settings, settings);
- if (!have_options || ppdConflicts(ppd))
+ cgiEndHTML();
+ }
+ else if (cgiIsPOST())
{
/*
- * Show the options to the user...
+ * Save hand-edited config file...
*/
- fputs("DEBUG: Showing options...\n", stderr);
+ http_status_t status; /* PUT status */
+ char tempfile[1024]; /* Temporary new cupsd.conf */
+ int tempfd; /* Temporary file descriptor */
+ cups_file_t *temp; /* Temporary file */
+ const char *start, /* Start of line */
+ *end; /* End of line */
- ppdLocalize(ppd);
- cgiStartHTML(cgiText(_("Set Printer Options")));
- cgiCopyTemplateLang("set-printer-options-header.tmpl");
+ /*
+ * Create a temporary file for the new cupsd.conf file...
+ */
- if (ppdConflicts(ppd))
+ if ((tempfd = cupsTempFd(tempfile, sizeof(tempfile))) < 0)
{
- for (i = ppd->num_groups, k = 0, group = ppd->groups;
- i > 0;
- i --, group ++)
- for (j = group->num_options, option = group->options;
- j > 0;
- j --, option ++)
- if (option->conflicted)
- {
- cgiSetArray("ckeyword", k, option->keyword);
- cgiSetArray("ckeytext", k, option->text);
- k ++;
- }
-
- cgiCopyTemplateLang("option-conflict.tmpl");
+ cgiStartHTML(cgiText(_("Edit Configuration File")));
+ cgiSetVariable("MESSAGE", cgiText(_("Unable to create temporary file:")));
+ cgiSetVariable("ERROR", strerror(errno));
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
+
+ perror(tempfile);
+ return;
}
- for (i = ppd->num_groups, group = ppd->groups;
- i > 0;
- i --, group ++)
+ if ((temp = cupsFileOpenFd(tempfd, "w")) == NULL)
{
- if (!strcmp(group->name, "InstallableOptions"))
- cgiSetVariable("GROUP", cgiText(_("Options Installed")));
- else
- cgiSetVariable("GROUP", group->text);
-
- cgiCopyTemplateLang("option-header.tmpl");
+ cgiStartHTML(cgiText(_("Edit Configuration File")));
+ cgiSetVariable("MESSAGE", cgiText(_("Unable to create temporary file:")));
+ cgiSetVariable("ERROR", strerror(errno));
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
- for (j = group->num_options, option = group->options;
- j > 0;
- j --, option ++)
- {
- if (!strcmp(option->keyword, "PageRegion"))
- continue;
+ perror(tempfile);
+ close(tempfd);
+ unlink(tempfile);
+ return;
+ }
- cgiSetVariable("KEYWORD", option->keyword);
- cgiSetVariable("KEYTEXT", option->text);
-
- if (option->conflicted)
- cgiSetVariable("CONFLICTED", "1");
- else
- cgiSetVariable("CONFLICTED", "0");
+ /*
+ * Copy the cupsd.conf text from the form variable...
+ */
- cgiSetSize("CHOICES", 0);
- cgiSetSize("TEXT", 0);
- for (k = 0, m = 0; k < option->num_choices; k ++)
- {
- /*
- * Hide custom option values...
- */
+ start = cgiGetVariable("CUPSDCONF");
+ while (start)
+ {
+ if ((end = strstr(start, "\r\n")) == NULL)
+ if ((end = strstr(start, "\n")) == NULL)
+ end = start + strlen(start);
- if (!strcmp(option->choices[k].choice, "Custom"))
- continue;
+ cupsFileWrite(temp, start, end - start);
+ cupsFilePutChar(temp, '\n');
- cgiSetArray("CHOICES", m, option->choices[k].choice);
- cgiSetArray("TEXT", m, option->choices[k].text);
+ if (*end == '\r')
+ start = end + 2;
+ else if (*end == '\n')
+ start = end + 1;
+ else
+ start = NULL;
+ }
- m ++;
+ cupsFileClose(temp);
- if (option->choices[k].marked)
- cgiSetVariable("DEFCHOICE", option->choices[k].choice);
- }
+ /*
+ * Upload the configuration file to the server...
+ */
- switch (option->ui)
- {
- case PPD_UI_BOOLEAN :
- cgiCopyTemplateLang("option-boolean.tmpl");
- break;
- case PPD_UI_PICKONE :
- cgiCopyTemplateLang("option-pickone.tmpl");
- break;
- case PPD_UI_PICKMANY :
- cgiCopyTemplateLang("option-pickmany.tmpl");
- break;
- }
- }
+ status = cupsPutFile(http, "/admin/conf/cupsd.conf", tempfile);
- cgiCopyTemplateLang("option-trailer.tmpl");
+ if (status != HTTP_CREATED)
+ {
+ cgiSetVariable("MESSAGE",
+ cgiText(_("Unable to upload cupsd.conf file:")));
+ cgiSetVariable("ERROR", httpStatus(status));
+
+ cgiStartHTML(cgiText(_("Edit Configuration File")));
+ cgiCopyTemplateLang("error.tmpl");
+ }
+ else
+ {
+ cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect");
+
+ cgiStartHTML(cgiText(_("Edit Configuration File")));
+ cgiCopyTemplateLang("restart.tmpl");
}
+ cgiEndHTML();
+
+ unlink(tempfile);
+ }
+ else
+ {
+ struct stat info; /* cupsd.conf information */
+ cups_file_t *cupsd; /* cupsd.conf file */
+ char *buffer; /* Buffer for entire file */
+ char filename[1024]; /* Filename */
+ const char *server_root; /* Location of config files */
+
+
/*
- * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
- * following attributes:
- *
- * attributes-charset
- * attributes-natural-language
- * printer-uri
+ * Locate the cupsd.conf file...
*/
- request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+ if ((server_root = getenv("CUPS_SERVERROOT")) == NULL)
+ server_root = CUPS_SERVERROOT;
- httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
- "localhost", 0, "/printers/%s", printer);
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
- NULL, uri);
+ snprintf(filename, sizeof(filename), "%s/cupsd.conf", server_root);
/*
- * Do the request and get back a response...
+ * Figure out the size...
*/
- if ((response = cupsDoRequest(http, request, "/")) != NULL)
+ if (stat(filename, &info))
{
- if ((attr = ippFindAttribute(response, "job-sheets-supported",
- IPP_TAG_ZERO)) != NULL)
- {
- /*
- * Add the job sheets options...
- */
+ cgiStartHTML(cgiText(_("Edit Configuration File")));
+ cgiSetVariable("MESSAGE",
+ cgiText(_("Unable to access cupsd.conf file:")));
+ cgiSetVariable("ERROR", strerror(errno));
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
- cgiSetVariable("GROUP", cgiText(_("Banners")));
- cgiCopyTemplateLang("option-header.tmpl");
+ perror(filename);
+ return;
+ }
- cgiSetSize("CHOICES", attr->num_values);
- cgiSetSize("TEXT", attr->num_values);
- for (k = 0; k < attr->num_values; k ++)
- {
- cgiSetArray("CHOICES", k, attr->values[k].string.text);
- cgiSetArray("TEXT", k, attr->values[k].string.text);
- }
+ if (info.st_size > (1024 * 1024))
+ {
+ cgiStartHTML(cgiText(_("Edit Configuration File")));
+ cgiSetVariable("MESSAGE",
+ cgiText(_("Unable to access cupsd.conf file:")));
+ cgiSetVariable("ERROR",
+ cgiText(_("Unable to edit cupsd.conf files larger than "
+ "1MB!")));
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
- attr = ippFindAttribute(response, "job-sheets-default", IPP_TAG_ZERO);
+ fprintf(stderr, "ERROR: \"%s\" too large (%ld) to edit!\n", filename,
+ (long)info.st_size);
+ return;
+ }
- cgiSetVariable("KEYWORD", "job_sheets_start");
- cgiSetVariable("KEYTEXT", cgiText(_("Starting Banner")));
- cgiSetVariable("DEFCHOICE", attr == NULL ?
- "" : attr->values[0].string.text);
+ /*
+ * Open the cupsd.conf file...
+ */
- cgiCopyTemplateLang("option-pickone.tmpl");
+ if ((cupsd = cupsFileOpen(filename, "r")) == NULL)
+ {
+ /*
+ * Unable to open - log an error...
+ */
- cgiSetVariable("KEYWORD", "job_sheets_end");
- cgiSetVariable("KEYTEXT", cgiText(_("Ending Banner")));
- cgiSetVariable("DEFCHOICE", attr == NULL && attr->num_values > 1 ?
- "" : attr->values[1].string.text);
+ cgiStartHTML(cgiText(_("Edit Configuration File")));
+ cgiSetVariable("MESSAGE",
+ cgiText(_("Unable to access cupsd.conf file:")));
+ cgiSetVariable("ERROR", strerror(errno));
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
- cgiCopyTemplateLang("option-pickone.tmpl");
+ perror(filename);
+ return;
+ }
- cgiCopyTemplateLang("option-trailer.tmpl");
- }
+ /*
+ * Allocate memory and load the file into a string buffer...
+ */
- if (ippFindAttribute(response, "printer-error-policy-supported",
- IPP_TAG_ZERO) ||
- ippFindAttribute(response, "printer-op-policy-supported",
- IPP_TAG_ZERO))
- {
- /*
- * Add the error and operation policy options...
- */
+ buffer = calloc(1, info.st_size + 1);
- cgiSetVariable("GROUP", cgiText(_("Policies")));
- cgiCopyTemplateLang("option-header.tmpl");
+ cupsFileRead(cupsd, buffer, info.st_size);
+ cupsFileClose(cupsd);
- /*
- * Error policy...
- */
+ cgiSetVariable("CUPSDCONF", buffer);
+ free(buffer);
- attr = ippFindAttribute(response, "printer-error-policy-supported",
- IPP_TAG_ZERO);
+ /*
+ * Show the current config file...
+ */
- if (attr)
- {
- cgiSetSize("CHOICES", attr->num_values);
- cgiSetSize("TEXT", attr->num_values);
- for (k = 0; k < attr->num_values; k ++)
- {
- cgiSetArray("CHOICES", k, attr->values[k].string.text);
- cgiSetArray("TEXT", k, attr->values[k].string.text);
- }
+ cgiStartHTML(cgiText(_("Edit Configuration File")));
- attr = ippFindAttribute(response, "printer-error-policy",
- IPP_TAG_ZERO);
+ printf("<!-- \"%s\" -->\n", filename);
- cgiSetVariable("KEYWORD", "printer_error_policy");
- cgiSetVariable("KEYTEXT", cgiText(_("Error Policy")));
- cgiSetVariable("DEFCHOICE", attr == NULL ?
- "" : attr->values[0].string.text);
- }
+ cgiCopyTemplateLang("edit-config.tmpl");
- cgiCopyTemplateLang("option-pickone.tmpl");
+ cgiEndHTML();
+ }
+}
- /*
- * Operation policy...
- */
- attr = ippFindAttribute(response, "printer-op-policy-supported",
- IPP_TAG_ZERO);
+/*
+ * 'do_delete_class()' - Delete a class...
+ */
- if (attr)
- {
- cgiSetSize("CHOICES", attr->num_values);
- cgiSetSize("TEXT", attr->num_values);
- for (k = 0; k < attr->num_values; k ++)
- {
- cgiSetArray("CHOICES", k, attr->values[k].string.text);
- cgiSetArray("TEXT", k, attr->values[k].string.text);
- }
+static void
+do_delete_class(http_t *http) /* I - HTTP connection */
+{
+ ipp_t *request; /* IPP request */
+ char uri[HTTP_MAX_URI]; /* Job URI */
+ const char *pclass; /* Printer class name */
- attr = ippFindAttribute(response, "printer-op-policy", IPP_TAG_ZERO);
- cgiSetVariable("KEYWORD", "printer_op_policy");
- cgiSetVariable("KEYTEXT", cgiText(_("Operation Policy")));
- cgiSetVariable("DEFCHOICE", attr == NULL ?
- "" : attr->values[0].string.text);
+ /*
+ * Get form variables...
+ */
- cgiCopyTemplateLang("option-pickone.tmpl");
- }
+ if (cgiGetVariable("CONFIRM") == NULL)
+ {
+ cgiStartHTML(cgiText(_("Delete Class")));
+ cgiCopyTemplateLang("class-confirm.tmpl");
+ cgiEndHTML();
+ return;
+ }
- cgiCopyTemplateLang("option-trailer.tmpl");
- }
+ if ((pclass = cgiGetVariable("PRINTER_NAME")) != NULL)
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+ "localhost", 0, "/classes/%s", pclass);
+ else
+ {
+ cgiStartHTML(cgiText(_("Delete Class")));
+ cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
+ return;
+ }
- ippDelete(response);
- }
+ /*
+ * Build a CUPS_DELETE_CLASS request, which requires the following
+ * attributes:
+ *
+ * attributes-charset
+ * attributes-natural-language
+ * printer-uri
+ */
+
+ request = ippNewRequest(CUPS_DELETE_CLASS);
+
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ NULL, uri);
+
+ /*
+ * Do the request and get back a response...
+ */
+
+ ippDelete(cupsDoRequest(http, request, "/admin/"));
+ /*
+ * Show the results...
+ */
+
+ if (cupsLastError() <= IPP_OK_CONFLICT)
+ {
/*
- * Binary protocol support...
+ * Redirect successful updates back to the classes page...
*/
- if (ppd->protocols && strstr(ppd->protocols, "BCP"))
- {
- protocol = ppdFindAttr(ppd, "cupsProtocol", NULL);
+ cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect&URL=/classes");
+ }
- cgiSetVariable("GROUP", cgiText(_("PS Binary Protocol")));
- cgiCopyTemplateLang("option-header.tmpl");
+ cgiStartHTML(cgiText(_("Delete Class")));
- cgiSetSize("CHOICES", 2);
- cgiSetSize("TEXT", 2);
- cgiSetArray("CHOICES", 0, "None");
- cgiSetArray("TEXT", 0, cgiText(_("None")));
+ if (cupsLastError() > IPP_OK_CONFLICT)
+ cgiShowIPPError(_("Unable to delete class:"));
+ else
+ cgiCopyTemplateLang("class-deleted.tmpl");
- if (strstr(ppd->protocols, "TBCP"))
- {
- cgiSetArray("CHOICES", 1, "TBCP");
- cgiSetArray("TEXT", 1, "TBCP");
- }
- else
- {
- cgiSetArray("CHOICES", 1, "BCP");
- cgiSetArray("TEXT", 1, "BCP");
- }
+ cgiEndHTML();
+}
- cgiSetVariable("KEYWORD", "protocol");
- cgiSetVariable("KEYTEXT", cgiText(_("PS Binary Protocol")));
- cgiSetVariable("DEFCHOICE", protocol ? protocol->value : "None");
- cgiCopyTemplateLang("option-pickone.tmpl");
+/*
+ * 'do_delete_printer()' - Delete a printer...
+ */
- cgiCopyTemplateLang("option-trailer.tmpl");
- }
+static void
+do_delete_printer(http_t *http) /* I - HTTP connection */
+{
+ ipp_t *request; /* IPP request */
+ char uri[HTTP_MAX_URI]; /* Job URI */
+ const char *printer; /* Printer printer name */
- cgiCopyTemplateLang("set-printer-options-trailer.tmpl");
+
+ /*
+ * Get form variables...
+ */
+
+ if (cgiGetVariable("CONFIRM") == NULL)
+ {
+ cgiStartHTML(cgiText(_("Delete Printer")));
+ cgiCopyTemplateLang("printer-confirm.tmpl");
cgiEndHTML();
+ return;
}
+
+ if ((printer = cgiGetVariable("PRINTER_NAME")) != NULL)
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+ "localhost", 0, "/printers/%s", printer);
else
+ {
+ cgiStartHTML(cgiText(_("Delete Printer")));
+ cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
+ return;
+ }
+
+ /*
+ * Build a CUPS_DELETE_PRINTER request, which requires the following
+ * attributes:
+ *
+ * attributes-charset
+ * attributes-natural-language
+ * printer-uri
+ */
+
+ request = ippNewRequest(CUPS_DELETE_PRINTER);
+
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ NULL, uri);
+
+ /*
+ * Do the request and get back a response...
+ */
+
+ ippDelete(cupsDoRequest(http, request, "/admin/"));
+
+ /*
+ * Show the results...
+ */
+
+ if (cupsLastError() <= IPP_OK_CONFLICT)
{
/*
- * Set default options...
+ * Redirect successful updates back to the printers page...
*/
- fputs("DEBUG: Setting options...\n", stderr);
+ cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect&URL=/printers");
+ }
- out = cupsTempFile2(tempfile, sizeof(tempfile));
- in = cupsFileOpen(filename, "r");
+ cgiStartHTML(cgiText(_("Delete Printer")));
- if (!in || !out)
- {
- cgiSetVariable("ERROR", strerror(errno));
- cgiStartHTML(cgiText(_("Set Printer Options")));
- cgiCopyTemplateLang("error.tmpl");
- cgiEndHTML();
+ if (cupsLastError() > IPP_OK_CONFLICT)
+ cgiShowIPPError(_("Unable to delete printer:"));
+ else
+ cgiCopyTemplateLang("printer-deleted.tmpl");
- if (in)
- cupsFileClose(in);
+ cgiEndHTML();
+}
- if (out)
- {
- cupsFileClose(out);
- unlink(tempfile);
- }
- unlink(filename);
- return;
- }
+/*
+ * 'do_export()' - Export printers to Samba...
+ */
- while (cupsFileGets(in, line, sizeof(line)))
- {
- if (!strncmp(line, "*cupsProtocol:", 14) && cgiGetVariable("protocol"))
- continue;
- else if (strncmp(line, "*Default", 8))
- cupsFilePrintf(out, "%s\n", line);
- else
- {
- /*
- * Get default option name...
- */
+static void
+do_export(http_t *http) /* I - HTTP connection */
+{
+ int i, j; /* Looping vars */
+ ipp_t *request, /* IPP request */
+ *response; /* IPP response */
+ const char *username, /* Samba username */
+ *password, /* Samba password */
+ *export_all; /* Export all printers? */
+ int export_count, /* Number of printers to export */
+ printer_count; /* Number of available printers */
+ const char *name, /* What name to pull */
+ *dest; /* Current destination */
+ char ppd[1024]; /* PPD file */
- strlcpy(keyword, line + 8, sizeof(keyword));
- for (keyptr = keyword; *keyptr; keyptr ++)
- if (*keyptr == ':' || isspace(*keyptr & 255))
- break;
+ /*
+ * Get form data...
+ */
- *keyptr = '\0';
+ username = cgiGetVariable("USERNAME");
+ password = cgiGetVariable("PASSWORD");
+ export_all = cgiGetVariable("EXPORT_ALL");
+ export_count = cgiGetSize("EXPORT_NAME");
- if (!strcmp(keyword, "PageRegion") ||
- !strcmp(keyword, "PaperDimension") ||
- !strcmp(keyword, "ImageableArea"))
- var = cgiGetVariable("PageSize");
- else
- var = cgiGetVariable(keyword);
+ /*
+ * Get list of available printers...
+ */
- if (var != NULL)
- cupsFilePrintf(out, "*Default%s: %s\n", keyword, var);
- else
- cupsFilePrintf(out, "%s\n", line);
- }
- }
+ cgiSetSize("PRINTER_NAME", 0);
+ cgiSetSize("PRINTER_EXPORT", 0);
- if ((var = cgiGetVariable("protocol")) != NULL)
- cupsFilePrintf(out, "*cupsProtocol: %s\n", cgiGetVariable("protocol"));
+ request = ippNewRequest(CUPS_GET_PRINTERS);
- cupsFileClose(in);
- cupsFileClose(out);
+ ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM,
+ "printer-type", 0);
- /*
- * Build a CUPS_ADD_PRINTER request, which requires the following
- * attributes:
- *
- * attributes-charset
- * attributes-natural-language
- * printer-uri
- * job-sheets-default
- * [ppd file]
- */
+ ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM,
+ "printer-type-mask", CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE |
+ CUPS_PRINTER_IMPLICIT);
- request = ippNewRequest(CUPS_ADD_PRINTER);
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+ "requested-attributes", NULL, "printer-name");
- httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
- "localhost", 0, "/printers/%s",
- cgiGetVariable("PRINTER_NAME"));
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
- NULL, uri);
+ if ((response = cupsDoRequest(http, request, "/")) != NULL)
+ {
+ cgiSetIPPVars(response, NULL, NULL, NULL, 0);
+ ippDelete(response);
- attr = ippAddStrings(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "job-sheets-default", 2, NULL, NULL);
- attr->values[0].string.text = strdup(cgiGetVariable("job_sheets_start"));
- attr->values[1].string.text = strdup(cgiGetVariable("job_sheets_end"));
+ if (!export_all)
+ {
+ printer_count = cgiGetSize("PRINTER_NAME");
- if ((var = cgiGetVariable("printer_error_policy")) != NULL)
- attr = ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "printer-error-policy", NULL, var);
+ for (i = 0; i < printer_count; i ++)
+ {
+ dest = cgiGetArray("PRINTER_NAME", i);
- if ((var = cgiGetVariable("printer_op_policy")) != NULL)
- attr = ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "printer-op-policy", NULL, var);
+ for (j = 0; j < export_count; j ++)
+ if (!strcasecmp(dest, cgiGetArray("EXPORT_NAME", j)))
+ break;
+
+ cgiSetArray("PRINTER_EXPORT", i, j < export_count ? "Y" : "");
+ }
+ }
+ }
+
+ /*
+ * Export or get the printers to export...
+ */
+ if (username && *username && password && *password &&
+ (export_all || export_count > 0))
+ {
/*
- * Do the request and get back a response...
+ * Do export...
*/
- ippDelete(cupsDoFileRequest(http, request, "/admin/", tempfile));
+ fputs("DEBUG: Export printers...\n", stderr);
- if (cupsLastError() > IPP_OK_CONFLICT)
+ if (export_all)
{
- cgiStartHTML(title);
- cgiShowIPPError(_("Unable to set options:"));
+ name = "PRINTER_NAME";
+ export_count = cgiGetSize("PRINTER_NAME");
}
else
- {
- /*
- * Redirect successful updates back to the printer page...
- */
+ name = "EXPORT_NAME";
- char refresh[1024]; /* Refresh URL */
+ for (i = 0; i < export_count; i ++)
+ {
+ dest = cgiGetArray(name, i);
+ if (!cupsAdminCreateWindowsPPD(http, dest, ppd, sizeof(ppd)))
+ break;
- cgiFormEncode(uri, printer, sizeof(uri));
- snprintf(refresh, sizeof(refresh),
- "5;URL=/admin/?OP=redirect&URL=/printers/%s", uri);
- cgiSetVariable("refresh_page", refresh);
+ j = cupsAdminExportSamba(dest, ppd, "localhost", username, password,
+ stderr);
- cgiStartHTML(title);
+ unlink(ppd);
- cgiCopyTemplateLang("printer-configured.tmpl");
+ if (!j)
+ break;
}
- cgiEndHTML();
-
- unlink(tempfile);
+ if (i < export_count)
+ cgiSetVariable("ERROR", cupsLastErrorString());
+ else
+ {
+ cgiStartHTML(cgiText(_("Export Printers to Samba")));
+ cgiCopyTemplateLang("samba-exported.tmpl");
+ cgiEndHTML();
+ return;
+ }
}
+ else if (username && !*username)
+ cgiSetVariable("ERROR",
+ cgiText(_("A Samba username is required to export "
+ "printer drivers!")));
+ else if (username && (!password || !*password))
+ cgiSetVariable("ERROR",
+ cgiText(_("A Samba password is required to export "
+ "printer drivers!")));
+
+ /*
+ * Show form...
+ */
- unlink(filename);
+ cgiStartHTML(cgiText(_("Export Printers to Samba")));
+ cgiCopyTemplateLang("samba-export.tmpl");
+ cgiEndHTML();
}
/*
- * 'do_config_server()' - Configure server settings.
+ * 'do_list_printers()' - List available printers...
*/
static void
-do_config_server(http_t *http) /* I - HTTP connection */
+do_list_printers(http_t *http) /* I - HTTP connection */
{
- if (cgiIsPOST() && !cgiGetVariable("CUPSDCONF"))
- {
- /*
- * Save basic setting changes...
- */
+ ipp_t *request, /* IPP request */
+ *response; /* IPP response */
+ ipp_attribute_t *attr; /* IPP attribute */
- int num_settings; /* Number of server settings */
- cups_option_t *settings; /* Server settings */
- const char *debug_logging, /* DEBUG_LOGGING value */
- *remote_admin, /* REMOTE_ADMIN value */
- *remote_any, /* REMOTE_ANY value */
- *remote_printers,
- /* REMOTE_PRINTERS value */
- *share_printers,/* SHARE_PRINTERS value */
-#ifdef HAVE_GSSAPI
- *default_auth_type,
- /* DefaultAuthType value */
-#endif /* HAVE_GSSAPI */
- *user_cancel_any;
- /* USER_CANCEL_ANY value */
+ cgiStartHTML(cgiText(_("List Available Printers")));
+ fflush(stdout);
+
+ /*
+ * Get the list of printers and their devices...
+ */
+
+ request = ippNewRequest(CUPS_GET_PRINTERS);
+
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+ "requested-attributes", NULL, "device-uri");
+
+ ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM, "printer-type",
+ CUPS_PRINTER_LOCAL);
+ ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM, "printer-type-mask",
+ CUPS_PRINTER_LOCAL);
+ if ((response = cupsDoRequest(http, request, "/")) != NULL)
+ {
/*
- * Get the checkbox values from the form...
+ * Got the printer list, now load the devices...
*/
- debug_logging = cgiGetVariable("DEBUG_LOGGING") ? "1" : "0";
- remote_admin = cgiGetVariable("REMOTE_ADMIN") ? "1" : "0";
- remote_any = cgiGetVariable("REMOTE_ANY") ? "1" : "0";
- remote_printers = cgiGetVariable("REMOTE_PRINTERS") ? "1" : "0";
- share_printers = cgiGetVariable("SHARE_PRINTERS") ? "1" : "0";
- user_cancel_any = cgiGetVariable("USER_CANCEL_ANY") ? "1" : "0";
-#ifdef HAVE_GSSAPI
- default_auth_type = cgiGetVariable("KERBEROS") ? "Negotiate" : "Basic";
+ int i; /* Looping var */
+ cups_array_t *printer_devices; /* Printer devices for local printers */
+ char *printer_device; /* Current printer device */
- fprintf(stderr, "DEBUG: DefaultAuthType %s\n", default_auth_type);
-#endif /* HAVE_GSSAPI */
/*
- * Get the current server settings...
+ * Allocate an array and copy the device strings...
*/
- if (!cupsAdminGetServerSettings(http, &num_settings, &settings))
+ printer_devices = cupsArrayNew((cups_array_func_t)strcmp, NULL);
+
+ for (attr = ippFindAttribute(response, "device-uri", IPP_TAG_URI);
+ attr;
+ attr = ippFindNextAttribute(response, "device-uri", IPP_TAG_URI))
{
- cgiStartHTML(cgiText(_("Change Settings")));
- cgiSetVariable("MESSAGE",
- cgiText(_("Unable to change server settings:")));
- cgiSetVariable("ERROR", cupsLastErrorString());
- cgiCopyTemplateLang("error.tmpl");
- cgiEndHTML();
- return;
+ cupsArrayAdd(printer_devices, strdup(attr->values[0].string.text));
}
/*
- * See if the settings have changed...
+ * Free the printer list and get the device list...
*/
- if (strcmp(debug_logging, cupsGetOption(CUPS_SERVER_DEBUG_LOGGING,
- num_settings, settings)) ||
- strcmp(remote_admin, cupsGetOption(CUPS_SERVER_REMOTE_ADMIN,
- num_settings, settings)) ||
- strcmp(remote_any, cupsGetOption(CUPS_SERVER_REMOTE_ANY,
- num_settings, settings)) ||
- strcmp(remote_printers, cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS,
- num_settings, settings)) ||
- strcmp(share_printers, cupsGetOption(CUPS_SERVER_SHARE_PRINTERS,
- num_settings, settings)) ||
-#ifdef HAVE_GSSAPI
- !cupsGetOption("DefaultAuthType", num_settings, settings) ||
- strcmp(default_auth_type, cupsGetOption("DefaultAuthType",
- num_settings, settings)) ||
-#endif /* HAVE_GSSAPI */
- strcmp(user_cancel_any, cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY,
- num_settings, settings)))
- {
- /*
- * Settings *have* changed, so save the changes...
- */
-
- cupsFreeOptions(num_settings, settings);
+ ippDelete(response);
- num_settings = 0;
- num_settings = cupsAddOption(CUPS_SERVER_DEBUG_LOGGING,
- debug_logging, num_settings, &settings);
- num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ADMIN,
- remote_admin, num_settings, &settings);
- num_settings = cupsAddOption(CUPS_SERVER_REMOTE_ANY,
- remote_any, num_settings, &settings);
- num_settings = cupsAddOption(CUPS_SERVER_REMOTE_PRINTERS,
- remote_printers, num_settings, &settings);
- num_settings = cupsAddOption(CUPS_SERVER_SHARE_PRINTERS,
- share_printers, num_settings, &settings);
- num_settings = cupsAddOption(CUPS_SERVER_USER_CANCEL_ANY,
- user_cancel_any, num_settings, &settings);
-#ifdef HAVE_GSSAPI
- num_settings = cupsAddOption("DefaultAuthType", default_auth_type,
- num_settings, &settings);
-#endif /* HAVE_GSSAPI */
+ request = ippNewRequest(CUPS_GET_DEVICES);
- if (!cupsAdminSetServerSettings(http, num_settings, settings))
- {
- cgiStartHTML(cgiText(_("Change Settings")));
- cgiSetVariable("MESSAGE",
- cgiText(_("Unable to change server settings:")));
- cgiSetVariable("ERROR", cupsLastErrorString());
- cgiCopyTemplateLang("error.tmpl");
- }
- else
- {
- cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect");
- cgiStartHTML(cgiText(_("Change Settings")));
- cgiCopyTemplateLang("restart.tmpl");
- }
- }
- else
+ if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
/*
- * No changes...
+ * Got the device list, let's parse it...
*/
- cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect");
- cgiStartHTML(cgiText(_("Change Settings")));
- cgiCopyTemplateLang("norestart.tmpl");
- }
+ const char *device_uri, /* device-uri attribute value */
+ *device_make_and_model, /* device-make-and-model value */
+ *device_info; /* device-info value */
- cupsFreeOptions(num_settings, settings);
- cgiEndHTML();
- }
- else if (cgiIsPOST())
- {
- /*
- * Save hand-edited config file...
- */
+ for (i = 0, attr = response->attrs; attr; attr = attr->next)
+ {
+ /*
+ * Skip leading attributes until we hit a device...
+ */
- http_status_t status; /* PUT status */
- char tempfile[1024]; /* Temporary new cupsd.conf */
- int tempfd; /* Temporary file descriptor */
- cups_file_t *temp; /* Temporary file */
- const char *start, /* Start of line */
- *end; /* End of line */
+ while (attr && attr->group_tag != IPP_TAG_PRINTER)
+ attr = attr->next;
+ if (!attr)
+ break;
- /*
- * Create a temporary file for the new cupsd.conf file...
- */
+ /*
+ * Pull the needed attributes from this device...
+ */
- if ((tempfd = cupsTempFd(tempfile, sizeof(tempfile))) < 0)
- {
- cgiStartHTML(cgiText(_("Edit Configuration File")));
- cgiSetVariable("MESSAGE", cgiText(_("Unable to create temporary file:")));
- cgiSetVariable("ERROR", strerror(errno));
- cgiCopyTemplateLang("error.tmpl");
- cgiEndHTML();
-
- perror(tempfile);
- return;
- }
+ device_info = NULL;
+ device_make_and_model = NULL;
+ device_uri = NULL;
- if ((temp = cupsFileOpenFd(tempfd, "w")) == NULL)
- {
- cgiStartHTML(cgiText(_("Edit Configuration File")));
- cgiSetVariable("MESSAGE", cgiText(_("Unable to create temporary file:")));
- cgiSetVariable("ERROR", strerror(errno));
- cgiCopyTemplateLang("error.tmpl");
- cgiEndHTML();
-
- perror(tempfile);
- close(tempfd);
- unlink(tempfile);
- return;
- }
+ while (attr && attr->group_tag == IPP_TAG_PRINTER)
+ {
+ if (!strcmp(attr->name, "device-info") &&
+ attr->value_tag == IPP_TAG_TEXT)
+ device_info = attr->values[0].string.text;
- /*
- * Copy the cupsd.conf text from the form variable...
- */
+ if (!strcmp(attr->name, "device-make-and-model") &&
+ attr->value_tag == IPP_TAG_TEXT)
+ device_make_and_model = attr->values[0].string.text;
- start = cgiGetVariable("CUPSDCONF");
- while (start)
- {
- if ((end = strstr(start, "\r\n")) == NULL)
- if ((end = strstr(start, "\n")) == NULL)
- end = start + strlen(start);
+ if (!strcmp(attr->name, "device-uri") &&
+ attr->value_tag == IPP_TAG_URI)
+ device_uri = attr->values[0].string.text;
- cupsFileWrite(temp, start, end - start);
- cupsFilePutChar(temp, '\n');
+ attr = attr->next;
+ }
- if (*end == '\r')
- start = end + 2;
- else if (*end == '\n')
- start = end + 1;
- else
- start = NULL;
- }
+ /*
+ * See if we have everything needed...
+ */
- cupsFileClose(temp);
+ if (device_info && device_make_and_model && device_uri &&
+ strcasecmp(device_make_and_model, "unknown") &&
+ strchr(device_uri, ':'))
+ {
+ /*
+ * Yes, now see if there is already a printer for this
+ * device...
+ */
- /*
- * Upload the configuration file to the server...
- */
+ if (!cupsArrayFind(printer_devices, (void *)device_uri))
+ {
+ /*
+ * Not found, so it must be a new printer...
+ */
- status = cupsPutFile(http, "/admin/conf/cupsd.conf", tempfile);
+ char options[1024], /* Form variables for this device */
+ *options_ptr; /* Pointer into string */
+ const char *ptr; /* Pointer into device string */
- if (status != HTTP_CREATED)
- {
- cgiSetVariable("MESSAGE",
- cgiText(_("Unable to upload cupsd.conf file:")));
- cgiSetVariable("ERROR", httpStatus(status));
- cgiStartHTML(cgiText(_("Edit Configuration File")));
- cgiCopyTemplateLang("error.tmpl");
- }
- else
- {
- cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect");
+ /*
+ * Format the printer name variable for this device...
+ *
+ * We use the device-info string first, then device-uri,
+ * and finally device-make-and-model to come up with a
+ * suitable name.
+ */
- cgiStartHTML(cgiText(_("Edit Configuration File")));
- cgiCopyTemplateLang("restart.tmpl");
- }
+ strcpy(options, "TEMPLATE_NAME=");
+ options_ptr = options + strlen(options);
- cgiEndHTML();
+ if (strncasecmp(device_info, "unknown", 7))
+ ptr = device_info;
+ else if ((ptr = strstr(device_uri, "://")) != NULL)
+ ptr += 3;
+ else
+ ptr = device_make_and_model;
- unlink(tempfile);
- }
- else
- {
- struct stat info; /* cupsd.conf information */
- cups_file_t *cupsd; /* cupsd.conf file */
- char *buffer; /* Buffer for entire file */
- char filename[1024]; /* Filename */
- const char *server_root; /* Location of config files */
+ for (;
+ options_ptr < (options + sizeof(options) - 1) && *ptr;
+ ptr ++)
+ if (isalnum(*ptr & 255) || *ptr == '_' || *ptr == '-' ||
+ *ptr == '.')
+ *options_ptr++ = *ptr;
+ else if ((*ptr == ' ' || *ptr == '/') && options_ptr[-1] != '_')
+ *options_ptr++ = '_';
+ else if (*ptr == '?' || *ptr == '(')
+ break;
+ /*
+ * Then add the make and model in the printer info, so
+ * that MacOS clients see something reasonable...
+ */
- /*
- * Locate the cupsd.conf file...
- */
+ strlcpy(options_ptr, "&PRINTER_LOCATION=Local+Printer"
+ "&PRINTER_INFO=",
+ sizeof(options) - (options_ptr - options));
+ options_ptr += strlen(options_ptr);
- if ((server_root = getenv("CUPS_SERVERROOT")) == NULL)
- server_root = CUPS_SERVERROOT;
+ cgiFormEncode(options_ptr, device_make_and_model,
+ sizeof(options) - (options_ptr - options));
+ options_ptr += strlen(options_ptr);
- snprintf(filename, sizeof(filename), "%s/cupsd.conf", server_root);
+ /*
+ * Then copy the device URI...
+ */
- /*
- * Figure out the size...
- */
+ strlcpy(options_ptr, "&DEVICE_URI=",
+ sizeof(options) - (options_ptr - options));
+ options_ptr += strlen(options_ptr);
- if (stat(filename, &info))
- {
- cgiStartHTML(cgiText(_("Edit Configuration File")));
- cgiSetVariable("MESSAGE",
- cgiText(_("Unable to access cupsd.conf file:")));
- cgiSetVariable("ERROR", strerror(errno));
- cgiCopyTemplateLang("error.tmpl");
- cgiEndHTML();
+ cgiFormEncode(options_ptr, device_uri,
+ sizeof(options) - (options_ptr - options));
+ options_ptr += strlen(options_ptr);
- perror(filename);
- return;
- }
+ if (options_ptr < (options + sizeof(options) - 1))
+ {
+ *options_ptr++ = '|';
+ cgiFormEncode(options_ptr, device_make_and_model,
+ sizeof(options) - (options_ptr - options));
+ }
- if (info.st_size > (1024 * 1024))
- {
- cgiStartHTML(cgiText(_("Edit Configuration File")));
- cgiSetVariable("MESSAGE",
- cgiText(_("Unable to access cupsd.conf file:")));
- cgiSetVariable("ERROR",
- cgiText(_("Unable to edit cupsd.conf files larger than "
- "1MB!")));
- cgiCopyTemplateLang("error.tmpl");
- cgiEndHTML();
+ /*
+ * Finally, set the form variables for this printer...
+ */
- fprintf(stderr, "ERROR: \"%s\" too large (%ld) to edit!\n", filename,
- (long)info.st_size);
- return;
- }
+ cgiSetArray("device_info", i, device_info);
+ cgiSetArray("device_make_and_model", i, device_make_and_model);
+ cgiSetArray("device_options", i, options);
+ cgiSetArray("device_uri", i, device_uri);
+ i ++;
+ }
+ }
- /*
- * Open the cupsd.conf file...
- */
+ if (!attr)
+ break;
+ }
+
+ ippDelete(response);
- if ((cupsd = cupsFileOpen(filename, "r")) == NULL)
- {
/*
- * Unable to open - log an error...
+ * Free the device list...
*/
- cgiStartHTML(cgiText(_("Edit Configuration File")));
- cgiSetVariable("MESSAGE",
- cgiText(_("Unable to access cupsd.conf file:")));
- cgiSetVariable("ERROR", strerror(errno));
- cgiCopyTemplateLang("error.tmpl");
- cgiEndHTML();
+ for (printer_device = (char *)cupsArrayFirst(printer_devices);
+ printer_device;
+ printer_device = (char *)cupsArrayNext(printer_devices))
+ free(printer_device);
- perror(filename);
- return;
+ cupsArrayDelete(printer_devices);
}
+ }
- /*
- * Allocate memory and load the file into a string buffer...
- */
-
- buffer = calloc(1, info.st_size + 1);
-
- cupsFileRead(cupsd, buffer, info.st_size);
- cupsFileClose(cupsd);
-
- cgiSetVariable("CUPSDCONF", buffer);
- free(buffer);
-
- /*
- * Show the current config file...
- */
-
- cgiStartHTML(cgiText(_("Edit Configuration File")));
-
- printf("<!-- \"%s\" -->\n", filename);
+ /*
+ * Finally, show the printer list...
+ */
- cgiCopyTemplateLang("edit-config.tmpl");
+ cgiCopyTemplateLang("list-available-printers.tmpl");
- cgiEndHTML();
- }
+ cgiEndHTML();
}
/*
- * 'do_delete_class()' - Delete a class...
+ * 'do_menu()' - Show the main menu...
*/
static void
-do_delete_class(http_t *http) /* I - HTTP connection */
+do_menu(http_t *http) /* I - HTTP connection */
{
- ipp_t *request; /* IPP request */
- char uri[HTTP_MAX_URI]; /* Job URI */
- const char *pclass; /* Printer class name */
+ int num_settings; /* Number of server settings */
+ cups_option_t *settings; /* Server settings */
+ const char *val; /* Setting value */
+ char filename[1024]; /* Temporary filename */
+ const char *datadir; /* Location of data files */
+ ipp_t *request, /* IPP request */
+ *response; /* IPP response */
/*
- * Get form variables...
+ * Get the current server settings...
*/
- if (cgiGetVariable("CONFIRM") == NULL)
+ if (!cupsAdminGetServerSettings(http, &num_settings, &settings))
{
- cgiStartHTML(cgiText(_("Delete Class")));
- cgiCopyTemplateLang("class-confirm.tmpl");
- cgiEndHTML();
- return;
+ cgiSetVariable("SETTINGS_MESSAGE",
+ cgiText(_("Unable to open cupsd.conf file:")));
+ cgiSetVariable("SETTINGS_ERROR", cupsLastErrorString());
}
- if ((pclass = cgiGetVariable("PRINTER_NAME")) != NULL)
- httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
- "localhost", 0, "/classes/%s", pclass);
- else
- {
- cgiStartHTML(cgiText(_("Delete Class")));
- cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
- cgiCopyTemplateLang("error.tmpl");
- cgiEndHTML();
- return;
- }
+ if ((val = cupsGetOption(CUPS_SERVER_DEBUG_LOGGING, num_settings,
+ settings)) != NULL && atoi(val))
+ cgiSetVariable("DEBUG_LOGGING", "CHECKED");
- /*
- * Build a CUPS_DELETE_CLASS request, which requires the following
- * attributes:
- *
- * attributes-charset
- * attributes-natural-language
- * printer-uri
- */
+ if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ADMIN, num_settings,
+ settings)) != NULL && atoi(val))
+ cgiSetVariable("REMOTE_ADMIN", "CHECKED");
- request = ippNewRequest(CUPS_DELETE_CLASS);
+ if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ANY, num_settings,
+ settings)) != NULL && atoi(val))
+ cgiSetVariable("REMOTE_ANY", "CHECKED");
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
- NULL, uri);
+ if ((val = cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS, num_settings,
+ settings)) != NULL && atoi(val))
+ cgiSetVariable("REMOTE_PRINTERS", "CHECKED");
- /*
- * Do the request and get back a response...
- */
+ if ((val = cupsGetOption(CUPS_SERVER_SHARE_PRINTERS, num_settings,
+ settings)) != NULL && atoi(val))
+ cgiSetVariable("SHARE_PRINTERS", "CHECKED");
- ippDelete(cupsDoRequest(http, request, "/admin/"));
+ if ((val = cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY, num_settings,
+ settings)) != NULL && atoi(val))
+ cgiSetVariable("USER_CANCEL_ANY", "CHECKED");
+
+#ifdef HAVE_GSSAPI
+ cgiSetVariable("HAVE_GSSAPI", "1");
+
+ if ((val = cupsGetOption("DefaultAuthType", num_settings,
+ settings)) != NULL && !strcasecmp(val, "Negotiate"))
+ cgiSetVariable("KERBEROS", "CHECKED");
+#endif /* HAVE_GSSAPI */
+
+ cupsFreeOptions(num_settings, settings);
/*
- * Show the results...
+ * See if Samba and the Windows drivers are installed...
*/
- if (cupsLastError() <= IPP_OK_CONFLICT)
+ if ((datadir = getenv("CUPS_DATADIR")) == NULL)
+ datadir = CUPS_DATADIR;
+
+ snprintf(filename, sizeof(filename), "%s/drivers/pscript5.dll", datadir);
+ if (!access(filename, R_OK))
{
/*
- * Redirect successful updates back to the classes page...
+ * Found Windows 2000 driver file, see if we have smbclient and
+ * rpcclient...
*/
- cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect&URL=/classes");
+ if (cupsFileFind("smbclient", getenv("PATH"), 1, filename,
+ sizeof(filename)) &&
+ cupsFileFind("rpcclient", getenv("PATH"), 1, filename,
+ sizeof(filename)))
+ cgiSetVariable("HAVE_SAMBA", "Y");
+ else
+ {
+ if (!cupsFileFind("smbclient", getenv("PATH"), 1, filename,
+ sizeof(filename)))
+ fputs("ERROR: smbclient not found!\n", stderr);
+
+ if (!cupsFileFind("rpcclient", getenv("PATH"), 1, filename,
+ sizeof(filename)))
+ fputs("ERROR: rpcclient not found!\n", stderr);
+ }
}
+ else
+ perror(filename);
- cgiStartHTML(cgiText(_("Delete Class")));
+ /*
+ * Subscriptions...
+ */
- if (cupsLastError() > IPP_OK_CONFLICT)
- cgiShowIPPError(_("Unable to delete class:"));
- else
- cgiCopyTemplateLang("class-deleted.tmpl");
+ request = ippNewRequest(IPP_GET_SUBSCRIPTIONS);
+
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ NULL, "ipp://localhost/");
+
+ if ((response = cupsDoRequest(http, request, "/")) != NULL)
+ {
+ cgiSetIPPVars(response, NULL, NULL, NULL, 0);
+ ippDelete(response);
+ }
+
+ /*
+ * Finally, show the main menu template...
+ */
+
+ cgiStartHTML(cgiText(_("Administration")));
+
+ cgiCopyTemplateLang("admin.tmpl");
cgiEndHTML();
}
/*
- * 'do_delete_printer()' - Delete a printer...
+ * 'do_printer_op()' - Do a printer operation.
*/
static void
-do_delete_printer(http_t *http) /* I - HTTP connection */
+do_printer_op(http_t *http, /* I - HTTP connection */
+ ipp_op_t op, /* I - Operation to perform */
+ const char *title) /* I - Title of page */
{
ipp_t *request; /* IPP request */
- char uri[HTTP_MAX_URI]; /* Job URI */
- const char *printer; /* Printer printer name */
-
+ char uri[HTTP_MAX_URI]; /* Printer URI */
+ const char *printer, /* Printer name (purge-jobs) */
+ *is_class; /* Is a class? */
- /*
- * Get form variables...
- */
- if (cgiGetVariable("CONFIRM") == NULL)
- {
- cgiStartHTML(cgiText(_("Delete Printer")));
- cgiCopyTemplateLang("printer-confirm.tmpl");
- cgiEndHTML();
- return;
- }
+ is_class = cgiGetVariable("IS_CLASS");
+ printer = cgiGetVariable("PRINTER_NAME");
- if ((printer = cgiGetVariable("PRINTER_NAME")) != NULL)
- httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
- "localhost", 0, "/printers/%s", printer);
- else
+ if (!printer)
{
- cgiStartHTML(cgiText(_("Delete Printer")));
cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
+ cgiStartHTML(title);
cgiCopyTemplateLang("error.tmpl");
cgiEndHTML();
return;
}
/*
- * Build a CUPS_DELETE_PRINTER request, which requires the following
+ * Build a printer request, which requires the following
* attributes:
*
* attributes-charset
* printer-uri
*/
- request = ippNewRequest(CUPS_DELETE_PRINTER);
+ request = ippNewRequest(op);
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+ "localhost", 0, is_class ? "/classes/%s" : "/printers/%s",
+ printer);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, uri);
ippDelete(cupsDoRequest(http, request, "/admin/"));
- /*
- * Show the results...
- */
-
- if (cupsLastError() <= IPP_OK_CONFLICT)
+ if (cupsLastError() > IPP_OK_CONFLICT)
+ {
+ cgiStartHTML(title);
+ cgiShowIPPError(_("Unable to change printer:"));
+ }
+ else
{
/*
- * Redirect successful updates back to the printers page...
+ * Redirect successful updates back to the printer page...
*/
- cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect&URL=/printers");
- }
+ char url[1024], /* Printer/class URL */
+ refresh[1024]; /* Refresh URL */
- cgiStartHTML(cgiText(_("Delete Printer")));
- if (cupsLastError() > IPP_OK_CONFLICT)
- cgiShowIPPError(_("Unable to delete printer:"));
- else
- cgiCopyTemplateLang("printer-deleted.tmpl");
+ cgiRewriteURL(uri, url, sizeof(url), NULL);
+ cgiFormEncode(uri, url, sizeof(uri));
+ snprintf(refresh, sizeof(refresh), "5;URL=/admin/?OP=redirect&URL=%s", uri);
+ cgiSetVariable("refresh_page", refresh);
+
+ cgiStartHTML(title);
+
+ if (op == IPP_PAUSE_PRINTER)
+ cgiCopyTemplateLang("printer-stop.tmpl");
+ else if (op == IPP_RESUME_PRINTER)
+ cgiCopyTemplateLang("printer-start.tmpl");
+ else if (op == CUPS_ACCEPT_JOBS)
+ cgiCopyTemplateLang("printer-accept.tmpl");
+ else if (op == CUPS_REJECT_JOBS)
+ cgiCopyTemplateLang("printer-reject.tmpl");
+ else if (op == IPP_PURGE_JOBS)
+ cgiCopyTemplateLang("printer-purge.tmpl");
+ else if (op == CUPS_SET_DEFAULT)
+ cgiCopyTemplateLang("printer-default.tmpl");
+ }
cgiEndHTML();
}
/*
- * 'do_export()' - Export printers to Samba...
+ * 'do_set_allowed_users()' - Set the allowed/denied users for a queue.
*/
static void
-do_export(http_t *http) /* I - HTTP connection */
+do_set_allowed_users(http_t *http) /* I - HTTP connection */
{
- int i, j; /* Looping vars */
+ int i; /* Looping var */
ipp_t *request, /* IPP request */
*response; /* IPP response */
- const char *username, /* Samba username */
- *password, /* Samba password */
- *export_all; /* Export all printers? */
- int export_count, /* Number of printers to export */
- printer_count; /* Number of available printers */
- const char *name, /* What name to pull */
- *dest; /* Current destination */
- char ppd[1024]; /* PPD file */
-
+ char uri[HTTP_MAX_URI]; /* Printer URI */
+ const char *printer, /* Printer name (purge-jobs) */
+ *is_class, /* Is a class? */
+ *users, /* List of users or groups */
+ *type; /* Allow/deny type */
+ int num_users; /* Number of users */
+ char *ptr, /* Pointer into users string */
+ *end, /* Pointer to end of users string */
+ quote; /* Quote character */
+ ipp_attribute_t *attr; /* Attribute */
+ static const char * const attrs[] = /* Requested attributes */
+ {
+ "requesting-user-name-allowed",
+ "requesting-user-name-denied"
+ };
- /*
- * Get form data...
- */
- username = cgiGetVariable("USERNAME");
- password = cgiGetVariable("PASSWORD");
- export_all = cgiGetVariable("EXPORT_ALL");
- export_count = cgiGetSize("EXPORT_NAME");
+ is_class = cgiGetVariable("IS_CLASS");
+ printer = cgiGetVariable("PRINTER_NAME");
- /*
- * Get list of available printers...
- */
+ if (!printer)
+ {
+ cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
+ cgiStartHTML(cgiText(_("Set Allowed Users")));
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
+ return;
+ }
- cgiSetSize("PRINTER_NAME", 0);
- cgiSetSize("PRINTER_EXPORT", 0);
+ users = cgiGetVariable("users");
+ type = cgiGetVariable("type");
- request = ippNewRequest(CUPS_GET_PRINTERS);
+ if (!users || !type ||
+ (strcmp(type, "requesting-user-name-allowed") &&
+ strcmp(type, "requesting-user-name-denied")))
+ {
+ /*
+ * Build a Get-Printer-Attributes request, which requires the following
+ * attributes:
+ *
+ * attributes-charset
+ * attributes-natural-language
+ * printer-uri
+ * requested-attributes
+ */
- ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM,
- "printer-type", 0);
+ request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
- ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM,
- "printer-type-mask", CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE |
- CUPS_PRINTER_IMPLICIT);
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+ "localhost", 0, is_class ? "/classes/%s" : "/printers/%s",
+ printer);
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ NULL, uri);
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
- "requested-attributes", NULL, "printer-name");
+ ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+ "requested-attributes",
+ (int)(sizeof(attrs) / sizeof(attrs[0])), NULL, attrs);
- if ((response = cupsDoRequest(http, request, "/")) != NULL)
- {
- cgiSetIPPVars(response, NULL, NULL, NULL, 0);
- ippDelete(response);
+ /*
+ * Do the request and get back a response...
+ */
- if (!export_all)
+ if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
- printer_count = cgiGetSize("PRINTER_NAME");
-
- for (i = 0; i < printer_count; i ++)
- {
- dest = cgiGetArray("PRINTER_NAME", i);
-
- for (j = 0; j < export_count; j ++)
- if (!strcasecmp(dest, cgiGetArray("EXPORT_NAME", j)))
- break;
+ cgiSetIPPVars(response, NULL, NULL, NULL, 0);
- cgiSetArray("PRINTER_EXPORT", i, j < export_count ? "Y" : "");
- }
+ ippDelete(response);
}
- }
- /*
- * Export or get the printers to export...
- */
+ cgiStartHTML(cgiText(_("Set Allowed Users")));
- if (username && *username && password && *password &&
- (export_all || export_count > 0))
+ if (cupsLastError() > IPP_OK_CONFLICT)
+ cgiShowIPPError(_("Unable to get printer attributes:"));
+ else
+ cgiCopyTemplateLang("users.tmpl");
+
+ cgiEndHTML();
+ }
+ else
{
/*
- * Do export...
+ * Save the changes...
*/
- fputs("DEBUG: Export printers...\n", stderr);
-
- if (export_all)
+ for (num_users = 0, ptr = (char *)users; *ptr; num_users ++)
{
- name = "PRINTER_NAME";
- export_count = cgiGetSize("PRINTER_NAME");
- }
- else
- name = "EXPORT_NAME";
-
- for (i = 0; i < export_count; i ++)
- {
- dest = cgiGetArray(name, i);
-
- if (!cupsAdminCreateWindowsPPD(http, dest, ppd, sizeof(ppd)))
- break;
-
- j = cupsAdminExportSamba(dest, ppd, "localhost", username, password,
- stderr);
-
- unlink(ppd);
-
- if (!j)
- break;
- }
-
- if (i < export_count)
- cgiSetVariable("ERROR", cupsLastErrorString());
- else
- {
- cgiStartHTML(cgiText(_("Export Printers to Samba")));
- cgiCopyTemplateLang("samba-exported.tmpl");
- cgiEndHTML();
- return;
- }
- }
- else if (username && !*username)
- cgiSetVariable("ERROR",
- cgiText(_("A Samba username is required to export "
- "printer drivers!")));
- else if (username && (!password || !*password))
- cgiSetVariable("ERROR",
- cgiText(_("A Samba password is required to export "
- "printer drivers!")));
-
- /*
- * Show form...
- */
+ /*
+ * Skip whitespace and commas...
+ */
- cgiStartHTML(cgiText(_("Export Printers to Samba")));
- cgiCopyTemplateLang("samba-export.tmpl");
- cgiEndHTML();
-}
+ while (*ptr == ',' || isspace(*ptr & 255))
+ ptr ++;
+ if (*ptr == '\'' || *ptr == '\"')
+ {
+ /*
+ * Scan quoted name...
+ */
-/*
- * 'do_menu()' - Show the main menu...
- */
+ quote = *ptr++;
-static void
-do_menu(http_t *http) /* I - HTTP connection */
-{
- int num_settings; /* Number of server settings */
- cups_option_t *settings; /* Server settings */
- const char *val; /* Setting value */
- char filename[1024]; /* Temporary filename */
- const char *datadir; /* Location of data files */
- ipp_t *request, /* IPP request */
- *response; /* IPP response */
- ipp_attribute_t *attr; /* IPP attribute */
+ for (end = ptr; *end; end ++)
+ if (*end == quote)
+ break;
+ }
+ else
+ {
+ /*
+ * Scan space or comma-delimited name...
+ */
+ for (end = ptr; *end; end ++)
+ if (isspace(*end & 255) || *end == ',')
+ break;
+ }
- /*
- * Get the current server settings...
- */
+ /*
+ * Advance to the next name...
+ */
- if (!cupsAdminGetServerSettings(http, &num_settings, &settings))
- {
- cgiSetVariable("SETTINGS_MESSAGE",
- cgiText(_("Unable to open cupsd.conf file:")));
- cgiSetVariable("SETTINGS_ERROR", cupsLastErrorString());
- }
+ ptr = end;
+ }
- if ((val = cupsGetOption(CUPS_SERVER_DEBUG_LOGGING, num_settings,
- settings)) != NULL && atoi(val))
- cgiSetVariable("DEBUG_LOGGING", "CHECKED");
+ /*
+ * Build a CUPS-Add-Printer/Class request, which requires the following
+ * attributes:
+ *
+ * attributes-charset
+ * attributes-natural-language
+ * printer-uri
+ * requesting-user-name-{allowed,denied}
+ */
- if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ADMIN, num_settings,
- settings)) != NULL && atoi(val))
- cgiSetVariable("REMOTE_ADMIN", "CHECKED");
+ request = ippNewRequest(is_class ? CUPS_ADD_CLASS : CUPS_ADD_PRINTER);
- if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ANY, num_settings,
- settings)) != NULL && atoi(val))
- cgiSetVariable("REMOTE_ANY", "CHECKED");
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+ "localhost", 0, is_class ? "/classes/%s" : "/printers/%s",
+ printer);
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ NULL, uri);
- if ((val = cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS, num_settings,
- settings)) != NULL && atoi(val))
- cgiSetVariable("REMOTE_PRINTERS", "CHECKED");
+ if (num_users == 0)
+ ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ "requesting-user-name-allowed", NULL, "all");
+ else
+ {
+ attr = ippAddStrings(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ type, num_users, NULL, NULL);
- if ((val = cupsGetOption(CUPS_SERVER_SHARE_PRINTERS, num_settings,
- settings)) != NULL && atoi(val))
- cgiSetVariable("SHARE_PRINTERS", "CHECKED");
+ for (i = 0, ptr = (char *)users; *ptr; i ++)
+ {
+ /*
+ * Skip whitespace and commas...
+ */
- if ((val = cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY, num_settings,
- settings)) != NULL && atoi(val))
- cgiSetVariable("USER_CANCEL_ANY", "CHECKED");
+ while (*ptr == ',' || isspace(*ptr & 255))
+ ptr ++;
-#ifdef HAVE_GSSAPI
- cgiSetVariable("HAVE_GSSAPI", "1");
+ if (*ptr == '\'' || *ptr == '\"')
+ {
+ /*
+ * Scan quoted name...
+ */
- if ((val = cupsGetOption("DefaultAuthType", num_settings,
- settings)) != NULL && !strcasecmp(val, "Negotiate"))
- cgiSetVariable("KERBEROS", "CHECKED");
-#endif /* HAVE_GSSAPI */
+ quote = *ptr++;
- cupsFreeOptions(num_settings, settings);
+ for (end = ptr; *end; end ++)
+ if (*end == quote)
+ break;
+ }
+ else
+ {
+ /*
+ * Scan space or comma-delimited name...
+ */
- /*
- * Get the list of printers and their devices...
- */
+ for (end = ptr; *end; end ++)
+ if (isspace(*end & 255) || *end == ',')
+ break;
+ }
- request = ippNewRequest(CUPS_GET_PRINTERS);
+ /*
+ * Terminate the name...
+ */
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
- "requested-attributes", NULL, "device-uri");
+ if (*end)
+ *end++ = '\0';
- ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM, "printer-type",
- CUPS_PRINTER_LOCAL);
- ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM, "printer-type-mask",
- CUPS_PRINTER_LOCAL);
+ /*
+ * Add the name...
+ */
- if ((response = cupsDoRequest(http, request, "/")) != NULL)
- {
- /*
- * Got the printer list, now load the devices...
- */
+ attr->values[i].string.text = strdup(ptr);
- int i; /* Looping var */
- cups_array_t *printer_devices; /* Printer devices for local printers */
- char *printer_device; /* Current printer device */
+ /*
+ * Advance to the next name...
+ */
+ ptr = end;
+ }
+ }
/*
- * Allocate an array and copy the device strings...
+ * Do the request and get back a response...
*/
- printer_devices = cupsArrayNew((cups_array_func_t)strcmp, NULL);
+ ippDelete(cupsDoRequest(http, request, "/admin/"));
- for (attr = ippFindAttribute(response, "device-uri", IPP_TAG_URI);
- attr;
- attr = ippFindNextAttribute(response, "device-uri", IPP_TAG_URI))
+ if (cupsLastError() > IPP_OK_CONFLICT)
{
- cupsArrayAdd(printer_devices, strdup(attr->values[0].string.text));
+ cgiStartHTML(cgiText(_("Set Allowed Users")));
+ cgiShowIPPError(_("Unable to change printer:"));
}
-
- /*
- * Free the printer list and get the device list...
- */
-
- ippDelete(response);
-
- request = ippNewRequest(CUPS_GET_DEVICES);
-
- if ((response = cupsDoRequest(http, request, "/")) != NULL)
+ else
{
/*
- * Got the device list, let's parse it...
+ * Redirect successful updates back to the printer page...
*/
- const char *device_uri, /* device-uri attribute value */
- *device_make_and_model, /* device-make-and-model value */
- *device_info; /* device-info value */
+ char url[1024], /* Printer/class URL */
+ refresh[1024]; /* Refresh URL */
- for (i = 0, attr = response->attrs; attr; attr = attr->next)
- {
- /*
- * Skip leading attributes until we hit a device...
- */
+ cgiRewriteURL(uri, url, sizeof(url), NULL);
+ cgiFormEncode(uri, url, sizeof(uri));
+ snprintf(refresh, sizeof(refresh), "5;URL=/admin/?OP=redirect&URL=%s",
+ uri);
+ cgiSetVariable("refresh_page", refresh);
- while (attr && attr->group_tag != IPP_TAG_PRINTER)
- attr = attr->next;
+ cgiStartHTML(cgiText(_("Set Allowed Users")));
- if (!attr)
- break;
+ cgiCopyTemplateLang(is_class ? "class-modified.tmpl" :
+ "printer-modified.tmpl");
+ }
- /*
- * Pull the needed attributes from this device...
- */
+ cgiEndHTML();
+ }
+}
- device_info = NULL;
- device_make_and_model = NULL;
- device_uri = NULL;
-
- while (attr && attr->group_tag == IPP_TAG_PRINTER)
- {
- if (!strcmp(attr->name, "device-info") &&
- attr->value_tag == IPP_TAG_TEXT)
- device_info = attr->values[0].string.text;
- if (!strcmp(attr->name, "device-make-and-model") &&
- attr->value_tag == IPP_TAG_TEXT)
- device_make_and_model = attr->values[0].string.text;
-
- if (!strcmp(attr->name, "device-uri") &&
- attr->value_tag == IPP_TAG_URI)
- device_uri = attr->values[0].string.text;
-
- attr = attr->next;
- }
-
- /*
- * See if we have everything needed...
- */
-
- if (device_info && device_make_and_model && device_uri &&
- strcasecmp(device_make_and_model, "unknown") &&
- strchr(device_uri, ':'))
- {
- /*
- * Yes, now see if there is already a printer for this
- * device...
- */
+/*
+ * 'do_set_options()' - Configure the default options for a queue.
+ */
- if (!cupsArrayFind(printer_devices, (void *)device_uri))
- {
- /*
- * Not found, so it must be a new printer...
- */
+static void
+do_set_options(http_t *http, /* I - HTTP connection */
+ int is_class) /* I - Set options for class? */
+{
+ int i, j, k, m; /* Looping vars */
+ int have_options; /* Have options? */
+ ipp_t *request, /* IPP request */
+ *response; /* IPP response */
+ ipp_attribute_t *attr; /* IPP attribute */
+ char uri[HTTP_MAX_URI]; /* Job URI */
+ const char *var; /* Variable value */
+ const char *printer; /* Printer printer name */
+ const char *filename; /* PPD filename */
+ char tempfile[1024]; /* Temporary filename */
+ cups_file_t *in, /* Input file */
+ *out; /* Output file */
+ char line[1024]; /* Line from PPD file */
+ char keyword[1024], /* Keyword from Default line */
+ *keyptr; /* Pointer into keyword... */
+ ppd_file_t *ppd; /* PPD file */
+ ppd_group_t *group; /* Option group */
+ ppd_option_t *option; /* Option */
+ ppd_attr_t *protocol; /* cupsProtocol attribute */
+ const char *title; /* Page title */
- char options[1024], /* Form variables for this device */
- *options_ptr; /* Pointer into string */
- const char *ptr; /* Pointer into device string */
+ title = cgiText(is_class ? _("Set Class Options") : _("Set Printer Options"));
- /*
- * Format the printer name variable for this device...
- *
- * We use the device-info string first, then device-uri,
- * and finally device-make-and-model to come up with a
- * suitable name.
- */
+ fprintf(stderr, "DEBUG: do_set_options(http=%p, is_class=%d)\n", http,
+ is_class);
- strcpy(options, "TEMPLATE_NAME=");
- options_ptr = options + strlen(options);
+ /*
+ * Get the printer name...
+ */
- if (strncasecmp(device_info, "unknown", 7))
- ptr = device_info;
- else if ((ptr = strstr(device_uri, "://")) != NULL)
- ptr += 3;
- else
- ptr = device_make_and_model;
+ if ((printer = cgiGetVariable("PRINTER_NAME")) != NULL)
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+ "localhost", 0, is_class ? "/classes/%s" : "/printers/%s",
+ printer);
+ else
+ {
+ cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
+ cgiStartHTML(title);
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
+ return;
+ }
- for (;
- options_ptr < (options + sizeof(options) - 1) && *ptr;
- ptr ++)
- if (isalnum(*ptr & 255) || *ptr == '_' || *ptr == '-' ||
- *ptr == '.')
- *options_ptr++ = *ptr;
- else if ((*ptr == ' ' || *ptr == '/') && options_ptr[-1] != '_')
- *options_ptr++ = '_';
- else if (*ptr == '?' || *ptr == '(')
- break;
+ fprintf(stderr, "DEBUG: printer=\"%s\", uri=\"%s\"...\n", printer, uri);
- /*
- * Then add the make and model in the printer info, so
- * that MacOS clients see something reasonable...
- */
+ /*
+ * Get the PPD file...
+ */
- strlcpy(options_ptr, "&PRINTER_LOCATION=Local+Printer"
- "&PRINTER_INFO=",
- sizeof(options) - (options_ptr - options));
- options_ptr += strlen(options_ptr);
+ if (is_class)
+ filename = NULL;
+ else
+ filename = cupsGetPPD2(http, printer);
- cgiFormEncode(options_ptr, device_make_and_model,
- sizeof(options) - (options_ptr - options));
- options_ptr += strlen(options_ptr);
+ if (filename)
+ {
+ fprintf(stderr, "DEBUG: Got PPD file: \"%s\"\n", filename);
- /*
- * Then copy the device URI...
- */
+ if ((ppd = ppdOpenFile(filename)) == NULL)
+ {
+ cgiSetVariable("ERROR", ppdErrorString(ppdLastError(&i)));
+ cgiSetVariable("MESSAGE", cgiText(_("Unable to open PPD file:")));
+ cgiStartHTML(title);
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
+ return;
+ }
+ }
+ else
+ {
+ fputs("DEBUG: No PPD file\n", stderr);
+ ppd = NULL;
+ }
- strlcpy(options_ptr, "&DEVICE_URI=",
- sizeof(options) - (options_ptr - options));
- options_ptr += strlen(options_ptr);
+ if (cgiGetVariable("job_sheets_start") != NULL ||
+ cgiGetVariable("job_sheets_end") != NULL)
+ have_options = 1;
+ else
+ have_options = 0;
- cgiFormEncode(options_ptr, device_uri,
- sizeof(options) - (options_ptr - options));
- options_ptr += strlen(options_ptr);
+ if (ppd)
+ {
+ ppdMarkDefaults(ppd);
- if (options_ptr < (options + sizeof(options) - 1))
- {
- *options_ptr++ = '|';
- cgiFormEncode(options_ptr, device_make_and_model,
- sizeof(options) - (options_ptr - options));
- }
+ DEBUG_printf(("<P>ppd->num_groups = %d\n"
+ "<UL>\n", ppd->num_groups));
- /*
- * Finally, set the form variables for this printer...
- */
+ for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
+ {
+ DEBUG_printf(("<LI>%s<UL>\n", group->text));
- cgiSetArray("device_info", i, device_info);
- cgiSetArray("device_make_and_model", i, device_make_and_model);
- cgiSetArray("device_options", i, options);
- cgiSetArray("device_uri", i, device_uri);
- i ++;
- }
+ for (j = group->num_options, option = group->options;
+ j > 0;
+ j --, option ++)
+ if ((var = cgiGetVariable(option->keyword)) != NULL)
+ {
+ DEBUG_printf(("<LI>%s = \"%s\"</LI>\n", option->keyword, var));
+ have_options = 1;
+ ppdMarkOption(ppd, option->keyword, var);
}
+#ifdef DEBUG
+ else
+ printf("<LI>%s not defined!</LI>\n", option->keyword);
+#endif /* DEBUG */
- if (!attr)
- break;
- }
-
- ippDelete(response);
-
- /*
- * Free the device list...
- */
-
- for (printer_device = (char *)cupsArrayFirst(printer_devices);
- printer_device;
- printer_device = (char *)cupsArrayNext(printer_devices))
- free(printer_device);
-
- cupsArrayDelete(printer_devices);
+ DEBUG_puts("</UL></LI>");
}
- }
-
- /*
- * See if Samba and the Windows drivers are installed...
- */
- if ((datadir = getenv("CUPS_DATADIR")) == NULL)
- datadir = CUPS_DATADIR;
+ DEBUG_printf(("</UL>\n"
+ "<P>ppdConflicts(ppd) = %d\n", ppdConflicts(ppd)));
+ }
- snprintf(filename, sizeof(filename), "%s/drivers/pscript5.dll", datadir);
- if (!access(filename, R_OK))
+ if (!have_options || ppdConflicts(ppd))
{
/*
- * Found Windows 2000 driver file, see if we have smbclient and
- * rpcclient...
+ * Show the options to the user...
*/
- if (cupsFileFind("smbclient", getenv("PATH"), 1, filename,
- sizeof(filename)) &&
- cupsFileFind("rpcclient", getenv("PATH"), 1, filename,
- sizeof(filename)))
- cgiSetVariable("HAVE_SAMBA", "Y");
- else
- {
- if (!cupsFileFind("smbclient", getenv("PATH"), 1, filename,
- sizeof(filename)))
- fputs("ERROR: smbclient not found!\n", stderr);
+ fputs("DEBUG: Showing options...\n", stderr);
- if (!cupsFileFind("rpcclient", getenv("PATH"), 1, filename,
- sizeof(filename)))
- fputs("ERROR: rpcclient not found!\n", stderr);
- }
- }
- else
- perror(filename);
+ cgiStartHTML(cgiText(_("Set Printer Options")));
+ cgiCopyTemplateLang("set-printer-options-header.tmpl");
- /*
- * Subscriptions...
- */
+ if (ppd)
+ {
+ ppdLocalize(ppd);
- request = ippNewRequest(IPP_GET_SUBSCRIPTIONS);
+ if (ppdConflicts(ppd))
+ {
+ for (i = ppd->num_groups, k = 0, group = ppd->groups;
+ i > 0;
+ i --, group ++)
+ for (j = group->num_options, option = group->options;
+ j > 0;
+ j --, option ++)
+ if (option->conflicted)
+ {
+ cgiSetArray("ckeyword", k, option->keyword);
+ cgiSetArray("ckeytext", k, option->text);
+ k ++;
+ }
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
- NULL, "ipp://localhost/");
+ cgiCopyTemplateLang("option-conflict.tmpl");
+ }
- if ((response = cupsDoRequest(http, request, "/")) != NULL)
- {
- cgiSetIPPVars(response, NULL, NULL, NULL, 0);
- ippDelete(response);
- }
+ for (i = ppd->num_groups, group = ppd->groups;
+ i > 0;
+ i --, group ++)
+ {
+ if (!strcmp(group->name, "InstallableOptions"))
+ cgiSetVariable("GROUP", cgiText(_("Options Installed")));
+ else
+ cgiSetVariable("GROUP", group->text);
- /*
- * Finally, show the main menu template...
- */
+ cgiCopyTemplateLang("option-header.tmpl");
+
+ for (j = group->num_options, option = group->options;
+ j > 0;
+ j --, option ++)
+ {
+ if (!strcmp(option->keyword, "PageRegion"))
+ continue;
- cgiStartHTML(cgiText(_("Administration")));
+ cgiSetVariable("KEYWORD", option->keyword);
+ cgiSetVariable("KEYTEXT", option->text);
+
+ if (option->conflicted)
+ cgiSetVariable("CONFLICTED", "1");
+ else
+ cgiSetVariable("CONFLICTED", "0");
+
+ cgiSetSize("CHOICES", 0);
+ cgiSetSize("TEXT", 0);
+ for (k = 0, m = 0; k < option->num_choices; k ++)
+ {
+ /*
+ * Hide custom option values...
+ */
- cgiCopyTemplateLang("admin.tmpl");
+ if (!strcmp(option->choices[k].choice, "Custom"))
+ continue;
- cgiEndHTML();
-}
+ cgiSetArray("CHOICES", m, option->choices[k].choice);
+ cgiSetArray("TEXT", m, option->choices[k].text);
+ m ++;
-/*
- * 'do_printer_op()' - Do a printer operation.
- */
+ if (option->choices[k].marked)
+ cgiSetVariable("DEFCHOICE", option->choices[k].choice);
+ }
-static void
-do_printer_op(http_t *http, /* I - HTTP connection */
- ipp_op_t op, /* I - Operation to perform */
- const char *title) /* I - Title of page */
-{
- ipp_t *request; /* IPP request */
- char uri[HTTP_MAX_URI]; /* Printer URI */
- const char *printer, /* Printer name (purge-jobs) */
- *is_class; /* Is a class? */
+ switch (option->ui)
+ {
+ case PPD_UI_BOOLEAN :
+ cgiCopyTemplateLang("option-boolean.tmpl");
+ break;
+ case PPD_UI_PICKONE :
+ cgiCopyTemplateLang("option-pickone.tmpl");
+ break;
+ case PPD_UI_PICKMANY :
+ cgiCopyTemplateLang("option-pickmany.tmpl");
+ break;
+ }
+ }
+ cgiCopyTemplateLang("option-trailer.tmpl");
+ }
+ }
- is_class = cgiGetVariable("IS_CLASS");
- printer = cgiGetVariable("PRINTER_NAME");
+ /*
+ * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
+ * following attributes:
+ *
+ * attributes-charset
+ * attributes-natural-language
+ * printer-uri
+ */
- if (!printer)
- {
- cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
- cgiStartHTML(title);
- cgiCopyTemplateLang("error.tmpl");
- cgiEndHTML();
- return;
- }
+ request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
- /*
- * Build a printer request, which requires the following
- * attributes:
- *
- * attributes-charset
- * attributes-natural-language
- * printer-uri
- */
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+ "localhost", 0, "/printers/%s", printer);
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ NULL, uri);
- request = ippNewRequest(op);
+ /*
+ * Do the request and get back a response...
+ */
- httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
- "localhost", 0, is_class ? "/classes/%s" : "/printers/%s",
- printer);
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
- NULL, uri);
+ if ((response = cupsDoRequest(http, request, "/")) != NULL)
+ {
+ if ((attr = ippFindAttribute(response, "job-sheets-supported",
+ IPP_TAG_ZERO)) != NULL)
+ {
+ /*
+ * Add the job sheets options...
+ */
- /*
- * Do the request and get back a response...
- */
+ cgiSetVariable("GROUP", cgiText(_("Banners")));
+ cgiCopyTemplateLang("option-header.tmpl");
- ippDelete(cupsDoRequest(http, request, "/admin/"));
+ cgiSetSize("CHOICES", attr->num_values);
+ cgiSetSize("TEXT", attr->num_values);
+ for (k = 0; k < attr->num_values; k ++)
+ {
+ cgiSetArray("CHOICES", k, attr->values[k].string.text);
+ cgiSetArray("TEXT", k, attr->values[k].string.text);
+ }
- if (cupsLastError() > IPP_OK_CONFLICT)
- {
- cgiStartHTML(title);
- cgiShowIPPError(_("Unable to change printer:"));
- }
- else
- {
- /*
- * Redirect successful updates back to the printer page...
- */
+ attr = ippFindAttribute(response, "job-sheets-default", IPP_TAG_ZERO);
- char url[1024], /* Printer/class URL */
- refresh[1024]; /* Refresh URL */
+ cgiSetVariable("KEYWORD", "job_sheets_start");
+ cgiSetVariable("KEYTEXT", cgiText(_("Starting Banner")));
+ cgiSetVariable("DEFCHOICE", attr == NULL ?
+ "" : attr->values[0].string.text);
+ cgiCopyTemplateLang("option-pickone.tmpl");
- cgiRewriteURL(uri, url, sizeof(url), NULL);
- cgiFormEncode(uri, url, sizeof(uri));
- snprintf(refresh, sizeof(refresh), "5;URL=/admin/?OP=redirect&URL=%s", uri);
- cgiSetVariable("refresh_page", refresh);
+ cgiSetVariable("KEYWORD", "job_sheets_end");
+ cgiSetVariable("KEYTEXT", cgiText(_("Ending Banner")));
+ cgiSetVariable("DEFCHOICE", attr == NULL && attr->num_values > 1 ?
+ "" : attr->values[1].string.text);
- cgiStartHTML(title);
+ cgiCopyTemplateLang("option-pickone.tmpl");
- if (op == IPP_PAUSE_PRINTER)
- cgiCopyTemplateLang("printer-stop.tmpl");
- else if (op == IPP_RESUME_PRINTER)
- cgiCopyTemplateLang("printer-start.tmpl");
- else if (op == CUPS_ACCEPT_JOBS)
- cgiCopyTemplateLang("printer-accept.tmpl");
- else if (op == CUPS_REJECT_JOBS)
- cgiCopyTemplateLang("printer-reject.tmpl");
- else if (op == IPP_PURGE_JOBS)
- cgiCopyTemplateLang("printer-purge.tmpl");
- else if (op == CUPS_SET_DEFAULT)
- cgiCopyTemplateLang("printer-default.tmpl");
- }
+ cgiCopyTemplateLang("option-trailer.tmpl");
+ }
- cgiEndHTML();
-}
+ if (ippFindAttribute(response, "printer-error-policy-supported",
+ IPP_TAG_ZERO) ||
+ ippFindAttribute(response, "printer-op-policy-supported",
+ IPP_TAG_ZERO))
+ {
+ /*
+ * Add the error and operation policy options...
+ */
+ cgiSetVariable("GROUP", cgiText(_("Policies")));
+ cgiCopyTemplateLang("option-header.tmpl");
-/*
- * 'do_set_allowed_users()' - Set the allowed/denied users for a queue.
- */
+ /*
+ * Error policy...
+ */
-static void
-do_set_allowed_users(http_t *http) /* I - HTTP connection */
-{
- int i; /* Looping var */
- ipp_t *request, /* IPP request */
- *response; /* IPP response */
- char uri[HTTP_MAX_URI]; /* Printer URI */
- const char *printer, /* Printer name (purge-jobs) */
- *is_class, /* Is a class? */
- *users, /* List of users or groups */
- *type; /* Allow/deny type */
- int num_users; /* Number of users */
- char *ptr, /* Pointer into users string */
- *end, /* Pointer to end of users string */
- quote; /* Quote character */
- ipp_attribute_t *attr; /* Attribute */
- static const char * const attrs[] = /* Requested attributes */
- {
- "requesting-user-name-allowed",
- "requesting-user-name-denied"
- };
+ attr = ippFindAttribute(response, "printer-error-policy-supported",
+ IPP_TAG_ZERO);
+
+ if (attr)
+ {
+ cgiSetSize("CHOICES", attr->num_values);
+ cgiSetSize("TEXT", attr->num_values);
+ for (k = 0; k < attr->num_values; k ++)
+ {
+ cgiSetArray("CHOICES", k, attr->values[k].string.text);
+ cgiSetArray("TEXT", k, attr->values[k].string.text);
+ }
+ attr = ippFindAttribute(response, "printer-error-policy",
+ IPP_TAG_ZERO);
- is_class = cgiGetVariable("IS_CLASS");
- printer = cgiGetVariable("PRINTER_NAME");
+ cgiSetVariable("KEYWORD", "printer_error_policy");
+ cgiSetVariable("KEYTEXT", cgiText(_("Error Policy")));
+ cgiSetVariable("DEFCHOICE", attr == NULL ?
+ "" : attr->values[0].string.text);
+ }
- if (!printer)
- {
- cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
- cgiStartHTML(cgiText(_("Set Allowed Users")));
- cgiCopyTemplateLang("error.tmpl");
- cgiEndHTML();
- return;
- }
+ cgiCopyTemplateLang("option-pickone.tmpl");
- users = cgiGetVariable("users");
- type = cgiGetVariable("type");
+ /*
+ * Operation policy...
+ */
- if (!users || !type ||
- (strcmp(type, "requesting-user-name-allowed") &&
- strcmp(type, "requesting-user-name-denied")))
- {
- /*
- * Build a Get-Printer-Attributes request, which requires the following
- * attributes:
- *
- * attributes-charset
- * attributes-natural-language
- * printer-uri
- * requested-attributes
- */
+ attr = ippFindAttribute(response, "printer-op-policy-supported",
+ IPP_TAG_ZERO);
- request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+ if (attr)
+ {
+ cgiSetSize("CHOICES", attr->num_values);
+ cgiSetSize("TEXT", attr->num_values);
+ for (k = 0; k < attr->num_values; k ++)
+ {
+ cgiSetArray("CHOICES", k, attr->values[k].string.text);
+ cgiSetArray("TEXT", k, attr->values[k].string.text);
+ }
- httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
- "localhost", 0, is_class ? "/classes/%s" : "/printers/%s",
- printer);
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
- NULL, uri);
+ attr = ippFindAttribute(response, "printer-op-policy", IPP_TAG_ZERO);
- ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
- "requested-attributes",
- (int)(sizeof(attrs) / sizeof(attrs[0])), NULL, attrs);
+ cgiSetVariable("KEYWORD", "printer_op_policy");
+ cgiSetVariable("KEYTEXT", cgiText(_("Operation Policy")));
+ cgiSetVariable("DEFCHOICE", attr == NULL ?
+ "" : attr->values[0].string.text);
- /*
- * Do the request and get back a response...
- */
+ cgiCopyTemplateLang("option-pickone.tmpl");
+ }
- if ((response = cupsDoRequest(http, request, "/")) != NULL)
- {
- cgiSetIPPVars(response, NULL, NULL, NULL, 0);
+ cgiCopyTemplateLang("option-trailer.tmpl");
+ }
ippDelete(response);
}
- cgiStartHTML(cgiText(_("Set Allowed Users")));
-
- if (cupsLastError() > IPP_OK_CONFLICT)
- cgiShowIPPError(_("Unable to get printer attributes:"));
- else
- cgiCopyTemplateLang("users.tmpl");
-
- cgiEndHTML();
- }
- else
- {
/*
- * Save the changes...
+ * Binary protocol support...
*/
- for (num_users = 0, ptr = (char *)users; *ptr; num_users ++)
+ if (ppd->protocols && strstr(ppd->protocols, "BCP"))
{
- /*
- * Skip whitespace and commas...
- */
-
- while (*ptr == ',' || isspace(*ptr & 255))
- ptr ++;
+ protocol = ppdFindAttr(ppd, "cupsProtocol", NULL);
- if (*ptr == '\'' || *ptr == '\"')
- {
- /*
- * Scan quoted name...
- */
+ cgiSetVariable("GROUP", cgiText(_("PS Binary Protocol")));
+ cgiCopyTemplateLang("option-header.tmpl");
- quote = *ptr++;
+ cgiSetSize("CHOICES", 2);
+ cgiSetSize("TEXT", 2);
+ cgiSetArray("CHOICES", 0, "None");
+ cgiSetArray("TEXT", 0, cgiText(_("None")));
- for (end = ptr; *end; end ++)
- if (*end == quote)
- break;
+ if (strstr(ppd->protocols, "TBCP"))
+ {
+ cgiSetArray("CHOICES", 1, "TBCP");
+ cgiSetArray("TEXT", 1, "TBCP");
}
else
{
- /*
- * Scan space or comma-delimited name...
- */
-
- for (end = ptr; *end; end ++)
- if (isspace(*end & 255) || *end == ',')
- break;
+ cgiSetArray("CHOICES", 1, "BCP");
+ cgiSetArray("TEXT", 1, "BCP");
}
- /*
- * Advance to the next name...
- */
+ cgiSetVariable("KEYWORD", "protocol");
+ cgiSetVariable("KEYTEXT", cgiText(_("PS Binary Protocol")));
+ cgiSetVariable("DEFCHOICE", protocol ? protocol->value : "None");
- ptr = end;
+ cgiCopyTemplateLang("option-pickone.tmpl");
+
+ cgiCopyTemplateLang("option-trailer.tmpl");
}
+ cgiCopyTemplateLang("set-printer-options-trailer.tmpl");
+ cgiEndHTML();
+ }
+ else
+ {
/*
- * Build a CUPS-Add-Printer/Class request, which requires the following
- * attributes:
- *
- * attributes-charset
- * attributes-natural-language
- * printer-uri
- * requesting-user-name-{allowed,denied}
+ * Set default options...
*/
- request = ippNewRequest(is_class ? CUPS_ADD_CLASS : CUPS_ADD_PRINTER);
-
- httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
- "localhost", 0, is_class ? "/classes/%s" : "/printers/%s",
- printer);
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
- NULL, uri);
+ fputs("DEBUG: Setting options...\n", stderr);
- if (num_users == 0)
- ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
- "requesting-user-name-allowed", NULL, "all");
- else
+ if (filename)
{
- attr = ippAddStrings(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
- type, num_users, NULL, NULL);
+ out = cupsTempFile2(tempfile, sizeof(tempfile));
+ in = cupsFileOpen(filename, "r");
- for (i = 0, ptr = (char *)users; *ptr; i ++)
+ if (!in || !out)
{
- /*
- * Skip whitespace and commas...
- */
+ cgiSetVariable("ERROR", strerror(errno));
+ cgiStartHTML(cgiText(_("Set Printer Options")));
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
- while (*ptr == ',' || isspace(*ptr & 255))
- ptr ++;
+ if (in)
+ cupsFileClose(in);
- if (*ptr == '\'' || *ptr == '\"')
+ if (out)
{
- /*
- * Scan quoted name...
- */
+ cupsFileClose(out);
+ unlink(tempfile);
+ }
- quote = *ptr++;
+ unlink(filename);
+ return;
+ }
- for (end = ptr; *end; end ++)
- if (*end == quote)
- break;
- }
+ while (cupsFileGets(in, line, sizeof(line)))
+ {
+ if (!strncmp(line, "*cupsProtocol:", 14) && cgiGetVariable("protocol"))
+ continue;
+ else if (strncmp(line, "*Default", 8))
+ cupsFilePrintf(out, "%s\n", line);
else
{
/*
- * Scan space or comma-delimited name...
+ * Get default option name...
*/
- for (end = ptr; *end; end ++)
- if (isspace(*end & 255) || *end == ',')
+ strlcpy(keyword, line + 8, sizeof(keyword));
+
+ for (keyptr = keyword; *keyptr; keyptr ++)
+ if (*keyptr == ':' || isspace(*keyptr & 255))
break;
- }
- /*
- * Terminate the name...
- */
+ *keyptr = '\0';
- if (*end)
- *end++ = '\0';
+ if (!strcmp(keyword, "PageRegion") ||
+ !strcmp(keyword, "PaperDimension") ||
+ !strcmp(keyword, "ImageableArea"))
+ var = cgiGetVariable("PageSize");
+ else
+ var = cgiGetVariable(keyword);
- /*
- * Add the name...
- */
+ if (var != NULL)
+ cupsFilePrintf(out, "*Default%s: %s\n", keyword, var);
+ else
+ cupsFilePrintf(out, "%s\n", line);
+ }
+ }
- attr->values[i].string.text = strdup(ptr);
+ if ((var = cgiGetVariable("protocol")) != NULL)
+ cupsFilePrintf(out, "*cupsProtocol: %s\n", cgiGetVariable("protocol"));
- /*
- * Advance to the next name...
- */
+ cupsFileClose(in);
+ cupsFileClose(out);
+ }
+ else
+ {
+ /*
+ * Make sure temporary filename is cleared when there is no PPD...
+ */
- ptr = end;
- }
+ tempfile[0] = '\0';
}
+ /*
+ * Build a CUPS_ADD_MODIFY_CLASS/PRINTER request, which requires the
+ * following attributes:
+ *
+ * attributes-charset
+ * attributes-natural-language
+ * printer-uri
+ * job-sheets-default
+ * printer-error-policy
+ * printer-op-policy
+ * [ppd file]
+ */
+
+ request = ippNewRequest(is_class ? CUPS_ADD_MODIFY_CLASS :
+ CUPS_ADD_MODIFY_PRINTER);
+
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ NULL, uri);
+
+ attr = ippAddStrings(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ "job-sheets-default", 2, NULL, NULL);
+ attr->values[0].string.text = _cupsStrAlloc(cgiGetVariable("job_sheets_start"));
+ attr->values[1].string.text = _cupsStrAlloc(cgiGetVariable("job_sheets_end"));
+
+ if ((var = cgiGetVariable("printer_error_policy")) != NULL)
+ attr = ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ "printer-error-policy", NULL, var);
+
+ if ((var = cgiGetVariable("printer_op_policy")) != NULL)
+ attr = ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
+ "printer-op-policy", NULL, var);
+
/*
* Do the request and get back a response...
*/
- ippDelete(cupsDoRequest(http, request, "/admin/"));
+ if (filename)
+ ippDelete(cupsDoFileRequest(http, request, "/admin/", tempfile));
+ else
+ ippDelete(cupsDoRequest(http, request, "/admin/"));
if (cupsLastError() > IPP_OK_CONFLICT)
{
- cgiStartHTML(cgiText(_("Set Allowed Users")));
- cgiShowIPPError(_("Unable to change printer:"));
+ cgiStartHTML(title);
+ cgiShowIPPError(_("Unable to set options:"));
}
else
{
* Redirect successful updates back to the printer page...
*/
- char url[1024], /* Printer/class URL */
- refresh[1024]; /* Refresh URL */
+ char refresh[1024]; /* Refresh URL */
- cgiRewriteURL(uri, url, sizeof(url), NULL);
- cgiFormEncode(uri, url, sizeof(uri));
- snprintf(refresh, sizeof(refresh), "5;URL=/admin/?OP=redirect&URL=%s",
- uri);
+ cgiFormEncode(uri, printer, sizeof(uri));
+ snprintf(refresh, sizeof(refresh), "5;URL=/admin/?OP=redirect&URL=/%s/%s",
+ is_class ? "classes" : "printers", uri);
cgiSetVariable("refresh_page", refresh);
- cgiStartHTML(cgiText(_("Set Allowed Users")));
+ cgiStartHTML(title);
- cgiCopyTemplateLang(is_class ? "class-modified.tmpl" :
- "printer-modified.tmpl");
+ cgiCopyTemplateLang("printer-configured.tmpl");
}
cgiEndHTML();
+
+ if (filename)
+ unlink(tempfile);
}
+
+ if (filename)
+ unlink(filename);
}
/*
- * End of "$Id: admin.c 6378 2007-03-21 07:18:18Z mike $".
+ * End of "$Id: admin.c 6440 2007-04-03 23:17:17Z mike $".
*/