"Fossies" - the Fresh Open Source Software Archive

Member "astrocam-2.7.6/astrocam.pl" (26 May 2009, 4523 Bytes) of package /linux/www/old/astrocam-2.7.6.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "astrocam.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/perl -wT
    2 
    3 # astrocam.pl is distributed under the following license:
    4 #
    5 # Copyright (C) 2007-2008 Steffen Wendzel <steffen (at) ploetner-it (dot) de>
    6 #
    7 # Redistribution and use in source and binary forms, with or without
    8 # modification, are permitted provided that the following conditions
    9 # are met:
   10 # 1. Redistributions of source code must retain the above copyright
   11 #    notice, this list of conditions and the following disclaimer.
   12 # 2. Redistributions in binary form must reproduce the above copyright
   13 #    notice, this list of conditions and the following disclaimer in the
   14 #    documentation and/or other materials provided with the distribution.
   15 #
   16 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26 # SUCH DAMAGE.
   27 
   28 use strict;
   29 use CGI qw(:standard);
   30 use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
   31 use IPC::Msg;
   32 use IPC::SysV; # qw/IPC_PRIVATE S_IRWXU/;
   33 
   34 sub ReadForm {
   35     my %FORM;
   36     foreach my $field (param()) {
   37         $FORM{$field} = param($field);
   38         # check for some bad characters here
   39         unless ($FORM{$field} =~ /^[a-zA-Z0-9\.\-\+\_]+$/ ) {
   40             die "Insecure Character in \"$FORM{$field}\" found.";
   41         }
   42     }
   43     return %FORM;
   44 }
   45 
   46 sub ReadConfig {
   47     my %CONFIG;
   48     open(FP, "</etc/astrocam.conf") || die "Cannot open /etc/astrocam.conf!";
   49     while (my $zeile = <FP>) {
   50         (my $name, my $value) = split(/[\ \t]/, $zeile);
   51         $value =~ s/[\r\n]//g;
   52         $CONFIG{$name} = $value;
   53     }
   54     close(FP);
   55     return %CONFIG;
   56 }
   57 
   58 ######################################################################################
   59 # handle form data
   60 ######################################################################################
   61 
   62 my %CONFIG = ReadConfig();
   63 
   64 # check if all needed vars are available for us
   65 foreach my $value ("imagesize-x", "imagesize-y", "ipckey", "design", "picfile", "refreshtime", "contenturl") {
   66     if ($CONFIG{$value} eq "") {
   67         die "at least one needed value ($value) in astrocam.conf is not set!";
   68     }
   69 }
   70 
   71 my %FORM = ReadForm();
   72 my $action = $FORM{"a"};
   73 
   74 if ($action) {
   75     if (not ($action =~ m/^[lLrRud]$/)) {
   76         die "action value not allowed!";
   77     }
   78     # now send the $action value via IPC to astrocam daemon
   79     msgsnd(msgget($CONFIG{"ipckey"}, 0), pack("l! a*", 1, $action), 0);
   80 }
   81 
   82 ######################################################################################
   83 # print website content
   84 ######################################################################################
   85 
   86 print header;
   87 print '<html>
   88 <head>
   89     <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
   90     <link rel="stylesheet" type="text/css" href="'.$CONFIG{"contenturl"}.'/'.$CONFIG{"design"}.'.css" title="prim">
   91     <title>AstroCam Webinterface</title>
   92 </head>
   93 <body>
   94 <table align="center">
   95 <tr>
   96     <td colspan="2">
   97         <img src="'.$CONFIG{"contenturl"}.'/spacer.gif" height="20px" width="1px" alt=".">
   98     </td>
   99 </tr>
  100 <tr>
  101     <td align="center" valign="top" class="menu">
  102         <img src="'.$CONFIG{"contenturl"}.'/spacer.gif" alt="." width="80px" height="1px"><br>
  103         <b>[<a href="?a=l">&lt;</a>]</b>
  104         <b>[<a href="?a=r">&gt;</a>]</b>
  105         <br>
  106         <b>[<a href="?a=L">&lt;&lt;</a>]</b>
  107         <b>[<a href="?a=R">&gt;&gt;</a>]</b>
  108         <p>
  109         <b>[<a href="?a=u">up</a>]</b><br>
  110         <b>[<a href="?a=d">down</a>]</b>        
  111     </td>
  112     <td align="center" valign="center" class="pic"
  113          width="'.$CONFIG{"imagesize-x"}.'" height="'.$CONFIG{"imagesize-y"}.'">
  114         <iframe border="0" width="'.$CONFIG{"imagesize-x"}.'" height="'.$CONFIG{"imagesize-y"}.'"
  115            src="pic.pl?refreshtime='.$CONFIG{"refreshtime"}.'&picfile='.$CONFIG{"picfile"}.'"
  116            scrolling="no" marginwidth="0" marginheight="0">Your browser does not support iframes!
  117         </iframe>
  118     </td>
  119 </tr>
  120 <tr>
  121     <td align="right" colspan="2" class="menu">
  122         <div style="font-size:9pt">
  123             <b>astrocam webinterface</b>
  124             [<a href="http://www.wendzel.de/?sub=softw&ssub=acam">info</a>]
  125         </div>
  126     </td>
  127 </tr>
  128 </table>
  129 </body>
  130 </html>';
  131