-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsidndomainorder.php
241 lines (228 loc) · 7.23 KB
/
sidndomainorder.php
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
include_once("./crypt.php");
include_once("./epp.php");
include_once("./analyze.php");
include_once("./setorderperiod.php");
include_once("./infoorderperiod.php");
// I don't like globals, but the abort handler must be able to close the EPP connection
date_default_timezone_set("UTC");
$epp = null;
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')
{
declare(ticks = 1);
pcntl_signal(SIGTERM, "signal_handler");
pcntl_signal(SIGINT, "signal_handler");
}
error_reporting(E_ALL ^ E_NOTICE);
if ($argc<2)
{
die(usage());
}
else
{
// Retrieve extra parameters from the arguments
$simplefile = false;
$next = null;
foreach ($argv as $arg)
{
if (substr($arg,0,2)=='--')
{
list($subarg,$param)=explode('=',$arg);
if ($subarg == '--file')
{
if ($param == 'simple')
{
$simplefile = true;
}
}
if ($subarg == '--next')
{
$next = $param;
}
}
}
switch($argv[1])
{
case 'connect':
if ($params = load_settings())
{
echo "Settings succesfully loaded from file\n";
}
break;
case 'analyze':
if ($argc<3)
{
die(usage());
}
// Analyze the DOMAIN_ORDER_FREQUENCY report from SIDN
checkinput($argv[2]);
analyzefile($argv[2]);
break;
case 'info':
if ($argc<3)
{
die(usage());
}
checkinput($argv[2]);
// Info all domain names in the csv file
if ($params = load_settings())
{
infoorderperiod($argv[2],$params);
}
break;
case 'distill':
if ($argc<4)
{
die(usage());
}
if (($argv[3]!='1m') && ($argv[3]!='3m') && ($argv[3]!='12m'))
{
die(usage());
}
distill($argv[2],$argv[3],$next);
break;
case 'set1month':
if ($argc<3)
{
die(usage());
}
// Set all domain names in the specified file to 1-month order frequency
checkinput($argv[2]);
if ($params = load_settings())
{
if ($simplefile)
{
setsimpleorderperiods($argv[2],1, $params);
}
else
{
setorderperiods($argv[2],1, $params);
}
}
break;
case 'set3month':
if ($argc<3)
{
die(usage());
}
// Set all domain names in the specified file to 3-month order frequency
checkinput($argv[2]);
if ($params=load_settings())
{
if ($simplefile)
{
setsimpleorderperiods($argv[2],3, $params);
}
else
{
setorderperiods($argv[2],3, $params);
}
}
break;
case 'set12month':
if ($argc<3)
{
die(usage());
}
// Set all domain names in the specified file to 12-month order frequency
checkinput($argv[2]);
if ($params=load_settings())
{
if ($simplefile)
{
setsimpleorderperiods($argv[2],12, $params);
}
else
{
setorderperiods($argv[2],12, $params);
}
}
break;
default:
die(usage());
}
}
function checkinput($file)
{
if ($file)
{
if (!file_exists($file))
{
die("File ".$file." could not be opened. Please specify the correct file name. File names are case sensitive.");
}
}
else
{
die(usage());
}
}
function usage()
{
return "Usage: sidndomainorder.php connect\n\n sidndomainorder.php analyze <inputfile>\n\n Where inputfile is the SIDN domain order report from the registry website (DOMAIN_ORDER_FREQUENCY).\n\n sidndomainorder.php distill <inputfile> <1m|3m|12m> [--next=12m]\n\n Distill orders from the input file.\n\n sidndomainorder.php info <inputfile>\n Info all domain name order periods from the domain names on file\n\n sidndomainorder.php set1month <inputfile> [params]\n Reset all domain names in the report to 1-month order period\n\n sidndomainorder.php set3month <inputfile> [params]\n Reset all domain names in the report to 3-month order period\n\n sidndomainorder.php set12month <inputfile> [params]\n Reset all domain names in the report to 12-month order period\n\n [params]\n --file=simple\n Accept a simple list of domain names for the set1month, set3month or set12month functions\n\n";
}
function load_settings()
{
$inifile = "sidndomainorder.ini";
$crypt = new crypt('$NwkP^RC!wHLz7BDT7z$n09Wq4659Lxo');
if (file_exists($inifile))
{
$params = json_decode($crypt->Decrypt(file_get_contents($inifile)));
if ($params)
{
if ((strlen($params->username)>0) && (strlen($params->password)>0))
{
return $params;
}
else
{
die ("User login credentials not found in $inifile file. Please remove the file and re-enter your login credentials\n");
}
}
else
{
die("Decryption of $inifile failed. Please remove the file and re-enter you login credentials\n");
}
}
else
{
echo "Settings file not found, please specify EPP user name and password. User name and password will be stored in a secure file\n";
echo "Please specify the EPP user name: ";
$char = fgets(STDIN, 64);
$username = trim($char);
echo "Please specify the EPP password: ";
$char = fgets(STDIN, 64);
$password = trim($char);
echo "Connecting to SIDN EPP server with your login credentials...";
$epp = new epp($username,$password);
if ($epp->testconnection())
{
echo "\nConnection to EPP server successful, saving user credentials in a secure file.\n";
$params = array('username'=>$username,'password'=>$password);
$encodedparams = json_encode($params);
file_put_contents($inifile, $crypt->Crypt($encodedparams));
return json_decode($encodedparams);
}
else
{
echo "\nConnection to EPP service failed, please re-check your login details.\n";
return null;
}
}
}
function signal_handler($signal)
{
global $epp;
switch($signal)
{
case SIGTERM:
case SIGKILL:
case SIGINT:
print "Program aborted\n";
if ($epp)
{
echo "Closing SIDN EPP connection\n";
$epp->forcedisconnect();
}
exit;
}
}