/*
- * "$Id: admin.c 7438 2008-04-09 03:27:37Z mike $"
+ * "$Id: admin.c 7888 2008-08-29 21:16:56Z mike $"
*
* Administration CGI for the Common UNIX Printing System (CUPS).
*
* See if we have form data...
*/
- if (!cgiInitialize())
+ if (!cgiInitialize() || !cgiGetVariable("OP"))
{
/*
* Nope, send the administration menu...
snprintf(prefix, sizeof(prefix), "http://%s:%s",
getenv("SERVER_NAME"), getenv("SERVER_PORT"));
+ fprintf(stderr, "DEBUG: redirecting with prefix %s!\n", prefix);
+
if ((url = cgiGetVariable("URL")) != NULL)
printf("Location: %s%s\n\n", prefix, url);
else
*/
if (strncmp(attr->values[0].string.text, var, strlen(var)) == 0)
- cgiSetVariable("DEVICE_URI", attr->values[0].string.text);
+ cgiSetVariable("CURRENT_DEVICE_URI", attr->values[0].string.text);
}
/*
*/
if (oldinfo)
- cgiSetIPPVars(oldinfo, NULL, NULL, NULL, 0);
+ {
+ if ((attr = ippFindAttribute(oldinfo, "printer-info",
+ IPP_TAG_TEXT)) != NULL)
+ cgiSetVariable("PRINTER_INFO", attr->values[0].string.text);
+
+ if ((attr = ippFindAttribute(oldinfo, "printer-location",
+ IPP_TAG_TEXT)) != NULL)
+ cgiSetVariable("PRINTER_LOCATION", attr->values[0].string.text);
+ }
cgiCopyTemplateLang("modify-printer.tmpl");
}
* Get the name, location, and description for a new printer...
*/
+#ifdef __APPLE__
+ if (!strncmp(var, "usb:", 4))
+ cgiSetVariable("printer_is_shared", "1");
+ else
+#endif /* __APPLE__ */
+ cgiSetVariable("printer_is_shared", "0");
+
cgiCopyTemplateLang("add-printer.tmpl");
}
* ppd-name
* device-uri
* printer-is-accepting-jobs
+ * printer-is-shared
* printer-state
*/
NULL, cgiGetVariable("PRINTER_INFO"));
if (!file)
- ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "ppd-name",
- NULL, cgiGetVariable("PPD_NAME"));
+ {
+ var = cgiGetVariable("PPD_NAME");
+ if (strcmp(var, "__no_change__"))
+ ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "ppd-name",
+ NULL, var);
+ }
strlcpy(uri, cgiGetVariable("DEVICE_URI"), sizeof(uri));
ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-accepting-jobs", 1);
+ var = cgiGetVariable("printer_is_shared");
+ ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-shared",
+ var && (!strcmp(var, "1") || !strcmp(var, "on")));
+
ippAddInteger(request, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
IPP_PRINTER_IDLE);
int num_settings; /* Number of server settings */
cups_option_t *settings; /* Server settings */
+ int advanced, /* Advanced settings shown? */
+ changed; /* Have settings changed? */
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 */
- *user_cancel_any;
+ *user_cancel_any,
/* USER_CANCEL_ANY value */
+ *browse_web_if, /* BrowseWebIF value */
+ *preserve_job_history,
+ /* PreserveJobHistory value */
+ *preserve_job_files,
+ /* PreserveJobFiles value */
+ *max_clients, /* MaxClients value */
+ *max_jobs, /* MaxJobs value */
+ *max_log_size; /* MaxLogSize value */
+ char local_protocols[255],
+ /* BrowseLocalProtocols */
+ remote_protocols[255];
+ /* BrowseRemoteProtocols */
#ifdef HAVE_GSSAPI
char default_auth_type[255];
/* DefaultAuthType value */
+ const char *val; /* Setting value */
#endif /* HAVE_GSSAPI */
* Get the checkbox values from the form...
*/
- 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";
+ 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";
+
+ advanced = cgiGetVariable("ADVANCEDSETTINGS") != NULL;
+ if (advanced)
+ {
+ /*
+ * Get advanced settings...
+ */
+
+ browse_web_if = cgiGetVariable("BROWSE_WEB_IF") ? "Yes" : "No";
+ preserve_job_history = cgiGetVariable("PRESERVE_JOB_HISTORY") ? "Yes" : "No";
+ preserve_job_files = cgiGetVariable("PRESERVE_JOB_FILES") ? "Yes" : "No";
+ max_clients = cgiGetVariable("MAX_CLIENTS");
+ max_jobs = cgiGetVariable("MAX_JOBS");
+ max_log_size = cgiGetVariable("MAX_LOG_SIZE");
+
+ if (!max_clients || atoi(max_clients) <= 0)
+ max_clients = "100";
+
+ if (!max_jobs || atoi(max_jobs) <= 0)
+ max_jobs = "500";
+
+ if (!max_log_size || atof(max_log_size) <= 0.0)
+ max_log_size = "1m";
+
+ if (cgiGetVariable("BROWSE_LOCAL_CUPS"))
+ strcpy(local_protocols, "cups");
+ else
+ local_protocols[0] = '\0';
+
+#ifdef HAVE_DNSSD
+ if (cgiGetVariable("BROWSE_LOCAL_DNSSD"))
+ {
+ if (local_protocols[0])
+ strcat(local_protocols, " dnssd");
+ else
+ strcat(local_protocols, "dnssd");
+ }
+#endif /* HAVE_DNSSD */
+
+#ifdef HAVE_LDAP
+ if (cgiGetVariable("BROWSE_LOCAL_LDAP"))
+ {
+ if (local_protocols[0])
+ strcat(local_protocols, " ldap");
+ else
+ strcat(local_protocols, "ldap");
+ }
+#endif /* HAVE_LDAP */
+
+#ifdef HAVE_LIBSLP
+ if (cgiGetVariable("BROWSE_LOCAL_SLP"))
+ {
+ if (local_protocols[0])
+ strcat(local_protocols, " slp");
+ else
+ strcat(local_protocols, "slp");
+ }
+#endif /* HAVE_SLP */
+
+ if (cgiGetVariable("BROWSE_REMOTE_CUPS"))
+ strcpy(remote_protocols, "cups");
+ else
+ remote_protocols[0] = '\0';
+
+#ifdef HAVE_LDAP
+ if (cgiGetVariable("BROWSE_REMOTE_LDAP"))
+ {
+ if (remote_protocols[0])
+ strcat(remote_protocols, " ldap");
+ else
+ strcat(remote_protocols, "ldap");
+ }
+#endif /* HAVE_LDAP */
+
+#ifdef HAVE_LIBSLP
+ if (cgiGetVariable("BROWSE_REMOTE_SLP"))
+ {
+ if (remote_protocols[0])
+ strcat(remote_protocols, " slp");
+ else
+ strcat(remote_protocols, "slp");
+ }
+#endif /* HAVE_SLP */
+ }
/*
* Get the current server settings...
strlcpy(default_auth_type, "Negotiate", sizeof(default_auth_type));
else
{
- const char *val = cupsGetOption("DefaultAuthType", num_settings,
- settings);
+ val = cupsGetOption("DefaultAuthType", num_settings, settings);
- if (val && !strcasecmp(val, "Negotiate"))
+ if (!val || !strcasecmp(val, "Negotiate"))
strlcpy(default_auth_type, "Basic", sizeof(default_auth_type));
else
strlcpy(default_auth_type, val, sizeof(default_auth_type));
* 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)) ||
+ changed = 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)) ||
+ !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)))
+ strcmp(user_cancel_any, cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY,
+ num_settings, settings));
+
+ if (advanced && !changed)
+ changed = cupsGetOption("BrowseLocalProtocols", num_settings, settings) ||
+ strcasecmp(local_protocols,
+ CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS) ||
+ cupsGetOption("BrowseRemoteProtocols", num_settings,
+ settings) ||
+ strcasecmp(remote_protocols,
+ CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS) ||
+ cupsGetOption("BrowseWebIF", num_settings, settings) ||
+ strcasecmp(browse_web_if, "No") ||
+ cupsGetOption("PreserveJobHistory", num_settings, settings) ||
+ strcasecmp(preserve_job_history, "Yes") ||
+ cupsGetOption("PreserveJobFiles", num_settings, settings) ||
+ strcasecmp(preserve_job_files, "No") ||
+ cupsGetOption("MaxClients", num_settings, settings) ||
+ strcasecmp(max_clients, "100") ||
+ cupsGetOption("MaxJobs", num_settings, settings) ||
+ strcasecmp(max_jobs, "500") ||
+ cupsGetOption("MaxLogSize", num_settings, settings) ||
+ strcasecmp(max_log_size, "1m");
+
+ if (changed)
{
/*
* Settings *have* changed, so save the changes...
num_settings, &settings);
#endif /* HAVE_GSSAPI */
+ if (advanced)
+ {
+ /*
+ * Add advanced settings...
+ */
+
+ if (cupsGetOption("BrowseLocalProtocols", num_settings, settings) ||
+ strcasecmp(local_protocols, CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS))
+ num_settings = cupsAddOption("BrowseLocalProtocols", local_protocols,
+ num_settings, &settings);
+ if (cupsGetOption("BrowseRemoteProtocols", num_settings, settings) ||
+ strcasecmp(remote_protocols, CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS))
+ num_settings = cupsAddOption("BrowseRemoteProtocols", remote_protocols,
+ num_settings, &settings);
+ if (cupsGetOption("BrowseWebIF", num_settings, settings) ||
+ strcasecmp(browse_web_if, "No"))
+ num_settings = cupsAddOption("BrowseWebIF", browse_web_if,
+ num_settings, &settings);
+ if (cupsGetOption("PreserveJobHistory", num_settings, settings) ||
+ strcasecmp(preserve_job_history, "Yes"))
+ num_settings = cupsAddOption("PreserveJobHistory",
+ preserve_job_history, num_settings,
+ &settings);
+ if (cupsGetOption("PreserveJobFiles", num_settings, settings) ||
+ strcasecmp(preserve_job_files, "No"))
+ num_settings = cupsAddOption("PreserveJobFiles", preserve_job_files,
+ num_settings, &settings);
+ if (cupsGetOption("MaxClients", num_settings, settings) ||
+ strcasecmp(max_clients, "100"))
+ num_settings = cupsAddOption("MaxClients", max_clients, num_settings,
+ &settings);
+ if (cupsGetOption("MaxJobs", num_settings, settings) ||
+ strcasecmp(max_jobs, "500"))
+ num_settings = cupsAddOption("MaxJobs", max_jobs, num_settings,
+ &settings);
+ if (cupsGetOption("MaxLogSize", num_settings, settings) ||
+ strcasecmp(max_log_size, "1m"))
+ num_settings = cupsAddOption("MaxLogSize", max_log_size, num_settings,
+ &settings);
+ }
+
if (!cupsAdminSetServerSettings(http, num_settings, settings))
{
if (cupsLastError() == IPP_NOT_AUTHORIZED)
cgiSetVariable("KERBEROS", "CHECKED");
#endif /* HAVE_GSSAPI */
+#ifdef HAVE_DNSSD
+ cgiSetVariable("HAVE_DNSSD", "1");
+#endif /* HAVE_DNSSD */
+
+#ifdef HAVE_LDAP
+ cgiSetVariable("HAVE_LDAP", "1");
+#endif /* HAVE_LDAP */
+
+#ifdef HAVE_LIBSLP
+ cgiSetVariable("HAVE_LIBSLP", "1");
+#endif /* HAVE_LIBSLP */
+
+ if ((val = cupsGetOption("BrowseRemoteProtocols", num_settings,
+ settings)) == NULL)
+ if ((val = cupsGetOption("BrowseProtocols", num_settings,
+ settings)) == NULL)
+ val = CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS;
+
+ if (strstr(val, "cups") || strstr(val, "CUPS"))
+ cgiSetVariable("BROWSE_REMOTE_CUPS", "CHECKED");
+
+ if (strstr(val, "ldap") || strstr(val, "LDAP"))
+ cgiSetVariable("BROWSE_REMOTE_LDAP", "CHECKED");
+
+ if (strstr(val, "slp") || strstr(val, "SLP"))
+ cgiSetVariable("BROWSE_REMOTE_SLP", "CHECKED");
+
+ if ((val = cupsGetOption("BrowseLocalProtocols", num_settings,
+ settings)) == NULL)
+ if ((val = cupsGetOption("BrowseProtocols", num_settings,
+ settings)) == NULL)
+ val = CUPS_DEFAULT_BROWSE_LOCAL_PROTOCOLS;
+
+ if (strstr(val, "cups") || strstr(val, "CUPS"))
+ cgiSetVariable("BROWSE_LOCAL_CUPS", "CHECKED");
+
+ if (strstr(val, "dnssd") || strstr(val, "DNSSD") ||
+ strstr(val, "dns-sd") || strstr(val, "DNS-SD") ||
+ strstr(val, "bonjour") || strstr(val, "BONJOUR"))
+ cgiSetVariable("BROWSE_LOCAL_DNSSD", "CHECKED");
+
+ if (strstr(val, "ldap") || strstr(val, "LDAP"))
+ cgiSetVariable("BROWSE_LOCAL_LDAP", "CHECKED");
+
+ if (strstr(val, "slp") || strstr(val, "SLP"))
+ cgiSetVariable("BROWSE_LOCAL_SLP", "CHECKED");
+
+ if ((val = cupsGetOption("BrowseWebIF", num_settings,
+ settings)) == NULL)
+ val = "No";
+
+ if (!strcasecmp(val, "yes") || !strcasecmp(val, "on") ||
+ !strcasecmp(val, "true"))
+ cgiSetVariable("BROWSE_WEB_IF", "CHECKED");
+
+ if ((val = cupsGetOption("PreserveJobHistory", num_settings,
+ settings)) == NULL)
+ val = "Yes";
+
+ if (!strcasecmp(val, "yes") || !strcasecmp(val, "on") ||
+ !strcasecmp(val, "true"))
+ {
+ cgiSetVariable("PRESERVE_JOB_HISTORY", "CHECKED");
+
+ if ((val = cupsGetOption("PreserveJobFiles", num_settings,
+ settings)) == NULL)
+ val = "No";
+
+ if (!strcasecmp(val, "yes") || !strcasecmp(val, "on") ||
+ !strcasecmp(val, "true"))
+ cgiSetVariable("PRESERVE_JOB_FILES", "CHECKED");
+ }
+
+ if ((val = cupsGetOption("MaxClients", num_settings, settings)) == NULL)
+ val = "100";
+
+ cgiSetVariable("MAX_CLIENTS", val);
+
+ if ((val = cupsGetOption("MaxJobs", num_settings, settings)) == NULL)
+ val = "500";
+
+ cgiSetVariable("MAX_JOBS", val);
+
+ if ((val = cupsGetOption("MaxLogSize", num_settings, settings)) == NULL)
+ val = "1m";
+
+ cgiSetVariable("MAX_LOG_SIZE", val);
+
cupsFreeOptions(num_settings, settings);
/*
while (*ptr == ',' || isspace(*ptr & 255))
ptr ++;
+ if (!*ptr)
+ break;
+
if (*ptr == '\'' || *ptr == '\"')
{
/*
while (*ptr == ',' || isspace(*ptr & 255))
ptr ++;
+ if (!*ptr)
+ break;
+
if (*ptr == '\'' || *ptr == '\"')
{
/*
ppd_option_t *option; /* Option */
ppd_coption_t *coption; /* Custom option */
ppd_cparam_t *cparam; /* Custom parameter */
- ppd_attr_t *protocol; /* cupsProtocol attribute */
+ ppd_attr_t *ppdattr; /* PPD attribute */
const char *title; /* Page title */
fprintf(stderr, "DEBUG: printer=\"%s\", uri=\"%s\"...\n", printer, uri);
+ /*
+ * If the user clicks on the Auto-Configure button, send an AutoConfigure
+ * command file to the printer...
+ */
+
+ if (cgiGetVariable("AUTOCONFIGURE"))
+ {
+ int job_id; /* Command file job */
+ char refresh[1024]; /* Refresh URL */
+ http_status_t status; /* Document status */
+ static const char *autoconfigure =/* Command file */
+ "#CUPS-COMMAND\n"
+ "AutoConfigure\n";
+
+
+ if ((job_id = cupsCreateJob(CUPS_HTTP_DEFAULT, printer, "Auto-Configure",
+ 0, NULL)) < 1)
+ {
+ cgiSetVariable("ERROR", cgiText(_("Unable to send auto-configure command "
+ "to printer driver!")));
+ cgiStartHTML(title);
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
+ return;
+ }
+
+ status = cupsStartDocument(CUPS_HTTP_DEFAULT, printer, job_id,
+ "AutoConfigure.command", CUPS_FORMAT_COMMAND, 1);
+ if (status == HTTP_CONTINUE)
+ status = cupsWriteRequestData(CUPS_HTTP_DEFAULT, autoconfigure,
+ strlen(autoconfigure));
+ if (status == HTTP_CONTINUE)
+ cupsFinishDocument(CUPS_HTTP_DEFAULT, printer);
+
+ if (cupsLastError() >= IPP_REDIRECTION_OTHER_SITE)
+ {
+ cgiSetVariable("ERROR", cupsLastErrorString());
+ cgiStartHTML(title);
+ cgiCopyTemplateLang("error.tmpl");
+ cgiEndHTML();
+
+ cupsCancelJob(printer, job_id);
+ return;
+ }
+
+ /*
+ * Redirect successful updates back to the printer page...
+ */
+
+ 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(title);
+
+ cgiCopyTemplateLang("printer-configured.tmpl");
+ cgiEndHTML();
+ return;
+ }
+
/*
* Get the PPD file...
*/
fputs("DEBUG: Showing options...\n", stderr);
+ if (ppd)
+ {
+ if (ppd->num_filters == 0 ||
+ ((ppdattr = ppdFindAttr(ppd, "cupsCommands", NULL)) != NULL &&
+ ppdattr->value && strstr(ppdattr->value, "AutoConfigure")))
+ cgiSetVariable("HAVE_AUTOCONFIGURE", "YES");
+ else
+ {
+ for (i = 0; i < ppd->num_filters; i ++)
+ if (!strncmp(ppd->filters[i], "application/vnd.cups-postscript", 31))
+ {
+ cgiSetVariable("HAVE_AUTOCONFIGURE", "YES");
+ break;
+ }
+ }
+ }
+
cgiStartHTML(cgiText(_("Set Printer Options")));
cgiCopyTemplateLang("set-printer-options-header.tmpl");
if (ppd && ppd->protocols && strstr(ppd->protocols, "BCP"))
{
- protocol = ppdFindAttr(ppd, "cupsProtocol", NULL);
+ ppdattr = ppdFindAttr(ppd, "cupsProtocol", NULL);
cgiSetVariable("GROUP", cgiText(_("PS Binary Protocol")));
cgiCopyTemplateLang("option-header.tmpl");
cgiSetVariable("KEYWORD", "protocol");
cgiSetVariable("KEYTEXT", cgiText(_("PS Binary Protocol")));
- cgiSetVariable("DEFCHOICE", protocol ? protocol->value : "None");
+ cgiSetVariable("DEFCHOICE", ppdattr ? ppdattr->value : "None");
cgiCopyTemplateLang("option-pickone.tmpl");
/*
- * End of "$Id: admin.c 7438 2008-04-09 03:27:37Z mike $".
+ * End of "$Id: admin.c 7888 2008-08-29 21:16:56Z mike $".
*/