]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cgi-bin/admin.c
Merge changes from CUPS 1.4svn-r7994.
[thirdparty/cups.git] / cgi-bin / admin.c
index f8c0d55e4789fde51c8c6ea4fac9f5719d6116f0..70a57dc5e0e0d7a35bb6fae7101b67b2e4abdb5f 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: admin.c 6378 2007-03-21 07:18:18Z mike $"
+ * "$Id: admin.c 7888 2008-08-29 21:16:56Z mike $"
  *
  *   Administration CGI for the Common UNIX Printing System (CUPS).
  *
+ *   Copyright 2007-2008 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   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:
  *
  *   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_menu()                 - Show the main menu...
+ *   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_sharing()          - Set printer-is-shared value...
+ *   do_set_options()          - Configure the default options for a queue.
+ *   do_set_sharing()          - Set printer-is-shared value.
+ *   get_option_value()        - Return the value of an option.
+ *   get_points()              - Get a value in points.
  *   match_string()            - Return the number of matching characters.
  */
 
@@ -51,6 +45,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/wait.h>
+#include <limits.h>
 
 
 /*
@@ -61,16 +56,20 @@ static void do_add_rss_subscription(http_t *http);
 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);
 static void    do_set_allowed_users(http_t *http);
 static void    do_set_sharing(http_t *http);
+static char    *get_option_value(ppd_file_t *ppd, const char *name,
+                                 char *buffer, size_t bufsize);
+static double  get_points(double number, const char *uval);
 static int     match_string(const char *a, const char *b);
 
 
@@ -116,7 +115,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   * See if we have form data...
   */
 
-  if (!cgiInitialize())
+  if (!cgiInitialize() || !cgiGetVariable("OP"))
   {
    /*
     * Nope, send the administration menu...
@@ -126,7 +125,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
     do_menu(http);
   }
-  else if ((op = cgiGetVariable("OP")) != NULL)
+  else if ((op = cgiGetVariable("OP")) != NULL && cgiIsPOST())
   {
    /*
     * Do the operation...
@@ -134,25 +133,7 @@ main(int  argc,                            /* I - Number of command-line arguments */
 
     fprintf(stderr, "DEBUG: op=\"%s\"...\n", op);
 
-    if (!strcmp(op, "redirect"))
-    {
-      const char *url;                 /* Redirection URL... */
-      char     prefix[1024];           /* URL prefix */
-
-
-      if (getenv("HTTPS"))
-        snprintf(prefix, sizeof(prefix), "https://%s:%s",
-                getenv("SERVER_NAME"), getenv("SERVER_PORT"));
-      else
-        snprintf(prefix, sizeof(prefix), "http://%s:%s",
-                getenv("SERVER_NAME"), getenv("SERVER_PORT"));
-
-      if ((url = cgiGetVariable("URL")) != NULL)
-        printf("Location: %s%s\n\n", prefix, url);
-      else
-        printf("Location: %s/admin\n\n", prefix);
-    }
-    else if (!strcmp(op, "start-printer"))
+    if (!strcmp(op, "start-printer"))
       do_printer_op(http, IPP_RESUME_PRINTER, cgiText(_("Start Printer")));
     else if (!strcmp(op, "stop-printer"))
       do_printer_op(http, IPP_PAUSE_PRINTER, cgiText(_("Stop Printer")));
@@ -172,6 +153,9 @@ main(int  argc,                             /* I - Number of command-line arguments */
       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, "find-new-printers") ||
+             !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"))
@@ -184,8 +168,10 @@ main(int  argc,                            /* I - Number of command-line arguments */
       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"))
@@ -197,7 +183,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
     else
     {
      /*
-      * Bad operation code...  Display an error...
+      * Bad operation code - display an error...
       */
 
       cgiStartHTML(cgiText(_("Administration")));
@@ -205,10 +191,30 @@ main(int  argc,                           /* I - Number of command-line arguments */
       cgiEndHTML();
     }
   }
+  else if (op && !strcmp(op, "redirect"))
+  {
+    const char *url;                   /* Redirection URL... */
+    char       prefix[1024];           /* URL prefix */
+
+
+    if (getenv("HTTPS"))
+      snprintf(prefix, sizeof(prefix), "https://%s:%s",
+              getenv("SERVER_NAME"), getenv("SERVER_PORT"));
+    else
+      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
+      printf("Location: %s/admin\n\n", prefix);
+  }
   else
   {
    /*
-    * Form data but no operation code...  Display an error...
+    * Form data but no operation code - display an error...
     */
 
     cgiStartHTML(cgiText(_("Administration")));
@@ -310,6 +316,16 @@ do_add_rss_subscription(http_t *http)      /* I - HTTP connection */
     return;
   }
 
+ /*
+  * Make sure we have a username...
+  */
+
+  if ((user = getenv("REMOTE_USER")) == NULL)
+  {
+    puts("Status: 401\n");
+    exit(0);
+  }
+
  /*
   * Validate the subscription name...
   */
@@ -354,9 +370,6 @@ do_add_rss_subscription(http_t *http)       /* I - HTTP connection */
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
                  NULL, printer_uri);
 
-  if ((user = getenv("REMOTE_USER")) == NULL)
-    user = "guest";
-
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
                NULL, user);
 
@@ -369,7 +382,12 @@ do_add_rss_subscription(http_t *http)      /* I - HTTP connection */
 
   ippDelete(cupsDoRequest(http, request, "/"));
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() == IPP_NOT_AUTHORIZED)
+  {
+    puts("Status: 401\n");
+    exit(0);
+  }
+  else if (cupsLastError() > IPP_OK_CONFLICT)
   {
     cgiStartHTML(_("Add RSS Subscription"));
     cgiShowIPPError(_("Unable to add RSS subscription:"));
@@ -630,7 +648,12 @@ do_am_class(http_t *http,          /* I - HTTP connection */
 
   ippDelete(cupsDoRequest(http, request, "/admin/"));
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() == IPP_NOT_AUTHORIZED)
+  {
+    puts("Status: 401\n");
+    exit(0);
+  }
+  else if (cupsLastError() > IPP_OK_CONFLICT)
   {
     cgiStartHTML(title);
     cgiShowIPPError(modify ? _("Unable to modify class:") :
@@ -732,67 +755,101 @@ do_am_printer(http_t *http,              /* I - HTTP connection */
   else
     oldinfo = NULL;
 
-  if ((name = cgiGetVariable("PRINTER_NAME")) == NULL ||
-      cgiGetVariable("PRINTER_LOCATION") == NULL)
-  {
-    cgiStartHTML(title);
+  file = cgiGetFile();
 
-    if (modify)
-    {
-     /*
-      * Update the location and description of an existing printer...
-      */
+  if (file)
+  {
+    fprintf(stderr, "DEBUG: file->tempfile=%s\n", file->tempfile);
+    fprintf(stderr, "DEBUG: file->name=%s\n", file->name);
+    fprintf(stderr, "DEBUG: file->filename=%s\n", file->filename);
+    fprintf(stderr, "DEBUG: file->mimetype=%s\n", file->mimetype);
+  }
 
-      if (oldinfo)
-       cgiSetIPPVars(oldinfo, NULL, NULL, NULL, 0);
+  if ((name = cgiGetVariable("PRINTER_NAME")) != NULL)
+  {
+    for (ptr = name; *ptr; ptr ++)
+      if ((*ptr >= 0 && *ptr <= ' ') || *ptr == 127 || *ptr == '/' || *ptr == '#')
+       break;
 
-      cgiCopyTemplateLang("modify-printer.tmpl");
+    if (*ptr || ptr == name || strlen(name) > 127)
+    {
+      cgiSetVariable("ERROR",
+                    cgiText(_("The printer name may only contain up to "
+                              "127 printable characters and may not "
+                              "contain spaces, slashes (/), or the "
+                              "pound sign (#).")));
+      cgiStartHTML(title);
+      cgiCopyTemplateLang("error.tmpl");
+      cgiEndHTML();
+      return;
     }
-    else
+  }
+
+  if ((var = cgiGetVariable("DEVICE_URI")) != NULL)
+  {
+    if ((uriptr = strrchr(var, '|')) != NULL)
     {
      /*
-      * Get the name, location, and description for a new printer...
+      * Extract make and make/model from device URI string...
       */
 
-      cgiCopyTemplateLang("add-printer.tmpl");
-    }
+      char     make[1024],             /* Make string */
+               *makeptr;               /* Pointer into make */
 
-    cgiEndHTML();
 
-    if (oldinfo)
-      ippDelete(oldinfo);
+      *uriptr++ = '\0';
 
-    return;
-  }
+      strlcpy(make, uriptr, sizeof(make));
 
-  for (ptr = name; *ptr; ptr ++)
-    if ((*ptr >= 0 && *ptr <= ' ') || *ptr == 127 || *ptr == '/' || *ptr == '#')
-      break;
+      if ((makeptr = strchr(make, ' ')) != NULL)
+        *makeptr = '\0';
+      else if ((makeptr = strchr(make, '-')) != NULL)
+        *makeptr = '\0';
+      else if (!strncasecmp(make, "laserjet", 8) ||
+               !strncasecmp(make, "deskjet", 7) ||
+               !strncasecmp(make, "designjet", 9))
+        strcpy(make, "HP");
+      else if (!strncasecmp(make, "phaser", 6))
+        strcpy(make, "Xerox");
+      else if (!strncasecmp(make, "stylus", 6))
+        strcpy(make, "Epson");
+      else
+        strcpy(make, "Generic");
 
-  if (*ptr || ptr == name || strlen(name) > 127)
-  {
-    cgiSetVariable("ERROR",
-                   cgiText(_("The printer name may only contain up to "
-                            "127 printable characters and may not "
-                            "contain spaces, slashes (/), or the "
-                            "pound sign (#).")));
-    cgiStartHTML(title);
-    cgiCopyTemplateLang("error.tmpl");
-    cgiEndHTML();
-    return;
-  }
+      if (!cgiGetVariable("CURRENT_MAKE"))
+        cgiSetVariable("CURRENT_MAKE", make);
 
-  file = cgiGetFile();
+      cgiSetVariable("PPD_MAKE", make);
 
-  if (file)
-  {
-    fprintf(stderr, "DEBUG: file->tempfile=%s\n", file->tempfile);
-    fprintf(stderr, "DEBUG: file->name=%s\n", file->name);
-    fprintf(stderr, "DEBUG: file->filename=%s\n", file->filename);
-    fprintf(stderr, "DEBUG: file->mimetype=%s\n", file->mimetype);
+      if (!cgiGetVariable("CURRENT_MAKE_AND_MODEL"))
+        cgiSetVariable("CURRENT_MAKE_AND_MODEL", uriptr);
+
+      if (!modify)
+      {
+        char   template[128],          /* Template name */
+               *tptr;                  /* Pointer into template name */
+
+       cgiSetVariable("PRINTER_INFO", uriptr);
+
+       for (tptr = template;
+            tptr < (template + sizeof(template) - 1) && *uriptr;
+            uriptr ++)
+         if (isalnum(*uriptr & 255) || *uriptr == '_' || *uriptr == '-' ||
+             *uriptr == '.')
+           *tptr++ = *uriptr;
+         else if ((*uriptr == ' ' || *uriptr == '/') && tptr[-1] != '_')
+           *tptr++ = '_';
+         else if (*uriptr == '?' || *uriptr == '(')
+           break;
+
+        *tptr = '\0';
+
+        cgiSetVariable("TEMPLATE_NAME", template);
+      }
+    }
   }
 
-  if ((var = cgiGetVariable("DEVICE_URI")) == NULL)
+  if (!var)
   {
    /*
     * Build a CUPS_GET_DEVICES request, which requires the following
@@ -853,7 +910,7 @@ do_am_printer(http_t *http,         /* I - HTTP connection */
       */
 
       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);
     }
 
    /*
@@ -889,7 +946,53 @@ do_am_printer(http_t *http,                /* I - HTTP connection */
     cgiCopyTemplateLang("choose-serial.tmpl");
     cgiEndHTML();
   }
-  else if (!file && (var = cgiGetVariable("PPD_NAME")) == NULL)
+  else if (!name || !cgiGetVariable("PRINTER_LOCATION"))
+  {
+    cgiStartHTML(title);
+
+    if (modify)
+    {
+     /*
+      * Update the location and description of an existing printer...
+      */
+
+      if (oldinfo)
+      {
+        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");
+    }
+    else
+    {
+     /*
+      * 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");
+    }
+
+    cgiEndHTML();
+
+    if (oldinfo)
+      ippDelete(oldinfo);
+
+    return;
+  }
+  else if (!file && !cgiGetVariable("PPD_NAME"))
   {
     if (modify)
     {
@@ -951,39 +1054,6 @@ do_am_printer(http_t *http,               /* I - HTTP connection */
                strerror(errno));
       }
     }
-    else if ((uriptr = strrchr(cgiGetVariable("DEVICE_URI"), '|')) != NULL)
-    {
-     /*
-      * Extract make and make/model from device URI string...
-      */
-
-      char     make[1024],             /* Make string */
-               *makeptr;               /* Pointer into make */
-
-
-      *uriptr++ = '\0';
-
-      strlcpy(make, uriptr, sizeof(make));
-
-      if ((makeptr = strchr(make, ' ')) != NULL)
-        *makeptr = '\0';
-      else if ((makeptr = strchr(make, '-')) != NULL)
-        *makeptr = '\0';
-      else if (!strncasecmp(make, "laserjet", 8) ||
-               !strncasecmp(make, "deskjet", 7) ||
-               !strncasecmp(make, "designjet", 9))
-        strcpy(make, "HP");
-      else if (!strncasecmp(make, "phaser", 6))
-        strcpy(make, "Xerox");
-      else if (!strncasecmp(make, "stylus", 6))
-        strcpy(make, "Epson");
-      else
-        strcpy(make, "Generic");
-
-      cgiSetVariable("CURRENT_MAKE", make);
-      cgiSetVariable("PPD_MAKE", make);
-      cgiSetVariable("CURRENT_MAKE_AND_MODEL", uriptr);
-    }
 
    /*
     * Build a CUPS_GET_PPDS request, which requires the following
@@ -999,7 +1069,9 @@ do_am_printer(http_t *http,                /* I - HTTP connection */
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
                  NULL, "ipp://localhost/printers/");
 
-    if ((var = cgiGetVariable("PPD_MAKE")) != NULL)
+    if ((var = cgiGetVariable("CURRENT_MAKE")) == NULL)
+      var = cgiGetVariable("PPD_MAKE");
+    if (var)
       ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_TEXT,
                    "ppd-make", NULL, var);
     else
@@ -1039,7 +1111,7 @@ do_am_printer(http_t *http,               /* I - HTTP connection */
        cgiCopyTemplateLang("choose-make.tmpl");
         cgiEndHTML();
       }
-      else if (!var)
+      else if (!var || cgiGetVariable("SELECT_MAKE"))
       {
         cgiStartHTML(title);
        cgiCopyTemplateLang("choose-make.tmpl");
@@ -1120,6 +1192,7 @@ do_am_printer(http_t *http,               /* I - HTTP connection */
     *    ppd-name
     *    device-uri
     *    printer-is-accepting-jobs
+    *    printer-is-shared
     *    printer-state
     */
 
@@ -1138,8 +1211,12 @@ do_am_printer(http_t *http,              /* I - HTTP connection */
                  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));
 
@@ -1170,6 +1247,10 @@ do_am_printer(http_t *http,              /* I - HTTP connection */
 
     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);
 
@@ -1182,16 +1263,21 @@ do_am_printer(http_t *http,             /* I - HTTP connection */
     else
       ippDelete(cupsDoRequest(http, request, "/admin/"));
 
-    if (cupsLastError() > IPP_OK_CONFLICT)
+    if (cupsLastError() == IPP_NOT_AUTHORIZED)
+    {
+      puts("Status: 401\n");
+      exit(0);
+    }
+    else if (cupsLastError() > IPP_OK_CONFLICT)
     {
       cgiStartHTML(title);
       cgiShowIPPError(modify ? _("Unable to modify printer:") :
                                _("Unable to add printer:"));
     }
-    else
+    else if (modify)
     {
      /*
-      * Redirect successful updates back to the printer or set-options pages...
+      * Redirect successful updates back to the printer page...
       */
 
       char     refresh[1024];          /* Refresh URL */
@@ -1199,21 +1285,24 @@ do_am_printer(http_t *http,             /* I - HTTP connection */
 
       cgiFormEncode(uri, name, sizeof(uri));
 
-      if (modify)
-       snprintf(refresh, sizeof(refresh),
-                "5;/admin/?OP=redirect&URL=/printers/%s", uri);
-      else
-       snprintf(refresh, sizeof(refresh),
-                "5;URL=/admin/?OP=set-printer-options&PRINTER_NAME=%s", uri);
+      snprintf(refresh, sizeof(refresh),
+              "5;/admin/?OP=redirect&URL=/printers/%s", uri);
 
       cgiSetVariable("refresh_page", refresh);
 
       cgiStartHTML(title);
 
-      if (modify)
-        cgiCopyTemplateLang("printer-modified.tmpl");
-      else
-        cgiCopyTemplateLang("printer-added.tmpl");
+      cgiCopyTemplateLang("printer-modified.tmpl");
+    }
+    else
+    {
+     /*
+      * Set the printer options...
+      */
+
+      cgiSetVariable("OP", "set-printer-options");
+      do_set_options(http, 0);
+      return;
     }
 
     cgiEndHTML();
@@ -1255,6 +1344,16 @@ do_cancel_subscription(http_t *http)/* I - HTTP connection */
     return;
   }
 
+ /*
+  * Require a username...
+  */
+
+  if ((user = getenv("REMOTE_USER")) == NULL)
+  {
+    puts("Status: 401\n");
+    exit(0);
+  }
+
  /*
   * Cancel the subscription...
   */
@@ -1266,15 +1365,17 @@ do_cancel_subscription(http_t *http)/* I - HTTP connection */
   ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
                 "notify-subscription-id", id);
 
-  if ((user = getenv("REMOTE_USER")) == NULL)
-    user = "guest";
-
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
                NULL, user);
 
   ippDelete(cupsDoRequest(http, request, "/"));
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() == IPP_NOT_AUTHORIZED)
+  {
+    puts("Status: 401\n");
+    exit(0);
+  }
+  else if (cupsLastError() > IPP_OK_CONFLICT)
   {
     cgiStartHTML(_("Cancel RSS Subscription"));
     cgiShowIPPError(_("Unable to cancel RSS subscription:"));
@@ -1295,1641 +1396,2053 @@ do_cancel_subscription(http_t *http)/* I - HTTP connection */
 
 
 /*
- * '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 */
+  if (cgiGetVariable("CHANGESETTINGS"))
+  {
+   /*
+    * Save basic setting changes...
+    */
 
+    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 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 */
 
-  title = cgiText(_("Set Printer Options"));
 
-  fprintf(stderr, "DEBUG: do_config_printer(http=%p)\n", http);
+   /*
+    * Get the checkbox values from the form...
+    */
 
- /*
-  * Get the printer name...
-  */
+    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";
 
-  if ((printer = cgiGetVariable("PRINTER_NAME")) != NULL)
-    httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
-                     "localhost", 0, "/printers/%s", printer);
-  else
-  {
-    cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
-    cgiStartHTML(title);
-    cgiCopyTemplateLang("error.tmpl");
-    cgiEndHTML();
-    return;
-  }
-
-  fprintf(stderr, "DEBUG: printer=\"%s\", uri=\"%s\"...\n", printer, uri);
-
- /*
-  * Get the PPD file...
-  */
-
-  if ((filename = cupsGetPPD2(http, printer)) == NULL)
-  {
-    fputs("DEBUG: No PPD file!?!\n", stderr);
+    advanced = cgiGetVariable("ADVANCEDSETTINGS") != NULL;
+    if (advanced)
+    {
+     /*
+      * Get advanced settings...
+      */
 
-    cgiStartHTML(title);
-    cgiShowIPPError(_("Unable to get PPD file!"));
-    cgiEndHTML();
-    return;
-  }
+      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");
 
-  fprintf(stderr, "DEBUG: Got PPD file: \"%s\"\n", filename);
+      if (!max_clients || atoi(max_clients) <= 0)
+       max_clients = "100";
 
-  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;
-  }
+      if (!max_jobs || atoi(max_jobs) <= 0)
+       max_jobs = "500";
 
-  if (cgiGetVariable("job_sheets_start") != NULL ||
-      cgiGetVariable("job_sheets_end") != NULL)
-    have_options = 1;
-  else
-    have_options = 0;
+      if (!max_log_size || atof(max_log_size) <= 0.0)
+       max_log_size = "1m";
 
-  ppdMarkDefaults(ppd);
+      if (cgiGetVariable("BROWSE_LOCAL_CUPS"))
+       strcpy(local_protocols, "cups");
+      else
+       local_protocols[0] = '\0';
 
-  DEBUG_printf(("<P>ppd->num_groups = %d\n"
-                "<UL>\n", ppd->num_groups));
+#ifdef HAVE_DNSSD
+      if (cgiGetVariable("BROWSE_LOCAL_DNSSD"))
+      {
+       if (local_protocols[0])
+         strcat(local_protocols, " dnssd");
+       else
+         strcat(local_protocols, "dnssd");
+      }
+#endif /* HAVE_DNSSD */
 
-  for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
-  {
-    DEBUG_printf(("<LI>%s<UL>\n", group->text));
+#ifdef HAVE_LDAP
+      if (cgiGetVariable("BROWSE_LOCAL_LDAP"))
+      {
+       if (local_protocols[0])
+         strcat(local_protocols, " ldap");
+       else
+         strcat(local_protocols, "ldap");
+      }
+#endif /* HAVE_LDAP */
 
-    for (j = group->num_options, option = group->options;
-         j > 0;
-        j --, option ++)
-      if ((var = cgiGetVariable(option->keyword)) != NULL)
+#ifdef HAVE_LIBSLP
+      if (cgiGetVariable("BROWSE_LOCAL_SLP"))
       {
-        DEBUG_printf(("<LI>%s = \"%s\"</LI>\n", option->keyword, var));
-        have_options = 1;
-       ppdMarkOption(ppd, option->keyword, var);
+       if (local_protocols[0])
+         strcat(local_protocols, " slp");
+       else
+         strcat(local_protocols, "slp");
       }
-#ifdef DEBUG
+#endif /* HAVE_SLP */
+      
+      if (cgiGetVariable("BROWSE_REMOTE_CUPS"))
+       strcpy(remote_protocols, "cups");
       else
-        printf("<LI>%s not defined!</LI>\n", option->keyword);
-#endif /* DEBUG */
+       remote_protocols[0] = '\0';
 
-    DEBUG_puts("</UL></LI>");
-  }
+#ifdef HAVE_LDAP
+      if (cgiGetVariable("BROWSE_REMOTE_LDAP"))
+      {
+       if (remote_protocols[0])
+         strcat(remote_protocols, " ldap");
+       else
+         strcat(remote_protocols, "ldap");
+      }
+#endif /* HAVE_LDAP */
 
-  DEBUG_printf(("</UL>\n"
-                "<P>ppdConflicts(ppd) = %d\n", ppdConflicts(ppd)));
+#ifdef HAVE_LIBSLP
+      if (cgiGetVariable("BROWSE_REMOTE_SLP"))
+      {
+       if (remote_protocols[0])
+         strcat(remote_protocols, " slp");
+       else
+         strcat(remote_protocols, "slp");
+      }
+#endif /* HAVE_SLP */
+    }
 
-  if (!have_options || ppdConflicts(ppd))
-  {
    /*
-    * Show the options to the user...
+    * Get the current server settings...
     */
 
-    fputs("DEBUG: Showing options...\n", stderr);
-
-    ppdLocalize(ppd);
-
-    cgiStartHTML(cgiText(_("Set Printer Options")));
-    cgiCopyTemplateLang("set-printer-options-header.tmpl");
-
-    if (ppdConflicts(ppd))
+    if (!cupsAdminGetServerSettings(http, &num_settings, &settings))
     {
-      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(_("Change Settings")));
+      cgiSetVariable("MESSAGE",
+                     cgiText(_("Unable to change server settings:")));
+      cgiSetVariable("ERROR", cupsLastErrorString());
+      cgiCopyTemplateLang("error.tmpl");
+      cgiEndHTML();
+      return;
     }
 
-    for (i = ppd->num_groups, group = ppd->groups;
-        i > 0;
-        i --, group ++)
+#ifdef HAVE_GSSAPI
+   /*
+    * Get authentication settings...
+    */
+
+    if (cgiGetVariable("KERBEROS"))
+      strlcpy(default_auth_type, "Negotiate", sizeof(default_auth_type));
+    else
     {
-      if (!strcmp(group->name, "InstallableOptions"))
-       cgiSetVariable("GROUP", cgiText(_("Options Installed")));
+      val = cupsGetOption("DefaultAuthType", num_settings, settings);
+
+      if (!val || !strcasecmp(val, "Negotiate"))
+        strlcpy(default_auth_type, "Basic", sizeof(default_auth_type));
       else
-       cgiSetVariable("GROUP", group->text);
+        strlcpy(default_auth_type, val, sizeof(default_auth_type));
+    }
 
-      cgiCopyTemplateLang("option-header.tmpl");
-      
-      for (j = group->num_options, option = group->options;
-           j > 0;
-          j --, option ++)
-      {
-        if (!strcmp(option->keyword, "PageRegion"))
-         continue;
+    fprintf(stderr, "DEBUG: DefaultAuthType %s\n", default_auth_type);
+#endif /* HAVE_GSSAPI */
 
-        cgiSetVariable("KEYWORD", option->keyword);
-        cgiSetVariable("KEYTEXT", option->text);
-           
-       if (option->conflicted)
-         cgiSetVariable("CONFLICTED", "1");
-       else
-         cgiSetVariable("CONFLICTED", "0");
+   /*
+    * See if the settings have changed...
+    */
 
-       cgiSetSize("CHOICES", 0);
-       cgiSetSize("TEXT", 0);
-       for (k = 0, m = 0; k < option->num_choices; k ++)
-       {
-        /*
-         * Hide custom option values...
-         */
+    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)) ||
+#endif /* HAVE_GSSAPI */
+             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...
+      */
 
-         if (!strcmp(option->choices[k].choice, "Custom"))
-           continue;
+      cupsFreeOptions(num_settings, settings);
 
-         cgiSetArray("CHOICES", m, option->choices[k].choice);
-         cgiSetArray("TEXT", m, option->choices[k].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 */
 
-          m ++;
+      if (advanced)
+      {
+       /*
+        * Add advanced settings...
+       */
 
-          if (option->choices[k].marked)
-           cgiSetVariable("DEFCHOICE", option->choices[k].choice);
-       }
+       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);
+      }
 
-        switch (option->ui)
+      if (!cupsAdminSetServerSettings(http, num_settings, settings))
+      {
+        if (cupsLastError() == IPP_NOT_AUTHORIZED)
        {
-         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;
+         puts("Status: 401\n");
+         exit(0);
        }
+
+       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
+    {
+     /*
+      * No changes...
+      */
 
-      cgiCopyTemplateLang("option-trailer.tmpl");
+      cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect");
+      cgiStartHTML(cgiText(_("Change Settings")));
+      cgiCopyTemplateLang("norestart.tmpl");
     }
 
+    cupsFreeOptions(num_settings, settings);
+
+    cgiEndHTML();
+  }
+  else if (cgiGetVariable("SAVECHANGES") && cgiGetVariable("CUPSDCONF"))
+  {
    /*
-    * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
-    * following attributes:
-    *
-    *    attributes-charset
-    *    attributes-natural-language
-    *    printer-uri
+    * Save hand-edited config file...
     */
 
-    request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+    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 */
 
-    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);
 
    /*
-    * Do the request and get back a response...
+    * Create a temporary file for the new cupsd.conf file...
     */
 
-    if ((response = cupsDoRequest(http, request, "/")) != NULL)
+    if ((tempfd = cupsTempFd(tempfile, sizeof(tempfile))) < 0)
     {
-      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 create temporary file:")));
+      cgiSetVariable("ERROR", strerror(errno));
+      cgiCopyTemplateLang("error.tmpl");
+      cgiEndHTML();
+      
+      perror(tempfile);
+      return;
+    }
 
-       cgiSetVariable("GROUP", cgiText(_("Banners")));
-       cgiCopyTemplateLang("option-header.tmpl");
+    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;
+    }
 
-       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);
-       }
+   /*
+    * Copy the cupsd.conf text from the form variable...
+    */
 
-        attr = ippFindAttribute(response, "job-sheets-default", IPP_TAG_ZERO);
+    start = cgiGetVariable("CUPSDCONF");
+    while (start)
+    {
+      if ((end = strstr(start, "\r\n")) == NULL)
+        if ((end = strstr(start, "\n")) == NULL)
+         end = start + strlen(start);
 
-        cgiSetVariable("KEYWORD", "job_sheets_start");
-       cgiSetVariable("KEYTEXT", cgiText(_("Starting Banner")));
-        cgiSetVariable("DEFCHOICE", attr == NULL ?
-                                   "" : attr->values[0].string.text);
+      cupsFileWrite(temp, start, end - start);
+      cupsFilePutChar(temp, '\n');
 
-       cgiCopyTemplateLang("option-pickone.tmpl");
+      if (*end == '\r')
+        start = end + 2;
+      else if (*end == '\n')
+        start = end + 1;
+      else
+        start = NULL;
+    }
 
-        cgiSetVariable("KEYWORD", "job_sheets_end");
-       cgiSetVariable("KEYTEXT", cgiText(_("Ending Banner")));
-        cgiSetVariable("DEFCHOICE", attr == NULL && attr->num_values > 1 ?
-                                   "" : attr->values[1].string.text);
+    cupsFileClose(temp);
 
-       cgiCopyTemplateLang("option-pickone.tmpl");
+   /*
+    * Upload the configuration file to the server...
+    */
 
-       cgiCopyTemplateLang("option-trailer.tmpl");
-      }
+    status = cupsPutFile(http, "/admin/conf/cupsd.conf", tempfile);
 
-      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");
-
-       /*
-        * Error policy...
-       */
-
-        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);
-
-          cgiSetVariable("KEYWORD", "printer_error_policy");
-         cgiSetVariable("KEYTEXT", cgiText(_("Error Policy")));
-          cgiSetVariable("DEFCHOICE", attr == NULL ?
-                                     "" : attr->values[0].string.text);
-        }
-
-       cgiCopyTemplateLang("option-pickone.tmpl");
-
-       /*
-        * Operation policy...
-       */
-
-        attr = ippFindAttribute(response, "printer-op-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-op-policy", IPP_TAG_ZERO);
-
-          cgiSetVariable("KEYWORD", "printer_op_policy");
-         cgiSetVariable("KEYTEXT", cgiText(_("Operation Policy")));
-          cgiSetVariable("DEFCHOICE", attr == NULL ?
-                                     "" : attr->values[0].string.text);
-
-         cgiCopyTemplateLang("option-pickone.tmpl");
-        }
-
-       cgiCopyTemplateLang("option-trailer.tmpl");
-      }
-
-      ippDelete(response);
+    if (status == HTTP_UNAUTHORIZED)
+    {
+      puts("Status: 401\n");
+      unlink(tempfile);
+      exit(0);
     }
-
-   /*
-    * Binary protocol support...
-    */
-
-    if (ppd->protocols && strstr(ppd->protocols, "BCP"))
+    else if (status != HTTP_CREATED)
     {
-      protocol = ppdFindAttr(ppd, "cupsProtocol", NULL);
-
-      cgiSetVariable("GROUP", cgiText(_("PS Binary Protocol")));
-      cgiCopyTemplateLang("option-header.tmpl");
-
-      cgiSetSize("CHOICES", 2);
-      cgiSetSize("TEXT", 2);
-      cgiSetArray("CHOICES", 0, "None");
-      cgiSetArray("TEXT", 0, cgiText(_("None")));
-
-      if (strstr(ppd->protocols, "TBCP"))
-      {
-       cgiSetArray("CHOICES", 1, "TBCP");
-       cgiSetArray("TEXT", 1, "TBCP");
-      }
-      else
-      {
-       cgiSetArray("CHOICES", 1, "BCP");
-       cgiSetArray("TEXT", 1, "BCP");
-      }
-
-      cgiSetVariable("KEYWORD", "protocol");
-      cgiSetVariable("KEYTEXT", cgiText(_("PS Binary Protocol")));
-      cgiSetVariable("DEFCHOICE", protocol ? protocol->value : "None");
+      cgiSetVariable("MESSAGE",
+                     cgiText(_("Unable to upload cupsd.conf file:")));
+      cgiSetVariable("ERROR", httpStatus(status));
 
-      cgiCopyTemplateLang("option-pickone.tmpl");
+      cgiStartHTML(cgiText(_("Edit Configuration File")));
+      cgiCopyTemplateLang("error.tmpl");
+    }
+    else
+    {
+      cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect");
 
-      cgiCopyTemplateLang("option-trailer.tmpl");
+      cgiStartHTML(cgiText(_("Edit Configuration File")));
+      cgiCopyTemplateLang("restart.tmpl");
     }
 
-    cgiCopyTemplateLang("set-printer-options-trailer.tmpl");
     cgiEndHTML();
+
+    unlink(tempfile);
   }
   else
   {
+    struct stat        info;                   /* cupsd.conf information */
+    cups_file_t        *cupsd;                 /* cupsd.conf file */
+    char       *buffer,                /* Buffer for entire file */
+               *bufptr,                /* Pointer into buffer */
+               *bufend;                /* End of buffer */
+    int                ch;                     /* Character from file */
+    char       filename[1024];         /* Filename */
+    const char *server_root;           /* Location of config files */
+
+
    /*
-    * Set default options...
+    * Locate the cupsd.conf file...
     */
 
-    fputs("DEBUG: Setting options...\n", stderr);
+    if ((server_root = getenv("CUPS_SERVERROOT")) == NULL)
+      server_root = CUPS_SERVERROOT;
+
+    snprintf(filename, sizeof(filename), "%s/cupsd.conf", server_root);
 
-    out = cupsTempFile2(tempfile, sizeof(tempfile));
-    in  = cupsFileOpen(filename, "r");
+   /*
+    * Figure out the size...
+    */
 
-    if (!in || !out)
+    if (stat(filename, &info))
     {
+      cgiStartHTML(cgiText(_("Edit Configuration File")));
+      cgiSetVariable("MESSAGE",
+                     cgiText(_("Unable to access cupsd.conf file:")));
       cgiSetVariable("ERROR", strerror(errno));
-      cgiStartHTML(cgiText(_("Set Printer Options")));
       cgiCopyTemplateLang("error.tmpl");
       cgiEndHTML();
 
-      if (in)
-        cupsFileClose(in);
-
-      if (out)
-      {
-        cupsFileClose(out);
-       unlink(tempfile);
-      }
-
-      unlink(filename);
+      perror(filename);
       return;
     }
 
-    while (cupsFileGets(in, line, sizeof(line)))
+    if (info.st_size > (1024 * 1024))
     {
-      if (!strncmp(line, "*cupsProtocol:", 14) && cgiGetVariable("protocol"))
-        continue;
-      else if (strncmp(line, "*Default", 8))
-        cupsFilePrintf(out, "%s\n", line);
-      else
-      {
-       /*
-        * Get default option name...
-       */
+      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();
 
-        strlcpy(keyword, line + 8, sizeof(keyword));
+      fprintf(stderr, "ERROR: \"%s\" too large (%ld) to edit!\n", filename,
+              (long)info.st_size);
+      return;
+    }
 
-       for (keyptr = keyword; *keyptr; keyptr ++)
-         if (*keyptr == ':' || isspace(*keyptr & 255))
-           break;
+   /*
+    * Open the cupsd.conf file...
+    */
 
-        *keyptr = '\0';
+    if ((cupsd = cupsFileOpen(filename, "r")) == NULL)
+    {
+     /*
+      * Unable to open - log an error...
+      */
 
-        if (!strcmp(keyword, "PageRegion") ||
-           !strcmp(keyword, "PaperDimension") ||
-           !strcmp(keyword, "ImageableArea"))
-         var = cgiGetVariable("PageSize");
-       else
-         var = cgiGetVariable(keyword);
+      cgiStartHTML(cgiText(_("Edit Configuration File")));
+      cgiSetVariable("MESSAGE",
+                     cgiText(_("Unable to access cupsd.conf file:")));
+      cgiSetVariable("ERROR", strerror(errno));
+      cgiCopyTemplateLang("error.tmpl");
+      cgiEndHTML();
 
-        if (var != NULL)
-         cupsFilePrintf(out, "*Default%s: %s\n", keyword, var);
-       else
-         cupsFilePrintf(out, "%s\n", line);
-      }
+      perror(filename);
+      return;
     }
 
-    if ((var = cgiGetVariable("protocol")) != NULL)
-      cupsFilePrintf(out, "*cupsProtocol: %s\n", cgiGetVariable("protocol"));
-
-    cupsFileClose(in);
-    cupsFileClose(out);
-
    /*
-    * Build a CUPS_ADD_PRINTER request, which requires the following
-    * attributes:
-    *
-    *    attributes-charset
-    *    attributes-natural-language
-    *    printer-uri
-    *    job-sheets-default
-    *    [ppd file]
+    * Allocate memory and load the file into a string buffer...
     */
 
-    request = ippNewRequest(CUPS_ADD_PRINTER);
-
-    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);
-
-    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 ((var = cgiGetVariable("printer_error_policy")) != NULL)
-      attr = ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
-                          "printer-error-policy", NULL, var);
+    if ((buffer = calloc(1, info.st_size + 1)) != NULL)
+    {
+      cupsFileRead(cupsd, buffer, info.st_size);
+      cgiSetVariable("CUPSDCONF", buffer);
+      free(buffer);
+    }
 
-    if ((var = cgiGetVariable("printer_op_policy")) != NULL)
-      attr = ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
-                          "printer-op-policy", NULL, var);
+    cupsFileClose(cupsd);
 
    /*
-    * Do the request and get back a response...
+    * Then get the default cupsd.conf file and put that into a string as
+    * well...
     */
 
-    ippDelete(cupsDoFileRequest(http, request, "/admin/", tempfile));
+    strlcat(filename, ".default", sizeof(filename));
 
-    if (cupsLastError() > IPP_OK_CONFLICT)
-    {
-      cgiStartHTML(title);
-      cgiShowIPPError(_("Unable to set options:"));
-    }
-    else
+    if (!stat(filename, &info) && info.st_size < (1024 * 1024) &&
+        (cupsd = cupsFileOpen(filename, "r")) != NULL)
     {
-     /*
-      * Redirect successful updates back to the printer page...
-      */
-
-      char     refresh[1024];          /* Refresh URL */
+      if ((buffer = calloc(1, 2 * info.st_size + 1)) != NULL)
+      {
+       bufend = buffer + 2 * info.st_size - 1;
 
+       for (bufptr = buffer;
+            bufptr < bufend && (ch = cupsFileGetChar(cupsd)) != EOF;)
+       {
+         if (ch == '\\' || ch == '\"')
+         {
+           *bufptr++ = '\\';
+           *bufptr++ = ch;
+         }
+         else if (ch == '\n')
+         {
+           *bufptr++ = '\\';
+           *bufptr++ = 'n';
+         }
+         else if (ch == '\t')
+         {
+           *bufptr++ = '\\';
+           *bufptr++ = 't';
+         }
+         else if (ch >= ' ')
+           *bufptr++ = ch;
+       }
 
-      cgiFormEncode(uri, printer, sizeof(uri));
-      snprintf(refresh, sizeof(refresh),
-               "5;URL=/admin/?OP=redirect&URL=/printers/%s", uri);
-      cgiSetVariable("refresh_page", refresh);
+       *bufptr = '\0';
 
-      cgiStartHTML(title);
+       cgiSetVariable("CUPSDCONF_DEFAULT", buffer);
+       free(buffer);
+      }
 
-      cgiCopyTemplateLang("printer-configured.tmpl");
+      cupsFileClose(cupsd);
     }
 
-    cgiEndHTML();
+   /*
+    * Show the current config file...
+    */
 
-    unlink(tempfile);
-  }
+    cgiStartHTML(cgiText(_("Edit Configuration File")));
+
+    cgiCopyTemplateLang("edit-config.tmpl");
 
-  unlink(filename);
+    cgiEndHTML();
+  }
 }
 
 
 /*
- * 'do_config_server()' - Configure server settings.
+ * 'do_delete_class()' - Delete a class.
  */
 
 static void
-do_config_server(http_t *http)         /* I - HTTP connection */
+do_delete_class(http_t *http)          /* I - HTTP connection */
 {
-  if (cgiIsPOST() && !cgiGetVariable("CUPSDCONF"))
+  ipp_t                *request;               /* IPP request */
+  char         uri[HTTP_MAX_URI];      /* Job URI */
+  const char   *pclass;                /* Printer class name */
+
+
+ /*
+  * Get form variables...
+  */
+
+  if (cgiGetVariable("CONFIRM") == NULL)
   {
-   /*
-    * Save basic setting changes...
-    */
+    cgiStartHTML(cgiText(_("Delete Class")));
+    cgiCopyTemplateLang("class-confirm.tmpl");
+    cgiEndHTML();
+    return;
+  }
 
-    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 */
+  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;
+  }
 
+ /*
+  * Build a CUPS_DELETE_CLASS request, which requires the following
+  * attributes:
+  *
+  *    attributes-charset
+  *    attributes-natural-language
+  *    printer-uri
+  */
 
-   /*
-    * Get the checkbox values from the form...
-    */
+  request = ippNewRequest(CUPS_DELETE_CLASS);
 
-    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";
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+               NULL, uri);
 
-    fprintf(stderr, "DEBUG: DefaultAuthType %s\n", default_auth_type);
-#endif /* HAVE_GSSAPI */
+ /*
+  * Do the request and get back a response...
+  */
 
-   /*
-    * Get the current server settings...
-    */
+  ippDelete(cupsDoRequest(http, request, "/admin/"));
 
-    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;
-    }
+ /*
+  * Show the results...
+  */
 
+  if (cupsLastError() == IPP_NOT_AUTHORIZED)
+  {
+    puts("Status: 401\n");
+    exit(0);
+  }
+  else if (cupsLastError() <= IPP_OK_CONFLICT)
+  {
    /*
-    * See if the settings have changed...
+    * Redirect successful updates back to the classes page...
     */
 
-    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...
-      */
+    cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect&URL=/classes");
+  }
 
-      cupsFreeOptions(num_settings, settings);
+  cgiStartHTML(cgiText(_("Delete Class")));
 
-      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 */
+  if (cupsLastError() > IPP_OK_CONFLICT)
+    cgiShowIPPError(_("Unable to delete class:"));
+  else
+    cgiCopyTemplateLang("class-deleted.tmpl");
 
-      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
-    {
-     /*
-      * No changes...
-      */
+  cgiEndHTML();
+}
 
-      cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect");
-      cgiStartHTML(cgiText(_("Change Settings")));
-      cgiCopyTemplateLang("norestart.tmpl");
-    }
 
-    cupsFreeOptions(num_settings, settings);
+/*
+ * 'do_delete_printer()' - Delete a printer.
+ */
+
+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 */
+
 
+ /*
+  * Get form variables...
+  */
+
+  if (cgiGetVariable("CONFIRM") == NULL)
+  {
+    cgiStartHTML(cgiText(_("Delete Printer")));
+    cgiCopyTemplateLang("printer-confirm.tmpl");
     cgiEndHTML();
+    return;
   }
-  else if (cgiIsPOST())
+
+  if ((printer = cgiGetVariable("PRINTER_NAME")) != NULL)
+    httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
+                     "localhost", 0, "/printers/%s", printer);
+  else
   {
-   /*
-    * Save hand-edited config file...
-    */
+    cgiStartHTML(cgiText(_("Delete Printer")));
+    cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
+    cgiCopyTemplateLang("error.tmpl");
+    cgiEndHTML();
+    return;
+  }
 
-    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 */
+ /*
+  * Build a CUPS_DELETE_PRINTER request, which requires the following
+  * attributes:
+  *
+  *    attributes-charset
+  *    attributes-natural-language
+  *    printer-uri
+  */
 
+  request = ippNewRequest(CUPS_DELETE_PRINTER);
 
-   /*
-    * Create a temporary file for the new cupsd.conf file...
-    */
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+               NULL, uri);
 
-    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;
-    }
+ /*
+  * Do the request and get back a response...
+  */
 
-    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;
-    }
+  ippDelete(cupsDoRequest(http, request, "/admin/"));
+
+ /*
+  * Show the results...
+  */
 
+  if (cupsLastError() == IPP_NOT_AUTHORIZED)
+  {
+    puts("Status: 401\n");
+    exit(0);
+  }
+  else if (cupsLastError() <= IPP_OK_CONFLICT)
+  {
    /*
-    * Copy the cupsd.conf text from the form variable...
+    * Redirect successful updates back to the printers page...
     */
 
-    start = cgiGetVariable("CUPSDCONF");
-    while (start)
+    cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect&URL=/printers");
+  }
+
+  cgiStartHTML(cgiText(_("Delete Printer")));
+
+  if (cupsLastError() > IPP_OK_CONFLICT)
+    cgiShowIPPError(_("Unable to delete printer:"));
+  else
+    cgiCopyTemplateLang("printer-deleted.tmpl");
+
+  cgiEndHTML();
+}
+
+
+/*
+ * 'do_export()' - Export printers to Samba.
+ */
+
+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 */
+
+
+ /*
+  * Get form data...
+  */
+
+  username     = cgiGetVariable("USERNAME");
+  password     = cgiGetVariable("PASSWORD");
+  export_all   = cgiGetVariable("EXPORT_ALL");
+  export_count = cgiGetSize("EXPORT_NAME");
+
+ /*
+  * Get list of available printers...
+  */
+
+  cgiSetSize("PRINTER_NAME", 0);
+  cgiSetSize("PRINTER_EXPORT", 0);
+
+  request = ippNewRequest(CUPS_GET_PRINTERS);
+
+  ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM,
+                "printer-type", 0);
+
+  ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM,
+                "printer-type-mask", CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE |
+                                    CUPS_PRINTER_IMPLICIT);
+
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+               "requested-attributes", NULL, "printer-name");
+
+  if ((response = cupsDoRequest(http, request, "/")) != NULL)
+  {
+    cgiSetIPPVars(response, NULL, NULL, NULL, 0);
+    ippDelete(response);
+
+    if (!export_all)
     {
-      if ((end = strstr(start, "\r\n")) == NULL)
-        if ((end = strstr(start, "\n")) == NULL)
-         end = start + strlen(start);
+      printer_count = cgiGetSize("PRINTER_NAME");
 
-      cupsFileWrite(temp, start, end - start);
-      cupsFilePutChar(temp, '\n');
+      for (i = 0; i < printer_count; i ++)
+      {
+        dest = cgiGetArray("PRINTER_NAME", i);
 
-      if (*end == '\r')
-        start = end + 2;
-      else if (*end == '\n')
-        start = end + 1;
-      else
-        start = NULL;
+        for (j = 0; j < export_count; j ++)
+         if (!strcasecmp(dest, cgiGetArray("EXPORT_NAME", j)))
+            break;
+
+        cgiSetArray("PRINTER_EXPORT", i, j < export_count ? "Y" : "");
+      }
     }
+  }
 
-    cupsFileClose(temp);
+ /*
+  * Export or get the printers to export...
+  */
 
+  if (username && *username && password && *password &&
+      (export_all || export_count > 0))
+  {
    /*
-    * Upload the configuration file to the server...
+    * Do export...
     */
 
-    status = cupsPutFile(http, "/admin/conf/cupsd.conf", tempfile);
+    fputs("DEBUG: Export printers...\n", stderr);
 
-    if (status != HTTP_CREATED)
+    if (export_all)
     {
-      cgiSetVariable("MESSAGE",
-                     cgiText(_("Unable to upload cupsd.conf file:")));
-      cgiSetVariable("ERROR", httpStatus(status));
-
-      cgiStartHTML(cgiText(_("Edit Configuration File")));
-      cgiCopyTemplateLang("error.tmpl");
+      name         = "PRINTER_NAME";
+      export_count = cgiGetSize("PRINTER_NAME");
     }
     else
+      name = "EXPORT_NAME";
+
+    for (i = 0; i < export_count; i ++)
     {
-      cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect");
+      dest = cgiGetArray(name, i);
 
-      cgiStartHTML(cgiText(_("Edit Configuration File")));
-      cgiCopyTemplateLang("restart.tmpl");
-    }
+      if (!cupsAdminCreateWindowsPPD(http, dest, ppd, sizeof(ppd)))
+        break;
 
-    cgiEndHTML();
+      j = cupsAdminExportSamba(dest, ppd, "localhost", username, password,
+                               stderr);
 
-    unlink(tempfile);
+      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
-  {
-    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 */
+  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...
+  */
 
-   /*
-    * Locate the cupsd.conf file...
-    */
+  cgiStartHTML(cgiText(_("Export Printers to Samba")));
+  cgiCopyTemplateLang("samba-export.tmpl");
+  cgiEndHTML();
+}
 
-    if ((server_root = getenv("CUPS_SERVERROOT")) == NULL)
-      server_root = CUPS_SERVERROOT;
 
-    snprintf(filename, sizeof(filename), "%s/cupsd.conf", server_root);
+/*
+ * 'do_list_printers()' - List available printers.
+ */
+
+static void
+do_list_printers(http_t *http)         /* I - HTTP connection */
+{
+  ipp_t                *request,               /* IPP request */
+               *response;              /* IPP response */
+  ipp_attribute_t *attr;               /* IPP attribute */
+
+
+  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)
+  {
    /*
-    * Figure out the size...
+    * Got the printer list, now load the devices...
     */
 
-    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();
+    int                i;                      /* Looping var */
+    cups_array_t *printer_devices;     /* Printer devices for local printers */
+    char       *printer_device;        /* Current printer device */
 
-      perror(filename);
-      return;
-    }
 
-    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();
+   /*
+    * Allocate an array and copy the device strings...
+    */
 
-      fprintf(stderr, "ERROR: \"%s\" too large (%ld) to edit!\n", filename,
-              (long)info.st_size);
-      return;
+    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))
+    {
+      cupsArrayAdd(printer_devices, strdup(attr->values[0].string.text));
     }
 
    /*
-    * Open the cupsd.conf file...
+    * Free the printer list and get the device list...
     */
 
-    if ((cupsd = cupsFileOpen(filename, "r")) == NULL)
+    ippDelete(response);
+
+    request = ippNewRequest(CUPS_GET_DEVICES);
+
+    if ((response = cupsDoRequest(http, request, "/")) != NULL)
     {
      /*
-      * Unable to open - log an error...
+      * Got the device list, let's parse it...
       */
 
-      cgiStartHTML(cgiText(_("Edit Configuration File")));
-      cgiSetVariable("MESSAGE",
-                     cgiText(_("Unable to access cupsd.conf file:")));
-      cgiSetVariable("ERROR", strerror(errno));
-      cgiCopyTemplateLang("error.tmpl");
-      cgiEndHTML();
+      const char *device_uri,          /* device-uri attribute value */
+               *device_make_and_model, /* device-make-and-model value */
+               *device_info;           /* device-info value */
 
-      perror(filename);
-      return;
-    }
 
-   /*
-    * Allocate memory and load the file into a string buffer...
-    */
+      for (i = 0, attr = response->attrs; attr; attr = attr->next)
+      {
+       /*
+        * Skip leading attributes until we hit a device...
+       */
 
-    buffer = calloc(1, info.st_size + 1);
+       while (attr && attr->group_tag != IPP_TAG_PRINTER)
+          attr = attr->next;
 
-    cupsFileRead(cupsd, buffer, info.st_size);
-    cupsFileClose(cupsd);
+       if (!attr)
+          break;
 
-    cgiSetVariable("CUPSDCONF", buffer);
-    free(buffer);
+       /*
+       * Pull the needed attributes from this device...
+       */
 
-   /*
-    * Show the current config file...
-    */
+       device_info           = NULL;
+       device_make_and_model = NULL;
+       device_uri            = NULL;
 
-    cgiStartHTML(cgiText(_("Edit Configuration File")));
+       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;
 
-    printf("<!-- \"%s\" -->\n", filename);
+          if (!strcmp(attr->name, "device-make-and-model") &&
+             attr->value_tag == IPP_TAG_TEXT)
+           device_make_and_model = attr->values[0].string.text;
 
-    cgiCopyTemplateLang("edit-config.tmpl");
+          if (!strcmp(attr->name, "device-uri") &&
+             attr->value_tag == IPP_TAG_URI)
+           device_uri = attr->values[0].string.text;
 
-    cgiEndHTML();
-  }
-}
+          attr = attr->next;
+       }
 
+       /*
+       * See if we have everything needed...
+       */
 
-/*
- * 'do_delete_class()' - Delete a class...
- */
+       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...
+         */
 
-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 */
+          if (!cupsArrayFind(printer_devices, (void *)device_uri))
+          {
+          /*
+           * Not found, so it must be a new printer...
+           */
 
+            char       option[1024],   /* Form variables for this device */
+                       *option_ptr;    /* Pointer into string */
+           const char  *ptr;           /* Pointer into device string */
 
- /*
-  * Get form variables...
-  */
 
-  if (cgiGetVariable("CONFIRM") == NULL)
-  {
-    cgiStartHTML(cgiText(_("Delete Class")));
-    cgiCopyTemplateLang("class-confirm.tmpl");
-    cgiEndHTML();
-    return;
-  }
+           /*
+           * 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.
+           */
 
-  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 (strncasecmp(device_info, "unknown", 7))
+             ptr = device_info;
+            else if ((ptr = strstr(device_uri, "://")) != NULL)
+             ptr += 3;
+           else
+             ptr = device_make_and_model;
 
- /*
-  * Build a CUPS_DELETE_CLASS request, which requires the following
-  * attributes:
-  *
-  *    attributes-charset
-  *    attributes-natural-language
-  *    printer-uri
-  */
+           for (option_ptr = option;
+                option_ptr < (option + sizeof(option) - 1) && *ptr;
+                ptr ++)
+             if (isalnum(*ptr & 255) || *ptr == '_' || *ptr == '-' ||
+                 *ptr == '.')
+               *option_ptr++ = *ptr;
+             else if ((*ptr == ' ' || *ptr == '/') && option_ptr[-1] != '_')
+               *option_ptr++ = '_';
+             else if (*ptr == '?' || *ptr == '(')
+               break;
 
-  request = ippNewRequest(CUPS_DELETE_CLASS);
+            *option_ptr = '\0';
 
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
-               NULL, uri);
+            cgiSetArray("TEMPLATE_NAME", i, option);
 
- /*
-  * Do the request and get back a response...
-  */
          /*
+           * Finally, set the form variables for this printer...
+           */
 
-  ippDelete(cupsDoRequest(http, request, "/admin/"));
+           cgiSetArray("device_info", i, device_info);
+           cgiSetArray("device_make_and_model", i, device_make_and_model);
+            cgiSetArray("device_uri", i, device_uri);
+           i ++;
+         }
+       }
 
- /*
-  * Show the results...
-  */
+        if (!attr)
+         break;
+      }
 
-  if (cupsLastError() <= IPP_OK_CONFLICT)
-  {
-   /*
-    * Redirect successful updates back to the classes page...
-    */
+      ippDelete(response);
 
-    cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect&URL=/classes");
+     /*
+      * 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);
+    }
   }
 
-  cgiStartHTML(cgiText(_("Delete Class")));
+ /*
+  * Finally, show the printer list...
+  */
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
-    cgiShowIPPError(_("Unable to delete class:"));
-  else
-    cgiCopyTemplateLang("class-deleted.tmpl");
+  cgiCopyTemplateLang("list-available-printers.tmpl");
 
   cgiEndHTML();
 }
 
 
 /*
- * 'do_delete_printer()' - Delete a printer...
+ * 'do_menu()' - Show the main menu.
  */
 
 static void
-do_delete_printer(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   *printer;               /* Printer printer 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 Printer")));
-    cgiCopyTemplateLang("printer-confirm.tmpl");
-    cgiEndHTML();
-    return;
+    cgiSetVariable("SETTINGS_MESSAGE",
+                   cgiText(_("Unable to open cupsd.conf file:")));
+    cgiSetVariable("SETTINGS_ERROR", cupsLastErrorString());
   }
 
-  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;
-  }
+  if ((val = cupsGetOption(CUPS_SERVER_DEBUG_LOGGING, num_settings,
+                           settings)) != NULL && atoi(val))
+    cgiSetVariable("DEBUG_LOGGING", "CHECKED");
+
+  if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ADMIN, num_settings,
+                           settings)) != NULL && atoi(val))
+    cgiSetVariable("REMOTE_ADMIN", "CHECKED");
+
+  if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ANY, num_settings,
+                           settings)) != NULL && atoi(val))
+    cgiSetVariable("REMOTE_ANY", "CHECKED");
+
+  if ((val = cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS, num_settings,
+                           settings)) != NULL && atoi(val))
+    cgiSetVariable("REMOTE_PRINTERS", "CHECKED");
 
- /*
-  * Build a CUPS_DELETE_PRINTER request, which requires the following
-  * attributes:
-  *
-  *    attributes-charset
-  *    attributes-natural-language
-  *    printer-uri
-  */
+  if ((val = cupsGetOption(CUPS_SERVER_SHARE_PRINTERS, num_settings,
+                           settings)) != NULL && atoi(val))
+    cgiSetVariable("SHARE_PRINTERS", "CHECKED");
 
-  request = ippNewRequest(CUPS_DELETE_PRINTER);
+  if ((val = cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY, num_settings,
+                           settings)) != NULL && atoi(val))
+    cgiSetVariable("USER_CANCEL_ANY", "CHECKED");
 
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
-               NULL, uri);
+#ifdef HAVE_GSSAPI
+  cgiSetVariable("HAVE_GSSAPI", "1");
 
- /*
-  * Do the request and get back a response...
-  */
+  if ((val = cupsGetOption("DefaultAuthType", num_settings,
+                           settings)) != NULL && !strcasecmp(val, "Negotiate"))
+    cgiSetVariable("KERBEROS", "CHECKED");
+#endif /* HAVE_GSSAPI */
 
-  ippDelete(cupsDoRequest(http, request, "/admin/"));
+#ifdef HAVE_DNSSD
+  cgiSetVariable("HAVE_DNSSD", "1");
+#endif /* HAVE_DNSSD */
 
- /*
-  * Show the results...
-  */
+#ifdef HAVE_LDAP
+  cgiSetVariable("HAVE_LDAP", "1");
+#endif /* HAVE_LDAP */
 
-  if (cupsLastError() <= IPP_OK_CONFLICT)
-  {
-   /*
-    * Redirect successful updates back to the printers page...
-    */
+#ifdef HAVE_LIBSLP
+  cgiSetVariable("HAVE_LIBSLP", "1");
+#endif /* HAVE_LIBSLP */
 
-    cgiSetVariable("refresh_page", "5;URL=/admin/?OP=redirect&URL=/printers");
-  }
+  if ((val = cupsGetOption("BrowseRemoteProtocols", num_settings,
+                           settings)) == NULL)
+    if ((val = cupsGetOption("BrowseProtocols", num_settings,
+                           settings)) == NULL)
+      val = CUPS_DEFAULT_BROWSE_REMOTE_PROTOCOLS;
 
-  cgiStartHTML(cgiText(_("Delete Printer")));
+  if (strstr(val, "cups") || strstr(val, "CUPS"))
+    cgiSetVariable("BROWSE_REMOTE_CUPS", "CHECKED");
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
-    cgiShowIPPError(_("Unable to delete printer:"));
-  else
-    cgiCopyTemplateLang("printer-deleted.tmpl");
+  if (strstr(val, "ldap") || strstr(val, "LDAP"))
+    cgiSetVariable("BROWSE_REMOTE_LDAP", "CHECKED");
 
-  cgiEndHTML();
-}
+  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;
 
-/*
- * 'do_export()' - Export printers to Samba...
- */
+  if (strstr(val, "cups") || strstr(val, "CUPS"))
+    cgiSetVariable("BROWSE_LOCAL_CUPS", "CHECKED");
 
-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 */
+  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");
 
- /*
-  * Get form data...
-  */
+  if (strstr(val, "slp") || strstr(val, "SLP"))
+    cgiSetVariable("BROWSE_LOCAL_SLP", "CHECKED");
 
-  username     = cgiGetVariable("USERNAME");
-  password     = cgiGetVariable("PASSWORD");
-  export_all   = cgiGetVariable("EXPORT_ALL");
-  export_count = cgiGetSize("EXPORT_NAME");
+  if ((val = cupsGetOption("BrowseWebIF", num_settings,
+                           settings)) == NULL)
+    val = "No";
 
- /*
-  * Get list of available printers...
-  */
+  if (!strcasecmp(val, "yes") || !strcasecmp(val, "on") ||
+      !strcasecmp(val, "true"))
+    cgiSetVariable("BROWSE_WEB_IF", "CHECKED");
 
-  cgiSetSize("PRINTER_NAME", 0);
-  cgiSetSize("PRINTER_EXPORT", 0);
+  if ((val = cupsGetOption("PreserveJobHistory", num_settings,
+                           settings)) == NULL)
+    val = "Yes";
 
-  request = ippNewRequest(CUPS_GET_PRINTERS);
+  if (!strcasecmp(val, "yes") || !strcasecmp(val, "on") ||
+      !strcasecmp(val, "true"))
+  {
+    cgiSetVariable("PRESERVE_JOB_HISTORY", "CHECKED");
 
-  ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM,
-                "printer-type", 0);
+    if ((val = cupsGetOption("PreserveJobFiles", num_settings,
+                            settings)) == NULL)
+      val = "No";
 
-  ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_ENUM,
-                "printer-type-mask", CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE |
-                                    CUPS_PRINTER_IMPLICIT);
+    if (!strcasecmp(val, "yes") || !strcasecmp(val, "on") ||
+       !strcasecmp(val, "true"))
+      cgiSetVariable("PRESERVE_JOB_FILES", "CHECKED");
+  }
 
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
-               "requested-attributes", NULL, "printer-name");
+  if ((val = cupsGetOption("MaxClients", num_settings, settings)) == NULL)
+    val = "100";
 
-  if ((response = cupsDoRequest(http, request, "/")) != NULL)
-  {
-    cgiSetIPPVars(response, NULL, NULL, NULL, 0);
-    ippDelete(response);
+  cgiSetVariable("MAX_CLIENTS", val);
 
-    if (!export_all)
-    {
-      printer_count = cgiGetSize("PRINTER_NAME");
+  if ((val = cupsGetOption("MaxJobs", num_settings, settings)) == NULL)
+    val = "500";
 
-      for (i = 0; i < printer_count; i ++)
-      {
-        dest = cgiGetArray("PRINTER_NAME", i);
+  cgiSetVariable("MAX_JOBS", val);
 
-        for (j = 0; j < export_count; j ++)
-         if (!strcasecmp(dest, cgiGetArray("EXPORT_NAME", j)))
-            break;
+  if ((val = cupsGetOption("MaxLogSize", num_settings, settings)) == NULL)
+    val = "1m";
 
-        cgiSetArray("PRINTER_EXPORT", i, j < export_count ? "Y" : "");
-      }
-    }
-  }
+  cgiSetVariable("MAX_LOG_SIZE", val);
+
+  cupsFreeOptions(num_settings, settings);
 
  /*
-  * Export or get the printers to export...
+  * See if Samba and the Windows drivers are installed...
   */
 
-  if (username && *username && password && *password &&
-      (export_all || export_count > 0))
+  if ((datadir = getenv("CUPS_DATADIR")) == NULL)
+    datadir = CUPS_DATADIR;
+
+  snprintf(filename, sizeof(filename), "%s/drivers/pscript5.dll", datadir);
+  if (!access(filename, R_OK))
   {
    /*
-    * Do export...
+    * Found Windows 2000 driver file, see if we have smbclient and
+    * rpcclient...
     */
 
-    fputs("DEBUG: Export printers...\n", stderr);
-
-    if (export_all)
-    {
-      name         = "PRINTER_NAME";
-      export_count = cgiGetSize("PRINTER_NAME");
-    }
+    if (cupsFileFind("smbclient", getenv("PATH"), 1, filename,
+                     sizeof(filename)) &&
+        cupsFileFind("rpcclient", getenv("PATH"), 1, filename,
+                    sizeof(filename)))
+      cgiSetVariable("HAVE_SAMBA", "Y");
     else
-      name = "EXPORT_NAME";
-
-    for (i = 0; i < export_count; i ++)
     {
-      dest = cgiGetArray(name, i);
+      if (!cupsFileFind("smbclient", getenv("PATH"), 1, filename,
+                        sizeof(filename)))
+        fputs("ERROR: smbclient not found!\n", stderr);
 
-      if (!cupsAdminCreateWindowsPPD(http, dest, ppd, sizeof(ppd)))
-        break;
+      if (!cupsFileFind("rpcclient", getenv("PATH"), 1, filename,
+                        sizeof(filename)))
+        fputs("ERROR: rpcclient not found!\n", stderr);
+    }
+  }
+  else
+    perror(filename);
 
-      j = cupsAdminExportSamba(dest, ppd, "localhost", username, password,
-                               stderr);
+ /*
+  * Subscriptions...
+  */
 
-      unlink(ppd);
+  request = ippNewRequest(IPP_GET_SUBSCRIPTIONS);
 
-      if (!j)
-        break;
-    }
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
+               NULL, "ipp://localhost/");
 
-    if (i < export_count)
-      cgiSetVariable("ERROR", cupsLastErrorString());
-    else
-    {
-      cgiStartHTML(cgiText(_("Export Printers to Samba")));
-      cgiCopyTemplateLang("samba-exported.tmpl");
-      cgiEndHTML();
-      return;
-    }
+  if ((response = cupsDoRequest(http, request, "/")) != NULL)
+  {
+    cgiSetIPPVars(response, NULL, NULL, NULL, 0);
+    ippDelete(response);
   }
-  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...
+  * Finally, show the main menu template...
   */
 
-  cgiStartHTML(cgiText(_("Export Printers to Samba")));
-  cgiCopyTemplateLang("samba-export.tmpl");
+  cgiStartHTML(cgiText(_("Administration")));
+
+  cgiCopyTemplateLang("admin.tmpl");
+
   cgiEndHTML();
 }
 
 
 /*
- * 'do_menu()' - Show the main menu...
+ * 'do_printer_op()' - Do a printer operation.
  */
 
 static void
-do_menu(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 */
 {
-  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 */
+  ipp_t                *request;               /* IPP request */
+  char         uri[HTTP_MAX_URI];      /* Printer URI */
+  const char   *printer,               /* Printer name (purge-jobs) */
+               *is_class;              /* Is a class? */
+
 
+  is_class = cgiGetVariable("IS_CLASS");
+  printer  = cgiGetVariable("PRINTER_NAME");
+
+  if (!printer)
+  {
+    cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
+    cgiStartHTML(title);
+    cgiCopyTemplateLang("error.tmpl");
+    cgiEndHTML();
+    return;
+  }
 
  /*
-  * Get the current server settings...
+  * Build a printer request, which requires the following
+  * attributes:
+  *
+  *    attributes-charset
+  *    attributes-natural-language
+  *    printer-uri
   */
 
-  if (!cupsAdminGetServerSettings(http, &num_settings, &settings))
+  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);
+
+ /*
+  * Do the request and get back a response...
+  */
+
+  ippDelete(cupsDoRequest(http, request, "/admin/"));
+
+  if (cupsLastError() == IPP_NOT_AUTHORIZED)
   {
-    cgiSetVariable("SETTINGS_MESSAGE",
-                   cgiText(_("Unable to open cupsd.conf file:")));
-    cgiSetVariable("SETTINGS_ERROR", cupsLastErrorString());
+    puts("Status: 401\n");
+    exit(0);
+  }
+  else if (cupsLastError() > IPP_OK_CONFLICT)
+  {
+    cgiStartHTML(title);
+    cgiShowIPPError(_("Unable to change printer:"));
   }
+  else
+  {
+   /*
+    * Redirect successful updates back to the printer page...
+    */
 
-  if ((val = cupsGetOption(CUPS_SERVER_DEBUG_LOGGING, num_settings,
-                           settings)) != NULL && atoi(val))
-    cgiSetVariable("DEBUG_LOGGING", "CHECKED");
+    char       url[1024],              /* Printer/class URL */
+               refresh[1024];          /* Refresh URL */
 
-  if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ADMIN, num_settings,
-                           settings)) != NULL && atoi(val))
-    cgiSetVariable("REMOTE_ADMIN", "CHECKED");
 
-  if ((val = cupsGetOption(CUPS_SERVER_REMOTE_ANY, num_settings,
-                           settings)) != NULL && atoi(val))
-    cgiSetVariable("REMOTE_ANY", "CHECKED");
+    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);
 
-  if ((val = cupsGetOption(CUPS_SERVER_REMOTE_PRINTERS, num_settings,
-                           settings)) != NULL && atoi(val))
-    cgiSetVariable("REMOTE_PRINTERS", "CHECKED");
+    cgiStartHTML(title);
 
-  if ((val = cupsGetOption(CUPS_SERVER_SHARE_PRINTERS, num_settings,
-                           settings)) != NULL && atoi(val))
-    cgiSetVariable("SHARE_PRINTERS", "CHECKED");
+    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");
+  }
 
-  if ((val = cupsGetOption(CUPS_SERVER_USER_CANCEL_ANY, num_settings,
-                           settings)) != NULL && atoi(val))
-    cgiSetVariable("USER_CANCEL_ANY", "CHECKED");
+  cgiEndHTML();
+}
 
-#ifdef HAVE_GSSAPI
-  cgiSetVariable("HAVE_GSSAPI", "1");
 
-  if ((val = cupsGetOption("DefaultAuthType", num_settings,
-                           settings)) != NULL && !strcasecmp(val, "Negotiate"))
-    cgiSetVariable("KERBEROS", "CHECKED");
-#endif /* HAVE_GSSAPI */
+/*
+ * 'do_set_allowed_users()' - Set the allowed/denied users for a queue.
+ */
 
-  cupsFreeOptions(num_settings, settings);
+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"
+               };
 
- /*
-  * Get the list of printers and their devices...
-  */
 
-  request = ippNewRequest(CUPS_GET_PRINTERS);
+  is_class = cgiGetVariable("IS_CLASS");
+  printer  = cgiGetVariable("PRINTER_NAME");
 
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
-               "requested-attributes", NULL, "device-uri");
+  if (!printer)
+  {
+    cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
+    cgiStartHTML(cgiText(_("Set Allowed Users")));
+    cgiCopyTemplateLang("error.tmpl");
+    cgiEndHTML();
+    return;
+  }
 
-  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);
+  users = cgiGetVariable("users");
+  type  = cgiGetVariable("type");
 
-  if ((response = cupsDoRequest(http, request, "/")) != NULL)
+  if (!users || !type ||
+      (strcmp(type, "requesting-user-name-allowed") &&
+       strcmp(type, "requesting-user-name-denied")))
   {
    /*
-    * Got the printer list, now load the devices...
+    * Build a Get-Printer-Attributes request, which requires the following
+    * attributes:
+    *
+    *    attributes-charset
+    *    attributes-natural-language
+    *    printer-uri
+    *    requested-attributes
     */
 
-    int                i;                      /* Looping var */
-    cups_array_t *printer_devices;     /* Printer devices for local printers */
-    char       *printer_device;        /* Current printer device */
+    request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+
+    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);
 
+    ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+                  "requested-attributes",
+                 (int)(sizeof(attrs) / sizeof(attrs[0])), NULL, attrs);
 
    /*
-    * 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);
+    if ((response = cupsDoRequest(http, request, "/")) != NULL)
+    {
+      cgiSetIPPVars(response, NULL, NULL, NULL, 0);
 
-    for (attr = ippFindAttribute(response, "device-uri", IPP_TAG_URI);
-         attr;
-        attr = ippFindNextAttribute(response, "device-uri", IPP_TAG_URI))
+      ippDelete(response);
+    }
+
+    cgiStartHTML(cgiText(_("Set Allowed Users")));
+
+    if (cupsLastError() == IPP_NOT_AUTHORIZED)
     {
-      cupsArrayAdd(printer_devices, strdup(attr->values[0].string.text));
+      puts("Status: 401\n");
+      exit(0);
     }
+    else if (cupsLastError() > IPP_OK_CONFLICT)
+      cgiShowIPPError(_("Unable to get printer attributes:"));
+    else
+      cgiCopyTemplateLang("users.tmpl");
 
+    cgiEndHTML();
+  }
+  else
+  {
    /*
-    * Free the printer list and get the device list...
+    * Save the changes...
     */
 
-    ippDelete(response);
-
-    request = ippNewRequest(CUPS_GET_DEVICES);
-
-    if ((response = cupsDoRequest(http, request, "/")) != NULL)
+    for (num_users = 0, ptr = (char *)users; *ptr; num_users ++)
     {
      /*
-      * Got the device list, let's parse it...
+      * Skip whitespace and commas...
       */
 
-      const char *device_uri,          /* device-uri attribute value */
-               *device_make_and_model, /* device-make-and-model value */
-               *device_info;           /* device-info value */
+      while (*ptr == ',' || isspace(*ptr & 255))
+       ptr ++;
 
+      if (!*ptr)
+        break;
 
-      for (i = 0, attr = response->attrs; attr; attr = attr->next)
+      if (*ptr == '\'' || *ptr == '\"')
       {
        /*
-        * Skip leading attributes until we hit a device...
+       * Scan quoted name...
        */
 
-       while (attr && attr->group_tag != IPP_TAG_PRINTER)
-          attr = attr->next;
-
-       if (!attr)
-          break;
+       quote = *ptr++;
 
+       for (end = ptr; *end; end ++)
+         if (*end == quote)
+           break;
+      }
+      else
+      {
        /*
-       * Pull the needed attributes from this device...
+       * Scan space or comma-delimited name...
        */
 
-       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;
-       }
+        for (end = ptr; *end; end ++)
+         if (isspace(*end & 255) || *end == ',')
+           break;
+      }
 
-       /*
-       * See if we have everything needed...
-       */
+     /*
+      * Advance to the next name...
+      */
 
-       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...
-         */
+      ptr = end;
+    }
 
-          if (!cupsArrayFind(printer_devices, (void *)device_uri))
-          {
-          /*
-           * Not found, so it must be a new printer...
-           */
+   /*
+    * Build a CUPS-Add-Printer/Class request, which requires the following
+    * attributes:
+    *
+    *    attributes-charset
+    *    attributes-natural-language
+    *    printer-uri
+    *    requesting-user-name-{allowed,denied}
+    */
 
-            char       options[1024],  /* Form variables for this device */
-                       *options_ptr;   /* Pointer into string */
-           const char  *ptr;           /* Pointer into device string */
+    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);
 
-           /*
-           * 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.
-           */
+    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);
 
-           strcpy(options, "TEMPLATE_NAME=");
-           options_ptr = options + strlen(options);
+      for (i = 0, ptr = (char *)users; *ptr; i ++)
+      {
+       /*
+        * Skip whitespace and commas...
+       */
 
-            if (strncasecmp(device_info, "unknown", 7))
-             ptr = device_info;
-            else if ((ptr = strstr(device_uri, "://")) != NULL)
-             ptr += 3;
-           else
-             ptr = device_make_and_model;
+        while (*ptr == ',' || isspace(*ptr & 255))
+         ptr ++;
 
-           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;
+        if (!*ptr)
+         break;
 
-           /*
-           * Then add the make and model in the printer info, so
-           * that MacOS clients see something reasonable...
-           */
+        if (*ptr == '\'' || *ptr == '\"')
+       {
+        /*
+         * Scan quoted name...
+         */
 
-            strlcpy(options_ptr, "&PRINTER_LOCATION=Local+Printer"
-                                "&PRINTER_INFO=",
-                   sizeof(options) - (options_ptr - options));
-           options_ptr += strlen(options_ptr);
+         quote = *ptr++;
 
-            cgiFormEncode(options_ptr, device_make_and_model,
-                         sizeof(options) - (options_ptr - options));
-           options_ptr += strlen(options_ptr);
+         for (end = ptr; *end; end ++)
+           if (*end == quote)
+             break;
+       }
+       else
+       {
+        /*
+         * Scan space or comma-delimited name...
+         */
 
-           /*
-           * Then copy the device URI...
-           */
+          for (end = ptr; *end; end ++)
+           if (isspace(*end & 255) || *end == ',')
+             break;
+        }
 
-           strlcpy(options_ptr, "&DEVICE_URI=",
-                   sizeof(options) - (options_ptr - options));
-           options_ptr += strlen(options_ptr);
+       /*
+        * Terminate the name...
+       */
 
-            cgiFormEncode(options_ptr, device_uri,
-                         sizeof(options) - (options_ptr - options));
-           options_ptr += strlen(options_ptr);
+        if (*end)
+          *end++ = '\0';
 
-            if (options_ptr < (options + sizeof(options) - 1))
-           {
-             *options_ptr++ = '|';
-             cgiFormEncode(options_ptr, device_make_and_model,
-                         sizeof(options) - (options_ptr - options));
-           }
+       /*
+        * Add the name...
+       */
 
-           /*
-           * Finally, set the form variables for this printer...
-           */
+        attr->values[i].string.text = strdup(ptr);
 
-           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 ++;
-         }
-       }
+       /*
+        * Advance to the next name...
+       */
 
-        if (!attr)
-         break;
+        ptr = end;
       }
+    }
 
-      ippDelete(response);
+   /*
+    * Do the request and get back a response...
+    */
+
+    ippDelete(cupsDoRequest(http, request, "/admin/"));
 
+    if (cupsLastError() == IPP_NOT_AUTHORIZED)
+    {
+      puts("Status: 401\n");
+      exit(0);
+    }
+    else if (cupsLastError() > IPP_OK_CONFLICT)
+    {
+      cgiStartHTML(cgiText(_("Set Allowed Users")));
+      cgiShowIPPError(_("Unable to change printer:"));
+    }
+    else
+    {
      /*
-      * Free the device list...
+      * Redirect successful updates back to the printer page...
       */
 
-      for (printer_device = (char *)cupsArrayFirst(printer_devices);
-           printer_device;
-          printer_device = (char *)cupsArrayNext(printer_devices))
-        free(printer_device);
+      char     url[1024],              /* Printer/class URL */
+               refresh[1024];          /* Refresh URL */
 
-      cupsArrayDelete(printer_devices);
+
+      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(cgiText(_("Set Allowed Users")));
+
+      cgiCopyTemplateLang(is_class ? "class-modified.tmpl" :
+                                     "printer-modified.tmpl");
     }
+
+    cgiEndHTML();
   }
+}
 
- /*
-  * See if Samba and the Windows drivers are installed...
-  */
 
-  if ((datadir = getenv("CUPS_DATADIR")) == NULL)
-    datadir = CUPS_DATADIR;
+/*
+ * 'do_set_options()' - Configure the default options for a queue.
+ */
 
-  snprintf(filename, sizeof(filename), "%s/drivers/pscript5.dll", datadir);
-  if (!access(filename, R_OK))
-  {
-   /*
-    * Found Windows 2000 driver file, see if we have smbclient and
-    * rpcclient...
-    */
+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 */
+               value[1024],            /* Option value */
+               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_coption_t        *coption;               /* Custom option */
+  ppd_cparam_t *cparam;                /* Custom parameter */
+  ppd_attr_t   *ppdattr;               /* PPD attribute */
+  const char   *title;                 /* Page title */
 
-    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);
+  title = cgiText(is_class ? _("Set Class Options") : _("Set Printer Options"));
+
+  fprintf(stderr, "DEBUG: do_set_options(http=%p, is_class=%d)\n", http,
+          is_class);
 
  /*
-  * Subscriptions...
+  * Get the printer name...
   */
 
-  request = ippNewRequest(IPP_GET_SUBSCRIPTIONS);
-
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
-               NULL, "ipp://localhost/");
-
-  if ((response = cupsDoRequest(http, request, "/")) != NULL)
+  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
   {
-    cgiSetIPPVars(response, NULL, NULL, NULL, 0);
-    ippDelete(response);
+    cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
+    cgiStartHTML(title);
+    cgiCopyTemplateLang("error.tmpl");
+    cgiEndHTML();
+    return;
   }
 
+  fprintf(stderr, "DEBUG: printer=\"%s\", uri=\"%s\"...\n", printer, uri);
+
  /*
-  * Finally, show the main menu template...
+  * If the user clicks on the Auto-Configure button, send an AutoConfigure
+  * command file to the printer...
   */
 
-  cgiStartHTML(cgiText(_("Administration")));
+  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";
 
-  cgiCopyTemplateLang("admin.tmpl");
 
-  cgiEndHTML();
-}
+    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);
 
-/*
- * 'do_printer_op()' - Do a printer operation.
- */
+    if (cupsLastError() >= IPP_REDIRECTION_OTHER_SITE)
+    {
+      cgiSetVariable("ERROR", cupsLastErrorString());
+      cgiStartHTML(title);
+      cgiCopyTemplateLang("error.tmpl");
+      cgiEndHTML();
 
-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? */
+      cupsCancelJob(printer, job_id);
+      return;
+    }
 
+   /*
+    * Redirect successful updates back to the printer page...
+    */
 
-  is_class = cgiGetVariable("IS_CLASS");
-  printer  = cgiGetVariable("PRINTER_NAME");
+    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);
 
-  if (!printer)
-  {
-    cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
     cgiStartHTML(title);
-    cgiCopyTemplateLang("error.tmpl");
+
+    cgiCopyTemplateLang("printer-configured.tmpl");
     cgiEndHTML();
     return;
   }
 
  /*
-  * Build a printer request, which requires the following
-  * attributes:
-  *
-  *    attributes-charset
-  *    attributes-natural-language
-  *    printer-uri
+  * Get the PPD file...
   */
 
-  request = ippNewRequest(op);
+  if (is_class)
+    filename = NULL;
+  else
+    filename = cupsGetPPD2(http, printer);
+
+  if (filename)
+  {
+    fprintf(stderr, "DEBUG: Got PPD file: \"%s\"\n", filename);
+
+    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;
+  }
+
+  if (cgiGetVariable("job_sheets_start") != NULL ||
+      cgiGetVariable("job_sheets_end") != NULL)
+    have_options = 1;
+  else
+    have_options = 0;
+
+  if (ppd)
+  {
+    ppdMarkDefaults(ppd);
+
+    for (option = ppdFirstOption(ppd);
+         option;
+        option = ppdNextOption(ppd))
+      if ((var = cgiGetVariable(option->keyword)) != NULL)
+      {
+       have_options = 1;
+       ppdMarkOption(ppd, option->keyword, var);
+      }
+  }
+
+  if (!have_options || ppdConflicts(ppd))
+  {
+   /*
+    * Show the options to the user...
+    */
+
+    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)
+    {
+      ppdLocalize(ppd);
 
-  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 (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 ++;
+           }
 
- /*
-  * Do the request and get back a response...
-  */
+       cgiCopyTemplateLang("option-conflict.tmpl");
+      }
 
-  ippDelete(cupsDoRequest(http, request, "/admin/"));
+      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);
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
-  {
-    cgiStartHTML(title);
-    cgiShowIPPError(_("Unable to change printer:"));
-  }
-  else
-  {
-   /*
-    * Redirect successful updates back to the printer page...
-    */
+       cgiCopyTemplateLang("option-header.tmpl");
+       
+       for (j = group->num_options, option = group->options;
+            j > 0;
+            j --, option ++)
+       {
+         if (!strcmp(option->keyword, "PageRegion"))
+           continue;
 
-    char       url[1024],              /* Printer/class URL */
-               refresh[1024];          /* Refresh URL */
+         cgiSetVariable("KEYWORD", option->keyword);
+         cgiSetVariable("KEYTEXT", option->text);
 
+         if (option->conflicted)
+           cgiSetVariable("CONFLICTED", "1");
+         else
+           cgiSetVariable("CONFLICTED", "0");
 
-    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);
+         cgiSetSize("CHOICES", 0);
+         cgiSetSize("TEXT", 0);
+         for (k = 0, m = 0; k < option->num_choices; k ++)
+         {
+           cgiSetArray("CHOICES", m, option->choices[k].choice);
+           cgiSetArray("TEXT", m, option->choices[k].text);
 
-    cgiStartHTML(title);
+           m ++;
 
-    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");
-  }
+           if (option->choices[k].marked)
+             cgiSetVariable("DEFCHOICE", option->choices[k].choice);
+         }
 
-  cgiEndHTML();
-}
+         cgiSetSize("PARAMS", 0);
+         cgiSetSize("PARAMTEXT", 0);
+         cgiSetSize("PARAMVALUE", 0);
+         cgiSetSize("INPUTTYPE", 0);
 
+         if ((coption = ppdFindCustomOption(ppd, option->keyword)))
+         {
+            const char *units = NULL;  /* Units value, if any */
 
-/*
- * 'do_set_allowed_users()' - Set the allowed/denied users for a queue.
- */
 
-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"
-               };
+           cgiSetVariable("ISCUSTOM", "1");
 
+           for (cparam = ppdFirstCustomParam(coption), m = 0;
+                cparam;
+                cparam = ppdNextCustomParam(coption), m ++)
+           {
+             if (!strcasecmp(option->keyword, "PageSize") &&
+                 strcasecmp(cparam->name, "Width") &&
+                 strcasecmp(cparam->name, "Height"))
+              {
+               m --;
+               continue;
+              }
+
+             cgiSetArray("PARAMS", m, cparam->name);
+             cgiSetArray("PARAMTEXT", m, cparam->text);
+             cgiSetArray("INPUTTYPE", m, "text");
+
+             switch (cparam->type)
+             {
+               case PPD_CUSTOM_POINTS :
+                   if (!strncasecmp(option->defchoice, "Custom.", 7))
+                   {
+                     units = option->defchoice + strlen(option->defchoice) - 2;
+
+                     if (strcmp(units, "mm") && strcmp(units, "cm") &&
+                         strcmp(units, "in") && strcmp(units, "ft"))
+                     {
+                       if (units[1] == 'm')
+                         units ++;
+                       else
+                         units = "pt";
+                     }
+                   }
+                   else
+                     units = "pt";
+
+                    if (!strcmp(units, "mm"))
+                     snprintf(value, sizeof(value), "%g",
+                              cparam->current.custom_points / 72.0 * 25.4);
+                    else if (!strcmp(units, "cm"))
+                     snprintf(value, sizeof(value), "%g",
+                              cparam->current.custom_points / 72.0 * 2.54);
+                    else if (!strcmp(units, "in"))
+                     snprintf(value, sizeof(value), "%g",
+                              cparam->current.custom_points / 72.0);
+                    else if (!strcmp(units, "ft"))
+                     snprintf(value, sizeof(value), "%g",
+                              cparam->current.custom_points / 72.0 / 12.0);
+                    else if (!strcmp(units, "m"))
+                     snprintf(value, sizeof(value), "%g",
+                              cparam->current.custom_points / 72.0 * 0.0254);
+                    else
+                     snprintf(value, sizeof(value), "%g",
+                              cparam->current.custom_points);
+                   cgiSetArray("PARAMVALUE", m, value);
+                   break;
+
+               case PPD_CUSTOM_CURVE :
+               case PPD_CUSTOM_INVCURVE :
+               case PPD_CUSTOM_REAL :
+                   snprintf(value, sizeof(value), "%g",
+                            cparam->current.custom_real);
+                   cgiSetArray("PARAMVALUE", m, value);
+                   break;
+
+               case PPD_CUSTOM_INT:
+                   snprintf(value, sizeof(value), "%d",
+                            cparam->current.custom_int);
+                   cgiSetArray("PARAMVALUE", m, value);
+                   break;
+
+               case PPD_CUSTOM_PASSCODE:
+               case PPD_CUSTOM_PASSWORD:
+                   if (cparam->current.custom_password)
+                     cgiSetArray("PARAMVALUE", m,
+                                 cparam->current.custom_password);
+                   else
+                     cgiSetArray("PARAMVALUE", m, "");
+                   cgiSetArray("INPUTTYPE", m, "password");
+                   break;
+
+               case PPD_CUSTOM_STRING:
+                   if (cparam->current.custom_string)
+                     cgiSetArray("PARAMVALUE", m,
+                                 cparam->current.custom_string);
+                   else
+                     cgiSetArray("PARAMVALUE", m, "");
+                   break;
+             }
+           }
 
-  is_class = cgiGetVariable("IS_CLASS");
-  printer  = cgiGetVariable("PRINTER_NAME");
+            if (units)
+           {
+             cgiSetArray("PARAMS", m, "Units");
+             cgiSetArray("PARAMTEXT", m, cgiText(_("Units")));
+             cgiSetArray("PARAMVALUE", m, units);
+           }
+         }
+         else
+           cgiSetVariable("ISCUSTOM", "0");
 
-  if (!printer)
-  {
-    cgiSetVariable("ERROR", cgiText(_("Missing form variable!")));
-    cgiStartHTML(cgiText(_("Set Allowed Users")));
-    cgiCopyTemplateLang("error.tmpl");
-    cgiEndHTML();
-    return;
-  }
+         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;
+         }
+       }
 
-  users = cgiGetVariable("users");
-  type  = cgiGetVariable("type");
+       cgiCopyTemplateLang("option-trailer.tmpl");
+      }
+    }
 
-  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:
+    * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
+    * following attributes:
     *
     *    attributes-charset
     *    attributes-natural-language
     *    printer-uri
-    *    requested-attributes
     */
 
     request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
 
     httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
-                     "localhost", 0, is_class ? "/classes/%s" : "/printers/%s",
-                    printer);
+                     "localhost", 0, "/printers/%s", printer);
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
-                NULL, uri);
-
-    ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
-                  "requested-attributes",
-                 (int)(sizeof(attrs) / sizeof(attrs[0])), NULL, attrs);
+                 NULL, uri);
 
    /*
     * Do the request and get back a response...
@@ -2937,154 +3450,291 @@ do_set_allowed_users(http_t *http)    /* I - HTTP connection */
 
     if ((response = cupsDoRequest(http, request, "/")) != NULL)
     {
-      cgiSetIPPVars(response, NULL, NULL, NULL, 0);
+      if ((attr = ippFindAttribute(response, "job-sheets-supported",
+                                   IPP_TAG_ZERO)) != NULL)
+      {
+       /*
+       * Add the job sheets options...
+       */
 
-      ippDelete(response);
-    }
+       cgiSetVariable("GROUP", cgiText(_("Banners")));
+       cgiCopyTemplateLang("option-header.tmpl");
 
-    cgiStartHTML(cgiText(_("Set Allowed Users")));
+       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)
-      cgiShowIPPError(_("Unable to get printer attributes:"));
-    else
-      cgiCopyTemplateLang("users.tmpl");
+        attr = ippFindAttribute(response, "job-sheets-default", IPP_TAG_ZERO);
 
-    cgiEndHTML();
-  }
-  else
-  {
-   /*
-    * Save the changes...
-    */
+        cgiSetVariable("KEYWORD", "job_sheets_start");
+       cgiSetVariable("KEYTEXT", cgiText(_("Starting Banner")));
+        cgiSetVariable("DEFCHOICE", attr != NULL ?
+                                   attr->values[0].string.text : "");
 
-    for (num_users = 0, ptr = (char *)users; *ptr; num_users ++)
-    {
-     /*
-      * Skip whitespace and commas...
-      */
+       cgiCopyTemplateLang("option-pickone.tmpl");
 
-      while (*ptr == ',' || isspace(*ptr & 255))
-       ptr ++;
+        cgiSetVariable("KEYWORD", "job_sheets_end");
+       cgiSetVariable("KEYTEXT", cgiText(_("Ending Banner")));
+        cgiSetVariable("DEFCHOICE", attr != NULL && attr->num_values > 1 ?
+                                   attr->values[1].string.text : "");
 
-      if (*ptr == '\'' || *ptr == '\"')
+       cgiCopyTemplateLang("option-pickone.tmpl");
+
+       cgiCopyTemplateLang("option-trailer.tmpl");
+      }
+
+      if (ippFindAttribute(response, "printer-error-policy-supported",
+                           IPP_TAG_ZERO) ||
+          ippFindAttribute(response, "printer-op-policy-supported",
+                          IPP_TAG_ZERO))
       {
        /*
-       * Scan quoted name...
+       * Add the error and operation policy options...
+       */
+
+       cgiSetVariable("GROUP", cgiText(_("Policies")));
+       cgiCopyTemplateLang("option-header.tmpl");
+
+       /*
+        * Error policy...
        */
 
-       quote = *ptr++;
+        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);
+
+          cgiSetVariable("KEYWORD", "printer_error_policy");
+         cgiSetVariable("KEYTEXT", cgiText(_("Error Policy")));
+          cgiSetVariable("DEFCHOICE", attr == NULL ?
+                                     "" : attr->values[0].string.text);
+        }
+
+       cgiCopyTemplateLang("option-pickone.tmpl");
+
+       /*
+        * Operation policy...
+       */
+
+        attr = ippFindAttribute(response, "printer-op-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-op-policy", IPP_TAG_ZERO);
+
+          cgiSetVariable("KEYWORD", "printer_op_policy");
+         cgiSetVariable("KEYTEXT", cgiText(_("Operation Policy")));
+          cgiSetVariable("DEFCHOICE", attr == NULL ?
+                                     "" : attr->values[0].string.text);
+
+         cgiCopyTemplateLang("option-pickone.tmpl");
+        }
+
+       cgiCopyTemplateLang("option-trailer.tmpl");
+      }
+
+      ippDelete(response);
+    }
+
+   /*
+    * Binary protocol support...
+    */
+
+    if (ppd && ppd->protocols && strstr(ppd->protocols, "BCP"))
+    {
+      ppdattr = ppdFindAttr(ppd, "cupsProtocol", NULL);
+
+      cgiSetVariable("GROUP", cgiText(_("PS Binary Protocol")));
+      cgiCopyTemplateLang("option-header.tmpl");
+
+      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", ppdattr ? ppdattr->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 = get_option_value(ppd, "PageSize", value, sizeof(value));
+         else
+           var = get_option_value(ppd, keyword, value, sizeof(value));
 
-       /*
-        * Add the name...
-       */
+         if (!var)
+           cupsFilePrintf(out, "%s\n", line);
+         else
+           cupsFilePrintf(out, "*Default%s: %s\n", keyword, var);
+       }
+      }
 
-        attr->values[i].string.text = strdup(ptr);
+     /*
+      * TODO: We need to set the port-monitor attribute!
+      */
 
-       /*
-        * Advance to the next name...
-       */
+      if ((var = cgiGetVariable("protocol")) != NULL)
+       cupsFilePrintf(out, "*cupsProtocol: %s\n", var);
 
-        ptr = end;
-      }
+      cupsFileClose(in);
+      cupsFileClose(out);
+    }
+    else
+    {
+     /*
+      * Make sure temporary filename is cleared when there is no PPD...
+      */
+
+      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)
+      ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME,
+                  "printer-error-policy", NULL, var);
+
+    if ((var = cgiGetVariable("printer_op_policy")) != NULL)
+      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)
+    if (cupsLastError() == IPP_NOT_AUTHORIZED)
     {
-      cgiStartHTML(cgiText(_("Set Allowed Users")));
-      cgiShowIPPError(_("Unable to change printer:"));
+      puts("Status: 401\n");
+      exit(0);
+    }
+    else if (cupsLastError() > IPP_OK_CONFLICT)
+    {
+      cgiStartHTML(title);
+      cgiShowIPPError(_("Unable to set options:"));
     }
     else
     {
@@ -3092,29 +3742,32 @@ do_set_allowed_users(http_t *http)      /* I - HTTP connection */
       * 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);
 }
 
 
 /*
- * 'do_set_sharing()' - Set printer-is-shared value...
+ * 'do_set_sharing()' - Set printer-is-shared value.
  */
 
 static void
@@ -3172,7 +3825,12 @@ do_set_sharing(http_t *http)             /* I - HTTP connection */
     ippDelete(response);
   }
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() == IPP_NOT_AUTHORIZED)
+  {
+    puts("Status: 401\n");
+    exit(0);
+  }
+  else if (cupsLastError() > IPP_OK_CONFLICT)
   {
     cgiStartHTML(cgiText(_("Set Publishing")));
     cgiShowIPPError(_("Unable to change printer-is-shared attribute:"));
@@ -3201,6 +3859,294 @@ do_set_sharing(http_t *http)            /* I - HTTP connection */
 }
 
 
+/*
+ * 'get_option_value()' - Return the value of an option.
+ *
+ * This function also handles generation of custom option values.
+ */
+
+static char *                          /* O - Value string or NULL on error */
+get_option_value(
+    ppd_file_t    *ppd,                        /* I - PPD file */
+    const char    *name,               /* I - Option name */
+    char          *buffer,             /* I - String buffer */
+    size_t        bufsize)             /* I - Size of buffer */
+{
+  char         *bufptr,                /* Pointer into buffer */
+               *bufend;                /* End of buffer */
+  ppd_coption_t *coption;              /* Custom option */
+  ppd_cparam_t *cparam;                /* Current custom parameter */
+  char         keyword[256];           /* Parameter name */
+  const char   *val,                   /* Parameter value */
+               *uval;                  /* Units value */
+  long         integer;                /* Integer value */
+  double       number,                 /* Number value */
+               number_points;          /* Number in points */
+
+
+ /*
+  * See if we have a custom option choice...
+  */
+
+  if ((val = cgiGetVariable(name)) == NULL)
+  {
+   /*
+    * Option not found!
+    */
+
+    return (NULL);
+  }
+  else if (strcasecmp(val, "Custom") ||
+           (coption = ppdFindCustomOption(ppd, name)) == NULL)
+  {
+   /*
+    * Not a custom choice...
+    */
+
+    strlcpy(buffer, val, bufsize);
+    return (buffer);
+  }
+
+ /*
+  * OK, we have a custom option choice, format it...
+  */
+
+  *buffer = '\0';
+
+  if (!strcmp(coption->keyword, "PageSize"))
+  {
+    const char *lval;                  /* Length string value */
+    double     width,                  /* Width value */
+               width_points,           /* Width in points */
+               length,                 /* Length value */
+               length_points;          /* Length in points */
+
+
+    val  = cgiGetVariable("PageSize.Width");
+    lval = cgiGetVariable("PageSize.Height");
+    uval = cgiGetVariable("PageSize.Units");
+
+    if (!val || !lval || !uval ||
+        (width = strtod(val, NULL)) == 0.0 ||
+        (length = strtod(lval, NULL)) == 0.0 ||
+        (strcmp(uval, "pt") && strcmp(uval, "in") && strcmp(uval, "ft") &&
+        strcmp(uval, "cm") && strcmp(uval, "mm") && strcmp(uval, "m")))
+      return (NULL);
+
+    width_points  = get_points(width, uval);
+    length_points = get_points(length, uval);
+
+    if (width_points < ppd->custom_min[0] ||
+        width_points > ppd->custom_max[0] ||
+        length_points < ppd->custom_min[1] ||
+       length_points > ppd->custom_max[1])
+      return (NULL);
+
+    snprintf(buffer, bufsize, "Custom.%gx%g%s", width, length, uval);
+  }
+  else if (cupsArrayCount(coption->params) == 1) 
+  {
+    cparam = ppdFirstCustomParam(coption);
+    snprintf(keyword, sizeof(keyword), "%s.%s", coption->keyword, cparam->name);
+
+    if ((val = cgiGetVariable(keyword)) == NULL)
+      return (NULL);
+
+    switch (cparam->type)
+    {
+      case PPD_CUSTOM_CURVE :
+      case PPD_CUSTOM_INVCURVE :
+      case PPD_CUSTOM_REAL :
+         if ((number = strtod(val, NULL)) == 0.0 ||
+             number < cparam->minimum.custom_real ||
+             number > cparam->maximum.custom_real)
+           return (NULL);
+
+          snprintf(buffer, bufsize, "Custom.%g", number);
+          break;
+
+      case PPD_CUSTOM_INT :
+          if (!*val || (integer = strtol(val, NULL, 10)) == LONG_MIN ||
+             integer == LONG_MAX ||
+             integer < cparam->minimum.custom_int ||
+             integer > cparam->maximum.custom_int)
+            return (NULL);
+
+          snprintf(buffer, bufsize, "Custom.%ld", integer);
+          break;
+
+      case PPD_CUSTOM_POINTS :
+          snprintf(keyword, sizeof(keyword), "%s.Units", coption->keyword);
+
+         if ((number = strtod(val, NULL)) == 0.0 ||
+             (uval = cgiGetVariable(keyword)) == NULL ||
+             (strcmp(uval, "pt") && strcmp(uval, "in") && strcmp(uval, "ft") &&
+              strcmp(uval, "cm") && strcmp(uval, "mm") && strcmp(uval, "m")))
+           return (NULL);
+
+         number_points = get_points(number, uval);
+         if (number_points < cparam->minimum.custom_points ||
+             number_points > cparam->maximum.custom_points)
+           return (NULL);
+
+         snprintf(buffer, bufsize, "Custom.%g%s", number, uval);
+          break;
+
+      case PPD_CUSTOM_PASSCODE :
+          for (uval = val; *uval; uval ++)
+           if (!isdigit(*uval & 255))
+             return (NULL);
+
+      case PPD_CUSTOM_PASSWORD :
+      case PPD_CUSTOM_STRING :
+          integer = (long)strlen(val);
+         if (integer < cparam->minimum.custom_string ||
+             integer > cparam->maximum.custom_string)
+           return (NULL);
+
+          snprintf(buffer, bufsize, "Custom.%s", val);
+         break;
+    }
+  }
+  else
+  {
+    const char *prefix = "{";          /* Prefix string */
+
+
+    bufptr = buffer;
+    bufend = buffer + bufsize;
+
+    for (cparam = ppdFirstCustomParam(coption);
+        cparam;
+        cparam = ppdNextCustomParam(coption))
+    {
+      snprintf(keyword, sizeof(keyword), "%s.%s", coption->keyword,
+               cparam->name);
+
+      if ((val = cgiGetVariable(keyword)) == NULL)
+       return (NULL);
+
+      snprintf(bufptr, bufend - bufptr, "%s%s=", prefix, cparam->name);
+      bufptr += strlen(bufptr);
+      prefix = " ";
+
+      switch (cparam->type)
+      {
+       case PPD_CUSTOM_CURVE :
+       case PPD_CUSTOM_INVCURVE :
+       case PPD_CUSTOM_REAL :
+           if ((number = strtod(val, NULL)) == 0.0 ||
+               number < cparam->minimum.custom_real ||
+               number > cparam->maximum.custom_real)
+             return (NULL);
+
+           snprintf(bufptr, bufend - bufptr, "%g", number);
+           break;
+
+       case PPD_CUSTOM_INT :
+           if (!*val || (integer = strtol(val, NULL, 10)) == LONG_MIN ||
+               integer == LONG_MAX ||
+               integer < cparam->minimum.custom_int ||
+               integer > cparam->maximum.custom_int)
+             return (NULL);
+
+           snprintf(bufptr, bufend - bufptr, "%ld", integer);
+           break;
+
+       case PPD_CUSTOM_POINTS :
+           snprintf(keyword, sizeof(keyword), "%s.Units", coption->keyword);
+
+           if ((number = strtod(val, NULL)) == 0.0 ||
+               (uval = cgiGetVariable(keyword)) == NULL ||
+               (strcmp(uval, "pt") && strcmp(uval, "in") &&
+                strcmp(uval, "ft") && strcmp(uval, "cm") &&
+                strcmp(uval, "mm") && strcmp(uval, "m")))
+             return (NULL);
+
+           number_points = get_points(number, uval);
+           if (number_points < cparam->minimum.custom_points ||
+               number_points > cparam->maximum.custom_points)
+             return (NULL);
+
+           snprintf(bufptr, bufend - bufptr, "%g%s", number, uval);
+           break;
+
+       case PPD_CUSTOM_PASSCODE :
+           for (uval = val; *uval; uval ++)
+             if (!isdigit(*uval & 255))
+               return (NULL);
+
+       case PPD_CUSTOM_PASSWORD :
+       case PPD_CUSTOM_STRING :
+           integer = (long)strlen(val);
+           if (integer < cparam->minimum.custom_string ||
+               integer > cparam->maximum.custom_string)
+             return (NULL);
+
+           if ((bufptr + 2) > bufend)
+             return (NULL);
+
+           bufend --;
+           *bufptr++ = '\"';
+
+           while (*val && bufptr < bufend)
+           {
+             if (*val == '\\' || *val == '\"')
+             {
+               if ((bufptr + 1) >= bufend)
+                 return (NULL);
+
+               *bufptr++ = '\\';
+             }
+
+             *bufptr++ = *val++;
+           }
+
+           if (bufptr >= bufend)
+             return (NULL);
+
+           *bufptr++ = '\"';
+           *bufptr   = '\0';
+           bufend ++;
+           break;
+      }
+
+      bufptr += strlen(bufptr);
+    }
+
+    if (bufptr == buffer || (bufend - bufptr) < 2)
+      return (NULL);
+
+    strcpy(bufptr, "}");
+  }
+
+  return (buffer);
+}
+
+
+/*
+ * 'get_points()' - Get a value in points.
+ */
+
+static double                          /* O - Number in points */
+get_points(double     number,          /* I - Original number */
+           const char *uval)           /* I - Units */
+{
+  if (!strcmp(uval, "mm"))             /* Millimeters */
+    return (number * 72.0 / 25.4);
+  else if (!strcmp(uval, "cm"))                /* Centimeters */
+    return (number * 72.0 / 2.54);
+  else if (!strcmp(uval, "in"))                /* Inches */
+    return (number * 72.0);
+  else if (!strcmp(uval, "ft"))                /* Feet */
+    return (number * 72.0 * 12.0);
+  else if (!strcmp(uval, "m"))         /* Meters */
+    return (number * 72.0 / 0.0254);
+  else                                 /* Points */
+    return (number);
+}
+
+
 /*
  * 'match_string()' - Return the number of matching characters.
  */
@@ -3251,5 +4197,5 @@ match_string(const char *a,               /* I - First string */
 
     
 /*
- * End of "$Id: admin.c 6378 2007-03-21 07:18:18Z mike $".
+ * End of "$Id: admin.c 7888 2008-08-29 21:16:56Z mike $".
  */