-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathie_server.php
58 lines (53 loc) · 1.55 KB
/
ie_server.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
#!/usr/bin/php
<?php
//Memcachedを利用する場合はtrueにしてください。
define('USE_MEMCACHED', false);
define('MEMCACHED_HOST', 'localhost');
define('MEMCACHED_PORT', 11211);
$objects = array(
array(
'username',
'domain',
'password'
)
);
define('IESERVER_URL', 'https://ieserver.net/cgi-bin/dip.cgi');
//IPアドレスの取得
$ip = trim(file_get_contents('http://ifconfig.me/ip'));
//IPアドレスが変更されているか調べる
if (USE_MEMCACHED) {
$cache = new memcached();
$cache->addServer(MEMCACHED_HOST, MEMCACHED_PORT);
$cachedip = $cache->get('ie_server:myipaddress');
} else {
$cachedipfile = __DIR__ . '/myipaddress';
if (file_exists($cachedipfile)) {
$cachedip = file($cachedipfile);
$cachedip = trim($cachedip[0]);
} else {
$cachedip = false;
}
}
if ($cachedip != $ip) {
foreach ($objects as $line) {
$curl = curl_init();
$post = 'username=' . $line[0] . '&domain=' . $line[1] . '&password=' . $line[2] . '&updatehost=1';
$options = array(
CURLOPT_URL => IESERVER_URL,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $post
);
curl_setopt_array($curl, $options);
curl_exec($curl);
curl_close($curl);
}
if (USE_MEMCACHED) {
$cache->set('ie_server:myipaddress', $ip);
} else {
$fp = fopen($cachedipfile, 'w');
fwrite($fp, $ip);
fclose($fp);
}
}