-
Notifications
You must be signed in to change notification settings - Fork 8
/
Onion_Config_02_wifi.ps1
146 lines (121 loc) · 5.09 KB
/
Onion_Config_02_wifi.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Wifi settings
param (
[Parameter(Mandatory = $false)]
[string]$Target
)
$SdCard_Version = ""
$SdCardState = ""
$ScriptPath = $MyInvocation.MyCommand.Path
$ScriptDirectory = Split-Path $ScriptPath -Parent
Set-Location -Path $ScriptDirectory
[Environment]::CurrentDirectory = Get-Location
if (-not $Target) {
. "$PSScriptRoot\Disk_selector.ps1"
if ($selectedTag -ne "") {
$selectedTagSplitted = $selectedTag.Split(",")
$Drive_Number = $($selectedTagSplitted[0])
$Drive_Letter = $($selectedTagSplitted[1])
$Target = "$Drive_Letter`:"
Write-Host "Selected Tag: $selectedTag"
Write-Host "Disk Number: $Drive_Number"
Write-Host "Disk Letter: $Drive_Letter"
}
else {
return
}
}
Add-Type -AssemblyName System.Windows.Forms
# Création du formulaire
$form = New-Object System.Windows.Forms.Form
$form.Text = "WiFi Configuration"
$form.Size = New-Object System.Drawing.Size(400, 200)
$form.StartPosition = "CenterScreen"
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$iconPath = Join-Path -Path $PSScriptRoot -ChildPath "tools\res\wifi.ico"
$icon = New-Object System.Drawing.Icon($iconPath)
$form.Icon = $icon
# Création de la première TextBox pour le SSID
$textboxSSID = New-Object System.Windows.Forms.TextBox
$textboxSSID.Location = New-Object System.Drawing.Point(10, 20)
$textboxSSID.Size = New-Object System.Drawing.Size(360, 20)
$form.Controls.Add($textboxSSID)
# Création de la deuxième TextBox pour le mot de passe
$textboxPassword = New-Object System.Windows.Forms.TextBox
$textboxPassword.Location = New-Object System.Drawing.Point(10, 50)
$textboxPassword.Size = New-Object System.Drawing.Size(360, 20)
$form.Controls.Add($textboxPassword)
# Création du bouton OK
$buttonOK = New-Object System.Windows.Forms.Button
$buttonOK.Location = New-Object System.Drawing.Point(10, 90)
$buttonOK.Size = New-Object System.Drawing.Size(75, 23)
$buttonOK.Text = "OK"
$buttonOK.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $buttonOK
$form.Controls.Add($buttonOK)
# Création du bouton Annuler
$buttonCancel = New-Object System.Windows.Forms.Button
$buttonCancel.Location = New-Object System.Drawing.Point(95, 90)
$buttonCancel.Size = New-Object System.Drawing.Size(75, 23)
$buttonCancel.Text = "Cancel"
$buttonCancel.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $buttonCancel
$form.Controls.Add($buttonCancel)
# Création du bouton pour obtenir les informations Wi-Fi du PC
$buttonGetWifiInfo = New-Object System.Windows.Forms.Button
$buttonGetWifiInfo.Location = New-Object System.Drawing.Point(180, 90)
$buttonGetWifiInfo.Size = New-Object System.Drawing.Size(180, 23)
$buttonGetWifiInfo.Text = "Get Wifi info from this PC"
$form.Controls.Add($buttonGetWifiInfo)
# Ajout d'un gestionnaire d'événement pour le bouton Get Wifi info
$buttonGetWifiInfo.Add_Click({
$wifiInfo = .\PC_WifiInfo.ps1
$textboxSSID.Text = $wifiInfo.SSID
$textboxPassword.Text = $wifiInfo.Password
})
# Affichage du formulaire
$result = $form.ShowDialog()
# Traitement des résultats du formulaire
if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
# Récupération des valeurs des TextBox
$ssid = $textboxSSID.Text
$password = $textboxPassword.Text
# Renommer le fichier runtime.sh en runtime_ori.sh
$sourceFilePath = "$Target\.tmp_update\runtime.sh"
$targetFilePath = "$Target\.tmp_update\runtime_ori.sh"
if (Test-Path $sourceFilePath) {
if (-not (Test-Path $targetFilePath)) {
Rename-Item -Path $sourceFilePath -NewName $targetFilePath -Force
}
# Contenu du fichier runtime.sh à écrire
$runtimeContent = @"
killall -9 main
killall -9 updater
if [ ! -f /appconfigs/wpa_supplicant.conf ]; then
echo "ctrl_interface=/var/run/wpa_supplicant" > /appconfigs/wpa_supplicant.conf
echo "update_config=1" >> /appconfigs/wpa_supplicant.conf
fi
echo -e "\nnetwork={\n ssid=`\"$ssid`\"\n psk=`\"$password`\"\n}" >> /appconfigs/wpa_supplicant.conf
mv "/mnt/SDCARD/.tmp_update/runtime_ori.sh" "/mnt/SDCARD/.tmp_update/runtime.sh"
/mnt/SDCARD/.tmp_update/runtime.sh
"@
# Écrire le contenu dans le fichier runtime.sh
$runtimeContent = $runtimeContent -replace "`r`n", "`n" # Remplace les CRLF par LF
$runtimeContent | Out-File -FilePath "$Target\.tmp_update\runtime.sh" -Encoding utf8 -NoNewline
}
else {
# Remplacer le fichier updater avec le nouveau contenu
$updaterContent = @"
#!/bin/sh
killall -9 main
if [ ! -f /appconfigs/wpa_supplicant.conf ]; then
echo "ctrl_interface=/var/run/wpa_supplicant" > /appconfigs/wpa_supplicant.conf
echo "update_config=1" >> /appconfigs/wpa_supplicant.conf
fi
echo -e "\nnetwork={\n ssid=`"$ssid`"\n psk=`"$password`"\n}" >> /appconfigs/wpa_supplicant.conf
cd /mnt/SDCARD/miyoo/app
./MainUI
"@
$updaterContent = $updaterContent -replace "`r`n", "`n" # Remplace les CRLF par LF
$updaterContent | Out-File -FilePath "$Target\.tmp_update\updater" -Encoding utf8 -NoNewline
}
}