Beispiel #1
0
 /**
  * Сохранение бана
  * @param array $data массив данных
  * @return null
  * @throws EngineException 
  */
 protected function save($data)
 {
     $admin_file = globals::g('admin_file');
     $id = (int) $data['id'];
     $cols = array('user' => 'username', 'email', 'ip_f', 'ip_t', 'reason', 'period', 'up' => 'update');
     extract(rex($data, $cols));
     $ip_f = ip2ulong($ip_f);
     $ip_t = ip2ulong($ip_t);
     $period = (double) $period;
     /* @var $etc etc */
     $etc = n("etc");
     $uid = 0;
     if ($user) {
         $r = $etc->select_user(null, $user, "id");
         $uid = $r["id"];
     }
     if (!$uid && !$email && !$ip_f && !$ip_t) {
         throw new EngineException("bans_nothing_banned");
     }
     $etc->ban_user($uid, !$id || $up ? $period : 0, $reason, $email, $ip_f, $ip_t, $id);
     if ($id) {
         $this->show($id);
         return;
     } else {
         furl::o()->location($admin_file);
     }
 }
Beispiel #2
0
					break;
				}
			}

			/* make sure that the DHCP Relay isn't enabled on this interface */
			if (isset($config['dhcrelay']['enable']) && (stristr($config['dhcrelay']['interface'], $if) !== false))
				$input_errors[] = sprintf(gettext("You must disable the DHCP relay on the %s interface before enabling the DHCP server."),$iflist[$if]);

			$dynsubnet_start = ip2ulong($_POST['range_from']);
			$dynsubnet_end = ip2ulong($_POST['range_to']);
			if (is_array($a_maps)) {
				foreach ($a_maps as $map) {
					if (empty($map['ipaddr']))
						continue;
					if ((ip2ulong($map['ipaddr']) > $dynsubnet_start) &&
						(ip2ulong($map['ipaddr']) < $dynsubnet_end)) {
						$input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
						break;
					}
				}
			}
		}
	}

	if (!$input_errors) {
		if (!is_numeric($pool)) {
			if ($act == "newpool") {
				$dhcpdconf = array();
			} else {
				if (!is_array($config['dhcpd'][$if]))
					$config['dhcpd'][$if] = array();
         continue;
     }
     if ($mapent['hostname'] == $_POST['hostname'] && $mapent['hostname'] || $mapent['mac'] == $_POST['mac']) {
         $input_errors[] = "Bu sunucu adı, IP adresi veya MAC adresi zaten kayıtlı.";
         break;
     }
 }
 if ($_POST['ipaddr']) {
     $dynsubnet_start = ip2ulong($config['dhcpd'][$if]['range']['from']);
     $dynsubnet_end = ip2ulong($config['dhcpd'][$if]['range']['to']);
     if (ip2ulong($_POST['ipaddr']) >= $dynsubnet_start && ip2ulong($_POST['ipaddr']) <= $dynsubnet_end) {
         $input_errors[] = "Sabit IP adresi otomatik dağıtım aralığında olmamalıdır.";
     }
     $lansubnet_start = ip2ulong(long2ip32(ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn)));
     $lansubnet_end = ip2ulong(long2ip32(ip2long($ifcfgip) | ~gen_subnet_mask_long($ifcfgsn)));
     if (ip2ulong($_POST['ipaddr']) < $lansubnet_start || ip2ulong($_POST['ipaddr']) > $lansubnet_end) {
         $input_errors[] = sprintf("IP adresi %s ağında bulunmalıdır.", $ifcfgdescr);
     }
 }
 if (!$input_errors) {
     $mapent = array();
     $mapent['mac'] = $_POST['mac'];
     $mapent['ipaddr'] = $_POST['ipaddr'];
     $mapent['hostname'] = $_POST['hostname'];
     $mapent['descr'] = base64_encode($_POST['descr']);
     if (isset($id) && $a_maps[$id]) {
         $a_maps[$id] = $mapent;
     } else {
         $a_maps[] = $mapent;
     }
     staticmaps_sort($if);
function sort_by_ip($a, $b)
{
    return ip2ulong($a) < ip2ulong($b) ? -1 : 1;
}
Beispiel #5
0
 /**
  * Получение первого и второго IP
  * @param string $firstip первый IP
  * @param string $lastip второй IP
  * @param bool $long преобразовывать в long?
  * @return null
  */
 public function get_ips(&$firstip, &$lastip, $long = false)
 {
     if ($long) {
         $firstip = ip2ulong($firstip);
         $lastip = ip2ulong($lastip);
     } else {
         $ip_f = longval($ip_f);
         $ip_t = longval($ip_t);
     }
     if ($lastip && !$firstip) {
         $firstip = $lastip;
     }
     if ($firstip && !$lastip) {
         $lastip = $firstip;
     }
     if ($firstip > $lastip && $lastip) {
         $t = $firstip;
         $firstip = $lastip;
         $lastip = $t;
     }
 }
Beispiel #6
0
                     $data['if'] = $dhcpif;
                     break;
                 }
             }
         }
         /* exit as soon as we have an interface */
         if ($data['if'] != "") {
             break;
         }
     }
 } else {
     foreach ($dhcpd as $dhcpif => $dhcpifconf) {
         if (!is_array($dhcpifconf['range'])) {
             continue;
         }
         if ($lip >= ip2ulong($dhcpifconf['range']['from']) && $lip <= ip2ulong($dhcpifconf['range']['to'])) {
             $data['if'] = $dhcpif;
             break;
         }
     }
 }
 echo "<tr>\n";
 echo "<td class=\"listlr\">{$fspans}{$data['ip']}{$fspane}</td>\n";
 $mac = $data['mac'];
 $mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
 if ($data['online'] != "online") {
     if (isset($mac_man[$mac_hi])) {
         // Manufacturer for this MAC is defined
         echo "<td class=\"listr\">{$fspans}<a href=\"services_wol.php?if={$data['if']}&amp;mac={$mac}\" title=\"" . gettext("{$mac} - send Wake on LAN packet to this MAC address") . "\">{$mac}</a><br /><font size=\"-2\"><i>{$mac_man[$mac_hi]}</i></font>{$fspane}</td>\n";
     } else {
         echo "<td class=\"listr\">{$fspans}<a href=\"services_wol.php?if={$data['if']}&amp;mac={$data['mac']}\" title=\"" . gettext("send Wake on LAN packet to this MAC address") . "\">{$data['mac']}</a>{$fspane}</td>\n";
Beispiel #7
0
 /**
  * Получение беззнакового целого представления IP
  * @param string $ip строка с IP
  * @return int беззнаковое целое представление IP
  */
 public function get_ip($ip)
 {
     return ip2ulong($ip);
 }
Beispiel #8
0
                 $input_errors[] = gettext("The specified range must not be within the range configured on a DHCP pool for this interface.");
                 break;
             }
         }
         /* make sure that the DHCP Relay isn't enabled on this interface */
         if (isset($config['dhcrelay']['enable']) && stristr($config['dhcrelay']['interface'], $if) !== false) {
             $input_errors[] = sprintf(gettext("You must disable the DHCP relay on the %s interface before enabling the DHCP server."), $iflist[$if]);
         }
         $dynsubnet_start = ip2ulong($_POST['range_from']);
         $dynsubnet_end = ip2ulong($_POST['range_to']);
         if (is_array($a_maps)) {
             foreach ($a_maps as $map) {
                 if (empty($map['ipaddr'])) {
                     continue;
                 }
                 if (ip2ulong($map['ipaddr']) > $dynsubnet_start && ip2ulong($map['ipaddr']) < $dynsubnet_end) {
                     $input_errors[] = sprintf(gettext("The DHCP range cannot overlap any static DHCP mappings."));
                     break;
                 }
             }
         }
     }
 }
 if (!$input_errors) {
     if (!is_numeric($pool)) {
         if ($act == "newpool") {
             $dhcpdconf = array();
         } else {
             if (!is_array($config['dhcpd'][$if])) {
                 $config['dhcpd'][$if] = array();
             }
Beispiel #9
0
 * @version             1.00
 */
require_once './include/include_announce.php';
require_once ROOT . '/include/classes/class.etc.php';
$etc = new etc();
$a = array("passkey", "peer_id", "port", "uploaded", "ip", "left", "compact", "event", "info_hash", "no_peer_id");
$c = count($a);
extract(rex($_REQUEST, $a));
if ($_REQUEST['num want']) {
    $_REQUEST['numwant'] = $_REQUEST['num want'];
}
if ($_REQUEST['num_want']) {
    $_REQUEST['numwant'] = $_REQUEST['num_want'];
}
$numwant = (int) $_REQUEST['numwant'];
$ip = ip2ulong($ip ? $ip : $_SERVER['REMOTE_ADDR']);
if (!$ip) {
    $bt->err('Invalid IP.');
}
$info_hash = bin2hex($info_hash);
$seeder = $left > 0 ? '0' : '1';
$area = $seeder ? 'seeders' : 'leechers';
//$bt->err('Unknown user. Passkey - ' . print_r($_SERVER, true));
$itime = config::o()->v('announce_interval') * 60;
if (!$itime) {
    $bt->err('There\'s not an announce interval o_O.');
}
$q = db::o()->p($info_hash)->query('SELECT cid, ' . $area . ',downloaded FROM content_torrents WHERE
    info_hash=? AND banned="0" LIMIT 1');
list($torrent, $seedleech, $downloaded) = db::o()->fetch_row($q);
if (!$torrent) {
Beispiel #10
0
         }
         foreach ($a_pools as $id => $p) {
             if (is_numeric($pool) && $id == $pool) {
                 continue;
             }
             if (is_inrange_v4($_POST['range_from'], $p['range']['from'], $p['range']['to']) || is_inrange_v4($_POST['range_to'], $p['range']['from'], $p['range']['to'])) {
                 $input_errors[] = gettext("The specified range must not be within the range configured on a DHCP pool for this interface.");
                 break;
             }
         }
         /* make sure that the DHCP Relay isn't enabled on this interface */
         if (isset($config['dhcrelay']['enable']) && stristr($config['dhcrelay']['interface'], $if) !== false) {
             $input_errors[] = sprintf(gettext("You must disable the DHCP relay on the %s interface before enabling the DHCP server."), $iflist[$if]);
         }
         $dynsubnet_start = ip2ulong($_POST['range_from']);
         $dynsubnet_end = ip2ulong($_POST['range_to']);
     }
 }
 if (!$input_errors) {
     if (!is_numeric($pool)) {
         if ($act == "newpool") {
             $dhcpdconf = array();
         } else {
             if (!is_array($config['dhcpd'][$if])) {
                 $config['dhcpd'][$if] = array();
             }
             $dhcpdconf = $config['dhcpd'][$if];
         }
     } else {
         if (is_array($a_pools[$pool])) {
             $dhcpdconf = $a_pools[$pool];
                $slease = array();
                $slease['ip'] = $static['ipaddr'];
                $slease['act'] = "static";
                $slease['staticmap_array_index'] = $staticmap_array_index;
                $leases[] = $slease;
                $staticmap_array_index++;
            }
        }
    }
    $ifcfgip = get_interface_ip($dhcpif);
    $ifcfgsn = get_interface_subnet($dhcpif);
    $subnet_start = ip2ulong(long2ip32(ip2long($ifcfgip) & gen_subnet_mask_long($ifcfgsn)));
    $subnet_end = ip2ulong(long2ip32(ip2long($ifcfgip) | ~gen_subnet_mask_long($ifcfgsn)));
    $result['range'] = ip2ulong($config['dhcpd'][$dhcpif]['range']['to']) - ip2ulong($config['dhcpd'][$dhcpif]['range']['from']);
    foreach ($leases as $data) {
        $lip = ip2ulong($data['ip']);
        if ($data['act'] != "active" && $data['act'] != "static" && $_GET['all'] != 1) {
            continue;
        }
        if ($data['act'] != "static") {
            if ($lip >= ip2ulong($config['dhcpd'][$dhcpif]['range']['from']) && $lip <= ip2ulong($config['dhcpd'][$dhcpif]['range']['to'])) {
                $result['active'] = $result['active'] + 1;
            }
        } else {
            if ($lip >= $subnet_start && $lip <= $subnet_end) {
                $result['static'] = $result['static'] + 1;
            }
        }
    }
}
echo $result['active'] . ":" . $result['static'] . ":" . $result['range'];
Beispiel #12
0
 /**
  * Функция для поиска IP вида 127.0.0.*
  * @param string $ip IP адрес
  * @param string $column столбец поиска
  * @return string условие, если верные IP
  */
 public function search_ip($ip, $column = 'ip')
 {
     if (!$column) {
         $column = 'ip';
     }
     $ip1 = ip2ulong(str_replace("*", "0", $ip));
     $ip2 = ip2ulong(str_replace("*", "255", $ip));
     $column = '`' . $column . '`';
     if ($ip1 && $ip2) {
         return '(' . $column . '<=' . $ip2 . ' AND ' . $column . '>=' . $ip1 . ')';
     } else {
         return '';
     }
 }
            $staticmap_array_index = 0;
            foreach ($config['dhcpd'][$ifname]['staticmap'] as $static) {
                $slease = array();
                $slease['ip'] = $static['ipaddr'];
                $slease['act'] = "static";
                $slease['staticmap_array_index'] = $staticmap_array_index;
                $leases[] = $slease;
                $staticmap_array_index++;
            }
        }
    }
    $ifcfgip = get_interface_ip($dhcpif);
    $ifcfgsn = get_interface_subnet($dhcpif);
    $subnet_start = gen_subnetv4($ifcfgip, $ifcfgsn);
    $subnet_end = gen_subnetv4_max($ifcfgip, $ifcfgsn);
    $result['range'] = ip2ulong($config['dhcpd'][$dhcpif]['range']['to']) - ip2ulong($config['dhcpd'][$dhcpif]['range']['from']);
    foreach ($leases as $data) {
        if ($data['act'] != "active" && $data['act'] != "static" && $_GET['all'] != 1) {
            continue;
        }
        if ($data['act'] != "static") {
            if (is_inrange_v4($data['ip'], $config['dhcpd'][$dhcpif]['range']['from'], $config['dhcpd'][$dhcpif]['range']['to'])) {
                $result['active'] = $result['active'] + 1;
            }
        } else {
            if (is_inrange_v4($data['ip'], $subnet_start, $subnet_end)) {
                $result['static'] = $result['static'] + 1;
            }
        }
    }
}
Beispiel #14
0
     $reqdfields[] = 'tunnel_network';
     $reqdfieldsn[] = gettext('Tunnel network');
 } else {
     if ($pconfig['serverbridge_dhcp'] && $pconfig['tunnel_network']) {
         $input_errors[] = gettext("Using a tunnel network and server bridge settings together is not allowed.");
     }
     if ($pconfig['serverbridge_dhcp_start'] && !$pconfig['serverbridge_dhcp_end'] || !$pconfig['serverbridge_dhcp_start'] && $pconfig['serverbridge_dhcp_end']) {
         $input_errors[] = gettext("Server Bridge DHCP Start and End must both be empty, or defined.");
     }
     if ($pconfig['serverbridge_dhcp_start'] && !is_ipaddrv4($pconfig['serverbridge_dhcp_start'])) {
         $input_errors[] = gettext("Server Bridge DHCP Start must be an IPv4 address.");
     }
     if ($pconfig['serverbridge_dhcp_end'] && !is_ipaddrv4($pconfig['serverbridge_dhcp_end'])) {
         $input_errors[] = gettext("Server Bridge DHCP End must be an IPv4 address.");
     }
     if (ip2ulong($pconfig['serverbridge_dhcp_start']) > ip2ulong($pconfig['serverbridge_dhcp_end'])) {
         $input_errors[] = gettext("The Server Bridge DHCP range is invalid (start higher than end).");
     }
 }
 do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
 if (count($input_errors) == 0) {
     // validation correct, save data
     $server = array();
     // delete(rename) old interface so a new TUN or TAP interface can be created.
     if (isset($id) && $pconfig['dev_mode'] != $a_server[$id]['dev_mode']) {
         openvpn_delete('server', $a_server[$id]);
     }
     // 1 on 1 copy of config attributes
     $copy_fields = "mode,protocol,dev_mode,local_port,description,crypto,digest,engine\n\t\t\t\t\t\t,tunnel_network,tunnel_networkv6,remote_network,remote_networkv6\n\t\t\t\t\t\t,gwredir,local_network,local_networkv6,maxclients,compression\n\t\t\t\t\t\t,passtos,client2client,dynamic_ip,pool_enable,topology_subnet\n\t\t\t\t\t\t,serverbridge_dhcp,serverbridge_interface,serverbridge_dhcp_start\n\t\t\t\t\t\t,serverbridge_dhcp_end,dns_domain,dns_server1,dns_server2,dns_server3\n\t\t\t\t\t\t,dns_server4,push_register_dns,ntp_server1,ntp_server2,netbios_enable\n\t\t\t\t\t\t,netbios_ntype,netbios_scope,no_tun_ipv6,verbosity_level,wins_server1\n\t\t\t\t\t\t,wins_server2,client_mgmt_port";
     foreach (explode(",", $copy_fields) as $fieldname) {
         $fieldname = trim($fieldname);
Beispiel #15
0
 /**
  * Получение IP пользователя
  * @param bool $longed в ip2ulong
  * @return string|int IP в формате целого числа, либо 4 чисел с точками
  */
 public function get_ip($longed = true)
 {
     $ip = $_SERVER['REMOTE_ADDR'] == "::1" ? "127.0.0.1" : $_SERVER['REMOTE_ADDR'];
     return $longed ? ip2ulong($ip) : $ip;
 }
Beispiel #16
0
     $reqdfieldsn = array_merge($reqdfieldsn, array(gettext("RADIUS server address"), gettext("RADIUS shared secret")));
 }
 do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
 if ($_POST['localip'] && !is_ipaddr($_POST['localip'])) {
     $input_errors[] = gettext("A valid server address must be specified.");
 }
 if ($_POST['pppoe_subnet'] && !is_ipaddr($_POST['remoteip'])) {
     $input_errors[] = gettext("A valid remote start address must be specified.");
 }
 if ($_POST['radiusserver'] && !is_ipaddr($_POST['radiusserver'])) {
     $input_errors[] = gettext("A valid RADIUS server address must be specified.");
 }
 $_POST['remoteip'] = $pconfig['remoteip'] = gen_subnet($_POST['remoteip'], $_POST['pppoe_subnet']);
 $subnet_start = ip2ulong($_POST['remoteip']);
 $subnet_end = ip2ulong($_POST['remoteip']) + $_POST['pppoe_subnet'] - 1;
 if (ip2ulong($_POST['localip']) >= $subnet_start && ip2ulong($_POST['localip']) <= $subnet_end) {
     $input_errors[] = gettext("The specified server address lies in the remote subnet.");
 }
 if ($_POST['localip'] == get_interface_ip($_POST['interface'])) {
     $input_errors[] = gettext("The specified server address is equal to an interface ip address.");
 }
 for ($x = 0; $x < 4999; $x++) {
     if ($_POST["username{$x}"]) {
         if (empty($_POST["password{$x}"])) {
             $input_errors[] = sprintf(gettext("No password specified for username %s"), $_POST["username{$x}"]);
         }
         if ($_POST["ip{$x}"] != "" && !is_ipaddr($_POST["ip{$x}"])) {
             $input_errors[] = sprintf(gettext("Incorrect ip address  specified for username %s"), $_POST["username{$x}"]);
         }
     }
 }
Beispiel #17
0
function is_inrange($test, $start, $end)
{
    if (ip2ulong($test) < ip2ulong($end) && ip2ulong($test) > ip2ulong($start)) {
        return true;
    } else {
        return false;
    }
}
 /* make sure it's not within the dynamic subnet */
 if ($_POST['ipaddr']) {
     $dynsubnet_start = ip2ulong($config['dhcpd'][$if]['range']['from']);
     $dynsubnet_end = ip2ulong($config['dhcpd'][$if]['range']['to']);
     if (ip2ulong($_POST['ipaddr']) >= $dynsubnet_start && ip2ulong($_POST['ipaddr']) <= $dynsubnet_end) {
         $input_errors[] = sprintf(gettext("The IP address must not be within the DHCP range for this interface."));
     }
     foreach ($a_pools as $pidx => $p) {
         if (is_inrange_v4($_POST['ipaddr'], $p['range']['from'], $p['range']['to'])) {
             $input_errors[] = gettext("The IP address must not be within the range configured on a DHCP pool for this interface.");
             break;
         }
     }
     $lansubnet_start = ip2ulong(gen_subnetv4($ifcfgip, $ifcfgsn));
     $lansubnet_end = ip2ulong(gen_subnetv4_max($ifcfgip, $ifcfgsn));
     $ipaddr_int = ip2ulong($_POST['ipaddr']);
     if ($ipaddr_int < $lansubnet_start || $ipaddr_int > $lansubnet_end) {
         $input_errors[] = sprintf(gettext("The IP address must lie in the %s subnet."), $ifcfgdescr);
     }
     if ($ipaddr_int == $lansubnet_start) {
         $input_errors[] = sprintf(gettext("The IP address cannot be the %s network address."), $ifcfgdescr);
     }
     if ($ipaddr_int == $lansubnet_end) {
         $input_errors[] = sprintf(gettext("The IP address cannot be the %s broadcast address."), $ifcfgdescr);
     }
 }
 if ($_POST['gateway'] && !is_ipaddrv4($_POST['gateway'])) {
     $input_errors[] = gettext("A valid IP address must be specified for the gateway.");
 }
 if ($_POST['wins1'] && !is_ipaddrv4($_POST['wins1']) || $_POST['wins2'] && !is_ipaddrv4($_POST['wins2'])) {
     $input_errors[] = gettext("A valid IP address must be specified for the primary/secondary WINS servers.");
Beispiel #19
0
 }
 $lip = ip2ulong($data['ip']);
 if ($data['act'] != "static") {
     foreach ($config['dhcpd'] as $dhcpif => $dhcpifconf) {
         if (!is_array($dhcpifconf['range'])) {
             continue;
         }
         if ($lip >= ip2ulong($dhcpifconf['range']['from']) && $lip <= ip2ulong($dhcpifconf['range']['to'])) {
             $data['if'] = $dhcpif;
             break;
         }
         // Check if the IP is in the range of any DHCP pools
         if (is_array($dhcpifconf['pool'])) {
             foreach ($dhcpifconf['pool'] as $dhcppool) {
                 if (is_array($dhcppool['range'])) {
                     if ($lip >= ip2ulong($dhcppool['range']['from']) && $lip <= ip2ulong($dhcppool['range']['to'])) {
                         $data['if'] = $dhcpif;
                         break 2;
                     }
                 }
             }
         }
     }
 }
 echo "<tr>\n";
 echo "<td class=\"listlr\">{$fspans}{$data['ip']}{$fspane}</td>\n";
 $mac = $data['mac'];
 $mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
 if ($data['online'] != "online") {
     if (isset($mac_man[$mac_hi])) {
         // Manufacturer for this MAC is defined