-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutoriser_Remote_Control.ps1
75 lines (62 loc) · 2.46 KB
/
Autoriser_Remote_Control.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#######################################################################################################################
#
# Autoriser_Remote_Control
#
#######################################################################################################################
#
# Ce script authentifie le script 'Remote Control' auprès de la Freebox spécifiée et récupère
# l'identifiant d'application correspondant.
#
#######################################################################################################################
# Definition de l'URI de la Freebox locale
$AdresseFreebox = "https://mafreebox.freebox.fr"
# Lecture des infos de version de la Freebox
$FbxApiInfo = Invoke-RestMethod -Uri $AdresseFreebox/api_version
# Stockage de l'URI et du port de la Freebox
if ($FbxApiInfo.https_available) {
$FreeboxURI = "https://{0}:{1}" -f $FbxApiInfo.api_domain, $FbxApiInfo.https_port
} else {
$FreeboxURI = "http://{0}" -f $FbxApiInfo.api_domain
}
# Définir l'application "Reboot Freebox"
$ApplicationInfo = @'
{
"app_id": "fr.freebox.remotecontrol",
"app_name": "Remote Control",
"app_version": "1.0.0",
"device_name": "demande"
}
'@
# Stocker l'URL de base des appels
$BaseUrl = "$AdresseFreebox$($FbxApiInfo.api_base_url)v$([int]$FbxApiInfo.api_version)"
# Demander l'autorisation
$Demande = Invoke-RestMethod -Uri "$BaseUrl/login/authorize" -Method Post -Body $ApplicationInfo
# Attente de la réponse
$Reponse = Invoke-RestMethod -Uri "$BaseUrl/login/authorize/$($Demande.result.track_id)"
"L'afficheur de la Freebox doit indiquer : ""Autoriser Remote Control sur demande ?"""
"Appuyer sur la flèche droite de la Freebox pour autoriser."
while ($Reponse.result.status -eq "pending") {
$Reponse = Invoke-RestMethod -Uri "$BaseUrl/login/authorize/$($Demande.result.track_id)"
Start-Sleep -Seconds 1
}
# Evaluation de la réponse
if ($Reponse.result.status -eq "granted") {
""
"Application ""Remote Control"" autorisée."
"URI de la Freebox: {0}" -f $FreeboxURI
"Identifiant d'application: {0}" -f $Demande.result.app_token
} else {
""
"Echec de l'autorisation: {0}." -f $Reponse.result.status
}
# Suppression des variables
Remove-Variable -Name "AdresseFreebox"
Remove-Variable -Name "FbxApiInfo"
Remove-Variable -Name "FreeboxURI"
Remove-Variable -Name "ApplicationInfo"
Remove-Variable -Name "BaseUrl"
Remove-Variable -Name "Demande"
Remove-Variable -Name "Reponse"
""
Pause
# EOF