Sub FritzBoxDaten()
Dim SID As String = FBLogin() 'enthält die SessionID: "&sid=" & SID
If SID = "-1" Then 'Fehlerfall
MsgBox("Anmelden nicht erfolgreich. Einlesen der Telefone abgebrochen./(FritzBoxDaten)", MsgBoxStyle.Critical)
Exit Sub
End If
Dim FBOX_ADR As String = ini.Read(DateiPfad, "Optionen", "TBFBAdr", "192.168.178.1") ' IP der FritzBox
Dim tempstring As String
tempstring = HTTPTrans.Read("http://" & FBOX_ADR & "/cgi-bin/webcm?getpage=../html/de/menus/menu2.html&var:lang=de&var:menu=fon&var:pagename=fondevices" & SID, System.Text.Encoding.UTF8)
FBLogout(SID)
tempstring = Replace(tempstring, Chr(34), "'", , , vbTextCompare) ' " in ' umwandeln
Dim Vorwahl As String ' In den Einstellungen eingegebene Vorwahl
Dim TelName As String ' Gefundener Telefonname
Dim TelNr As String ' Dazugehörige Telefonnummer
Dim SIPID As String = "-1"
Dim pos(6) As Integer ' Positionsmarker
' Positionsmarker
Dim i As Integer ' Laufvariable
Dim Anzahl As Integer = 0
Dim AnzahlISDN As Integer = 0
Dim ID As Integer
Dim PortName() As String = Split("readFon123;readNTHotDialList;readFonControl;readVoipExt;readTam;readFaxMail", ";")
Dim Section As String
Dim TelefonString() As String
Vorwahl = ini.Read(DateiPfad, "Optionen", "TBVorwahl", "")
'Alten Einstellungen löschen
ini.Write(DateiPfad, "Telefone", vbNullString, "")
'MSNs emitteln
pos(0) = 1
For i = 0 To 9
pos(0) = InStr(pos(0), tempstring, "nrs.msn.push('", vbTextCompare) + 14
If Not pos(0) = 14 Then
pos(1) = InStr(pos(0), tempstring, "'", vbTextCompare)
TelNr = Mid(tempstring, pos(0), pos(1) - pos(0))
If Not TelNr = "" Then
If Left(TelNr, Len(Vorwahl)) = Vorwahl Then TelNr = Mid(TelNr, Len(Vorwahl) + 1)
ini.Write(DateiPfad, "Telefone", "MSN" & CStr(i), TelNr)
Debug.Print(TelNr)
End If
End If
Next
' 'Internetnummern ermitteln
For i = 0 To 19
pos(0) = InStr(pos(0), tempstring, "nrs.sip.push('", vbTextCompare) + 14
If Not pos(0) = 14 Then
pos(1) = InStr(pos(0), tempstring, "'", vbTextCompare)
TelNr = Mid(tempstring, pos(0), pos(1) - pos(0))
If Not TelNr = "" Then
If Left(TelNr, Len(Vorwahl)) = Vorwahl Then TelNr = Mid(TelNr, Len(Vorwahl) + 1)
ini.Write(DateiPfad, "Telefone", "SIP" & CStr(i), TelNr)
Debug.Print(TelNr)
SIPID = CStr(i)
End If
End If
Next
ini.Write(DateiPfad, "Telefone", "SIPID", SIPID)
Debug.Print(SIPID)
'Festnetznummer ermitteln
pos(0) = InStr(1, tempstring, "telcfg:settings/MSN/POTS", vbTextCompare)
pos(1) = InStr(pos(0), tempstring, "value='", vbTextCompare) + 7
pos(2) = InStr(pos(1), tempstring, "' id", vbTextCompare)
TelNr = Mid(tempstring, pos(1), pos(2) - pos(1))
If Left(TelNr, Len(Vorwahl)) = Vorwahl Then TelNr = Mid(TelNr, Len(Vorwahl) + 1)
Debug.Print(TelNr)
ini.Write(DateiPfad, "Telefone", "POTS", TelNr)
'Telefone ermitteln
pos(0) = 1
For i = 0 To UBound(PortName)
pos(0) = InStr(pos(0), tempstring, PortName(i), CompareMethod.Text)
pos(1) = InStr(pos(0), tempstring, "return list;", CompareMethod.Text) + Len("return list;")
Section = Mid(tempstring, pos(0), pos(1) - pos(0))
TelefonString = Split(Section, "});", , CompareMethod.Text)
For Each Telefon In TelefonString
If InStr(Telefon, "return list") = 0 And InStr(Telefon, "Isdn-Default") = 0 Then
pos(0) = InStr(Telefon, "name: ", CompareMethod.Text) + Len("name: ")
pos(1) = InStr(pos(0), Telefon, ",", CompareMethod.Text)
TelName = Mid(Telefon, pos(0), pos(1) - pos(0))
If TelName = "fonName" Then
pos(0) = InStr(Telefon, "fonName = '", CompareMethod.Text) + Len("fonName = '")
pos(1) = InStr(pos(0), Telefon, "'", CompareMethod.Text)
TelName = Mid(Telefon, pos(0), pos(1) - pos(0))
Else
TelName = Replace(TelName, "'", "", , , CompareMethod.Text)
End If
pos(2) = InStr(pos(1), Telefon, "number: ", CompareMethod.Text) + Len("number: ")
pos(3) = InStr(pos(2), Telefon, Chr(10), CompareMethod.Text)
TelNr = Replace(Trim(Mid(Telefon, pos(2), pos(3) - pos(2))), "'", "", , , CompareMethod.Text)
TelNr = Replace(TelNr, Chr(10), "", , , CompareMethod.Text)
If Strings.Left(TelNr, 3) = "SIP" Then TelNr = ini.Read(DateiPfad, "Telefone", TelNr, "")
If Not Trim(TelName) = "" And Not Trim(TelNr) = "" Then
Select Case i
Case 0
If Strings.Left(TelNr, Len(Vorwahl)) = Vorwahl Then TelNr = Mid(TelNr, Len(Vorwahl) + 1)
pos(4) = InStr(Telefon, "n = parseInt('", CompareMethod.Text) + Len("n = parseInt('")
pos(5) = InStr(pos(4), Telefon, "'", CompareMethod.Text)
ID = CInt(Mid(Telefon, pos(4), pos(5) - pos(4))) + 1
ini.Write(DateiPfad, "Telefone", CStr(ID), TelNr & ";" & TelName)
Anzahl += 1
Case 1
AnzahlISDN += 1
pos(2) = InStr(Telefon, "partyNo = '", CompareMethod.Text) + Len("partyNo = '")
pos(3) = InStr(pos(2), Telefon, "'", CompareMethod.Text)
TelNr = Trim(Mid(Telefon, pos(2), pos(3) - pos(2)))
pos(4) = InStr(Telefon, "n = parseInt('", CompareMethod.Text) + Len("n = parseInt('")
pos(5) = InStr(pos(4), Telefon, "'", CompareMethod.Text)
ID = CInt(Mid(Telefon, pos(4), pos(5) - pos(4)))
If Strings.Left(TelNr, Len(Vorwahl)) = Vorwahl Then TelNr = Mid(TelNr, Len(Vorwahl) + 1)
ini.Write(DateiPfad, "Telefone", "5" & ID, TelNr & ";" & TelName)
Case 2
Anzahl += 1
pos(2) = InStr(Telefon, "intern: isUnpersonalizedMini ? '' : '**", CompareMethod.Text) + Len("intern: isUnpersonalizedMini ? '' : '**") + 2
pos(3) = InStr(pos(2), Telefon, "'", CompareMethod.Text)
ID = CInt(Trim(Mid(Telefon, pos(2), pos(3) - pos(2))))
pos(2) = InStr(TelNr, ":", CompareMethod.Text) + 2
TelNr = Trim(Mid(TelNr, pos(2)))
If Strings.Left(TelNr, Len(Vorwahl)) = Vorwahl Then TelNr = Mid(TelNr, Len(Vorwahl) + 1)
ini.Write(DateiPfad, "Telefone", "6" & ID, TelNr & ";" & TelName)
Case 3
pos(4) = InStr(Telefon, "n = parseInt('", CompareMethod.Text) + Len("n = parseInt('")
pos(5) = InStr(pos(4), Telefon, "'", CompareMethod.Text)
ID = CInt(Mid(Telefon, pos(4), pos(5) - pos(4)))
Anzahl += 1
ini.Write(DateiPfad, "Telefone", "2" & ID, TelNr & ";" & TelName)
Case 4
pos(2) = InStr(Telefon, "tamDisplay = '", CompareMethod.Text) + Len("tamDisplay = '")
pos(3) = InStr(pos(2), Telefon, "'", CompareMethod.Text)
If Mid(Telefon, pos(4), pos(5) - pos(4)) = "1" Then
pos(4) = InStr(Telefon, "n = parseInt('", CompareMethod.Text) + Len("n = parseInt('")
pos(5) = InStr(pos(4), Telefon, "'", CompareMethod.Text)
ID = CInt(Mid(Telefon, pos(4), pos(5) - pos(4)))
ini.Write(DateiPfad, "Telefone", "60" & ID, ";" & TelName)
Anzahl += 1
End If
End Select
End If
End If
Next
Next
If Not AnzahlISDN = 0 Then ini.Write(DateiPfad, "Telefone", "50", ";ISDN-Basis")
ini.Write(DateiPfad, "Telefone", "Anzahl", CStr(Anzahl + AnzahlISDN))
End Sub ' (FritzBoxDaten)