4 # These are functions specific to the hostconfig file
7 # written by Michael A. Peters <mpeters@mac.com>
9 sub hostconfig_settings
13 # This subroutine reads the hostconfig file into an array
14 # and outputs a second array containing matched pairs of
15 # the startup action and what the startup action is set to
18 local($conffile, @hconf);
19 $conffile = "$config{'hostconfig'}";
20 open(LOCAL, $conffile);
23 @conf = grep /^\w/, @conf;
25 push @hconf, [ split /=/ ];
34 # Gathers information about an action item that is set in the hostconfig
37 # It takes one arguement- the type of info wanted (description or
40 # It outputs a hash where the action item is the key, and what was
41 # requested is the value.
43 # Thus, we can use the hash to find out what startup script is
44 # associated with the MAILSERVER action or what description goes with
47 # Originally I wanted to output an array with two elements where the
48 # first was one type of hash, and the second element was the second type # of hash, but I couldn't get that to work (array of hashes)
51 local ($hash_type, @startupdir, $plist, @action_to_description, @action_to_script, @sec_action_to_description, @sec_action_to_script, $element, @ls, @script, $a, $action_name, @param, $description);
55 @startupdir = split (/:/, $config{'startup_dirs'});
56 $plist = $config{'plist'};
57 @action_to_description = ();
58 @action_to_script = ();
59 @sec_action_to_description = ();
60 @sec_action_to_script = ();
62 foreach $element (@startupdir) {
63 if ( -d "$element" ) {
64 opendir (LOCAL, $element);
69 #we need BOTH an executable and a plist- or its useless.
70 #executable script has to be in a directory of the same
72 if (( -x "$element/$a/$a") && ( -e "$element/$a/$plist")) {
73 #Get the startup action associated with script
74 open (SCRIPT, "$element/$a/$a");
77 @script = grep /:=/, @script;
78 # we are looking at a line in the script that looks like:
79 #if [ "${WEBMIN:=-NO-}" = "-YES-" ]; then
80 # and we want to extract the WEBMIN part as the action_name
81 if ( $script[0] =~ /\$\{(.*):/ ) {
88 open (PLIST, "$element/$a/$plist");
91 @param = grep /Description[ \t]*=/, @param;
92 # we are looking at a line in the plist that looks like:
93 #\t\tDescription\t\t= "Webmin System Administration Daemon";
94 # and we want to extract the contents of the quotes
95 if ( $param[0] =~ /\"(.*)\"/ ) {
101 # make the primary hash
102 if ( $action_name ne "" ) {
103 $action_to_description{$action_name} = "$description";
104 $action_to_script{$action_name} = "$element/$a/$a";
106 # make the secondary hash
108 if ( $script[0] ne "" ) {
109 foreach $secondary (@script) {
110 if ( $secondary =~ /\$\{(.*):/ ) {
112 $sec_action_to_description{$action_name} = "$description";
113 $sec_action_to_script{$action_name} = "$element/$a/$a";
117 } #ends the: if (( -x "$element/$a/$a") && ( -e "$element/$a/$plist")
118 } #ends the: foreach $a (@ls)
119 } #ends the: if ( -d "$element" )
120 } #ends the: foreach $element (@startupdir)
122 # now we have two sets of each hash
123 # elements in sec_blah that are not already in blah
124 # need to be integrated into blah
126 # We have to do this because some scripts use several action_name just
127 # for that particular script, and sometimes what one action is set to is
128 # used in how another script acts even though that is not the action for # that script.
130 # Thus, if a action_item is in the secondary array and is not in the
131 # primary, we know that it is a case where more than one action belongs
132 # to a script- but if its in both, the action probably belongs to the
133 # script in the primary.
135 while (($key,$value) = each %action_to_description) {
136 $sec_action_to_description{$key} = "$value";
138 while (($key,$value) = each %action_to_script) {
139 $sec_action_to_script{$key} = "$value";
142 if ( $hash_type eq "description" ) {
143 return %sec_action_to_description;
145 elsif ( $hash_type eq "startscript" ) {
146 return %sec_action_to_script;
155 # This sub writes a table row in html for index.cgi.
156 # It takes the startup action, setting, and provides
157 # as its arguements- and outputs a string.
160 local($ahref, $setting, $link, $description);
161 my($ahref, $setting, $description) = @_;
163 if ($access{'bootup'} == 1) {
164 push(@cols, "<a href=\"edit_hostconfig.cgi?0+$ahref\">$ahref</a>");
169 if ( $setting eq "-NO-" ) {
170 push(@cols, "<FONT color=#ff0000>$setting</font>");
172 elsif ( $setting ne "" ) {
173 push(@cols, $setting);
178 push(@cols, $description);
179 if ( $ahref ne "" ) {
180 return &ui_columns_row(\@cols);
183 return "<!-- this is annoying- I'll have to track it down.. -->";
187 sub hostconfig_editaction
191 # This sub takes either one or two arguements- the first (action name)
192 # is required, the second is the StartupItems script affected by
193 # the setting of the action.
195 # If there is no script, the current setting is used as the default in
196 # a text field for editing.
198 # If there is a script, but the setting is something like automatic in
199 # the Network script where there isn't an alternative, then radio button # choice between the defined setting and a custom one is offered.
201 # If, as is the case with most scripts, there is a -NO- and -YES-
202 # option, then those two choices are offered as a radio button option
203 # and a text box option just in case a custom answer is needed.
208 local(@sconf, @sfile, @possible_settings, $current, $setting, $line, $option_selected, $buttons, $pre);
209 my($action_item, $startupfile) = @_;
211 # get current setting
212 $line = "$config{'hostconfig'}";
216 @sconf = grep /^$action_item=/, @sconf;
217 ($dontcare, $current) = split(/=/, $sconf[0]);
218 if ( $current eq "" ) {
219 $current = "udefined";
225 @possible_settings = ();
226 $option_selected = "";
228 $option_selected = "";
230 # get possible settings
231 if ( $startupfile ne "" ) {
232 open(LOCAL, $startupfile);
236 # I really need to write a parser to get
237 # this done- so that I can deal with
240 # But this is better than nothing...
242 @sfile = grep /\{$action_item:=/, @sfile;
243 for $element (@sfile) {
244 # We are looking at a line that looks like
245 #if [ "${WEBMIN:=-NO-}" = "-YES-" ]; then
246 # We want the -NO- and -YES-
247 if ( $element =~ /\"\$\{$action_item:=(.*)\}\"[ \t]*=[ \t]*\"(.*)\"/ ) {
248 push @possible_settings, ($1, $2);
251 # get rid of duplicate entries
252 %unique = map { $_ => 1 } @possible_settings;
253 @possible_settings = keys %unique;
254 } # end of :if ( $startupfile ne "" )
256 if ( $possible_settings[0] eq "" ) {
257 $buttons = "<input type=text name=choice value=\"$current\">";
260 foreach $setting (@possible_settings) {
261 if ( $setting ne $current ) {
262 if ( $buttons eq "" ) {
266 $pre = "$buttons<br>\n";
268 $buttons = "$pre<input type=radio name=choice value=\"$setting\">$setting";
271 $option_selected = "yes";
272 if ( $buttons eq "" ) {
276 $pre = "$buttons<br>\n";
278 $buttons = "$pre<input type=radio name=choice value=\"$setting\" checked>$setting";
281 # add custom text option
282 if ( $option_selected eq "yes" ) {
283 $buttons = "$buttons<br>\n<input type=radio name=choice value=custom> <input type=text name=custom size=60 value=\"\">";
286 $buttons = "$buttons<br>\n<input type=radio name=choice value=custom checked> <input type=text name=custom size=60 value=\"$current\">";
290 $buttons = "$buttons\n<input type=hidden name=action value=$action_item>\n";
296 sub hostconfig_createtext
298 # simply outputs the text in the create new action table
299 my($text_line,$required_field) = @_;
300 if ( $required_field ne "" ) {
301 $output="<td><font size=-1 color=#ff0000>*</font><b>$text_line</b></td>\n";
304 $output="<td><b>$text_line</b></td>\n";