"Fossies" - the Fresh Open Source Software Archive

Member "absence-v2.1/cgi-bin/AbsenceConfig.pm" (20 Oct 2013, 20863 Bytes) of package /linux/www/web-absence-2.1.tar.gz:


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 "AbsenceConfig.pm" see the Fossies "Dox" file reference documentation.

    1 #=======================================================================
    2 # this is where everything that is site-specific gets defined
    3 # $Id: AbsenceConfig.pm 111 2013-10-20 17:57:24Z urban $
    4 # copyright Robert Urban
    5 #=======================================================================
    6 
    7 #======================================================================
    8 #    This file is part of Absence.
    9 #
   10 #    Absence is free software: you can redistribute it and/or modify
   11 #    it under the terms of the GNU General Public License as published by
   12 #    the Free Software Foundation, either version 3 of the License, or
   13 #    (at your option) any later version.
   14 #
   15 #    Absence is distributed in the hope that it will be useful,
   16 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
   17 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18 #    GNU General Public License for more details.
   19 #
   20 #    You should have received a copy of the GNU General Public License
   21 #    along with Absence.  If not, see <http://www.gnu.org/licenses/>.
   22 #======================================================================
   23 
   24 package AbsenceConfig;
   25 
   26 use FileHandle;
   27 
   28 my $VERSION = '2.0.1';
   29 my $DEBUG       = 0;
   30 
   31 #-------------------------------------------------------------
   32 # INSTANCES
   33 # (are not currently supported, tested, or working)
   34 #
   35 # If you want multiple instances of absence, you MUST add
   36 # an instance-name and corresponding path to the config-file
   37 # below.  Do not include the config-file in the path.  The
   38 # config-file is ALWAYS called "absence.conf".
   39 #
   40 # Additionally you must edit your top-html file (the one which
   41 # defines the frames) and add "?instance=<your-instance>" to
   42 # the end of both frame target-URLs.  For example:
   43 #
   44 #   SRC="/cgi-bin/absence-control.pl?instance=foo"
   45 #   SRC="/cgi-bin/absence.pl?instance=foo"
   46 #
   47 # for an instance you call "foo"
   48 #-------------------------------------------------------------
   49 my %INSTANCES = (
   50     # example
   51     #2  => '/home/httpd/urban/www.spielwiese.de/html/absence2',
   52 );
   53 
   54 #-------------------------------------------------------------
   55 # DATA and CGI directories
   56 # ACHTUNG.  You will probably want to set these
   57 #-------------------------------------------------------------
   58 
   59 # the following variables are declared for convenience
   60 
   61 #-------------------------------------------------------------
   62 # this is the relative path to the data-dir.
   63 #-------------------------------------------------------------
   64 my $data_dir_rel    = '/absence';                   # as used in a URL
   65 
   66 #-------------------------------------------------------------
   67 # This is the absolute path to the data directory, for the
   68 # use of a perl script looking for data-files.
   69 #
   70 # users of windoze/IIS will probably need to shove some
   71 # absolute path into "$data_dir_abs". For example:
   72 #   $data_dir_abs = "c:/inetpub/wwwroot$data_dir_rel";
   73 #-------------------------------------------------------------
   74 my $data_dir_abs    = "$ENV{DOCUMENT_ROOT}$data_dir_rel";   # as used by Perl
   75 
   76 #-------------------------------------------------------------
   77 # the relative path to the cgi-bin, i.e., what is needed to
   78 # create a URL for a cgi-script.
   79 #-------------------------------------------------------------
   80 my $cgi_dir_rel = "/cgi-bin";
   81 my $cgi_dir_abs = "$ENV{DOCUMENT_ROOT}/..$cgi_dir_rel";
   82 
   83 my $js_dir_abs  = "$data_dir_abs/JavaScript";
   84 my $js_dir_rel  = "$data_dir_rel/JavaScript";
   85 
   86 my %VARS = (
   87     data_dir_rel    => $data_dir_rel,
   88     data_dir_abs    => $data_dir_abs,
   89     cgi_dir_rel     => $cgi_dir_rel,
   90     cgi_dir_abs     => $cgi_dir_abs,
   91     js_dir_abs      => $js_dir_abs,
   92     js_dir_rel      => $js_dir_rel,
   93 
   94     #-------------------------------------------------------------
   95     # where are the images kept.  Probably OK as is.
   96     #-------------------------------------------------------------
   97     image_dir_rel   => "$data_dir_rel/img",
   98     image_dir_abs   => "$data_dir_abs/img",
   99 
  100     #-------------------------------------------------------------
  101     # access to database
  102     #-------------------------------------------------------------
  103     database_name   => 'absence',
  104     database_host   => 'localhost',
  105     database_port   => undef,
  106     database_user   => 'absence',
  107     database_pass   => 'absence',
  108 
  109     #-------------------------------------------------------------
  110     # where is log file.  Probably OK as is.
  111     #-------------------------------------------------------------
  112     log_file        => "$data_dir_abs/log",
  113 
  114     #-------------------------------------------------------------
  115     # where to put backup copies of things
  116     #-------------------------------------------------------------
  117     backup_dir      => "$data_dir_abs/backup",
  118 
  119     #-------------------------------------------------------------
  120     # marking current month and day
  121     #-------------------------------------------------------------
  122     mark_curr_month => 'yes',
  123     mark_curr_day   => 'yes',
  124     curr_day_style  => 'box',   # can be "fill" or "box"
  125     curr_day_begin_row  => 2,
  126     auto_refresh    => 'yes',
  127 
  128     #-------------------------------------------------------------
  129     # paths to various CGI-scripts
  130     #-------------------------------------------------------------
  131     main_script     => "$cgi_dir_rel/absence.pl",
  132     manage_script   => "$cgi_dir_rel/absence-manage.pl",
  133     control_script  => "$cgi_dir_rel/absence-control.pl",
  134     js_acl_script   => "$js_dir_rel/acl.js",
  135     nph_lo_script   => "$cgi_dir_rel/nph-absence-logout.pl",
  136 
  137     #-------------------------------------------------------------
  138     # this is the URL to the html page containing the frameset.
  139     # If your main page is called "index.html" and you are using
  140     # Apache, this can simply be set to "$data_dir_rel".
  141     #-------------------------------------------------------------
  142     top_page        => "$data_dir_rel/index.html",
  143 
  144     #-------------------------------------------------------------
  145     # legend-style.  can either be "constant:<num>" or "fit"
  146     # if set to constant, all legend-labels will be <num> pixels wide
  147     # if "fit" labels will be fit to text
  148     #-------------------------------------------------------------
  149 
  150     #legend_style   => 'constant:60',
  151     legend_style    => 'fit',
  152 
  153     #-------------------------------------------------------------
  154     # select the image-type, png, jpg, or gif.  'gif' is only
  155     # supported on ancient versions of gd.  'png' is probably
  156     # the best choice if you have it.
  157     #-------------------------------------------------------------
  158     image_type      => 'png',   # one of 'png', 'jpg', or 'gif'
  159 
  160     #-------------------------------------------------------------
  161     # map_type determines whether client or server-side image-maps
  162     # are used.  The value 'client' causes a map to be generated
  163     # and integrated into the main web-page for each month.  This
  164     # can cause thousands of map-areas to be defined, depending
  165     # on how many months are displayed and how many people are
  166     # in a group.
  167     # The value 'server' causes the "ismap" option to be added to
  168     # the month-image, which additionally is a hyperlink. This
  169     # results in the coordinates of the click being passed to
  170     # the server for processing.
  171     # The advantage of the client-side option is tooltips are used
  172     # to display the contents of a reservation.
  173     # CAUTION: "server" maps *cannot* be used when multiple
  174     # reservations per day are configured.
  175     # In fact, "server" maps are not well tested, so I recommend
  176     # sticking to "client" maps. Bandwidth is free, right?
  177     #
  178     # legal values: "client" or "server"
  179     #-------------------------------------------------------------
  180     map_type        => 'client',
  181 
  182     #-------------------------------------------------------------
  183     # draw separation-lines between day-columns, "yes" or "no"
  184     #-------------------------------------------------------------
  185     vertical_grid   => 'yes',
  186 
  187     #-------------------------------------------------------------
  188     # multiple reservations per day
  189     #-------------------------------------------------------------
  190     multi_res       => 'yes',
  191     max_multi       => 3,
  192     variable_height => 'yes',
  193     min_height      => 1,
  194 
  195     #-------------------------------------------------------------
  196     # holiday configuration
  197     # ---------------------
  198     # "holiday_label" is the label used in the legend to indicate
  199     # holidays (bank-holidays in brittain).
  200     # "holiday_mark" determines how a holiday is indicated on
  201     # the month-image.  "small" means the square underneath
  202     # the day-number is colored using the color indicated by
  203     # "mi_bankholiday".  "large" means the whole column is
  204     # colored, starting at the day-number and going to the bottom
  205     # of the month-image.
  206     #
  207     # "holiday_scheme" can have two values, "basic", and "advanced"
  208     # basic means the old (v1.8) holiday style is used.  all holidays
  209     # in the DB will be displayed in the header, i.e., the country
  210     # and region are ignored.
  211     # "advanced" means the holidays must be associated with a country
  212     # and/or a region. "header_holiday_country" and "header_holiday_region"
  213     # determine which holidays are displayed in the header
  214     #-------------------------------------------------------------
  215     holiday_label   => 'Bank Holiday',
  216     holiday_scheme  => 'advanced',
  217 
  218     # the following only applies when "holiday_scheme" is "basic"
  219     holiday_mark    => 'large',     # can be 'large' or 'small'
  220 
  221     # the following are only relevant if holiday_scheme is 'advanced'
  222     show_holidays_in_header => 'yes',
  223     header_holiday_country  => 'de',    # ISO country-code
  224     header_holiday_region   => 'Bayern',
  225 
  226     #-------------------------------------------------------------
  227     # SKIP stuff
  228     #
  229     # if "skip_we_hol" is set to "yes", an absence including
  230     # weekend days and holidays will be displayed as a sequence
  231     # of individual blocks that only cover the non-holiday
  232     # weekdays.  That is, weekends and holidays are skipped.
  233     # "skip_mark_skipped" causes a frame to be drawn in the
  234     # day-boxes of all skipped days.  The color used is the same
  235     # as for the blocks.
  236     # To use skipping, you must also check the corresponding box
  237     # for a particular reservation-type using the managment web page.
  238     #-------------------------------------------------------------
  239     skip_we_hol     => 'yes',
  240     skip_mark_skipped   => 'yes',
  241 
  242     #-------------------------------------------------------------
  243     # this determines whether a user can be a member of multiple
  244     # groups, or only a single one.  values: "single", "multiple"
  245     #-------------------------------------------------------------
  246     group_policy    => 'multiple',  # 'single' or 'multiple'
  247 
  248     #-------------------------------------------------------------
  249     # various authentication/authorization parameters
  250     #
  251     # "partial_auth_hack" deserves perhaps some explanation.
  252     # It is a mechanism for restricting administrative access (in
  253     # a trivial and easily defeated manner) to certain admin-operations.
  254     # Currently they include all reservation-type operations.
  255     # partial_auth_hack exists simply to deter non-hostile
  256     # reservation-type changes...
  257     # if you want any real protection from hostile users, you must
  258     # turn on real authentication/authorization
  259     #-------------------------------------------------------------
  260     authentication  => 'yes',       # 'yes' or 'no'
  261     auth_type       => 'simple',    # currently can be "http" or "simple"
  262     secret          => 'qwerty',    # a random string
  263     credential_src  => 'absence',   # 'absence' or 'htaccess'
  264     session_timeout => '30m',       # use suffixs m,h,d,w for units, 0 for none
  265     manage_password => 'yes',       # 'yes' or 'no'
  266     pw_hash_format  => 'md5',       # "cleartext" or "md5"
  267     partial_auth_hack           => 0,
  268     partial_auth_hack_pw        => 'secret',
  269 
  270     # the following are for http authentication
  271     htaccess_path   => "$data_dir_abs/password.file",
  272     auth_realm      => 'Absence',   # for 'http' authentication
  273 
  274     #-------------------------------------------------------------
  275     # access control defaults
  276     # The format for "rules" is "<permission>:<object>"
  277     # <permission> can be "w", or "r" for "write", or "read" respectively.
  278     # <object> can only be "self" for people,
  279     # or "self", "all" groups.
  280     # for people, "self" refers to the object associated with the
  281     # authenticated user. Note that "r:self" for either people or
  282     # group defaults makes no sense.
  283     #
  284     # for groups, "self" refers to any group which has the person
  285     # as a member who corresponds to the authenticate user.
  286     # To give all users all rights, set group defaults to "a:all";
  287     # The group rule "r:self" is implicit and cannot be disabled.
  288     # Some examples:
  289     #
  290     #   # all users should be able to modify any people in groups
  291     #   # to which they belong:
  292     #   pacl_default    => undef,
  293     #   gacl_default    => 'w:self',
  294     #
  295     #   # users should only be able to modify their own objects:
  296     #   pacl_default    => 'w:self',
  297     #   gacl_default    => undef,
  298     #
  299     #   # users should only be able to read groups to which they belong
  300     #   pacl_default    => undef,
  301     #   gacl_default    => undef,
  302     #-------------------------------------------------------------
  303     pacl_default    => undef,
  304     gacl_default    => 'w:self',
  305 
  306     #-------------------------------------------------------------
  307     # if the managed objects represent people, there must be
  308     # some association between the managed objects and authenticated
  309     # users.
  310     #-------------------------------------------------------------
  311     objects_are_people  => 'yes',
  312 
  313     #-------------------------------------------------------------
  314     # set the following if you want alternating background colors
  315     # for people rows.  The first color used is "mi_altbg",
  316     # the second is "mi_background"
  317     #-------------------------------------------------------------
  318     alternate_colors    => 'no',
  319 
  320     #-------------------------------------------------------------
  321     # %% COLORS %%
  322     #-------------------------------------------------------------
  323 
  324     #-------------------------------------------------------------
  325     # MONTH-IMAGE colors
  326     #
  327     # color-names that begin with "mi_" belong to "month-images".
  328     # colors may be specified in four formats:
  329     #
  330     #  1: '#rrggbb'
  331     #  2: '0xrrggbb'
  332     #  3: 'rr gg bb'
  333     #  4: '0xrr 0xgg 0xbb'
  334     #
  335     # where 'rr', 'gg', and 'bb' are the red, green, and blue
  336     # components, respectively.  In forms 1 and 2, the components
  337     # *must* be hexadecimal numbers.  In forms 3 and 4, they *may*
  338     # be decimal or hexadecimal.  If hex, each component must
  339     # be preceeded by "0x"
  340     #-------------------------------------------------------------
  341     mi_background   => '#b0a0b0',   # normal background
  342     mi_altbg        => '#c0b0c0',   # 2nd color for alternating bg
  343     mi_weekend      => '#908090',   # weekend background
  344     mi_bankholiday  => '#a020f0',   # guess?
  345     mi_text_dark    => '#000000',   # color for text
  346     mi_text_light   => '#ffffff',   # not currently used
  347     #mi_grid        => '#808080',   # grid color (absence blocks jump out)
  348     mi_grid         => '#404040',   # grid color
  349     mi_cwbox        => '#aa80aa',   # the calendar-week boxes
  350     mi_padding      => '#605060',   # to pad months < 31 days
  351     mi_res_border   => '#000000',   # reservation border when multi_res enabled
  352 
  353     #-------------------------------------------------------------
  354     # colors used to highlight current month and/or day
  355     #-------------------------------------------------------------
  356     mi_curr_day     => '#ffffff',   # frame around current day
  357     mi_cm_bg        => '#c0b0c0',
  358     mi_cm_altbg     => '#d0c0d0',
  359     mi_cm_weekend   => '#a090a0',
  360     mi_cm_grid      => '#808080',   # grid color
  361     mi_cm_monthlab  => '#2020ff',
  362     mi_cm_mi_frame  => '#ffffff',   # the frame around the image
  363     mi_cm_cwbox     => '#ba90ba',
  364 
  365     #-------------------------------------------------------------
  366     # web-page colors
  367     # These are specified according to HTML rules: either
  368     # "#rrggbb" (each component  a 2-digit hex values, as above),
  369     # or a color-name can be specified.
  370     #-------------------------------------------------------------
  371     wp_main         => '#acacac',       # bg col for display frame
  372     wp_control      => '#ff9081',       # bg col for control frame
  373     wp_nopriv       => 'teal',          # bg col for auth errors
  374     wp_manage       => '#aaa0b8',       # bg col for management
  375     wp_aflabel      => 'papayawhip',    # bg col for labels in absence form
  376     wp_afbg         => '#acacac',       # bg col for absence form
  377 );
  378 # %%END_MARKER%%
  379 
  380 if (exists($ENV{INSTANCE_NAME})) {
  381     # an instance has been specified
  382     my $inst = $ENV{INSTANCE_NAME};
  383     print "** instance specified: [$inst] **<BR>\n";
  384     if (exists($INSTANCES{$inst})) {
  385         my $cf = "$INSTANCES{$inst}/absence.conf";
  386         if (! -e $cf) {
  387             die "no configfile found for instance [$inst] ($cf)\n";
  388         }
  389         parse($cf);
  390     } else {
  391         die "instance [$inst] not defined\n";
  392     }
  393 }
  394 
  395 sub fetch
  396 {
  397     my $val = shift;
  398 
  399     if (exists($VARS{$val})) {
  400         return undef unless(defined($VARS{$val}));
  401         if ($VARS{$val} =~ /^(yes|true)$/i) { return 1; }
  402         if ($VARS{$val} =~ /^(no|false)$/i) { return 0; }
  403         return $VARS{$val};
  404     }
  405 
  406     return undef;
  407 }
  408 
  409 sub parse
  410 {
  411     my ($file) = @_;
  412 
  413     my $fh = FileHandle->new($file);
  414     defined($fh) || die "open [$file] for reading";
  415     while(<$fh>) {
  416         $DEBUG && print "CONF> $_";
  417         if (/^\s*$/) { next; }      # skip blank lines
  418         if (/^\s*#$/) { next; }     # skip comment lines
  419         if (/^\s*(\S+)\s*=\s*(\S+)/) {
  420             $varname = $1;
  421             $value = $2;
  422             $value =~ s/\${([^}]+)}/expand($1)/ge;
  423             $DEBUG && print "  setting [$varname] = [$value]\n";
  424             $VARS{$varname} = $value;
  425         }
  426     }
  427     $fh->close;
  428 }
  429 
  430 sub expand
  431 {
  432     my $vname = shift;
  433 
  434     if (exists($VARS{$vname})) {
  435         return $VARS{$vname};
  436     } else {
  437         die "error in config-file\n";
  438     }
  439 }
  440 
  441 sub dumpVars
  442 {
  443     foreach my $var (sort keys(%VARS)) {
  444         printf("%-18s %s\n", $var, $VARS{$var});
  445     }
  446 }
  447 
  448 1;
  449 
  450 __END__
  451 
  452 =head1 NAME
  453 
  454 AbsenceConfig.pm - handles configuration for web-absence
  455 
  456 =head1 SYNOPSIS
  457 
  458   use AbsenceConfig;
  459 
  460   AbsenceConfig::fetch('config-param');
  461 
  462 =head1 DESCRIPTION
  463 
  464 C<AbsenceConfig.pm> handles the configuration information that
  465 belongs to a particular instance.  The module itself defines
  466 'default' values for all configuration parameters.  If no
  467 instance is explicitly configured, these 'default' values
  468 are used.  If an instance is configured, the instance-specific
  469 parameter has precedence, then the default value.
  470 
  471 Currently understood parameters are:
  472 
  473 =over 4
  474 
  475 =item data_dir_rel
  476 
  477 The relative directory path where data-files reside
  478 (C<absence.db>, C<month_mod_times.db>, C<holiday.db>, C<absence-types.db>).
  479 That is, the path as used in HTML source.
  480 
  481 =item data_dir_abs
  482 
  483 The absolute directory path where data-files reside.
  484 That is, the path as used in CGI scripts.
  485 
  486 =item cgi_dir_rel
  487 
  488 The relative directory path where CGI-scripts and modules reside.
  489 
  490 =item image_dir_rel
  491 
  492 The relative directory path where the month-images and legend reside.
  493 
  494 =item image_dir_abs
  495 
  496 The absolute directory path where the month-images and legend reside.
  497 
  498 =item database_file
  499 
  500 The absolute path to the database file.
  501 
  502 =item modtime_db_file
  503 
  504 The absolute path to the modification time file.  This is used to hold
  505 the modification times for month-images.  The modification time allows
  506 URLs for the month-images to be constructed such that the browser
  507 automatically reloads a month-image when it has been modified.
  508 
  509 =item holiday_db_file
  510 
  511 The absolute path to the holiday database file.
  512 
  513 =item log_file
  514 
  515 The absolute path to the log file.
  516 
  517 =item type_file
  518 
  519 The absolute path to the absence-type file.  This is where the various
  520 kinds of absences can be defined along with a color.
  521 
  522 =item main_script
  523 
  524 The relative path to C<absence.pl>.
  525 
  526 =item manage_script
  527 
  528 The relative path to C<absence-manage.pl>.
  529 
  530 =item control_script
  531 
  532 The relative path to C<absence-control.pl>.
  533 
  534 =item top_page
  535 
  536 The relative path to the startinge-page.  This is usually C<index.html>
  537 on UNIX systems.  If you are using Apache, you can simply set this
  538 to C<$data_dir_rel>.
  539 
  540 =item legend_style
  541 
  542 The method used to arrive at the width for the legend boxes.  There are
  543 two possibilities, C<fit> and C<contant:N> (where N is the width in pixels).
  544 C<fit> uses the text to determine the width of the box. C<contant:N>
  545 simply causes all boxes to have a width of N pixels.
  546 
  547 =item backup_copies
  548 
  549 Before the database is modified, a backup copy named C<absence.db.savN>
  550 is made, where N is incremented each time.  This determines how many copies
  551 are kept.
  552 
  553 =item image_type
  554 
  555 The format of the images used (legend and month-images).  The choices are
  556 C<png>, C<jpg>, and C<gif>.  The version of GD that you installed must
  557 support the format you choose here.
  558 
  559 =item map_type
  560 
  561 This determines what method to use for manipulating absences.  There
  562 are two choices, C<server> (server-side image maps) and C<client>
  563 (client-side image maps).  Client-side image maps allow the display
  564 of so-called "tool-tips", but the the HTML generated is very large.
  565 Server-side image maps result in much smaller HTML, but you must
  566 click on absences and holidays to get more information about them.
  567 Server-side image maps won't work on windoze/IIS.
  568 
  569 =item cookie_domain
  570 
  571 The domain information to be used when setting cookies.
  572 
  573 =item holiday_label
  574 
  575 The label that should be used to mark (bank) holidays, as opposed
  576 to vacation (as understood in america :).
  577 
  578 =item group_policy
  579 
  580 This determines whether a user can be a member of multiple groups,
  581 or only of a single group.  Values are C<single> and C<multiple>.
  582 
  583 =back
  584 
  585 =head1 INSTANCES
  586 
  587 absence now supports multiple "instances".  That is, completely
  588 independent databases which all use the same Perl scripts and
  589 modules.
  590 
  591 =cut