Sign in to follow this  
Followers 0
tjestr

Using variables outside a function

12 posts in this topic

#1 ·  Posted (edited)

Hello, I'm working on a small vpn client. I'm new to autoit and i don't know how to solve the following problem:

I get various errors that variables are not defined, but i don't know how i have to define them.

I want that the decrypted vpn informations can be used by other functions.

If you know how to, please help me :)

#include <constants.au3>
#include <guiconstants.au3>
#include <string.au3>

;----------Function Encrypt------------------------------------------------------------------

$crypt_password = "test"

func encrypt ()
    $encrypt_vpn_user = _StringEncrypt (1, "" & $vpn_user, "" & $crypt_password, 4)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', "" & $encrypt_vpn_user)

    $encrypt_vpn_password = _StringEncrypt (1, "" &$vpn_password, "" & $crypt_password, 6)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', "" & $encrypt_vpn_password)

    $encrypt_vpn_host = _StringEncrypt (1, "" & $vpn_host, "" & $crypt_password, 5)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', "" &$encrypt_vpn_host)

    $encrypt_vpn_site = _StringEncrypt (1, "" & $vpn_site, "" & $crypt_password, 3)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', "" &$encrypt_vpn_site)
EndFunc

;----------Function Decrypt------------------------------------------------------------------

func decrypt ()
    $decrypted_vpn_user_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', '')
    $decrypt_vpn_user = _StringEncrypt (0, "" & $decrypted_vpn_user_ini, "" & $crypt_password, 4)

    $decrypted_vpn_password_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', '')
    $decrypt_vpn_password = _StringEncrypt (0, "" & $decrypted_vpn_password_ini, "" & $crypt_password, 6)

    $decrypted_vpn_host_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', '')
    $decrypt_vpn_host = _StringEncrypt (0, "" & $decrypted_vpn_host_ini, "" & $crypt_password, 5)

    $decrypted_vpn_site_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', '')
    $decrypt_vpn_site = _StringEncrypt (0, "" & $decrypted_vpn_site_ini, "" & $crypt_password, 3)
EndFunc

;----------Function Read Input---------------------------------------------------------------

func readinput ()
    $vpn_user = GUICtrlRead($input_vpn_user)
    $vpn_password = GUICtrlRead($input_vpn_password)
    $vpn_host = GUICtrlRead($input_vpn_host)
    $vpn_site = GUICtrlRead($input_vpn_site)
EndFunc

;----------Select VPN Inforamtion------------------------------------------------------------



func selectvpninformation ()
    $WinMain = GuiCreate('VPN Informations', 320, 235)

    GuiCtrlCreateLabel('User:',10,40,70,20)
    GUICtrlCreateLabel('Password:',10,80,70,20)
    GuiCtrlCreateLabel('Host:',10,120,70,20)
    GuiCtrlCreateLabel('Sitename:',10,160,70,20)
    
    $input_vpn_user = GuiCtrlCreateInput('', 80,35,220,20)
    $input_vpn_password = GuiCtrlCreateInput('',80,75,220,20)
    $input_vpn_host = GuiCtrlCreateInput('', 80,115,220,20)
    $input_vpn_site = GuiCtrlCreateInput('', 80,155,220,20)
    
    $OKButton = GuiCtrlCreateButton('OK',240,185,60,35)

    GuiSetState()

    Do
       $Msg = GuiGetMsg()
       If $msg = $OKButton Then
            GuiSetState(@SW_DISABLE,$WinMain)
            
            call ("readinput")
            call ("encrypt")
            call ("decrypt")
          Exit
        EndIf
    Until $msg = $GUI_EVENT_CLOSE 
EndFunc
Edited by tjestr

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

; AutoIt Version: 3.0
; Language:       English
; Platform:       WinXP SP2
; Author:         Falko Dohse (fd@familiedohse.de)
; Function:       VPN Client to connect to a VPN server

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++ Includes ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#include <constants.au3>
#include <guiconstants.au3>
#include <createvpnsite.au3>
#include <cryption.au3>
#include <string.au3>
#NoTrayIcon

;----------Function Check Connection---------------------------------------------------

func readIpConfig()
    $foo = Run("rasdial", @SystemDir, @SW_HIDE, $STDOUT_CHILD)
    $output = ""
    While 1
        $output &= StdoutRead($foo)
        If @error Then ExitLoop
    WEnd
    return $output
EndFunc

;----------Function Show Connection Status---------------------------------------------

func checkstatus()
    $ipcfg = readIpConfig()
    if stringinstr($ipcfg,"Keine Verbindung") Then
        TraySetIcon("disconnected.ico")
        TrayTip("Not connected to VPN-Site","Disconnected from VPN-Site", 5)
    Else
        TraySetIcon("connected.ico")
        TrayTip("VPN connection succuessfully established","Connected to: " & $vpn_site, 5)
    EndIf
EndFunc

;-----------Function Startup Status----------------------------------------------------

func startupstatus()
    call ("readIpConfig")
    call ("checkstatus")
EndFunc

;----------Function Connect------------------------------------------------------------

$rasdial = "Rasdial.exe"

func connect ()
    RunWait($rasdial & " " & $vpn_site & " " & $vpn_user & " " & $vpn_password, "" , @SW_HIDE)
    sleep(3000)
    call ("readIpConfig")
    call ("checkstatus")
EndFunc

;----------Function Disconnect---------------------------------------------------------

func disconnect ()
    RunWait($rasdial & " " & $vpn_site & " /disconnect","", @SW_HIDE)
    sleep(500)
    call ("readIpConfig")
    call ("checkstatus")    
EndFunc

;----------Function Check Autostart----------------------------------------------------

Global $State[1]

func autostart ()
    If $State[0] = 1 Then
        TrayItemSetState($autostart, $TRAY_UNCHECKED)
        $State[0] = 0
    ElseIf  $State[0] = 0 Then
        TrayItemSetState($autostart, $TRAY_CHECKED)
        $State[0] = 1  
    EndIf
EndFunc

;----------Function Save State---------------------------------------------------------

Func SaveState()
    IniWrite(@ScriptDir & '\state.ini', 'STATE', 'AutoStart', $State[0])
EndFunc

;----------Function Load tate----------------------------------------------------------

Func LoadState()
    If FileExists(@ScriptDir & '\state.ini') Then
        $State[0] = IniRead(@ScriptDir & '\state.ini', 'STATE', 'AutoStart', '')
        If $State[0] = 1 Then
            TrayItemSetState($autostart, $TRAY_CHECKED)
            call ("connect")
        ElseIf $State[0] = 0 Then
            TrayItemSetState($autostart, $TRAY_UNCHECKED)
        EndIf   
    EndIf
EndFunc

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++ Main ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

call ("startupstatus")

;----------Tray Menue------------------------------------------------------------------

Opt("TrayMenuMode", 1)

$create_vpnsite = TrayCreateItem("Create VPN Site")
$create_blank = TrayCreateItem("")
$vpn_connect = TrayCreateItem("VPN connect")
$vpn_disconnect = TrayCreateItem("VPN disconnect")
$create_blank = TrayCreateItem("")
$autostart = TrayCreateItem("Autostart")
$create_blank = TrayCreateItem("")
$exit = TrayCreateItem("Exit")

TraySetState()
LoadState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $create_vpnsite
            call ("selectvpninformation")
            call ("createvpnsite")
        Case $msg = $vpn_connect
            call ("connect")
        Case $msg = $vpn_disconnect
            call ("disconnect")
        Case $msg = $autostart
            call ("autostart")
        Case $msg = $exit
            call ("SaveState")
            call ("disconnect")
            ExitLoop
    EndSelect
WEnd

Exit

Maybe I'm too confused to see the mistakes....

I've never coded such a programm before.

Edited by tjestr

Share this post


Link to post
Share on other sites

#include <constants.au3>
#include <guiconstants.au3>
#include <string.au3>

;----------Function Encrypt------------------------------------------------------------------
$crypt_password = "test"

;----------Select VPN Inforamtion------------------------------------------------------------

    $WinMain = GuiCreate('VPN Informations', 320, 235)

    GuiCtrlCreateLabel('User:',10,40,70,20)
    GUICtrlCreateLabel('Password:',10,80,70,20)
    GuiCtrlCreateLabel('Host:',10,120,70,20)
    GuiCtrlCreateLabel('Sitename:',10,160,70,20)
   
    $input_vpn_user = GuiCtrlCreateInput('', 80,35,220,20)
    $input_vpn_password = GuiCtrlCreateInput('',80,75,220,20)
    $input_vpn_host = GuiCtrlCreateInput('', 80,115,220,20)
    $input_vpn_site = GuiCtrlCreateInput('', 80,155,220,20)
   
    $OKButton = GuiCtrlCreateButton('OK',240,185,60,35)

    GuiSetState()

    Do
       $Msg = GuiGetMsg()
       If $msg = $OKButton Then
            GuiSetState(@SW_DISABLE,$WinMain)
           
            call ("readinput")
            call ("encrypt")
            call ("decrypt")
          Exit
        EndIf
    Until $msg = $GUI_EVENT_CLOSE

func encrypt ($vpn_user, $vpn_password, $vpn_site, $vpn_host)
    $encrypt_vpn_user = _StringEncrypt (1, "" & $vpn_user, "" & $crypt_password, 4)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', "" & $encrypt_vpn_user)

    $encrypt_vpn_password = _StringEncrypt (1, "" &$vpn_password, "" & $crypt_password, 6)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', "" & $encrypt_vpn_password)

    $encrypt_vpn_host = _StringEncrypt (1, "" & $vpn_host, "" & $crypt_password, 5)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', "" &$encrypt_vpn_host)

    $encrypt_vpn_site = _StringEncrypt (1, "" & $vpn_site, "" & $crypt_password, 3)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', "" &$encrypt_vpn_site)
EndFunc

;----------Function Decrypt------------------------------------------------------------------

func decrypt ()
    $decrypted_vpn_user_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', '')
    $decrypt_vpn_user = _StringEncrypt (0, "" & $decrypted_vpn_user_ini, "" & $crypt_password, 4)

    $decrypted_vpn_password_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', '')
    $decrypt_vpn_password = _StringEncrypt (0, "" & $decrypted_vpn_password_ini, "" & $crypt_password, 6)

    $decrypted_vpn_host_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', '')
    $decrypt_vpn_host = _StringEncrypt (0, "" & $decrypted_vpn_host_ini, "" & $crypt_password, 5)

    $decrypted_vpn_site_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', '')
    $decrypt_vpn_site = _StringEncrypt (0, "" & $decrypted_vpn_site_ini, "" & $crypt_password, 3)
EndFunc

;----------Function Read Input---------------------------------------------------------------

func readinput ()
    $vpn_user = GUICtrlRead($input_vpn_user)
    $vpn_password = GUICtrlRead($input_vpn_password)
    $vpn_host = GUICtrlRead($input_vpn_host)
    $vpn_site = GUICtrlRead($input_vpn_site)
EndFunc

I am not sure but this worked for me

Share this post


Link to post
Share on other sites

If you want to read them outside where they are declared, use Global $varname.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Can you give me an example?

Is this possible?

func decrypt ()
    $decrypted_vpn_user_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', '')
    global $decrypt_vpn_user = _StringEncrypt (0, "" & $decrypted_vpn_user_ini, "" & $crypt_password, 4)

    $decrypted_vpn_password_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', '')
    global $decrypt_vpn_password = _StringEncrypt (0, "" & $decrypted_vpn_password_ini, "" & $crypt_password, 6)

    $decrypted_vpn_host_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', '')
    global $decrypt_vpn_host = _StringEncrypt (0, "" & $decrypted_vpn_host_ini, "" & $crypt_password, 5)

    $decrypted_vpn_site_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', '')
    global $decrypt_vpn_site = _StringEncrypt (0, "" & $decrypted_vpn_site_ini, "" & $crypt_password, 3)
EndFunc
oÝ÷ ØÈßÙ¢)ඬÛ'¢Úh²Èçè®g­¢·vØ^wè®f­ì²Ú+yا¶¯j»ºÚ"µÍ[ÈÝÞ

B[ÙØÞ
K   ][ÝÑXÜYÙ[YI][ÝË   ][ÝÉ][ÝÈ    [È ÌÍÙXÜÝÝÙB[ÙØÞ
K   ][ÝÑXÜYÜÝÛÜ  ][ÝË  ][ÝÉ][ÝÈ    [È ÌÍÙXÜÝÜÜÝÛÜ
B[ÙØÞ
K   ][ÝÑXÜYÜÝ  ][ÝË  ][ÝÉ][ÝÈ    [È ÌÍÙXÜÝÚÜÝ
B[ÙØÞ
K   ][ÝÑXÜYÚ]I][ÝË    ][ÝÉ][ÝÈ    [È ÌÍÙXÜÝÜÚ]JB[[Â
Edited by tjestr

Share this post


Link to post
Share on other sites

Global outside of the func

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Like this?

;----------Function Decrypt------------------------------------------------------------------
global $decrypt_vpn_user
global $decrypt_vpn_password
global $decrypt_vpn_host 
global $decrypt_vpn_site

func decrypt ()
    $decrypted_vpn_user_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', '')
    $decrypt_vpn_user = _StringEncrypt (0, "" & $decrypted_vpn_user_ini, "" & $crypt_password, 4)

    $decrypted_vpn_password_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', '')
    $decrypt_vpn_password = _StringEncrypt (0, "" & $decrypted_vpn_password_ini, "" & $crypt_password, 6)

    $decrypted_vpn_host_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', '')
    $decrypt_vpn_host = _StringEncrypt (0, "" & $decrypted_vpn_host_ini, "" & $crypt_password, 5)

    $decrypted_vpn_site_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', '')
    $decrypt_vpn_site = _StringEncrypt (0, "" & $decrypted_vpn_site_ini, "" & $crypt_password, 3)
EndFunc

;----------TestBox---------------------------------------------------------------------------

func testbox ()
    msgbox (1, "Decrypted Username", "" & $decrypt_vpn_user)
    msgbox (1, "Decrypted Password", "" & $decrypt_vpn_password)
    msgbox (1, "Decrypted Host", "" & $decrypt_vpn_host)
    msgbox (1, "Decrypted Site", "" & $decrypt_vpn_site)
EndFunc

call ("decrypt")
call ("testbox")

No MSGBOXes appear...

Edited by tjestr

Share this post


Link to post
Share on other sites

Like this?

;----------Function Decrypt------------------------------------------------------------------
global $decrypt_vpn_user
global $decrypt_vpn_password
global $decrypt_vpn_host 
global $decrypt_vpn_site

func decrypt ()
    $decrypted_vpn_user_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', '')
    $decrypt_vpn_user = _StringEncrypt (0, "" & $decrypted_vpn_user_ini, "" & $crypt_password, 4)

    $decrypted_vpn_password_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', '')
    $decrypt_vpn_password = _StringEncrypt (0, "" & $decrypted_vpn_password_ini, "" & $crypt_password, 6)

    $decrypted_vpn_host_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', '')
    $decrypt_vpn_host = _StringEncrypt (0, "" & $decrypted_vpn_host_ini, "" & $crypt_password, 5)

    $decrypted_vpn_site_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', '')
    $decrypt_vpn_site = _StringEncrypt (0, "" & $decrypted_vpn_site_ini, "" & $crypt_password, 3)
EndFunc

;----------TestBox---------------------------------------------------------------------------

func testbox ()
    msgbox (1, "Decrypted Username", "" & $decrypt_vpn_user)
    msgbox (1, "Decrypted Password", "" & $decrypt_vpn_password)
    msgbox (1, "Decrypted Host", "" & $decrypt_vpn_host)
    msgbox (1, "Decrypted Site", "" & $decrypt_vpn_site)
EndFunc

call ("decrypt")
call ("testbox")

No MSGBOXes appear...

Mind posting full script so I can test it?

Share this post


Link to post
Share on other sites

OK, sorry, here is the full script

#include <constants.au3>
#include <guiconstants.au3>
#include <string.au3>

;----------Function Encrypt------------------------------------------------------------------

$crypt_password = "test"

func encrypt ()
    $encrypt_vpn_user = _StringEncrypt (1, "" & $readinput_vpn_user, "" & $crypt_password, 4)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', "" & $encrypt_vpn_user)

    $encrypt_vpn_password = _StringEncrypt (1, "" &$readinput_vpn_password, "" & $crypt_password, 6)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', "" & $encrypt_vpn_password)

    $encrypt_vpn_host = _StringEncrypt (1, "" & $readinput_vpn_host, "" & $crypt_password, 5)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', "" &$encrypt_vpn_host)

    $encrypt_vpn_site = _StringEncrypt (1, "" & $readinput_vpn_site, "" & $crypt_password, 3)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', "" &$encrypt_vpn_site)
EndFunc

;----------Function Decrypt------------------------------------------------------------------
global $decrypt_vpn_user
global $decrypt_vpn_password
global $decrypt_vpn_host 
global $decrypt_vpn_site

func decrypt ()
    $decrypted_vpn_user_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', '')
    $decrypt_vpn_user = _StringEncrypt (0, "" & $decrypted_vpn_user_ini, "" & $crypt_password, 4)

    $decrypted_vpn_password_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', '')
    $decrypt_vpn_password = _StringEncrypt (0, "" & $decrypted_vpn_password_ini, "" & $crypt_password, 6)

    $decrypted_vpn_host_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', '')
    $decrypt_vpn_host = _StringEncrypt (0, "" & $decrypted_vpn_host_ini, "" & $crypt_password, 5)

    $decrypted_vpn_site_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', '')
    $decrypt_vpn_site = _StringEncrypt (0, "" & $decrypted_vpn_site_ini, "" & $crypt_password, 3)
EndFunc

;----------TestBox---------------------------------------------------------------------------

func testbox ()
    msgbox (1, "Decrypted Username", "" & $decrypt_vpn_user)
    msgbox (1, "Decrypted Password", "" & $decrypt_vpn_password)
    msgbox (1, "Decrypted Host", "" & $decrypt_vpn_host)
    msgbox (1, "Decrypted Site", "" & $decrypt_vpn_site)
EndFunc

;----------Function Read Input---------------------------------------------------------------

global $readinput_vpn_user 
global $readinput_vpn_password
global $readinput_vpn_host
global $readinput_vpn_site

func readinput ()
    $readinput_vpn_user = GUICtrlRead($input_vpn_user)
    $readinput_vpn_password = GUICtrlRead($input_vpn_password)
    $readinput_vpn_host = GUICtrlRead($input_vpn_host)
    $readinput_vpn_site = GUICtrlRead($input_vpn_site)
EndFunc

;----------Select VPN Inforamtion------------------------------------------------------------

global $input_vpn_user
global $input_vpn_password
global $input_vpn_host
global $input_vpn_site

func selectvpninformation ()
    $WinMain = GuiCreate('VPN Informations', 320, 235)

    GuiCtrlCreateLabel('User:',10,40,70,20)
    GUICtrlCreateLabel('Password:',10,80,70,20)
    GuiCtrlCreateLabel('Host:',10,120,70,20)
    GuiCtrlCreateLabel('Sitename:',10,160,70,20)
    
    $input_vpn_user = GuiCtrlCreateInput('', 80,35,220,20)
    $input_vpn_password = GuiCtrlCreateInput('',80,75,220,20)
    $input_vpn_host = GuiCtrlCreateInput('', 80,115,220,20)
    $input_vpn_site = GuiCtrlCreateInput('', 80,155,220,20)
    
    $OKButton = GuiCtrlCreateButton('OK',240,185,60,35)

    GuiSetState()

    Do
       $Msg = GuiGetMsg()
       If $msg = $OKButton Then
            GuiSetState(@SW_DISABLE,$WinMain)
            call ("readinput")
            call ("encrypt")
            call ("decrypt")
          Exit
        EndIf
    Until $msg = $GUI_EVENT_CLOSE 
EndFunc

call ("selectvpninformation")
call ("testbox")

Share this post


Link to post
Share on other sites

Removed all Calls:

The reason your MsgBox's aren't being called is because

A) When you hit Ok, it will fill in the ini then EXIT. It never gets that chance to call the textboxes.

:shocked: They will show up when you Hit the X in the top right, although there will be no info because when you hit OK it exits.

#include <constants.au3>
#include <guiconstants.au3>
#include <string.au3>

;----------Function Encrypt------------------------------------------------------------------

$crypt_password = "test"

func encrypt ()
    $encrypt_vpn_user = _StringEncrypt (1, "" & $readinput_vpn_user, "" & $crypt_password, 4)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', "" & $encrypt_vpn_user)

    $encrypt_vpn_password = _StringEncrypt (1, "" &$readinput_vpn_password, "" & $crypt_password, 6)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', "" & $encrypt_vpn_password)

    $encrypt_vpn_host = _StringEncrypt (1, "" & $readinput_vpn_host, "" & $crypt_password, 5)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', "" &$encrypt_vpn_host)

    $encrypt_vpn_site = _StringEncrypt (1, "" & $readinput_vpn_site, "" & $crypt_password, 3)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', "" &$encrypt_vpn_site)
EndFunc

;----------Function Decrypt------------------------------------------------------------------
global $decrypt_vpn_user
global $decrypt_vpn_password
global $decrypt_vpn_host 
global $decrypt_vpn_site

func decrypt ()
    $decrypted_vpn_user_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', '')
    $decrypt_vpn_user = _StringEncrypt (0, "" & $decrypted_vpn_user_ini, "" & $crypt_password, 4)

    $decrypted_vpn_password_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', '')
    $decrypt_vpn_password = _StringEncrypt (0, "" & $decrypted_vpn_password_ini, "" & $crypt_password, 6)

    $decrypted_vpn_host_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', '')
    $decrypt_vpn_host = _StringEncrypt (0, "" & $decrypted_vpn_host_ini, "" & $crypt_password, 5)

    $decrypted_vpn_site_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', '')
    $decrypt_vpn_site = _StringEncrypt (0, "" & $decrypted_vpn_site_ini, "" & $crypt_password, 3)
EndFunc

;----------TestBox---------------------------------------------------------------------------

func testbox ()
    msgbox (1, "Decrypted Username", "" & $decrypt_vpn_user)
    msgbox (1, "Decrypted Password", "" & $decrypt_vpn_password)
    msgbox (1, "Decrypted Host", "" & $decrypt_vpn_host)
    msgbox (1, "Decrypted Site", "" & $decrypt_vpn_site)
EndFunc

;----------Function Read Input---------------------------------------------------------------

global $readinput_vpn_user 
global $readinput_vpn_password
global $readinput_vpn_host
global $readinput_vpn_site

func readinput ()
    $readinput_vpn_user = GUICtrlRead($input_vpn_user)
    $readinput_vpn_password = GUICtrlRead($input_vpn_password)
    $readinput_vpn_host = GUICtrlRead($input_vpn_host)
    $readinput_vpn_site = GUICtrlRead($input_vpn_site)
EndFunc

;----------Select VPN Inforamtion------------------------------------------------------------

global $input_vpn_user
global $input_vpn_password
global $input_vpn_host
global $input_vpn_site

func selectvpninformation ()
    $WinMain = GuiCreate('VPN Informations', 320, 235)

    GuiCtrlCreateLabel('User:',10,40,70,20)
    GUICtrlCreateLabel('Password:',10,80,70,20)
    GuiCtrlCreateLabel('Host:',10,120,70,20)
    GuiCtrlCreateLabel('Sitename:',10,160,70,20)
    
    $input_vpn_user = GuiCtrlCreateInput('', 80,35,220,20)
    $input_vpn_password = GuiCtrlCreateInput('',80,75,220,20)
    $input_vpn_host = GuiCtrlCreateInput('', 80,115,220,20)
    $input_vpn_site = GuiCtrlCreateInput('', 80,155,220,20)
    
    $OKButton = GuiCtrlCreateButton('OK',240,185,60,35)

    GuiSetState()

    Do
       $Msg = GuiGetMsg()
       If $msg = $OKButton Then
            GuiSetState(@SW_DISABLE,$WinMain)
            readinput()
            encrypt()
            decrypt()
          Exit
        EndIf
    Until $msg = $GUI_EVENT_CLOSE 
EndFunc

Share this post


Link to post
Share on other sites

OK, that seems to be right :shocked:, but how can i call the function to enter the vpn informations (selectvpnfunctions), and ,for testing the script, the (testbox) function?

Share this post


Link to post
Share on other sites

You need to give your script a "form" because right now is a collection of functions - try to structure it like : a body of the script and functions and try to use maybe the option: Opt("GUIOnEventMode", 1)

I did this for you ... take a closer look at it and you can do anything you wish ... :shocked:

#include <constants.au3>
#include <guiconstants.au3>
#include <string.au3>

;----------Function Encrypt------------------------------------------------------------------
Opt("GUIOnEventMode", 1)
$crypt_password = "test"

global $decrypt_vpn_user, $decrypt_vpn_password, $decrypt_vpn_host, $decrypt_vpn_site  
global $readinput_vpn_user, $readinput_vpn_password, $readinput_vpn_host, $readinput_vpn_site
global $input_vpn_user, $input_vpn_password,$input_vpn_host,$input_vpn_site 

$WinMain = GuiCreate('VPN Informations', 320, 235)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GuiCtrlCreateLabel('User:',10,40,70,20)
GUICtrlCreateLabel('Password:',10,80,70,20)
GuiCtrlCreateLabel('Host:',10,120,70,20)
GuiCtrlCreateLabel('Sitename:',10,160,70,20)
$input_vpn_user = GuiCtrlCreateInput('', 80,35,220,20)
$input_vpn_password = GuiCtrlCreateInput('',80,75,220,20)
$input_vpn_host = GuiCtrlCreateInput('', 80,115,220,20)
$input_vpn_site = GuiCtrlCreateInput('', 80,155,220,20)

$OKButton = GuiCtrlCreateButton('OK',240,185,60,35)
GUICtrlSetOnEvent (-1, "run_program")

GuiSetState()

While 1
    Sleep (100)
Wend

Func run_program()
    ;you can put anything here to be run when clicking the OK button
    readinput()
    encrypt()
    decrypt()
    testbox()
    Exit
EndFunc

Func Close ()
    Exit
EndFunc
    

func encrypt ()
    $encrypt_vpn_user = _StringEncrypt (1, "" & $readinput_vpn_user, "" & $crypt_password, 4)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', "" & $encrypt_vpn_user)

    $encrypt_vpn_password = _StringEncrypt (1, "" &$readinput_vpn_password, "" & $crypt_password, 6)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', "" & $encrypt_vpn_password)

    $encrypt_vpn_host = _StringEncrypt (1, "" & $readinput_vpn_host, "" & $crypt_password, 5)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', "" &$encrypt_vpn_host)

    $encrypt_vpn_site = _StringEncrypt (1, "" & $readinput_vpn_site, "" & $crypt_password, 3)
    IniWrite(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', "" &$encrypt_vpn_site)
EndFunc

;----------Function Decrypt------------------------------------------------------------------


func decrypt ()
    $decrypted_vpn_user_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Username', 'VPN_User', '')
    $decrypt_vpn_user = _StringEncrypt (0, "" & $decrypted_vpn_user_ini, "" & $crypt_password, 4)

    $decrypted_vpn_password_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Password', 'VPN_Password', '')
    $decrypt_vpn_password = _StringEncrypt (0, "" & $decrypted_vpn_password_ini, "" & $crypt_password, 6)

    $decrypted_vpn_host_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Hostname', 'VPN_Host', '')
    $decrypt_vpn_host = _StringEncrypt (0, "" & $decrypted_vpn_host_ini, "" & $crypt_password, 5)

    $decrypted_vpn_site_ini = IniRead(@ScriptDir & '\vpn.ini', 'VPN_Site', 'VPN_Site', '')
    $decrypt_vpn_site = _StringEncrypt (0, "" & $decrypted_vpn_site_ini, "" & $crypt_password, 3)
EndFunc

;----------TestBox---------------------------------------------------------------------------

func testbox ()
    msgbox (1, "Decrypted Username", "" & $decrypt_vpn_user)
    msgbox (1, "Decrypted Password", "" & $decrypt_vpn_password)
    msgbox (1, "Decrypted Host", "" & $decrypt_vpn_host)
    msgbox (1, "Decrypted Site", "" & $decrypt_vpn_site)
EndFunc

;----------Function Read Input---------------------------------------------------------------



func readinput ()
    $readinput_vpn_user = GUICtrlRead($input_vpn_user)
    $readinput_vpn_password = GUICtrlRead($input_vpn_password)
    $readinput_vpn_host = GUICtrlRead($input_vpn_host)
    $readinput_vpn_site = GUICtrlRead($input_vpn_site)
EndFunc

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0