Permalink
Browse files

DB: Parse additional extinfo columns

  • Loading branch information...
binarymaster committed May 8, 2018
1 parent 7beded3 commit f20e8746b66e172227e3b854ce18deec1521e137
Showing with 53 additions and 0 deletions.
  1. +3 −0 3wifi.sql
  2. +24 −0 db.php
  3. +26 −0 utils.php
View
@@ -232,6 +232,9 @@ INSERT INTO `users` SET
CREATE TABLE `extinfo` (
`id` INT(11) NOT NULL,
`data` VARCHAR(255) NOT NULL,
`sn1` VARCHAR(50) NULL DEFAULT NULL,
`sn2` VARCHAR(50) NULL DEFAULT NULL,
`cable_mac` BIGINT(15) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `data_index` (`data`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
View
24 db.php
@@ -457,6 +457,8 @@ function db_add_ap($row, $cmtid, $uid)
for ($i = 0; $i <= 3; $i++)
if (!isset($DNS[$i])) $DNS[$i] = 'NULL';
$data = trim(preg_replace('/\s+/', ' ', $row[21])); // Comment
if ($data == "HNAP bypass auth")
$data = '';
QuerySql("INSERT INTO BASE_TABLE (`cmtid`,`IP`,`Port`,`Authorization`,`name`,`RadioOff`,`Hidden`,`NoBSSID`,`BSSID`,`ESSID`,`Security`,`WiFiKey`,`WPSPIN`,`LANIP`,`LANMask`,`WANIP`,`WANMask`,`WANGateway`,`DNS1`,`DNS2`,`DNS3`)
VALUES ($cmtid, $addr, $port, $auth, $name, $radio, $hide, $NoBSSID, $bssid, $essid, $sec, $key, $wps, $lanip, $lanmsk, $wanip, $wanmsk, $gate, $DNS[0], $DNS[1], $DNS[2])
ON DUPLICATE KEY UPDATE
@@ -484,8 +486,30 @@ function db_add_ap($row, $cmtid, $uid)
$res->close();
$id = (int)$row[0];
// Добавляем информацию
$dt = parseDelimStr($data);
$data = '\''.$db->real_escape_string($data).'\'';
$db->query("INSERT INTO extinfo (`id`, `data`) VALUES ($id, $data) ON DUPLICATE KEY UPDATE `data` = $data");
$sn = getDelimStr('Serial', $dt);
if (!$sn)
$sn = getDelimStr('SN', $dt);
if ($sn !== false)
{
$sn = '\''.$db->real_escape_string($sn).'\'';
$db->query("UPDATE extinfo SET `sn1` = $sn WHERE `id` = $id");
}
$sn = getDelimStr('PON SN', $dt);
if ($sn !== false)
{
$sn = '\''.$db->real_escape_string($sn).'\'';
$db->query("UPDATE extinfo SET `sn2` = $sn WHERE `id` = $id");
}
$mac = getDelimStr('Cable MAC', $dt);
if ($mac !== false && ismac($mac))
{
$mac = mac2dec($mac);
$db->query("UPDATE extinfo SET `cable_mac` = $mac WHERE `id` = $id");
}
}
return 0;
}
View
@@ -61,6 +61,32 @@ function pin2str($pin)
{
return ($pin == 1 ? '' : str_pad($pin, 8, '0', STR_PAD_LEFT));
}
function parseDelimStr($str)
{
$delim = ', ';
if (strpos($str, '; ') !== false)
$delim = '; ';
$ex = explode($delim, $str);
$ret = array();
foreach ($ex as $part)
{
$n = explode(': ', $part);
foreach ($n as $s)
$ret[] = $s;
}
return $ret;
}
function getDelimStr($name, $arr)
{
for ($i = 0; $i < (count($arr) >> 1); $i++)
{
if ($arr[$i << 1] == $name)
{
return $arr[($i << 1) + 1];
}
}
return false;
}
// IP block
function _long2ip($arg)

0 comments on commit f20e874

Please sign in to comment.