Handle hostnames with upper-case letters
[webmin.git] / smf / dep_viewer.cgi
1 #!/usr/local/bin/perl
2 # dependency/dependent tree viewer
3 # Display a form for displaying/editing SMF service states in dependency
4 # and dependent trees.
5
6 require './smf-lib.pl';
7 &ReadParse();
8
9 # get instance fmri
10 if (defined($in{'fmri'})) {
11         $fmri = $in{'fmri'};
12         # remove quotes...
13         $fmri =~ /\'([^\']*)\'/;
14         $fmri = $1;
15 } else {
16         &error("No fmri supplied to dep viewer!");
17         }
18
19 # deal with application of state changes first. this way
20 # dep lists will show new states...
21 if (defined($in{'change_state'})) {
22         $cmd = "$in{'change_state'}";
23         # get update fmri list
24         @update_fmris = split(/\0/, $in{'applyto'});
25         &svc_state_cmd("$cmd", \@update_fmris);
26         }
27
28 @depy_expand_list = ();
29 # which dependency fmris do we expand?
30 if (defined($in{'dependency_expandlist'})) {
31         # get required expansions. each is fmri
32         @depy_expand_list = split(/\0/, $in{'dependency_expandlist'});
33         }
34 # Expand list - list of fmris to expand. By default, expand top fmri.
35 push(@depy_expand_list, $fmri);
36
37 @dept_expand_list = ();
38 # which dependent fmris do we expand?
39 if (defined($in{'dependent_expandlist'})) {
40         # get required expansions. each is fmri
41         @dept_expand_list = split(/\0/, $in{'dependent_expandlist'});
42         }
43 # Expand list - list of fmris to expand. By default, expand top fmri.
44 push(@dept_expand_list, $fmri);
45
46 # get new expansion/contractions submitted...
47 @inkeys = keys(%in);
48 foreach $inkey (@inkeys) {
49         if ($inkey =~ /dependency_expand_(.*)$/) {
50                 $expand_fmri = $1;
51                 push(@depy_expand_list, $expand_fmri);
52                 }
53         if ($inkey =~ /dependency_contract_(.*)$/) {
54                 $contract_fmri = $1;
55                 foreach $e (@depy_expand_list) {
56                         $old = shift(@depy_expand_list);
57                         if ($old eq $contract_fmri) {
58                                 next;
59                                 }
60                         push(@depy_expand_list, $old);
61                         }
62                 }
63         if ($inkey =~ /dependent_expand_(.*)$/) {
64                 $expand_fmri = $1;
65                 push(@dept_expand_list, $expand_fmri);
66                 }
67         if ($inkey =~ /dependent_contract_(.*)$/) {
68                 $contract_fmri = $1;
69                 foreach $e (@dept_expand_list) {
70                         $old = shift(@dept_expand_list);
71                         if ($old eq $contract_fmri) {
72                                 next;
73                                 }
74                         push(@dept_expand_list, $old);
75                         }
76                 }
77         }
78
79 # Gather service description, and state info
80 $description = &run_smf_cmds("/usr/bin/svcs -H -oDESC $fmri", 0);
81
82 %depy_tree = ();
83 %dept_tree = ();
84 $depy_treeref = \%depy_tree;
85 $dept_treeref= \%dept_tree;
86 $instance_state = &svc_get_state_cmd($fmri);
87 &build_dep_tree("dependent", $dept_treeref, $fmri, 0, \@dept_expand_list,
88         $instance_state);
89 &build_dep_tree("dependency", $depy_treeref, $fmri, 0, \@depy_expand_list,
90         $instance_state);
91
92 &ui_print_header(undef, $text{'dep_viewer_title'}, "", undef);
93
94 print "<form method=\"POST\" action=\"dep_viewer.cgi?fmri='$fmri'\">\n";
95
96 print "<h2>$description</h2>\n";
97 print "<h2>";
98 &text_and_whats_this("dep_viewer_detail");
99 print "</h2>";
100
101 print "<h2>$text{'dep_viewer_depy_info'}</h2>\n";
102 print "<p>$text{'dep_viewer_apply'}:&nbsp\n";
103 &print_state_buttons();
104 print "</p>\n";
105 &print_dep_tree("dependency", $depy_treeref, $fmri, 0, \@depy_expand_list);
106
107 print "<h2>$text{'dep_viewer_dept_info'}</h2>\n";
108 print "<p>$text{'dep_viewer_apply'}:&nbsp\n";
109 &print_state_buttons();
110 print "</p>\n";
111 &print_dep_tree("dependent", $dept_treeref, $fmri, 0, \@dept_expand_list);
112
113 print "</form>\n";
114
115 &print_cmds_run();
116
117 &ui_print_footer("instance_viewer.cgi?fmri='$fmri'",
118         $text{'dep_viewer_back'});