Get rid of local
[webmin.git] / web-lib.pl
1 =head1 web-lib.pl
2
3 This file must be included by all Webmin CGI scripts, either directly or via
4 another module-specific .pl file. For example :
5
6  do '../web-lib.pl';
7  init_config();
8  do '../ui-lib.pl';
9  ui_print_header(undef, 'My Module', '');
10
11 This file in turn includes web-lib-funcs.pl, which is where the majority of
12 the Webmin API functions are defined.
13
14 =cut
15
16 # Configuration and spool directories
17 if (!defined($ENV{'WEBMIN_CONFIG'})) {
18         die "WEBMIN_CONFIG not set";
19         }
20 $config_directory = $ENV{'WEBMIN_CONFIG'};
21 if (!defined($ENV{'WEBMIN_VAR'})) {
22         open(VARPATH, "$config_directory/var-path");
23         chop($var_directory = <VARPATH>);
24         close(VARPATH);
25         }
26 else {
27         $var_directory = $ENV{'WEBMIN_VAR'};
28         }
29
30 if ($ENV{'SESSION_ID'}) {
31         # Hide this variable from called programs, but keep it for internal use
32         $main::session_id = $ENV{'SESSION_ID'};
33         delete($ENV{'SESSION_ID'});
34         }
35 if ($ENV{'REMOTE_PASS'}) {
36         # Hide the password too
37         $main::remote_pass = $ENV{'REMOTE_PASS'};
38         delete($ENV{'REMOTE_PASS'});
39         }
40
41 if ($> == 0 && $< != 0 && !$ENV{'FOREIGN_MODULE_NAME'}) {
42         # Looks like we are running setuid, but the real UID hasn't been set.
43         # Do so now, so that executed programs don't get confused
44         $( = $);
45         $< = $>;
46         }
47
48 # On Windows, always do IO in binary mode
49 #binmode(STDIN);
50 #binmode(STDOUT);
51
52 $remote_error_handler = "error";
53 @INC = &unique(@INC, ".");
54 %month_to_number_map = ( 'jan' => 0, 'feb' => 1, 'mar' => 2, 'apr' => 3,
55                          'may' => 4, 'jun' => 5, 'jul' => 6, 'aug' => 7,
56                          'sep' => 8, 'oct' => 9, 'nov' =>10, 'dec' =>11 );
57 %number_to_month_map = reverse(%month_to_number_map);
58 $main::initial_process_id ||= $$;
59 $main::http_cache_directory = $ENV{'WEBMIN_VAR'}."/cache";
60 $main::default_debug_log_size = 10*1024*1024;
61 $main::default_debug_log_file = $ENV{'WEBMIN_VAR'}."/webmin.debug";
62
63 $webmin_feedback_address = "feedback\@webmin.com";
64 $default_lang = "en";
65 $default_charset = "iso-8859-1";
66
67 =head2 unique(string, ...)
68
69 Returns the unique elements of some array, passed as its parameters.
70
71 =cut
72 sub unique
73 {
74 my (%found, @rv);
75 foreach my $e (@_) {
76         if (!$found{$e}++) { push(@rv, $e); }
77         }
78 return @rv;
79 }
80
81 if (!$done_web_lib_funcs) {
82         my $script = -r '../web-lib-funcs.pl' ? '../web-lib-funcs.pl'
83                                                  : 'web-lib-funcs.pl';
84         do $script;
85         }
86
87 1;
88