rector Posted September 20, 2006 Posted September 20, 2006 Hi, I have wrote a programm to create a ipsec policy for decide hosts. The programm has two listboxes. A inputbox add the host to the first listbox, the second listbox listed the active hosts. My problems are: Listbox 1: At the moment I can add a hostname serveral times but my goal is that a host can add only one time. Listbox 2: The entries in the listbox should be sort everythime when a host will be add to the box and/or a new ipsec policy was created. MyCode: #include <GUIConstants.au3> #include <GuiListView.au3> Global $Statuslabel = "Bereit" Global $Version = "" Global $File_1 = @ScriptDir & "\bin\clientsrv.txt" Global $File_2 = @ScriptDir & "\bin\info.log" Global $File_3 = @ScriptDir & "\bin\start.cmd" Global $File_4 = @ScriptDir & "\bin\info.ini" Global $Port_1 = "Portno" Global $Port_2 = "Portno2" $Form1 = GUICreate($Version, 760, 520, 192, 125) $Tab1 = GUICtrlCreateTab(16, 10, 730, 470) GUICtrlCreateTabItem("Server-Verwaltung") $clientaddbutton = GUICtrlCreateButton("Client(s) hinzufügen >>>", 305, 140, 150, 20) $clientrmvbutton = GUICtrlCreateButton("Client entfernen", 470, 385, 240, 20) $Client = GUICtrlCreateInput ( "Hostname FQDN", 48 , 80, 150, 20) $addbutton = GUICtrlCreateButton ( "Hinzufügen", 215, 80, 85, 20) $rmvbutton = GUICtrlCreateButton ( "Entfernen" ,48, 385, 240, 20) $ListView1 = GUICtrlCreateListView("Servername |IP-Adresse ", 48, 140, 240, 230) $ListView2 = GUICtrlCreateListView("Servername |IP-Adresse ", 470, 140, 240, 230) $Label_1 = GUICtrlCreateLabel ( "", 305, 180, 150, 200) $Group_1 = GuiCtrlCreateGroup ( " Vorbereitungsliste ", 38, 115, 260, 355) $Group_2 = GuiCtrlCreateGroup ( "", 38, 410, 260, 60) $Group_3 = GuiCtrlCreateGroup ( " Serverliste ", 460, 115, 260, 355) $Group_4 = GuiCtrlCreateGroup ( "", 460, 410, 260, 60) $clientcreatebutton = GUICtrlCreateButton("Aktivierung", 470, 430, 240, 20) $Status = GUICtrlCreateLabel ( $Statuslabel , 48, 425, 240, 35, BitOR($SS_SUNKEN, $SS_CENTER, $BS_CENTER)) $Datei_menu = GUICtrlCreateMenu ( "&Daten") $Datei_item_end = GUICtrlCreateMenuitem ( "B&eenden" , $Datei_menu) $viewmenu = GUICtrlCreateMenu("A&nsicht",-1,1) $viewstatusitem = GUICtrlCreateMenuitem ("Statusfeld",$viewmenu) GUICtrlSetState(-1,$GUI_CHECKED) $Info_menu = GUICtrlCreateMenu ( "?" ) $Info_item_info = GUICtrlCreateMenuitem ( "Info", $Info_menu) ; Clients einlesen $filesrv = FileOpen($File_1, 0) If $filesrv = -1 Then $Status = GUICtrlCreateLabel ( "Serverliste nicht gefunden.", 48, 425, 240, 35, BitOR($SS_SUNKEN, $SS_CENTER)) ;Exit EndIf ; Read in lines of text until the EOF is reached While 1 $linesrv = FileReadLine($filesrv) If @error = -1 Then ExitLoop $linesrv = StringSplit ($linesrv, ";") GUICtrlCreateListViewItem (StringUpper($linesrv[1]) & "|" & $linesrv[2], $ListView2) Wend FileClose($filesrv) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE or $msg = $Datei_item_end Then ExitLoop If $msg = $viewstatusitem Then If BitAnd(GUICtrlRead($viewstatusitem),$GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($viewstatusitem,$GUI_UNCHECKED) GUICtrlSetState($Status,$GUI_HIDE) Else GUICtrlSetState($viewstatusitem,$GUI_CHECKED) GUICtrlSetState($Status,$GUI_SHOW) EndIf EndIf Select Case $msg = $Info_item_info MsgBox (64, $Version, "" & @CRLF & " " _ & @CRLF & @CRLF & " ") case $msg = $addbutton GUICtrlSetState ($addbutton, $GUI_Disable) GUICtrlSetState ($rmvbutton, $GUI_Disable) GUICtrlSetState ($clientaddbutton, $GUI_Disable) GUICtrlSetState ($clientrmvbutton, $GUI_Disable) $host = GUICtrlRead ($Client) ; nslookup check RunWait(@COMSPEC & " /c " & @WindowsDir & "\system32\nslookup.exe " & $host & " > " & CHR(34) & $File_2 & CHR(34), "",@SW_HIDE) $filenslookup = FileOpen ($File_2, 0) If $filenslookup = -1 Then GUICtrlSetData ($Status, "NSLOOKUP nicht ausführbar.") Exit EndIf $line = FileReadLine($filenslookup, 4) $line_1 = FileReadLine($filenslookup, 5) If @error = -1 Then GUICtrlSetData ($Status, "Hostname nicht im DNS vorhanden.") Else $line = StringReplace ( $line, "Name: ", "") $line_1 = StringReplace ( $line_1, "Address: ", "") GUICtrlCreateListViewItem (StringUpper($line) & "|" & $line_1, $ListView1) GUICtrlSetData ($Status, "Server erfolgreich hinzugefügt.") EndIf FileClose($filenslookup) FileDelete($File_2) GUICtrlSetState ($addbutton, $GUI_Enable) GUICtrlSetState ($rmvbutton, $GUI_Enable) GUICtrlSetState ($clientaddbutton, $GUI_Enable) GUICtrlSetState ($clientrmvbutton, $GUI_Enable) case $msg = $rmvbutton GUICtrlSetState ($addbutton, $GUI_Disable) GUICtrlSetState ($rmvbutton, $GUI_Disable) GUICtrlSetState ($clientaddbutton, $GUI_Disable) GUICtrlSetState ($clientrmvbutton, $GUI_Disable) $host = GUICtrlRead(GUICtrlRead($ListView1)) $host_1 = GUICtrlRead($ListView1) If $host_1 = 0 Then GUICtrlSetData ($Status, "Keinen Datensatz ausgewählt.") Else GUICtrlDelete($host_1) GUICtrlSetData ($Status, "Datensatz erfolgreich gelöscht.") EndIf GUICtrlSetState ($addbutton, $GUI_Enable) GUICtrlSetState ($rmvbutton, $GUI_Enable) GUICtrlSetState ($clientaddbutton, $GUI_Enable) GUICtrlSetState ($clientrmvbutton, $GUI_Enable) case $msg = $clientaddbutton GUICtrlSetState ($addbutton, $GUI_Disable) GUICtrlSetState ($rmvbutton, $GUI_Disable) GUICtrlSetState ($clientaddbutton, $GUI_Disable) GUICtrlSetState ($clientrmvbutton, $GUI_Disable) For $x = 0 To _GUICtrlListViewGetItemCount($ListView1) - 1 $ret = _GUICtrlListViewGetItemText($ListView1, $x) GUICtrlCreateListViewItem($ret, $ListView2) Next _GUICtrlListViewDeleteAllItems($ListView1) GUICtrlSetState ($addbutton, $GUI_Enable) GUICtrlSetState ($rmvbutton, $GUI_Enable) GUICtrlSetState ($clientaddbutton, $GUI_Enable) GUICtrlSetState ($clientrmvbutton, $GUI_Enable) case $msg = $clientrmvbutton GUICtrlSetState ($addbutton, $GUI_Disable) GUICtrlSetState ($rmvbutton, $GUI_Disable) GUICtrlSetState ($clientaddbutton, $GUI_Disable) GUICtrlSetState ($clientrmvbutton, $GUI_Disable) $host = GUICtrlRead(GUICtrlRead($ListView2)) $host_1 = GUICtrlRead($ListView2) If $host_1 = 0 Then GUICtrlSetData ($Status, "Keinen Datensatz ausgewählt.") Else GUICtrlDelete($host_1) GUICtrlSetData ($Status, "Datensatz erfolgreich gelöscht.") EndIf GUICtrlSetState ($addbutton, $GUI_Enable) GUICtrlSetState ($rmvbutton, $GUI_Enable) GUICtrlSetState ($clientaddbutton, $GUI_Enable) GUICtrlSetState ($clientrmvbutton, $GUI_Enable) case $msg = $clientcreatebutton $IPSecfile = FileOpen ($File_3, 2) For $i = 2 To 36 $var = FileReadLine ($File_4, $i) FileWriteLine($IPSecfile, $var) Next For $x = 0 To _GUICtrlListViewGetItemCount($ListView2) - 1 $ret = _GUICtrlListViewGetItemText($ListView2, $x) $ret = StringSplit ( $ret, "|") FileWriteLine($IPSecfile, "netsh ipsec static add filter filterlist=" & CHR(34) & "Incoming Traffic" & CHR(34) & " srcaddr=" _ & $ret[1] & " dstaddr=me description=" & CHR(34) & "VMLIC Incoming Traffic" & CHR(34) & " protocol=TCP srcport=0 dstport=" & $Port_1) FileWriteLine($IPSecfile, "netsh ipsec static add filter filterlist=" & CHR(34) & "Incoming Traffic" & CHR(34) & " srcaddr=" _ & $ret[1] & " dstaddr=me description=" & CHR(34) & "VMLIC Incoming Traffic" & CHR(34) & " protocol=TCP srcport=0 dstport=" & $Port_2) Next FileWriteLine ($IPSecfile, @CRLF) For $i = 38 To 47 $var = FileReadLine ($File_4, $i) FileWriteLine ($IPSecfile, $var) Next FileClose($IPSecfile) GUICtrlSetData ($Status, "Neue Hostliste erfolgreich aktiviert.") EndSelect Wend
jvanegmond Posted September 20, 2006 Posted September 20, 2006 I even got a error running that. Line 51: Array dimension exceeded. github.com/jvanegmond
rector Posted September 20, 2006 Author Posted September 20, 2006 Sorry, please create in the script directory the folder "bin" and unzip the attachment there. The Script was wrote with AutoIt v3.2.1.1 (beta). Thanks, rectorinfo.zip
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now