Added list-fritzbox-calls.ps1

This commit is contained in:
Markus Fleschutz 2021-01-03 11:49:06 +01:00
parent 19517b13d1
commit 1d2246df2d
4 changed files with 104 additions and 2 deletions

View File

@ -22,6 +22,7 @@ list-automatic-variables.ps1, lists PowerShell automatic variables
list-empty-dirs.ps1, lists empty subfolders in a directory tree
list-files.ps1, lists all files in the given folder and also in every subfolder
list-formatted.ps1, lists the current working directory formatted in columns
list-fritzbox-calls.ps1, lists the FRITZ!Box calls
list-installed-software.ps1, lists the installed software
list-logbook.ps1, lists the content of the logbook
list-unused-files.ps1, lists unused files in a directory tree

1 Filename Description
22 list-empty-dirs.ps1 lists empty subfolders in a directory tree
23 list-files.ps1 lists all files in the given folder and also in every subfolder
24 list-formatted.ps1 lists the current working directory formatted in columns
25 list-fritzbox-calls.ps1 lists the FRITZ!Box calls
26 list-installed-software.ps1 lists the installed software
27 list-logbook.ps1 lists the content of the logbook
28 list-unused-files.ps1 lists unused files in a directory tree

View File

@ -31,6 +31,7 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol
* [list-installed-software.ps1](Scripts/list-installed-software.ps1) - lists the installed software
* [list-files.ps1](Scripts/list-files.ps1) - lists all files in the given folder and also in every subfolder
* [list-formatted.ps1](Scripts/list-formatted.ps1) - lists the current working directory formatted in columns
* [list-fritzbox-calls.ps1](Scripts/list-fritzbox-calls.ps1) - lists the FRITZ!Box calls
* [list-logbook.ps1](Scripts/list-logbook.ps1) - lists the content of the logbook
* [list-unused-files.ps1](Scripts/list-unused-files.ps1) - lists unused files in a directory tree
* [list-cmdlets.ps1](Scripts/list-cmdlets.ps1) - lists the PowerShell cmdlets

View File

@ -0,0 +1,100 @@
#!/snap/bin/powershell
<#
.SYNTAX ./list-fritzbox-calls.ps1 [<username>] [<password>]
.DESCRIPTION lists the phone calls of the FRITZ!Box device
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
param([string]$USERNAME = "", [string]$PASSWORD = "")
if ($USERNAME -eq "") {
$USERNAME = read-host "Enter username for FRITZ!Box"
}
if ($PASSWORD -eq "") {
$PASSWORD = read-host "Enter password for FRITZ!Box"
}
$FB_FQDN = "fritz.box"
if ($PSVersionTable.PSVersion.Major -lt 3) {
write-host "ERROR: Minimum Powershell Version 3.0 is required!" -F Yellow
return
}
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls,Tls11,Tls12'
[xml]$serviceinfo = Invoke-RestMethod -Method GET -Uri "http://$($FB_FQDN):49000/tr64desc.xml"
[System.Xml.XmlNamespaceManager]$ns = new-Object System.Xml.XmlNamespaceManager $serviceinfo.NameTable
$ns.AddNamespace("ns",$serviceinfo.DocumentElement.NamespaceURI)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
function Execute-SOAPRequest { param([Xml]$SOAPRequest, [string]$soapactionheader, [String]$URL)
try {
$wr = [System.Net.WebRequest]::Create($URL)
$wr.Headers.Add('SOAPAction',$soapactionheader)
$wr.ContentType = 'text/xml; charset="utf-8"'
$wr.Accept = 'text/xml'
$wr.Method = 'POST'
$wr.PreAuthenticate = $true
$wr.Credentials = [System.Net.NetworkCredential]::new($USERNAME,$PASSWORD)
$requestStream = $wr.GetRequestStream()
$SOAPRequest.Save($requestStream)
$requestStream.Close()
[System.Net.HttpWebResponse]$wresp = $wr.GetResponse()
$responseStream = $wresp.GetResponseStream()
$responseXML = [Xml]([System.IO.StreamReader]($responseStream)).ReadToEnd()
$responseStream.Close()
return $responseXML
} catch {
if ($_.Exception.InnerException.Response){
throw ([System.IO.StreamReader]($_.Exception.InnerException.Response.GetResponseStream())).ReadToEnd()
} else {
throw $_.Exception.InnerException
}
}
}
function New-Request {
param(
[parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string]$urn,
[parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string]$action,
[hashtable]$parameter = @{},
$Protocol = 'https'
)
# SOAP Request Body Template
[xml]$request = @"
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
</s:Body>
</s:Envelope>
"@
$service = $serviceinfo.SelectNodes('//ns:service',$ns) | ?{$_.ServiceType -eq $URN}
if(!$service){throw "URN does not exist."}
$actiontag = $request.CreateElement('u',$action,$service.serviceType)
$parameter.GetEnumerator() | %{
$el = $request.CreateElement($_.Key)
$el.InnerText = $_.Value
$actiontag.AppendChild($el)| out-null
}
$request.GetElementsByTagName('s:Body')[0].AppendChild($actiontag) | out-null
$resp = Execute-SOAPRequest $request "$($service.serviceType)#$($action)" "$($Protocol)://$($FB_FQDN):$(@{$true=$script:secport;$false=49000}[($Protocol -eq 'https')])$($service.controlURL)"
return $resp
}
$script:secport = (New-Request -urn "urn:dslforum-org:service:DeviceInfo:1" -action 'GetSecurityPort' -proto 'http').Envelope.Body.GetSecurityPortResponse.NewSecurityPort
function GetCallList(){
param(
[int]$maxentries = 999,
[int]$days = 999
)
$resp = New-Request -urn 'urn:dslforum-org:service:X_AVM-DE_OnTel:1' -action 'GetCallList'
$list = [xml](new-object System.Net.WebClient).DownloadString("$($resp.Envelope.Body.GetCallListResponse.NewCallListURL)&max=$maxentries&days=$days")
return $list.root.call
}
GetCallList | format-table -property Date,Duration,Caller,Called
echo $Result
exit 0

View File

@ -8,10 +8,10 @@
param([string]$USERNAME = "", [string]$PASSWORD = "")
if ($USERNAME -eq "") {
$USERNAME = "Enter username for FRITZ!Box"
$USERNAME = read-host "Enter username for FRITZ!Box"
}
if ($PASSWORD -eq "") {
$PASSWORD = "Enter password for FRITZ!Box"
$PASSWORD = read-host "Enter password for FRITZ!Box"
}
$FB_FQDN = "fritz.box"