Added “useproxyfor” option

This commit is contained in:
pezcurrel 2024-08-21 10:54:55 +02:00
parent a15ebc4da5
commit 494eabf233

View file

@ -65,7 +65,8 @@ $opts=[
'bottoken'=>null,
'botmaxchars'=>null,
'_sendtoot'=>false,
'proxy'=>null
'proxy'=>null,
'useproxyfor'=>null
];
$msglevs=['Debug', 'Info', 'Warning', 'Error', 'None'];
@ -139,8 +140,11 @@ PROXY SUPPORT
This script supports socks5 proxy to connect to an instance. It will try to
use a proxy if it finds a readable «getinstinfo.ini» file in the same
directory it lives in, with a «proxy» parameter with this syntax:
[user:pass@]<host>[:port].
directory it lives in, with a «proxy» parameter defining the proxy to use and
a «useproxyfor» parameter including the hostname its working on (see
«SYNOPSIS» above).
«proxy» syntax: [user:pass@]<host>[:port]
«useproxyfor» syntax: host[,host][...]
LICENSE
@ -167,7 +171,8 @@ if (is_array($iniarr)) {
}
if (!is_null($opts['bothost']) && !is_null($opts['bottoken']) && !is_null($opts['botmaxchars']))
$opts['_sendtoot']=true;
if (isset($iniarr['proxy'])) $opts['proxy']=$iniarr['proxy'];
if (isset($iniarr['proxy']) && !isempty($iniarr['proxy'])) $opts['proxy']=$iniarr['proxy'];
if (isset($iniarr['useproxyfor']) && !isempty($iniarr['useproxyfor'])) $opts['useproxyfor']=explode(',',$iniarr['useproxyfor']);
} else {
eecho(1,"Could not open «{$inifp}» (it does not exist or is not readable).\n");
}
@ -265,6 +270,11 @@ eecho(1,'[[[ Working on «'.$opts['hostname'].'» ]]]'.N);
if (willtrunc($opts['hostname'],'Instances','URI'))
mexit('«'.$opts['hostname'].'»: ignoring it because hostname is too long for the «URI» column of «Instances» table.'.N,2);
if (is_array($opts['useproxyfor']) && !is_null($opts['proxy']) && in_array($opts['hostname'],$opts['useproxyfor']))
eecho(1,"«{$opts['hostname']}»: will use configured proxy («{$opts['proxy']}») to fetch its data.\n");
else
$opts['proxy']=null;
eecho(0,'«'.$opts['hostname'].'»: trying to fetch its info from the database...'.N);
$res=myq($link,'SELECT * FROM Instances WHERE URI=\''.myesc($link,$opts['hostname']).'\'',__LINE__);
$count=mysqli_num_rows($res);