注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

My Unix World

不要迷恋Unix,Unix只是计算世界很小的一部分!

 
 
 

日志

 
 

【转】Postscript写的Web Server  

2009-01-20 23:49:40|  分类: utility-script |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
来源:http://hi.baidu.com/sockerboy/blog/item/1542c65cec941c47faf2c07d.html

要使用这个PostScript HTTPd,系统中应该有Ghostscript,并且需要inetd或xinetd支持,先在这两
个的配置文件中加入:
  • inetd.conf version:
    8080 stream tcp nowait nobody /usr/bin/gs gs -dNODISPLAY -q    
    /home/elly
    /psweb/pshttpd.ps
    #以上内容为一行,添加到/etc/inetd.conf,替换为pshttpd的路径名
  • xinetd version:
    # default: on
    # Start PS-HTTD
     











    service pshttpd



    {



    socket_type = stream



    protocol = tcp



    port = 8080



    user = pugo



    wait = no



    server = /usr/bin/gs



    server_args = -dNODISPLAY -q /home/elly/psweb/pshttpd.ps



    disable = no



    }
  • 然后把下面内容存到你的pshttpd.ps文件中,这个脚本其中有几处小毛病的(包含一个
    安全漏洞  【转】Postscript写的Web Server - liqi xie - My Unix World),另外路径相关的配置也需要你自己改:
    %!
    %===================================================
    % PS-HTTPD V1.3
    % Copyright 2000 Anders Karlsson, pugo@pugo.org
    % License: GNU General Public License
    %===================================================
    % This dictionary maps between extensions and mime-types
    % Observe that "html" isn't part of this dict, that's because
    % it's default in print_header.
    /extensiondict 27 dict def
    extensiondict begin
       /jpg (Content-type: image/jpeg\n) def
       /jpeg (Content-type: image/jpeg\n) def
       /gif (Content-type: image/gif\n) def
       /png (Content-type: image/png\n) def
       /tif (Content-type: image/tiff\n) def
       /tiff (Content-type: image/tiff\n) def
       /txt (Content-type: text/plain\n) def
       /css (Content-type: text/css\n) def
       /ps   (Content-type: application/postscript\n) def
       /pdf (Content-type: application/pdf\n) def
       /eps (Content-type: application/postscript\n) def
       /tar (Content-type: application/x-tar\n) def
       /rpm (Content-type: application/x-rpm\n) def
       /zip (Content-type: application/zip\n) def
       /mp3 (Content-type: audio/mpeg\n) def
       /mp2 (Content-type: audio/mpeg\n) def
       /mid (Content-type: audio/midi\n) def
       /midi (Content-type: audio/midi\n) def
       /wav (Content-type: audio/x-wav\n) def
       /au   (Content-type: audio/basic\n) def
       /ram (Content-type: audio/x-pn-realaudio\n) def
       /ra   (Content-type: audio/x-realaudio\n) def
       /mpg (Content-type: video/mpeg\n) def
       /mpeg (Content-type: video/mpeg\n) def
       /qt   (Content-type: video/quicktime\n) def
       /mov (Content-type: video/quicktime\n) def
       /avi (Content-type: video/x-msvideo\n) def
    end

    /get_file   % read file /infile and send it to %stdout
    {
       /buff 2048 string def
      
       { % loop
          infile buff readstring
          { stdout exch writestring }
          { stdout exch writestring infile closefile exit } ifelse
       } bind loop
    } bind def

    /read_command   % read command from stdin and define it to /command
    {
       /stdin (%stdin) (r) file def
       /inbuff 256 string def
      
       stdin inbuff readline
       pop
       /command exch def
    } bind def

    /conbcatstr % A better string-concat
    {
    exch dup length 2 index length add string
    dup dup 4 2 roll copy length 4 -1 roll putinterval
    } bind def
       
       
    /hitcount  % Add 1 to the hitcount-file
    {
    (/home/pugo/psweb/hits) (r+) file
    dup dup
    dup 16 string readline pop
    1 index 0 setfileposition
    cvi 1 add 16 string cvs
    writestring (\n) writestring
    closefile
    } bind def

    % Return extension of file on stack
    /get_extension   % (filepath.ext) -- (bool) (ext)
    {
       dup
       { % loop
          (.) search
          { pop pop }
          { exit } ifelse
       } loop
       exch 1 index ne
    } bind def

    % Print a HTTP-header
    /print_header
    {
       stdout (HTTP/1.0 200 OK\n) writestring
       stdout (MIME-Version: 1.0\n) writestring
       stdout (Server: PS-HTTPD/1.3\n) writestring
          get_extension
       {
          % If the extension exists in dictionary, then use it,
          % otherwise hope that text/html is good enough.
          dup extensiondict exch known
          { extensiondict exch get stdout exch writestring }
          { pop stdout (Content-type: text/html\n) writestring } ifelse
       }
       { % Couldn't get extension, guess it's text/html
          pop stdout (Content-type: text/plain\n) writestring
       } ifelse
      
       stdout (\n) writestring
    } bind def

    % Parse the HTTP-command read from user
    /parse_result
    {
       command token
       {
          (GET) eq
          {
             ( ) search
    {
            root exch conbcatstr           % build path
            /filename exch def pop pop     % define filename and clean stack
            filename filename length 1 sub 1 getinterval (/) eq
            { filename (index.html) conbcatstr
              /filename exch def } if      % add index.html
      
            filename (..) search           % Check if user tries to use ".."
            { stdout (4711 Stupid user error!\n\n) writestring quit } if pop
                  
            filename /infile exch (r) file def    % open file
           
            filename print_header
            get_file
             } if
          } if
       } if  
    } bind def

    % Redefine handleerror in errordict to quit on all errors.
    % Otherwise it will be possible to telnet and get a postscript-prompt
    errordict begin
    /handleerror { stdout (<B>PS-HTTPD ERROR</B><BR>Probably wrong URL\n\n)
     







    writestring quit } def







    end

    % Init environment
    /stdout (%stdout) (w) file def
    /command () def

    % Root-path (root of WWW-pages)
    /root (/home/elly/psweb) def

    hitcount % add one to the hitcount
    % Read a command from the server
    read_command
    parse_result
    quit
      评论这张
     
    阅读(302)| 评论(0)
    推荐 转载

    历史上的今天

    评论

    <#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    页脚

    网易公司版权所有 ©1997-2017