本文整理汇总了PHP中IP::isIPAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP IP::isIPAddress方法的具体用法?PHP IP::isIPAddress怎么用?PHP IP::isIPAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IP
的用法示例。
在下文中一共展示了IP::isIPAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: trySubmit
function trySubmit()
{
global $wgOut, $wgUser;
$errors = array();
$ip = $this->mUnblockIP;
if (!IP::isIPAddress($ip) && strlen($ip)) {
$errors[] = array('globalblocking-unblock-ipinvalid', $ip);
$ip = '';
}
if (0 == ($id = GlobalBlocking::getGlobalBlockId($ip))) {
$errors[] = array('globalblocking-notblocked', $ip);
}
if (count($errors) > 0) {
return $errors;
}
$dbw = GlobalBlocking::getGlobalBlockingMaster();
$dbw->delete('globalblocks', array('gb_id' => $id), __METHOD__);
$page = new LogPage('gblblock');
$page->addEntry('gunblock', Title::makeTitleSafe(NS_USER, $ip), $this->mReason);
$successmsg = wfMsgExt('globalblocking-unblock-unblocked', array('parse'), $ip, $id);
$wgOut->addHTML($successmsg);
$link = $wgUser->getSkin()->makeKnownLinkObj(SpecialPage::getTitleFor('GlobalBlockList'), wfMsg('globalblocking-return'));
$wgOut->addHTML($link);
$wgOut->setSubtitle(wfMsg('globalblocking-unblock-successsub'));
return array();
}
示例2: validate
/**
* @param string|MWRestrictions $value The value the field was submitted with
* @param array $alldata The data collected from the form
*
* @return bool|string True on success, or String error to display, or
* false to fail validation without displaying an error.
*/
public function validate($value, $alldata)
{
if ($this->isHidden($alldata)) {
return true;
}
if (isset($this->mParams['required']) && $this->mParams['required'] !== false && $value instanceof MWRestrictions && !$value->toArray()['IPAddresses']) {
return $this->msg('htmlform-required')->parse();
}
if (is_string($value)) {
// MWRestrictions::newFromArray failed; one of the IP ranges must be invalid
$status = Status::newGood();
foreach (explode(PHP_EOL, $value) as $range) {
if (!\IP::isIPAddress($range)) {
$status->fatal('restrictionsfield-badip', $range);
}
}
if ($status->isOK()) {
$status->fatal('unknown-error');
}
return $status->getMessage()->parse();
}
if (isset($this->mValidationCallback)) {
return call_user_func($this->mValidationCallback, $value, $alldata, $this->mParent);
}
return true;
}
示例3: execute
public function execute($par)
{
global $wgLogRestrictions;
$this->setHeaders();
$this->outputHeader();
$opts = new FormOptions();
$opts->add('type', '');
$opts->add('user', '');
$opts->add('page', '');
$opts->add('pattern', false);
// $opts->add( 'year', null, FormOptions::INTNULL ); don't default to zero
$opts->add('year', '');
$opts->add('month', null, FormOptions::INTNULL);
$opts->add('tagfilter', '');
$opts->add('offset', '');
$opts->add('dir', '');
$opts->add('offender', '');
// Set values
$opts->fetchValuesFromRequest($this->getRequest());
if ($par !== null) {
$this->parseParams($opts, (string) $par);
}
# Don't let the user get stuck with a certain date
if ($opts->getValue('offset') || $opts->getValue('dir') == 'prev') {
$opts->setValue('year', '');
$opts->setValue('month', '');
}
// If the user doesn't have the right permission to view the specific
// log type, throw a PermissionsError
// If the log type is invalid, just show all public logs
$type = $opts->getValue('type');
if (!LogPage::isLogType($type)) {
$opts->setValue('type', '');
} elseif (isset($wgLogRestrictions[$type]) && !$this->getUser()->isAllowed($wgLogRestrictions[$type])) {
throw new PermissionsError($wgLogRestrictions[$type]);
}
# Handle type-specific inputs
$qc = array();
if ($opts->getValue('type') == 'suppress') {
$offender = User::newFromName($opts->getValue('offender'), false);
if ($offender && $offender->getId() > 0) {
$qc = array('ls_field' => 'target_author_id', 'ls_value' => $offender->getId());
} elseif ($offender && IP::isIPAddress($offender->getName())) {
$qc = array('ls_field' => 'target_author_ip', 'ls_value' => $offender->getName());
}
}
# Some log types are only for a 'User:' title but we might have been given
# only the username instead of the full title 'User:username'. This part try
# to lookup for a user by that name and eventually fix user input. See bug 1697.
wfRunHooks('GetLogTypesOnUser', array(&$this->typeOnUser));
if (in_array($opts->getValue('type'), $this->typeOnUser)) {
# ok we have a type of log which expect a user title.
$target = Title::newFromText($opts->getValue('page'));
if ($target && $target->getNamespace() === NS_MAIN) {
# User forgot to add 'User:', we are adding it for him
$opts->setValue('page', Title::makeTitleSafe(NS_USER, $opts->getValue('page')));
}
}
$this->show($opts, $qc);
}
示例4: lookupIPActivity
/**
* Gets wikis an IP address might have edits on
*
* @author Daniel Grunwell (Grunny)
* @param String $ipAddress The IP address to lookup
*/
public static function lookupIPActivity($ipAddress)
{
global $wgDevelEnvironment, $wgSpecialsDB;
wfProfileIn(__METHOD__);
if (empty($ipAddress) || !IP::isIPAddress($ipAddress)) {
wfProfileOut(__METHOD__);
return false;
}
$result = [];
$ipLong = ip2long($ipAddress);
if (empty($wgDevelEnvironment)) {
$dbr = wfGetDB(DB_SLAVE, [], $wgSpecialsDB);
$res = $dbr->select(['multilookup'], ['ml_city_id'], ['ml_ip' => $ipLong], __METHOD__);
foreach ($res as $row) {
if (!in_array($row->ml_city_id, self::$excludedWikis)) {
if (WikiFactory::isPublic($row->ml_city_id)) {
$result[] = (int) $row->ml_city_id;
}
}
}
$dbr->freeResult($res);
} else {
// on devbox - set up the list manually
$result = [165];
}
wfProfileOut(__METHOD__);
return $result;
}
示例5: showList
function showList()
{
global $wgOut, $wgScript;
$errors = array();
// Validate search IP
$ip = $this->mSearchIP;
if (!IP::isIPAddress($ip) && strlen($ip)) {
$errors[] = array('globalblocking-list-ipinvalid', $ip);
$ip = '';
}
$wgOut->addWikiMsg('globalblocking-list-intro');
// Build the search form
$searchForm = '';
$searchForm .= Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('globalblocking-search-legend'));
$searchForm .= Xml::openElement('form', array('method' => 'get', 'action' => $wgScript, 'name' => 'globalblocklist-search'));
$searchForm .= Html::hidden('title', SpecialPage::getTitleFor('GlobalBlockList')->getPrefixedText());
if (is_array($errors) && count($errors) > 0) {
$errorstr = '';
foreach ($errors as $error) {
if (is_array($error)) {
$msg = array_shift($error);
} else {
$msg = $error;
$error = array();
}
$errorstr .= Xml::tags('li', null, wfMsgExt($msg, array('parseinline'), $error));
}
$wgOut->addWikiMsg('globalblocking-unblock-errors', count($errors));
$wgOut->addHTML(Xml::tags('ul', array('class' => 'error'), $errorstr));
}
$fields = array();
$fields['globalblocking-search-ip'] = Xml::input('ip', 45, $ip);
$searchForm .= Xml::buildForm($fields, 'globalblocking-search-submit');
$searchForm .= Xml::closeElement('form') . Xml::closeElement('fieldset');
$wgOut->addHTML($searchForm);
// Build a list of blocks.
$conds = array();
if (strlen($ip)) {
list($range_start, $range_end) = IP::parseRange($ip);
if ($range_start != $range_end) {
// They searched for a range. Match that exact range only
$conds = array('gb_address' => $ip);
} else {
// They searched for an IP. Match any range covering that IP
$hex_ip = IP::toHex($ip);
$ip_pattern = substr($hex_ip, 0, 4) . '%';
// Don't bother checking blocks out of this /16.
$dbr = wfGetDB(DB_SLAVE);
$conds = array('gb_range_end>=' . $dbr->addQuotes($hex_ip), 'gb_range_start<=' . $dbr->addQuotes($hex_ip), 'gb_range_start like ' . $dbr->addQuotes($ip_pattern), 'gb_expiry>' . $dbr->addQuotes($dbr->timestamp(wfTimestampNow())));
}
}
$pager = new GlobalBlockListPager($this, $conds);
$body = $pager->getBody();
if ($body != '') {
$wgOut->addHTML($pager->getNavigationBar() . Html::rawElement('ul', array(), $body) . $pager->getNavigationBar());
} else {
$wgOut->wrapWikiMsg("<div class='mw-globalblocking-noresults'>\n\$1</div>\n", array('globalblocking-list-noresults'));
}
}
示例6: wfSpecialLog
/**
* constructor
*/
function wfSpecialLog($par = '')
{
global $wgRequest, $wgOut, $wgUser, $wgLogTypes;
# Get parameters
$parms = explode('/', $par = $par !== null ? $par : '');
$symsForAll = array('*', 'all');
if ($parms[0] != '' && (in_array($par, $wgLogTypes) || in_array($par, $symsForAll))) {
$type = $par;
$user = $wgRequest->getText('user');
} else {
if (count($parms) == 2) {
$type = $parms[0];
$user = $parms[1];
} else {
$type = $wgRequest->getVal('type');
$user = $par != '' ? $par : $wgRequest->getText('user');
}
}
$title = $wgRequest->getText('page');
$pattern = $wgRequest->getBool('pattern');
$y = $wgRequest->getIntOrNull('year');
$m = $wgRequest->getIntOrNull('month');
$tagFilter = $wgRequest->getVal('tagfilter');
# Don't let the user get stuck with a certain date
$skip = $wgRequest->getText('offset') || $wgRequest->getText('dir') == 'prev';
if ($skip) {
$y = '';
$m = '';
}
# Handle type-specific inputs
$qc = array();
if ($type == 'suppress') {
$offender = User::newFromName($wgRequest->getVal('offender'), false);
if ($offender && $offender->getId() > 0) {
$qc = array('ls_field' => 'target_author_id', 'ls_value' => $offender->getId());
} else {
if ($offender && IP::isIPAddress($offender->getName())) {
$qc = array('ls_field' => 'target_author_ip', 'ls_value' => $offender->getName());
}
}
}
# Create a LogPager item to get the results and a LogEventsList item to format them...
$loglist = new LogEventsList($wgUser->getSkin(), $wgOut, 0);
$pager = new LogPager($loglist, $type, $user, $title, $pattern, $qc, $y, $m, $tagFilter);
# Set title and add header
$loglist->showHeader($pager->getType());
# Show form options
$loglist->showOptions($pager->getType(), $pager->getUser(), $pager->getPage(), $pager->getPattern(), $pager->getYear(), $pager->getMonth(), $pager->getFilterParams(), $tagFilter);
# Insert list
$logBody = $pager->getBody();
if ($logBody) {
$wgOut->addHTML($pager->getNavigationBar() . $loglist->beginLogEventsList() . $logBody . $loglist->endLogEventsList() . $pager->getNavigationBar());
} else {
$wgOut->addWikiMsg('logempty');
}
}
示例7: testisIPAddress
/**
* @covers IP::isIPAddress
*/
public function testisIPAddress()
{
$this->assertTrue(IP::isIPAddress('::'), 'RFC 4291 IPv6 Unspecified Address');
$this->assertTrue(IP::isIPAddress('::1'), 'RFC 4291 IPv6 Loopback Address');
$this->assertTrue(IP::isIPAddress('74.24.52.13/20', 'IPv4 range'));
$this->assertTrue(IP::isIPAddress('fc:100:a:d:1:e:ac:0/24'), 'IPv6 range');
$this->assertTrue(IP::isIPAddress('fc::100:a:d:1:e:ac/96'), 'IPv6 range with "::"');
$validIPs = array('fc:100::', 'fc:100:a:d:1:e:ac::', 'fc::100', '::fc:100:a:d:1:e:ac', '::fc', 'fc::100:a:d:1:e:ac', 'fc:100:a:d:1:e:ac:0', '124.24.52.13', '1.24.52.13');
foreach ($validIPs as $ip) {
$this->assertTrue(IP::isIPAddress($ip), "{$ip} is a valid IP address");
}
}
示例8: __construct
/**
* Construct an IP address representation.
* @param string $address The textual representation of an IP address or CIDR range.
*/
public function __construct($address)
{
// analyze address format
$this->is_valid = IP::isIPAddress($address);
if (!$this->is_valid) {
return;
}
$this->is_ipv4 = IP::isIPv4($address);
$this->is_ipv6 = !$this->is_ipv4 && IP::isIPv6($address);
// analyze address range
$this->is_range = IP::isValidBlock($address);
$this->encoded_range = IP::parseRange($address);
$this->range = array(IP::prettifyIP(IP::formatHex($this->encoded_range[self::START])), IP::prettifyIP(IP::formatHex($this->encoded_range[self::END])));
}
示例9: index
public function index()
{
wfProfileIn(__METHOD__);
if (!$this->getUser()->isAllowed('coppatool')) {
wfProfileOut(__METHOD__);
$this->displayRestrictionError();
return false;
}
$this->specialPage->setHeaders();
$this->response->setTemplateEngine(WikiaResponse::TEMPLATE_ENGINE_MUSTACHE);
$this->userName = trim($this->getVal('username', $this->getPar()));
$this->isIP = false;
$this->validUser = false;
if (IP::isIPAddress($this->userName)) {
$this->userName = IP::sanitizeIP($this->userName);
$this->isIP = true;
$this->validUser = true;
} else {
$userObj = User::newFromName($this->userName);
if (!$userObj || $userObj->getId() === 0) {
$this->validUser = false;
} else {
$this->userName = $userObj->getName();
$this->validUser = true;
}
}
$this->userForm = $this->app->renderView('WikiaStyleGuideForm', 'index', ['form' => ['isInvalid' => $this->validUser || $this->userName === '' ? false : true, 'errorMsg' => $this->validUser || $this->userName === '' ? '' : $this->msg('coppatool-nosuchuser', $this->userName)->escaped(), 'inputs' => [['type' => 'text', 'name' => 'username', 'isRequired' => true, 'label' => $this->msg('coppatool-label-username')->escaped(), 'value' => Sanitizer::encodeAttribute($this->userName)], ['type' => 'submit', 'value' => $this->msg('coppatool-submit')->escaped()]], 'method' => 'GET', 'action' => $this->getTitle()->getLocalUrl()]]);
if ($this->validUser) {
$this->getOutput()->addModules('ext.coppaTool');
$this->buttons = [];
$this->blankImgUrl = wfBlankImgUrl();
$this->formHeading = $this->msg('coppatool-form-header')->escaped();
if (!$this->isIP) {
$this->buttons[] = ['buttonAction' => 'disable-account', 'buttonLink' => Html::element('a', ['href' => '#'], $this->msg('coppatool-disable')->escaped()), 'done' => $userObj->getGlobalFlag('disabled', false)];
$this->buttons[] = ['buttonAction' => 'blank-profile', 'buttonLink' => Html::element('a', ['href' => '#'], $this->msg('coppatool-blank-user-profile')->escaped())];
$this->buttons[] = ['buttonAction' => 'delete-userpages', 'buttonLink' => Html::element('a', ['href' => '#'], $this->msg('coppatool-delete-user-pages')->escaped())];
$this->buttons[] = ['buttonAction' => 'coppa-imagereview', 'buttonLink' => Linker::link(Title::newFromText('CoppaImageReview', NS_SPECIAL), $this->msg('coppatool-imagereview')->escaped(), ['target' => '_blank'], ['username' => $this->userName], ['known', 'noclasses'])];
} else {
$this->buttons[] = ['buttonAction' => 'phalanx-ip', 'buttonLink' => Linker::link(Title::newFromText('Phalanx', NS_SPECIAL), $this->msg('coppatool-phalanx-ip')->escaped(), ['target' => '_blank'], ['type' => Phalanx::TYPE_USER, 'wpPhalanxCheckBlocker' => $this->userName, 'target' => $this->userName], ['known', 'noclasses'])];
$this->buttons[] = ['buttonAction' => 'rename-ip', 'buttonLink' => Html::element('a', ['href' => '#'], $this->msg('coppatool-rename-ip')->escaped())];
}
}
wfProfileOut(__METHOD__);
}
示例10: execute
public function execute($par)
{
global $wgRequest;
$this->setHeaders();
$this->outputHeader();
$opts = new FormOptions();
$opts->add('type', '');
$opts->add('user', '');
$opts->add('page', '');
$opts->add('pattern', false);
$opts->add('year', null, FormOptions::INTNULL);
$opts->add('month', null, FormOptions::INTNULL);
$opts->add('tagfilter', '');
$opts->add('offset', '');
$opts->add('dir', '');
$opts->add('offender', '');
// Set values
$opts->fetchValuesFromRequest($wgRequest);
if ($par) {
$this->parseParams($opts, (string) $par);
}
# Don't let the user get stuck with a certain date
if ($opts->getValue('offset') || $opts->getValue('dir') == 'prev') {
$opts->setValue('year', '');
$opts->setValue('month', '');
}
# Handle type-specific inputs
$qc = array();
if ($opts->getValue('type') == 'suppress') {
$offender = User::newFromName($opts->getValue('offender'), false);
if ($offender && $offender->getId() > 0) {
$qc = array('ls_field' => 'target_author_id', 'ls_value' => $offender->getId());
} elseif ($offender && IP::isIPAddress($offender->getName())) {
$qc = array('ls_field' => 'target_author_ip', 'ls_value' => $offender->getName());
}
}
$this->show($opts, $qc);
}
示例11: loadFromArray
private function loadFromArray(array $restrictions)
{
static $validKeys = ['IPAddresses'];
static $neededKeys = ['IPAddresses'];
$keys = array_keys($restrictions);
$invalidKeys = array_diff($keys, $validKeys);
if ($invalidKeys) {
throw new InvalidArgumentException('Array contains invalid keys: ' . implode(', ', $invalidKeys));
}
$missingKeys = array_diff($neededKeys, $keys);
if ($missingKeys) {
throw new InvalidArgumentException('Array is missing required keys: ' . implode(', ', $missingKeys));
}
if (!is_array($restrictions['IPAddresses'])) {
throw new InvalidArgumentException('IPAddresses is not an array');
}
foreach ($restrictions['IPAddresses'] as $ip) {
if (!\IP::isIPAddress($ip)) {
throw new InvalidArgumentException("Invalid IP address: {$ip}");
}
}
$this->ipAddresses = $restrictions['IPAddresses'];
}
示例12: testisIPAddress
/**
* not sure it should be tested with boolean false. hashar 20100924
* @covers IP::isIPAddress
*/
public function testisIPAddress()
{
$this->assertFalse(IP::isIPAddress(false), 'Boolean false is not an IP');
$this->assertFalse(IP::isIPAddress(true), 'Boolean true is not an IP');
$this->assertFalse(IP::isIPAddress(""), 'Empty string is not an IP');
$this->assertFalse(IP::isIPAddress('abc'), 'Garbage IP string');
$this->assertFalse(IP::isIPAddress(':'), 'Single ":" is not an IP');
$this->assertFalse(IP::isIPAddress('2001:0DB8::A:1::1'), 'IPv6 with a double :: occurence');
$this->assertFalse(IP::isIPAddress('2001:0DB8::A:1::'), 'IPv6 with a double :: occurence, last at end');
$this->assertFalse(IP::isIPAddress('::2001:0DB8::5:1'), 'IPv6 with a double :: occurence, firt at beginning');
$this->assertFalse(IP::isIPAddress('124.24.52'), 'IPv4 not enough quads');
$this->assertFalse(IP::isIPAddress('24.324.52.13'), 'IPv4 out of range');
$this->assertFalse(IP::isIPAddress('.24.52.13'), 'IPv4 starts with period');
$this->assertFalse(IP::isIPAddress('fc:100:300'), 'IPv6 with only 3 words');
$this->assertTrue(IP::isIPAddress('::'), 'RFC 4291 IPv6 Unspecified Address');
$this->assertTrue(IP::isIPAddress('::1'), 'RFC 4291 IPv6 Loopback Address');
$this->assertTrue(IP::isIPAddress('74.24.52.13/20', 'IPv4 range'));
$this->assertTrue(IP::isIPAddress('fc:100:a:d:1:e:ac:0/24'), 'IPv6 range');
$this->assertTrue(IP::isIPAddress('fc::100:a:d:1:e:ac/96'), 'IPv6 range with "::"');
$validIPs = array('fc:100::', 'fc:100:a:d:1:e:ac::', 'fc::100', '::fc:100:a:d:1:e:ac', '::fc', 'fc::100:a:d:1:e:ac', 'fc:100:a:d:1:e:ac:0', '124.24.52.13', '1.24.52.13');
foreach ($validIPs as $ip) {
$this->assertTrue(IP::isIPAddress($ip), "{$ip} is a valid IP address");
}
}
示例13: loadParameters
function loadParameters()
{
global $wgAbuseFilterIsCentral;
$request = $this->getRequest();
$this->mSearchUser = trim($request->getText('wpSearchUser'));
if ($wgAbuseFilterIsCentral) {
$this->mSearchWiki = $request->getText('wpSearchWiki');
}
$u = User::newFromName($this->mSearchUser);
if ($u) {
$this->mSearchUser = $u->getName();
// Username normalisation
} elseif (IP::isIPAddress($this->mSearchUser)) {
// It's an IP
$this->mSearchUser = IP::sanitizeIP($this->mSearchUser);
} else {
$this->mSearchUser = null;
}
$this->mSearchTitle = $request->getText('wpSearchTitle');
$this->mSearchFilter = null;
if (self::canSeeDetails()) {
$this->mSearchFilter = $request->getText('wpSearchFilter');
}
}
示例14: getClientIPfromXFF
/**
* Locates the client IP within a given XFF string
* @param string $xff
* @return array( string, bool )
*/
public static function getClientIPfromXFF($xff)
{
global $wgSquidServers, $wgSquidServersNoPurge;
if (!$xff) {
return array(null, false);
}
// Avoid annoyingly long xff hacks
$xff = trim(substr($xff, 0, 255));
$client = null;
$isSquidOnly = true;
$trusted = true;
// Check each IP, assuming they are separated by commas
$ips = explode(',', $xff);
foreach ($ips as $ip) {
$ip = trim($ip);
// If it is a valid IP, not a hash or such
if (IP::isIPAddress($ip)) {
# The first IP should be the client.
# Start only from the first public IP.
if (is_null($client)) {
if (IP::isPublic($ip)) {
$client = $ip;
}
} elseif (!in_array($ip, $wgSquidServers) && !in_array($ip, $wgSquidServersNoPurge)) {
$isSquidOnly = false;
break;
}
}
}
return array($client, $isSquidOnly);
}
示例15: isBlockedGlobally
/**
* Check if user is blocked on all wikis.
* Do not use for actual edit permission checks!
* This is intented for quick UI checks.
*
* @param $ip String IP address, uses current client if none given
* @return Bool True if blocked, false otherwise
*/
public function isBlockedGlobally($ip = '')
{
if ($this->mBlockedGlobally !== null) {
return $this->mBlockedGlobally;
}
// User is already an IP?
if (IP::isIPAddress($this->getName())) {
$ip = $this->getName();
} elseif (!$ip) {
$ip = $this->getRequest()->getIP();
}
$blocked = false;
wfRunHooks('UserIsBlockedGlobally', array(&$this, $ip, &$blocked));
$this->mBlockedGlobally = (bool) $blocked;
return $this->mBlockedGlobally;
}