-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.cgi
executable file
·171 lines (155 loc) · 4.78 KB
/
edit.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/local/bin/perl
# Show a page for creating or editing a bootup action associated with
# some domain.
use strict;
use warnings;
our (%text, %in, %config);
our $module_name;
require './virtualmin-init-lib.pl';
&ReadParse();
my $d = $in{'dom'} ? &virtual_server::get_domain($in{'dom'}) : undef;
&ui_print_header($d ? &virtual_server::domain_in($d) : undef,
$in{'new'} ? $text{'edit_title1'} : $text{'edit_title2'}, "");
my $init;
my $tmpl;
if (!$in{'new'}) {
# Get the existing action
($init) = grep { $_->{'id'} eq $in{'id'} }
&list_domain_actions($d);
$init || &error($text{'edit_egone'});
}
else {
# Adding a new action
$init = { 'status' => 1 };
($tmpl) = grep { $_->{'id'} eq $in{'tmpl'} } &list_action_templates();
if ($config{'mode'} eq 'smf' && !$tmpl) {
$init->{'stop'} = ':kill';
}
}
print &ui_form_start("save.cgi", "post");
print &ui_hidden("new", $in{'new'});
print &ui_hidden("tmpl", $in{'tmpl'});
print &ui_hidden("id", $in{'id'});
if ($in{'dom'}) {
print &ui_hidden("dom", $in{'dom'});
}
print &ui_table_start($text{'edit_header'}, undef, 2);
# Domain selector, if needed
if (!$in{'dom'}) {
my @doms = grep { $_->{$module_name} &&
&virtual_server::can_edit_domain($_) }
&virtual_server::list_domains();
print &ui_table_row($text{'edit_dom'},
&ui_select("dom", undef,
[ map { [ $_->{'id'}, $_->{'dom'} ] } @doms ]));
}
# Action name
print &ui_table_row($text{'edit_name'},
&ui_textbox("name", $init->{'name'}, 30));
# Description
print &ui_table_row($text{'edit_desc'},
&ui_textbox("desc", $init->{'desc'}, 60));
# Enabled?
if (&can_start_actions()) {
# Init mode, in which we can just control if started at boot
print &ui_table_row($text{'edit_status'},
&ui_yesno_radio("status", int($init->{'status'})));
}
else {
# SMF mode, in which we can see the real status
my @opts = ( [ 1, $text{'yes'} ],
[ 0, $text{'no'} ] );
if ($init->{'status'} == 2) {
push(@opts, [ 2, $text{'edit_maint'} ]);
}
print &ui_table_row($text{'edit_status2'},
&ui_radio("status", $init->{'status'}, \@opts));
if ($init->{'status'} == 2) {
# Show failure log
print &ui_table_row($text{'edit_startlog'},
"<pre>".&html_escape($init->{'startlog'})."</pre>");
}
}
if ($tmpl) {
# Adding from template .. show name
print &ui_table_row($text{'edit_tmpl'}, $tmpl->{'desc'});
# Show parameters
for(my $i=0; defined($tmpl->{'pname_'.$i}); $i++) {
my $tt = $tmpl->{'ptype_'.$i};
my $tn = 'param_'.$tmpl->{'pname_'.$i};
my $of = $tmpl->{'popts_'.$i};
my @opts = $of ? &read_opts_file($of) : ( );
print &ui_table_row($tmpl->{'pdesc_'.$i},
$tt == 0 ? &ui_textbox($tn, undef, 50) :
$tt == 1 ? &ui_textbox($tn, undef, 10) :
$tt == 2 ? &ui_textbox($tn, undef, 50).
&file_chooser_button($tn) :
$tt == 3 ? &ui_radio($tn, $opts[0]->[0], \@opts) :
$tt == 4 ? &ui_select($tn, $opts[0]->[0], \@opts) :
undef);
}
# Show fixed code for start and stop
my $start = $tmpl->{'start'};
$start = &substitute_template($start, $d) if ($d);
print &ui_table_row($text{'edit_start'},
"<pre>".&html_escape($start)."</pre>");
my $stop = $tmpl->{'stop'};
$stop = &substitute_template($stop, $d) if ($d);
print &ui_table_row($text{'edit_stop'},
$stop eq ":kill" ? $text{'edit_stopkill'} :
"<pre>".&html_escape($stop)."</pre>");
}
else {
# Start code
print &ui_table_row($text{'edit_start'},
&ui_textarea("start", $init->{'start'}, 5, 80));
# Stop code
my $stopdef;
if ($config{'mode'} eq 'smf') {
$stopdef = &ui_radio(
"stop_def", $init->{'stop'} eq ':kill' ? 1 : 0,
[ [ 1, $text{'edit_stopkill'} ],
[ 0, $text{'edit_stopbelow'} ] ])."<br>\n";
}
print &ui_table_row($text{'edit_stop'},
$stopdef.
&ui_textarea("stop", $init->{'stop'} eq ':kill' ? undef :
$init->{'stop'}, 5, 80));
# Current processes
if (!$in{'new'}) {
my @procs = &get_started_processes($init);
if (@procs) {
my @table = ( );
foreach my $p (@procs) {
push(@table, [ $p->{'pid'}, $p->{'cpu'},
$p->{'size'}, $p->{'args'} ]);
}
print &ui_table_row($text{'edit_procs'},
&ui_columns_table(
[ $text{'edit_ppid'}, $text{'edit_pcpu'},
$text{'edit_psize'}, $text{'edit_pcmd'} ],
undef,
\@table));
}
}
}
# SMF FMRI
if (!$in{'new'} && $init->{'fmri'}) {
print &ui_table_row($text{'edit_fmri'},
"<tt>".&html_escape($init->{'fmri'})."</tt>");
}
print &ui_table_end();
if ($in{'new'}) {
print &ui_form_end([ [ "create", $text{'create'} ] ]);
}
else {
print &ui_form_end([ [ "save", $text{'save'} ],
[ "delete", $text{'delete'} ],
undef,
&can_start_actions() ? (
[ "startnow", $text{'edit_startnow'} ],
[ "stopnow", $text{'edit_stopnow'} ]
) : ( )
]);
}
&ui_print_footer("index.cgi?dom=$in{'dom'}", $text{'index_return'});