diff --git a/3wifi.php b/3wifi.php index 11bcc46..9c8ee9f 100755 --- a/3wifi.php +++ b/3wifi.php @@ -895,10 +895,11 @@ function randhex($length) $useapi = false; if (!is_null($key)) $useapi = $UserManager->AuthByApiKey($key, true); + $ip = _ip2long($_SERVER["REMOTE_ADDR"]); $uid = $UserManager->uID; if (is_null($uid) || $UserManager->Level < 1 || ($useapi && $UserManager->ApiAccess != 'write')) $uid = 'NULL'; - if ($db->query('INSERT INTO tasks (`tid`,`created`,`modified`,`ext`,`comment`,`checkexist`,`nowait`,`uid`) VALUES (\''.$tid.'\', now(), now(), \''.$ext.'\', \''.$comment.'\', '.$checkexist.', '.$nowait.', '.$uid.')')) + if ($db->query('INSERT INTO tasks (`tid`,`created`,`modified`,`ext`,`comment`,`checkexist`,`nowait`,`uid`,`ipaddr`) VALUES (\''.$tid.'\', now(), now(), \''.$ext.'\', \''.$comment.'\', '.$checkexist.', '.$nowait.', '.$uid.', '.$ip.')')) { $json['upload']['state'] = true; $json['upload']['tid'] = $tid; @@ -972,11 +973,13 @@ function randhex($length) } $id = (int)$id; $sql = "SELECT - * + *, extinfo.data AS extinfo FROM `BASE_TABLE` INNER JOIN `GEO_TABLE` USING(BSSID) LEFT JOIN `comments` USING(cmtid) + LEFT JOIN extinfo USING (id) + LEFT JOIN logupload USING (id) WHERE id = $id"; $res = QuerySql($sql); @@ -990,6 +993,8 @@ function randhex($length) $json['data'] = array( 'id' => (int)$row['id'], 'time' => $row['time'], + 'updated' => $row['updated'], + 'last_uploader' => _long2ip($row['ipaddr']), 'comment' => $row['cmtval'], 'ip' => _long2ip($row['IP']), 'port' => (int)$row['Port'], @@ -1010,6 +1015,7 @@ function randhex($length) 'dns1' => _long2ip($row['DNS1']), 'dns2' => _long2ip($row['DNS2']), 'dns3' => _long2ip($row['DNS3']), + 'extinfo' => $row['extinfo'], 'lat' => 'none', 'lon' => 'none', 'quadkey' => $row['quadkey'], diff --git a/3wifi.sql b/3wifi.sql index dd8d496..09b9827 100644 --- a/3wifi.sql +++ b/3wifi.sql @@ -71,6 +71,7 @@ CREATE TABLE `comments` ( CREATE TABLE `tasks` ( `tid` CHAR(32) NOT NULL, `uid` INT(11) UNSIGNED NULL DEFAULT NULL, + `ipaddr` INT(11) NOT NULL, `tstate` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0, `created` TIMESTAMP NOT NULL DEFAULT current_timestamp(), `modified` TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), @@ -178,7 +179,7 @@ CREATE TABLE `users` ( CREATE TABLE `logauth` ( `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `IP` INT(15) UNSIGNED NOT NULL, + `IP` INT(15) NOT NULL, `uid` INT(11) UNSIGNED NULL DEFAULT NULL, `action` TINYINT(3) UNSIGNED NOT NULL, `data` CHAR(64) NOT NULL DEFAULT '', @@ -186,6 +187,18 @@ CREATE TABLE `logauth` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- Дамп структуры для таблицы 3wifi.logupload +CREATE TABLE `logupload` ( + `id` INT(10) UNSIGNED NOT NULL, + `updated` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `ipaddr` INT(11) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `FK1_logupload_base` (`id`), + INDEX `updated` (`updated`), + INDEX `ipaddr` (`ipaddr`), + CONSTRAINT `FK1_logupload_base` FOREIGN KEY (`id`) REFERENCES `base` (`id`) ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + -- Дамп структуры для таблицы 3wifi.uploads CREATE TABLE `uploads` ( `uid` INT(10) UNSIGNED NOT NULL, diff --git a/3wifid.php b/3wifid.php index 734a459..b5d1063 100755 --- a/3wifid.php +++ b/3wifid.php @@ -70,7 +70,7 @@ { $cntp++; if ($cntp == 1) continue; // Пропуск заголовка CSV - $res = db_add_ap($data, $cmtid, $uid); + $res = db_add_ap($data, $cmtid, $uid, $task['ipaddr']); ($res == 0 ? $cnta++ : $warn[$cntp - 1] = $res); if (microtime(true) - $time > $hangcheck) { @@ -86,7 +86,7 @@ { $data = explode("\t", $str); $cntp++; - $res = db_add_ap($data, $cmtid, $uid); + $res = db_add_ap($data, $cmtid, $uid, $task['ipaddr']); ($res == 0 ? $cnta++ : $warn[$cntp] = $res); if (microtime(true) - $time > $hangcheck) { diff --git a/db.php b/db.php index 5575e19..bd61baa 100644 --- a/db.php +++ b/db.php @@ -226,6 +226,7 @@ function getTask($tid) $result = array(); $result['id'] = $row['tid']; $result['uid'] = $row['uid']; + $result['ipaddr'] = (int)$row['ipaddr']; $result['state'] = (int)$row['tstate']; $result['created'] = $row['created']; $result['modified'] = $row['modified']; @@ -356,7 +357,7 @@ function CheckRelevanceOfMemoryTables($UseFix) return $Result; } -function db_add_ap($row, $cmtid, $uid) +function db_add_ap($row, $cmtid, $uid, $ipaddr) { global $checkexist; global $db; @@ -463,13 +464,18 @@ function db_add_ap($row, $cmtid, $uid) 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 `cmtid`=$cmtid,`IP`=$addr,`Port`=$port,`Authorization`=$auth,`name`=$name,`RadioOff`=$radio,`Hidden`=$hide,`NoBSSID`=$NoBSSID,`BSSID`=$bssid,`ESSID`=$essid,`Security`=$sec,`WiFiKey`=$key,`WPSPIN`=$wps,`LANIP`=$lanip,`LANMask`=$lanmsk,`WANIP`=$wanip,`WANMask`=$wanmsk,`WANGateway`=$gate,`DNS1`=$DNS[0],`DNS2`=$DNS[1],`DNS3`=$DNS[2];"); + // Берём id точки из таблицы base в любом случае (могут быть расхождения с mem_base) + $res = $db->query("SELECT id FROM ".BASE_TABLE." WHERE NoBSSID=$NoBSSID AND BSSID=$bssid AND BINARY ESSID=$essid AND BINARY WiFiKey=$key AND WPSPIN=$wps"); + $row = $res->fetch_row(); + $res->close(); + $id = (int)$row[0]; + if ($ipaddr != 0) + { + // Регистрируем кто и когда загрузил / последний раз обновил эту точку + $db->query("INSERT INTO logupload (`id`, `ipaddr`) VALUES ($id, $ipaddr) ON DUPLICATE KEY UPDATE `ipaddr` = $ipaddr, `updated` = NOW()"); + } if (!is_null($uid)) { - // Берём id точки из таблицы base в любом случае (могут быть расхождения с mem_base) - $res = $db->query("SELECT id FROM ".BASE_TABLE." WHERE NoBSSID=$NoBSSID AND BSSID=$bssid AND BINARY ESSID=$essid AND BINARY WiFiKey=$key AND WPSPIN=$wps"); - $row = $res->fetch_row(); - $res->close(); - $id = (int)$row[0]; // Выясняем, если кто-то уже загрузил такую точку $res = $db->query("SELECT COUNT(uid) FROM uploads WHERE id=$id"); $row = $res->fetch_row(); @@ -481,11 +487,6 @@ function db_add_ap($row, $cmtid, $uid) if (!empty($data)) { // Собираем доп. информацию о точке (может быть серийник и что-либо ещё) - $res = $db->query("SELECT id FROM ".BASE_TABLE." WHERE NoBSSID=$NoBSSID AND BSSID=$bssid AND BINARY ESSID=$essid AND BINARY WiFiKey=$key AND WPSPIN=$wps"); - $row = $res->fetch_row(); - $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");