вторник, 29 августа 2017 г.

Сверка пользователей для openvpn

 systemctl enable openvpn  - включает все openvpn.conf


/etc/openvpn/server/users
login:pass:+:

----
#!/usr/bin/perl -t
use strict;
my $server      = "users";
my $status      = "0";
my @z= localtime(time);
my $hou = $z[2];my $min = $z[1];my $sec = $z[0];my $day = $z[3];my $mon = $z[4];
if (length $z[2] eq 1) {$hou = "0".$hou;}
if (length $z[1] eq 1) {$min = "0".$min;}
if (length $z[0] eq 1) {$sec = "0".$sec;}
if (length $z[3] eq 1) {$day = "0".$day;}
if (length $z[4] eq 1) {$mon = "0".$mon;}

my $time =  $hou.
":".$min.":".$sec;
my $date =  $day.".".$mon.".".($z[5]+1900);
my $time =  $date." ".$time;

open (ifile,@ARGV[0]);
 my @all = {ifile};
 my $username    = @all[0];
 my $pass        = @all[1];
close(ifile);
#DEBUG
#open (tfile,">>/tmp/debug.env");
#foreach $key(keys %ENV){ print tfile $key." ".$ENV{$key}."\n";}
#close (tfile);

my $ip = $ENV{'untrusted_ip'};
chomp($username);chomp($pass);
open (ifile,"/etc/openvpn/".$server."/users");
@all={ifile};
close (ifile);
my $i=0;
while ($i}=$#all){
    my @pstr=split(":",@all[$i]);
    if ((@pstr[0] eq $username) and (@pstr[1] eq $pass) and (@pstr[2] eq "+")) {$status="1";}
    $i++;
}
if ($status eq "0"){open (erfile,">>/var/log/openvpn/test.error.log"); print erfile $time." ".$ip," ".$username." ".$pass."\n";close (erfile);}
if ($status eq "1"){open (okfile,">>/var/log/openvpn/test.status.log");print okfile $time." ".$ip." ".$username."\n";close (okfile);}

exit ($status eq "0");

Комментариев нет:

Отправить комментарий