Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use Digest::MD5 qw(md5 md5_hex md5_base64);
- use version; our $VERSION = qv(0.01);
- my $password_file = '/etc/openvpn/auth/user_password.txt';
- my $ARG = undef;
- if ( $ARG = shift @ARGV ) {
- if ( !open( UPFILE, "<$ARG" ) ) {
- print "Could not open username/password tmp file: $ARG\n";
- exit 1;
- }
- }
- else {
- print "No username/password file specified on command line\n";
- exit 1;
- }
- my $username = <UPFILE>;
- my $password = <UPFILE>;
- if ( !$username || !$password ) {
- print "Username/password not found in tmp file: $ARG\n";
- exit 1;
- }
- chomp $username;
- chomp $password;
- close(UPFILE);
- if ( !open( USER_PASSWORD, "<$password_file" ) ) {
- print "Could not open username/password db file: $ARG\n";
- exit 1;
- }
- foreach my $line (<USER_PASSWORD>) {
- chomp($line);
- my ( $read_user, $read_password ) = split(/:/, $line);
- if ( $read_user eq $username ) {
- my $hex_password = md5_hex $password;
- if ( $hex_password eq $read_password) {
- close(USER_PASSWORD);
- exit 0;
- }
- exit 1;
- }
- }
- close(USER_PASSWORD);
- exit 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement