本文整理汇总了PHP中IP::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP IP::isValid方法的具体用法?PHP IP::isValid怎么用?PHP IP::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IP
的用法示例。
在下文中一共展示了IP::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBogusIPs
public function testBogusIPs()
{
$invalid = array('www.xn--var-xla.net', '216.17.184.G', '216.17.184.1.', '216.17.184', '216.17.184.', '256.17.184.1');
foreach ($invalid as $i) {
$this->assertFalse(IP::isValid($i), "{$i} is an invalid IPv4 address");
}
}
示例2: execute
public function execute($sub)
{
global $wgOut, $wgRequest;
global $wgLandingPageBase, $wgChapterLandingPages, $wgLandingPageDefaultTarget;
$lang = preg_match('/^[A-Za-z-]+$/', $wgRequest->getVal('lang')) ? $wgRequest->getVal('lang') : 'en';
$utm_source = $wgRequest->getVal('utm_source');
$utm_medium = $wgRequest->getVal('utm_medium');
$utm_campaign = $wgRequest->getVal('utm_campaign');
$referrer = $wgRequest->getHeader('referer');
$target = $wgRequest->getVal('target', null);
if (!$target) {
$target = $wgLandingPageDefaultTarget;
}
$tracking = '?' . wfArrayToCGI(array('utm_source' => "{$utm_source}", 'utm_medium' => "{$utm_medium}", 'utm_campaign' => "{$utm_campaign}", 'referrer' => "{$referrer}", 'target' => "{$target}"));
$ip = $wgRequest->getVal('ip') ? $wgRequest->getVal('ip') : wfGetIP();
if (IP::isValid($ip)) {
$country = geoip_country_code_by_name($ip);
if (is_string($country) && array_key_exists($country, $wgChapterLandingPages)) {
$wgOut->redirect($this->getDestination($utm_source) . '/' . $wgChapterLandingPages[$country] . $tracking);
return;
}
}
// No valid IP or chapter page - let's just go for the passed in url or our fallback
if (Http::isValidURI($target)) {
$wgOut->redirect($target . '/' . $lang . $tracking);
return;
} else {
$wgOut->redirect($wgLandingPageBase . $target . '/' . $lang . $tracking);
}
}
示例3: save
function save()
{
$_POST["mac"] = str_replace("-", ":", $_POST["mac"]);
$_POST["mac"] = strtolower($_POST["mac"]);
$ipClass = new IP();
if (!$ipClass->IsvalidMAC($_POST["mac"])) {
echo "MAC: {$_POST["mac"]} Invalid!\n";
return;
}
if (!$ipClass->isValid($_POST["ipaddr"])) {
echo "MAC: {$_POST["ipaddr"]} Invalid!\n";
return;
}
$cmp = new computers();
$uid = $cmp->ComputerIDFromMAC($_POST["mac"]);
if ($uid != null) {
$cmp = new computers($uid);
}
if ($uid == null) {
$uid = "{$_POST["hostname"]}\$";
}
$cmp->uid = $uid;
$cmp->ComputerIP = $_POST["ipaddr"];
$cmp->ComputerMacAddress = $_POST["mac"];
$cmp->ComputerRealName = $_POST["hostname"];
if ($cmp->Add()) {
echo $cmp->ldap_error;
}
}
示例4: execute
function execute($par)
{
global $wgRequest, $wgOut, $wgFundraiserLPDefaults;
// Set the country parameter
$country = $wgRequest->getVal('country');
// If no country was passed do a GeoIP lookup
if (!$country) {
if (function_exists('geoip_country_code_by_name')) {
$ip = wfGetIP();
if (IP::isValid($ip)) {
$country = geoip_country_code_by_name($ip);
}
}
}
// If country still isn't set, set it to the default
if (!$country) {
$country = $wgFundraiserLPDefaults['country'];
}
$params = array('country' => $country);
// Pass any other params that are set
$excludeKeys = array('country', 'title');
foreach ($wgRequest->getValues() as $key => $value) {
// Skip the required variables
if (!in_array($key, $excludeKeys)) {
$params[$key] = $value;
}
}
// Redirect to FundraiserLandingPage
$wgOut->redirect($this->getTitleFor('FundraiserLandingPage')->getLocalUrl($params));
}
示例5: dns_add
function dns_add(){
$_POST["nameserver"]=trim($_POST["nameserver"]);
$IPClass=new IP();
if(!$IPClass->isValid($_POST["nameserver"])){
echo "{$_POST["nameserver"]} invalid\n";
return;
}
$nameserver[$_POST["nameserver"]]=true;
$q=new mysql_squid_builder();
$q->QUERY_SQL("INSERT INTO dns_servers (dnsserver,zOrder) VALUES ('{$_POST["nameserver"]}','1')");
if(!$q->ok){echo $q->mysql_error;}
}
示例6: enable_popup
function enable_popup(){
$page=CurrentPageName();
$tpl=new templates();
$sock=new sockets();
$UtDNSEnable=$sock->GET_INFO("UtDNSEnable");
if(!is_numeric($UtDNSEnable)){$UtDNSEnable=0;}
$UtDNSIPAddr=$sock->GET_INFO("UtDNSIPAddr");
$ip=new IP();
if(!$ip->isValid($UtDNSIPAddr)){$UtDNSIPAddr=$_SERVER["REMOTE_ADDR"];}
$t=time();
$html="
<div style='width:98%' class=form>
".Paragraphe_switch_img("{enable_disable_cloud_protection}", "{enable_disable_cloud_protection_explain}","UtDNSEnable-$t",$UtDNSEnable,null,450)."
<table style='width:100%'>
<tr>
<td class=legend style='font-size:16px'>{redirect_ip_address}:</td>
<td>". Field_text("UtDNSIPAddr",$UtDNSIPAddr,"font-size:16px;")."</td>
</tr>
</table>
<div style='width:99%;text-align:right;margin-top:20px'><hr>". button("{apply}","Save$t()",32)."</div>
</div>
<script>
var xSave$t= function (obj) {
var results=obj.responseText;
if(results.length>5){alert(results);}
CacheOff();
Loadjs('squid.restart.php?ApplyConfToo=yes&ask=yes');
}
function Save$t(){
var XHR = new XHRConnection();
XHR.appendData('UtDNSEnable',document.getElementById('UtDNSEnable-$t').value);
XHR.appendData('UtDNSIPAddr',document.getElementById('UtDNSIPAddr-$t').value);
XHR.sendAndLoad('$page', 'POST',xSave$t);
}
</script>
";
echo $tpl->_ENGINE_parse_body($html);
}
示例7: execute
public function execute()
{
$lb = wfGetLB();
if ($lb->getServerCount() == 1) {
$this->error("This script dumps replication lag times, but you don't seem to have\n" . "a multi-host db server configuration.");
} else {
$lags = $lb->getLagTimes();
foreach ($lags as $n => $lag) {
$host = $lb->getServerName($n);
if (IP::isValid($host)) {
$ip = $host;
$host = gethostbyaddr($host);
} else {
$ip = gethostbyname($host);
}
$starLen = min(intval($lag), 40);
$stars = str_repeat('*', $starLen);
$this->output(sprintf("%10s %20s %3d %s\n", $ip, $host, $lag, $stars));
}
}
}
示例8: execute
public function execute($sub)
{
global $wgRequest, $wgPriorityCountries;
// Pull in query string parameters
$language = $wgRequest->getVal('language', 'en');
$this->basic = $wgRequest->getBool('basic');
$country = $wgRequest->getVal('country');
// If no country was passed, try to do GeoIP lookup
// Requires php5-geoip package
if (!$country && function_exists('geoip_country_code_by_name')) {
$ip = wfGetIP();
if (IP::isValid($ip)) {
$country = geoip_country_code_by_name($ip);
}
}
if (!$country) {
$country = 'US';
// Default
}
// determine if we are fulfilling a request for a priority country
$priority = in_array($country, $wgPriorityCountries);
// handle the actual redirect
$this->routeRedirect($country, $language, $priority);
}
示例9: showViewFooter
/**
* Show the footer section of an ordinary page view
*/
public function showViewFooter()
{
global $wgOut, $wgUseTrackbacks;
# check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
if ($this->mTitle->getNamespace() == NS_USER_TALK && IP::isValid($this->mTitle->getText())) {
$wgOut->addWikiMsg('anontalkpagetext');
}
# If we have been passed an &rcid= parameter, we want to give the user a
# chance to mark this new article as patrolled.
$this->showPatrolFooter();
# Trackbacks
if ($wgUseTrackbacks) {
$this->addTrackbacks();
}
}
示例10: postfix_add_network_v2_save
function postfix_add_network_v2_save()
{
$tpl = new templates();
if ($_GET["ip_addr"] == null) {
echo $tpl->_ENGINE_parse_body('{error} :{address} -> Null! ');
return null;
}
if ($_GET["ip_addr2"] == null) {
echo $tpl->_ENGINE_parse_body('{error} :{address} -> Null! ');
return null;
}
include_once 'ressources/class.tcpip.inc';
$ip = new IP();
if (!$ip->isValid($_GET["ip_addr"])) {
echo $tpl->_ENGINE_parse_body('{error} :{address} {bad_format} -> ' . $_GET["ip_addr"]);
return null;
}
$cdir = $ip->ip2cidr($_GET["ip_addr"], $_GET["ip_addr2"]);
if ($cdir == null) {
echo $tpl->_ENGINE_parse_body('{error} :{address} {bad_format} -> ' . $_GET["ip_addr"] . "/" . $_GET["ip_addr2"]);
return null;
}
$main = new main_cf();
writelogs("save new {$cdir} for mynetwork settings", __FUNCTION__, __FILE__);
$response = $main->add_my_networks($cdir);
if ($response != null) {
echo $tpl->_ENGINE_parse_body("{error} :{$response}");
return null;
}
writelogs("save postfix configuration", __FUNCTION__, __FILE__);
$main->save_conf();
writelogs("save postfix configuration done", __FUNCTION__, __FILE__);
echo $tpl->_ENGINE_parse_body('{success}');
}
示例11: showViewFooter
/**
* Show the footer section of an ordinary page view
*/
public function showViewFooter()
{
# check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
if ($this->getTitle()->getNamespace() == NS_USER_TALK && IP::isValid($this->getTitle()->getText())) {
$this->getContext()->getOutput()->addWikiMsg('anontalkpagetext');
}
# If we have been passed an &rcid= parameter, we want to give the user a
# chance to mark this new article as patrolled.
$this->showPatrolFooter();
wfRunHooks('ArticleViewFooter', array($this));
}
示例12: parseTarget
/**
* From an existing Block, get the target and the type of target.
* Note that, except for null, it is always safe to treat the target
* as a string; for User objects this will return User::__toString()
* which in turn gives User::getName().
*
* @param string|int|User|null $target
* @return array( User|String|null, Block::TYPE_ constant|null )
*/
public static function parseTarget($target)
{
# We may have been through this before
if ($target instanceof User) {
if (IP::isValid($target->getName())) {
return array($target, self::TYPE_IP);
} else {
return array($target, self::TYPE_USER);
}
} elseif ($target === null) {
return array(null, null);
}
$target = trim($target);
if (IP::isValid($target)) {
# We can still create a User if it's an IP address, but we need to turn
# off validation checking (which would exclude IP addresses)
return array(User::newFromName(IP::sanitizeIP($target), false), Block::TYPE_IP);
} elseif (IP::isValidBlock($target)) {
# Can't create a User from an IP range
return array(IP::sanitizeRange($target), Block::TYPE_RANGE);
}
# Consider the possibility that this is not a username at all
# but actually an old subpage (bug #29797)
if (strpos($target, '/') !== false) {
# An old subpage, drill down to the user behind it
$parts = explode('/', $target);
$target = $parts[0];
}
$userObj = User::newFromName($target);
if ($userObj instanceof User) {
# Note that since numbers are valid usernames, a $target of "12345" will be
# considered a User. If you want to pass a block ID, prepend a hash "#12345",
# since hash characters are not valid in usernames or titles generally.
return array($userObj, Block::TYPE_USER);
} elseif (preg_match('/^#\\d+$/', $target)) {
# Autoblock reference in the form "#12345"
return array(substr($target, 1), Block::TYPE_AUTO);
} else {
# WTF?
return array(null, null);
}
}
示例13: import_file
function import_file()
{
$q = new mysql_squid_builder();
$filename = "/usr/share/artica-postfix/ressources/logs/web/nginx.import";
if (!is_file($filename)) {
echo "{$filename} no such file\n";
return;
}
$f = explode("\n", @file_get_contents($filename));
$IpClass = new IP();
while (list($index, $line) = each($f)) {
if (trim($line) == null) {
continue;
}
if (strpos($line, ",") == 0) {
continue;
}
$tr = explode(",", $line);
if (count($tr) < 2) {
continue;
}
$sourceserver = trim($tr[0]);
$sitename = trim($tr[1]);
if (!isset($tr[2])) {
$tr[2] = 0;
}
if (!isset($tr[3])) {
$tr[3] = null;
}
$ssl = $tr[2];
$forceddomain = $tr[3];
if (!preg_match("#(.+?):([0-9]+)#", $sourceserver, $re)) {
if ($ssl == 1) {
$sourceserver_port = 443;
}
if ($ssl == 0) {
$sourceserver_port = 80;
}
} else {
$sourceserver = trim($re[1]);
$sourceserver_port = $re[2];
}
if (!preg_match("#(.+?):([0-9]+)#", $sitename, $re)) {
if ($ssl == 1) {
$sitename_port = 443;
}
if ($ssl == 0) {
$sitename_port = 80;
}
} else {
$sitename = trim($re[1]);
$sitename_port = $re[2];
}
if ($forceddomain != null) {
$title_source = $forceddomain;
} else {
$title_source = $sourceserver;
}
echo "Importing {$sitename} ({$sitename_port}) -> {$sourceserver} ({$sourceserver_port})\n";
// On cherche la source:
if ($sitename == null) {
echo "Local sitename is null\n";
continue;
}
if ($sourceserver == null) {
echo "Source is null\n";
continue;
}
if (!$IpClass->isValid($sourceserver)) {
$tcp = gethostbyname($sourceserver);
if (!$IpClass->isValid($tcp)) {
echo "Source {$sourceserver} cannot be resolved\n";
continue;
}
}
$ligne = mysql_fetch_array($q->QUERY_SQL("SELECT ID FROM reverse_sources WHERE ipaddr='{$sourceserver}' AND `port`='{$sourceserver_port}'"));
$IDS = intval($ligne["ID"]);
if ($IDS == 0) {
$sql = "INSERT IGNORE INTO `reverse_sources` (`servername`,`ipaddr`,`port`,`ssl`,`enabled`,`forceddomain`)\n\t\t\tVALUES ('{$title_source}','{$sourceserver}','{$sourceserver_port}','{$ssl}',1,'{$forceddomain}')";
$q->QUERY_SQL($sql);
$ligne = mysql_fetch_array($q->QUERY_SQL("SELECT ID FROM reverse_sources WHERE ipaddr='{$sourceserver}' AND `port`='{$sourceserver_port}'"));
$IDS = intval($ligne["ID"]);
}
if ($IDS == 0) {
echo "Failed to add {$sourceserver}/{$sourceserver_port}/{$forceddomain}\n";
continue;
}
// On attaque le site web:
$ligne = mysql_fetch_array($q->QUERY_SQL("SELECT servername,cache_peer_id FROM reverse_www WHERE servername='{$sitename}'"));
if (trim($ligne["servername"] != null)) {
echo "{$sitename} already exists on cache ID : {$ligne["cache_peer_id"]}/{$IDS}\n";
if ($ligne["cache_peer_id"] != $IDS) {
$q->QUERY_SQL("UPDATE reverse_www SET `cache_peer_id`={$IDS} WHERE servername='{$sitename}'");
}
continue;
}
$sql = "INSERT IGNORE INTO `reverse_www` (`servername`,`cache_peer_id`,`port`,`ssl`) VALUES\n\t\t('{$sitename}','{$IDS}','{$sitename_port}','{$ssl}')";
$q->QUERY_SQL($sql);
if (!$q->ok) {
echo $q->mysql_error;
//.........这里部分代码省略.........
示例14: showViewFooter
/**
* Show the footer section of an ordinary page view
*/
public function showViewFooter()
{
# check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
if ($this->getTitle()->getNamespace() == NS_USER_TALK && IP::isValid($this->getTitle()->getText())) {
$this->getContext()->getOutput()->addWikiMsg('anontalkpagetext');
}
// Show a footer allowing the user to patrol the shown revision or page if possible
$patrolFooterShown = $this->showPatrolFooter();
Hooks::run('ArticleViewFooter', array($this, $patrolFooterShown));
}
示例15: instances_duplicate_perform
function instances_duplicate_perform(){
$tpl=new templates();
$tcp=new IP();
$q=new mysql();
$sock=new sockets();
$instance_hostname=$_GET["hostname"];
$instance_src_hostname=$_GET["src"];
$main=new maincf_multi($instance_src_hostname);
$novirtual=false;
$instance_ip=$_GET["ip"];
$instance_ip_src=$main->ip_addr;
if($instance_ip_src==null){echo $tpl->javascript_parse_text("\"$instance_src_hostname\" No such instance");return;}
$organization=$_GET["ou"];
if($organization==null){
echo $tpl->javascript_parse_text("{error_choose_organization}");return;}
if(trim($instance_hostname)==null){echo $tpl->javascript_parse_text("{instance_server_name}: NULL");return;}
if(!$tcp->isValid($instance_ip)){echo $tpl->javascript_parse_text("{ipaddr}: \"$instance_ip\" Invalid");return;}
if(!$tcp->isValid($instance_ip_src)){echo $tpl->javascript_parse_text("{ipaddr}: \"$instance_ip_src\" Invalid");return;}
$main=new maincf_multi(null,null,$instance_ip);
if($main->myhostname<>null){echo $tpl->javascript_parse_text("{ipaddr}: \"$instance_ip\" {already_used} -> $main->myhostname");return;}
$main=new maincf_multi($instance_hostname,null,null);
if($main->ip_addr<>null){echo $tpl->javascript_parse_text("{hostname}: \"$instance_hostname\" {already_used} -> $main->ip_addr");return;}
$sql="SELECT ipaddr FROM nics_virtuals WHERE ipaddr='$instance_ip'";
$ligne=mysql_fetch_array($q->QUERY_SQL($sql,"artica_backup"));
if($ligne["ipaddr"]<>null){echo $tpl->javascript_parse_text("{ipaddr}: \"$instance_ip\" {already_used} -> {virtual_interfaces}");return;}
$sql="SELECT ipaddr FROM nics_vlan WHERE ipaddr='$instance_ip'";
$ligne=mysql_fetch_array($q->QUERY_SQL($sql,"artica_backup"));
if($ligne["ipaddr"]<>null){
writelogs("Associated to a vlan -> unset Contruct virtuals addresses",__FUNCTION__,__FILE__,__LINE__);
$novirtual=true;
}
$PING=trim($sock->getFrameWork("cmd.php?ping=".urlencode($instance_ip)));
if($PING=="TRUE"){
echo $tpl->javascript_parse_text("$instance_ip:\n{ip_already_exists_in_the_network}");
return;
}
if(!$novirtual){
writelogs("No virtual: FALSE",__FUNCTION__,__FILE__,__LINE__);
$instance_ip_tbl=explode(".",$instance_ip);
unset($instance_ip_tbl[count($instance_ip_tbl)-1]);
$net=@implode(".",$instance_ip_tbl);
writelogs("virtual: net -> $net",__FUNCTION__,__FILE__,__LINE__);
$sql="SELECT * FROM nics_virtuals WHERE ipaddr LIKE '$net.%' ORDER BY ID DESC LIMIT 0,1";
$ligne=mysql_fetch_array($q->QUERY_SQL($sql,"artica_backup"));
if($ligne["ipaddr"]==null){echo $tpl->javascript_parse_text("{ipaddr}: \"$net*\" {no_such_interfaces} -> {virtual_interfaces}\n{you_need_to_create_virtual_ip_first}");return;}
writelogs("$net.* {$ligne["nic"]} -> $instance_ip/{$ligne["netmask"]}",__FUNCTION__,__FILE__,__LINE__);
$sql="INSERT INTO nics_virtuals (nic,org,ipaddr,netmask,cdir,gateway)
VALUES('{$ligne["nic"]}','$organization','$instance_ip','{$ligne["netmask"]}','{$ligne["cdir"]}','{$ligne["gateway"]}');";
$q=new mysql();
$q->QUERY_SQL($sql,"artica_backup");
if(!$q->ok){
writelogs("virtual:ERROR $q->mysql_error",__FUNCTION__,__FILE__,__LINE__);
echo $q->mysql_error;
return;
}
}
writelogs("All are OK -> starting importation",__FUNCTION__,__FILE__,__LINE__);
$sql="SELECT `key`,`value`,`ValueTEXT`,`uuid` FROM `postfix_multi` WHERE `ip_address`='$instance_ip_src'";
$results=$q->QUERY_SQL($sql,"artica_backup");
while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){
$key=$ligne["key"];
$value=$ligne["value"];
$ValueTEXT=$ligne["ValueTEXT"];
$uuid=$ligne["uuid"];
if($key=="inet_interfaces"){continue;}
if($key=="myhostname"){continue;}
$value=addslashes($value);
$ValueTEXT=addslashes($ValueTEXT);
$sql="INSERT INTO `postfix_multi`
(`key`,`value`,`ValueTEXT`,`uuid`,`ou`,`ip_address`)
VALUES('$key','$value','$ValueTEXT','$uuid','$organization','$instance_ip')";
writelogs($sql,__FUNCTION__,__FILE__,__LINE__);
$q->QUERY_SQL($sql,"artica_backup");
if(!$q->ok){
echo $q->mysql_error;
FailedIP($instance_ip);
return;
}
}
$sql="INSERT INTO `postfix_multi`
(`key`,`value`,`uuid`,`ou`,`ip_address`)
VALUES('inet_interfaces','$instance_ip','$uuid','$organization','$instance_ip')";
writelogs($sql,__FUNCTION__,__FILE__,__LINE__);
//.........这里部分代码省略.........