-
Notifications
You must be signed in to change notification settings - Fork 2
/
geniplist
executable file
·38 lines (34 loc) · 954 Bytes
/
geniplist
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
#!/usr/bin/php -f
<?php
/**
* 从http://:8080/api/queryAllMachine?cluster=ipcam获取ip列表
* 并存入目录,供easylogin程序使用
* 黑夜目录在$HOME/.easylogin下
*/
$HOME = getenv("HOME");
if(empty($HOME)){
die("NOT FIND HOME DIR\n");
}
$iplistdir = "$HOME/.easylogin/iplist";
if (!is_dir($iplistdir)) {
mkdir($iplistdir, 0777, true);
}
`rm -rf $iplistdir/*`;
iplist();
function iplist(){
$iplist = json_decode(file_get_contents("http://xxxx:8080/api/queryAllMachine"), true);
if(empty($iplist)){
die("No iplist found!\n");
}
global $iplistdir;
foreach($iplist as $clustername => $cluster){
mkdir($iplistdir."/".$clustername, 0777, true);
foreach($cluster as $cname => $component){
$ms = array();
foreach($component as $machine){
$ms[$machine['machine'] . "|$clustername/$cname"] = true;
}
file_put_contents($iplistdir."/".$clustername."/".$cname, implode("\n", array_keys($ms)), FILE_APPEND);
}
}
}