Esempio n. 1
0
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;
    }
}
function CalculCDR()
{
    $ip = new IP();
    $ipfrom = $_GET["mynet_ipfrom"];
    $ipto = $_GET["mynet_ipto"];
    $SIP = $ip->ip2cidr($ipfrom, $ipto);
    echo trim($SIP);
}
Esempio n. 3
0
 public function testConstructSuccess()
 {
     $ip = new IP(TestDataGenerator::ipInt());
     $range = new Range($ip, $ip);
     $this->assertInstanceOf('Bankiru\\IPTools\\Range', $range);
     $this->assertEquals($ip->getIntValue(), $range->getStart()->getIntValue());
     $this->assertEquals($ip->getIntValue(), $range->getEnd()->getIntValue());
 }
Esempio n. 4
0
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;}
	
}
Esempio n. 5
0
 public function testPrivateIPs()
 {
     $private = array('10.0.0.1', '172.16.0.1', '192.168.0.1');
     foreach ($private as $p) {
         $this->assertFalse(IP::isPublic($p), "{$p} is not a public IP address");
     }
 }
 /**
  * @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;
 }
 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));
 }
Esempio n. 8
0
 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:'******'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:'******'page', Title::makeTitleSafe(NS_USER, $opts->getValue('page')));
         }
     }
     $this->show($opts, $qc);
 }
Esempio n. 9
0
function wfWikiaAbortAutoblock($autoblockip, $block)
{
    if (!IP::isPublic($autoblockip)) {
        wfDebug("IP {$autoblockip} was prevented from being autoblocked by internal IP autoblock");
        return false;
    }
}
Esempio n. 10
0
 public function save()
 {
     wfProfileIn(__METHOD__);
     $action = "";
     if ($this->data['type'] & self::TYPE_USER && User::isIP($this->data['text'])) {
         $this->data['ip_hex'] = IP::toHex($this->data['text']);
     }
     $dbw = wfGetDB(DB_MASTER, array(), $this->wg->ExternalSharedDB);
     if (empty($this->data['id'])) {
         /* add block */
         $dbw->insert($this->db_table, $this->mapToDB(), __METHOD__);
         $action = 'add';
     } else {
         $dbw->update($this->db_table, $this->mapToDB(), array('p_id' => $this->data['id']), __METHOD__);
         $action = 'edit';
     }
     if ($dbw->affectedRows()) {
         if ($action == 'add') {
             $this->data['id'] = $dbw->insertId();
         }
         $this->log($action);
     } else {
         $action = '';
     }
     $dbw->commit();
     wfProfileOut(__METHOD__);
     return $action ? $this->data['id'] : false;
 }
Esempio n. 11
0
 /**
  * Get IP
  *
  * @access	public
  * @return	string
  */
 public static function getClientIP()
 {
     if (self::$ClientIP !== FALSE) {
         return self::$ClientIP;
     }
     $CieIP = (isset($_SERVER['HTTP_CLIENT_IP']) and $_SERVER['HTTP_CLIENT_IP'] != "") ? $_SERVER['HTTP_CLIENT_IP'] : FALSE;
     $RemIP = (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] != "") ? $_SERVER['REMOTE_ADDR'] : FALSE;
     $ForIP = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and $_SERVER['HTTP_X_FORWARDED_FOR'] != "") ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE;
     if ($CieIP && $RemIP) {
         self::$ClientIP = $CieIP;
     } elseif ($RemIP) {
         self::$ClientIP = $RemIP;
     } elseif ($CieIP) {
         self::$ClientIP = $CieIP;
     } elseif ($ForIP) {
         self::$ClientIP = $ForIP;
     }
     if (strstr(self::$ClientIP, ',')) {
         $x = explode(',', self::$ClientIP);
         self::$ClientIP = end($x);
     }
     // checked IP address
     $CheckIP = new IPValidator();
     if (!$CheckIP->isValid(self::$ClientIP)) {
         self::$ClientIP = '0.0.0.0';
     }
     unset($CheckIP);
     unset($CieIP);
     unset($RemIP);
     unset($ForIP);
     return self::$ClientIP;
 }
 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);
     }
 }
 /**
  *
  * @param string $name
  * @param int $amount
  * @return boolean false if failed
  */
 private function credit($name = null, $amount = 0)
 {
     $output = $this->getOutput();
     $output->addWikiText("=== Credit (name, amount) ===");
     $output->addWikiText("name = {$name}");
     $output->addWikiText("amount = {$amount}");
     $user = User::newFromName($name);
     if (!$user || $user->getId() == 0) {
         $output->addWikiText("=== ERROR: Invalid UserName ===");
         return false;
     }
     $output->addWikiText("=== User ===");
     $output->addWikiText("user_id = " . $user->getId());
     $output->addWikiText("user_name = " . $user->getName());
     $output->addWikiText("user_realname = " . $user->getRealName());
     $output->addWikiText("user_email = " . $user->getEmail());
     $output->addWikiText("=== Transaction ===");
     $output->addWikiText("True balance before = " . TMRecord::getTrueBalanceFromDB($user->getId()));
     if (!is_int($amount) || $amount <= 0 || $amount > 1000) {
         $output->addWikiText("=== ERROR: Invalid Amount ===");
         return false;
     }
     $tmr = array('tmr_type' => TM_REFUND_TYPE, 'tmr_user_id' => $user->getId(), 'tmr_mail' => $user->getEmail(), 'tmr_ip' => IP::sanitizeIP(wfGetIP()), 'tmr_amount' => $amount, 'tmr_currency' => 'EUR', 'tmr_desc' => 'tm-refund', 'tmr_status' => 'OK');
     wfRunHooks('CreateTransaction', array(&$tmr));
     $output->addWikiText("==== DONE ====");
     $output->addWikiText("True balance after = " . TMRecord::getTrueBalanceFromDB($user->getId()));
     $output->addWikiText("== SUCCESS ==");
 }
 public function execute()
 {
     $dbw = wfGetDB(DB_MASTER);
     // Perform this in a transaction so an failed load doesn't erase current data.
     $dbw->begin();
     // Clear existing GeoIP data.
     try {
         $dbw->delete('geoip', '*', __METHOD__);
     } catch (DBQueryError $e) {
         $this->error('ERROR: Could not delete existing geographic data. Is the GeoIP schema loaded?', true);
     }
     // Load fresh data from the first (and only) argument.
     $filename = $this->getArg(0);
     $lines = exec('wc -l ' . $filename);
     $handle = fopen($filename, 'r');
     $count = 0;
     while (($data = fgetcsv($handle, 256, ',')) !== false) {
         // Output a nice progress bar.
         if ($count % 1000 == 0) {
             $progress = ceil($count / $lines * 50);
             $this->output('[' . str_repeat('=', $progress) . str_repeat(' ', 50 - $progress) . '] ' . ceil($count / $lines * 100) . '%' . "\r");
         }
         ++$count;
         $record = array('begin_ip_long' => IP::toUnsigned($data[0]), 'end_ip_long' => IP::toUnsigned($data[1]), 'country_code' => $data[4]);
         $dbw->insert('geoip', $record, __METHOD__);
     }
     $this->output("\n");
     $dbw->commit();
     $this->output('Successfully loaded ' . $count . ' geographic IP ranges.' . "\n");
 }
Esempio n. 15
0
 public function offsetGet($offset)
 {
     if (!$this->offsetExists($offset)) {
         throw new OutOfBoundsException("Offset {$offset} does not exists");
     }
     return $this->first_ip->plus($offset);
 }
 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();
 }
Esempio n. 17
0
function network_add()
{
    $tpc = new IP();
    if (!$tpc->isValidBlock($_POST["network-add"])) {
        echo "{$_POST["network-add"]} invalid";
        return;
    }
    $q = new mysql_squid_builder();
    $q->QUERY_SQL("INSERT IGNORE INTO webauth_rules_nets (pattern,ruleid) VALUES ('{$_POST["network-add"]}','{$_POST["ruleid"]}')");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $sock = new sockets();
    $sock->getFrameWork("hotspot.php?remove-cache=yes");
}
Esempio n. 18
0
 /**
  * Find the wikis with revisions for the specified users
  *
  * @param array $identifiers
  * @return array of wikiId => array of users with revisions on that wiki
  */
 protected function getAffectedWikis(array $identifiers)
 {
     global $wgStatsDB, $wgStatsDBEnabled, $wgDevelEnvironment;
     $wikiIds = [];
     if (!$wgStatsDBEnabled) {
         // requires stats database to function
         // TODO log this?
         return $wikiIds;
     }
     // on devbox we have to fall back to static list
     // because we have no active read-write statsdb there
     if (!empty($wgDevelEnvironment)) {
         global $wgCityId;
         return array($wgCityId => $identifiers);
     }
     $sdb = wfGetDB(DB_SLAVE, [], $wgStatsDB);
     foreach ($identifiers as $identifier) {
         list($userId, $ip) = $this->getUserByIdentifier($identifier);
         $affectedWikis = (new WikiaSQL())->DISTINCT('wiki_id')->FROM('events')->WHERE('user_id')->EQUAL_TO($userId);
         if ($userId == 0 && isset($ip)) {
             $affectedWikis->AND_('ip')->EQUAL_TO(IP::toUnsigned($identifier));
         }
         // TODO can userId be 0 and the identifier not be an IP?
         $wikis = $affectedWikis->runLoop($sdb, function ($_, $row) use(&$wikiIds, $identifier) {
             if (empty($wikiIds[$row->wiki_id])) {
                 $wikiIds[$row->wiki_id] = [];
             }
             $wikiIds[$row->wiki_id][] = $identifier;
         });
     }
     return $wikiIds;
 }
 protected function findWikis($users)
 {
     global $wgStatsDB, $wgStatsDBEnabled, $wgDevelEnvironment;
     if (!$wgStatsDBEnabled) {
         return false;
     }
     // on devbox we have to fall back to static list
     // because we have no active read-write statsdb there
     if (!empty($wgDevelEnvironment)) {
         return array(165);
     }
     $dbr = wfGetDB(DB_SLAVE, array(), $wgStatsDB);
     $wikiIds = array();
     foreach ($users as $user) {
         if ($user['id'] != 0) {
             // regular user
             $where = array('user_id' => intval($user['id']));
         } else {
             // ip - anons
             $where = array('user_id' => 0, 'ip' => IP::toUnsigned($user['ip']));
         }
         $res = $dbr->select('events', 'wiki_id', $where, __METHOD__, array('DISTINCT'));
         $userWikiIds = array();
         while ($row = $dbr->fetchObject($res)) {
             $wikiIds[$row->wiki_id] = true;
             $userWikiIds[] = $row->wiki_id;
         }
         $this->log("User \"" . $user['canonical'] . "\": found " . count($userWikiIds) . " wikis: " . implode(', ', $userWikiIds));
     }
     $wikiIds = array_keys($wikiIds);
     sort($wikiIds);
     return $wikiIds;
 }
Esempio n. 20
0
 /**
  * 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;
 }
 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'));
     }
 }
Esempio n. 22
0
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);
	
}
Esempio n. 23
0
 /**
  * @return number|string
  */
 public function getHostsCount()
 {
     $blockSize = $this->getBlockSize();
     if ($this->ip->getVersion() === IP::IP_V4) {
         return $blockSize > 2 ? $blockSize - 2 : $blockSize;
     }
     return $blockSize;
 }
Esempio n. 24
0
    public function getSubnets()
    {
        $new = array();

        foreach ($this->subnets as $key=>&$s)
        {
            while ($s[0] <= $s[1])
            {
                $length = $s[1] - $s[0] + 1;
                for ($i = (32 - floor(log($length, 2))); $i <= 32; $i++)
                {
                    $test_ip = long2ip($s[0]) . '/' . $i;
                    $test = new IP($test_ip);
                    if ($test->getNetwork(true) == $s[0] && $test->getBroadcast(true) <= $s[1])
                    {
                        $s[0] = $test->getBroadcast(true) + 1;
                        $new[$test->getIP(true)] = $test->getIP() . "/" . $test->getCIDR();
                        break;
                    }
                }
            }
        }
        ksort($new);
        return $new;
    }
Esempio n. 25
0
 /**
  * 获取客户端城市IP地址
  */
 public static function getCityIP($value)
 {
     Yii::import('application.extensions.17mon.*');
     require_once 'IP.class.php';
     //IP::init();
     $ip = IP::find($value);
     //'106.185.24.112'
     return $ip;
 }
Esempio n. 26
0
function efNetworkAuth_checkForNetworkAuthUser()
{
    global $wgNetworkAuthUsers;
    $ip = wfGetIP();
    foreach ($wgNetworkAuthUsers as $networkAuthUser) {
        if (isset($networkAuthUser['user'])) {
            if (isset($networkAuthUser['iprange'])) {
                if (is_array($networkAuthUser['iprange'])) {
                    $ranges = $networkAuthUser['iprange'];
                } else {
                    $ranges = explode("\n", $networkAuthUser['iprange']);
                }
                $hex = IP::toHex($ip);
                foreach ($ranges as $range) {
                    $parsedRange = IP::parseRange($range);
                    if ($hex >= $parsedRange[0] && $hex <= $parsedRange[1]) {
                        global $wgNetworkAuthHost;
                        $wgNetworkAuthHost = $ip;
                        return $networkAuthUser['user'];
                    }
                }
            }
            if (isset($networkAuthUser['ippattern'])) {
                if (is_array($networkAuthUser['ippattern'])) {
                    $patterns = $networkAuthUser['ippattern'];
                } else {
                    $patterns = explode("\n", $networkAuthUser['ippattern']);
                }
                foreach ($patterns as $pattern) {
                    if (preg_match($pattern, $ip)) {
                        global $wgNetworkAuthHost;
                        $wgNetworkAuthHost = $ip;
                        return $networkAuthUser['user'];
                    }
                }
            }
            if (isset($networkAuthUser['hostpattern'])) {
                if (is_array($networkAuthUser['hostpattern'])) {
                    $patterns = $networkAuthUser['hostpattern'];
                } else {
                    $patterns = explode("\n", $networkAuthUser['hostpattern']);
                }
                $host = gethostbyaddr($ip);
                foreach ($patterns as $pattern) {
                    if (preg_match($pattern, $host)) {
                        global $wgNetworkAuthHost;
                        $wgNetworkAuthHost = $host;
                        return $networkAuthUser['user'];
                    }
                }
            }
        } else {
            # No user for range - useless.
        }
    }
    return '';
}
Esempio n. 27
0
 /**
  * @return int
  */
 public function count()
 {
     if ($this->firstIP->getVersion() === IP::IP_V4) {
         $count = $this->lastIP->toLong() - $this->firstIP->toLong();
     } else {
         $count = bcsub($this->lastIP->toLong(), $this->firstIP->toLong());
     }
     return $count;
 }
Esempio n. 28
0
 /**
  * @dataProvider invalidOperations
  * @expectedException OutOfBoundsException
  */
 public function testPlusMinusOob($ip, $plus, $minus)
 {
     $ip = IP::create($ip);
     if ($plus !== null) {
         $ip->plus($plus);
     } elseif ($minus !== null) {
         $ip->minus($minus);
     }
 }
Esempio n. 29
0
 function test_ipv4()
 {
     $mask_ar = array("195.100.100.0", "195.100.100.1", "195.100.100.0/24", "195.100.100.255/24", "195.100.100.255/16", "195.200.100.127/25");
     $tested_subnets = array(array("ip" => "195.100.100.1", "cidr" => "195.100.100.1", "expected_result" => true), array("ip" => "195.100.100.1", "cidr" => "195.100.100.1/32", "expected_result" => true), array("ip" => "195.100.100.2", "cidr" => "195.100.100.1/32", "expected_result" => false), array("ip" => "195.100.100.1", "cidr" => "195.100.100.0/24", "expected_result" => true), array("ip" => "195.100.100.1", "cidr" => "195.100.100.255/24", "expected_result" => true), array("ip" => "195.100.101.1", "cidr" => "195.100.100.255/24", "expected_result" => false), array("ip" => "195.100.101.1", "cidr" => "195.100.100.255/16", "expected_result" => true), array("ip" => "195.100.101.1", "cidr" => "195.100.100.255/255.255.0.0", "expected_result" => true), array("ip" => "195.100.100.128", "cidr" => "195.100.100.127/25", "expected_result" => false), array("ip" => "195.100.100.127", "cidr" => "195.100.100.127/25", "expected_result" => true), array("ip" => "195.100.100.127", "cidr" => "195.100.100.127/255.255.255.128", "expected_result" => true), array("ip" => "195.100.100.1", "cidr" => $mask_ar, "expected_result" => true), array("ip" => "195.100.101.1", "cidr" => $mask_ar, "expected_result" => true), array("ip" => "195.101.101.1", "cidr" => $mask_ar, "expected_result" => false), array("ip" => "195.101.100.1", "cidr" => $mask_ar, "expected_result" => false), array("ip" => "195.200.100.127", "cidr" => $mask_ar, "expected_result" => true), array("ip" => "195.200.100.128", "cidr" => $mask_ar, "expected_result" => false), array("ip" => "195.200.100.128", "cidr" => "21DA:00D3:0000:2F3B::/64", "expected_result" => false), array("ip" => "195.200.100.128", "cidr" => "0::0/64", "expected_result" => false), array("ip" => "195.200.100.128", "cidr" => "::1", "expected_result" => false));
     foreach ($tested_subnets as $idx => $subnet) {
         $this->assertEquals($subnet["expected_result"], IP::Match4($subnet["ip"], $subnet["cidr"]), sprintf("Failed with idx: %d, %s", $idx, print_r($subnet, true)));
         $this->assertEquals($subnet["expected_result"], IP::Match($subnet["ip"], $subnet["cidr"]), sprintf("Failed with idx: %d, %s", $idx, print_r($subnet, true)));
     }
 }
Esempio n. 30
0
	public static function
	canAttack(User $user, User $target) {
		if (!$user->id or !$target->id) {
			return false;
		}
		
		$count = IP::getCount($target, $user->currentIP);
		return ($count == 0);
	}