forked from KurtisLiggett/Simple-IP-Config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.au3
More file actions
95 lines (87 loc) · 3.8 KB
/
cli.au3
File metadata and controls
95 lines (87 loc) · 3.8 KB
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
; -----------------------------------------------------------------------------
; This file is part of Simple IP Config.
;
; Simple IP Config is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; Simple IP Config is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with Simple IP Config. If not, see <http://www.gnu.org/licenses/>.
;
;
; The CLI commands:
;
; Command: /set-config
; Params: "profile name"
; -----------------------------------------------------------------------------
Global $cmdLine
Func CheckCmdLine()
If $CMDLINE[0] Then
If (UBound($CMDLINE) = 3) Then
Switch $CMDLINE[1]
Case '/set-config'
$profileName = $CMDLINE[2]
; Code for configuration
_loadProfiles()
; Let's check if the profile name exists
If NOT Profiles_isNewName($profiles, $profileName) Then
$cmdLine = 1
$sMsg = 'Applying profile "' & $profileName & '"...'
_Toast_Set(0, 0xAAAAAA, 0x000000, 0xFFFFFF, 0x000000, 10, "", 250, 250)
$aRet = _Toast_Show(0, "Simple IP Config", $sMsg, 0, False) ; Delay can be set here because script continues
$ipAuto = Profiles_GetValue($profiles, $profileName, $PROFILES_IpAuto)
$ipAddress = Profiles_GetValue($profiles, $profileName, $PROFILES_IpAddress)
$ipSubnet = Profiles_GetValue($profiles, $profileName, $PROFILES_IpSubnet)
$ipGateway = Profiles_GetValue($profiles, $profileName, $PROFILES_IpGateway)
$dnsAuto = Profiles_GetValue($profiles, $profileName, $PROFILES_DnsAuto)
$dnsPref = Profiles_GetValue($profiles, $profileName, $PROFILES_DnsPref)
$dnsAlt = Profiles_GetValue($profiles, $profileName, $PROFILES_DnsAlt)
$dnsReg = Profiles_GetValue($profiles, $profileName, $PROFILES_RegisterDns)
$adapterName = Profiles_GetValue($profiles, $profileName, $PROFILES_AdapterName)
_apply($ipAuto, $ipAddress, $ipSubnet, $ipGateway, $dnsAuto, $dnsPref, $dnsAlt, $dnsReg, $adapterName, RunCallback_cli)
_cmdLineMain($profileName)
EndIf
$sMsg = 'The profile "' & $profileName & '" could not be found.'
_Toast_Set(0, 0xFF0000, 0xFFFFFF, 0xFFFFFF, 0x000000, 10, "", 250, 250)
$aRet = _Toast_Show(0, "Simple IP Config", $sMsg, -3, True) ; Delay can be set here because script continues
Case Else
Exit
EndSwitch
Exit
Else
$sMsg = "Incorrect number of parameters."
_Toast_Set(0, 0xFF0000, 0xFFFFFF, 0xFFFFFF, 0x000000, 10, "", 250, 250)
$aRet = _Toast_Show(0, "Simple IP Config", $sMsg, -3, True) ; Delay can be set here because script continues
Exit
EndIf
EndIf
EndFunc
Func RunCallback_cli($sDescription, $sNextDescription, $sStdOut)
Return 0
EndFunc
;main loop when called from CLI
;Loop and do nothing until the profile has been set
Func _cmdLineMain($profileName)
While 1
If asyncRun_isIdle() Then
_Toast_Hide()
If StringInStr($sStdOut, "failed") Then
$sMsg = 'An error occurred while applying the profile "' & $profileName & '".' &@CRLF&@CRLF&$sStdOut
_Toast_Set(0, 0xFF0000, 0xFFFFFF, 0xFFFFFF, 0x000000, 10, "", 250, 250)
$aRet = _Toast_Show(0, "Simple IP Config", $sMsg, -7, True) ; Delay can be set here because script continues
Else
$sMsg = 'Profile "' & $profileName & '" applied successfully.'
_Toast_Set(0, 0xAAAAAA, 0x000000, 0xFFFFFF, 0x000000, 10, "", 250, 250)
$aRet = _Toast_Show(0, "Simple IP Config", $sMsg, 2, True) ; Delay can be set here because script continues
EndIf
Exit
EndIf
Sleep(100)
WEnd
EndFunc