📄 add_comm.php
字号:
<?php
include('login.php');
include('lib/conf.php');
include('lib/function.php');
require('lib/IPv4.php');
$name = $_POST["name"];
$description = $_POST["description"];
$netclass = $_POST["netclass"];
$max_usr = $_POST["max_usr"];
$type_comm = $_POST["type_comm"];
$type_vpn = $_POST["type_vpn"];
$file_key = $_POST["file_key"];
$host_srv = $_POST["host_srv"];
$port_srv = $_POST["port_srv"];
if ($name == "") {
echo "Invalid name<br>";
echo "<a href=\"javascript:history.back();\">Go back</a>";
exit();
}
if ($netclass == "A") {
$max_usr = $_POST["max_usrA"];
$num1 = $_POST["num1A"];
$num2 = $_POST["num2A"];
$num3 = $_POST["num3A"];
$num4 = $_POST["num4A"];
}
if ($netclass == "C") {
$max_usr = $_POST["max_usrC"];
$num1 = $_POST["num1C"];
$num2 = $_POST["num2C"];
$num3 = $_POST["num3C"];
$num4 = $_POST["num4C"];
}
// create ip subnet
$subnet = "$num1"."."."$num2"."."."$num3"."."."$num4";
// create ip netmask
if ($max_usr == "16777214") $netmask="255.0.0.0";
if ($max_usr == "8388606") $netmask="255.128.0.0";
if ($max_usr == "4194302") $netmask="255.192.0.0";
if ($max_usr == "2097150") $netmask="255.224.0.0";
if ($max_usr == "1048574") $netmask="255.240.0.0";
if ($max_usr == "524286") $netmask="255.248.0.0";
if ($max_usr == "262142") $netmask="255.252.0.0";
if ($max_usr == "131070") $netmask="255.254.0.0";
if ($max_usr == "65534") $netmask="255.255.0.0";
if ($max_usr == "32766") $netmask="255.255.128.0";
if ($max_usr == "16382") $netmask="255.255.192.0";
if ($max_usr == "8190") $netmask="255.255.224.0";
if ($max_usr == "4094") $netmask="255.255.240.0";
if ($max_usr == "2046") $netmask="255.255.248.0";
if ($max_usr == "1022") $netmask="255.255.252.0";
if ($max_usr == "510") $netmask="255.255.254.0";
if ($max_usr == "254") $netmask="255.255.255.0";
if ($max_usr == "126") $netmask="255.255.255.128";
if ($max_usr == "62") $netmask="255.255.255.192";
if ($max_usr == "30") $netmask="255.255.255.224";
if ($max_usr == "14") $netmask="255.255.255.240";
if ($max_usr == "6") $netmask="255.255.255.248";
if ($max_usr == "2") $netmask="255.255.255.252";
// create IPv4 object
$ip_calc = new Net_IPv4();
// set variables
$ip_calc->ip = $subnet;
$ip_calc->netmask = $netmask;
// calculate
$error = $ip_calc->calculate();
if (is_object($error)) {
echo "An error occured: ".$error->getMessage();
exit();
}
if ($ip_calc->network != $subnet) {
echo "Invalid subnet<br>";
echo "<a href=\"javascript:history.back();\">Go back</a>";
exit();
}
if ($type_vpn == "NOTCRYPT") {
$file_key="NULL";
$key="NULL";
}
if (($type_vpn == "CRYPT") && ($file_key == "")) {
echo "Invalid filename or null value of the key, please enter a valid name<br>";
echo "<a href=\"javascript:history.back();\">Go back</a>";
exit();
}
if ($type_vpn == "CRYPT") {
if(($fhandle = fopen('/dev/urandom','rb')) != FALSE) {
set_magic_quotes_runtime(0);
for($i=0;$i<256;$i++) {
$val = ord(fgetc($fhandle));
if($val <= 0x0f) $rb = sprintf("0%X",$val);
else $rb = sprintf("%X",$val);
$rs = strtolower($rs);
if (($i!=0) && ($i%16==0)) $rs .= "
";
$rs .= "$rb";
}
fclose($fhandle);
}
$key = "#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
";
$key = $key. "$rs
-----END OpenVPN Static key V1-----
";
}
if ($host_srv != "my_vpn.dyndns.org" || $host_srv != "") {
if ($host_srv != gethostbyname($host_srv)) {
$ip_host = new Net_IPv4();
if (! $ip_host->validateIP(gethostbyname($host_srv))) {
echo "Invalid Hostname or IP Address<br>";
echo "<a href=\"javascript:history.back();\">Go back</a>";
exit();
}
}
else {
$ip_host = new Net_IPv4();
if (! $ip_host->validateIP($host_srv)) {
echo "Invalid Hostname or IP Address<br>";
echo "<a href=\"javascript:history.back();\">Go back</a>";
exit();
}
}
}
else {
echo "Invalid Hostname or IP Address<br>";
echo "<a href=\"javascript:history.back();\">Go back</a>";
exit();
}
$conn = mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname,$conn);
$query = "INSERT INTO `COMM` (`id`, `name`, `description`, `subnet`, `netmask`, `file_key`, `host_srv`, `port_srv`, `tot_usr`, `type_vpn`, `max_usr`, `key`, `uname_admin`, `status`, `type_comm`) VALUES ('', '$name', '$description', '$subnet', '$netmask', '$file_key', '$host_srv', '$port_srv', '1', '$type_vpn', '$max_usr', '$key', '$user_name', '1', '$type_comm');";
mysql_query($query)
or die("<br>Invalid query: $query\n<BR>\n" . mysql_error());
$query = "SELECT id FROM COMM WHERE name = '$name'";
$result = mysql_query($query)
or die("<br>Invalid query: $query\n<BR>\n" . mysql_error());
$fetch_em = mysql_fetch_array($result);
$id1 = $fetch_em['id'];
// ip_num generator
$ip = ip2long($subnet);
$nm = ip2long($netmask);
$nw = ($ip & $nm);
$bc = $nw | (~$nm);
$broadcast_addr = long2ip($bc);
$ip_num=CalculateIPRange($subnet, $broadcast_addr, 1);
//add directly the admin to the community
$query = "SELECT `email` FROM `USERS` WHERE `user_name` LIKE '$user_name'";
$result = mysql_query($query)
or die("<br>Invalid query: $query\n<BR>\n" . mysql_error());
$row = mysql_fetch_row ($result);
$email = $row[0];
$hash=md5($email.$hidden_hash_var);
$query = "INSERT INTO `MEMB` (`id`, `id1`, `ip_num`, `confirmed`, `hash`) VALUES ('$uid', '$id1', '$ip_num', '1', '$hash');";
mysql_query($query)
or die("<br>Invalid query: $query\n<BR>\n" . mysql_error());
//mysql_close($conn);
redirect("index.php?pag=myaccount");
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -