/*
- * "$Id: classes.c 6889 2007-08-29 22:23:35Z mike $"
+ * "$Id$"
*
- * Class status CGI for the Common UNIX Printing System (CUPS).
+ * Class status CGI for CUPS.
*
- * Copyright 2007 by Apple Inc.
- * Copyright 1997-2006 by Easy Software Products.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
*
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
- *
- * Contents:
- *
- * main() - Main entry for CGI.
- * show_all_classes() - Show all classes...
- * show_class() - Show a single class.
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*/
/*
* Local functions...
*/
-void show_all_classes(http_t *http, const char *username);
-void show_class(http_t *http, const char *printer);
+static void do_class_op(http_t *http, const char *printer, ipp_op_t op,
+ const char *title);
+static void show_all_classes(http_t *http, const char *username);
+static void show_class(http_t *http, const char *printer);
/*
*/
int /* O - Exit status */
-main(int argc, /* I - Number of command-line arguments */
- char *argv[]) /* I - Command-line arguments */
+main(void)
{
const char *pclass; /* Class name */
const char *user; /* Username */
*/
cgiSetVariable("SECTION", "classes");
+ cgiSetVariable("REFRESH_PAGE", "");
/*
* See if we are displaying a printer or all classes...
if (!*pclass)
pclass = NULL;
+
+ if (pclass)
+ cgiSetVariable("PRINTER_NAME", pclass);
}
/*
else
show_class(http, pclass);
}
- else if (!strcasecmp(op, "print-test-page") && pclass)
- cgiPrintTestPage(http, pclass);
- else if (!strcasecmp(op, "move-jobs") && pclass)
- cgiMoveJobs(http, pclass, 0);
+ else if (pclass)
+ {
+ if (!*op)
+ {
+ const char *server_port = getenv("SERVER_PORT");
+ /* Port number string */
+ int port = atoi(server_port ? server_port : "0");
+ /* Port number */
+ char uri[1024]; /* URL */
+
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri),
+ getenv("HTTPS") ? "https" : "http", NULL,
+ getenv("SERVER_NAME"), port, "/classes/%s", pclass);
+
+ printf("Location: %s\n\n", uri);
+ }
+ else if (!strcmp(op, "start-class"))
+ do_class_op(http, pclass, IPP_RESUME_PRINTER, cgiText(_("Resume Class")));
+ else if (!strcmp(op, "stop-class"))
+ do_class_op(http, pclass, IPP_PAUSE_PRINTER, cgiText(_("Pause Class")));
+ else if (!strcmp(op, "accept-jobs"))
+ do_class_op(http, pclass, CUPS_ACCEPT_JOBS, cgiText(_("Accept Jobs")));
+ else if (!strcmp(op, "reject-jobs"))
+ do_class_op(http, pclass, CUPS_REJECT_JOBS, cgiText(_("Reject Jobs")));
+ else if (!strcmp(op, "cancel-jobs"))
+ do_class_op(http, pclass, IPP_OP_CANCEL_JOBS, cgiText(_("Cancel Jobs")));
+ else if (!_cups_strcasecmp(op, "print-test-page"))
+ cgiPrintTestPage(http, pclass);
+ else if (!_cups_strcasecmp(op, "move-jobs"))
+ cgiMoveJobs(http, pclass, 0);
+ else
+ {
+ /*
+ * Unknown/bad operation...
+ */
+
+ cgiStartHTML(pclass);
+ cgiCopyTemplateLang("error-op.tmpl");
+ cgiEndHTML();
+ }
+ }
else
{
/*
* Unknown/bad operation...
*/
- if (pclass)
- cgiStartHTML(pclass);
- else
- cgiStartHTML(cgiText(_("Classes")));
-
+ cgiStartHTML(cgiText(_("Classes")));
cgiCopyTemplateLang("error-op.tmpl");
cgiEndHTML();
}
}
+/*
+ * 'do_class_op()' - Do a class operation.
+ */
+
+static void
+do_class_op(http_t *http, /* I - HTTP connection */
+ const char *printer, /* I - Printer name */
+ 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 */
+ resource[HTTP_MAX_URI]; /* Path for request */
+
+
+ /*
+ * Build a printer request, which requires the following
+ * attributes:
+ *
+ * attributes-charset
+ * attributes-natural-language
+ * printer-uri
+ */
+
+ request = ippNewRequest(op);
+
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+ "localhost", 0, "/classes/%s", printer);
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+ NULL, uri);
+
+ /*
+ * Do the request and get back a response...
+ */
+
+ snprintf(resource, sizeof(resource), "/classes/%s", printer);
+ ippDelete(cupsDoRequest(http, request, resource));
+
+ if (cupsLastError() == IPP_NOT_AUTHORIZED)
+ {
+ puts("Status: 401\n");
+ exit(0);
+ }
+ else if (cupsLastError() > IPP_OK_CONFLICT)
+ {
+ cgiStartHTML(title);
+ cgiShowIPPError(_("Unable to do maintenance command"));
+ }
+ else
+ {
+ /*
+ * Redirect successful updates back to the printer page...
+ */
+
+ char url[1024], /* Printer/class URL */
+ refresh[1024]; /* Refresh URL */
+
+
+ cgiRewriteURL(uri, url, sizeof(url), NULL);
+ cgiFormEncode(uri, url, sizeof(uri));
+ snprintf(refresh, sizeof(refresh), "5;URL=%s", uri);
+ cgiSetVariable("refresh_page", refresh);
+
+ cgiStartHTML(title);
+
+ cgiSetVariable("IS_CLASS", "YES");
+
+ 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_OP_CANCEL_JOBS)
+ cgiCopyTemplateLang("printer-cancel-jobs.tmpl");
+ }
+
+ cgiEndHTML();
+}
+
+
/*
* 'show_all_classes()' - Show all classes...
*/
-void
+static void
show_all_classes(http_t *http, /* I - Connection to server */
const char *user) /* I - Username */
{
sprintf(val, "%d", count);
cgiSetVariable("TOTAL", val);
- if ((var = cgiGetVariable("ORDER")) != NULL)
- ascending = !strcasecmp(var, "asc");
+ if ((var = cgiGetVariable("ORDER")) != NULL && *var)
+ ascending = !_cups_strcasecmp(var, "asc");
else
ascending = 1;
cgiCopyTemplateLang("classes-header.tmpl");
- if (count > 0)
+ if (count > CUPS_PAGE_MAX)
cgiCopyTemplateLang("pager.tmpl");
cgiCopyTemplateLang("classes.tmpl");
- if (count > 0)
+ if (count > CUPS_PAGE_MAX)
cgiCopyTemplateLang("pager.tmpl");
/*
* Show the error...
*/
- cgiShowIPPError(_("Unable to get class list:"));
+ cgiShowIPPError(_("Unable to get class list"));
}
cgiEndHTML();
* 'show_class()' - Show a single class.
*/
-void
+static void
show_class(http_t *http, /* I - Connection to server */
const char *pclass) /* I - Name of class */
{
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL,
uri);
- cgiGetAttributes(request, "classes.tmpl");
+ cgiGetAttributes(request, "class.tmpl");
/*
* Do the request and get back a response...
* Show the class status...
*/
- cgiSetVariable("_SINGLE_DEST", "1");
- cgiCopyTemplateLang("classes.tmpl");
+ cgiCopyTemplateLang("class.tmpl");
/*
* Show jobs for the specified class...
*/
cgiStartHTML(pclass);
- cgiShowIPPError(_("Unable to get class status:"));
+ cgiShowIPPError(_("Unable to get class status"));
}
cgiEndHTML();
/*
- * End of "$Id: classes.c 6889 2007-08-29 22:23:35Z mike $".
+ * End of "$Id$".
*/