Added regexps check before adding an inst to “Instances” and “Peers” tables
This commit is contained in:
parent
738fa8c864
commit
943c65b2ba
1 changed files with 34 additions and 30 deletions
|
@ -289,38 +289,42 @@ function crawl(&$list,$id) {
|
|||
}
|
||||
}
|
||||
}
|
||||
$responded=false;
|
||||
lecho(1,'trying to load «'.$inst.'»’s instance info...'.N);
|
||||
$instinfo=gurl('https://'.$inst.'/api/v1/instance/peers',$opts['timeout'],$opts['curltimeout']);
|
||||
if ($instinfo['cont']===false) {
|
||||
lecho(2,'could not load «'.$inst.'»’s instance info: '.$instinfo['emsg'].'.'.N);
|
||||
} else {
|
||||
$instinfo=@json_decode($instinfo['cont'],true);
|
||||
if (is_array($instinfo))
|
||||
$responded=true;
|
||||
else
|
||||
lecho(2,'loading «'.$inst.'»’s instance info, got bad JSON.'.N);
|
||||
}
|
||||
if ($responded && !in_array($inst,$insts)) {
|
||||
lecho(1,'instance «'.$inst.'» responded :-)'.N);
|
||||
$insts[]=$inst;
|
||||
$res=myq($link,'SELECT ID FROM Instances WHERE URI=\''.myesc($link,$inst).'\'');
|
||||
if (mysqli_num_rows($res)==0) {
|
||||
lecho(1,'instance «'.$inst.'» is new :-)'.N);
|
||||
myq($link,'INSERT INTO Instances SET URI=\''.myesc($link,$inst).'\', InsertTS='.$now);
|
||||
$newc++;
|
||||
if (!ckexarr($inst)) {
|
||||
$responded=false;
|
||||
lecho(1,'trying to load «'.$inst.'»’s instance info...'.N);
|
||||
$instinfo=gurl('https://'.$inst.'/api/v1/instance',$opts['timeout'],$opts['curltimeout']);
|
||||
if ($instinfo['cont']===false) {
|
||||
lecho(2,'could not load «'.$inst.'»’s instance info: '.$instinfo['emsg'].'.'.N);
|
||||
} else {
|
||||
$instinfo=@json_decode($instinfo['cont'],true);
|
||||
if (is_array($instinfo))
|
||||
$responded=true;
|
||||
else
|
||||
lecho(2,'loading «'.$inst.'»’s instance info, got bad JSON.'.N);
|
||||
}
|
||||
if ($responded && !in_array($inst,$insts)) {
|
||||
lecho(1,'instance «'.$inst.'» responded :-)'.N);
|
||||
$insts[]=$inst;
|
||||
$res=myq($link,'SELECT ID FROM Instances WHERE URI=\''.myesc($link,$inst).'\'');
|
||||
if (mysqli_num_rows($res)==0) {
|
||||
lecho(1,'instance «'.$inst.'» is new :-)'.N);
|
||||
myq($link,'INSERT INTO Instances SET URI=\''.myesc($link,$inst).'\', InsertTS='.$now);
|
||||
$newc++;
|
||||
}
|
||||
}
|
||||
$res=myq($link,'SELECT * FROM Peers WHERE Hostname=\''.myesc($link,$inst).'\'');
|
||||
$nrows=mysqli_num_rows($res);
|
||||
if ($nrows>0) {
|
||||
if ($nrows>1) lecho(2,'«'.$inst.'» has '.$nrows.' records in “Peers” table! :-('.N);
|
||||
$row=mysqli_fetch_assoc($res);
|
||||
if ($responded) myq($link,'UPDATE Peers SET LastOkCheckTS='.$now.' WHERE ID='.$row['ID']);
|
||||
} else {
|
||||
$query='INSERT INTO Peers SET Hostname=\''.myesc($link,$inst).'\', FirstCheckTS='.$now;
|
||||
if ($responded) $query.=', LastOkCheckTS='.$now;
|
||||
myq($link,$query);
|
||||
}
|
||||
}
|
||||
$res=myq($link,'SELECT * FROM Peers WHERE Hostname=\''.myesc($link,$inst).'\'');
|
||||
$nrows=mysqli_num_rows($res);
|
||||
if ($nrows>0) {
|
||||
if ($nrows>1) lecho(2,'«'.$inst.'» has '.$nrows.' records in “Peers” table! :-('.N);
|
||||
$row=mysqli_fetch_assoc($res);
|
||||
if ($responded) myq($link,'UPDATE Peers SET LastOkCheckTS='.$now.' WHERE ID='.$row['ID']);
|
||||
} else {
|
||||
$query='INSERT INTO Peers SET Hostname=\''.myesc($link,$inst).'\', FirstCheckTS='.$now;
|
||||
if ($responded) $query.=', LastOkCheckTS='.$now;
|
||||
myq($link,$query);
|
||||
lecho(2,'ignoring instance «'.$inst.'» because it matches an exclusion regexp: won’t add it to «Instances» and «Peers» tables.'.N);
|
||||
}
|
||||
}
|
||||
unset($list);
|
||||
|
|
Loading…
Reference in a new issue