<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; CMD/BAT: AFTOGEN - OpenVPN CCD-config & certificate generation script]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=6195</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=6195&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «CMD/BAT: AFTOGEN - OpenVPN CCD-config & certificate generation script».]]></description>
		<lastBuildDate>Thu, 08 Sep 2011 06:59:26 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[CMD/BAT: AFTOGEN - OpenVPN CCD-config & certificate generation script]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=51308#p51308</link>
			<description><![CDATA[<p><a href="http://rghost.ru/20827661.image"><span class="postimg"><img src="http://rghost.ru/20827661/thumb.png" alt="http://rghost.ru/20827661/thumb.png" /></span></a></p><div class="codebox"><pre><code>
@REM #######################################
@REM ############ CONFGURATION #############
@REM #######################################
@
@rem enable custom OpenVPN path usage [&quot;default&quot; | &quot;custom&quot;]
@set rfid.ovpn.use_path=custom
@
@rem path to your openvpn non standard directory (ATTENTION! no trailing slashes might be placed)
@set rfid.ovpn.path.custom=C:\Documents and Settings\dafanasiev\Рабочий стол\bin\OpenVPN
@set rfid.ovpn.check_bins=yes
@
@rem does script should check required files presence &amp; versions
@set rfid.ovpn.keys.policy=backup
@set rfid.ovpn.backup.path=backup
@set rfid.ovpn.keys.new_ca=yes
@
@rem create list of certificates [boolean option]
@set rfid.ovpn.crt.multigen=yes
@set rfid.ovpn.crt.mgen_start=0
@set rfid.ovpn.crt.mgen_stop=7
@set rfid.ovpn.crt.mgen.make_ccd=yes
@
@rem automate client number to subject CN option and output files names
@set rfid.ovpn.crt.mgen_autonum=yes
@
@rem enable this option if certificate should be signed, use &quot;1&quot; or &quot;yes&quot; without quotes
@set rfid.ovpn.crt.use_sign=yes
@
@rem --- CERTFICATE subject options ---
@    set rfid.ovpn.crt.CN.custom=client
@
@rem trigger, enables using custom certificate subject options
@    set rfid.ovpn.crt.more_opts=no
@
@rem RDN customization, e.g. CN -&gt; CommonName for certificates
@rem RDN synthax: /C=CountryName/ST=Providence/..
@    set rfid.ovpn.crt.C.custom=RU
@    set rfid.ovpn.crt.ST.custom=NW
@    set rfid.ovpn.crt.L.custom=Saint-Petersburg
@    set rfid.ovpn.crt.O.custom=RKT
@    set rfid.ovpn.crt.OU.custom=ITDep
@    set rfid.ovpn.crt.EML.custom=shenin@controlenergo.ru

@rem verbosity level
@    set rfid.ovpn.ui.debug=0
@    set rfid.ovpn.ui.logging=yes
@    set rfid.ovpn.ui.logpath=logs
@    set rfid.ovpn.ui.clear_screen=no



@REM #######################################
@REM ############# PREPARING ###############
@REM #######################################
@echo off
cls
echo.
chcp 1251&gt;nul
setlocal enabledelayedexpansion
set rfid.ovpn.cd=%cd%

rem Ctrl+C fix
rem if not &quot;%1&quot; == &quot;exec&quot; (
rem         cmd /c &quot;echo y | %0 exec %1&quot;
rem         goto :EOF
rem )
rem shift

if &quot;%rfid.ovpn.ui.logpath%&quot; == &quot;&quot; set &quot;%rfid.ovpn.ui.logpath%&quot;=logs

rem OpenVPN defaults
    set rfid.ovpn.path.default=%programfiles%\OpenVPN
    set rfid.ovpn.keys.path=keys
	rem applying configured paths
	if &quot;%1&quot; == &quot;&quot; (
		if &quot;%rfid.ovpn.use_path%&quot; == &quot;&quot; set rfid.ovpn.use_path=default
		set rfid.ovpn.path=!rfid.ovpn.path.%rfid.ovpn.use_path%!
	) else (
		set rfid.ovpn.path=!rfid.ovpn.path.%1!
	)
rem openssl preparing
    set rfid.ovpn.ossl.lpath=bin\openssl.exe
	set rfid.ovpn.ossl.path=&quot;%rfid.ovpn.path%\%rfid.ovpn.ossl.lpath%&quot;
    set rfid.ovpn.ossl.gendir=easy-rsa
    set rfid.ovpn.ossl.cfgpath=&quot;%rfid.ovpn.path%\easy-rsa\openssl.cnf&quot;
    set rfid.ovpn.ossl.genca_opts=req -days 3650 -nodes -new -x509 -config %rfid.ovpn.ossl.cfgpath% -batch
    set rfid.ovpn.ossl.genreq_opts=req -config %rfid.ovpn.ossl.cfgpath% -days 3650 -nodes -new -multivalue-rdn -batch
    set rfid.ovpn.ossl.gencrt_opts=ca -config %rfid.ovpn.ossl.cfgpath% -days 3650 -batch
rem OpenVPN CCD configuration
    set rfid.ovpn.ccd.path=config\ccd
    set rfid.ovpn.ccd.net.default=10.10.1.
rem RDN certificate subject defaults
    set rfid.ovpn.crt.CN.default=client
    set rfid.ovpn.crt.C.default=RU
    set rfid.ovpn.crt.ST.default=NW
    set rfid.ovpn.crt.L.default=Saint-Petersburg
    set rfid.ovpn.crt.O.default=Radiofid
    set rfid.ovpn.crt.OU.default=development
    set rfid.ovpn.crt.EML.default=support@radiofid.ru



REM ############ proc start ###############

echo    iRZ® AFTOGEN
echo  =======================================================================
echo    OpenVPN certificate generation ^&amp; client configuration script
echo.
echo    Author: ********* ******
echo    iRZ® - is registered trademark of RADIOFID Corp. All rights reserved.
echo  -----------------------------------------------------------------------
echo.
rem checking selected path to OpenVPN directory
echo   [#] checking %rfid.ovpn.use_path% OpenVPN path
if not exist &quot;!rfid.ovpn.path!&quot; (
    if &quot;%rfid.ovpn.use_path%&quot; == &quot;custom&quot; (
        if &quot;%rfid.ovpn.path%&quot; == &quot;&quot; (
            set /p rfid.runvar=  [?] undefined custom path, use default OpenVPN path instead? [y/n] 
            if &quot;!rfid.runvar!&quot; == &quot;y&quot; (
                echo   [i] checking default OpenVPN path
                set rfid.ovpn.path=%rfid.ovpn.path.default%
                if exist &quot;!rfid.ovpn.path!&quot; goto cert_prep
                echo       [E] directory &quot;!rfid.ovpn.path!&quot; not found
                echo.
            )
        )
    ) else (
        echo       [E] directory &quot;%rfid.ovpn.path%&quot; not found
        echo.
    )
    echo   [E] unable to continue, install OpenVPN first, or verify option
    echo       &#039;rfid.ovpn.use_path&#039;, acceptable values: &#039;default&#039;, &#039;custom&#039;
    echo   [i] if you are selected custom path you also must set option
    echo       &#039;rfid.ovpn.path.custom&#039; with real path to your OpenVPN binaries
    echo.
    goto unload
) else (
	rem enter main dir
	echo   [D] entering easy-rsa directory
	cd %rfid.ovpn.path%\%rfid.ovpn.ossl.gendir%
	rem echo   [D] current directory changed to &#039;%rfid.ovpn.path%\%rfid.ovpn.ossl.gendir%&#039;
	echo   [*] applying VARS for further usage
	call vars &gt;nul 2&lt;&amp;1
	
	call :backup_prep

	rem prepare logging
	if &quot;%rfid.ovpn.ui.logging%&quot; == &quot;yes&quot; (
		if &quot;%rfid.ovpn.ui.logpath%&quot; == &quot;&quot; (
			set rfid.ovpn.ui.logpath=%rfid.ovpn.path%\%rfid.ovpn.ossl.gendir%\logs
		) else (
			set rfid.ovpn.ui.logpath=%rfid.ovpn.path%\%rfid.ovpn.ossl.gendir%\%rfid.ovpn.ui.logpath%
		)
		if not exist &quot;!rfid.ovpn.ui.logpath!&quot; md &quot;!rfid.ovpn.ui.logpath!&quot;
		if not exist &quot;!rfid.ovpn.ui.logpath!&quot; (
			set rfid.ovpn.ui.logging=ERROR_PATH_NOT_FOUND
			echo   [E] unable to access logging path, loggind disabled
			goto jmp_1
		)
		if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
			echo   [i] logging enabled, log to:
			echo.
			echo       !rfid.ovpn.ui.logpath!\
			echo.
		)
	)
	:jmp_1
    rem switching to check binaries proc if needed
	if &quot;%rfid.ovpn.check_bins%&quot; == &quot;yes&quot; goto check_bins
	if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; echo   [i] binaries check disabled
	goto check_ca
)

:backup_prep
	rem backup option analyze
	if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;&quot; (
		set rfid.ovpn.keys.policy=backup
		echo   [i] old openvpn files policy not set, defaulting to &#039;backup&#039;
		goto jmp_2
	)
	if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;replace&quot; (
		echo   [i] file replacement enabled
		goto jmp_2
	)
	if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;backup&quot; (
		echo   [i] backup files creation enabled
		goto jmp_2
	)
	echo   [i] unknown client old files policy &#039;%rfid.ovpn.keys.policy%&#039;
	echo       -i- defaulting to &#039;backup&#039; policy
	set rfid.ovpn.keys.policy=backup
	:jmp_2
goto :eof

REM ####### checking binaries ##########
:check_bins
	echo   [#] checking for neccessary binaries ^&amp; directories..
	echo.
	rem echo %rfid.ovpn.ossl.path%
	rem echo !%rfid.ovpn.ossl.path!

	if exist &quot;%rfid.ovpn.path%\%rfid.ovpn.ossl.gendir%!&quot; (
		if exist %rfid.ovpn.ossl.path% (
			echo         * openssl.exe   - [OK]
			if exist %rfid.ovpn.ossl.cfgpath% (
			echo         * openssl.cnf   - [OK]
			
				echo         * easy-rsa\     - [OK]
				goto check_ca
			) else echo         * openssl.cnf   - [NOT FOUND]
		) else echo         * openssl.exe   - [NOT FOUND]
	) else echo         * easy-rsa\     - [NOT FOUND]
	echo.
	echo   [E] unable to continue, seems your OpenVPN installation is corrupted,
	echo       please reinstall OpenVPN first and try again
goto unload



REM ####### checking CA files ##########
:check_ca
	rem check VPN-server private key
	if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
		echo.
		echo   [#] checking server root CA private key
	)
	if not exist &quot;%rfid.ovpn.path%\easy-rsa\%rfid.ovpn.keys.path%\ca.key&quot; (
		echo.
		echo   [E] server CA root private key not found!
		set /p rfid.runvar=  [?] generate server key now? [y/n] 
		if &quot;!rfid.runvar!&quot; == &quot;y&quot; goto ca_gen
		:cagen_callback
		if exist &quot;%rfid.ovpn.path%\easy-rsa\%rfid.ovpn.keys.path%\ca.key&quot; goto cert_prep
		echo   [E] unable to generate clients certificates while CA key is missing
		goto :unload
	) else if &quot;%rfid.ovpn.keys.new_ca%&quot; == &quot;yes&quot; (
		echo.
		goto ca_gen
	)
goto cert_prep



:ca_gen
	echo   [*] generating server root CA key
	if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;2&quot; (
		rem set
		rem echo rfid.ovpn.ossl.path		= %rfid.ovpn.ossl.path%
		rem echo rfid.ovpn.ossl.genca_opts	= %rfid.ovpn.ossl.genca_opts%
	)
	if exist &quot;%rfid.ovpn.keys.path%\ca.key&quot; (
		if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;backup&quot; (
			if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
				echo       -F- moving old server root CA key &#039;&quot;%rfid.ovpn.keys.path%\ca.key&quot;&#039;
			)
			move &quot;%rfid.ovpn.keys.path%\ca.key&quot; &quot;%rfid.ovpn.keys.path%\ca.key.old&quot; &gt;nul 2&lt;&amp;1
		) else if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;replace&quot; (
			if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
				echo       -F- removing old server root CA key &#039;&quot;%rfid.ovpn.keys.path%\ca.key&quot;&#039;
			)
			del /q /f &quot;%rfid.ovpn.keys.path%\ca.key&quot; &gt;nul 2&lt;&amp;1
		)
	)
	if exist &quot;%rfid.ovpn.keys.path%\ca.crt&quot; (
		if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;backup&quot; (
			if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
				echo       -F- moving old server root certificate &#039;&quot;%rfid.ovpn.keys.path%\ca.crt&quot;&#039;
			)
			move &quot;%rfid.ovpn.keys.path%\ca.crt&quot; &quot;%rfid.ovpn.keys.path%\ca.crt.old&quot; &gt;nul 2&lt;&amp;1
		) else if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;replace&quot; (
			if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
				echo       -F- removing old server root certificate &#039;&quot;%rfid.ovpn.keys.path%\ca.crt&quot;&#039;
			)
			del /q /f &quot;%rfid.ovpn.keys.path%\ca.crt&quot; &gt;nul 2&lt;&amp;1
		)
	)
	set rfid.ovpn.ossl.genca=%rfid.ovpn.ossl.path% %rfid.ovpn.ossl.genca_opts%	^
		-keyout %rfid.ovpn.keys.path%\ca.key									^
		-out %rfid.ovpn.keys.path%\ca.crt

	if &quot;%rfid.ovpn.ui.logging%&quot; == &quot;yes&quot; (
		echo %date% %time% &gt; !rfid.ovpn.ui.logpath!\ossl_ca_key_crt_gen.log
		echo ---------------------- &gt;&gt; !rfid.ovpn.ui.logpath!\ossl_ca_key_crt_gen.log
		!rfid.ovpn.ossl.genca! &gt;&gt; !rfid.ovpn.ui.logpath!\ossl_ca_key_crt_gen.log 2&lt;&amp;1
	) else if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;2&quot; (
		!rfid.ovpn.ossl.genca!
	) else !rfid.ovpn.ossl.genca! &gt;nul 2&lt;&amp;1

	rem goto :eof
	rem move %rfid.ovpn.keys.path%\ca.crt %rfid.ovpn.keys.path%\ca.crt_
	if not exist &quot;%rfid.ovpn.keys.path%\ca.key&quot; (
		echo   [E] new server CA key not found, unable to continue
		set errorlevel=1
		goto unload
	)
goto cagen_callback



REM ### certificate preparing section ###
:cert_prep
	if &quot;%rfid.ovpn.ui.clear_screen%&quot; == &quot;yes&quot; cls
	title AFTOGEN :: Certificates setup
	echo.
	echo    ^&lt;^&lt;^&lt; Certificate user information ^&gt;^&gt;^&gt;
	echo    ------------------------------------
	rem setting Common Name
	if &quot;%rfid.ovpn.crt.CN.custom%&quot; == &quot;&quot; (
		set rfid.runvar=
		set /p rfid.runvar=  [?] Common Name option not set, enter name [%rfid.ovpn.crt.CN.default%]: 
		if &quot;!rfid.runvar!&quot; == &quot;&quot; (
			echo   [i] using default CN
			set rfid.ovpn.crt.CN=%rfid.ovpn.crt.CN.default%
		) else (
			set rfid.ovpn.crt.CN=!rfid.runvar!
		)
	) else (
		set rfid.ovpn.crt.CN=%rfid.ovpn.crt.CN.custom%
	)
	rem customize additional certificate options [TODO, currently unsupported]
	if &quot;%rfid.ovpn.crt.more_opts%&quot; == &quot;yes&quot; goto more_cert_opts
	rem apply default RDNs
	echo   [i] using default certificate subject RDN
	set rfid.ovpn.crt.C=%rfid.ovpn.crt.C.default%
	set rfid.ovpn.crt.ST=%rfid.ovpn.crt.ST.default%
	set rfid.ovpn.crt.L=%rfid.ovpn.crt.L.default%
	set rfid.ovpn.crt.O=%rfid.ovpn.crt.O.default%
	set rfid.ovpn.crt.OU=%rfid.ovpn.crt.OU.default%
	set rfid.ovpn.crt.EML=%rfid.ovpn.crt.EML.default%
	set rfid.ovpn.crt.rdn=/C=%rfid.ovpn.crt.C%/ST=%rfid.ovpn.crt.ST%/L=%rfid.ovpn.crt.L%/O=%rfid.ovpn.crt.O%/OU=%rfid.ovpn.crt.OU%/CN=%rfid.ovpn.crt.CN%
	if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
		goto sh_opts
	) else (
		goto cert_gen
	)



:more_cert_opts
echo   [i] using custom certificate subject RDN
set rfid.ovpn.crt.C=%rfid.ovpn.crt.C.custom%
set rfid.ovpn.crt.ST=%rfid.ovpn.crt.ST.custom%
set rfid.ovpn.crt.L=%rfid.ovpn.crt.L.custom%
set rfid.ovpn.crt.O=%rfid.ovpn.crt.O.custom%
set rfid.ovpn.crt.OU=%rfid.ovpn.crt.OU.custom%
set rfid.ovpn.crt.EML=%rfid.ovpn.crt.EML.custom%
set rfid.ovpn.crt.rdn=/C=%rfid.ovpn.crt.C%/ST=%rfid.ovpn.crt.ST%/L=%rfid.ovpn.crt.L%/O=%rfid.ovpn.crt.O%/OU=%rfid.ovpn.crt.OU%/CN=%rfid.ovpn.crt.CN%
if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
    goto sh_opts
) else (
    goto cert_gen
)



:sh_opts
echo.
echo     • CommonName is set to         &#039;%rfid.ovpn.crt.CN%&#039;
echo     • Country is set to            &#039;%rfid.ovpn.crt.C%&#039;
echo     • Providence is set to         &#039;%rfid.ovpn.crt.ST%&#039;
echo     • City is set to               &#039;%rfid.ovpn.crt.L%&#039;
echo     • Organization is set to       &#039;%rfid.ovpn.crt.O%&#039;
echo     • Organization Unit is set to  &#039;%rfid.ovpn.crt.OU%&#039;
echo     • Support E-mail is set to     &#039;%rfid.ovpn.crt.EML%&#039;
goto cert_gen


:deb_JMP
	echo   [i] using following RDN map:
	echo.
	echo       %rfid.ovpn.crt.rdn%/emailAddress=%rfid.ovpn.crt.EML%
	echo.
	echo   [*] assembling OpenSSL call
	goto cert_mgen

REM ######## generation section ############
:cert_gen
	if &quot;%rfid.ovpn.ui.clear_screen%&quot; == &quot;yes&quot; cls
	title AFTOGEN :: Certificate ^&amp; CCD generation
	echo.
	echo    ^&lt;^&lt;^&lt; Certificate generation ^&gt;^&gt;^&gt;
	echo    ------------------------------

	goto deb_JMP
	cd /d %rfid.ovpn.path%
	if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
		if not errorlevel == 1 (
			echo   [D] current directory changed to &#039;%rfid.ovpn.path%&#039;
		) else (
			echo   [E] unable to enter OpenVPN directory, please check if it was
			echo       deleted during script execution befor this call
		)
	)


:update_idx
	rem echo.
	rem echo    update_idx^(^)^:
	rem set rfid.ovpn.indexupdated
	rem echo.
	if exist &quot;%rfid.ovpn.keys.path%\index.txt&quot; (
		if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;replace&quot; (
			if not &quot;%rfid.ovpn.indexupdated%&quot; == &quot;1&quot; (
				echo       -*- flushing Index
				rem echo IDXCP
				copy &quot;%rfid.ovpn.keys.path%\..\index.txt.start&quot; &quot;%rfid.ovpn.keys.path%\index.txt&quot; &gt;nul 2&lt;&amp;1
				copy &quot;%rfid.ovpn.keys.path%\..\serial.start&quot; &quot;%rfid.ovpn.keys.path%\serial&quot; &gt;nul 2&lt;&amp;1
				set rfid.ovpn.indexupdated=1
			)
			echo.
			echo %rfid.ovpn.indexupdate%
			echo !rfid.ovpn.indexupdate!
			echo.	
		) else if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;backup&quot; (
			if not &quot;%rfid.ovpn.indexupdated%&quot; == &quot;1&quot; (
				rem echo IDXCP
				if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
					echo       -*- moving old Index
				)
				copy /y &quot;%rfid.ovpn.keys.path%\index.txt&quot; &quot;%rfid.ovpn.keys.path%\index.txt.old&quot; &gt;nul 2&lt;&amp;1
				copy /y &quot;%rfid.ovpn.keys.path%\serial&quot; &quot;%rfid.ovpn.keys.path%\serial.old&quot; &gt;nul 2&lt;&amp;1
				echo       -*- flushing Index
				copy /y &quot;%rfid.ovpn.keys.path%\..\index.txt.start&quot; &quot;%rfid.ovpn.keys.path%\index.txt&quot; &gt;nul 2&lt;&amp;1
				copy /y &quot;%rfid.ovpn.keys.path%\..\serial.start&quot; &quot;%rfid.ovpn.keys.path%\serial&quot; &gt;nul 2&lt;&amp;1
				set rfid.ovpn.indexupdated=1
			)
		)
	)
goto :eof



:cert_mgen
	echo.
	echo   [i] MGEN enabled
	set rfid.ovpn.crt.rdn.orig=%rfid.ovpn.crt.rdn%
	set rfid.ovpn.crt.CN.orig=%rfid.ovpn.crt.CN%
	if &quot;%rfid.ovpn.crt.mgen.make_ccd%&quot; == &quot;yes&quot; (
		echo   [i] CCD generator enabled [CCD -^&gt; %rfid.ovpn.ccd.path%, NET -^&gt; %rfid.ovpn.ccd.net.default%0]
		set rfid.ovpn.ccd.path=%rfid.ovpn.path%\%rfid.ovpn.ccd.path%
	)

	for /l %%i in (%rfid.ovpn.crt.mgen_start%,1,%rfid.ovpn.crt.mgen_stop%) do (

		if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;2&quot; (
			echo   [D] genstart ^(%%i of %rfid.ovpn.crt.mgen_stop% - %rfid.ovpn.crt.mgen_start%^)
		)
		if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
			echo       -*- appending number postfix in RDN CN option
		)
		set rfid.ovpn.crt.rdn=%rfid.ovpn.crt.rdn.orig%_%%i\/%rfid.ovpn.crt.EML%
		set rfid.ovpn.mgen.filename=%rfid.ovpn.crt.CN.orig%_%%i

		
		set rfid.ovpn.ossl.genreq=%rfid.ovpn.ossl.path% %rfid.ovpn.ossl.genreq_opts%	^
		 -keyout %rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.key					^
		 -out %rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.csr						^
		 -subj !rfid.ovpn.crt.rdn!
		set rfid.ovpn.ossl.gencrt=%rfid.ovpn.ossl.path% %rfid.ovpn.ossl.gencrt_opts%	^
		 -out %rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.crt						^
		 -in %rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.csr
		rem updating logpath for current environ
		set rfid.ovpn.ui.logpath=%rfid.ovpn.path%\%rfid.ovpn.ossl.gendir%\%rfid.ovpn.ui.logpath%

		rem calculating CCD file path &amp; contents
			if &quot;%rfid.ovpn.crt.mgen.make_ccd%&quot; == &quot;yes&quot; (
				if not exist &quot;%rfid.ovpn.ccd.path%&quot; (
					md &quot;%rfid.ovpn.ccd.path%&quot;
					if not exist &quot;%rfid.ovpn.ccd.path%&quot; (
						set rfid.ovpn.crt.mgen.make_ccd=no
						echo   [E] unable to create CCD, CCD generator disabled
					) else (
						if &quot;rfid.ovpn.ui.debug&quot; GEQ &quot;1&quot; (
							echo       -D- CCD created
						)
					)
				)
				if &quot;%rfid.ovpn.crt.mgen_start%&quot; == &quot;0&quot; (
					set rfid.runvar.loctapp=2
				) else if &quot;%rfid.ovpn.crt.mgen_start%&quot; == &quot;1&quot; (
					set rfid.runvar.loctapp=1
				) else set rfid.runvar.loctapp=0
				set /a rfid.runvar.lastoctet=&quot;%%i+rfid.runvar.loctapp&quot;
				set rfid.runvar.caddr=%rfid.ovpn.ccd.net.default%!rfid.runvar.lastoctet!
			)

		REM GENERATOR
			if exist &quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.key&quot; (
				if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;replace&quot; (
					call :update_idx
					if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
						echo       -F- replacing &#039;!rfid.ovpn.mgen.filename!.key&#039; with new one
					)
					del /q /f &quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.key&quot; &gt;nul 2&lt;&amp;1
					if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
						echo       -F- replacing &#039;!rfid.ovpn.mgen.filename!.csr&#039; with new one
					)
					del /q /f &quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.csr&quot; &gt;nul 2&lt;&amp;1
				) else if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;backup&quot; (
					call :update_idx
					if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
						echo       -F- moving old &#039;!rfid.ovpn.mgen.filename!.key&#039; key
					)
					rem echo &quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.key&quot;
					move	&quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.key&quot; ^
							&quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.key.old&quot; &gt;nul 2&lt;&amp;1
					if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
						echo       -F- moving old certificate request &#039;!rfid.ovpn.mgen.filename!.csr&#039;
					)
					move	&quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.csr&quot; ^
							&quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.csr.old&quot; &gt;nul 2&lt;&amp;1
				)
			)
			
			if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
				echo       -K- generating certificate request for %rfid.ovpn.crt.CN%_%%i..
			)
			
			if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;2&quot; (
				rem set
				rem echo rfid.ovpn.crt.rdn			-   !rfid.ovpn.crt.rdn!
				rem echo rfid.ovpn.mgen.filename  	-   !rfid.ovpn.mgen.filename!
				rem echo rfid.ovpn.ossl.genreq      -   !rfid.ovpn.ossl.genreq!
				rem echo rfid.ovpn.ossl.gencrt      -   !rfid.ovpn.ossl.gencrt!
				rem echo rfid.ovpn.ossl.path        -   %rfid.ovpn.ossl.path%
			)
			rem creating keyfile &amp; certificate request
			if &quot;%rfid.ovpn.ui.logging%&quot; == &quot;yes&quot; (
				!rfid.ovpn.ossl.genreq! &gt; &quot;%rfid.ovpn.ui.logpath%&quot;\ossl_%rfid.ovpn.crt.CN%_%%i_reqgen.log 2&lt;&amp;1
			) else !rfid.ovpn.ossl.genreq! &gt;nul 2&lt;&amp;1

			if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; echo       -#- checking if CSR ^&amp; KEY files exist
			if not exist &quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.key&quot; (
				echo.
				echo   [E] exiting, new keyfile &#039;!rfid.ovpn.mgen.filename!.key&#039; not found &amp; goto unload
			)
			if not exist &quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.csr&quot; (
				echo.
				echo   [E] exiting, new key-request file&#039;!rfid.ovpn.mgen.filename!.csr&#039; not found &amp; goto unload
			)
		REM GENERATOR 2
			if exist &quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.crt&quot; (
				call :update_idx
				if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;replace&quot; (
					if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
						echo       -F- replacing &#039;!rfid.ovpn.mgen.filename!.crt&#039; with new one
					)
					del /q /f &quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.crt&quot; &gt;nul 2&lt;&amp;1
				) else if  &quot;%rfid.ovpn.keys.policy%&quot; == &quot;backup&quot; (
					call :update_idx
					if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; (
						echo       -F- moving old certificate &#039;!rfid.ovpn.mgen.filename!.crt&#039;
					)
					move	&quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.crt&quot; ^
							&quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.crt.old&quot; &gt;nul 2&lt;&amp;1
				)
			)
			rem creating certificate
			if &quot;%rfid.ovpn.crt.mgen.make_ccd%&quot; == &quot;yes&quot; (
				echo       -K- generating certificate for %rfid.ovpn.crt.CN%_%%i [!rfid.runvar.caddr!]..
			) else (
				echo       -K- generating certificate for %rfid.ovpn.crt.CN%_%%i..
			)

			if &quot;%rfid.ovpn.ui.logging%&quot; == &quot;yes&quot; (
				!rfid.ovpn.ossl.gencrt! &gt; &quot;%rfid.ovpn.ui.logpath%&quot;\ossl_%rfid.ovpn.crt.CN%_%%i_keygen.log 2&lt;&amp;1
			) else !rfid.ovpn.ossl.gencrt! &gt;nul 2&lt;&amp;1

			if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;1&quot; echo       -#- checking if certificate file exist
			if not exist &quot;%rfid.ovpn.keys.path%\!rfid.ovpn.mgen.filename!.crt&quot; (
				echo   [E] exiting, certificate file &#039;!rfid.ovpn.mgen.filename!.crt&#039; not found &amp; goto unload
			)

		rem MGEN improved with CCD implementation
			if &quot;%rfid.ovpn.crt.mgen.make_ccd%&quot; == &quot;yes&quot; (
				echo ifconfig-push %rfid.ovpn.ccd.net.default%1 !rfid.runvar.caddr!&gt;&quot;%rfid.ovpn.ccd.path%\!rfid.ovpn.mgen.filename!&quot;
				if &quot;%rfid.ovpn.ui.logging%&quot; == &quot;yes&quot; (
					copy &quot;%rfid.ovpn.ccd.path%\!rfid.ovpn.mgen.filename!&quot; &quot;%rfid.ovpn.ui.logpath%\!rfid.ovpn.mgen.filename!.ccd&quot; &gt;nul 2&lt;&amp;1
				)
			)
		)
	)
	rem cert req opts:     -keyout %rfid.ovpn.keys.path%\[client_name].key -out %rfid.ovpn.keys.path%\[client_name].csr -subj &quot;/C=CountryName/ST=Providence/L=CityName/CN=[client_name]&quot;
	rem cert dynamic opts: -out %rfid.ovpn.keys.path%\%1.crt -in %rfid.ovpn.keys.path%\%1.csr
	echo.
	echo   [+] work complete
	if &quot;%rfid.ovpn.keys.policy%&quot; == &quot;replace&quot; (
		echo   [X] cleanup..
		del /q /f %rfid.ovpn.keys.path%\*.old &gt;nul 2&lt;&amp;1
	)
goto :unload



REM ########## unload routine ##############
:unload
	echo   [ ] execution complete
	echo.
	if &quot;%rfid.ovpn.ui.debug%&quot; GEQ &quot;2&quot; (
		echo.
		echo   [D] ENV STACK:
		set rfid.ovpn
	)
	endlocal
	color
	title %CD%
:EOF</code></pre></div><p><a href="http://rghost.ru/20827981">мануал в MHT</a> (бета)<br />скрин старый, в представленном коде CCD уже работает</p><p>жду критики<br />спасибо)</p>]]></description>
			<author><![CDATA[null@example.com (dasknix)]]></author>
			<pubDate>Thu, 08 Sep 2011 06:59:26 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=51308#p51308</guid>
		</item>
	</channel>
</rss>
