1#!/usr/local/bin/perl
2# index.cgi
3# Display a list of services, built from svcs command
4
5$unsafe_index_cgi = 1;
6require './smf-lib.pl';
7&ReadParse();
8&ui_print_header(undef, $text{'index_title'}, "", "help", 1, 1, 0,
9	&help_search_link("smf", "man", "doc", "howto"));
10
11# deal with application of state changes first. this way
12# fmri list will show changes...
13if (defined($in{'change_state'})) {
14	$cmd = "$in{'change_state'}";
15	# get update fmri list
16	@update_fmris = split(/\0/, $in{'applyto'});
17	&svc_state_cmd("$cmd", \@update_fmris);
18	}
19
20# service type
21if (defined($in{'type'})) {
22	$svc_type = $in{'type'};
23} else {
24	$svc_type = "All";
25	}
26if (defined($in{'include_disabled'})) {
27	$include_disabled = $in{'include_disabled'};
28} else {
29	$include_disabled = $default_include_disabled;
30	}
31if ($include_disabled == 1) {
32	$checked_include_disabled = "checked";
33} else {
34	$checked_include_disabled = "";
35	}
36# opts for svcs listing
37$opts = "$default_svc_options";
38
39if (defined($in{'opts'})) {
40	@extraopts = split(/\0/, $in{'opts'});
41	foreach $extraopt (@extraopts) {
42		$opts = "$opts,$extraopt";
43		}
44	}
45$sortopt = "$default_sortopt";
46if (defined($in{'sortopt'})) {
47	$sortopt = $in{'sortopt'};
48	}
49
50print "<h2>";
51&text_and_whats_this("index_detail");
52print "</h2>\n";
53# Checkboxes for view update
54print "<form method=\"POST\" action=\"index.cgi\">\n";
55print "<p><table>\n";
56print "<tr><td><b>$text{'index_svc_type'}</b></td>\n";
57print "<td>";
58@typelist = sort keys %svc_types;
59&print_selection("type", "$svc_type", \@typelist);
60print "</td></tr>\n";
61print "<tr><td><b>$text{'index_extraopts'}</b></td>\n";
62print "</b></td>\n";
63print "<td>";
64@additional_option_names = sort keys %svc_options;
65foreach $o (@additional_option_names) {
66	if ($default_svc_options =~ /$o/) {
67		next;
68		}
69	$checked = "unchecked";
70	if ($opts=~ /$o/) {
71		$checked = "checked";
72		$opts_str="$opts_str\&opts=$o";
73		}
74	print "$svc_options{$o}";
75	print "<input type=checkbox name=\"opts\" value=\"$o\" $checked>&nbsp;";
76	}
77print "</td></tr>\n";
78print "<tr><td><b>$text{'index_include_disabled'}</b></td>\n";
79print "<td>";
80print
81"<input type=checkbox name=\"include_disabled\" value=1 $checked_include_disabled>";
82print "</td></tr>\n";
83print "<tr><td>&nbsp;</td><td>\n";
84print "<input type=submit name=\"submit\" value=\"Update View\"/></td></tr>";
85print "</table></p></form>\n";
86
87print "<form method=\"POST\" action=\"index.cgi?include_disabled=$include_disabled&type=$svc_type&sortopt=$sortopt$opts_str\">\n";
88
89print "<table border width=100%>\n";
90print "<tr><td><table width=100%>\n";
91# multiple select buttons(enable, disable, maintenance, degraded, clear, delete)
92print "<tr $cb><td>\n";
93print "<input type=\"button\" onClick=location.href=\"smfwizard_service.cgi?clearout=1\" value=\"$text{'index_create_new_service'}\">";
94print "&nbsp;";
95print "<input type=\"button\" onClick=location.href=\"search_instance.cgi\" value=\"$text{'index_search_instance'}\">\n";
96print "</td></tr><tr $cb><td><b>$text{'index_apply'}</b>:&nbsp;";
97&print_state_buttons();
98# add delete/create new buttons in addition to statechange buttons
99print "<input type=submit name=\"change_state\" onClick=\"return (confirm(\'$text{'index_deleteconfirm'}\'))\" value=\"$text{'index_delete'}\">&nbsp;\n";
100print "</td></tr></table></td></tr>\n";
101print "<tr><td><table width=100%>\n";
102@svcs_info = &svcs_listing("$svc_types{$svc_type}", "$sortopt");
103@optlist = split(/,/, $opts);
104print "<tr $cb>\n";
105print "<td>$text{'index_select'}</td>\n";
106foreach $o (@optlist) {
107	# clicking should reverse sort option if we`re already sorting by
108	# this option...
109	if ($sortopt =~/-S$o/) {
110		$new_sortopt = "-s$o";
111	} elsif ($sortopt =~/-s$o/) {
112		$new_sortopt = "-S$o";
113	} else {
114		$new_sortopt = "-s$o";
115		}
116	print "<td>";
117	print "$text{'index_sort_by'}:&nbsp;";
118	print "<a href=\"index.cgi?include_disabled=$include_disabled&type=$svc_type&sortopt=$new_sortopt$opts_str\">";
119	print "$svc_options{$o}</a></td>\n";
120	}
121print "</tr>\n";
122
123for $svc_info (@svcs_info) {
124	# if we are displaying enabled only, skip disabled
125	if (($include_disabled != 1) && ($svc_info->{'STATE'} eq "disabled")) {
126		next;
127		}
128	print "<tr $cb>";
129	$fmri = $svc_info->{'FMRI'};
130	if ("$fmri" =~ /^lrc:\//) {
131		print "<td>-</td>\n";
132	} else {
133		print "<td><input type=checkbox name=\"applyto\" value=\"$svc_info->{'FMRI'}\"></td>\n";
134		}
135        foreach $opt (@optlist) {
136		$field = $svc_info->{$opt};
137		if ($opt eq "FMRI") {
138			$field =~ /$svc_types{$svc_type}(.*)/;
139			$svc = $1;
140			# make sure legacy svcs are unclickable!
141			if ($field =~ /svc:\//) {
142				print "<td>";
143				print
144		"<a href=\"instance_viewer.cgi?fmri='$fmri'\">$svc</a>";
145				print "</td>\n";
146			} else {
147				print "<td>$svc</td>\n";
148				}
149		} elsif ($opt eq "STATE") {
150			print
151			    "<td>";
152			print
153    "<font color=$state_colors{$svc_info->{$opt}}>$svc_info->{$opt}</font>\n";
154			print "</td>\n";
155		} else {
156			print "<td>$field</td>"
157		}
158	}
159	print "</tr>\n";
160}
161print "</table></td></tr></table></form>\n";
162
163&print_cmds_run();
164
165&ui_print_footer("/", $text{'index'});
166
167