Started work on UI for debug mode
[webmin.git] / web-lib.pl
1 # web-lib.pl
2 # Common functions and definitions for web admin programs
3
4 # Configuration and spool directories
5 if (!defined($ENV{'WEBMIN_CONFIG'})) {
6         die "WEBMIN_CONFIG not set";
7         }
8 $config_directory = $ENV{'WEBMIN_CONFIG'};
9 if (!defined($ENV{'WEBMIN_VAR'})) {
10         open(VARPATH, "$config_directory/var-path");
11         chop($var_directory = <VARPATH>);
12         close(VARPATH);
13         }
14 else {
15         $var_directory = $ENV{'WEBMIN_VAR'};
16         }
17
18 if ($ENV{'SESSION_ID'}) {
19         # Hide this variable from called programs, but keep it for internal use
20         $main::session_id = $ENV{'SESSION_ID'};
21         delete($ENV{'SESSION_ID'});
22         }
23 if ($ENV{'REMOTE_PASS'}) {
24         # Hide the password too
25         $main::remote_pass = $ENV{'REMOTE_PASS'};
26         delete($ENV{'REMOTE_PASS'});
27         }
28
29 if ($> == 0 && $< != 0 && !$ENV{'FOREIGN_MODULE_NAME'}) {
30         # Looks like we are running setuid, but the real UID hasn't been set.
31         # Do so now, so that executed programs don't get confused
32         $( = $);
33         $< = $>;
34         }
35
36 # On Windows, always do IO in binary mode
37 #binmode(STDIN);
38 #binmode(STDOUT);
39
40 $remote_error_handler = "error";
41 @INC = &unique(@INC, ".");
42 %month_to_number_map = ( 'jan' => 0, 'feb' => 1, 'mar' => 2, 'apr' => 3,
43                          'may' => 4, 'jun' => 5, 'jul' => 6, 'aug' => 7,
44                          'sep' => 8, 'oct' => 9, 'nov' =>10, 'dec' =>11 );
45 %number_to_month_map = reverse(%month_to_number_map);
46 $main::initial_process_id ||= $$;
47 $main::http_cache_directory = $ENV{'WEBMIN_VAR'}."/cache";
48 $main::default_debug_log_size = 10*1024*1024;
49 $main::default_debug_log_file = $ENV{'WEBMIN_VAR'}."/webmin.debug";
50
51 # unique
52 # Returns the unique elements of some array
53 sub unique
54 {
55 local(%found, @rv, $e);
56 foreach $e (@_) {
57         if (!$found{$e}++) { push(@rv, $e); }
58         }
59 return @rv;
60 }
61
62 if (!$done_web_lib_funcs) {
63         local $script = -r '../web-lib-funcs.pl' ? '../web-lib-funcs.pl'
64                                                  : 'web-lib-funcs.pl';
65         do $script;
66         }
67
68 1;
69