Revision 8a31882d
Added by Steve Beaver over 4 years ago
src/usr/local/www/vpn_wg_edit.php | ||
---|---|---|
52 | 52 |
|
53 | 53 |
if ($_POST['save']) { |
54 | 54 |
// $input_errors = wg_do_post($POST); |
55 |
exit(); |
|
55 | 56 |
} |
56 | 57 |
|
57 | 58 |
$shortcut_section = "wireguard"; |
... | ... | |
111 | 112 |
|
112 | 113 |
|
113 | 114 |
$section2 = new Form_Section('Peers'); |
114 |
|
|
115 |
/* |
|
115 | 116 |
$idx = 0; |
116 | 117 |
foreach ($pconfig['peers'] as $peer) { |
117 | 118 |
$section2->addInput(new Form_Input( |
... | ... | |
123 | 124 |
|
124 | 125 |
$idx++; |
125 | 126 |
} |
127 |
*/ |
|
128 |
|
|
129 |
if (!is_array($pconfig['peers'])) { |
|
130 |
$pconfig['peers'] = array(); |
|
131 |
} |
|
132 |
|
|
133 |
$peer_count = count($pconfig['peers']); |
|
134 |
$peer_num = 0; |
|
135 |
$peer_help = gettext("Description"); |
|
136 |
$dnshost_help = gettext("Public key"); |
|
137 |
$dnsgw_help = gettext("Endpoint"); |
|
138 |
$ka_help = gettext("Keepalive"); |
|
139 |
$aips_help = gettext("Allowed IPs"); |
|
140 |
|
|
141 |
// If there are no peers, make an empty entry for initial display. |
|
142 |
if ($peer_count == 0) { |
|
143 |
$pconfig['peer'][] = ''; |
|
144 |
} |
|
145 |
|
|
146 |
foreach ($pconfig['peers'] as $peer) { |
|
147 |
$is_last_peer = (($peer_num == $peer_count - 1) || $peer_count == 0); |
|
148 |
$group = new Form_Group('Peer ' . $peer_num); |
|
149 |
$group->addClass('repeatable')->addClass('peer_group_' . $peer_num); |
|
150 |
|
|
151 |
$group->add(new Form_Input( |
|
152 |
'descp' . $peer_num, |
|
153 |
'Description', |
|
154 |
'text', |
|
155 |
$peer['descr'] |
|
156 |
))->setHelp(($is_last_peer) ? $peer_help:null); |
|
157 |
|
|
158 |
$group->add(new Form_Input( |
|
159 |
'endpoint' . $peer_num, |
|
160 |
'Endpoint', |
|
161 |
'text', |
|
162 |
$peer['endpoint'] |
|
163 |
))->setHelp(($is_last_peer) ? $dnsgw_help:null)->setWidth(3); |
|
164 |
|
|
165 |
$group->add(new Form_Input( |
|
166 |
'persistentkeepalive', |
|
167 |
'Keepalive', |
|
168 |
'PDF_pcos_get_number(p, doc, path)', |
|
169 |
$peer['persistentkeepalive'] |
|
170 |
))->setHelp(($is_last_peer) ? $ka_help:null)->setWidth(1); |
|
171 |
|
|
172 |
$group->add(new Form_Button( |
|
173 |
'killpeer' . $peer_num, |
|
174 |
'Delete', |
|
175 |
null, |
|
176 |
'fa-trash' |
|
177 |
))->setWidth(1)->addClass('btn-warning btn-sm'); |
|
178 |
|
|
179 |
$group2 = new Form_Group(''); |
|
180 |
$group2->addClass('repeatable')->addClass('peer_group_' . $peer_num); |
|
181 |
|
|
182 |
$group2->add(new Form_Input( |
|
183 |
'publickeyp' . $peer_num, |
|
184 |
'Public key', |
|
185 |
'text', |
|
186 |
$peer['publickey'] |
|
187 |
))->setHelp(($is_last_peer) ? $dnshost_help:null)->setWidth(4); |
|
188 |
|
|
189 |
|
|
190 |
$group2->add(new Form_Input( |
|
191 |
'allowedips' . $peer_num, |
|
192 |
'Allowed IPs', |
|
193 |
'text', |
|
194 |
$peer['allowedips'] |
|
195 |
))->setHelp(($is_last_peer) ? $aips_help:null); |
|
196 |
|
|
197 |
$section2->add($group); |
|
198 |
$section2->add($group2); |
|
199 |
$peer_num++; |
|
200 |
} |
|
201 |
|
|
202 |
$section2->addInput(new Form_Button( |
|
203 |
'addrow', |
|
204 |
'Add peer', |
|
205 |
null, |
|
206 |
'fa-plus' |
|
207 |
))->addClass('btn-success addbtn btn-sm'); |
|
126 | 208 |
|
127 | 209 |
$form->add($section2); |
128 | 210 |
|
... | ... | |
133 | 215 |
<script type="text/javascript"> |
134 | 216 |
//<![CDATA[ |
135 | 217 |
events.push(function() { |
136 |
|
|
218 |
// Don't show delete button if there is only one peer |
|
219 |
function hideDeleteBtn() { |
|
220 |
if ($('[id^=descp]').length <= 1) { |
|
221 |
$('[id^=killpeer]').hide(); |
|
222 |
} else { |
|
223 |
$('[id^=killpeer]').show(); |
|
224 |
} |
|
225 |
} |
|
226 |
|
|
227 |
// Delete a peer |
|
228 |
$('[id^=killpeer]').click(function (event) { |
|
229 |
event.preventDefault(); |
|
230 |
if (confirm('Are you sure you want to delete this peer?')) { |
|
231 |
var row = event.target.id.slice(8); |
|
232 |
var target = '.peer_group_' + row |
|
233 |
$(target).remove(); |
|
234 |
hideDeleteBtn(); |
|
235 |
} |
|
236 |
|
|
237 |
}) |
|
137 | 238 |
}); |
138 | 239 |
//]]> |
139 | 240 |
</script> |
Also available in: Unified diff
Split peer form into two rows with custom Javascript methods