1#!/usr/local/bin/perl
2# index.cgi
3# Display a list of services, built from svcs command
4
5require './smf-lib.pl';
6&ReadParse();
7&ui_print_header(undef, $text{'property_group_editor_title'}, "");
8
9# get instance fmri
10if (defined($in{'fmri'})) {
11	$fmri = $in{'fmri'};
12	# remove quotes...
13	$fmri =~ /\'([^\']*)\'/;
14	$fmri = $1;
15	if ($fmri =~ /(svc:\/[^:]*):(.*)/) {
16		$svc = $1;
17		$inst = $2;
18	} else {
19		&error("Invalid fmri: instance must be specified!");
20		}
21} else {
22	&error("No fmri supplied to property group editor!");
23	}
24
25# deal with add/deletion of property groups first. this way
26# pgroup list will show changes...
27if ((defined($in{'add'})) &&
28    (defined($in{'addname'})) &&
29    (defined($in{'addtype'})) &&
30    (defined($in{'addsinst'}))) {
31	$addname = "$in{'addname'}";
32	$addtype = "$in{'addtype'}";
33	$addsinst = "$in{'addsinst'}";
34	if (($addname =~ /.+/) && ($addtype =~ /.+/) && ($addsinst =~ /.+/)) {
35		&svc_addpg("$svc", "$addsinst", "$addname", "$addtype");
36		}
37	}
38if (defined($in{'remove'})) {
39	# get remove pg list
40	@remove_pgs = split(/\0/, $in{'applyto'});
41	foreach $rpg (@remove_pgs) {
42		# split into service or instance level/name
43		if ($rpg =~ /([^\/]*)\/(.*)/) {
44			$pgsinst = $1;
45			$pgname = $2;
46			&svc_delpg("$svc", "$pgsinst", "$pgname");
47			}
48		}
49	}
50
51@pgroup_listing_svc = &svc_listpg($svc, "service");
52@pgroup_listing_inst = &svc_listpg($svc, $inst);
53@pgroup_listing = (@pgroup_listing_svc, @pgroup_listing_inst);
54
55print "<h2>";
56&text_and_whats_this("property_group_editor_detail");
57print " : $fmri </h2>\n";
58
59print "<form method=\"POST\" action=\"property_group_editor.cgi?fmri='$fmri'\">\n";
60
61# add pg table first...
62print "<p><h3>$text{'property_group_editor_addpg'}</h3>\n";
63print "<table><tr>";
64print "<td><b>$text{'property_group_editor_addsinst'}</b></td>\n";
65print "<td><b>$text{'property_group_editor_addname'}</b></td>\n";
66print "<td><b>$text{'property_group_editor_addtype'}</b></td></tr>\n";
67print "<tr><td>\n";
68@sinstarray = ("service", "$inst");
69&print_selection("addsinst", "service", \@sinstarray);
70print "</td><td>\n";
71print "<input size=30 name=\"addname\" value=\"\">\n";
72print "</td><td>\n";
73print "<input size=30 name=\"addtype\" value=\"\">\n";
74print "</td></tr>\n";
75print "<tr><td>&nbsp;</td><td>&nbsp;</td><td>";
76print "<input type=submit name=\"add\" value=\"$text{'property_group_editor_add'}\">\n";
77print "</td></tr></table></b>\n";
78
79print "<table border width=100%>\n";
80print "<tr><td><table width=100%>\n";
81print "<tr $cb><td><b>$text{'property_group_editor_apply'}</b>:&nbsp;";
82print "<input type=submit name=\"remove\" onClick=\"return (confirm(\'$text{'property_group_editor_deleteconfirm'}\'))\" value=\"$text{'property_group_editor_delete'}\">&nbsp;\n";
83print "</td></tr></table></td></tr>\n";
84print "<tr><td><table width=100%>\n";
85print "<tr $cb>\n";
86print "<td><b>$text{'property_group_editor_select'}</b></td>\n";
87print "<td><b>$text{'property_group_editor_sinst'}</b></td>\n";
88print "<td><b>$text{'property_group_editor_pgroup_name'}</b></td>\n";
89print "<td><b>$text{'property_group_editor_pgroup_type'}</b></td></tr>\n";
90
91foreach $pg (@pgroup_listing) {
92	print "<tr $cb>";
93	$sinst = $pg->{'sinst'};
94	$name = $pg->{'pgroup_name'};
95	$type = $pg->{'pgroup_type'};
96	print "<td>\n";
97	print "<input type=checkbox name=\"applyto\" value=\"$sinst/$name\">";
98	print "</td><td>\n";
99	print "$sinst</td><td>\n";
100	# don't allow edit of nonpersistent items!
101	if ($type =~ /NONPERSISTENT/) {
102		print "$name";
103	} else {
104		$entity = ($sinst eq "service") ? "$svc" : "$fmri";
105		print
106	"<a href=\"property_editor.cgi?fmri='$fmri'&sinst=$sinst&pgroup=$name\">$name</a>";
107		}
108	print "</td><td>$type</td>\n";
109	print "</tr>\n";
110}
111print "</table></td></tr></table></form>\n";
112
113&print_cmds_run();
114
115&ui_print_footer("instance_viewer.cgi?fmri='$fmri'",
116	$text{'property_group_editor_back'});
117
118