Code : Tout sélectionner
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=orange.ico
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Res_Fileversion=1.0.0
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("LiveBox - Suppression de périphériques", 435, 153, 192, 124)
$Combo1 = GUICtrlCreateCombo("Périphépiques déconnectés", 24, 72, 385, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL,$CBS_DROPDOWNLIST))
GUICtrlSetState($Combo1, $GUI_DISABLE)
$Label1 = GUICtrlCreateLabel("Selectionnez un périphérique à supprimer", 24, 56, 198, 16)
$Button1 = GUICtrlCreateButton("Supprimer", 336, 112, 75, 25)
$Button2 = GUICtrlCreateButton("Supprimer tout", 24, 112, 75, 25)
GUICtrlSetState($Button1, $GUI_DISABLE)
GUICtrlSetState($Button2, $GUI_DISABLE)
$Input1 = GUICtrlCreateInput("admin", 24, 24, 65, 21)
GUICtrlSetState($Input1, $GUI_DISABLE)
$Input2 = GUICtrlCreateInput("", 96, 24, 161, 21, $ES_PASSWORD) ;Password
$Label2 = GUICtrlCreateLabel("Utilisateur", 24, 8, 50, 16)
$Label3 = GUICtrlCreateLabel("Mot de passe", 96, 8, 68, 16)
$Label4 = GUICtrlCreateLabel("Livebox IP/host", 264, 8, 79, 16)
$Input3 = GUICtrlCreateInput("livebox", 264, 24, 81, 21)
$Button3 = GUICtrlCreateButton("Connexion", 352, 22, 59, 24)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $USER = "admin"
Global $LIVEBOX = ""
Global $sContextID = ""
Global $PASSWORD = ""
Global $sDevice_list =""
Global $sMenu = ""
Global $sDefaut_device = ""
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button3 ;Connexion ********************************************************
$PASSWORD = GUICtrlRead($Input2)
$LIVEBOX = GUICtrlRead($Input3)
if ($PASSWORD ="") Then
msgbox(48,"ERREUR","Veuillez indiquer votre mot de passe Livebox")
Elseif ($LIVEBOX ="") Then
msgbox(48,"ERREUR","Veuillez indiquer une IP ou un nom d'hote pour votre LiveBox")
Else
if auth_livebox()="" then
Device_list()
GUICtrlSetState($Combo1, $GUI_ENABLE)
GUICtrlSetState($Button1, $GUI_ENABLE)
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetData($Combo1, "", "") ; destruction liste précédente
GUICtrlSetData($Combo1, $sMenu, $sDefaut_device)
;msgbox(0,"Connexion","Connexion établie.")
endif
EndIf
Case $Button1 ;supprimer 1 périphérique *******************************************
$sDevice = GUICtrlRead($Combo1)
$aMac = StringSplit($sDevice,"/")
if $sDevice<>"" Then
$sMac = StringReplace($aMac[2]," ","") ; on enelève les espaces
Delete_Device($sMac)
msgbox(0,"Suppression","Périphérique supprimé.")
Device_list()
GUICtrlSetData($Combo1, "", "") ; destruction liste précédente
GUICtrlSetData($Combo1, $sMenu, $sDefaut_device)
Endif
Case $Button2 ;supprimer tous les périphériques ************************************
Delete_All()
msgbox(0,"Suppression","Tous les périphériques ont été supprimés.")
Device_list()
GUICtrlSetData($Combo1, "", "") ; destruction liste précédente
GUICtrlSetData($Combo1, $sMenu, $sDefaut_device)
EndSwitch
WEnd
Func auth_livebox()
$str = "/authenticate?username=" & $USER & "&password=" & $PASSWORD
$oHTTP.Open("POST", "http://" & $LIVEBOX & $str, False)
$oHTTP.SetRequestHeader("Content-Type", "application/json")
$oHTTP.Send()
$oReceived = $oHTTP.ResponseText
$sContextID = StringRegExp($oReceived, 'contextID":"([^"]+)"|()$', 1)[0]
if $sContextID="" Then
msgbox(48,"ERREUR"," Mot de passe incorrect : " & $PASSWORD)
return "NOLOGIN"
EndIf
EndFunc ;==>auth_livebox
Func Device_list()
if LB_type()="lbv3fr" Then ;Livebox 3
$PARAMS = '{"parameters":{"expression":".Active==false","traverse":"down","flags":""}}'
$oHTTP.Open("POST", "http://" & $LIVEBOX & "/sysbus/Devices:get", False)
$oHTTP.SetRequestHeader("X-Context", $sContextID)
$oHTTP.Send($PARAMS)
$sDevice_list = $oHTTP.ResponseText
$aDevice_Names = StringRegExp($sDevice_list, 'bridge","Name":"(.*?)","DeviceType', 3)
$aDevice_MAC = StringRegExp($sDevice_list, 'PhysAddress":"(.*?)","Ageing', 3)
$aDevice_IP = StringRegExp($sDevice_list, 'IPAddress":"(.*?)","IPAddressSource', 3)
Global $aAll_MAC = $aDevice_MAC
$sMenu = ""
for $i=0 to ubound($aDevice_Names) - 1 ; creation de la liste pour menu déroulant
$sMenu = $sMenu & $aDevice_Names[$i] & " / " & $aDevice_MAC[$i] & " / " & $aDevice_IP[$i] & "|"
Next
if isArray($aDevice_Names) then
$sDefaut_device = $aDevice_Names[0] & " / " & $aDevice_MAC[0] & " / " & $aDevice_IP[0]
Else
$sDefaut_device=""
Endif
Elseif LB_type()="lbv2fr" Then ; Livebox 2
$PARAMS = '{"parameters":{}}'
$oHTTP.Open("POST", "http://" & $LIVEBOX & "/sysbus/Hosts:getDevices", False)
$oHTTP.SetRequestHeader("X-Context", $sContextID)
$oHTTP.Send($PARAMS)
$sDevice_list = $oHTTP.ResponseText
$aDevice_Names = StringRegExp($sDevice_list, 'hostName":"(.*?)","dnsName', 3)
$aDevice_MAC = StringRegExp($sDevice_list, 'physAddress":"(.*?)","ipAddress', 3)
$aDevice_ACTIV = StringRegExp($sDevice_list, 'active":(.*?),"lastConnection', 3)
$aDevice_IP = StringRegExp($sDevice_list, 'ipAddress":"(.*?)","addressSource', 3)
Global $aAll_MAC = $aDevice_MAC
$sMenu = ""
for $i=0 to ubound($aDevice_Names) - 1 ; creation de la liste pour menu déroulant
if $aDevice_ACTIV[$i] = "false" Then
$sMenu = $sMenu & $aDevice_Names[$i] & " / " & $aDevice_MAC[$i] & " / " & $aDevice_IP[$i] & "|"
EndIf
Next
if isArray($aDevice_Names) then
$sDefaut_device = $aDevice_Names[0] & " / " & $aDevice_MAC[0] & " / " & $aDevice_IP[0]
Else
$sDefaut_device=""
Endif
Endif
EndFunc ;==>Device_list
Func Delete_Device($Mac_address)
if $Mac_address="" Then
msgbox(48,"ERREUR","Tous les périphériques ont été supprimés.")
Else
$PARAMS = '{"parameters":{"physAddress":"' & $Mac_address & '"}}'
$oHTTP.Open("POST", "http://" & $LIVEBOX & "/sysbus/Hosts:delHost", False)
$oHTTP.SetRequestHeader("X-Context", $sContextID)
$oHTTP.Send($PARAMS)
Endif
EndFunc ;==>Delete_Device
Func Delete_All()
For $i=0 to ubound($aAll_MAC) - 1
$PARAMS = '{"parameters":{"physAddress":"' & $aAll_MAC[$i] & '"}}'
$oHTTP.Open("POST", "http://" & $LIVEBOX & "/sysbus/Hosts:delHost", False)
$oHTTP.SetRequestHeader("X-Context", $sContextID)
$oHTTP.Send($PARAMS)
Next
EndFunc ;==>Delete_All
Func LB_type()
$oHTTP.Open("GET", "http://" & $LIVEBOX, False)
$oHTTP.Send()
$return = $oHTTP.ResponseText
$aModel = StringRegExp($return, "BUILD_PROJECT: '(.*?)',", 3)
if IsArray($aModel) Then
$sModel = $aModel[0]
else
msgbox(48,"ERREUR","Model de Livebox inconnu")
Exit
EndIf
return $sModel
EndFunc ;==>LB_type