OpenVPN authorization without username and password entering
1. Editing OpenVPN configs for authorization without username and password entering by hand 2. OpenVPN configs already modified to auth without username and password entering 3. Scripts to modify OpenVPN configs for authorization without username and password – 3.1. BASH script – 3.2. Windows Batch script – 3.3. Perl script – 3.4. PHP script – 3.5. Python script – 3.6. Ruby script1. Editing OpenVPN configs by hand
It is necessary to edit OpenVPN config file to be authorized without username and password entering. Open selected config file (.ovpn) through text editor, replace line auth-user-pass by auth-user-pass auth.txt and save it.... auth-user-pass auth.txt ...OpenVPN client will get username and password from the file auth.txt which should be placed in the same directory as edited config file. The auth.txt must have 2 lines only: username on the first line and password on the second.
username password
The username and password are the same as the username and password of the DeepWebVPN Cabinet.
DON'T use the Notepad to edit a config file in the Windows, use WordPad, it shows UNIX like line breaks correctly.
2. Modified OpenVPN configs to auth without username and password entering
DeepWebVPN provides already modified OpenVPN configs to auth without username and password entering. There are available to download: archive of all OpenVPN configs, archive of the Single chains only and archive of the Double chains only.After unpacking downloaded archive don't forget to create file auth.txt like it is described in the Editing OpenVPN configs by hand subsection.
.
3. Scripts to modify OpenVPN configs
The described below scripts must have execute permission and be run in a appropriate interpreter.
The user who runs the script must have permission to modify config files.
3.1. BASH script
#!/bin/bash # Update all OpenVPN configs for use user login and password from file # profexer(https://rdot.org/forum/member.php?u=1143) for deepwebvpn.net, 2015 if [ $# -ne 3 ]; then echo 'Please, enter configs dir, your name and password.' exit fi if [ ! -d $1 ]; then echo -e '\e[91mConfigs dir not exists\e[39m' exit fi cd $1 if [ -f 'auth.txt' ]; then if [ ! -w 'auth.txt' ]; then echo -e '\e[91mPlease, fix permissions for auth.txt\e[39m' exit fi read -r -p 'File auth.txt exists. Rewrite (Y/n)? ' ans if [ "$ans" == "n" ] || [ "$ans" == "N" ]; then exit fi fi echo -e "$2\n$3" > auth.txt for fl in *.ovpn; do echo -n $fl if [ ! -r $fl ]; then echo -e "\e[91m NOT READABLE" elif [ ! -w $fl ]; then echo -e "\e[91m NOT WRITABLE" else sed -i 's/auth-user-pass/auth-user-pass auth.txt/' $fl echo -e "\e[92m OK" fi echo -ne "\e[39m" done
3.2. Windows Batch script
@echo off SetLocal EnableDelayedExpansion echo Update all OpenVPN configs for use user login and password from file. echo. Set /p dir="Enter configs dir: " Set /p name="Enter username: " Set /p pass="Enter password: " for /f "DELIMS=" %%i in ('dir "%dir%\*.ovpn" /b') do ( for /f "usebackq tokens=*" %%j in ("%dir%\%%i") do (set line=%%j& (<nul set /p a=!line:auth-user-pass=auth-user-pass auth.txt!& echo.)>>"%dir%\.tmp") del "%dir%\%%i" & ren "%dir%\.tmp" "%%i") (<nul set /p a=%name%& echo.& <nul set /p a=%pass%) > "%dir%\auth.txt" echo. pause
3.3. Perl script
#!/usr/bin/perl if (@ARGV != 3) { print "Usage: make_auth.pl <configs dir> <username> <password>\n"; exit 1; } my ($config_dir, $username, $password) = @ARGV; #if ((substr $config_dir, -1) != "/") { $config_dir = $config_dir . "/"; #} my @configs = glob $config_dir . "*.ovpn"; print $configs; if (@configs < 1) { print "No config files found in directory or not enough permissions"; exit 1; } foreach $config_file (@configs) { print "Modifying $config_file\n"; open my $lines, $config_file or die "Could not open $config_file: $!"; my @config; while(my $line = <$lines>) { my $line_trim = $line; $line_trim =~ s/^\s+|\s+$//g; if ($line_trim eq "auth-user-pass") { $line =~ s/auth-user-pass/auth-user-pass auth.txt/g; } push @config, $line; } close $lines; open my $fh, ">", $config_file; while (@config > 0) { $line = shift @config; print $fh $line; } close $fh; } open my $fh, ">", $config_dir . "auth.txt"; print $fh $username . "\n" . $password . "\n"; close $fh; print "OK\n";
3.4. PHP script
<?php # Update all OpenVPN configs for use user login and password from file # profexer(https://rdot.org/forum/member.php?u=1143) for deepwebvpn.net, 2015 if($argc!=4) die("Please, enter configs dir, your name and password.\n"); if( !is_dir($argv[1]) ) die("\033[91mConfigs dir not exists.\033[0m\n"); if( !@chdir($argv[1]) ) die("\033[91mCan't open configs dir. Please, check permissions.\033[0m\n"); if( file_exists('auth.txt') ) { if( is_dir('auth.txt') ) die("Funny)\n"); if( !is_writable('auth.txt') ) die("\033[91mPlease, fix permissions for auth.txt\033[0m\n"); echo 'File auth.txt exists. Rewrite (Y/n)? '; $c = fread(STDIN, 1); if($c=='n' || $c=='N') die; } file_put_contents('auth.txt', $argv[2]."\n".$argv[3]); $fls = glob("*.ovpn"); foreach($fls as $fl) if( !is_dir($fl) ) { echo $fl; if( !is_readable($fl) ) echo "\033[91m NOT READABLE\033[0m"; elseif( !is_writable($fl) ) echo "\033[91m NOT WRITABLE\033[0m"; else { file_put_contents($fl, preg_replace('#auth-user-pass#m', 'auth-user-pass auth.txt', file_get_contents($fl))); echo "\033[92m OK\033[0m"; } echo "\n"; } ?>
3.5. Python script
#!/usr/bin/python import sys, glob if len(sys.argv) != 4: print "Usage: ./%s <configs dir> <username> <password>" % (sys.argv[0]) sys.exit(0) config_dir = sys.argv[1] if sys.argv[1][-1] == "/" else sys.argv[1] + "/" username = sys.argv[2] password = sys.argv[3] glob_res = glob.glob(config_dir + "*.ovpn") if len(glob_res) == 0: print 'No config files found. Maybe wrong dir?' sys.exit(1) try: for config in glob_res: print "Modifying %s" % (config) content = [] for line in open(config, "r"): if "auth-user-pass" == line.strip(): content.append(line.replace("auth-user-pass", "auth-user-pass auth.txt")) else: content.append(line) with open(config, "w") as config_file: config_file.write("".join(content)) with open(config_dir + "auth.txt", "w") as auth_file: auth_file.write(username + "\n") auth_file.write(password + "\n") print "OK" except: print "Error occured. May be insufficient permissions?" sys.exit(1)
3.6. Ruby script
#!/usr/bin/env ruby if ARGV.size!=3 puts "Usage: ./make_auth.rb <configs dir> <username> <password>" exit(0) end config_dir=ARGV[0] username=ARGV[1] password=ARGV[2] Dir.glob("#{config_dir}/*.ovpn").each do |ovpn| print "Reconfig #{ovpn}...\t" content=[] File.open(ovpn, 'r') do |fl| while !fl.eof str=fl.gets str="auth-user-pass auth.txt\n" if str.include?('auth-user-pass') content << [str] end end File.open(ovpn, 'w') do |fl| fl.puts content.join("") end puts "done" File.open("#{config_dir}/auth.txt", 'w') do |auth| auth.puts username auth.puts password end end