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
|
define_type(
'cname',
-namespace='zoneedit_',
-prototype,
-description='Add, remove, and list cnames for the given zone at ZoneEdit.'
);
local(
'username' = string,
'password' = string,
'zone' = string,
'cname' = string,
'cnames' = array,
'target' = string
);
define_tag(
'oncreate',
-req='zone',
-req='username',
-req='password'
);
self->zone = #zone;
self->username = #username;
self->password = #password;
/define_tag;
define_tag(
'send',
-req='post',
-encodenone
);
local('response') = string;
protect;
#response = include_url(
'https://www.zoneedit.com/auth/edit.html?zone=' + self->zone + '&type=CNAME',
-username = self->username,
-password = self->password,
-postparams = #post,
-timeout = 15
);
/protect;
return(#response);
/define_tag;
define_tag(
'add',
-req='cname',
-req='target'
);
local(
'out' = false,
'response' = string,
'postparams' = array(
'AddNew' = 'Add New Alias',
'dnsfrom' = #cname,
'dnsto' = #target,
'confirm' = 'Yes'
)
);
#response = self->send(#postparams);
#response >> '<span class="subzone">' + #cname + '.</span>' ? #out = true;
return(#out);
/define_tag;
define_tag('list');
local(
'response' = string,
'names' = null,
'ids' = null,
'out' = array
);
#response = self->send(array);
#names = string_findregexp(
#response,
-find='<span class="subzone">([a-z0-9\\-\\.]+?)\\.</span>',
-ignorecase
)->removeall(
match_regexp('<span class="subzone">[a-z0-9\\-\\.]+?\\.</span>')
)&;
#ids = string_findregexp(
#response,
-find='<input type="checkbox" name="del" value="([0-9]+)">',
-ignorecase
)->removeall(
match_regexp('<input type="checkbox" name="del" value="[0-9]+">')
)&;
iterate(#names, local('i'));
protect;
#out->insert(#i = #ids->get(loop_count));
/protect;
/iterate;
return(#out);
/define_tag;
define_tag(
'remove',
-req='cname'
);
local('cnames') = self->list;
protect;
local('id') = #cnames->find(#cname)->first->second;
handle_error;
return(false);
/handle_error;
/protect;
local(
'out' = false,
'response' = string,
'postparams' = array(
'Delete' = 'Delete Selected',
'del' = #id,
'confirm' = 'Yes'
)
);
#response = self->send(#postparams);
#out = (#response !>> ('<span class="subzone">' + #cname + '.</span>'));
return(#out);
/define_tag;
/define_type;
|