Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.18 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3.  
  4.  
  5. use strict;
  6. use warnings;
  7. use Digest::MD5  qw(md5 md5_hex md5_base64);
  8. use version; our $VERSION = qv(0.01);
  9.  
  10. my $password_file = '/etc/openvpn/auth/user_password.txt';
  11. my $ARG = undef;
  12. if ( $ARG = shift @ARGV ) {
  13.     if ( !open( UPFILE, "<$ARG" ) ) {
  14.         print "Could not open username/password tmp file: $ARG\n";
  15.         exit 1;
  16.     }
  17. }
  18. else {
  19.     print "No username/password file specified on command line\n";
  20.     exit 1;
  21. }
  22.  
  23. my $username = <UPFILE>;
  24. my $password = <UPFILE>;
  25.  
  26. if ( !$username || !$password ) {
  27.     print "Username/password not found in tmp file: $ARG\n";
  28.     exit 1;
  29. }
  30.  
  31. chomp $username;
  32. chomp $password;
  33.  
  34. close(UPFILE);
  35.  
  36. if ( !open( USER_PASSWORD, "<$password_file" ) ) {
  37.     print "Could not open username/password db file: $ARG\n";
  38.     exit 1;
  39. }
  40. foreach my $line (<USER_PASSWORD>) {
  41.     chomp($line);
  42.     my ( $read_user, $read_password ) = split(/:/, $line);
  43.     if ( $read_user eq $username ) {
  44.         my $hex_password = md5_hex $password;
  45.         if ( $hex_password eq $read_password) {
  46.             close(USER_PASSWORD);
  47.             exit 0;
  48.         }
  49.         exit 1;
  50.     }
  51. }
  52.  
  53. close(USER_PASSWORD);
  54.  
  55. exit 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement