VIVILPROJECT GEEKZONE
very technical part of some VIVILPROJECT projects
-------------------------------------------------

(c) 2010-2022 Sébastien WILLEMIJNS



Last version available on http://www.willemijns.com/geekzone.htm




   Some services (SKYDRIVE) which purpose virtual drive mapping does not accept than her product is a real remote drive (to avoid temporary traffic as temporary files, classical example is OpenOffice softwares loads some temp files during edition in the same directory) so they are an easy method to test if your virtual drive is on this case:
On a real HD this easy test batch below only create one file named "it_s_ok.txt" on "vivilproject-testdrive" directory: if you do not see ONLY this file on the directory, your remote dir is not a real virtual directory but only a gateway ;)
                                    test.bat
rem z:
rem cd \SKYDRIVE
md vivilproject-testdrive
cd vivilproject-testdrive
cd ..
rd /S /Q vivilproject-testdrive
md vivilproject-testdrive
cd vivilproject-testdrive
echo one.one > one.one
rename one.one one.two
move one.two three.two
copy three.two > it_s_ok.txt
del three.two
                                    







Following lines contains my batch on Windows XP French Version to stay forever on the VPN and block all your classical Internet traffic:
WARNING ! (for the moment ?) my batch will be not able to automaticallly reconnect VPNs if DSL or core VPN connexions hangs up !
"; launch-vpn.bat:                                    
set patte=
rem
rem
rem
rem
rem                             VIVILPROJECT BLOCK VPN v1.0 ALPHA
rem                     (c) 2010-$year www.contact.willemijns.com
rem
rem
rem
rem - Works well on XP SP3 with PPTP VPN
rem
rem
rem
rem 1) Download open source "gsar.exe" from
rem http://gnuwin32.sourceforge.net/packages/gsar.htm
rem
rem 2) Before beginning, you must reboot your computer and do a restore point
rem of your system because you can crash the system if you do an error.
rem
rem 3) Modify parameter below and execute batch
rem
rem 4) After the connexion to the VPN, the batch will create on your desktop
rem a file name "unblock-vpn.bat" which permit you to return to the net
rem                  WITH YOUR OWN IP GIVEN BY YOUR ISP
rem In others words, clicking on this link on your desktop restore your
rem classical Internet connexion WITH AN IMMEDIATE EFFECT AND LET THE !!! 
rem VPN CONNEXION IN WORK STATE (without traffic of course ;)WORKclassical Internet connexion WITH AN IMMEDIATE EFFECT AND LET THE
rem
rem
rem                    TYPE YOUR DEFAULT GATEWAY OF YOUR DSL ROUTER
set fixedip=192.168.1.1
rem                    TYPE THE NUMBER CORRESPONDING TO YOUR REAL NETWORK CARD  
rem                    Mine is "NVIDIA nForce Networking Controller - ...."
set networkcard=2
rem                    TYPE THE DIRECTORY NAME OF YOUR DESKTOP
set desktopname=bureau
rem                    TYPE THE CHOOSEN NAME OF THE VPN
set vpnname="IBVPN"
rem                    TYPE THE TRANSLATION OF "Defaut gataway" displayed
rem                                by the "route" command-line   
set gatwyname="Passerelle par défaut"


route print > %TEMP%\vivilproject-blokvpn1
find %gatwyname% %TEMP%\vivilproject-blokvpn1 > %TEMP%\vivilproject-blokvpn2.bat
%patte%gsar.exe -s:x20 -r -o %TEMP%\vivilproject-blokvpn2.bat
%patte%gsar.exe -s:x3A -r:x0D:x0Aset:x20ipvpnold= -o %TEMP%\vivilproject-blokvpn2.bat
call %TEMP%\vivilproject-blokvpn2.bat
rasphone -d %vpnname%
route print > %TEMP%\vivilproject-blokvpn1
find %gatwyname% %TEMP%\vivilproject-blokvpn1 > %TEMP%\vivilproject-blokvpn2.bat
%patte%gsar.exe -s:x20 -r -o %TEMP%\vivilproject-blokvpn2.bat
%patte%gsar.exe -s:x3A -r:x0D:x0Aset:x20ipvpnnew= -o %TEMP%\vivilproject-blokvpn2.bat
call %TEMP%\vivilproject-blokvpn2.bat
@cls
@echo.
@echo     Actually:
@echo     - Choosen network card is "0x%networkcard%"
@echo     - Choosen network card is now "%ipvpnnew%" (old was "%ipvpnold%")
@echo.
@find " ..." %TEMP%\vivilproject-blokvpn1
@echo.
@echo  ********************* PRESS A KEY TO LAUNCH PROCESS *************************
@echo.
@pause
route delete 0.0.0.0 %fixedip%
echo cls > "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo VIVILPROJECT UNBLOCK VPN >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo v1.0 ALPHA (c) 2010 www.contact.willemijns.com >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo RESTORE YOUR VPN TO THE DEFAULT GATEWAY IF "%fixedip%" >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo ON THE VIRTUAL NETWORK CARD NUMBER "%networkcard%" ARE GOOD VALUES FOR YOU ! >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo Execute this batch to restore your connexion >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo If you have any trouble after the process, use your restore point !!! >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo NO HELP CAN BE GIVEN. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo Press 3 times on any key now to validate process. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @pause >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @pause >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @pause >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo route add 0.0.0.0 mask 0.0.0.0 %fixedip% IF %networkcard% >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo Done. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo I repeat again: >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo If you have any trouble now, use your restore point !!! >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @echo NO HELP CAN BE GIVEN. >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
echo @pause >> "%USERPROFILE%\%desktopname%\unblock-vpn.bat"
                                    







Now this is the AUTOHOTKEY script to automatically launch OPENVPN sessions...
do not forget to see the common warnings too ;)
--------------------------------------------------------------------------------
#Persistent
SetTimer, EnterAuth, 250
return

EnterAuth:
Process, wait, openvpn-gui-1.0.3.exe, 2
If %ErrorLevel% = 0
{
Run, c:\Progra~1\OpenVPN\bin\openvpn-gui-1.0.3.exe --connect YOUR_OVPN_FILE.ovpn
}

IfWinExist OpenVPN - User Authentication
{
WinActivate, OpenVPN - User Authentication
ControlSetText, Edit1, YOUR_USERNAME, OpenVPN - User Authentication ahk_class #32770
ControlSetText, Edit2, YOUR_PASSWORD, OpenVPN - User Authentication ahk_class #32770
ControlSend, Edit1, {Enter}, OpenVPN - User Authentication ahk_class #32770
}
return
--------------------------------------------------------------------------------







Now this is the method to launch OPENVPN on Windows as a service...
3 conditions:
1a) You must use an OpenVPN build with "-enable-password-save" option. (http://www.acevpn.com/2009/12/07/openvpn-build-with-save-password-enabled/)
2) Keep only ONE KEYSET on the "config" directory ! (usually the .crt file and one .ovpn file)
3) In the .ovpn file change "auth-user-pass" to "auth-user-pass foo.txt"

FYI i have noticed the VPN connexion only works again after 2/3 minutes if an hang-up occurs (IP renewing, ISP disconnection, you unplug modem by error...)
do not afraid during this time no core traffic is transferred by your real IP :)
do not forget to see the common warnings too ;)
--------------------------------------------------------------------------------
net stop openvpnservice
c:\progra~1\openvpn\bin\openvpnserv -remove
c:\progra~1\openvpn\bin\openvpnserv -install
echo YOUR_USERNAME> c:\progra~1\openvpn\config\foo.txt
echo YOUR_PASSWORD>> c:\progra~1\openvpn\config\foo.txt
net start openvpnservice
del c:\progra~1\openvpn\config\foo.txt
--------------------------------------------------------------------------------







COMMON WARNING: NEVER FORGET THIS BATCH IS NOT LAUNCHED AT THE BOOT !!!
To detect "on the fly" what is your actual IP, you can use a batch thanks to curl and this php script on a webhoster:
I offer you the php script, build yourself the batch ;)
* (DynIP) if myIP contains "." *AND* does not contains ".dyn.myisp.com" then launch...
* (FixedIP) if myIP is not " 93.251.200.56 " then launch...
--------------------------------------- whatismyip.php
<?php echo " ";
echo $_SERVER["REMOTE_ADDR"];
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
echo " ";
echo $hostname; echo " ";
 ?>
---------------------------------------










How to inscrease cronjobs to create regular cronjobs of less than 1 minute ?
Solution is given by a cronjob hoster, thanks to him ;)
--------------------------------------------------------------------------------
<?php
# script to increase cronjobs to less than 1 minute
# Offered by SETCRONJOB
  // Cron settings
  $cron_url="http://yoursite.com/path/to/cron.php"; // Cron URL here.
  $time_interval=20; // Time interval needed (second).
  $real_time_interval=1; // Real time interval (minute).
  
  
  set_time_limit(0);
  ignore_user_abort(1);
  
  $number_of_execution=floor($real_time_interval*60/$time_interval);
  for($i=0; $i<$number_of_execution; $i++) {
    $time=microtime(1);
    file_get_contents($cron_url);
    $time=microtime(1)-$time;
    $i<$number_of_execution and sleep($time_interval-$time);
  }
?>
---------------------------------------







   Some services refuse you change their default directory ("My Dropbox" is a well-known example, they are others methods to bypass this:
W7, VISTA:mklink /J "C:\Users\YOURNAME\Documents\Dropbox\DesiredFolder" "C:\Path\To\Desired\Folder"
XP:fsutil hardlink create "C:\Path\To\Desired\Folder" "C:\Documents and Settings\User\My Documents\My Dropbox\DesiredFolder"
DROPBOX GUI or other generic method for others OSes are here.







How to compare byte per byte a folder on commandline ?
Use Testpath v1.3 http://www.parks.lv/home/ojarsk/DL.htm or http://ojars.lv/dl.htm
-------------------------- go.bat
del *.log
set path1=e:\ex_humyo
set path2=d:\ex_humyo
testpath.exe /A "%path1%" "%path2%" /R "log1.log" /OS7
testpath.exe /A "%path2%" "%path1%" /R "log2.log" /OS7
notepad log1.log
notepad log2.log
---------------------------------------






What's new ?
February 28 2010: Creation of this document.
June 28 2010: Add VPN things.
July 1 2010: Add CRONJOB thing.
May 10 2011: Add SyncotherMethod thing.
January 12 2012: Add how to compare files/folders ?



Send here your feedbacks
I REPEAT THAN NO HELP WILL BE GIVEN TO THIS WEBPAGE !!!!!