/[smecontribs]/rpms/smeserver-openvpn-bridge/contribs8/smeserver-openvpn-bridge-2.0-code_cleanup1.patch
ViewVC logotype

Contents of /rpms/smeserver-openvpn-bridge/contribs8/smeserver-openvpn-bridge-2.0-code_cleanup1.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Sun Mar 3 21:14:33 2013 UTC (11 years, 8 months ago) by unnilennium
Branch: MAIN
CVS Tags: smeserver-openvpn-bridge-2_0-49_el5_sme, smeserver-openvpn-bridge-2_0-55_el5_sme, smeserver-openvpn-bridge-2_0-48_el5_sme, smeserver-openvpn-bridge-2_0-56_el5_sme, smeserver-openvpn-bridge-2_0-51_el5_sme, smeserver-openvpn-bridge-2_0-52_el5_sme, smeserver-openvpn-bridge-2_0-53_el5_sme, smeserver-openvpn-bridge-2_0-54_el5_sme, smeserver-openvpn-bridge-2_0-47_el5_sme, smeserver-openvpn-bridge-2_0-50_el5_sme, HEAD
Initial import

1 --- smeserver-openvpn-bridge-2.0/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/openvpnbridge.pm.code_cleanup1 2009-11-17 23:18:32.000000000 +0100
2 +++ smeserver-openvpn-bridge-2.0/root/usr/lib/perl5/site_perl/esmith/FormMagick/Panel/openvpnbridge.pm 2009-11-18 08:48:37.000000000 +0100
3 @@ -24,9 +24,9 @@
4 download_file
5 print_custom_button
6 print_section_bar
7 - write_pem
8 - read_pem
9 - disconnect_client
10 + write_pem
11 + read_pem
12 + disconnect_client
13 );
14
15 our $config_db = esmith::ConfigDB->open || die "Couldn't open ConfigDB\n";
16 @@ -47,43 +47,43 @@
17
18 # Retourne le paramètre demandé
19 sub get_prop{
20 - my ($fm, $prop, $default) = @_;
21 - return $config_db->get_prop("openvpn-bridge", $prop) || $default;
22 + my ($fm, $prop, $default) = @_;
23 + return $config_db->get_prop("openvpn-bridge", $prop) || $default;
24 }
25
26 # Retourne l'état du service
27 sub get_status{
28 - my ($fm) = @_;
29 - my $status = get_prop('','status','disabled');
30 - if ($status eq 'enabled'){
31 - return $fm->localise('ENABLED');
32 - }
33 - else{
34 - return $fm->localise('DISABLED');
35 - }
36 + my ($fm) = @_;
37 + my $status = get_prop('','status','disabled');
38 + if ($status eq 'enabled'){
39 + return $fm->localise('ENABLED');
40 + }
41 + else{
42 + return $fm->localise('DISABLED');
43 + }
44 }
45
46 # Retourne le mode d'authentification
47 sub get_auth_type{
48 - my ($fm) = @_;
49 - my $auth_type = get_prop('','userAuth');
50 - if ($auth_type eq 'CrtOnly'){
51 - return $fm->localise('CRT_ONLY');
52 - }
53 - elsif ($auth_type eq 'CrtWithPass'){
54 - return $fm->localise('CRT_WITH_PASS');
55 - }
56 - else{
57 - return $fm->localise('BAD_VALUE');
58 - }
59 + my ($fm) = @_;
60 + my $auth_type = get_prop('','userAuth');
61 + if ($auth_type eq 'CrtOnly'){
62 + return $fm->localise('CRT_ONLY');
63 + }
64 + elsif ($auth_type eq 'CrtWithPass'){
65 + return $fm->localise('CRT_WITH_PASS');
66 + }
67 + else{
68 + return $fm->localise('BAD_VALUE');
69 + }
70 }
71
72 # Retourne la plage d'adresses
73 sub get_ip_pool{
74 - my ($fm) = @_;
75 - my $start = get_prop('','startPool') || "x.x.x.x";
76 - my $end = get_prop('','endPool') || "x.x.x.x";
77 - return "$start - $end";
78 + my ($fm) = @_;
79 + my $start = get_prop('','startPool') || "x.x.x.x";
80 + my $end = get_prop('','endPool') || "x.x.x.x";
81 + return "$start - $end";
82 }
83
84 # Inscrit les valeurs de la configuration dans la db
85 @@ -93,8 +93,8 @@
86
87 $config_db->set_prop('openvpn-bridge', 'status', $q->param("status"));
88 $config_db->set_prop('openvpn-bridge', 'userAuth', $q->param("auth_type"));
89 - $config_db->set_prop('openvpn-bridge', 'startPool', $q->param("start_pool"));
90 - $config_db->set_prop('openvpn-bridge', 'endPool', $q->param("end_pool"));
91 + $config_db->set_prop('openvpn-bridge', 'startPool', $q->param("start_pool"));
92 + $config_db->set_prop('openvpn-bridge', 'endPool', $q->param("end_pool"));
93
94 unless ( system ("/sbin/e-smith/signal-event", "openvpn-bridge-update") == 0 ){
95 return $fm->error('ERROR_OCCURED', 'FIRST');;
96 @@ -105,7 +105,7 @@
97
98 # Affiche les connexions en cours
99 sub print_clients_table{
100 - my $fm = shift;
101 + my $fm = shift;
102 my $q = $fm->{cgi};
103 my $common_name = $fm->localise('COMMON_NAME');
104 my $real_ip = $fm->localise('REAL_IP');
105 @@ -113,12 +113,12 @@
106 my $sent = $fm->localise('SENT');
107 my $received = $fm->localise('RECEIVED');
108 my $connected_since = $fm->localise('CONNECTED_SINCE');
109 - my $disconnect = $fm->localise('DISCONNECT');
110 -
111 - # On récupère les paramètre et on les parse
112 - my $param = get_prop('',"management");
113 - my @param = split(/:/,$param);
114 - my $host = $param[0];
115 + my $disconnect = $fm->localise('DISCONNECT');
116 +
117 + # On récupère les paramètre et on les parse
118 + my $param = get_prop('',"management");
119 + my @param = split(/:/,$param);
120 + my $host = $param[0];
121 my $port = $param[1];
122 my $pass = $param[2];
123
124 @@ -127,17 +127,17 @@
125 host => $host,
126 port => $port,
127 password => $pass,
128 - timeout => 3
129 + timeout => 3
130 });
131
132 - # On se connecte ou on retourne le message d'erreur
133 - unless($vpn->connect()){
134 - print $q->Tr($q->td($fm->localise('ERROR_CONNECT_TO_MANAGER')));
135 - return "";
136 - }
137 + # On se connecte ou on retourne le message d'erreur
138 + unless($vpn->connect()){
139 + print $q->Tr($q->td($fm->localise('ERROR_CONNECT_TO_MANAGER')));
140 + return "";
141 + }
142 my $r = $vpn->status_ref();
143 -
144 - my %virtIP;
145 +
146 + my %virtIP;
147 my %realIP;
148 my %remotePort;
149 my %sentBytes;
150 @@ -148,167 +148,158 @@
151
152 foreach( @{$r->{CLIENT_LIST}} ){
153 my $CN = $$_[0];
154 - unshift (@commonNames,$CN);
155 - $virtIP{$_} = $$_[1];
156 - my @ipPort = split (/:/,$$_[1]);
157 - $realIP{$CN} = $ipPort[0];
158 - $remotePort{$CN} = $ipPort[1];
159 - $virtIP{$CN} = $$_[2];
160 - $receivedBytes{$CN} = $$_[3]/1048576;
161 - $receivedBytes{$CN} = sprintf("%.2f", $receivedBytes{$CN});
162 - $sentBytes{$CN} = $$_[4]/1048576;
163 - $sentBytes{$CN} = sprintf("%.2f", $sentBytes{$CN});
164 - $connectedSince{$CN} = $$_[5];
165 - }
166 -
167 - # Si @commonName est vide, il n'y a aucun client connecté
168 - unless ( scalar @commonNames ){
169 - print $q->Tr($q->td($fm->localise('NO_CLIENTS_CONNECTED')));
170 - return "";
171 + unshift (@commonNames,$CN);
172 + $virtIP{$_} = $$_[1];
173 + my @ipPort = split (/:/,$$_[1]);
174 + $realIP{$CN} = $ipPort[0];
175 + $remotePort{$CN} = $ipPort[1];
176 + $virtIP{$CN} = $$_[2];
177 + $receivedBytes{$CN} = $$_[3]/1048576;
178 + $receivedBytes{$CN} = sprintf("%.2f", $receivedBytes{$CN});
179 + $sentBytes{$CN} = $$_[4]/1048576;
180 + $sentBytes{$CN} = sprintf("%.2f", $sentBytes{$CN});
181 + $connectedSince{$CN} = $$_[5];
182 + }
183 +
184 + # Si @commonName est vide, il n'y a aucun client connecté
185 + unless ( scalar @commonNames ){
186 + print $q->Tr($q->td($fm->localise('NO_CLIENTS_CONNECTED')));
187 + return "";
188 }
189
190 - print $q->start_table({-CLASS => "sme-border"}),"\n";
191 + print $q->start_table({-CLASS => "sme-border"}),"\n";
192 print $q->Tr (
193 - esmith::cgi::genSmallCell($q, $common_name,"header"),
194 - esmith::cgi::genSmallCell($q, $real_ip,"header"),
195 - esmith::cgi::genSmallCell($q, $virtual_ip,"header"),
196 - esmith::cgi::genSmallCell($q, $sent,"header"),
197 - esmith::cgi::genSmallCell($q, $received,"header"),
198 - esmith::cgi::genSmallCell($q, $connected_since,"header"),
199 - esmith::cgi::genSmallCell($q, $disconnect,"header", 3)),"\n";
200 + esmith::cgi::genSmallCell($q, $common_name,"header"),
201 + esmith::cgi::genSmallCell($q, $real_ip,"header"),
202 + esmith::cgi::genSmallCell($q, $virtual_ip,"header"),
203 + esmith::cgi::genSmallCell($q, $sent,"header"),
204 + esmith::cgi::genSmallCell($q, $received,"header"),
205 + esmith::cgi::genSmallCell($q, $connected_since,"header"),
206 + esmith::cgi::genSmallCell($q, $disconnect,"header", 3)),"\n";
207 +
208 + foreach my $cn (@commonNames){
209 + print $q->Tr (esmith::cgi::genSmallCell($q,"$cn"),
210 + esmith::cgi::genSmallCell($q,"$realIP{$cn} ($remotePort{$cn})"),
211 + esmith::cgi::genSmallCell ($q, "$virtIP{$cn}"),
212 + esmith::cgi::genSmallCell ($q, "$sentBytes{$cn}".' MB'),
213 + esmith::cgi::genSmallCell ($q, "$receivedBytes{$cn}".' MB'),
214 + esmith::cgi::genSmallCell ($q, "$connectedSince{$cn}"),
215 + esmith::cgi::genSmallCell ($q, $q->a ({href => $q->url (-absolute => 1).
216 + $base_url."CLIENT_DISCONNECT_PAGE&common_name=".
217 + $cn}, $disconnect)));
218
219 - foreach my $cn (@commonNames){
220 - print $q->Tr (esmith::cgi::genSmallCell($q,"$cn"),
221 - esmith::cgi::genSmallCell($q,"$realIP{$cn} ($remotePort{$cn})"),
222 - esmith::cgi::genSmallCell ($q, "$virtIP{$cn}"),
223 - esmith::cgi::genSmallCell ($q, "$sentBytes{$cn}".' MB'),
224 - esmith::cgi::genSmallCell ($q, "$receivedBytes{$cn}".' MB'),
225 - esmith::cgi::genSmallCell ($q, "$connectedSince{$cn}"),
226 - esmith::cgi::genSmallCell ($q, $q->a ({href => $q->url (-absolute => 1).
227 - $base_url."CLIENT_DISCONNECT_PAGE&common_name=".
228 - $cn}, $disconnect)));
229 -
230 - }
231 - print $q->end_table,"\n";
232 - return "";
233 + }
234 + print $q->end_table,"\n";
235 + return "";
236 }
237
238 # Retourne la liste des règles
239 sub print_rules{
240 - my $fm = shift;
241 - my $q = $fm->{cgi};
242 -
243 - my @rules = $rules_db->get_all_by_prop(type => 'rule');
244 -
245 - unless (@rules){
246 + my $fm = shift;
247 + my $q = $fm->{cgi};
248 +
249 + my @rules = $rules_db->get_all_by_prop(type => 'rule');
250 +
251 + unless (@rules){
252 print $q->Tr($q->td($fm->localise('NO_RULE')));
253 return "";
254 }
255 -
256 - print $q->start_table({-CLASS => "sme-border"}),"\n";
257 - print $q->Tr (
258 - esmith::cgi::genSmallCell(
259 - $q, $fm->localise('COMMON_NAME'),"header"
260 - ),
261 - esmith::cgi::genSmallCell(
262 - $q, $fm->localise('IP_ADDRESS'),"header"
263 - ),
264 - esmith::cgi::genSmallCell(
265 - $q, $fm->localise('COMMENT'),"header"
266 - ),
267 - esmith::cgi::genSmallCell(
268 - $q, $fm->localise('GATEWAY_REDIRECTION'),"header"
269 - ),
270 - esmith::cgi::genSmallCell(
271 - $q, $fm->localise('ACCESS'),"header"
272 - ),
273 - esmith::cgi::genSmallCell(
274 - $q, $fm->localise('MODIFY'),"header"
275 - ),
276 +
277 + print $q->start_table({-CLASS => "sme-border"}),"\n";
278 + print $q->Tr (
279 esmith::cgi::genSmallCell(
280 - $q, $fm->localise('REMOVE'),"header"
281 - )
282 + $q, $fm->localise('COMMON_NAME'),"header"),
283 + esmith::cgi::genSmallCell(
284 + $q, $fm->localise('IP_ADDRESS'),"header"),
285 + esmith::cgi::genSmallCell(
286 + $q, $fm->localise('COMMENT'),"header"),
287 + esmith::cgi::genSmallCell(
288 + $q, $fm->localise('GATEWAY_REDIRECTION'),"header"),
289 + esmith::cgi::genSmallCell(
290 + $q, $fm->localise('ACCESS'),"header"),
291 + esmith::cgi::genSmallCell(
292 + $q, $fm->localise('MODIFY'),"header"),
293 + esmith::cgi::genSmallCell(
294 + $q, $fm->localise('REMOVE'),"header")
295 ),"\n";
296
297
298 - foreach (@rules){
299 + foreach (@rules){
300
301 - my $rule = $_->key;
302 - my $rec_rule = $rules_db->get("$rule");
303 + my $rule = $_->key;
304 + my $rec_rule = $rules_db->get("$rule");
305
306 - my $ip = $rec_rule->prop("ip") || $fm->localise('DYNAMIC');
307 - my $gw = $rec_rule->prop("redirectGW") || 'disabled';
308 - my $access = $rec_rule->prop("access") || 'allowed';
309 - $gw = ( $gw eq 'enabled')
310 - ? $fm->localise('ENABLED')
311 - : $fm->localise('DISABLED');
312 - $access = ( $access eq 'allowed')
313 - ? $fm->localise('ALLOWED')
314 - : $fm->localise('DENIED');
315 - print $q->Tr (esmith::cgi::genSmallCell($q,"$rule"),
316 - esmith::cgi::genSmallCell($q,"$ip"),
317 - esmith::cgi::genSmallCell($q,$rec_rule->prop("comment")),
318 - esmith::cgi::genSmallCell($q,$gw),
319 - esmith::cgi::genSmallCell($q,$access),
320 + my $ip = $rec_rule->prop("ip") || $fm->localise('DYNAMIC');
321 + my $gw = $rec_rule->prop("redirectGW") || 'disabled';
322 + my $access = $rec_rule->prop("access") || 'allowed';
323 + $gw = ( $gw eq 'enabled')
324 + ? $fm->localise('ENABLED')
325 + : $fm->localise('DISABLED');
326 + $access = ( $access eq 'allowed')
327 + ? $fm->localise('ALLOWED')
328 + : $fm->localise('DENIED');
329 + print $q->Tr (esmith::cgi::genSmallCell($q,"$rule"),
330 + esmith::cgi::genSmallCell($q,"$ip"),
331 + esmith::cgi::genSmallCell($q,$rec_rule->prop("comment")),
332 + esmith::cgi::genSmallCell($q,$gw),
333 + esmith::cgi::genSmallCell($q,$access),
334 esmith::cgi::genSmallCell ($q,
335 - $q->a ({href => $q->url (-absolute => 1).
336 - $base_url."CREATE_OR_MODIFY_RULE_PAGE&action=modify&common_name=".$rule}, $fm->localise('MODIFY'))),
337 + $q->a ({href => $q->url (-absolute => 1).
338 + $base_url."CREATE_OR_MODIFY_RULE_PAGE&action=modify&common_name=".$rule}, $fm->localise('MODIFY'))),
339 esmith::cgi::genSmallCell ($q,
340 - $q->a ({href => $q->url (-absolute => 1).
341 - $base_url."REMOVE_RULE_PAGE&common_name=".$rule}, $fm->localise('REMOVE'))));
342 + $q->a ({href => $q->url (-absolute => 1).
343 + $base_url."REMOVE_RULE_PAGE&common_name=".$rule}, $fm->localise('REMOVE'))));
344 }
345 - print $q->end_table,"\n";
346 - return "";
347 + print $q->end_table,"\n";
348 + return "";
349 }
350
351 # Ajouter ou modifier une règle
352 sub create_or_modify_rule{
353 - my ($fm) = @_;
354 - my $q = $fm->{cgi};
355 - my $rule = $q->param('common_name');
356 - my $comment = $q->param('comment');
357 - my $ip = $q->param('reserved_ip');
358 - my $gw_redirection = $q->param('gw_redirection');
359 - my $access = $q->param('access');
360 - my $action = $q->param('action');
361 -
362 - if ($action eq 'create'){
363 - if ($rules_db->get($rule)){
364 - $fm->error('CN_CONFLICT','RULES_PAGE');
365 - return undef;
366 - }
367 - my $msg = $fm->validate_common_name($rule);
368 - unless ($msg eq "OK"){
369 - return $fm->error($msg,'RULES_PAGE');
370 - }
371 - else{
372 - $rules_db->new_record(
373 - $rule,
374 - {
375 - comment => $comment,
376 - ip => $ip,
377 - redirectGW => $gw_redirection,
378 - access => $access,
379 - type => 'rule',
380 - }
381 - );
382 - }
383 -
384 - $fm->success('SUCCESS','RULES_PAGE');
385 - }
386 - elsif ($action eq 'modify'){
387 - my $rec_rule = $rules_db->get($rule);
388 - $rec_rule->set_prop('comment',$comment);
389 - $rec_rule->set_prop('ip',$ip);
390 - $rec_rule->set_prop('redirectGW',$gw_redirection);
391 - $rec_rule->set_prop('access',$access);
392 - }
393 - unless ( system ("/sbin/e-smith/signal-event", "openvpn-bridge-reload-ccd") == 0 ){
394 - $fm->error('ERROR_OCCURED','RULES_PAGE');
395 - return undef;
396 + my ($fm) = @_;
397 + my $q = $fm->{cgi};
398 + my $rule = $q->param('common_name');
399 + my $comment = $q->param('comment');
400 + my $ip = $q->param('reserved_ip');
401 + my $gw_redirection = $q->param('gw_redirection');
402 + my $access = $q->param('access');
403 + my $action = $q->param('action');
404 +
405 + if ($action eq 'create'){
406 + if ($rules_db->get($rule)){
407 + $fm->error('CN_CONFLICT','RULES_PAGE');
408 + return undef;
409 + }
410 + my $msg = $fm->validate_common_name($rule);
411 + unless ($msg eq "OK"){
412 + return $fm->error($msg,'RULES_PAGE');
413 + }
414 + else{
415 + $rules_db->new_record(
416 + $rule,{
417 + comment => $comment,
418 + ip => $ip,
419 + redirectGW => $gw_redirection,
420 + access => $access,
421 + type => 'rule',
422 + }
423 + );
424 + }
425 +
426 + $fm->success('SUCCESS','RULES_PAGE');
427 }
428 - $fm->success('SUCCESS','RULES_PAGE');
429 -
430 + elsif ($action eq 'modify'){
431 + my $rec_rule = $rules_db->get($rule);
432 + $rec_rule->set_prop('comment',$comment);
433 + $rec_rule->set_prop('ip',$ip);
434 + $rec_rule->set_prop('redirectGW',$gw_redirection);
435 + $rec_rule->set_prop('access',$access);
436 + }
437 + unless ( system ("/sbin/e-smith/signal-event", "openvpn-bridge-reload-ccd") == 0 ){
438 + $fm->error('ERROR_OCCURED','RULES_PAGE');
439 + return undef;
440 + }
441 + $fm->success('SUCCESS','RULES_PAGE');
442 }
443
444 # Afficher le champ Nom Commun
445 @@ -317,9 +308,9 @@
446 my $q = $fm->{cgi};
447 my $rule = $fm->{cgi}->param('common_name') || '';
448 my $action = $fm->{cgi}->param('action') || '';
449 - print qq(<tr><td colspan="2">) . $fm->localise('DESC_COMMON_NAME').qq(</td></tr>);
450 + print qq(<tr><td colspan="2">) . $fm->localise('DESC_COMMON_NAME').qq(</td></tr>);
451 print qq(<tr><td class="sme-noborders-label">) .
452 - $fm->localise('COMMON_NAME') . qq(</td>\n);
453 + $fm->localise('COMMON_NAME') . qq(</td>\n);
454 if ($action eq 'modify' and $rule) {
455 print qq(
456 <td class="sme-noborders-content">$rule
457 @@ -339,7 +330,8 @@
458 $q->param(-name=>'access',-value=>
459 $rec_rule->prop('access'));
460 }
461 - } else {
462 + }
463 + else {
464 print qq(
465 <td><input type="text" name="common_name" value="$rule">
466 <input type="hidden" name="action" value="create">
467 @@ -349,35 +341,34 @@
468
469 print qq(</tr>\n);
470 return undef;
471 -
472 }
473
474
475 sub print_rule_to_remove{
476 - my ($fm) = @_;
477 - my $q = $fm->{cgi};
478 - my $rule = $q->param('common_name');
479 - my $rec_rule = $rules_db->get($rule);
480 - my $comment = $rec_rule->prop('comment');
481 -
482 - print $q->Tr(
483 - $q->td(
484 - { -class => 'sme-noborders-label' },
485 - $fm->localise('COMMON_NAME')
486 - ),
487 - $q->td( { -class => 'sme-noborders-content' }, $rule )
488 - ),
489 - "\n";
490 + my ($fm) = @_;
491 + my $q = $fm->{cgi};
492 + my $rule = $q->param('common_name');
493 + my $rec_rule = $rules_db->get($rule);
494 + my $comment = $rec_rule->prop('comment');
495 +
496 print $q->Tr(
497 - $q->td(
498 - { -class => 'sme-noborders-label' },
499 - $fm->localise('COMMENT')
500 - ),
501 - $q->td( { -class => 'sme-noborders-content' }, $comment )
502 - ),
503 - "\n";
504 -
505 - print $q->table(
506 + $q->td(
507 + { -class => 'sme-noborders-label' },
508 + $fm->localise('COMMON_NAME')
509 + ),
510 + $q->td( { -class => 'sme-noborders-content' }, $rule )
511 + ),
512 + "\n";
513 + print $q->Tr(
514 + $q->td(
515 + { -class => 'sme-noborders-label' },
516 + $fm->localise('COMMENT')
517 + ),
518 + $q->td( { -class => 'sme-noborders-content' }, $comment )
519 + ),
520 + "\n";
521 +
522 + print $q->table(
523 { -width => '100%' },
524 $q->Tr(
525 $q->th(
526 @@ -404,37 +395,37 @@
527 }
528
529 sub print_client_to_disconnect{
530 - my ($fm) = @_;
531 - my $q = $fm->{cgi};
532 - my $cn = $q->param('common_name');
533 -
534 - print $q->Tr(
535 - $q->td(
536 - { -class => 'sme-noborders-label' },
537 - $fm->localise('COMMON_NAME')
538 - ),
539 - $q->td( { -class => 'sme-noborders-content' }, $cn )
540 - ),
541 - "\n";
542 -
543 - print $q->table(
544 - { -width => '100%' },
545 - $q->Tr(
546 - $q->th(
547 - { -class => 'sme-layout' },
548 - $q->submit(
549 - -name => 'cancel',
550 - -value => $fm->localise('CANCEL')
551 - ),
552 - ' ',
553 - $q->submit(
554 - -name => 'disconnect',
555 - -value => $fm->localise('DISCONNECT')
556 - )
557 - )
558 - )
559 - ),
560 - "\n";
561 + my ($fm) = @_;
562 + my $q = $fm->{cgi};
563 + my $cn = $q->param('common_name');
564 +
565 + print $q->Tr(
566 + $q->td(
567 + { -class => 'sme-noborders-label' },
568 + $fm->localise('COMMON_NAME')
569 + ),
570 + $q->td( { -class => 'sme-noborders-content' }, $cn )
571 + ),
572 + "\n";
573 +
574 + print $q->table(
575 + { -width => '100%' },
576 + $q->Tr(
577 + $q->th(
578 + { -class => 'sme-layout' },
579 + $q->submit(
580 + -name => 'cancel',
581 + -value => $fm->localise('CANCEL')
582 + ),
583 + ' ',
584 + $q->submit(
585 + -name => 'disconnect',
586 + -value => $fm->localise('DISCONNECT')
587 + )
588 + )
589 + )
590 + ),
591 + "\n";
592
593 # Clear these values to prevent collisions when the page reloads.
594 $q->delete("cancel");
595 @@ -444,301 +435,297 @@
596 }
597
598 sub disconnect_client{
599 - my ($fm) = @_;
600 - my $q = $fm->{cgi};
601 - my $cn = $q->param('common_name');
602 - # On récupère les paramètre et on les parse
603 - my $param = get_prop('',"management");
604 - my @param = split(/:/,$param);
605 - my $host = $param[0];
606 + my ($fm) = @_;
607 + my $q = $fm->{cgi};
608 + my $cn = $q->param('common_name');
609 + # On récupère les paramètre et on les parse
610 + my $param = get_prop('',"management");
611 + my @param = split(/:/,$param);
612 + my $host = $param[0];
613 my $port = $param[1];
614 my $pass = $param[2];
615 - my $vpn = Net::OpenVPN::Manage->new({
616 + my $vpn = Net::OpenVPN::Manage->new({
617 host => $host,
618 port => $port,
619 password => $pass,
620 - timeout => 3
621 - });
622 - unless($q->param('cancel')){
623 - unless($vpn->connect()){
624 - $fm->error('ERROR_CONNECT_TO_MANAGER','SHOW_CLIENTS_PAGE');
625 - return undef;
626 - }
627 -
628 - unless($vpn->kill($cn)){
629 - $fm->error('ERROR_CONNECT_TO_MANAGER','SHOW_CLIENTS_PAGE');
630 - return undef;
631 - }
632 - $fm->success('CLIENT_DISCONNECTED','SHOW_CLIENTS_PAGE');
633 - return undef;
634 - }
635 - $fm->error('CANCELED','SHOW_CLIENTS_PAGE');
636 - return undef;
637 + timeout => 3
638 + });
639 + unless($q->param('cancel')){
640 + unless($vpn->connect()){
641 + $fm->error('ERROR_CONNECT_TO_MANAGER','SHOW_CLIENTS_PAGE');
642 + return undef;
643 + }
644 + unless($vpn->kill($cn)){
645 + $fm->error('ERROR_CONNECT_TO_MANAGER','SHOW_CLIENTS_PAGE');
646 + return undef;
647 + }
648 + $fm->success('CLIENT_DISCONNECTED','SHOW_CLIENTS_PAGE');
649 + return undef;
650 + }
651 + $fm->error('CANCELED','SHOW_CLIENTS_PAGE');
652 + return undef;
653 }
654
655 sub print_crt_not_ready_warning{
656 - my ($fm) = @_;
657 + my ($fm) = @_;
658
659 - # First, check the service "bridge" is running
660 - my $bridge = $config_db->get_prop('bridge', 'status') || 'disabled';
661 + # First, check the service "bridge" is running
662 + my $bridge = $config_db->get_prop('bridge', 'status') || 'disabled';
663
664 - unless ($bridge eq 'enabled'){
665 - return $fm->localise('BRIDGE_NOT_ENABLED');
666 - }
667 -
668 - # If any of the required files is missing or empty
669 - # Warn the user
670 - if (
671 - (( -z "$pubdir/cacert.pem" ) || ( ! -e "$pubdir/cacert.pem" )) ||
672 - (( -z "$pubdir/cert.pem") || ( ! -e "$pubdir/cert.pem" )) ||
673 - (( -z "$privdir/key.pem") || ( ! -e "$privdir/key.pem" )) ||
674 - (( -z "$pubdir/cacrl.pem") || ( ! -e "$pubdir/cacrl.pem" )) ||
675 - (( -z "$pubdir/dh.pem") || ( ! -e "$pubdir/dh.pem" ))
676 - ){
677 -
678 - return $fm->localise('CRT_CONFIG_ERROR');
679 - }
680 - return $fm->localise('CRT_CONFIG_OK');
681 + unless ($bridge eq 'enabled'){
682 + return $fm->localise('BRIDGE_NOT_ENABLED');
683 + }
684 +
685 + # If any of the required files is missing or empty
686 + # Warn the user
687 + if (
688 + (( -z "$pubdir/cacert.pem" ) || ( ! -e "$pubdir/cacert.pem" )) ||
689 + (( -z "$pubdir/cert.pem") || ( ! -e "$pubdir/cert.pem" )) ||
690 + (( -z "$privdir/key.pem") || ( ! -e "$privdir/key.pem" )) ||
691 + (( -z "$pubdir/cacrl.pem") || ( ! -e "$pubdir/cacrl.pem" )) ||
692 + (( -z "$pubdir/dh.pem") || ( ! -e "$pubdir/dh.pem" ))
693 + ){
694 +
695 + return $fm->localise('CRT_CONFIG_ERROR');
696 + }
697 + return $fm->localise('CRT_CONFIG_OK');
698 }
699
700 sub print_client_config{
701 - my ($fm) = @_;
702 - my $q = $fm->{cgi};
703 - my $proto = get_prop('','proto','udp');
704 - $proto = 'tcp-client' if ($proto eq 'tcp');
705 - my $port = ($proto eq 'udp' ? (get_prop('','UDPPort','1194')):(get_prop('','TCPPort','1194')));
706 - my $mtutest = get_prop('','mtuTest','enabled');
707 - my $fragment = get_prop('','fragment','');
708 - my $tunmtu = get_prop('','tunMtu','');
709 - my $cipher = get_prop('','cipher','');
710 - if ($proto eq 'tcp'){
711 - $mtutest = 'disabled';
712 - $fragment = '';
713 - }
714 + my ($fm) = @_;
715 + my $q = $fm->{cgi};
716 + my $proto = get_prop('','proto','udp');
717 + $proto = 'tcp-client' if ($proto eq 'tcp');
718 + my $port = ($proto eq 'udp' ? (get_prop('','UDPPort','1194')):(get_prop('','TCPPort','1194')));
719 + my $mtutest = get_prop('','mtuTest','enabled');
720 + my $fragment = get_prop('','fragment','');
721 + my $tunmtu = get_prop('','tunMtu','');
722 + my $cipher = get_prop('','cipher','');
723 + if ($proto eq 'tcp'){
724 + $mtutest = 'disabled';
725 + $fragment = '';
726 + }
727 my $fic = '';
728
729 - $fic .= "rport $port\n";
730 - $fic .= "proto $proto\n";
731 - $fic .= "dev tap\n";
732 - $fic .= "nobind\n";
733 - $fic .= "remote ".$config_db->get('SystemName')->value.".".$config_db->get('DomainName')->value."\n\n";
734 - $fic .= "tls-client\n";
735 - $fic .= "tls-auth takey.pem 1\n"
736 - if (( -e "$privdir/takey.pem")&&( !-z "$privdir/takey.pem"));
737 - $fic .= "ns-cert-type server\n\n";
738 - $fic .= (get_prop('','userAuth','CrtWithPass') eq 'CrtWithPass' ? "auth-user-pass\n\n" : "\n");
739 - $fic .= "# Replace user.p12 with the certificate\n# bundle in PKCS12 format\n";
740 - $fic .= "pkcs12 user.p12\n\n";
741 - $fic .= "# You can replace the pkcs12\n# directive with the old ones\n";
742 - $fic .= "#ca cacert.pem\n#cert user.pem\n#key user-key.pem\n\n";
743 - if ($mtutest eq 'enabled'){
744 - $fic .= "mtu-test\n";
745 - }
746 - elsif (($mtutest eq 'disabled')){
747 - if ($tunmtu ne ''){
748 - $fic .= "tun-mtu $tunmtu\n";
749 - }
750 - if (($proto eq 'udp') && ($fragment ne '')){
751 - $fic .= "fragment $fragment\nmssfix\n";
752 - }
753 - }
754 - $fic .= (get_prop('','compLzo','enabled') eq 'enabled' ? "comp-lzo\n" : "");
755 -
756 - $fic .= "cipher $cipher\n" if (($cipher ne '') && ($cipher ne 'auto'));
757 -
758 - $fic .= "pull\n";
759 -
760 - print(esmith::cgi::genTextRow($q, $q->textarea (-name => "config_file",
761 - -override => 1,
762 - -default => $fic,
763 - -rows => 30,
764 - -columns => 60)));
765 + $fic .= "rport $port\n";
766 + $fic .= "proto $proto\n";
767 + $fic .= "dev tap\n";
768 + $fic .= "nobind\n";
769 + $fic .= "remote ".$config_db->get('SystemName')->value.".".$config_db->get('DomainName')->value."\n\n";
770 + $fic .= "tls-client\n";
771 + $fic .= "tls-auth takey.pem 1\n"
772 + if (( -e "$privdir/takey.pem")&&( !-z "$privdir/takey.pem"));
773 + $fic .= "ns-cert-type server\n\n";
774 + $fic .= (get_prop('','userAuth','CrtWithPass') eq 'CrtWithPass' ? "auth-user-pass\n\n" : "\n");
775 + $fic .= "# Replace user.p12 with the certificate\n# bundle in PKCS12 format\n";
776 + $fic .= "pkcs12 user.p12\n\n";
777 + $fic .= "# You can replace the pkcs12\n# directive with the old ones\n";
778 + $fic .= "#ca cacert.pem\n#cert user.pem\n#key user-key.pem\n\n";
779 + if ($mtutest eq 'enabled'){
780 + $fic .= "mtu-test\n";
781 + }
782 + elsif (($mtutest eq 'disabled')){
783 + if ($tunmtu ne ''){
784 + $fic .= "tun-mtu $tunmtu\n";
785 + }
786 + if (($proto eq 'udp') && ($fragment ne '')){
787 + $fic .= "fragment $fragment\nmssfix\n";
788 + }
789 + }
790 + $fic .= (get_prop('','compLzo','enabled') eq 'enabled' ? "comp-lzo\n" : "");
791 + $fic .= "cipher $cipher\n" if (($cipher ne '') && ($cipher ne 'auto'));
792 + $fic .= "pull\n";
793 +
794 + print(esmith::cgi::genTextRow($q,
795 + $q->textarea (
796 + -name => "config_file",
797 + -override => 1,
798 + -default => $fic,
799 + -rows => 30,
800 + -columns => 60)
801 + )
802 + );
803 return "";
804 }
805
806
807 sub remove_rule{
808 - my ($fm) = @_;
809 - my $q = $fm->{cgi};
810 -
811 - my $rule = $q->param('common_name');
812 -
813 - unless($q->param("cancel")){
814 - unless ($rules_db->get($rule)->delete()){
815 - $fm->error('ERROR_OCCURED','RULES_PAGE');
816 - return undef;
817 - }
818 - unless (system ("/sbin/e-smith/signal-event", "openvpn-bridge-reload-ccd") == 0 ){
819 - $fm->error('ERROR_OCCURED','RULES_PAGE');
820 - return undef;
821 - }
822 - $fm->success('SUCCESS','RULES_PAGE');
823 - return undef;
824 + my ($fm) = @_;
825 + my $q = $fm->{cgi};
826 + my $rule = $q->param('common_name');
827 + unless($q->param("cancel")){
828 + unless ($rules_db->get($rule)->delete()){
829 + $fm->error('ERROR_OCCURED','RULES_PAGE');
830 + return undef;
831 + }
832 + unless (system ("/sbin/e-smith/signal-event", "openvpn-bridge-reload-ccd") == 0 ){
833 + $fm->error('ERROR_OCCURED','RULES_PAGE');
834 + return undef;
835 + }
836 + $fm->success('SUCCESS','RULES_PAGE');
837 + return undef;
838 }
839 - $fm->error('CANCELED','RULES_PAGE');
840 - return undef;
841 + $fm->error('CANCELED','RULES_PAGE');
842 + return undef;
843 }
844
845 sub print_custom_button{
846 - my ($fm,$desc,$url) = @_;
847 - my $q = $fm->{cgi};
848 - $url="openvpnbridge?page=0&page_stack=&Next=Next&wherenext=".$url;
849 -
850 - print " <tr>\n <td colspan='2'>\n";
851 + my ($fm,$desc,$url) = @_;
852 + my $q = $fm->{cgi};
853 + $url="openvpnbridge?page=0&page_stack=&Next=Next&wherenext=".$url;
854 +
855 + print " <tr>\n <td colspan='2'>\n";
856 print $q->p($q->a({href => $url, -class => "button-like"},
857 - $fm->localise($desc)));
858 + $fm->localise($desc)));
859 print qq(</tr>\n);
860 return undef;
861 }
862
863 sub print_section_bar{
864 - my ($fm) = @_;
865 - print " <tr>\n <td colspan='2'>\n";
866 - print "<hr class=\"sectionbar\"/>\n";
867 - return undef;
868 + my ($fm) = @_;
869 + print " <tr>\n <td colspan='2'>\n";
870 + print "<hr class=\"sectionbar\"/>\n";
871 + return undef;
872 }
873
874 sub read_pem{
875 - my ($fm,$pem) = @_;
876 - my $q = $fm->{cgi};
877 - my $dir = '';
878 - my $ret;
879 - if (($pem eq 'cacert.pem') || ($pem eq 'cert.pem') || ($pem eq 'dh.pem')){
880 - $dir = $pubdir;
881 - }
882 - elsif (($pem eq 'key.pem') || ($pem eq 'takey.pem')){
883 - $dir = $privdir;
884 - }
885 -
886 - if (! open (PEM, "<$dir/$pem")){
887 - $fm->error('ERROR_OPEN_PEM','FIRST');
888 - # Tell the user something bad has happened
889 - return;
890 + my ($fm,$pem) = @_;
891 + my $q = $fm->{cgi};
892 + my $dir = '';
893 + my $ret;
894 + if (($pem eq 'cacert.pem') || ($pem eq 'cert.pem') || ($pem eq 'dh.pem')){
895 + $dir = $pubdir;
896 + }
897 + elsif (($pem eq 'key.pem') || ($pem eq 'takey.pem')){
898 + $dir = $privdir;
899 }
900
901 - while (<PEM>){
902 - $ret .= $_;
903 - }
904 + if (! open (PEM, "<$dir/$pem")){
905 + $fm->error('ERROR_OPEN_PEM','FIRST');
906 + # Tell the user something bad has happened
907 + return;
908 + }
909 + while (<PEM>){
910 + $ret .= $_;
911 + }
912 + close PEM;
913
914 - close PEM;
915 -
916 - return $ret;
917 + return $ret;
918 }
919
920 sub write_pem{
921 - my ($fm) = @_;
922 - my $q = $fm->{cgi};
923 + my ($fm) = @_;
924 + my $q = $fm->{cgi};
925
926 - my $ca = $q->param('ca_pem');
927 - my $crt = $q->param('crt_pem');
928 - my $key = $q->param('key_pem');
929 - my $dh = $q->param('dhpar_pem');
930 - my $ta = $q->param('ta_pem');
931 -
932 - $config_db->set_prop('openvpn-bridge', 'CrlUrl', $q->param('crl_url'));
933 -
934 - if (! open (CA, ">$pubdir/cacert.pem")){
935 - $fm->error('ERROR_OPEN_CA','FIRST');
936 - # Tell the user something bad has happened
937 + my $ca = $q->param('ca_pem');
938 + my $crt = $q->param('crt_pem');
939 + my $key = $q->param('key_pem');
940 + my $dh = $q->param('dhpar_pem');
941 + my $ta = $q->param('ta_pem');
942 +
943 + $config_db->set_prop('openvpn-bridge', 'CrlUrl', $q->param('crl_url'));
944 +
945 + if (! open (CA, ">$pubdir/cacert.pem")){
946 + $fm->error('ERROR_OPEN_CA','FIRST');
947 + # Tell the user something bad has happened
948 return;
949 - }
950 - print CA $ca;
951 - close CA;
952 -
953 - if (! open (CRT, ">$pubdir/cert.pem")){
954 - $fm->error('ERROR_OPEN_CRT','FIRST');
955 - # Tell the user something bad has happened
956 + }
957 + print CA $ca;
958 + close CA;
959 +
960 + if (! open (CRT, ">$pubdir/cert.pem")){
961 + $fm->error('ERROR_OPEN_CRT','FIRST');
962 + # Tell the user something bad has happened
963 return;
964 - }
965 - print CRT $crt;
966 - close CRT;
967 -
968 - if (! open (KEY, ">$privdir/key.pem")){
969 - $fm->error('ERROR_OPEN_KEY','FIRST');
970 - # Tell the user something bad has happened
971 + }
972 + print CRT $crt;
973 + close CRT;
974 +
975 + if (! open (KEY, ">$privdir/key.pem")){
976 + $fm->error('ERROR_OPEN_KEY','FIRST');
977 + # Tell the user something bad has happened
978 return;
979 - }
980 - print KEY $key;
981 - close KEY;
982 -
983 - if (! open (DH, ">$pubdir/dh.pem")){
984 - $fm->error('ERROR_OPEN_DH','FIRST');
985 - # Tell the user something bad has happened
986 + }
987 + print KEY $key;
988 + close KEY;
989 +
990 + if (! open (DH, ">$pubdir/dh.pem")){
991 + $fm->error('ERROR_OPEN_DH','FIRST');
992 + # Tell the user something bad has happened
993 return;
994 - }
995 - print DH $dh;
996 - close DH;
997 -
998 - if (! open (TA, ">$privdir/takey.pem")){
999 - $fm->error('ERROR_OPEN_TA','FIRST');
1000 - # Tell the user something bad has happened
1001 + }
1002 + print DH $dh;
1003 + close DH;
1004 +
1005 + if (! open (TA, ">$privdir/takey.pem")){
1006 + $fm->error('ERROR_OPEN_TA','FIRST');
1007 + # Tell the user something bad has happened
1008 return;
1009 - }
1010 - print TA $ta;
1011 - close TA;
1012 -
1013 - # Restrict permissions on sensitive data
1014 - esmith::util::chownFile("root", "root","$privdir");
1015 - esmith::util::chownFile("root", "root","$pubdir");
1016 - chmod 0700, "$privdir";
1017 - chmod 0755, "$pubdir";
1018 -
1019 - unless(system("/sbin/e-smith/signal-event openvpn-bridge-update") == 0){
1020 - $fm->error('ERROR_OCCURED','RULES_PAGE');
1021 - return undef;
1022 - }
1023 - $fm->success('SUCCESS','FIRST');
1024 - return undef;
1025 + }
1026 + print TA $ta;
1027 + close TA;
1028 +
1029 + # Restrict permissions on sensitive data
1030 + esmith::util::chownFile("root", "root","$privdir");
1031 + esmith::util::chownFile("root", "root","$pubdir");
1032 + chmod 0700, "$privdir";
1033 + chmod 0755, "$pubdir";
1034 +
1035 + unless(system("/sbin/e-smith/signal-event openvpn-bridge-update") == 0){
1036 + $fm->error('ERROR_OCCURED','RULES_PAGE');
1037 + return undef;
1038 + }
1039 + $fm->success('SUCCESS','FIRST');
1040 + return undef;
1041 }
1042
1043
1044 # Validations
1045
1046 sub is_ip{
1047 - my ($fm,$ip) = @_;
1048 - return CGI::FormMagick::Validator::ip_number($fm, $ip);
1049 + my ($fm,$ip) = @_;
1050 + return CGI::FormMagick::Validator::ip_number($fm, $ip);
1051 }
1052
1053 sub ip_is_in_local_net {
1054 my ($fm,$ip) = @_;
1055 -
1056 +
1057 unless(is_ip($fm, $ip) eq 'OK'){
1058 - return $fm->localise('NOT_A_VALID_IP',{ip => $ip});
1059 + return $fm->localise('NOT_A_VALID_IP',{ip => $ip});
1060 }
1061 -
1062 +
1063 my $local_ip = $config_db->get('LocalIP')->value();
1064 my $local_netmask = $config_db->get('LocalNetmask')->value;
1065 my ($local_network, $local_broadcast) =
1066 - esmith::util::computeNetworkAndBroadcast( $local_ip, $local_netmask );
1067 -
1068 + esmith::util::computeNetworkAndBroadcast( $local_ip, $local_netmask );
1069 +
1070 my ($ip_network,$ip_broadcast) =
1071 - esmith::util::computeNetworkAndBroadcast($ip, $local_netmask);
1072 -
1073 - if ($ip_network ne $local_network){
1074 + esmith::util::computeNetworkAndBroadcast($ip, $local_netmask);
1075
1076 - return $fm->localise('NOT_IN_LOCAL_NET',{ip => $ip});
1077 + if ($ip_network ne $local_network){
1078 + return $fm->localise('NOT_IN_LOCAL_NET',{ip => $ip});
1079 }
1080 return "OK";
1081 }
1082
1083 sub ip_is_in_local_net_or_blank {
1084 - my ($fm,$ip) = @_;
1085 -
1086 - if ($ip eq ''){
1087 - return 'OK';
1088 - }
1089 - return ip_is_in_local_net ($fm,$ip);
1090 + my ($fm,$ip) = @_;
1091 +
1092 + if ($ip eq ''){
1093 + return 'OK';
1094 + }
1095 + return ip_is_in_local_net ($fm,$ip);
1096 }
1097
1098 sub end_is_after_start{
1099 - my ($fm,$end) = @_;
1100 - my $start = $fm->{cgi}->param('start_pool');
1101 - my $start_ip = new Net::IP($start);
1102 - my $end_ip = new Net::IP($end);
1103 - unless ($end_ip->bincomp('gt',$start_ip)){
1104 - return $fm->localise('START_AFTER_END');
1105 - }
1106 - return 'OK';
1107 + my ($fm,$end) = @_;
1108 + my $start = $fm->{cgi}->param('start_pool');
1109 + my $start_ip = new Net::IP($start);
1110 + my $end_ip = new Net::IP($end);
1111 + unless ($end_ip->bincomp('gt',$start_ip)){
1112 + return $fm->localise('START_AFTER_END');
1113 + }
1114 + return 'OK';
1115 }
1116
1117 sub not_in_dhcp_range
1118 @@ -754,19 +741,18 @@
1119 &&
1120 esmith::util::IPquadToAddr($address)
1121 <= esmith::util::IPquadToAddr($end)){
1122 - return $fm->localise("ADDR_IN_DHCP_RANGE",{ip => $address});
1123 - }
1124 - else{
1125 + return $fm->localise("ADDR_IN_DHCP_RANGE",{ip => $address});
1126 + }
1127 + else{
1128 return "OK";
1129 - }
1130 + }
1131 }
1132
1133 sub validate_common_name
1134 {
1135 my ($fm, $common_name) = @_;
1136
1137 - unless ($common_name =~ /^([a-zA-Z0-9][\_\.\-a-zA-Z0-9]*)$/)
1138 - {
1139 + unless ($common_name =~ /^([a-zA-Z0-9][\_\.\-a-zA-Z0-9]*)$/){
1140 return $fm->localise('INVALID_CHARS',{string => $common_name});
1141 }
1142 return "OK";
1143 @@ -777,10 +763,9 @@
1144 my ($fm, $url) = @_;
1145
1146 unless ($url =~ /^(http:\/\/)|(https:\/\/)/){
1147 - return $fm->localise('NOT_A_VALID_URL',{string => $url});
1148 - }
1149 + return $fm->localise('NOT_A_VALID_URL',{string => $url});
1150 + }
1151 return "OK";
1152 -
1153 }
1154
1155

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed