-
Notifications
You must be signed in to change notification settings - Fork 15
/
Pubyun.rsc
82 lines (75 loc) · 2.97 KB
/
Pubyun.rsc
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
# Pubyun ddns update
# 脚本依赖 loadModule logger
# local variable
:local logTag "Pubyun"
# 脚本日志级别
:local logLevel "DEBUG"
# Load module
:global loadModule; if ( !any $loadModule ) do={
do {/system script run [find name=loadModule]} on-error={:error "Script loadModule not found!"}
}
# set log level to debug
:local logger ([ $loadModule logger init=({"logTag"=$logTag;"level"=$logLevel;}) ]->"logger")
:local return do={
:local msg
if (any $2 and $1 = "error") do={
set msg $2
return {
"result"=false;
"logMessage"=$msg;
"info"=$info
}
}
return {"result"=true; "info"=$info}
}
# 更新地址
## 必须传入参数
## - Dep: 函数依赖数组
## - user: pubyun 的用户名
## - password: 函数依赖数组
## - domain: 函数依赖数组
## - ipaddress: ipv4 地址
:local update do={
:local logTag "update"
if ( ! any $Dep ) do={ :error message=("[$logTag] <update> Dep(Dependency) is not defined!") }
:local return ($Dep->"return")
:local logger ($Dep->"logger")
:local result
:local functionName $logTag
:local apiUrl "http://members.3322.org/dyndns/update?"
if (! any $user) do={ return [ $return error ("<$functionName> user is not defined!") ] }
if (! any $password) do={ return [ $return error ("<$functionName> password is not defined!") ] }
if (! any $domain) do={ return [ $return error ("<$functionName> domain is not defined!") ] }
if (! any $ipaddress) do={ return [ $return error ("<$functionName> ipaddress is not defined!") ] }
:local payload ("hostname=$domain&myip=$ipaddress")
:set apiUrl ($apiUrl . $payload)
$logger debug ("[$logTag] ====================== Request parameter======================")
$logger debug ("[$logTag] user: $user")
$logger debug ("[$logTag] password: $password")
$logger debug ("[$logTag] domain: $domain")
$logger debug ("[$logTag] ipaddress: $ipaddress")
$logger debug ("[$logTag] ====================== Request full command ======================")
$logger debug ("[$logTag] tool fetch url=$apiUrl mode=http user=$user password=$password output=user as-value")
do {
set result [/tool fetch url=$apiUrl mode=http user=$user password=$password output=user as-value]
} on-error={
return [ $return error ("[$logTag] <$functionName> Failed to update IP address!") ]
}
$logger debug ("[$logTag] ====================== Request result ======================")
$logger debug ("[$logTag] " . [:tostr $result]);
$logger debug ("[$logTag] ====================== END ======================")
if ( ! any [find ($result->"data") "good"] ) do={
if ( ! any [ find ($result->"data") "nochg" ] ) do={
return [ $return error ("<$functionName> Failed to update IP address! " . ($result->data)) ]
}
}
return [ $return ]
}
return {
"moduleName"="Pubyun";
"update"=$update;
"Dep"={
"return"=$return;
"logger"=$logger;
}
}