Handle hostnames with upper-case letters
[webmin.git] / Webmin-API-1.0 / API.pm
1 package Webmin::API;
2
3 require 5.005_62;
4
5 require Exporter;
6
7 our @ISA = qw(Exporter);
8
9 # Items to export into callers namespace by default. Note: do not export
10 # names by default without a very good reason. Use EXPORT_OK instead.
11 # Do not simply export all your public functions/methods/constants.
12
13 our @EXPORT = (
14         '$config_directory',
15         '$var_directory',
16         '$remote_error_handler',
17         '%month_to_number_map',
18         '%number_to_month_map',
19         '$config_file',
20         '%gconfig',
21         '$null_file',
22         '$path_separator',
23         '$root_directory',
24         '$module_name',
25         '@root_directories',
26         '$base_remote_user',
27         '$remote_user',
28         '$module_config_directory',
29         '$module_config_file',
30         '%config',
31         '$current_theme',
32         '$theme_root_directory',
33         '%tconfig',
34         '$tb',
35         '$cb',
36         '$scriptname',
37         '$webmin_logfile',
38         '$current_lang',
39         '$current_lang_info',
40         '@lang_order_list',
41         '%text',
42         '%module_info',
43         '$module_root_directory',
44         '$default_lang',
45         );
46
47 our $VERSION = '1.0';
48
49 # Find old symbols by Webmin import
50 my %oldsyms = %Webmin::API::;
51
52 # Preloaded methods go here.
53 $main::no_acl_check++;
54 $ENV{'WEBMIN_CONFIG'} ||= "/etc/webmin";
55 $ENV{'WEBMIN_VAR'} ||= "/var/webmin";
56 open(MINISERV, $ENV{'WEBMIN_CONFIG'}."/miniserv.conf") ||
57         die "Could not open Webmin config file ".
58             $ENV{'WEBMIN_CONFIG'}."/miniserv.conf : $!";
59 my $webmin_root;
60 while(<MINISERV>) {
61         s/\r|\n//g;
62         if (/^root=(.*)/) {
63                 $webmin_root = $1;
64                 }
65         }
66 close(MINISERV);
67 $webmin_root || die "Could not find Webmin root directory";
68 chdir($webmin_root);
69 if ($0 =~ /\/([^\/]+)$/) {
70         $0 = $webmin_root."/".$1;
71         }
72 else {
73         $0 = $webmin_root."/api.pl";    # Fake name
74         }
75 require './web-lib.pl';
76 &init_config();
77
78 # Export core symbols
79 foreach my $lib ("$webmin_root/web-lib.pl",
80                  "$webmin_root/web-lib-funcs.pl") {
81         open(WEBLIB, $lib);
82         while(<WEBLIB>) {
83                 if (/^sub\s+([a-z0-9\_]+)/i) {
84                         push(@EXPORT, $1);
85                         }
86                 }
87         close(WEBLIB);
88         }
89 our @EXPORT_OK = ( @EXPORT );
90
91 1;
92 __END__
93
94 =head1 NAME
95
96 Webmin::API - Perl module to make calling of Webmin functions from regular
97               command-line Perl scripts easier.
98
99 =head1 SYNOPSIS
100
101   use Webmin::API;
102   @pids = &find_byname("httpd");
103   foreign_require("cron", "cron-lib.pl");
104   @jobs = &cron::list_cron_jobs();
105
106 =head1 DESCRIPTION
107
108 This module just provides a convenient way to call Webmin API functions
109 from a script that is not run as a Webmin CGI, without having to include a 
110 bunch of boilerplate initialization code at the top. It's main job is to export
111 all API functions into the namespace of the caller, and to setup the Webmin
112 environment.
113
114 =head2 EXPORT
115
116 All core Webmin API functions, like find_byname, foreign_config and so on.
117
118 =head1 AUTHOR
119
120 Jamie Cameron, jcameron@webmin.com
121
122 =head1 SEE ALSO
123
124 perl(1).
125
126 =cut
127