1 |
diff -urN smeserver-wireguard-1.0.old/createlink smeserver-wireguard-1.0/createlink |
2 |
--- smeserver-wireguard-1.0.old/createlink 2021-12-21 22:33:27.000000000 +0400 |
3 |
+++ smeserver-wireguard-1.0/createlink 2021-12-21 22:49:18.704000000 +0400 |
4 |
@@ -8,6 +8,12 @@ |
5 |
/etc/wireguard/server_public.key |
6 |
/etc/rc.d/init.d/masq |
7 |
)); |
8 |
+# for smeserver-manager |
9 |
+safe_symlink('restart', "root/etc/e-smith/events/$event/services2adjust/smanager"); |
10 |
+event_link('navigation2-conf', "$event", '80'); |
11 |
+event_link('routes2-conf', "$event", '80'); |
12 |
+event_link('locales2-conf', "$event", '80'); |
13 |
+ |
14 |
# server_public.key will expand server_private.key to keep sync |
15 |
|
16 |
#TODO |
17 |
diff -urN smeserver-wireguard-1.0.old/createlinks-exe smeserver-wireguard-1.0/createlinks-exe |
18 |
--- smeserver-wireguard-1.0.old/createlinks-exe 1970-01-01 04:00:00.000000000 +0400 |
19 |
+++ smeserver-wireguard-1.0/createlinks-exe 2021-12-02 18:34:30.000000000 +0400 |
20 |
@@ -0,0 +1,23 @@ |
21 |
+#!/usr/bin/perl -w |
22 |
+ |
23 |
+use esmith::Build::CreateLinks qw(:all); |
24 |
+ |
25 |
+panel_link("webhosting", "manager"); |
26 |
+ |
27 |
+for my $event (qw( |
28 |
+ webhosting-modify smeserver-webhosting-update |
29 |
+ )) |
30 |
+{ |
31 |
+ #we can avoid those 2 as we are tricking ourself as ibay-modify and it will do those and php |
32 |
+ #templates2events("/etc/httpd/conf/httpd.conf", $event); |
33 |
+ #safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/httpd-e-smith"); |
34 |
+ event_link("webhosting-php-expand", $event, "05"); |
35 |
+ event_link("webhosting-php-adjust", $event, "90"); |
36 |
+} |
37 |
+$event="smeserver-webhosting-update"; |
38 |
+event_link("navigation-conf", $event, "70"); |
39 |
+# for smeserver-manager |
40 |
+safe_symlink('restart', "root/etc/e-smith/events/$event/services2adjust/smanager"); |
41 |
+event_link('navigation2-conf', "$event", '80'); |
42 |
+event_link('routes2-conf', "$event", '80'); |
43 |
+event_link('locales2-conf', "$event", '80'); |
44 |
diff -urN smeserver-wireguard-1.0.old/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm smeserver-wireguard-1.0/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm |
45 |
--- smeserver-wireguard-1.0.old/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm 2021-12-21 22:33:27.000000000 +0400 |
46 |
+++ smeserver-wireguard-1.0/root/usr/share/perl5/vendor_perl/esmith/FormMagick/Panel/wireguard.pm 2022-04-15 19:43:48.000000000 +0400 |
47 |
@@ -190,9 +190,11 @@ |
48 |
my $q = $fm->{cgi}; |
49 |
my $username = $q->param('account'); |
50 |
my $info = $q->param('info'); |
51 |
- ($info) = $info =~ /([A-Za-z0-9_-]+)/; |
52 |
+ ($info) = $info =~ /([A-Za-z0-9_\-. ]+)/; |
53 |
+# trim both ends |
54 |
+ $info =~ s/^ +| +$//g; |
55 |
($username) = $username =~ /([A-Za-z0-9_-]+)/; |
56 |
- return $fm->error("ERROR_FIELD_CONTENT", 'FIRST_PAGE') unless (defined $username and defined $info); |
57 |
+ return $fm->error("ERROR_FIELD_CONTENT", 'FIRST_PAGE') unless ($username and $info); |
58 |
#get username |
59 |
my $user = $accounts->get($username) or return "$username does not exist"; |
60 |
return $fm->error("ERROR_WRONG_ACCT_TYPE", 'FIRST_PAGE') unless $user->prop("type") eq "user" or $user->key eq "admin"; |
61 |
@@ -345,6 +347,11 @@ |
62 |
my $allowedips = $q->param('allowedips') || ''; |
63 |
|
64 |
#todo validate fields |
65 |
+ ($info) = $info =~ /([A-Za-z0-9_\-. ]+)/; |
66 |
+# trim both ends |
67 |
+ $info =~ s/^ +| +$//g; |
68 |
+ |
69 |
+ return $fm->error("ERROR_FIELD_CONTENT", 'FIRST_PAGE') unless $info; |
70 |
|
71 |
my %props = ('user' => $account |
72 |
,'private' => $private |
73 |
diff -urN smeserver-wireguard-1.0.old/root/usr/share/smanager/lib/SrvMngr/Controller/Wireguard.pm smeserver-wireguard-1.0/root/usr/share/smanager/lib/SrvMngr/Controller/Wireguard.pm |
74 |
--- smeserver-wireguard-1.0.old/root/usr/share/smanager/lib/SrvMngr/Controller/Wireguard.pm 1970-01-01 04:00:00.000000000 +0400 |
75 |
+++ smeserver-wireguard-1.0/root/usr/share/smanager/lib/SrvMngr/Controller/Wireguard.pm 2022-04-15 19:44:29.000000000 +0400 |
76 |
@@ -0,0 +1,572 @@ |
77 |
+package SrvMngr::Controller::Wireguard; |
78 |
+ |
79 |
+#---------------------------------------------------------------------- |
80 |
+# heading : Configuration |
81 |
+# description : Wireguard |
82 |
+# navigation : 6000 6750 |
83 |
+# |
84 |
+# name : wireguard, method : get, url : /wireguard, ctlact : wireguard#main |
85 |
+# name : wireguardd, method : post, url : /wireguard, ctlact : wireguard#do_display |
86 |
+# name : wireguardu, method : post, url : /wireguard2, ctlact : wireguard#do_action |
87 |
+# name : wireguardr, method : get, url : /wireguard2, ctlact : wireguard#do_display |
88 |
+# |
89 |
+# routes : end |
90 |
+#---------------------------------------------------------------------- |
91 |
+use strict; |
92 |
+use warnings; |
93 |
+use Mojo::Base 'Mojolicious::Controller'; |
94 |
+ |
95 |
+use Locale::gettext; |
96 |
+use SrvMngr::I18N; |
97 |
+use SrvMngr qw( theme_list init_session is_normal_password ); |
98 |
+ |
99 |
+use esmith::ConfigDB; |
100 |
+use Net::IP; |
101 |
+ |
102 |
+our $adb = esmith::AccountsDB->open() || die "Couldn't open accounts DB\ndb"; |
103 |
+our $cdb = esmith::ConfigDB->open() || die "Couldn't open config DB\n"; |
104 |
+our $wdb = esmith::ConfigDB->open('wireguard') || esmith::ConfigDB->create('wireguard'); |
105 |
+our $ndb = esmith::NetworksDB->open_ro || die "Error opening networks DB\n"; |
106 |
+ |
107 |
+ |
108 |
+sub main { |
109 |
+ |
110 |
+ my $c = shift; |
111 |
+ $c->app->log->info($c->log_req); |
112 |
+ |
113 |
+ my %wrg_datas = (); |
114 |
+ my $title = $c->l('wrg_FORM_TITLE'); |
115 |
+ |
116 |
+ $wrg_datas{'trt'} = 'LST'; |
117 |
+ |
118 |
+ $cdb = esmith::ConfigDB->open() || die "Couldn't open config DB\n"; |
119 |
+ my $wg = $cdb->get('wg-quick@wg0'); |
120 |
+ |
121 |
+ $wrg_datas{'wgpub'} = $wg->prop('public'); |
122 |
+ $wrg_datas{'wgip'} = $wg->prop('ip'); |
123 |
+ $wrg_datas{'wgmask'} = $wg->prop('mask'); |
124 |
+ $wrg_datas{'wgport'} = $wg->prop('UDPPort'); |
125 |
+ $wrg_datas{'sstatus'} = $wg->prop('status'); |
126 |
+ |
127 |
+ my @wgstatus = `/usr/bin/wg show wg0 dump`; |
128 |
+ |
129 |
+ my $type = 'wg0'; |
130 |
+ my @wgconf = $wdb->get_all_by_prop(type=>$type); |
131 |
+ |
132 |
+ $c->stash( title => $title, wrg_datas => \%wrg_datas, |
133 |
+ wgstatus => \@wgstatus, wgconf => \@wgconf ); |
134 |
+ |
135 |
+ $c->render(template => 'wireguard'); |
136 |
+ |
137 |
+}; |
138 |
+ |
139 |
+ |
140 |
+sub do_display { |
141 |
+ |
142 |
+ my $c = shift; |
143 |
+ $c->app->log->info($c->log_req); |
144 |
+ |
145 |
+ my $rt = $c->current_route; |
146 |
+ my $trt = ($c->param('trt') || ''); |
147 |
+ my $wgconf = $c->param('Wgconf') || ''; |
148 |
+ |
149 |
+ my %wrg_datas = (); |
150 |
+ my $title = $c->l('wrg_FORM_TITLE'); |
151 |
+ my $modul = ''; |
152 |
+ |
153 |
+ $wrg_datas{'trt'} = $trt; |
154 |
+ |
155 |
+ if ( $trt eq 'QRC' ) { |
156 |
+ $wrg_datas{'wgconf'} = $wgconf; |
157 |
+ } |
158 |
+ |
159 |
+ if ( $trt eq 'MOD' ) { |
160 |
+ $wrg_datas{'wgconf'} = $wgconf; |
161 |
+ my $rec = $wdb->get($wgconf); |
162 |
+ if ( $rec ) { |
163 |
+ $wrg_datas{'info'} = $rec->prop('info') || ''; |
164 |
+ $wrg_datas{'allowedips'} = $rec->prop('allowedips') || ''; |
165 |
+ $wrg_datas{'private'} = $rec->prop('private') || ''; |
166 |
+ $wrg_datas{'public'} = $rec->prop('public') || ''; |
167 |
+ $wrg_datas{'account'} = $rec->prop('user') || ''; |
168 |
+ $wrg_datas{'status'} = $rec->prop('status') || ''; |
169 |
+ $wrg_datas{'dns'} = $rec->prop('dns') || ''; |
170 |
+ } |
171 |
+ } |
172 |
+ |
173 |
+ if ( $trt eq 'REM' ) { |
174 |
+ $wrg_datas{'wgconf'} = $wgconf; |
175 |
+ my $rec = $wdb->get($wgconf); |
176 |
+ $wrg_datas{'wgcomment'} = $rec->prop('info') || ''; |
177 |
+ } |
178 |
+ |
179 |
+ if ( $trt eq 'NEW' ) { |
180 |
+ # nothing for a new client |
181 |
+ } |
182 |
+ |
183 |
+ if ( $trt eq 'UPD' ) { |
184 |
+ my $wg = $cdb->get('wg-quick@wg0'); |
185 |
+ $wrg_datas{'ip'} = $wg->prop('ip'); |
186 |
+ $wrg_datas{'mask'} = $wg->prop('mask'); |
187 |
+ $wrg_datas{'private'} = $wg->prop('private'); |
188 |
+ $wrg_datas{'public'} = $wg->prop('public'); |
189 |
+ $wrg_datas{'status'} = $wg->prop('status'); |
190 |
+ } |
191 |
+ |
192 |
+ if ( $trt eq 'LST' ) { |
193 |
+ my @wgss = $adb->wgss(); |
194 |
+ $c->stash( wgss => \@wgss ); |
195 |
+ } |
196 |
+ |
197 |
+ $c->stash( title => $title, modul => $modul, wrg_datas => \%wrg_datas ); |
198 |
+ $c->render( template => 'wireguard' ); |
199 |
+ |
200 |
+}; |
201 |
+ |
202 |
+ |
203 |
+sub do_action { |
204 |
+ |
205 |
+ my $c = shift; |
206 |
+ $c->app->log->info($c->log_req); |
207 |
+ |
208 |
+ my $rt = $c->current_route; |
209 |
+ my $trt = ($c->param('trt') || ''); |
210 |
+ |
211 |
+ my %wrg_datas = (); |
212 |
+ my $title = $c->l('wrg_FORM_TITLE'); |
213 |
+ |
214 |
+ $wrg_datas{'trt'} = $trt; |
215 |
+ |
216 |
+ my $result = ''; |
217 |
+ my $res = ''; |
218 |
+ |
219 |
+ if ( $trt eq 'QRC' ) { |
220 |
+ # NEVER |
221 |
+ } |
222 |
+ |
223 |
+ if ( $trt eq 'LST' ) { |
224 |
+ # NEVER |
225 |
+ } |
226 |
+ |
227 |
+ if ( $trt eq 'MOD' ) { |
228 |
+ $wrg_datas{'wgconf'} = $c->param('Wgconf'); |
229 |
+ # controls |
230 |
+ $res = 'OK'; # no controls here... |
231 |
+ $result .= $res unless $res eq 'OK'; |
232 |
+ if ( ! $result ) { |
233 |
+ $res = performModifyClient( $c ); |
234 |
+ $result .= $res unless $res eq 'OK'; |
235 |
+ if ( ! $result ) { |
236 |
+ $result = $c->l('wrg_SUCCESSFULLY_MODIFIED_CONF'); |
237 |
+ } |
238 |
+ } |
239 |
+ } |
240 |
+ |
241 |
+ if ( $trt eq 'REM' ) { |
242 |
+ if ($c->param("cancel")) { |
243 |
+ $c->stash( error => $c->l('wrg_CANCELLED') ); |
244 |
+ $c->redirect_to('/wireguard'); |
245 |
+ } |
246 |
+ # controls |
247 |
+ $res = 'OK'; # no controls here... |
248 |
+ $result .= $res unless $res eq 'OK'; |
249 |
+ if ( ! $result ) { |
250 |
+ $res = performRemoveClient( $c ); |
251 |
+ $result .= $res unless $res eq 'OK'; |
252 |
+ if ( ! $result ) { |
253 |
+ $result = $c->l('wrg_SUCCESSFULLY_REMOVED_CONF'); |
254 |
+ } |
255 |
+ } |
256 |
+ } |
257 |
+ |
258 |
+ if ( $trt eq 'NEW' ) { |
259 |
+ |
260 |
+ # controls |
261 |
+ $res = 'OK'; # no controls here... |
262 |
+ $result .= $res unless $res eq 'OK'; |
263 |
+ if ( ! $result ) { |
264 |
+ $res = performCreateClient( $c ); |
265 |
+ $result .= $res unless $res eq 'OK'; |
266 |
+ if ( ! $result ) { |
267 |
+ $result = $c->l('wrg_SUCCESSFULLY_ADDED_CONF'); |
268 |
+ } |
269 |
+ } |
270 |
+ } |
271 |
+ |
272 |
+ if ( $trt eq 'UPD' ) { |
273 |
+ |
274 |
+ # controls |
275 |
+ $res = 'OK'; # no controls here... |
276 |
+ $result .= $res unless $res eq 'OK'; |
277 |
+ if ( ! $result ) { |
278 |
+ $res = performUpdateConfig( $c ); |
279 |
+ $result .= $res unless $res eq 'OK'; |
280 |
+ if ( ! $result ) { |
281 |
+ $result = $c->l('wrg_SUCCESSFULLY_UPDATED_CONF'); |
282 |
+ } |
283 |
+ } |
284 |
+ } |
285 |
+ |
286 |
+ |
287 |
+ # common parts |
288 |
+ |
289 |
+ if ($res ne 'OK') { |
290 |
+ $c->stash( error => $result ); |
291 |
+ $c->stash( title => $title, wrg_datas => \%wrg_datas ); |
292 |
+ return $c->render('wireguard'); |
293 |
+ } |
294 |
+ |
295 |
+ #force reload as successfull (for Main) |
296 |
+ $wdb = esmith::ConfigDB->open('wireguard'); |
297 |
+ |
298 |
+ my $message = "'Wireguard' update ($trt) DONE"; |
299 |
+ $c->app->log->info($message); |
300 |
+ $c->flash( success => $result ); |
301 |
+ |
302 |
+ $c->redirect_to('/wireguard'); |
303 |
+} |
304 |
+ |
305 |
+ |
306 |
+# action for 'MOD' |
307 |
+sub performModifyClient{ |
308 |
+ |
309 |
+ my $c = shift; |
310 |
+ my $msg = "OK"; |
311 |
+ |
312 |
+ my $wgacc = $c->param('Wgconf'); |
313 |
+ my $account = $c->param('Account'); |
314 |
+ my $private = $c->param('Private') || ''; |
315 |
+ my $public = $c->param('Public') || ''; |
316 |
+ my $info = $c->param('Info'); |
317 |
+ my $status = $c->param('Status') || 'disabled'; |
318 |
+ my $allowedips = $c->param('Allowedips') || ''; |
319 |
+ |
320 |
+ #todo validate fields |
321 |
+ |
322 |
+# Untaint info and account before use in system() |
323 |
+ ($info) = $info =~ /([A-Za-z0-9_\-. ]+)/; |
324 |
+# trim both ends |
325 |
+ $info =~ s/^ +| +$//g; |
326 |
+ ($account) = $account =~ /([A-Za-z0-9_-]+)/; |
327 |
+ |
328 |
+ return $c->l('wrg_ERROR_FIELD_CONTENT') unless ($account and $info); |
329 |
+ |
330 |
+ my %props = ('user' => $account |
331 |
+ ,'private' => $private |
332 |
+ ,'public' => $public |
333 |
+ ,'info' => $info |
334 |
+ ,'status' => $status |
335 |
+ ,'allowedips' => $allowedips |
336 |
+ ); |
337 |
+ |
338 |
+ $wdb->get($wgacc)->merge_props(%props) |
339 |
+ or $msg = "Error occurred while modifying pseudonym in database."; |
340 |
+ |
341 |
+ # Untaint before use in system() |
342 |
+ ($wgacc) = ($wgacc =~ /(\d+\.+\d+\.+\d+\.+\d+\.+\/\d+\.+)/); |
343 |
+ system( "/sbin/e-smith/signal-event", "wireguard-user-modify", "$wgacc",) |
344 |
+ == 0 or $msg = "Error occurred while modifying wirequard account."; |
345 |
+ |
346 |
+ return "$msg" |
347 |
+ |
348 |
+} |
349 |
+ |
350 |
+ |
351 |
+# action for 'NEW' |
352 |
+sub performCreateClient { |
353 |
+ |
354 |
+ my $c = shift; |
355 |
+ my $type = shift; |
356 |
+ |
357 |
+ my $username = $c->param('Account'); |
358 |
+ my $info = $c->param('Info'); |
359 |
+ |
360 |
+# Untaint info and account before use in system() |
361 |
+ ($info) = $info =~ /([A-Za-z0-9_\-. ]+)/; |
362 |
+# trim both ends |
363 |
+ $info =~ s/^ +| +$//g; |
364 |
+ |
365 |
+ ($username) = $username =~ /([A-Za-z0-9_-]+)/; |
366 |
+ |
367 |
+ return $c->l('wrg_ERROR_FIELD_CONTENT') unless ($username and $info); |
368 |
+ |
369 |
+ #get username |
370 |
+ my $user = $adb->get($username) or return "$username does not exist"; |
371 |
+ return $c->l('wrg_ERROR_WRONG_ACCT_TYPE') unless $user->prop("type") eq "user" or $user->key eq "admin"; |
372 |
+ $username = $user->key; |
373 |
+ |
374 |
+ # execute the event wireguard-user-create username info |
375 |
+ unless ( system ("/sbin/e-smith/signal-event", "wireguard-user-create", "$username" , "$info") == 0 ){ |
376 |
+ return $c->error('wrg_ERROR_OCCURED'); |
377 |
+ } |
378 |
+ |
379 |
+ return 'OK'; |
380 |
+} |
381 |
+ |
382 |
+ |
383 |
+# action for 'UPD' |
384 |
+sub performUpdateConfig { |
385 |
+ |
386 |
+ my $c = shift; |
387 |
+ my $msg = "OK"; |
388 |
+ |
389 |
+ my $ip = $c->param('Ip'); |
390 |
+ my $mask = $c->param('Mask'); |
391 |
+ my $private = $c->param('Private'); |
392 |
+ my $public = $c->param('Public'); |
393 |
+ my $status = $c->param('Status'); |
394 |
+ |
395 |
+ unless (defined $private) { |
396 |
+ $private =`/usr/bin/wg genkey`; |
397 |
+ ($private) = ($private =~ /(\w+)/); |
398 |
+ $public = `/usr/bin/echo $private | /usr/bin/wg pubkey`; |
399 |
+ } |
400 |
+ |
401 |
+ # we get number of entries in wireguard db |
402 |
+ my @num=$wdb->get_all_by_prop(type=>"wg0"); |
403 |
+ if ( scalar @num >0 ) { |
404 |
+ # we get current values |
405 |
+ my $pprivate=$cdb->get('wg-quick@wg0')->prop('private'); |
406 |
+ my $ppublic=$cdb->get('wg-quick@wg0')->prop('public'); |
407 |
+ my $pip=$cdb->get('wg-quick@wg0')->prop('ip'); |
408 |
+ my $pmask=$cdb->get('wg-quick@wg0')->prop('mask'); |
409 |
+ # if # entries >0 and private |public | ip is chnaged then we push an error and stop |
410 |
+ if ($pprivate ne $private || $ppublic ne $public || $pip ne $ip || $mask ne $pmask) { |
411 |
+ return $c->l('wrg_CLIENTS_ALREADY_CONFIGURED'); |
412 |
+ } |
413 |
+ } |
414 |
+ |
415 |
+ #todo validate fields |
416 |
+ |
417 |
+ my %props = ('ip' => $ip |
418 |
+ ,'mask' => $mask |
419 |
+ ,'private' => $private |
420 |
+ ,'public' => $public |
421 |
+ ,'status' => $status |
422 |
+ ); |
423 |
+ |
424 |
+ $cdb->get('wg-quick@wg0')->merge_props(%props) |
425 |
+ or $msg = "Error occurred while modifying server details."; |
426 |
+ |
427 |
+ # Test Ip is inside CIDR |
428 |
+ if ( ! test_for_private_ip( $ip,$mask ) ) { $msg = "IP must be in private range"; } |
429 |
+ #else {$msg = "Ip is inside range $ip / $mask";} |
430 |
+ |
431 |
+ unless ($msg eq "OK"){ |
432 |
+ # Untaint before use in system() |
433 |
+ ($ip) = ($ip =~ /(\d+\.+\d+\.+\d+\.+\d+\.+\/\d+\.+)/); |
434 |
+ system( "/sbin/e-smith/signal-event", "wireguard-conf-modify", "$ip",) |
435 |
+ == 0 or $msg = "Error occurred while modifying wireguard conf."; |
436 |
+ } |
437 |
+ |
438 |
+ return "$msg"; |
439 |
+ |
440 |
+} |
441 |
+ |
442 |
+ |
443 |
+# action for 'REM' |
444 |
+sub performRemoveClient{ |
445 |
+ |
446 |
+ my ($c) = @_; |
447 |
+ |
448 |
+ my $conf = $c->param('Wgconf'); |
449 |
+ if ($c->param("remove")){ |
450 |
+ unless ($wdb->get($conf)->delete()){ |
451 |
+ return $c->l('wrg_ERROR_OCCURED'); |
452 |
+ } |
453 |
+ unless (system ("/sbin/e-smith/signal-event", "wireguard-user-delete") == 0 ){ |
454 |
+ return $c->l('wrg_ERROR_OCCURED'); |
455 |
+ } |
456 |
+ return 'OK'; |
457 |
+ } |
458 |
+ return $c->l('wrg_CANCELLED'); |
459 |
+ |
460 |
+} |
461 |
+ |
462 |
+ |
463 |
+# called from templates |
464 |
+sub get_existing_accounts { |
465 |
+ |
466 |
+ my $c = shift; |
467 |
+ my @existingAccounts = ('Administrator'); |
468 |
+ |
469 |
+ foreach my $account ($adb->get_all_by_prop(type=>'user')) { |
470 |
+ push @existingAccounts, $account->key; |
471 |
+ } |
472 |
+ return \@existingAccounts; |
473 |
+ |
474 |
+} |
475 |
+ |
476 |
+ |
477 |
+# called from templates |
478 |
+sub get_wgs_info { |
479 |
+ |
480 |
+ my ($c, $attr, $data) = @_; |
481 |
+ |
482 |
+ return undef if ( not defined $attr or not defined $data ); |
483 |
+ |
484 |
+ my $value; |
485 |
+ $value = $wdb->get("$data")->prop('info') if ( $attr eq 'info' and $wdb->get("$data") ); |
486 |
+ $value = $wdb->get("$data")->prop('user') if ( $attr eq 'user' and $wdb->get("$data") ); |
487 |
+ |
488 |
+ return $value; |
489 |
+ |
490 |
+} |
491 |
+ |
492 |
+ |
493 |
+# called from templates |
494 |
+sub get_conf_info { |
495 |
+ |
496 |
+ my ( $c, $ipacc ) = @_; |
497 |
+ ##my $ipacc = $c->param('Wgconf'); |
498 |
+ |
499 |
+ #untaint |
500 |
+ ($ipacc) = $ipacc =~ /(\d+\.\d+\.\d+\.\d+\/\d+)/; |
501 |
+ #get from db |
502 |
+ |
503 |
+ # return if does not exist |
504 |
+ my $acc = $wdb->get($ipacc) or return undef; |
505 |
+ |
506 |
+ # return if current user is not admin or the user |
507 |
+ return undef unless $c->is_admin; |
508 |
+ |
509 |
+ my $key = $acc->key; |
510 |
+ my $info = $acc->prop('info'); |
511 |
+ my $private = $acc->prop('private'); |
512 |
+ my $wg0 = $cdb->get('wg-quick@wg0'); |
513 |
+ my $ServPublic = $wg0->prop('public'); |
514 |
+ my $Port = $wg0->prop('UDPPort'); |
515 |
+ my $allowedips = $acc->prop('allowedips') || "0.0.0.0/0"; |
516 |
+ |
517 |
+ #here we guess wan IP |
518 |
+ # are we server-gateway mode ? so external lan, should do |
519 |
+ # else we should guess from an external service |
520 |
+ my $ExternalIP = $cdb->get('ExternalInterface')->prop('IPAddress'); |
521 |
+ $ExternalIP = get_internet_ip_address() unless defined $ExternalIP; |
522 |
+ |
523 |
+ #DNS |
524 |
+ my $IPAddress = $cdb->get('InternalInterface')->prop('IPAddress'); |
525 |
+ my $dns = ($allowedips =~ /0.0.0.0\/0/)? "DNS = $IPAddress" : "" ; |
526 |
+ |
527 |
+ my $fulltext ="#configuration for $key $info |
528 |
+[Interface] |
529 |
+PrivateKey = $private |
530 |
+Address = $key |
531 |
+$dns |
532 |
+ |
533 |
+[Peer] |
534 |
+PublicKey = $ServPublic |
535 |
+AllowedIPs = $allowedips |
536 |
+Endpoint = $ExternalIP:$Port |
537 |
+"; |
538 |
+ my @fulltext = split( "\n", $fulltext); |
539 |
+ |
540 |
+ return \@fulltext; |
541 |
+ |
542 |
+} |
543 |
+ |
544 |
+ |
545 |
+# called from templates |
546 |
+sub get_conf_qr { |
547 |
+ |
548 |
+ my ( $c, $fulltext, $type) = @_; |
549 |
+ |
550 |
+ my $qr=`echo "$fulltext" |qrencode -t PNG -o - |base64`; |
551 |
+ |
552 |
+ return $qr; |
553 |
+ |
554 |
+} |
555 |
+ |
556 |
+ |
557 |
+sub get_internet_ip_address { |
558 |
+ |
559 |
+ #we could use DNS to do this faster but some provider will block DNS |
560 |
+ #dig +short myip.opendns.com @resolver1.opendns.com |
561 |
+ #also resolver1.opendns.com resolver2.opendns.com resolver3.opendns.com |
562 |
+ #here a list of available site with https |
563 |
+ use Net::DNS; |
564 |
+ use LWP::Simple; |
565 |
+ my $timeout=1; |
566 |
+ |
567 |
+ my @httpslist=qw( |
568 |
+checkip.amazonaws.com |
569 |
+myexternalip.com/raw |
570 |
+ifconfig.me/ |
571 |
+icanhazip.com/ |
572 |
+ident.me/ |
573 |
+tnx.nl/ip |
574 |
+ipecho.net/plain |
575 |
+wgetip.com/ |
576 |
+ip.tyk.nu/ |
577 |
+bot.whatismyipaddress.com/ |
578 |
+ipof.in/txt |
579 |
+l2.io/ip |
580 |
+eth0.me/ ); |
581 |
+ my @dns = ( |
582 |
+ ['myip.opendns.com', 'resolver1.opendns.com', 'A'], |
583 |
+ ['myip.opendns.com', 'resolver2.opendns.com', 'A'], |
584 |
+ ['myip.opendns.com', 'resolver3.opendns.com', 'A'], |
585 |
+ ['myip.opendns.com', 'resolver4.opendns.com', 'A'], |
586 |
+ ['whoami.akamai.net', 'ns1-1.akamaitech.net', 'A'], |
587 |
+ ['o-o.myaddr.l.google.com', 'ns1.google.com', 'TXT'] |
588 |
+ |
589 |
+ ); |
590 |
+ |
591 |
+ my $ip; |
592 |
+ |
593 |
+ #foreach my $i ( 0 .. $#dns) { |
594 |
+ # dns calls; test only one random... |
595 |
+ my $i = rand(@httpslist); |
596 |
+ my $res = Net::DNS::Resolver->new( |
597 |
+ nameservers => [ $dns[$i][1] ], |
598 |
+ udp_timeout => $timeout, |
599 |
+ tcp_timeout => $timeout |
600 |
+ ); |
601 |
+ |
602 |
+ my $reply = $res->search($dns[$i][0], $dns[$i][2]); |
603 |
+ if ($reply) { |
604 |
+ foreach my $rr ($reply->answer) { |
605 |
+ $ip= $rr->txtdata if $rr->can("txtdata"); |
606 |
+ $ip= $rr->address if $rr->can("address"); |
607 |
+ # untaint, dns output is tainted |
608 |
+ ($ip) = $ip =~ /(\d+\.\d+\.\d+\.\d+)/; |
609 |
+ return $ip if $ip =~ /(\d+\.\d+\.\d+\.\d+)/; |
610 |
+ } |
611 |
+ } else { |
612 |
+ warn "query failed: ", $res->errorstring, "\n"; |
613 |
+ } |
614 |
+ #} |
615 |
+ |
616 |
+ # https calls |
617 |
+ my $ii=0; |
618 |
+ my $service; |
619 |
+ while ( $ii <5 ) { |
620 |
+ $service=$httpslist[rand(@httpslist)]; |
621 |
+ $ip = (get "https://$service" ); |
622 |
+ chomp $ip; |
623 |
+ $ii++; |
624 |
+ last if $ip =~ /(\d+\.\d+\.\d+\.\d+)/; |
625 |
+ } |
626 |
+ # not needed but in case, untaint |
627 |
+ ($ip) = $ip =~ /(\d+\.\d+\.\d+\.\d+)/; |
628 |
+ return $ip; |
629 |
+ |
630 |
+} |
631 |
+ |
632 |
+ |
633 |
+sub test_for_private_ip { |
634 |
+ |
635 |
+ use NetAddr::IP; |
636 |
+ $_ = shift; |
637 |
+ my $mask = shift; |
638 |
+ return unless /(\d+\.\d+\.\d+\.\d+)/; |
639 |
+ my $iprange = NetAddr::IP->new($1,"$mask"); |
640 |
+ return unless $iprange; |
641 |
+ return ($iprange->first()->is_rfc1918() and $iprange->last()->is_rfc1918()); |
642 |
+ |
643 |
+} |
644 |
+ |
645 |
+ |
646 |
+1 |
647 |
+ |
648 |
+__END__ |
649 |
diff -urN smeserver-wireguard-1.0.old/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Wireguard/wireguard_en.lex smeserver-wireguard-1.0/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Wireguard/wireguard_en.lex |
650 |
--- smeserver-wireguard-1.0.old/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Wireguard/wireguard_en.lex 1970-01-01 04:00:00.000000000 +0400 |
651 |
+++ smeserver-wireguard-1.0/root/usr/share/smanager/lib/SrvMngr/I18N/Modules/Wireguard/wireguard_en.lex 2022-04-08 23:15:52.000000000 +0400 |
652 |
@@ -0,0 +1,55 @@ |
653 |
+'wrg_WIREGUARD_TITLE' => 'Wireguard panel', |
654 |
+'wrg_FORM_TITLE' => 'Wireguard', |
655 |
+'wrg_DESC_MAIN_PAGE' => 'Welcome to the wireguard panel. You can edit the configuration before creating any client, have a quick look on active connections, and manage clients.', |
656 |
+'wrg_LABEL_CONFIG' => 'Here is the main service configuration and status with active clients.', |
657 |
+'wrg_EDIT_CONFIG' => 'Edit Configuration', |
658 |
+'wrg_PUBLIC_KEY' => 'Public key', |
659 |
+'wrg_IP' => 'IP', |
660 |
+'wrg_PORT' => 'Port', |
661 |
+'wrg_INFO' => 'Information', |
662 |
+'wrg_ENDPOINT' => 'Remote IP', |
663 |
+'wrg_VPN_IP' => 'Internal IP', |
664 |
+'wrg_LATEST_HANDSHAKE' => 'Last handshake', |
665 |
+'wrg_RECEIVED' => 'Received', |
666 |
+'wrg_SENT' => 'Sent', |
667 |
+'wrg_KEEPALIVE' => 'Keep alive', |
668 |
+'wrg_LABEL_CLIENTS' => 'Here is the list of configured clients, You can access their configuration sample or easy configuration QR Code, alter their configuration, remove them or create new clients.', |
669 |
+'wrg_ADD_CLIENT' => 'Configure new client', |
670 |
+'wrg_CONF_NAME' => 'Dedicated IP', |
671 |
+'wrg_USER' => 'Associated User', |
672 |
+'wrg_DESC_MOD_CONFIG_PAGE' => 'Here you can alter the configuration. Be carefull, you can not alter the IP, subnet, private and public keys after you have created clients. The reason is that configured client will also need to be modified if yo do so.', |
673 |
+'wrg_DESC_IP_ACC_WIREGUARD' => 'Wireguard server internal IP.', |
674 |
+'wrg_INFO_IP_WIREGUARD' => 'IP', |
675 |
+'wrg_DESC_MASK_WIREGUARD' => 'Bitmask for the VPN internal network (e.g.: 22).', |
676 |
+'wrg_INFO_MASK_WIREGUARD' => 'Mask', |
677 |
+'wrg_DESC_PRIVATE_CONFIG' => 'Private key for the server, if empty one will be generated.', |
678 |
+'wrg_LABEL_PRIVATE' => 'Private key', |
679 |
+'wrg_DESC_PUBLIC_CONFIG' => 'Public key for the server generated from the private key.', |
680 |
+'wrg_LABEL_PUBLIC' => 'Public key', |
681 |
+'wrg_DESC_STATUS' => 'Status of the sevice.', |
682 |
+'wrg_LABEL_STATUS' => 'Status', |
683 |
+'wrg_DESC_ADD_CLIENT_PAGE' => 'To create a new client. please select user and add information to identify the purpose of this client. The first available IP will be associated and a private/public key pair will be generated for you.', |
684 |
+'wrg_DESC_SELECT_ACCOUNT' => 'Select the associated user account to the wireguard client', |
685 |
+'wrg_SELECT_ACCOUNT' => 'User account', |
686 |
+'wrg_DESC_INFO_ACC_WIREGUARD' => 'Fill a short description to remember what is the purpose of this client, as a user could have multiple clients.', |
687 |
+'wrg_INFO_ACC_WIREGUARD' => 'Information', |
688 |
+'wrg_DESC_DISPLAY_QR_PAGE' => 'You can copy paste this specific configuration to your client computer, or scan the QR code with your phone to configure your client.', |
689 |
+'wrg_DESC_MODIFY_CLIENT_PAGE' => 'You can alter the configuration of the client. Note that providing the private key is not required if you want to keep it secret from the admin, but you will not be able to use the QR code to configure your client and will have to add it manually.', |
690 |
+'wrg_QRCODE' => 'Display Configuration', |
691 |
+'wrg_DESC_CONF_NAME' => 'Dedicated IP associated with this client. It is also its primary identity.', |
692 |
+'wrg_DESC_PRIVATE' => 'Private key for this client, one is generated for easy access, but you can provide yours, or leave it blank, it is only needed to use the scan and configure QR code.', |
693 |
+'wrg_DESC_PUBLIC' => 'Public key is generated from private key, you can provide yours, it is mandatory to be able to connect the client.', |
694 |
+'wrg_DESC_ALLOWEDIPS' => 'You can manually provide the IP blocks that will be redirected through the VPN. This can be configured later on the client, but is provided to ease configuration with QR code. See wireguard man page for syntax. Leave it blank for all traffic to be redirected.', |
695 |
+'wrg_LABEL_ALLOWEDIPS' => 'Allowed IPs', |
696 |
+'wrg_DESC_REMOVE_CLIENT' => 'Do you want to remove this client?', |
697 |
+'wrg_ERROR_FIELD_CONTENT' => 'You must provide a user and information to create a new client.', |
698 |
+'wrg_ERROR_WRONG_ACCT_TYPE' => 'The associated account shoult be a user or admin account.', |
699 |
+'wrg_ERROR_OCCURED' => 'An error occured', |
700 |
+'wrg_CLIENTS_ALREADY_CONFIGURED' => 'You can not alter the server ip, mask, private and public key as there are already some clients configured.', |
701 |
+'wrg_NO_CONF' => 'No configured client', |
702 |
+'wrg_INTERFACE' => 'Interface', |
703 |
+'wrg_CANCELLED' => 'Operation cancelled', |
704 |
+'wrg_SUCCESSFULLY_MODIFIED_CONF' => 'Client configuration successfully modified', |
705 |
+'wrg_SUCCESSFULLY_REMOVED_CONF' => 'Client successfully removed', |
706 |
+'wrg_SUCCESSFULLY_ADDED_CONF' => 'New client successfully added', |
707 |
+'wrg_SUCCESSFULLY_UPDATED_CONF' => 'Server configuration successfully modified', |
708 |
diff -urN smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/partials/_wrg_list.html.ep smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/partials/_wrg_list.html.ep |
709 |
--- smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/partials/_wrg_list.html.ep 1970-01-01 04:00:00.000000000 +0400 |
710 |
+++ smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/partials/_wrg_list.html.ep 2022-04-15 19:26:26.000000000 +0400 |
711 |
@@ -0,0 +1,130 @@ |
712 |
+<div id='wrg_list'> |
713 |
+ |
714 |
+ <p><%=l 'wrg_DESC_MAIN_PAGE'%><br></p> |
715 |
+ |
716 |
+ %= form_for 'wireguard' => (method => 'POST') => begin |
717 |
+ %= hidden_field 'trt' => 'UPD' |
718 |
+ <p><%=l 'wrg_LABEL_CONFIG'%><br><br></p> |
719 |
+ %= submit_button l('wrg_EDIT_CONFIG'), class => 'action' |
720 |
+ % end |
721 |
+ |
722 |
+ <p><span class=label> |
723 |
+ %=l 'wrg_INTERFACE' |
724 |
+ </span> wg0<br></p> |
725 |
+ |
726 |
+ <p><span class=label> |
727 |
+ %=l 'wrg_LABEL_STATUS' |
728 |
+ </span> |
729 |
+ %= $wrg_datas->{sstatus} |
730 |
+ <br></p> |
731 |
+ |
732 |
+ <p><span class=label> |
733 |
+ %=l 'wrg_PUBLIC_KEY' |
734 |
+ </span> |
735 |
+ %= $wrg_datas->{wgpub} |
736 |
+ <br></p> |
737 |
+ |
738 |
+ <p><span class=label> |
739 |
+ %=l 'wrg_IP' |
740 |
+ </span> |
741 |
+ %= $wrg_datas->{wgip}.'/'.$wrg_datas->{wgmask} |
742 |
+ <br></p> |
743 |
+ |
744 |
+ <p><span class=label> |
745 |
+ %=l 'wrg_PORT' |
746 |
+ </span> |
747 |
+ %= $wrg_datas->{wgport} |
748 |
+ <br></p> |
749 |
+ |
750 |
+ <table class="sme-border"><tbody> |
751 |
+ <tr> |
752 |
+ <th class='sme-border'> |
753 |
+ %=l 'wrg_PUBLIC_KEY' |
754 |
+ </th><th class='sme-border'> |
755 |
+ %=l 'wrg_INFO' |
756 |
+ </th><th class='sme-border'> |
757 |
+ %=l 'wrg_ENDPOINT' |
758 |
+ </th><th class='sme-border'> |
759 |
+ %=l 'wrg_VPN_IP' |
760 |
+ </th><th class='sme-border'> |
761 |
+ %=l 'wrg_LATEST_HANDSHAKE' |
762 |
+ </th><th class='sme-border'> |
763 |
+ %=l 'wrg_RECEIVED' |
764 |
+ </th><th class='sme-border'> |
765 |
+ %=l 'wrg_LATEST_SEND' |
766 |
+ </th><th class='sme-border'> |
767 |
+ %=l 'wrg_KEEPALIVE' |
768 |
+ </th> |
769 |
+ </tr> |
770 |
+ |
771 |
+ % if (scalar @$wgstatus > 0) { |
772 |
+ % foreach my $list (@$wgstatus) { |
773 |
+ % #public-key | private-key | listen-port |persistent-keepalive |
774 |
+ % my @line = split(' ',$list); |
775 |
+ % next if $line[1] eq $wrg_datas->{wgpub}; |
776 |
+ % my ($ginfo, $user); |
777 |
+ % $ginfo = $c->get_wgs_info('info', "$line[3]"); |
778 |
+ % $user = $c->get_wgs_info('user', "$line[3]"); |
779 |
+ % use POSIX qw( strftime ); |
780 |
+ % my $dateR= ($line[4] ) ? strftime("%Y-%m-%d %H:%M:%S", localtime($line[4])) : " "; |
781 |
+ <tr> |
782 |
+ %= t td => (class => 'sme-border') => $line[0] |
783 |
+ %= t td => (class => 'sme-border') => "$user : $ginfo" |
784 |
+ %= t td => (class => 'sme-border') => $line[2] |
785 |
+ %= t td => (class => 'sme-border') => $line[3] |
786 |
+ %= t td => (class => 'sme-border') => $dateR |
787 |
+ %= t td => (class => 'sme-border') => $line[5] |
788 |
+ %= t td => (class => 'sme-border') => $line[6] |
789 |
+ %= t td => (class => 'sme-border') => $line[7] |
790 |
+ </tr> |
791 |
+ % } |
792 |
+ % } |
793 |
+ </tbody></table> |
794 |
+ |
795 |
+ %= form_for 'wireguard' => (method => 'POST') => begin |
796 |
+ <hr class='sectionbar'/> |
797 |
+ <p><%=l 'wrg_LABEL_CLIENTS'%><br><br></p> |
798 |
+ %= hidden_field 'trt' => 'NEW' |
799 |
+ %= submit_button l('wrg_ADD_CLIENT'), class => 'action' |
800 |
+ % end |
801 |
+ |
802 |
+ % if ( scalar @$wgconf == 0 ) { |
803 |
+ %=l 'wrg_NO_CONF' |
804 |
+ % } else { |
805 |
+ <table class="sme-border"><tbody> |
806 |
+ <tr> |
807 |
+ <th class='sme-border'> |
808 |
+ %=l 'wrg_CONF_NAME' |
809 |
+ </th><th class='sme-border'> |
810 |
+ %=l 'wrg_USER' |
811 |
+ </th><th class='sme-border'> |
812 |
+ %=l 'wrg_INFO' |
813 |
+ </th><th class='sme-border'> |
814 |
+ %=l 'wrg_LABEL_STATUS' |
815 |
+ </th><th class='sme-border' colspan='3'> |
816 |
+ %=l 'ACTION' |
817 |
+ </th> |
818 |
+ </tr> |
819 |
+ % foreach my $conf (@$wgconf) { |
820 |
+ % my $status = $c->l(uc($conf->prop('status') || 'enabled')); |
821 |
+ <tr> |
822 |
+ %= t td => (class => 'sme-border') => $conf->key |
823 |
+ %= t td => (class => 'sme-border') => $conf->prop('user') || '' |
824 |
+ %= t td => (class => 'sme-border') => $conf->prop('info') || '' |
825 |
+ %= t td => (class => 'sme-border') => $status |
826 |
+ % my $action = |
827 |
+ % "<a href='wireguard2?CsrfDef=TOKEN&trt=QRC&Wgconf=" . $conf->key . "'>" . l('wrg_QRCODE') . "</a>"; |
828 |
+ <td class='sme-border'><%= $c->render_to_string(inline => $action) %></td> |
829 |
+ % $action = |
830 |
+ % "<a href='wireguard2?CsrfDef=TOKEN&trt=MOD&Wgconf=" . $conf->key . "'>" . l('MODIFY') . "</a>"; |
831 |
+ <td class='sme-border'><%= $c->render_to_string(inline => $action) %></td> |
832 |
+ % $action = |
833 |
+ % "<a href='wireguard2?CsrfDef=TOKEN&trt=REM&Wgconf=" . $conf->key . "'>" . l('REMOVE') . "</a>"; |
834 |
+ <td class='sme-border'><%= $c->render_to_string(inline => $action) %></td> |
835 |
+ </tr> |
836 |
+ % } |
837 |
+ </tbody> |
838 |
+ </table> |
839 |
+ %} |
840 |
+ <hr class='sectionbar'/> |
841 |
+</div> |
842 |
diff -urN smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/partials/_wrg_mod.html.ep smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/partials/_wrg_mod.html.ep |
843 |
--- smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/partials/_wrg_mod.html.ep 1970-01-01 04:00:00.000000000 +0400 |
844 |
+++ smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/partials/_wrg_mod.html.ep 2022-04-15 19:28:16.000000000 +0400 |
845 |
@@ -0,0 +1,94 @@ |
846 |
+<div id='wrg_mod'> |
847 |
+ |
848 |
+ %= form_for '/wireguard2' => (method => 'POST') => begin |
849 |
+ <p> |
850 |
+ %=l 'wrg_DESC_MODIFY_CLIENT_PAGE' |
851 |
+ </p> |
852 |
+ <hr class='sectionbar'/> |
853 |
+ |
854 |
+ <p> |
855 |
+ %=l 'wrg_DESC_CONF_NAME' |
856 |
+ </p> |
857 |
+ |
858 |
+ <p><span class=label> |
859 |
+ %=l 'wrg_CONF_NAME' |
860 |
+ </span> |
861 |
+ %= $wrg_datas->{wgconf} |
862 |
+ <br></p> |
863 |
+ |
864 |
+ <p> |
865 |
+ %=l 'wrg_DESC_SELECT_ACCOUNT' |
866 |
+ </p> |
867 |
+ |
868 |
+ <p><span class=label> |
869 |
+ %=l 'wrg_SELECT_ACCOUNT' |
870 |
+ </span><span class=data> |
871 |
+ % param 'Account' => $wrg_datas->{account} unless param 'Account'; |
872 |
+ %= select_field 'Account' => $c->get_existing_accounts(), class => 'input' |
873 |
+ <br></span></p> |
874 |
+ |
875 |
+ <p> |
876 |
+ %=l 'wrg_DESC_INFO_ACC_WIREGUARD' |
877 |
+ </p> |
878 |
+ |
879 |
+ <p><span class=label> |
880 |
+ %=l 'wrg_INFO_ACC_WIREGUARD' |
881 |
+ </span><span class=data> |
882 |
+ % param 'Info' => $wrg_datas->{info} unless param 'Info'; |
883 |
+ %=text_field 'Info' => size => '45', class => 'input' |
884 |
+ <br></span></p> |
885 |
+ |
886 |
+ <p> |
887 |
+ %=l 'wrg_DESC_PRIVATE' |
888 |
+ </p> |
889 |
+ |
890 |
+ <p><span class=label> |
891 |
+ %=l 'wrg_LABEL_PRIVATE' |
892 |
+ </span><span class=data> |
893 |
+ % param 'Private' => $wrg_datas->{private} unless param 'Private'; |
894 |
+ %=text_field 'Private' => size => '45', class => 'input' |
895 |
+ <br></span></p> |
896 |
+ |
897 |
+ <p> |
898 |
+ %=l 'wrg_DESC_PUBLIC' |
899 |
+ </p> |
900 |
+ |
901 |
+ <p><span class=label> |
902 |
+ %=l 'wrg_LABEL_PUBLIC' |
903 |
+ </span><span class=data> |
904 |
+ % param 'Public' => $wrg_datas->{public} unless param 'Public'; |
905 |
+ %=text_field 'Public' => size => '45', class => 'input' |
906 |
+ <br></span></p> |
907 |
+ |
908 |
+ <p> |
909 |
+ %=l 'wrg_DESC_STATUS' |
910 |
+ </p> |
911 |
+ |
912 |
+ <p><span class=label> |
913 |
+ %=l 'STATUS' |
914 |
+ </span><span class=data> |
915 |
+ % param 'Status' => $wrg_datas->{status} unless param 'Status'; |
916 |
+ %= select_field 'Status' => [[ (l 'DISABLED') => 'disabled'], [ (l 'ENABLED') => 'enabled']], class => 'input' |
917 |
+ <br></span></p> |
918 |
+ |
919 |
+ <p> |
920 |
+ %=l 'wrg_DESC_ALLOWEDIPS' |
921 |
+ </p> |
922 |
+ |
923 |
+ <p><span class=label> |
924 |
+ %=l 'wrg_LABEL_ALLOWEDIPS' |
925 |
+ </span><span class=data> |
926 |
+ % param 'Allowedips' => $wrg_datas->{allowedips} unless param 'Allowedips'; |
927 |
+ %=text_field 'Allowedips' => size => '45', class => 'input' |
928 |
+ <br></span></p> |
929 |
+ |
930 |
+ <div class='center'> |
931 |
+ %= submit_button l('MODIFY'), name => 'modify', class => 'action' |
932 |
+ </div> |
933 |
+ |
934 |
+ %= hidden_field 'trt' => $wrg_datas->{trt} |
935 |
+ %= hidden_field 'Wgconf' => $wrg_datas->{wgconf} |
936 |
+ |
937 |
+ % end |
938 |
+ |
939 |
+</div> |
940 |
diff -urN smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/partials/_wrg_new.html.ep smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/partials/_wrg_new.html.ep |
941 |
--- smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/partials/_wrg_new.html.ep 1970-01-01 04:00:00.000000000 +0400 |
942 |
+++ smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/partials/_wrg_new.html.ep 2021-12-13 20:22:45.000000000 +0400 |
943 |
@@ -0,0 +1,38 @@ |
944 |
+<div id='wrg_new'> |
945 |
+ |
946 |
+ %= form_for '/wireguard2' => (method => 'POST') => begin |
947 |
+ <p> |
948 |
+ %=l 'wrg_DESC_ADD_CLIENT_PAGE' |
949 |
+ </p> |
950 |
+ |
951 |
+ <p> |
952 |
+ %=l 'wrg_DESC_SELECT_ACCOUNT' |
953 |
+ </p> |
954 |
+ |
955 |
+ <p><span class=label> |
956 |
+ %=l 'wrg_SELECT_ACCOUNT' |
957 |
+ </span><span class=data> |
958 |
+ <!-- param 'Account' => $wrg_datas->{account} unless param 'Account'; --> |
959 |
+ %= select_field 'Account' => $c->get_existing_accounts(), class => 'input' |
960 |
+ <br></span></p> |
961 |
+ |
962 |
+ <p> |
963 |
+ %=l 'wrg_DESC_INFO_ACC_WIREGUARD' |
964 |
+ </p> |
965 |
+ |
966 |
+ <p><span class=label> |
967 |
+ %=l 'wrg_INFO_ACC_WIREGUARD' |
968 |
+ </span><span class=data> |
969 |
+ <!-- param 'Info' => $wrg_datas->{info} unless param 'Info'; --> |
970 |
+ %=text_field 'Info' => size => '60', class => 'input' |
971 |
+ <br></span></p> |
972 |
+ |
973 |
+ <div class='center'> |
974 |
+ %= submit_button l('ADD'), class => 'action' |
975 |
+ </div> |
976 |
+ |
977 |
+ %= hidden_field 'trt' => $wrg_datas->{trt} |
978 |
+ |
979 |
+ % end |
980 |
+ |
981 |
+</div> |
982 |
diff -urN smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/partials/_wrg_qrc.html.ep smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/partials/_wrg_qrc.html.ep |
983 |
--- smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/partials/_wrg_qrc.html.ep 1970-01-01 04:00:00.000000000 +0400 |
984 |
+++ smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/partials/_wrg_qrc.html.ep 2022-04-15 19:27:47.000000000 +0400 |
985 |
@@ -0,0 +1,17 @@ |
986 |
+<div id='wrg_qrc'> |
987 |
+ |
988 |
+ % my $fulltext = join("\n", @{$c->get_conf_info( $wrg_datas->{wgconf} )}); |
989 |
+ <br><br> |
990 |
+ %= text_area Info => "$fulltext", cols => 70, rows => 10 |
991 |
+ <br> |
992 |
+ |
993 |
+ % my $qr = $c->get_conf_qr("$fulltext"); |
994 |
+ %= image "data:image/png;base64,$qr" |
995 |
+ |
996 |
+ <br> |
997 |
+ %=l 'wrg_DESC_DISPLAY_QR_PAGE' |
998 |
+ <br> |
999 |
+ %= hidden_field 'trt' => $wrg_datas->{trt} |
1000 |
+ %= hidden_field 'Wgconf' => $wrg_datas->{wgconf} |
1001 |
+ |
1002 |
+</div> |
1003 |
diff -urN smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/partials/_wrg_rem.html.ep smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/partials/_wrg_rem.html.ep |
1004 |
--- smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/partials/_wrg_rem.html.ep 1970-01-01 04:00:00.000000000 +0400 |
1005 |
+++ smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/partials/_wrg_rem.html.ep 2022-04-15 19:27:07.000000000 +0400 |
1006 |
@@ -0,0 +1,30 @@ |
1007 |
+<div id='wrg_rem'> |
1008 |
+ |
1009 |
+ %= form_for '/wireguard2' => (method => 'POST') => begin |
1010 |
+ <p> |
1011 |
+ %=l 'wrg_DESC_REMOVE_CLIENT' |
1012 |
+ </p> |
1013 |
+ |
1014 |
+ <p><br><span class=label> |
1015 |
+ %=l 'wrg_CONF_NAME' |
1016 |
+ </span> |
1017 |
+ %= $wrg_datas->{wgconf} |
1018 |
+ <br></p> |
1019 |
+ |
1020 |
+ <p><span class=label> |
1021 |
+ %=l 'COMMENT' |
1022 |
+ </span> |
1023 |
+ %= $wrg_datas->{wgcomment} |
1024 |
+ <br></p> |
1025 |
+ |
1026 |
+ <div class='center'> |
1027 |
+ %= submit_button l('CANCEL'), name => 'cancel', class => 'action' |
1028 |
+ %= submit_button l('REMOVE'), name => 'remove', class => 'action' |
1029 |
+ </div> |
1030 |
+ |
1031 |
+ %= hidden_field 'trt' => $wrg_datas->{trt} |
1032 |
+ %= hidden_field 'Wgconf' => $wrg_datas->{wgconf} |
1033 |
+ |
1034 |
+ % end |
1035 |
+ |
1036 |
+</div> |
1037 |
diff -urN smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/partials/_wrg_upd.html.ep smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/partials/_wrg_upd.html.ep |
1038 |
--- smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/partials/_wrg_upd.html.ep 1970-01-01 04:00:00.000000000 +0400 |
1039 |
+++ smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/partials/_wrg_upd.html.ep 2022-04-15 19:27:19.000000000 +0400 |
1040 |
@@ -0,0 +1,72 @@ |
1041 |
+<div id='wrg_upd'> |
1042 |
+ |
1043 |
+ %= form_for '/wireguard2' => (method => 'POST') => begin |
1044 |
+ <p> |
1045 |
+ %=l 'wrg_DESC_MOD_CONFIG_PAGE' |
1046 |
+ </p> |
1047 |
+ |
1048 |
+ <p> |
1049 |
+ %=l 'wrg_DESC_IP_ACC_WIREGUARD' |
1050 |
+ </p> |
1051 |
+ |
1052 |
+ <p><span class=label> |
1053 |
+ %=l 'wrg_INFO_IP_WIREGUARD' |
1054 |
+ </span><span class=data> |
1055 |
+ % param 'Ip' => $wrg_datas->{ip} unless param 'Ip'; |
1056 |
+ %=text_field 'Ip' => class => 'input' |
1057 |
+ <br></span></p> |
1058 |
+ |
1059 |
+ <p> |
1060 |
+ %=l 'wrg_DESC_MASK_WIREGUARD' |
1061 |
+ </p> |
1062 |
+ |
1063 |
+ <p><span class=label> |
1064 |
+ %=l 'wrg_INFO_MASK_WIREGUARD' |
1065 |
+ </span><span class=data> |
1066 |
+ % param 'Mask' => $wrg_datas->{mask} unless param 'Mask'; |
1067 |
+ %=text_field 'Mask' => class => 'input' |
1068 |
+ <br></span></p> |
1069 |
+ |
1070 |
+ <p> |
1071 |
+ %=l 'wrg_DESC_PRIVATE_CONFIG' |
1072 |
+ </p> |
1073 |
+ |
1074 |
+ <p><span class=label> |
1075 |
+ %=l 'wrg_LABEL_PRIVATE' |
1076 |
+ </span><span class=data> |
1077 |
+ % param 'Private' => $wrg_datas->{private} unless param 'Private'; |
1078 |
+ %=text_field 'Private' => size => '45', class => 'input' |
1079 |
+ <br></span></p> |
1080 |
+ |
1081 |
+ <p> |
1082 |
+ %=l 'wrg_DESC_PUBLIC_CONFIG' |
1083 |
+ </p> |
1084 |
+ |
1085 |
+ <p><span class=label> |
1086 |
+ %=l 'wrg_LABEL_PUBLIC' |
1087 |
+ </span><span class=data> |
1088 |
+ % param 'Public' => $wrg_datas->{public} unless param 'Public'; |
1089 |
+ %=text_field 'Public' => size => '45', class => 'input' |
1090 |
+ <br></span></p> |
1091 |
+ |
1092 |
+ <p> |
1093 |
+ %=l 'wrg_DESC_STATUS' |
1094 |
+ </p> |
1095 |
+ |
1096 |
+ <p><span class=label> |
1097 |
+ %=l 'STATUS' |
1098 |
+ </span><span class=data> |
1099 |
+ % param 'Status' => $wrg_datas->{status} unless param 'Status'; |
1100 |
+ %= select_field 'Status' => [[ (l 'DISABLED') => 'disabled'], [ (l 'ENABLED') => 'enabled']], class => 'input' |
1101 |
+ <br></span></p> |
1102 |
+ |
1103 |
+ <div class='center'> |
1104 |
+ %= submit_button l('MODIFY'), name => 'modify', class => 'action' |
1105 |
+ </div> |
1106 |
+ |
1107 |
+ %= hidden_field 'trt' => $wrg_datas->{trt} |
1108 |
+ %= hidden_field 'Wgconf' => $wrg_datas->{wgconf} |
1109 |
+ |
1110 |
+ % end |
1111 |
+ |
1112 |
+</div> |
1113 |
diff -urN smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/wireguard.html.ep smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/wireguard.html.ep |
1114 |
--- smeserver-wireguard-1.0.old/root/usr/share/smanager/themes/default/templates/wireguard.html.ep 1970-01-01 04:00:00.000000000 +0400 |
1115 |
+++ smeserver-wireguard-1.0/root/usr/share/smanager/themes/default/templates/wireguard.html.ep 2021-12-13 18:40:42.000000000 +0400 |
1116 |
@@ -0,0 +1,35 @@ |
1117 |
+% layout 'default', title => "Sme server 2 - wireguard"; |
1118 |
+ |
1119 |
+% content_for 'module' => begin |
1120 |
+<div id='module' class='localnetworks-panel'> |
1121 |
+ |
1122 |
+ % if ($config->{debug} == 1) { |
1123 |
+ <p> |
1124 |
+ %= dumper $c->current_route |
1125 |
+ %= dumper $wrg_datas |
1126 |
+ </p> |
1127 |
+ % } |
1128 |
+ % if ( stash 'error' ) { |
1129 |
+ <br><div class=sme-error> |
1130 |
+ %= $c->render_to_string(inline => stash 'error') |
1131 |
+ </div> |
1132 |
+ %} |
1133 |
+ |
1134 |
+ <h1><%= $title%></h1> |
1135 |
+ |
1136 |
+ % if ($wrg_datas->{trt} eq 'UPD') { |
1137 |
+ %= include 'partials/_wrg_upd' |
1138 |
+ %} elsif ($wrg_datas->{trt} eq 'NEW') { |
1139 |
+ %= include 'partials/_wrg_new' |
1140 |
+ %} elsif ($wrg_datas->{trt} eq 'QRC') { |
1141 |
+ %= include 'partials/_wrg_qrc' |
1142 |
+ %} elsif ($wrg_datas->{trt} eq 'MOD') { |
1143 |
+ %= include 'partials/_wrg_mod' |
1144 |
+ %} elsif ($wrg_datas->{trt} eq 'REM') { |
1145 |
+ %= include 'partials/_wrg_rem' |
1146 |
+ %} else { |
1147 |
+ %= include 'partials/_wrg_list' |
1148 |
+ %} |
1149 |
+ |
1150 |
+</div> |
1151 |
+%end |