diff --git a/server/cn/home/www/IoTgod-www-pre/usr/plugins/RobotsPlus/Logs.php b/server/cn/home/www/IoTgod-www-pre/usr/plugins/RobotsPlus/Logs.php new file mode 100644 index 0000000..6fe4e8e --- /dev/null +++ b/server/cn/home/www/IoTgod-www-pre/usr/plugins/RobotsPlus/Logs.php @@ -0,0 +1,247 @@ + +
+
+ +
+
+
+ plugin('RobotsPlus'); + $botlist = $config->botlist; + $pagecount = $config->pagecount; + $isdrop = $config->droptable; + if ($botlist == null || $pagecount == null || $isdrop == null) + { + throw new Typecho_Plugin_Exception('请先设置插件!'); + } + $db = Typecho_Db::get(); + $prefix = $db->getPrefix(); + $p = 1; + $rtype = ''; + $oldtype = ''; + if (isset($_POST['rpage'])) { + $p = $_POST['rpage']; + } + if (isset($_POST['do'])) { + $do = $_POST['do']; + if ($do == 'delete') { + if (isset($_POST['lid'])) { + $lids = $_POST['lid']; + $deleteCount = 0; + if ($lids && is_array($lids)) { + foreach ($lids as $lid) { + if ($db->query($db->delete($prefix.'robots_logs')->where('lid = ?', $lid))) { + $deleteCount ++; + } + } + } + Typecho_Widget::widget('Widget_Notice')->set('成功删除蜘蛛日志',NULL,'success'); + Typecho_Response::redirect(Typecho_Common::url('extending.php?panel=RobotsPlus%2FLogs.php', $options->adminUrl)); + }else{ + Typecho_Widget::widget('Widget_Notice')->set('当前没有选择的日志',NULL,'notice'); + Typecho_Response::redirect(Typecho_Common::url('extending.php?panel=RobotsPlus%2FLogs.php', $options->adminUrl)); + } + } + if (strpos($do,'clear')!==false) + { + try + { + $cleartype = substr($do, 6); + $options = Typecho_Widget::widget('Widget_Options'); + $timeStamp = $options->gmtTime; + $offset = $options->timezone - $options->serverTimezone; + $gtime = $timeStamp + $offset; + $lowtime = $gtime - ($cleartype * 86400); + $db->query($db->delete($prefix.'robots_logs')->where('ltime < ?', $lowtime)); + Typecho_Widget::widget('Widget_Notice')->set('清除日志成功',NULL,'success'); + Typecho_Response::redirect(Typecho_Common::url('extending.php?panel=RobotsPlus%2FLogs.php', $options->adminUrl)); + } + catch (Typecho_Db_Exception $e) + { + Typecho_Widget::widget('Widget_Notice')->set('清除日志失败',NULL,'notice'); + Typecho_Response::redirect(Typecho_Common::url('extending.php?panel=RobotsPlus%2FLogs.php', $options->adminUrl)); + } + } + } + if (isset($_POST['oldtype'])) { + $oldtype = $_POST['oldtype']; + } + if (isset($_POST['rpage']) && $_POST['rtype']!=='') { + $rtype = $_POST['rtype']; + if ($oldtype !== $rtype) { + $p = 1; + } + $logs = $db->fetchAll($db->select()->from($prefix.'robots_logs')->where('bot = ?', $rtype)->order($prefix.'robots_logs.lid', Typecho_Db::SORT_DESC)->page($p, $pagecount)); + $rows = count($db->fetchAll($db->select('lid')->from($prefix.'robots_logs')->where('bot = ?', $rtype))); + }else{ + $logs = $db->fetchAll($db->select()->from($prefix.'robots_logs')->order($prefix.'robots_logs.lid', Typecho_Db::SORT_DESC)->page($p, $pagecount)); + $rows = count($db->fetchAll($db->select('lid')->from($prefix.'robots_logs'))); + } + $co = $rows % $pagecount; + $pageno = floor($rows / $pagecount); + if ($co !== 0) { + $pageno += 1; + } + ?> +
+

操作: + 全选, + 不选    + 选中项: + 删除    + 清除选项: + 清除所有 + 保留一天 + 保留两天 + 保留三天 + 保留一周 + 保留半个月 + 保留一个月 +

+ + + +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
受访地址 蜘蛛名称IP地址查询位置日期
">
+ +
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/server/cn/home/www/IoTgod-www-pre/usr/plugins/RobotsPlus/Mysql.sql b/server/cn/home/www/IoTgod-www-pre/usr/plugins/RobotsPlus/Mysql.sql new file mode 100644 index 0000000..b85c86b --- /dev/null +++ b/server/cn/home/www/IoTgod-www-pre/usr/plugins/RobotsPlus/Mysql.sql @@ -0,0 +1,8 @@ +CREATE TABLE `typecho_robots_logs` ( + `lid` int(10) unsigned NOT NULL auto_increment, + `bot` varchar(16) default NULL, + `url` varchar(64) default NULL, + `ip` varchar(16) default NULL, + `ltime` int(10) unsigned default '0', + PRIMARY KEY (`lid`) +) ENGINE=MYISAM DEFAULT CHARSET=%charset%; \ No newline at end of file diff --git a/server/cn/home/www/IoTgod-www-pre/usr/plugins/RobotsPlus/Plugin.php b/server/cn/home/www/IoTgod-www-pre/usr/plugins/RobotsPlus/Plugin.php new file mode 100644 index 0000000..3a443c9 --- /dev/null +++ b/server/cn/home/www/IoTgod-www-pre/usr/plugins/RobotsPlus/Plugin.php @@ -0,0 +1,128 @@ +header = array('RobotsPlus_Plugin', 'isbot'); + return _t($meg.'。请进行初始化设置'); + } + public static function deactivate() + { + $config = Typecho_Widget::widget('Widget_Options')->plugin('RobotsPlus'); + $isdrop = $config->droptable; + if ($isdrop == 0) + { + $db = Typecho_Db::get(); + $prefix = $db->getPrefix(); + $db->query("DROP TABLE `".$prefix."robots_logs`", Typecho_Db::WRITE); + } + Helper::removePanel(1, 'RobotsPlus/Logs.php'); + } + public static function config(Typecho_Widget_Helper_Form $form) + { + $options = array ( + 'baidu' => '百度', + 'google' => '谷歌', + 'sogou' => '搜狗', + 'youdao' => '有道', + 'soso' => '搜搜', + 'bing' => '必应', + 'yahoo' => '雅虎', + '360' => '360搜索' + ); + $botlist = new Typecho_Widget_Helper_Form_Element_Checkbox( + 'botlist', $options, '', + '蜘蛛记录设置:', '请选择要记录的蜘蛛日志'); + + $pagecount = new Typecho_Widget_Helper_Form_Element_Text( + 'pagecount', NULL, '', + '分页数量', '每页显示的日志数量'); + $dbool = array ( + '0' => '删除', + '1' => '不删除' + ); + $droptable = new Typecho_Widget_Helper_Form_Element_Radio( + 'droptable', $dbool, '', + '删除数据表:', '请选择是否在禁用插件时,删除日志数据表'); + $form->addInput($botlist); + $form->addInput($pagecount); + $form->addInput($droptable); + } + public static function personalConfig(Typecho_Widget_Helper_Form $form) + { + } + public static function install() + { + $installDb = Typecho_Db::get(); + $type = explode('_', $installDb->getAdapterName()); + $type = array_pop($type); + $prefix = $installDb->getPrefix(); + $scripts = file_get_contents('usr/plugins/RobotsPlus/Mysql.sql'); + $scripts = str_replace('typecho_', $prefix, $scripts); + $scripts = str_replace('%charset%', 'utf8', $scripts); + $scripts = explode(';', $scripts); + try { + foreach ($scripts as $script) { + $script = trim($script); + if ($script) { + $installDb->query($script, Typecho_Db::WRITE); + } + } + return '成功创建数据表,插件启用成功'; + } catch (Typecho_Db_Exception $e) { + $code = $e->getCode(); + if(('Mysql' == $type && 1050 == $code)) { + $script = 'SELECT `lid`, `bot`, `url`, `ip`, `ltime` from `' . $prefix . 'robots_logs`'; + $installDb->query($script, Typecho_Db::READ); + return '数据表已存在,插件启用成功'; + } else { + throw new Typecho_Plugin_Exception('数据表建立失败,插件启用失败。错误号:'.$code); + } + } + } + public static function isbot($rule = NULL) + { + $config = Typecho_Widget::widget('Widget_Options')->plugin('RobotsPlus'); + $bot = NULL; + $botlist = $config->botlist; + if (sizeof($botlist)>0) { + @ $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); + foreach ($botlist as $value) { + if (strpos($useragent,$value)!== false) { + $bot = $value; + } + } + if ($bot !== NULL) { + $request = new Typecho_Request; + $ip = $request->getIp(); + $url = $_SERVER['REQUEST_URI']; + if ($ip == NULL){ + $ip = 'UnKnow'; + } + $options = Typecho_Widget::widget('Widget_Options'); + $timeStamp = $options->gmtTime; + $offset = $options->timezone - $options->serverTimezone; + $gtime = $timeStamp + $offset; + $db = Typecho_Db::get(); + $rows = array ( + 'bot' => $bot, + 'url' => $url, + 'ip' => $ip, + 'ltime' => $gtime, + ); + $db->query($db->insert('table.robots_logs')->rows($rows)); + } + } + } +} diff --git a/server/cn/home/www/IoTgod-www/usr/plugins/RobotsPlus/Logs.php b/server/cn/home/www/IoTgod-www/usr/plugins/RobotsPlus/Logs.php new file mode 100644 index 0000000..6fe4e8e --- /dev/null +++ b/server/cn/home/www/IoTgod-www/usr/plugins/RobotsPlus/Logs.php @@ -0,0 +1,247 @@ + +
+
+ +
+
+
+ plugin('RobotsPlus'); + $botlist = $config->botlist; + $pagecount = $config->pagecount; + $isdrop = $config->droptable; + if ($botlist == null || $pagecount == null || $isdrop == null) + { + throw new Typecho_Plugin_Exception('请先设置插件!'); + } + $db = Typecho_Db::get(); + $prefix = $db->getPrefix(); + $p = 1; + $rtype = ''; + $oldtype = ''; + if (isset($_POST['rpage'])) { + $p = $_POST['rpage']; + } + if (isset($_POST['do'])) { + $do = $_POST['do']; + if ($do == 'delete') { + if (isset($_POST['lid'])) { + $lids = $_POST['lid']; + $deleteCount = 0; + if ($lids && is_array($lids)) { + foreach ($lids as $lid) { + if ($db->query($db->delete($prefix.'robots_logs')->where('lid = ?', $lid))) { + $deleteCount ++; + } + } + } + Typecho_Widget::widget('Widget_Notice')->set('成功删除蜘蛛日志',NULL,'success'); + Typecho_Response::redirect(Typecho_Common::url('extending.php?panel=RobotsPlus%2FLogs.php', $options->adminUrl)); + }else{ + Typecho_Widget::widget('Widget_Notice')->set('当前没有选择的日志',NULL,'notice'); + Typecho_Response::redirect(Typecho_Common::url('extending.php?panel=RobotsPlus%2FLogs.php', $options->adminUrl)); + } + } + if (strpos($do,'clear')!==false) + { + try + { + $cleartype = substr($do, 6); + $options = Typecho_Widget::widget('Widget_Options'); + $timeStamp = $options->gmtTime; + $offset = $options->timezone - $options->serverTimezone; + $gtime = $timeStamp + $offset; + $lowtime = $gtime - ($cleartype * 86400); + $db->query($db->delete($prefix.'robots_logs')->where('ltime < ?', $lowtime)); + Typecho_Widget::widget('Widget_Notice')->set('清除日志成功',NULL,'success'); + Typecho_Response::redirect(Typecho_Common::url('extending.php?panel=RobotsPlus%2FLogs.php', $options->adminUrl)); + } + catch (Typecho_Db_Exception $e) + { + Typecho_Widget::widget('Widget_Notice')->set('清除日志失败',NULL,'notice'); + Typecho_Response::redirect(Typecho_Common::url('extending.php?panel=RobotsPlus%2FLogs.php', $options->adminUrl)); + } + } + } + if (isset($_POST['oldtype'])) { + $oldtype = $_POST['oldtype']; + } + if (isset($_POST['rpage']) && $_POST['rtype']!=='') { + $rtype = $_POST['rtype']; + if ($oldtype !== $rtype) { + $p = 1; + } + $logs = $db->fetchAll($db->select()->from($prefix.'robots_logs')->where('bot = ?', $rtype)->order($prefix.'robots_logs.lid', Typecho_Db::SORT_DESC)->page($p, $pagecount)); + $rows = count($db->fetchAll($db->select('lid')->from($prefix.'robots_logs')->where('bot = ?', $rtype))); + }else{ + $logs = $db->fetchAll($db->select()->from($prefix.'robots_logs')->order($prefix.'robots_logs.lid', Typecho_Db::SORT_DESC)->page($p, $pagecount)); + $rows = count($db->fetchAll($db->select('lid')->from($prefix.'robots_logs'))); + } + $co = $rows % $pagecount; + $pageno = floor($rows / $pagecount); + if ($co !== 0) { + $pageno += 1; + } + ?> +
+

操作: + 全选, + 不选    + 选中项: + 删除    + 清除选项: + 清除所有 + 保留一天 + 保留两天 + 保留三天 + 保留一周 + 保留半个月 + 保留一个月 +

+ + + +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
受访地址 蜘蛛名称IP地址查询位置日期
">
+ +
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/server/cn/home/www/IoTgod-www/usr/plugins/RobotsPlus/Mysql.sql b/server/cn/home/www/IoTgod-www/usr/plugins/RobotsPlus/Mysql.sql new file mode 100644 index 0000000..b85c86b --- /dev/null +++ b/server/cn/home/www/IoTgod-www/usr/plugins/RobotsPlus/Mysql.sql @@ -0,0 +1,8 @@ +CREATE TABLE `typecho_robots_logs` ( + `lid` int(10) unsigned NOT NULL auto_increment, + `bot` varchar(16) default NULL, + `url` varchar(64) default NULL, + `ip` varchar(16) default NULL, + `ltime` int(10) unsigned default '0', + PRIMARY KEY (`lid`) +) ENGINE=MYISAM DEFAULT CHARSET=%charset%; \ No newline at end of file diff --git a/server/cn/home/www/IoTgod-www/usr/plugins/RobotsPlus/Plugin.php b/server/cn/home/www/IoTgod-www/usr/plugins/RobotsPlus/Plugin.php new file mode 100644 index 0000000..3a443c9 --- /dev/null +++ b/server/cn/home/www/IoTgod-www/usr/plugins/RobotsPlus/Plugin.php @@ -0,0 +1,128 @@ +header = array('RobotsPlus_Plugin', 'isbot'); + return _t($meg.'。请进行初始化设置'); + } + public static function deactivate() + { + $config = Typecho_Widget::widget('Widget_Options')->plugin('RobotsPlus'); + $isdrop = $config->droptable; + if ($isdrop == 0) + { + $db = Typecho_Db::get(); + $prefix = $db->getPrefix(); + $db->query("DROP TABLE `".$prefix."robots_logs`", Typecho_Db::WRITE); + } + Helper::removePanel(1, 'RobotsPlus/Logs.php'); + } + public static function config(Typecho_Widget_Helper_Form $form) + { + $options = array ( + 'baidu' => '百度', + 'google' => '谷歌', + 'sogou' => '搜狗', + 'youdao' => '有道', + 'soso' => '搜搜', + 'bing' => '必应', + 'yahoo' => '雅虎', + '360' => '360搜索' + ); + $botlist = new Typecho_Widget_Helper_Form_Element_Checkbox( + 'botlist', $options, '', + '蜘蛛记录设置:', '请选择要记录的蜘蛛日志'); + + $pagecount = new Typecho_Widget_Helper_Form_Element_Text( + 'pagecount', NULL, '', + '分页数量', '每页显示的日志数量'); + $dbool = array ( + '0' => '删除', + '1' => '不删除' + ); + $droptable = new Typecho_Widget_Helper_Form_Element_Radio( + 'droptable', $dbool, '', + '删除数据表:', '请选择是否在禁用插件时,删除日志数据表'); + $form->addInput($botlist); + $form->addInput($pagecount); + $form->addInput($droptable); + } + public static function personalConfig(Typecho_Widget_Helper_Form $form) + { + } + public static function install() + { + $installDb = Typecho_Db::get(); + $type = explode('_', $installDb->getAdapterName()); + $type = array_pop($type); + $prefix = $installDb->getPrefix(); + $scripts = file_get_contents('usr/plugins/RobotsPlus/Mysql.sql'); + $scripts = str_replace('typecho_', $prefix, $scripts); + $scripts = str_replace('%charset%', 'utf8', $scripts); + $scripts = explode(';', $scripts); + try { + foreach ($scripts as $script) { + $script = trim($script); + if ($script) { + $installDb->query($script, Typecho_Db::WRITE); + } + } + return '成功创建数据表,插件启用成功'; + } catch (Typecho_Db_Exception $e) { + $code = $e->getCode(); + if(('Mysql' == $type && 1050 == $code)) { + $script = 'SELECT `lid`, `bot`, `url`, `ip`, `ltime` from `' . $prefix . 'robots_logs`'; + $installDb->query($script, Typecho_Db::READ); + return '数据表已存在,插件启用成功'; + } else { + throw new Typecho_Plugin_Exception('数据表建立失败,插件启用失败。错误号:'.$code); + } + } + } + public static function isbot($rule = NULL) + { + $config = Typecho_Widget::widget('Widget_Options')->plugin('RobotsPlus'); + $bot = NULL; + $botlist = $config->botlist; + if (sizeof($botlist)>0) { + @ $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); + foreach ($botlist as $value) { + if (strpos($useragent,$value)!== false) { + $bot = $value; + } + } + if ($bot !== NULL) { + $request = new Typecho_Request; + $ip = $request->getIp(); + $url = $_SERVER['REQUEST_URI']; + if ($ip == NULL){ + $ip = 'UnKnow'; + } + $options = Typecho_Widget::widget('Widget_Options'); + $timeStamp = $options->gmtTime; + $offset = $options->timezone - $options->serverTimezone; + $gtime = $timeStamp + $offset; + $db = Typecho_Db::get(); + $rows = array ( + 'bot' => $bot, + 'url' => $url, + 'ip' => $ip, + 'ltime' => $gtime, + ); + $db->query($db->insert('table.robots_logs')->rows($rows)); + } + } + } +}