Custom CGIs

Opher Shachar ophers at ladpc.co.il
Sun Dec 17 08:45:10 PST 2006


> Opher Shachar wrote:
> > Hello,
> > I created a custom CGI and placed it in /usr/share/cups/doc.
> > One functionality of the CGI is to send back files:
> > I write to stdout:
> >      Content-type: text/plain; charset=<either of utf-8 or iso-8859-8>
> > or
> >      Content-type: application/postscript
> >      Content-length: <file size>
> >
> > Then the file (I leave an extra newline after the headers) but on the browser side I see a blank page and eventually timeout.
> > (It all works fine when sending text/html content)
> >
> > Q: Does CUPS support anything but text/html from its CGIs?
>
> Yes, of course.  You can't set the content-length, however - CUPS does
> that for you...

I created this plaintext.cgi file on two machines: one running CUPS 1.1.22 the other 1.2.7
(/etc/cups/cgi.types contains this single line: application/x-httpd-cgi cgi)
---------------- plaintext.cgi start ----------------
#!/bin/sh
############################################
# This is a test shell script for CUPS
############################################
alias echo='echo -e'
echo 'Content-type: text/plain'
echo
echo 'This is a specially crafted plain text ducument.'
----------------  plaintext.cgi end  ----------------
It ran OK on CUPS 1.1.22 but NOT on 1.2.7 !!

> > Another thing, the CUPS CGIs (admin.cgi, jobs.cgi ...) have a nice trait that they will ask for a new Authentication as needed.
> > ex. say I authenticated as the job owner to do "Hold Job" but I need admin preveliges to to "Hold Job" on a job I don't own - I'll be ask to re-authenticate instead of getting "Not Authorized/access denied" or the likes.
> >
> > Q: How can my CGI signal the CUPS Web Server to ask the User Agent (eg. InternetExplorer / FireFox) for Authentication.
>
> The Status: header is used for this:
>
>      Status: 401

Thanks, this works like a charm :)

Regards,
Opher Shachar.




More information about the cups mailing list