remove all of my private package

This commit is contained in:
coolsnowwolf 2018-10-06 18:24:46 +08:00
parent 00209c9bb8
commit c39d3721a6
896 changed files with 0 additions and 161741 deletions

View File

@ -1,105 +0,0 @@
#
# Copyright (C) 2017 adbyby-ram
# Copyright (C) 2017 yushi studio <ywb94@qq.com>
#
# This is free software, licensed under the GNU General Public License v3.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=adbyby-ram
PKG_VERSION:=1.0
PKG_LICENSE:=GPLv3
PKG_LICENSE_FILES:=LICENSE
PKG_MAINTAINER:=yushi studio <ywb94@qq.com>
include $(INCLUDE_DIR)/package.mk
define Package/luci-app-adbyby-ram
SECTION:=luci
CATEGORY:=LuCI
SUBMENU:=3. Applications
TITLE:=adbyby-ram LuCI interface
URL:=https://github.com/ywb94/adbyby-ram
PKGARCH:=all
endef
define Package/luci-app-adbyby-ram/description
LuCI Support for adbyby-ram.
endef
define Build/Prepare
$(foreach po,$(wildcard ${CURDIR}/files/luci/i18n/*.po), \
po2lmo $(po) $(PKG_BUILD_DIR)/$(patsubst %.po,%.lmo,$(notdir $(po)));)
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/luci-app-adbyby-ram/prerm
#!/bin/sh
# check if we are on real system
if [ -z "$${IPKG_INSTROOT}" ]; then
/etc/init.d/adbyby_ram disable
/etc/init.d/adbyby_ram stop
fi
exit 0
endef
define Package/luci-app-adbyby-ram/postinst
#!/bin/sh
if [ -z "$${IPKG_INSTROOT}" ]; then
chmod 755 /etc/init.d/adbyby_ram >/dev/null 2>&1
/etc/init.d/adbyby_ram enable >/dev/null 2>&1
fi
exit 0
endef
ifeq ($(ARCH),mips)
define Package/luci-app-adbyby-ram/install
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
$(INSTALL_DATA) ./files/luci/controller/adbyby.lua $(1)/usr/lib/lua/luci/controller/adbyby.lua
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n
$(INSTALL_DATA) $(PKG_BUILD_DIR)/adbyby.*.lmo $(1)/usr/lib/lua/luci/i18n
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi
$(INSTALL_DATA) ./files/luci/model/cbi/*.lua $(1)/usr/lib/lua/luci/model/cbi/
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) ./files/adbyby_ar71xx.sh $(1)/usr/bin/adbyby.sh
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DATA) ./files/adbyby.config $(1)/etc/config/adbyby
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/adbyby.init $(1)/etc/init.d/adbyby_ram
endef
endif
ifeq ($(ARCH),mipsel)
define Package/luci-app-adbyby-ram/install
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
$(INSTALL_DATA) ./files/luci/controller/adbyby.lua $(1)/usr/lib/lua/luci/controller/adbyby.lua
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n
$(INSTALL_DATA) $(PKG_BUILD_DIR)/adbyby.*.lmo $(1)/usr/lib/lua/luci/i18n
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi
$(INSTALL_DATA) ./files/luci/model/cbi/*.lua $(1)/usr/lib/lua/luci/model/cbi/
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) ./files/adbyby_ramips.sh $(1)/usr/bin/adbyby.sh
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DATA) ./files/adbyby.config $(1)/etc/config/adbyby
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/adbyby.init $(1)/etc/init.d/adbyby_ram
endef
endif
$(eval $(call BuildPackage,luci-app-adbyby-ram))

View File

@ -1,3 +0,0 @@
config adbyby 'adbyby'
option enable '0'

View File

@ -1,58 +0,0 @@
#!/bin/sh /etc/rc.common
######################################################################
#
# Function : Run adbyby in RAM
#
# Creater : ywb94@qq.com, 2017-02-16
#
# Copyright : yushi studio
#
######################################################################
START=80
start() {
/etc/init.d/adbyby_ram enabled
if [ $? == 1 ]; then
return
fi
#不重复启动
icount=`ps -w|grep adbyby.sh|grep -v grep|wc -l`
icount2=`netstat -nautp|grep adbyby|grep -v grep|wc -l`
if [ $icount = 0 -a $icount2 = 0 ] ;then
/usr/bin/adbyby.sh &
fi
}
stop() {
#确保清除防火墙规则
i=0
icount=`iptables -t nat -L|grep "ports 8118"|wc -l`
while [ $i -le 10 -a $icount -gt 1 ]
do
let i=i+1
iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8118
icount=`iptables -t nat -L|grep "ports 8118"|wc -l`
done
if [ -f /tmp/adbyby/bin/stopadbb ] ;then
cd /tmp/adbyby/bin
./stopadbb 2>/dev/null
fi
icount=`ps -w|grep adbyby.sh|grep -v grep|wc -l`
if [ $icount -gt 0 ] ;then
mid=`ps -w|grep adbyby.sh|grep -v grep|awk '{print $1}'`
kill -9 $mid
fi
}
restart() {
stop
start
}

View File

@ -1,49 +0,0 @@
#!/bin/sh
cd /tmp
#等待网络连接成功
wget_ok="0"
#rm -f 7620n.tar.gz
rm -f ar71xx.tar.gz
while [ "$wget_ok" = "0" ]
do
#wget http://update.adbyby.com/download/7620n.tar.gz
wget http://update.adbyby.com/download/ar71xx.tar.gz
if [ "$?" == "0" ]; then
wget_ok="1"
else
sleep 30
fi
done
#解压、启动adbyby
mkdir -p adbyby
#tar -zvxf 7620n.tar.gz -C ./adbyby
tar -zvxf ar71xx.tar.gz -C ./adbyby
#更新一次规则
murl=`cat /tmp/adbyby/bin/update.info|grep lazy.txt|awk '{print $1}'`
if [ ${#murl} -gt 5 ] ;then
murl2=`cat /tmp/adbyby/bin/update.info|grep lazy.txt|awk '{print $2}'`
mfile="/tmp/adbyby/bin"${murl2//\\//}
wget $murl -O $mfile
fi
murl=`cat /tmp/adbyby/bin/update.info|grep video.txt|awk '{print $1}'`
if [ ${#murl} -gt 5 ] ;then
murl2=`cat /tmp/adbyby/bin/update.info|grep video.txt|awk '{print $2}'`
mfile="/tmp/adbyby/bin"${murl2//\\//}
wget $murl -O $mfile
fi
murl=`cat /tmp/adbyby/bin/update.info|grep user.action|awk '{print $1}'`
if [ ${#murl} -gt 5 ] ;then
murl2=`cat /tmp/adbyby/bin/update.info|grep user.action|awk '{print $2}'`
mfile="/tmp/adbyby/bin"${murl2//\\//}
wget $murl -O $mfile
fi
cd ./adbyby/bin
./startadbb

View File

@ -1,48 +0,0 @@
#!/bin/sh
cd /tmp
#等待网络连接成功
wget_ok="0"
rm -f 7620n.tar.gz
#rm -f ar71xx.tar.gz
while [ "$wget_ok" = "0" ]
do
wget http://update.adbyby.com/download/7620n.tar.gz
#wget http://update.adbyby.com/download/ar71xx.tar.gz
if [ "$?" == "0" ]; then
wget_ok="1"
else
sleep 30
fi
done
#解压、启动adbyby
mkdir -p adbyby
tar -zvxf 7620n.tar.gz -C ./adbyby
#tar -zvxf ar71xx.tar.gz -C ./adbyby
#更新一次规则
murl=`cat /tmp/adbyby/bin/update.info|grep lazy.txt|awk '{print $1}'`
if [ ${#murl} -gt 5 ] ;then
murl2=`cat /tmp/adbyby/bin/update.info|grep lazy.txt|awk '{print $2}'`
mfile="/tmp/adbyby/bin"${murl2//\\//}
wget $murl -O $mfile
fi
murl=`cat /tmp/adbyby/bin/update.info|grep video.txt|awk '{print $1}'`
if [ ${#murl} -gt 5 ] ;then
murl2=`cat /tmp/adbyby/bin/update.info|grep video.txt|awk '{print $2}'`
mfile="/tmp/adbyby/bin"${murl2//\\//}
wget $murl -O $mfile
fi
murl=`cat /tmp/adbyby/bin/update.info|grep user.action|awk '{print $1}'`
if [ ${#murl} -gt 5 ] ;then
murl2=`cat /tmp/adbyby/bin/update.info|grep user.action|awk '{print $2}'`
mfile="/tmp/adbyby/bin"${murl2//\\//}
wget $murl -O $mfile
fi
cd ./adbyby/bin
./startadbb

View File

@ -1,10 +0,0 @@
module("luci.controller.adbyby", package.seeall)
function index()
if not nixio.fs.access("/etc/config/adbyby") then
return
end
entry({"admin","services", "adbyby"}, cbi("adbyby"), _("Adbyby"), 20)
end

View File

@ -1,38 +0,0 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n"
msgid "Not exist"
msgstr "不存在"
msgid "AD Block"
msgstr "广告屏蔽"
msgid "Disable"
msgstr "停用"
msgid "Enable"
msgstr "启用"
msgid "Running Status"
msgstr "运行状态"
msgid "Lazy rules time"
msgstr "Lazy规则日期"
msgid "Video rules time"
msgstr "Video规则日期"
msgid "Running"
msgstr "运行中"
msgid "Not Running"
msgstr "未运行"
msgid "Wait Connect.."
msgstr "等待联网"
msgid "Enable Adbyby"
msgstr "是否启用Adbyby"
msgid "Adbyby"
msgstr "广告屏蔽"

View File

@ -1,72 +0,0 @@
local m, s, o,oo
local Run_flag=0
local lazy_time=translate("Not exist")
local video_time=translate("Not exist")
local sys = require "luci.sys"
icount=tonumber(sys.exec("ps -w | grep adbyby |grep -v grep| wc -l"))
if tonumber(icount)>0 then
icount=tonumber(sys.exec("netstat -nautp | grep adbyby |grep -v grep| wc -l"))
if tonumber(icount)>0 then
Run_flag=1
else
Run_flag=2
end
end
if nixio.fs.access("/tmp/adbyby/bin/data/lazy.txt") then
time_cmd="awk 'NR==1{print $3\" \"$4}' /tmp/adbyby/bin/data/lazy.txt"
lazy_time=sys.exec(time_cmd)
end
if nixio.fs.access("/tmp/adbyby/bin/data/video.txt") then
time_cmd="awk 'NR==1{print $3\" \"$4}' /tmp/adbyby/bin/data/video.txt"
video_time=sys.exec(time_cmd)
end
m = Map("adbyby", translate("AD Block"))
s = m:section(NamedSection, "adbyby","adbyby", "")
s.addremove = false
oo = s:option(ListValue, "enable",translate("Enable Adbyby"))
oo:value("0", translate("Disable"))
oo:value("1", translate("Enable"))
oo.widget = "radio"
oo.advance_second_title = true
oo.orientation = "horizontal"
o=s:option(DummyValue, "runstatus",translate("Running Status"))
o.rawhtml = true
if Run_flag==1 then
o.value="<font color='green'>" .. translate("Running") .. "</font>"
elseif Run_flag==0 then
o.value="<font color='red'>" .. translate("Not Running") .. "</font>"
else
o.value="<font color='blue'>" .. translate("Wait Connect..") .. "</font>"
end
o=s:option(DummyValue, "version1",translate("Lazy rules time"))
o.rawhtml = true
o.value="<font color='blue'>" .. lazy_time .. "</font>"
o=s:option(DummyValue, "version2",translate("Video rules time"))
o.rawhtml = true
o.value="<font color='blue'>" .. video_time .. "</font>"
local apply = luci.http.formvalue("cbi.apply")
if apply then
local m_enable=luci.http.formvalue("cbid.adbyby.adbyby.enable")
if m_enable=="0" then
luci.sys.call("/etc/init.d/adbyby_ram disable")
luci.sys.call("/etc/init.d/adbyby_ram stop")
else
luci.sys.call("/etc/init.d/adbyby_ram enable")
luci.sys.call("/etc/init.d/adbyby_ram start")
end
--luci.http.redirect(luci.dispatcher.build_url("admin/services/adbyby"))
end
return m

View File

@ -1,70 +0,0 @@
#
# Copyright (C) 2015-2016 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v3.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=adbyby
PKG_VERSION:=2.7
PKG_RELEASE:=20180616
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
SECTION:=net
CATEGORY:=Network
TITLE:=Powerful adblock module to block ad.
DEPENDS:=
URL:=http://www.adbyby.com/
endef
define Package/$(PKG_NAME)/description
Adbyby is a powerful adblock module to block ad,just like adblock.
endef
define Build/Prepare
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/share/adbyby
$(INSTALL_BIN) ./files/adbyby.sh $(1)/usr/share/adbyby/
$(INSTALL_BIN) ./files/adbybyfirst.sh $(1)/usr/share/adbyby/
$(INSTALL_BIN) ./files/adbybyupdate.sh $(1)/usr/share/adbyby/
$(INSTALL_CONF) ./files/adhook.ini $(1)/usr/share/adbyby/
$(INSTALL_CONF) ./files/user.action $(1)/usr/share/adbyby/
$(INSTALL_DIR) $(1)/usr/share/adbyby/data
$(INSTALL_DATA) ./files/data/* $(1)/usr/share/adbyby/data/
$(INSTALL_DIR) $(1)/usr/share/adbyby/doc
$(INSTALL_DATA) ./files/doc/* $(1)/usr/share/adbyby/doc/
ifeq ($(ARCH),mipsel)
$(INSTALL_BIN) ./files/7620n/adbyby $(1)/usr/share/adbyby/
endif
ifeq ($(ARCH),mips)
$(INSTALL_BIN) ./files/ar71xx/adbyby $(1)/usr/share/adbyby/
endif
ifeq ($(ARCH),i386)
$(INSTALL_BIN) ./files/x86/adbyby $(1)/usr/share/adbyby/
endif
ifeq ($(ARCH),x86_64)
$(INSTALL_BIN) ./files/x86_64/adbyby $(1)/usr/share/adbyby/
endif
ifeq ($(ARCH),arm)
$(INSTALL_BIN) ./files/arm/adbyby $(1)/usr/share/adbyby/
endif
ifeq ($(ARCH),aarch64)
$(INSTALL_BIN) ./files/armv7/adbyby $(1)/usr/share/adbyby/
endif
endef
$(eval $(call BuildPackage,$(PKG_NAME)))

View File

@ -1,16 +0,0 @@
#!/bin/sh
PROG_PATH=/usr/share/adbyby
err=0
until [ $err -ge 5 ]; do
if [ -n "$(pgrep $PROG_PATH/adbyby)" ]; then
iptables-save | grep ADBYBY >/dev/null || \
/etc/init.d/adbyby add_rule
sleep 10
err=0
else
$PROG_PATH/adbyby --no-daemon &>/dev/null &
sleep 1
err=$((err+1))
fi
done
/etc/init.d/adbyby del_rule

View File

@ -1,11 +0,0 @@
#!/bin/sh
PROG_PATH=/usr/share/adbyby
if [ -z "$(dnsmasq --version | grep no-ipset)" ]; then
[ $(uci get adbyby.@adbyby[-1].wan_mode) -ne 2 ] && \
[ $(awk -F= '/^ipset/{print $2}' $PROG_PATH/adhook.ini) -eq 1 ] && \
{
sed -i 's/adbyby_list/adbyby_wan/' /tmp/adbyby_host.conf
echo conf-file=/tmp/adbyby_host.conf >> /etc/dnsmasq.conf
/etc/init.d/dnsmasq restart
}
fi

View File

@ -1,11 +0,0 @@
#!/bin/sh
PROG_PATH=/usr/share/adbyby
if [ -z "$(dnsmasq --version | grep no-ipset)" ]; then
[ $(uci get adbyby.@adbyby[-1].wan_mode) -ne 2 ] && \
[ $(awk -F= '/^ipset/{print $2}' $PROG_PATH/adhook.ini) -eq 1 ] && \
{
sed -i 's/adbyby_list/adbyby_wan/' /tmp/adbyby_host.conf
ipset -F adbyby_wan 2>/dev/null
/etc/init.d/dnsmasq restart
}
fi

View File

@ -1,14 +0,0 @@
[cfg]
### 2.1 ###
listen-address=0.0.0.0:8118
buffer-limit=1024
keep-alive-timeout=30
socket-timeout=60
### 2.5 ###
max_client_connections=0
### 2.6 ###
stack_size=200
auto_restart=0
### 2.7 ###
debug=0
ipset=0

Binary file not shown.

View File

@ -1,121 +0,0 @@
//IE6、7、8、9, from adsafe
%USERPROFILE%\Local Settings\Temporary Internet Files\*.html
%USERPROFILE%\Local Settings\Temporary Internet Files\*.js
%USERPROFILE%\Local Settings\Temporary Internet Files\*.htm
%USERPROFILE%\Local Settings\Temporary Internet Files\*.xml
%USERPROFILE%\Local Settings\Temporary Internet Files\*.css
%USERPROFILE%\Local Settings\Temporary Internet Files\*.swf
%USERPROFILE%\Local Settings\Temporary Internet Files\*.flv
%USERPROFILE%\Local Settings\Temporary Internet Files\*.mp4
%USERPROFILE%\Local Settings\Temporary Internet Files\Content.IE5\*.*
%USERPROFILE%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*
%USERPROFILE%\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\*.*
//360安全浏览器
%USERPROFILE%\Application Data\360se\ie8data\Temporary Internet Files\*.*
//chrome
%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\Cache\*.*
//360极速浏览器
%USERPROFILE%\Local Settings\Application Data\360Chrome\Chrome\User Data\Default\CacheIE\*.*
%USERPROFILE%\Local Settings\Application Data\360Chrome\Chrome\User Data\Default\Cache\*.*
%USERPROFILE%\AppData\Local\360Chrome\Chrome\User Data\Default\Cache\*.*
%USERPROFILE%\Local Settings\Application Data\360Chrome\Chrome\User Data\Default\CacheIE\Content.IE5\*.*
//搜狗浏览器
%USERPROFILE%\Application Data\SogouExplorer\Webkit\Default\Cache\*.*
%USERPROFILE%\AppData\Roaming\SogouExplorer\Webkit\Default\Cache\*.*
//opera浏览器
%USERPROFILE%\AppData\Local\Opera\Opera\cache\*.*
%USERPROFILE%\Local Settings\Application Data\Opera\Opera\cache\*.*
%USERPROFILE%\Local Settings\Application Data\Opera\Opera\application_cache\mcache\*.*
%USERPROFILE%\Local Settings\Application Data\Opera\Opera\application_cache\cache_groups.xml
%USERPROFILE%\Local Settings\Application Data\Opera\Opera\opcache\*.*
//淘宝浏览器
%USERPROFILE%\AppData\Local\TaoBrowser\User Data\Default\Cache\*.*
%USERPROFILE%\AppData\Local\TaoBrowser\User Data\Default\JumpListIcons\*.*
%USERPROFILE%\Local Settings\Application Data\TaoBrowser\User Data\Default\Cache\*.*
//百度浏览器
%USERPROFILE%\Application Data\Baidu\browser\DiskCache\*.*
%USERPROFILE%\AppData\Roaming\Baidu\browser\DiskCache\*.*
//猎豹浏览器
%USERPROFILE%\Local Settings\Application Data\liebao\User Data\Default\Cache\*.*
%USERPROFILE%\Local Settings\Application Data\liebao\User Data\iecache\Content.IE5\*.*
%USERPROFILE%\AppData\Local\liebao\User Data\Default\Cache\*.*
%USERPROFILE%\AppData\Local\liebao\User Data\Default\JumpListIcons\*.*
//Letv
%USERPROFILE%\Application Data\Letv\Logg\*.log
//PPSStream
%APPDATA%\PPStream\adsys\*.*
%APPDATA%\PPStream\banner\*.*
%APPDATA%\PPStream\notice\*.*
%APPDATA%\PPStream\CLCache\*.pld
%APPDATA%\PPStream\FDSCache\*.blf
//PPTV
%APPDATA%\PPLive\PPTV\cache\*.*
//风行
%USERPROFILE%\funshion\cache\*.*
//youku
-s%appdata%\Macromedia\Flash Player\#SharedObjects\YOUKU_FSO_PROXY.sol
-s%APPDATA%\Roaming\Macromedia\Flash Player\#SharedObjects\YOUKU_FSO_PROXY.sol
//letv
-s%appdata%\Macromedia\Flash Player\#SharedObjects\com.letv.sol
//iqiyi
-s%appdata%\Macromedia\Flash Player\#SharedObjects\qiyi_statistics.sol
//chrome YOUKU
-s%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\YOUKU_FSO_PROXY.sol
//chrome LeTv
-s%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\com.letv.sol
//chrome iqiyi
-s%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\qiyi_statistics.sol
//360 youku
-s%USERPROFILE%\AppData\Local\360Chrome\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\YOUKU_FSO_PROXY.sol
//360 letv
-s%USERPROFILE%\AppData\Local\360Chrome\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\com.letv.sol
//360 iqiyi
-s%USERPROFILE%\AppData\Local\360Chrome\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\qiyi_statistics.sol
//暴风影音5
%ALLUSERSPROFILE%\Baofeng\StormPlayer\Profiles\md\*.*
%ALLUSERSPROFILE%\Baofeng\StormPlayer\Profiles\vod\*.*
%ALLUSERSPROFILE%\Application Data\Baofeng\StormPlayer\Profiles\md\*.*
%ALLUSERSPROFILE%\Application Data\Baofeng\StormPlayer\Profiles\vod\*.*
%ALLUSERSPROFILE%\Baofeng\Application Data\StormPlayer\Profiles\md\*.*
%ALLUSERSPROFILE%\Baofeng\Application Data\StormPlayer\Profiles\vod\*.*
//pptv
%ALLUSERSPROFILE%\PPLive\PPTV\Cache\pluginad\*.*
%ALLUSERSPROFILE%\Application Data\PPLive\PPTV\Cache\pluginad\*.*
%ALLUSERSPROFILE%\Application Data\PPLive\PPTV\screensaver\*.*
//多米
C:\Program Files\DuoMi\dmdeskinfo.exe
//UUSEE
%TEMP%\UUFile\*.*
//iqiyi
%ALLUSERSPROFILE%\Application Data\Qiyi\qiyiclient\cache\*.*

View File

@ -1,43 +0,0 @@
//youku
-y%appdata%\Macromedia\Flash Player\#SharedObjects\YOUKU_FSO_PROXY.sol
//youku win7
-y%APPDATA%\Roaming\Macromedia\Flash Player\#SharedObjects\YOUKU_FSO_PROXY.sol
//chrome YOUKU
-y%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\YOUKU_FSO_PROXY.sol
//360 youku
-y%USERPROFILE%\AppData\Local\360Chrome\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\YOUKU_FSO_PROXY.sol
//sougou youku
-y%appdata%\SogouExplorer\Webkit\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\YOUKU_FSO_PROXY.sol
-y%userprofile%\Local Settings\Application Data\Google\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\YOUKU_FSO_PROXY.sol
-y%userprofile%\Local Settings\Application Data\UCBrowser\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\YOUKU_FSO_PROXY.sol
-y%userprofile%\Local Settings\Application Data\360Chrome\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\YOUKU_FSO_PROXY.sol
//qq
%appdata%\Tencent\QQ\Misc\com.tencent.advertisement\*.*
%appdata%\Tencent\QQ\Misc\com.tencent.advertisement\GDT_0\*.*
//letv
-s%appdata%\Macromedia\Flash Player\#SharedObjects\com.letv.sol
//letv1
-s%APPDATA%\Roaming\Macromedia\Flash Player\#SharedObjects\com.letv.sol
//iqiyi
-s%appdata%\Macromedia\Flash Player\#SharedObjects\qiyi_statistics.sol
//iqiyi1
-s%APPDATA%\Roaming\Macromedia\Flash Player\#SharedObjects\qiyi_statistics.sol
//chrome LeTv
-s%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\com.letv.sol
//chrome iqiyi
-s%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\qiyi_statistics.sol
//360 letv
-s%USERPROFILE%\AppData\Local\360Chrome\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\com.letv.sol
//360 iqiyi
-s%USERPROFILE%\AppData\Local\360Chrome\Chrome\User Data\Default\Pepper Data\Shockwave Flash\WritableRoot\#SharedObjects\qiyi_statistics.sol

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +0,0 @@
! ------------------------------ ADByby 自定义过滤语法简表---------------------------------
! -------------- 规则基于abp规则并进行了字符替换部分的扩展-----------------------------
! ABP规则请参考https://adblockplus.org/zh_CN/filters下面为大致摘要
! "!" 为行注释符,注释行以该符号起始作为一行注释语义,用于规则描述
! "*" 为字符通配符能够匹配0长度或任意长度的字符串该通配符不能与正则语法混用。
! "^" 为分隔符,可以是除了字母、数字或者 _ - . % 之外的任何字符。
! "|" 为管线符号,来表示地址的最前端或最末端
! "||" 为子域通配符,方便匹配主域名下的所有子域。
! "~" 为排除标识符,通配符能过滤大多数广告,但同时存在误杀, 可以通过排除标识符修正误杀链接。
! "##" 为元素选择器标识符后面跟需要隐藏元素的CSS样式例如 #ad_id .ad_class
!! 元素隐藏暂不支持全局规则和排除规则
!! 字符替换扩展
! 文本替换选择器标识符,后面跟需要替换的文本数据,格式:$s@模式字符串@替换后的文本@
! 支持通配符*和?
! -------------------------------------------------------------------------------------------

View File

@ -1,23 +0,0 @@
! -----更新时间: 2018-06-13 22:56:37 by:xwhyc-----------------------------------------------
! -----广告反馈:http://www.adbyby.com/help.htm QQ群: 79547134(满), 364066294(满)470705224534897434,438394572--------------
!-------------------------------------------
twmeiju.com##iframe[width="336"]
txzqw##.ad-text,.tac,#banner,[id^="ads_"]
|http://*.com/logo/ad.js
|http://*.com/logo/logo.js
|http://*.com/logo/logoxia.js
|http://*.com/logo/playjs.js
|http://m.haxdu.com/hi18/$script
|http://www.hqck.net/templets/default/js/ntes_jslib_1.x.js
||51wady.com/me.php?id=
||haxwx3.com/web/js/$script
||jiawen88.com
!-----------------------
!---------adbyby---------

File diff suppressed because one or more lines are too long

View File

@ -1,10 +0,0 @@
;¸üйæÔòurl,dir,size,reverse,reverse
http://update.adbyby.com/rule3/lazy.jpg \data\lazy.txt 385337 4 0
http://update.adbyby.com/rule3/video.jpg \data\video.txt 1028 4 0
http://update.adbyby.com/rule3/user.action \user.action 512 5 0
http://update.adbyby.com/rule3/clean.ini \data\clean.ini 2167 0 0
http://update.adbyby.com/rule3/adclear.ini \data\adclear.ini 4901 0 0
https://github.com/gchangchen/suho/raw/master/adhook.dll \adhook.dll 117248 0 0 2.4.3.2
https://github.com/gchangchen/suho/raw/master/adhook64.dll \adhook64.dll 142848 0 0 2.4.3.2
https://github.com/gchangchen/suho/raw/master/adbyby.exe \adbyby.exe 1004183 1 0 2.4.4.0

View File

@ -1,9 +0,0 @@
{+fast-redirects{s@&plid=\d+&uid=@&plid=7038006&uid=@} }
hot.vrs.sohu.com/vrs_flash.action\?vid=
{+fast-redirects{s@/Main.swf\?(?!plid)@/Main.swf?plid=7038006&@} }
tv.sohu.com/upload/swf/201.*?/Main.swf\?
{+fast-redirects{s@http://tv.sohu.com/upload/swf/.*?/PlayerShell.swf@http://update.adbyby.com/swf/sohu_livezb.swf@} }
tv.sohu.com/upload/swf/.*?/PlayerShell.swf\?
{+fast-redirects{s@pl.youku.com/playlist/m3u8\?keyframe=0&.*@update.adbyby.com/youku.m3u8@} }
pl.youku.com/playlist/m3u8\?keyframe=0&

Binary file not shown.

View File

@ -1,109 +0,0 @@
#
# Copyright (C) 2007-2009 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=aMule
PKG_VERSION:=2.3.2
PKG_RELEASE:=2
PKG_REV=4b87b20
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-r$(PKG_REV).tar.bz2
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=$(PKG_REV)
PKG_SOURCE_URL:=https://github.com/amule-project/amule.git
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_BUILD_DEPENDS:=libgd libcryptopp
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
define Package/amule/config
config AMULE_CRYPTOPP_STATIC_LINKING
bool "Link libcryptopp statically"
default y
endef
define Package/amule
SUBMENU:=P2P
SECTION:=net
CATEGORY:=Network
TITLE:=A multi-platform eMule-like ed2k client
URL:=http://www.amule.org/
DEPENDS:=+libpng +libpthread +libncurses +libreadline +libwxbase +libupnp +libbfd \
$(ICONV_DEPENDS) $(INTL_DEPENDS) +!AMULE_CRYPTOPP_STATIC_LINKING:libcryptopp
endef
CONFIGURE_ARGS+= \
--disable-static \
--disable-rpath \
--with-gnu-ld \
--disable-ccache \
--disable-optimize \
--disable-profile \
--disable-monolithic \
--enable-amule-daemon \
--enable-amulecmd \
--enable-webserver \
--disable-amule-gui \
--disable-cas \
--disable-wxcas \
--disable-ed2k \
--disable-alc \
--disable-alcc \
--disable-fileview \
--disable-plasmamule \
--without-wxdebug \
--enable-dlp \
--enable-upnp \
--with-zlib="$(STAGING_DIR)/usr" \
--with-gdlib-prefix="$(STAGING_DIR)/usr" \
--with-libpng-prefix="$(STAGING_DIR)/usr" \
--with-wx-prefix="$(STAGING_DIR)/usr" \
--with-crypto-prefix="$(STAGING_DIR)/usr" \
--with-libiconv-prefix="$(ICONV_PREFIX)" \
--with-libintl-prefix="$(INTL_PREFIX)" \
--with-libupnp-prefix="$(STAGING_DIR)/usr" \
--without-x \
--disable-debug
TARGET_LDFLAGS += -liconv
define Build/Configure
cd $(PKG_BUILD_DIR) && sh ./autogen.sh
$(call Build/Configure/Default)
endef
ifeq ($(CONFIG_AMULE_CRYPTOPP_STATIC_LINKING),y)
SED_CMD:=sed
else
SED_CMD:=true
endif
define Build/Compile
$(SED_CMD) -i 's;^CRYPTOPP_LIBS.*;CRYPTOPP_LIBS \= "$(STAGING_DIR)/usr/lib/libcryptopp.a";g' \
$(PKG_BUILD_DIR)/src/Makefile
$(MAKE) -C $(PKG_BUILD_DIR) \
HOSTCC="$(HOSTCC)" \
DESTDIR="$(PKG_INSTALL_DIR)" \
all
endef
define Package/amule/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_DIR) $(1)/usr/share/amule/webserver
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/amule{cmd,d} $(1)/usr/bin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/webserver/src/amuleweb $(1)/usr/bin/
$(CP) $(PKG_BUILD_DIR)/src/webserver/default $(1)/usr/share/amule/webserver
endef
$(eval $(call BuildPackage,amule))

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +0,0 @@
diff -Naur a/m4/libupnp.m4 b/m4/libupnp.m4
--- a/m4/libupnp.m4 2016-10-06 19:01:54.000000000 +0800
+++ b/m4/libupnp.m4 2016-10-11 07:36:39.198318574 +0800
@@ -52,7 +52,6 @@
[export PKG_CONFIG_PATH=$withval/lib/pkgconfig])
dnl Check for libupnp >= MIN_LIBUPNP_VERSION
- AS_IF([test $cross_compiling = no], [
AC_MSG_CHECKING([for libupnp version >= MIN_LIBUPNP_VERSION])
AS_IF([test -n "$PKG_CONFIG"], [
AS_IF([$PKG_CONFIG libupnp --exists], [
@@ -79,11 +78,6 @@
])
AC_MSG_RESULT([$result$resultstr])
libupnp_error="libupnp >= MIN_LIBUPNP_VERSION not found$resultstr"
- ], [
-dnl Currently cross-compilation with libupnp is not supported.
- result=no
- libupnp_error="cross compiling"
- ])
dnl Execute the right action.
AS_IF([test ${result:-no} = yes], [$2], [$3])

View File

@ -1,78 +0,0 @@
diff --git a/src/amule.h b/src/amule.h
index f25702f..240c02d 100644
--- a/src/amule.h
+++ b/src/amule.h
@@ -553,6 +553,13 @@ class CamuleDaemonApp : public CamuleApp
int OnExit();
virtual int InitGui(bool geometry_enable, wxString &geometry_string);
+ // The GTK wxApps sets its file name conversion properly
+ // in wxApp::Initialize(), while wxAppConsole::Initialize()
+ // does not, leaving wxConvFile being set to wxConvLibc. File
+ // name conversion should be set otherwise amuled will abort to
+ // handle non-ASCII file names which monolithic amule can handle.
+ // This function are overrided to perform this.
+ virtual bool Initialize(int& argc_, wxChar **argv_);
#ifdef AMULED_APPTRAITS
struct sigaction m_oldSignalChildAction;
diff --git a/src/amuled.cpp b/src/amuled.cpp
index 486da59..86e1ff8 100644
--- a/src/amuled.cpp
+++ b/src/amuled.cpp
@@ -704,6 +704,41 @@ int CamuleDaemonApp::InitGui(bool ,wxString &)
return 0;
}
+bool CamuleDaemonApp::Initialize(int& argc_, wxChar **argv_)
+{
+ if ( !wxAppConsole::Initialize(argc_, argv_) ) {
+ return false;
+ }
+
+#ifdef __UNIX__
+ wxString encName;
+#if wxUSE_INTL
+ // if a non default locale is set,
+ // assume that the user wants his
+ // filenames in this locale too
+ encName = wxLocale::GetSystemEncodingName().Upper();
+
+ // But don't consider ASCII in this case.
+ if ( !encName.empty() ) {
+ if ( encName == wxT("US-ASCII") ) {
+ // This means US-ASCII when returned
+ // from GetEncodingFromName().
+ encName.clear();
+ }
+ }
+#endif // wxUSE_INTL
+
+ // in this case, UTF-8 is used by default.
+ if ( encName.empty() ) {
+ encName = wxT("UTF-8");
+ }
+
+ static wxConvBrokenFileNames fileconv(encName);
+ wxConvFileName = &fileconv;
+#endif // __UNIX__
+
+ return true;
+}
int CamuleDaemonApp::OnExit()
{
diff --git a/src/libs/common/Path.cpp b/src/libs/common/Path.cpp
index 28152a2..5efefd0 100644
--- a/src/libs/common/Path.cpp
+++ b/src/libs/common/Path.cpp
@@ -229,7 +229,8 @@ CPath::CPath(const wxString& filename)
}
wxCharBuffer fn = filename2char(filename);
- if (fn.data()) {
+ // add fn.length() for wx 3.x
+ if (fn.data()) {
// Filename is valid in the current locale. This means that
// it either originated from a (wx)system-call, or from a
// user with a properly setup system.

View File

@ -1,174 +0,0 @@
diff --git a/src/SearchList.cpp b/src/SearchList.cpp
index 32b28e9..342a18f 100644
--- a/src/SearchList.cpp
+++ b/src/SearchList.cpp
@@ -75,7 +75,7 @@ void ParsedSearchExpression(const CSearchExpr* pexpr)
int iOpNot = 0;
for (unsigned int i = 0; i < pexpr->m_aExpr.GetCount(); i++) {
- wxString str(pexpr->m_aExpr[i]);
+ const wxString& str = pexpr->m_aExpr[i];
if (str == SEARCHOPTOK_AND) {
iOpAnd++;
} else if (str == SEARCHOPTOK_OR) {
@@ -108,6 +108,25 @@ void ParsedSearchExpression(const CSearchExpr* pexpr)
// optimize search expression, if no OR nor NOT specified
if (iOpAnd > 0 && iOpOr == 0 && iOpNot == 0) {
+ // figure out if we can use a better keyword than the one the user selected
+ // for example most user will search like this "The oxymoronaccelerator 2", which would ask the node which indexes "the"
+ // This causes higher traffic for such nodes and makes them a viable target to attackers, while the kad result should be
+ // the same or even better if we ask the node which indexes the rare keyword "oxymoronaccelerator", so we try to rearrange
+ // keywords and generally assume that the longer keywords are rarer
+ if (/*thePrefs::GetRearrangeKadSearchKeywords() &&*/ !s_strCurKadKeyword.IsEmpty()) {
+ for (unsigned int i = 0; i < pexpr->m_aExpr.GetCount(); i++) {
+ if (pexpr->m_aExpr[i] != SEARCHOPTOK_AND) {
+ if (pexpr->m_aExpr[i] != s_strCurKadKeyword
+ && pexpr->m_aExpr[i].find_first_of(Kademlia::CSearchManager::GetInvalidKeywordChars()) == wxString::npos
+ && pexpr->m_aExpr[i].Find('"') != 0 // no quoted expressions as keyword
+ && pexpr->m_aExpr[i].length() >= 3
+ && s_strCurKadKeyword.length() < pexpr->m_aExpr[i].length())
+ {
+ s_strCurKadKeyword = pexpr->m_aExpr[i];
+ }
+ }
+ }
+ }
wxString strAndTerms;
for (unsigned int i = 0; i < pexpr->m_aExpr.GetCount(); i++) {
if (pexpr->m_aExpr[i] != SEARCHOPTOK_AND) {
@@ -285,7 +304,7 @@ void CSearchList::RemoveResults(long searchID)
}
-wxString CSearchList::StartNewSearch(uint32* searchID, SearchType type, const CSearchParams& params)
+wxString CSearchList::StartNewSearch(uint32* searchID, SearchType type, CSearchParams& params)
{
// Check that we can actually perform the specified desired search.
if ((type == KadSearch) && !Kademlia::CKademlia::IsRunning()) {
@@ -306,6 +325,16 @@ wxString CSearchList::StartNewSearch(uint32* searchID, SearchType type, const CS
m_resultType.Clear();
}
+ if (type == KadSearch) {
+ Kademlia::WordList words;
+ Kademlia::CSearchManager::GetWords(params.searchString, &words);
+ if (!words.empty()) {
+ params.strKeyword = words.front();
+ } else {
+ return _("No keyword for Kad search - aborting");
+ }
+ }
+
bool supports64bit = type == KadSearch ? true : theApp->serverconnect->GetCurrentServer() != NULL && (theApp->serverconnect->GetCurrentServer()->GetTCPFlags() & SRV_TCPFLG_LARGEFILES);
bool packetUsing64bit;
@@ -332,8 +361,7 @@ wxString CSearchList::StartNewSearch(uint32* searchID, SearchType type, const CS
// searchstring will get tokenized there
// The tab must be created with the Kad search ID, so searchID is updated.
- Kademlia::CSearch* search = Kademlia::CSearchManager::PrepareFindKeywords(
- params.searchString, data->GetLength(), data->GetRawBuffer(), *searchID);
+ Kademlia::CSearch* search = Kademlia::CSearchManager::PrepareFindKeywords(params.strKeyword, data->GetLength(), data->GetRawBuffer(), *searchID);
*searchID = search->GetSearchID();
m_currentSearch = *searchID;
@@ -632,7 +660,7 @@ void CSearchList::StopSearch(bool globalOnly)
}
-CSearchList::CMemFilePtr CSearchList::CreateSearchData(const CSearchParams& params, SearchType WXUNUSED(type), bool supports64bit, bool& packetUsing64bit)
+CSearchList::CMemFilePtr CSearchList::CreateSearchData(CSearchParams& params, SearchType type, bool supports64bit, bool& packetUsing64bit)
{
// Count the number of used parameters
unsigned int parametercount = 0;
@@ -659,14 +687,16 @@ CSearchList::CMemFilePtr CSearchList::CreateSearchData(const CSearchParams& para
_astrParserErrors.Empty();
_SearchExpr.m_aExpr.Empty();
+ s_strCurKadKeyword.Clear();
+ if (type == KadSearch) {
+ wxASSERT( !params.strKeyword.IsEmpty() );
+ s_strCurKadKeyword = params.strKeyword;
+ }
+
LexInit(params.searchString);
int iParseResult = yyparse();
LexFree();
-#ifdef __DEBUG__
- AddLogLineNS(CFormat(wxT("Search parsing result for \"%s\": %i"))
- % params.searchString % iParseResult);
-#endif
if (_astrParserErrors.GetCount() > 0) {
for (unsigned int i=0; i < _astrParserErrors.GetCount(); ++i) {
AddLogLineNS(CFormat(wxT("Error %u: %s\n")) % i % _astrParserErrors[i]);
@@ -681,21 +711,13 @@ CSearchList::CMemFilePtr CSearchList::CreateSearchData(const CSearchParams& para
return CMemFilePtr(NULL);
}
- #ifdef __DEBUG__
- wxString mes(wxT("Search expression:"));
- for (unsigned int i = 0; i < _SearchExpr.m_aExpr.GetCount(); i++) {
- mes << wxT(" ") << _SearchExpr.m_aExpr[i];
+ if (type == KadSearch && s_strCurKadKeyword != params.strKeyword) {
+ AddDebugLogLineN(logSearch, CFormat(wxT("Keyword was rearranged, using '%s' instead of '%s'")) % s_strCurKadKeyword % params.strKeyword);
+ params.strKeyword = s_strCurKadKeyword;
}
- AddLogLineNS(mes);
- AddLogLineNS(CFormat(wxT("Expression count: %i")) % _SearchExpr.m_aExpr.GetCount());
- #endif
parametercount += _SearchExpr.m_aExpr.GetCount();
- #ifdef __DEBUG__
- AddLogLineNS(CFormat(wxT("Parameters: %i")) % parametercount);
- #endif
-
/* Leave the unicode comment there, please... */
CSearchExprTarget target(data.get(), true /*I assume everyone is unicoded */ ? utf8strRaw : utf8strNone, supports64bit, packetUsing64bit);
diff --git a/src/SearchList.h b/src/SearchList.h
index 35b0fc6..6db7508 100644
--- a/src/SearchList.h
+++ b/src/SearchList.h
@@ -64,6 +64,8 @@ class CSearchList : public wxEvtHandler
//! The actual string to search for.
wxString searchString;
+ //! The keyword selected for Kad search
+ wxString strKeyword;
//! The type of files to search for (may be empty), one of ED2KFTSTR_*
wxString typeText;
//! The filename extension. May be empty.
@@ -90,7 +92,7 @@ class CSearchList : public wxEvtHandler
* @param params The search parameters, see CSearchParams.
* @return An empty string on success, otherwise an error-message.
*/
- wxString StartNewSearch(uint32* searchID, SearchType type, const CSearchParams& params);
+ wxString StartNewSearch(uint32* searchID, SearchType type, CSearchParams& params);
/** Stops the current search (global or Kad), if any is in progress. */
void StopSearch(bool globalOnly = false);
@@ -189,7 +191,7 @@ class CSearchList : public wxEvtHandler
typedef std::auto_ptr<CMemFile> CMemFilePtr;
/** Create a basic search-packet for the given search-type. */
- CMemFilePtr CreateSearchData(const CSearchParams& params, SearchType type, bool supports64bit, bool& packetUsing64bit);
+ CMemFilePtr CreateSearchData(CSearchParams& params, SearchType type, bool supports64bit, bool& packetUsing64bit);
//! Timer used for global search intervals.
diff --git a/src/kademlia/kademlia/SearchManager.cpp b/src/kademlia/kademlia/SearchManager.cpp
index e7f25d4..f9ee924 100644
--- a/src/kademlia/kademlia/SearchManager.cpp
+++ b/src/kademlia/kademlia/SearchManager.cpp
@@ -127,7 +127,7 @@ CSearch* CSearchManager::PrepareFindKeywords(const wxString& keyword, uint32_t s
wxString wstrKeyword = s->m_words.front();
- AddLogLineNS(CFormat(_("Keyword for search: %s")) % wstrKeyword);
+ AddDebugLogLineN(logSearch, CFormat(wxT("Keyword for search: %s")) % wstrKeyword);
// Kry - I just decided to assume everyone is unicoded
// GonoszTopi - seconded

View File

@ -1,37 +0,0 @@
#
# Copyright (C) 2010-2011 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=autocore
PKG_VERSION:=1
PKG_RELEASE:=11
include $(INCLUDE_DIR)/package.mk
define Package/autocore
TITLE:=x86/x64 auto core loadbalance script.
MAINTAINER:=Lean
DEPENDS:=@TARGET_x86 +bc +lm-sensors
endef
define Package/autocore/description
A usb autoconfig hotplug script.
endef
define Build/Compile
endef
define Package/autocore/install
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/autocore $(1)/etc/init.d/autocore
$(INSTALL_DIR) $(1)/etc
$(INSTALL_DATA) ./files/index.htm $(1)/etc/index.htm
endef
$(eval $(call BuildPackage,autocore))

View File

@ -1,40 +0,0 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2017 lean <coolsnowwolf@gmail.com>
START=99
start()
{
rfc=4096
cc=$(grep -c processor /proc/cpuinfo)
rsfe=$(echo $cc*$rfc | bc)
sysctl -w net.core.rps_sock_flow_entries=$rsfe
for fileRps in $(ls /sys/class/net/eth*/queues/rx-*/rps_cpus)
do
echo $cc > $fileRps
done
for fileRfc in $(ls /sys/class/net/eth*/queues/rx-*/rps_flow_cnt)
do
echo $rfc > $fileRfc
done
for fileRps in $(ls /sys/class/net/eth*/queues/tx-*/xps_cpus)
do
echo $cc > $fileRps
done
a=$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq)
b=$(echo -n ' : ')
c=$(cat /proc/cpuinfo | grep 'core id' | sort -u | wc -l)
d=$(echo -n ' Core ')
e=$(cat /proc/cpuinfo | grep 'processor' | wc -l)
f=$(echo -n ' Thread ')
g=${a}${b}${c}${d}${e}${f}
echo $g > /tmp/sysinfo/model
[ -f /etc/index.htm ] && mv /etc/index.htm /usr/lib/lua/luci/view/admin_status/index.htm
}

View File

@ -1,828 +0,0 @@
<%#
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008-2011 Jo-Philipp Wich <jow@openwrt.org>
Licensed to the public under the Apache License 2.0.
-%>
<%
local fs = require "nixio.fs"
local util = require "luci.util"
local stat = require "luci.tools.status"
local ver = require "luci.version"
local has_ipv6 = fs.access("/proc/net/ipv6_route")
local has_dhcp = fs.access("/etc/config/dhcp")
local has_wifi = ((fs.stat("/etc/config/wireless", "size") or 0) > 0)
local sysinfo = luci.util.ubus("system", "info") or { }
local boardinfo = luci.util.ubus("system", "board") or { }
local unameinfo = nixio.uname() or { }
local meminfo = sysinfo.memory or {
total = 0,
free = 0,
buffered = 0,
shared = 0
}
local swapinfo = sysinfo.swap or {
total = 0,
free = 0
}
local has_dsl = fs.access("/etc/init.d/dsl_control")
if luci.http.formvalue("status") == "1" then
local ntm = require "luci.model.network".init()
local wan = ntm:get_wannet()
local wan6 = ntm:get_wan6net()
local conn_count = tonumber(
fs.readfile("/proc/sys/net/netfilter/nf_conntrack_count") or "") or 0
local conn_max = tonumber(luci.sys.exec(
"sysctl -n -e net.nf_conntrack_max net.ipv4.netfilter.ip_conntrack_max"
):match("%d+")) or 4096
local rv = {
uptime = sysinfo.uptime or 0,
localtime = os.date(),
loadavg = sysinfo.load or { 0, 0, 0 },
memory = meminfo,
swap = swapinfo,
connmax = conn_max,
conncount = conn_count,
leases = stat.dhcp_leases(),
leases6 = stat.dhcp6_leases(),
wifinets = stat.wifi_networks()
}
if wan then
rv.wan = {
ipaddr = wan:ipaddr(),
gwaddr = wan:gwaddr(),
netmask = wan:netmask(),
dns = wan:dnsaddrs(),
expires = wan:expires(),
uptime = wan:uptime(),
proto = wan:proto(),
ifname = wan:ifname(),
link = wan:adminlink()
}
end
if wan6 then
rv.wan6 = {
ip6addr = wan6:ip6addr(),
gw6addr = wan6:gw6addr(),
dns = wan6:dns6addrs(),
ip6prefix = wan6:ip6prefix(),
uptime = wan6:uptime(),
proto = wan6:proto(),
ifname = wan6:ifname(),
link = wan6:adminlink()
}
end
if has_dsl then
local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat")
local dsl_func = loadstring(dsl_stat)
if dsl_func then
rv.dsl = dsl_func()
end
end
luci.http.prepare_content("application/json")
luci.http.write_json(rv)
return
elseif luci.http.formvalue("hosts") == "1" then
luci.http.prepare_content("application/json")
luci.http.write_json(luci.sys.net.host_hints())
return
end
-%>
<%+header%>
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-18.143.28733-7acacf2"></script>
<script type="text/javascript">//<![CDATA[
function progressbar(v, m)
{
var vn = parseInt(v) || 0;
var mn = parseInt(m) || 100;
var pc = Math.floor((100 / mn) * vn);
return String.format(
'<div style="width:200px; position:relative; border:1px solid #999999">' +
'<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
'<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
'<small>%s / %s (%d%%)</small>' +
'</div>' +
'</div>' +
'</div>', pc, v, m, pc
);
}
function wifirate(bss, rx) {
var p = rx ? 'rx_' : 'tx_',
s = '%.1f <%:Mbit/s%>, %d<%:MHz%>'
.format(bss[p+'rate'] / 1000, bss[p+'mhz']),
ht = bss[p+'ht'], vht = bss[p+'vht'],
mhz = bss[p+'mhz'], nss = bss[p+'nss'],
mcs = bss[p+'mcs'], sgi = bss[p+'short_gi'];
if (ht || vht) {
if (vht) s += ', VHT-MCS %d'.format(mcs);
if (nss) s += ', VHT-NSS %d'.format(nss);
if (ht) s += ', MCS %s'.format(mcs);
if (sgi) s += ', <%:Short GI%>';
}
return s;
}
function duid2mac(duid) {
// DUID-LLT / Ethernet
if (duid.length === 28 && duid.substr(0, 8) === '00010001')
return duid.substr(16).replace(/(..)(?=..)/g, '$1:').toUpperCase();
// DUID-LL / Ethernet
if (duid.length === 20 && duid.substr(0, 8) === '00030001')
return duid.substr(8).replace(/(..)(?=..)/g, '$1:').toUpperCase();
return null;
}
var npoll = 1;
var hosts = <%=luci.http.write_json(luci.sys.net.host_hints())%>;
function updateHosts() {
XHR.get('<%=REQUEST_URI%>', { hosts: 1 }, function(x, data) {
hosts = data;
});
}
XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 },
function(x, info)
{
if (!(npoll++ % 5))
updateHosts();
var si = document.getElementById('wan4_i');
var ss = document.getElementById('wan4_s');
var ifc = info.wan;
if (ifc && ifc.ifname && ifc.proto != 'none')
{
var s = String.format(
'<strong><%:Type%>: </strong>%s<br />' +
'<strong><%:Address%>: </strong>%s<br />' +
'<strong><%:Netmask%>: </strong>%s<br />' +
'<strong><%:Gateway%>: </strong>%s<br />',
ifc.proto,
(ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0',
(ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255',
(ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0'
);
for (var i = 0; i < ifc.dns.length; i++)
{
s += String.format(
'<strong><%:DNS%> %d: </strong>%s<br />',
i + 1, ifc.dns[i]
);
}
if (ifc.expires > -1)
{
s += String.format(
'<strong><%:Expires%>: </strong>%t<br />',
ifc.expires
);
}
if (ifc.uptime > 0)
{
s += String.format(
'<strong><%:Connected%>: </strong>%t<br />',
ifc.uptime
);
}
ss.innerHTML = String.format('<small>%s</small>', s);
si.innerHTML = String.format(
'<img src="<%=resource%>/icons/ethernet.png" />' +
'<br /><small><a href="%s">%s</a></small>',
ifc.link, ifc.ifname
);
}
else
{
si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
ss.innerHTML = '<em><%:Not connected%></em>';
}
<% if has_ipv6 then %>
var si6 = document.getElementById('wan6_i');
var ss6 = document.getElementById('wan6_s');
var ifc6 = info.wan6;
if (ifc6 && ifc6.ifname && ifc6.proto != 'none')
{
var s = String.format(
'<strong><%:Type%>: </strong>%s%s<br />',
ifc6.proto, (ifc6.ip6prefix) ? '-pd' : ''
);
if (!ifc6.ip6prefix)
{
s += String.format(
'<strong><%:Address%>: </strong>%s<br />',
(ifc6.ip6addr) ? ifc6.ip6addr : '::'
);
}
else
{
s += String.format(
'<strong><%:Prefix Delegated%>: </strong>%s<br />',
ifc6.ip6prefix
);
if (ifc6.ip6addr)
{
s += String.format(
'<strong><%:Address%>: </strong>%s<br />',
ifc6.ip6addr
);
}
}
s += String.format(
'<strong><%:Gateway%>: </strong>%s<br />',
(ifc6.gw6addr) ? ifc6.gw6addr : '::'
);
for (var i = 0; i < ifc6.dns.length; i++)
{
s += String.format(
'<strong><%:DNS%> %d: </strong>%s<br />',
i + 1, ifc6.dns[i]
);
}
if (ifc6.uptime > 0)
{
s += String.format(
'<strong><%:Connected%>: </strong>%t<br />',
ifc6.uptime
);
}
ss6.innerHTML = String.format('<small>%s</small>', s);
si6.innerHTML = String.format(
'<img src="<%=resource%>/icons/ethernet.png" />' +
'<br /><small><a href="%s">%s</a></small>',
ifc6.link, ifc6.ifname
);
}
else
{
si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>';
ss6.innerHTML = '<em><%:Not connected%></em>';
}
<% end %>
<% if has_dsl then %>
var dsl_i = document.getElementById('dsl_i');
var dsl_s = document.getElementById('dsl_s');
var s = String.format(
'<strong><%:Status%>: </strong>%s<br />' +
'<strong><%:Line State%>: </strong>%s [0x%x]<br />' +
'<strong><%:Line Mode%>: </strong>%s<br />' +
'<strong><%:Annex%>: </strong>%s<br />' +
'<strong><%:Profile%>: </strong>%s<br />' +
'<strong><%:Data Rate%>: </strong>%s/s / %s/s<br />' +
'<strong><%:Max. Attainable Data Rate (ATTNDR)%>: </strong>%s/s / %s/s<br />' +
'<strong><%:Latency%>: </strong>%s / %s<br />' +
'<strong><%:Line Attenuation (LATN)%>: </strong>%s dB / %s dB<br />' +
'<strong><%:Signal Attenuation (SATN)%>: </strong>%s dB / %s dB<br />' +
'<strong><%:Noise Margin (SNR)%>: </strong>%s dB / %s dB<br />' +
'<strong><%:Aggregate Transmit Power(ACTATP)%>: </strong>%s dB / %s dB<br />' +
'<strong><%:Forward Error Correction Seconds (FECS)%>: </strong>%s / %s<br />' +
'<strong><%:Errored seconds (ES)%>: </strong>%s / %s<br />' +
'<strong><%:Severely Errored Seconds (SES)%>: </strong>%s / %s<br />' +
'<strong><%:Loss of Signal Seconds (LOSS)%>: </strong>%s / %s<br />' +
'<strong><%:Unavailable Seconds (UAS)%>: </strong>%s / %s<br />' +
'<strong><%:Header Error Code Errors (HEC)%>: </strong>%s / %s<br />' +
'<strong><%:Non Pre-emtive CRC errors (CRC_P)%>: </strong>%s / %s<br />' +
'<strong><%:Pre-emtive CRC errors (CRCP_P)%>: </strong>%s / %s<br />' +
'<strong><%:Line Uptime%>: </strong>%s<br />' +
'<strong><%:ATU-C System Vendor ID%>: </strong>%s<br />' +
'<strong><%:Power Management Mode%>: </strong>%s<br />',
info.dsl.line_state, info.dsl.line_state_detail,
info.dsl.line_state_num,
info.dsl.line_mode_s,
info.dsl.annex_s,
info.dsl.profile_s,
info.dsl.data_rate_down_s, info.dsl.data_rate_up_s,
info.dsl.max_data_rate_down_s, info.dsl.max_data_rate_up_s,
info.dsl.latency_num_down, info.dsl.latency_num_up,
info.dsl.line_attenuation_down, info.dsl.line_attenuation_up,
info.dsl.signal_attenuation_down, info.dsl.signal_attenuation_up,
info.dsl.noise_margin_down, info.dsl.noise_margin_up,
info.dsl.actatp_down, info.dsl.actatp_up,
info.dsl.errors_fec_near, info.dsl.errors_fec_far,
info.dsl.errors_es_near, info.dsl.errors_es_far,
info.dsl.errors_ses_near, info.dsl.errors_ses_far,
info.dsl.errors_loss_near, info.dsl.errors_loss_far,
info.dsl.errors_uas_near, info.dsl.errors_uas_far,
info.dsl.errors_hec_near, info.dsl.errors_hec_far,
info.dsl.errors_crc_p_near, info.dsl.errors_crc_p_far,
info.dsl.errors_crcp_p_near, info.dsl.errors_crcp_p_far,
info.dsl.line_uptime_s,
info.dsl.atuc_vendor_id,
info.dsl.power_mode_s
);
dsl_s.innerHTML = String.format('<small>%s</small>', s);
dsl_i.innerHTML = String.format(
'<img src="<%=resource%>/icons/ethernet.png" />' +
'<br /><small>DSL</small>'
);
<% end %>
<% if has_dhcp then %>
var ls = document.getElementById('lease_status_table');
if (ls)
{
/* clear all rows */
while( ls.rows.length > 1 )
ls.rows[0].parentNode.deleteRow(1);
for( var i = 0; i < info.leases.length; i++ )
{
var timestr;
if (info.leases[i].expires === false)
timestr = '<em><%:unlimited%></em>';
else if (info.leases[i].expires <= 0)
timestr = '<em><%:expired%></em>';
else
timestr = String.format('%t', info.leases[i].expires);
var tr = ls.rows[0].parentNode.insertRow(-1);
tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
tr.insertCell(-1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?';
tr.insertCell(-1).innerHTML = info.leases[i].ipaddr;
tr.insertCell(-1).innerHTML = info.leases[i].macaddr;
tr.insertCell(-1).innerHTML = timestr;
}
if( ls.rows.length == 1 )
{
var tr = ls.rows[0].parentNode.insertRow(-1);
tr.className = 'cbi-section-table-row';
var td = tr.insertCell(-1);
td.colSpan = 4;
td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
}
}
var ls6 = document.getElementById('lease6_status_table');
if (ls6 && info.leases6)
{
ls6.parentNode.style.display = 'block';
/* clear all rows */
while( ls6.rows.length > 1 )
ls6.rows[0].parentNode.deleteRow(1);
for( var i = 0; i < info.leases6.length; i++ )
{
var timestr;
if (info.leases6[i].expires === false)
timestr = '<em><%:unlimited%></em>';
else if (info.leases6[i].expires <= 0)
timestr = '<em><%:expired%></em>';
else
timestr = String.format('%t', info.leases6[i].expires);
var tr = ls6.rows[0].parentNode.insertRow(-1);
tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
var host = hosts[duid2mac(info.leases6[i].duid)];
if (!info.leases6[i].hostname)
tr.insertCell(-1).innerHTML =
(host && (host.name || host.ipv4 || host.ipv6))
? '<div style="max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space: nowrap">? (%h)</div>'.format(host.name || host.ipv4 || host.ipv6)
: '?';
else
tr.insertCell(-1).innerHTML =
(host && host.name && info.leases6[i].hostname != host.name)
? '<div style="max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space: nowrap">%h (%h)</div>'.format(info.leases6[i].hostname, host.name)
: info.leases6[i].hostname;
tr.insertCell(-1).innerHTML = info.leases6[i].ip6addr;
tr.insertCell(-1).innerHTML = info.leases6[i].duid;
tr.insertCell(-1).innerHTML = timestr;
}
if( ls6.rows.length == 1 )
{
var tr = ls6.rows[0].parentNode.insertRow(-1);
tr.className = 'cbi-section-table-row';
var td = tr.insertCell(-1);
td.colSpan = 4;
td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
}
}
<% end %>
<% if has_wifi then %>
var assoclist = [ ];
var ws = document.getElementById('wifi_status_table');
if (ws)
{
var wsbody = ws.rows[0].parentNode;
while (ws.rows.length > 0)
wsbody.deleteRow(0);
for (var didx = 0; didx < info.wifinets.length; didx++)
{
var dev = info.wifinets[didx];
var tr = wsbody.insertRow(-1);
var td;
td = tr.insertCell(-1);
td.width = "33%";
td.innerHTML = dev.name;
td.style.verticalAlign = "top";
td = tr.insertCell(-1);
var s = '';
for (var nidx = 0; nidx < dev.networks.length; nidx++)
{
var net = dev.networks[nidx];
var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel && !net.disabled);
var icon;
if (!is_assoc)
icon = "<%=resource%>/icons/signal-none.png";
else if (net.quality == 0)
icon = "<%=resource%>/icons/signal-0.png";
else if (net.quality < 25)
icon = "<%=resource%>/icons/signal-0-25.png";
else if (net.quality < 50)
icon = "<%=resource%>/icons/signal-25-50.png";
else if (net.quality < 75)
icon = "<%=resource%>/icons/signal-50-75.png";
else
icon = "<%=resource%>/icons/signal-75-100.png";
s += String.format(
'<table><tr><td style="text-align:center; width:32px; padding:3px">' +
'<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
'<br /><small>%d%%</small>' +
'</td><td style="text-align:left; padding:3px"><small>' +
'<strong><%:SSID%>:</strong> <a href="%s">%h</a><br />' +
'<strong><%:Mode%>:</strong> %s<br />' +
'<strong><%:Channel%>:</strong> %d (%.3f <%:GHz%>)<br />' +
'<strong><%:Bitrate%>:</strong> %s <%:Mbit/s%><br />',
icon, net.signal, net.noise,
net.quality,
net.link, net.ssid || '?',
net.mode,
net.channel, net.frequency,
net.bitrate || '?'
);
if (is_assoc)
{
s += String.format(
'<strong><%:BSSID%>:</strong> %s<br />' +
'<strong><%:Encryption%>:</strong> %s',
net.bssid || '?',
net.encryption
);
}
else
{
s += '<em><%:Wireless is disabled or not associated%></em>';
}
s += '</small></td></tr></table>';
for (var bssid in net.assoclist)
{
var bss = net.assoclist[bssid];
bss.bssid = bssid;
bss.link = net.link;
bss.name = net.name;
bss.ifname = net.ifname;
bss.radio = dev.name;
assoclist.push(bss);
}
}
if (!s)
s = '<em><%:No information available%></em>';
td.innerHTML = s;
}
}
var ac = document.getElementById('wifi_assoc_table');
if (ac)
{
/* clear all rows */
while( ac.rows.length > 1 )
ac.rows[0].parentNode.deleteRow(1);
assoclist.sort(function(a, b) {
return (a.name == b.name)
? (a.bssid < b.bssid)
: (a.name > b.name )
;
});
for( var i = 0; i < assoclist.length; i++ )
{
var tr = ac.rows[0].parentNode.insertRow(-1);
tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2));
var icon;
var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5;
if (q < 1)
icon = "<%=resource%>/icons/signal-0.png";
else if (q < 2)
icon = "<%=resource%>/icons/signal-0-25.png";
else if (q < 3)
icon = "<%=resource%>/icons/signal-25-50.png";
else if (q < 4)
icon = "<%=resource%>/icons/signal-50-75.png";
else
icon = "<%=resource%>/icons/signal-75-100.png";
tr.insertCell(-1).innerHTML = String.format(
'<span class="ifacebadge" title="%q"><img src="<%=resource%>/icons/wifi.png" /> %h</span>',
assoclist[i].radio, assoclist[i].ifname
);
tr.insertCell(-1).innerHTML = String.format(
'<a href="%s">%s</a>',
assoclist[i].link,
'%h'.format(assoclist[i].name).nobr()
);
tr.insertCell(-1).innerHTML = assoclist[i].bssid;
var host = hosts[assoclist[i].bssid];
if (host)
tr.insertCell(-1).innerHTML = String.format(
'<div style="max-width:200px;overflow:hidden;text-overflow:ellipsis">%s</div>',
((host.name && (host.ipv4 || host.ipv6))
? '%h (%s)'.format(host.name, host.ipv4 || host.ipv6)
: '%h'.format(host.name || host.ipv4 || host.ipv6)).nobr()
);
else
tr.insertCell(-1).innerHTML = '?';
tr.insertCell(-1).innerHTML = String.format(
'<span class="ifacebadge" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%> / <%:SNR%>: %d"><img src="%s" /> %d / %d <%:dBm%></span>',
assoclist[i].signal, assoclist[i].noise, assoclist[i].signal - assoclist[i].noise,
icon,
assoclist[i].signal, assoclist[i].noise
);
tr.insertCell(-1).innerHTML = wifirate(assoclist[i], true).nobr() + '<br />' + wifirate(assoclist[i], false).nobr();
}
if (ac.rows.length == 1)
{
var tr = ac.rows[0].parentNode.insertRow(-1);
tr.className = 'cbi-section-table-row';
var td = tr.insertCell(-1);
td.colSpan = 7;
td.innerHTML = '<br /><em><%:No information available%></em>';
}
}
<% end %>
var e;
if (e = document.getElementById('localtime'))
e.innerHTML = info.localtime;
if (e = document.getElementById('uptime'))
e.innerHTML = String.format('%t', info.uptime);
if (e = document.getElementById('loadavg'))
e.innerHTML = String.format(
'%.02f, %.02f, %.02f',
info.loadavg[0] / 65535.0,
info.loadavg[1] / 65535.0,
info.loadavg[2] / 65535.0
);
if (e = document.getElementById('memtotal'))
e.innerHTML = progressbar(
((info.memory.free + info.memory.buffered) / 1024) + " <%:kB%>",
(info.memory.total / 1024) + " <%:kB%>"
);
if (e = document.getElementById('memfree'))
e.innerHTML = progressbar(
(info.memory.free / 1024) + " <%:kB%>",
(info.memory.total / 1024) + " <%:kB%>"
);
if (e = document.getElementById('membuff'))
e.innerHTML = progressbar(
(info.memory.buffered / 1024) + " <%:kB%>",
(info.memory.total / 1024) + " <%:kB%>"
);
if (e = document.getElementById('swaptotal'))
e.innerHTML = progressbar(
(info.swap.free / 1024) + " <%:kB%>",
(info.swap.total / 1024) + " <%:kB%>"
);
if (e = document.getElementById('swapfree'))
e.innerHTML = progressbar(
(info.swap.free / 1024) + " <%:kB%>",
(info.swap.total / 1024) + " <%:kB%>"
);
if (e = document.getElementById('conns'))
e.innerHTML = progressbar(info.conncount, info.connmax);
}
);
//]]></script>
<h2 name="content"><%:Status%></h2>
<fieldset class="cbi-section">
<legend><%:System%></legend>
<table width="100%" cellspacing="10">
<tr><td width="33%"><%:Hostname%></td><td><%=luci.sys.hostname() or "?"%></td></tr>
<tr><td width="33%"><%:Model%></td><td><%=pcdata(boardinfo.model or boardinfo.system or "?")%></td></tr>
<tr><td width="33%"><%:CPU Temperature%></td><td><%=luci.sys.exec("sensors | grep 'Core 0' | cut -c10-24")%> @ <%=luci.sys.exec("grep 'MHz' /proc/cpuinfo | cut -c11- |sed -n '1p'")%> MHz</td></tr>
<tr><td width="33%"><%:Firmware Version%></td><td>
<%=pcdata(ver.distname)%> <%=pcdata(ver.distversion)%> /
<%=pcdata(ver.luciname)%> (<%=pcdata(ver.luciversion)%>)
</td></tr>
<tr><td width="33%"><%:Kernel Version%></td><td><%=unameinfo.release or "?"%></td></tr>
<tr><td width="33%"><%:Local Time%></td><td id="localtime">-</td></tr>
<tr><td width="33%"><%:Uptime%></td><td id="uptime">-</td></tr>
<tr><td width="33%"><%:Load Average%></td><td id="loadavg">-</td></tr>
</table>
</fieldset>
<fieldset class="cbi-section">
<legend><%:Memory%></legend>
<table width="100%" cellspacing="10">
<tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr>
<tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr>
<tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr>
</table>
</fieldset>
<% if swapinfo.total > 0 then %>
<fieldset class="cbi-section">
<legend><%:Swap%></legend>
<table width="100%" cellspacing="10">
<tr><td width="33%"><%:Total Available%></td><td id="swaptotal">-</td></tr>
<tr><td width="33%"><%:Free%></td><td id="swapfree">-</td></tr>
</table>
</fieldset>
<% end %>
<fieldset class="cbi-section">
<legend><%:Network%></legend>
<table width="100%" cellspacing="10">
<tr><td width="33%" style="vertical-align:top"><%:IPv4 WAN Status%></td><td>
<table><tr>
<td id="wan4_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
<td id="wan4_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
</tr></table>
</td></tr>
<% if has_ipv6 then %>
<tr><td width="33%" style="vertical-align:top"><%:IPv6 WAN Status%></td><td>
<table><tr>
<td id="wan6_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
<td id="wan6_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
</tr></table>
</td></tr>
<% end %>
<tr><td width="33%"><%:Active Connections%></td><td id="conns">-</td></tr>
</table>
</fieldset>
<% if has_dhcp then %>
<fieldset class="cbi-section">
<legend><%:DHCP Leases%></legend>
<table class="cbi-section-table" id="lease_status_table">
<tr class="cbi-section-table-titles">
<th class="cbi-section-table-cell"><%:Hostname%></th>
<th class="cbi-section-table-cell"><%:IPv4-Address%></th>
<th class="cbi-section-table-cell"><%:MAC-Address%></th>
<th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
</tr>
<tr class="cbi-section-table-row">
<td colspan="4"><em><br /><%:Collecting data...%></em></td>
</tr>
</table>
</fieldset>
<fieldset class="cbi-section" style="display:none">
<legend><%:DHCPv6 Leases%></legend>
<table class="cbi-section-table" id="lease6_status_table">
<tr class="cbi-section-table-titles">
<th class="cbi-section-table-cell"><%:Host%></th>
<th class="cbi-section-table-cell"><%:IPv6-Address%></th>
<th class="cbi-section-table-cell"><%:DUID%></th>
<th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
</tr>
<tr class="cbi-section-table-row">
<td colspan="4"><em><br /><%:Collecting data...%></em></td>
</tr>
</table>
</fieldset>
<% end %>
<% if has_dsl then %>
<fieldset class="cbi-section">
<legend><%:DSL%></legend>
<table width="100%" cellspacing="10">
<tr><td width="33%" style="vertical-align:top"><%:DSL Status%></td><td>
<table><tr>
<td id="dsl_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td>
<td id="dsl_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td>
</tr></table>
</td></tr>
</table>
</fieldset>
<% end %>
<% if has_wifi then %>
<fieldset class="cbi-section">
<legend><%:Wireless%></legend>
<table id="wifi_status_table" width="100%" cellspacing="10">
<tr><td><em><%:Collecting data...%></em></td></tr>
</table>
</fieldset>
<fieldset class="cbi-section">
<legend><%:Associated Stations%></legend>
<table class="cbi-section-table valign-middle" id="wifi_assoc_table">
<tr class="cbi-section-table-titles">
<th class="cbi-section-table-cell">&#160;</th>
<th class="cbi-section-table-cell"><%:Network%></th>
<th class="cbi-section-table-cell"><%:MAC-Address%></th>
<th class="cbi-section-table-cell"><%:Host%></th>
<th class="cbi-section-table-cell"><%:Signal%> / <%:Noise%></th>
<th class="cbi-section-table-cell"><%:RX Rate%> / <%:TX Rate%></th>
</tr>
<tr class="cbi-section-table-row">
<td colspan="6"><em><br /><%:Collecting data...%></em></td>
</tr>
</table>
</fieldset>
<% end %>
<%-
local incdir = util.libpath() .. "/view/admin_status/index/"
if fs.access(incdir) then
local inc
for inc in fs.dir(incdir) do
if inc:match("%.htm$") then
include("admin_status/index/" .. inc:gsub("%.htm$", ""))
end
end
end
-%>
<%+footer%>

View File

@ -1,36 +0,0 @@
#
# Copyright (C) 2010-2011 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=automount
PKG_VERSION:=1
PKG_RELEASE:=19
PKG_ARCH:=all
include $(INCLUDE_DIR)/package.mk
define Package/automount
TITLE:=Mount autoconfig hotplug script.
MAINTAINER:=Lean
DEPENDS:=block-mount +kmod-usb-storage +kmod-usb-storage-extras
endef
define Package/automount/description
A usb autoconfig hotplug script.
endef
define Build/Compile
endef
define Package/automount/install
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/15-automount $(1)/etc/15-automount
$(INSTALL_BIN) ./files/zzz-move-automount $(1)/etc/uci-defaults/zzz-move-automount
endef
$(eval $(call BuildPackage,automount))

View File

@ -1,27 +0,0 @@
#!/bin/sh
# Copyright (C) 2015 OpenWrt.org
# 0 yes blockdevice handles this - 1 no it is not there
blkdev=`dirname $DEVPATH`
basename=`basename $blkdev`
device=`basename $DEVPATH`
skip=`block info | sed 's/\(.*\): .*/\1/' | grep -q $device ; echo $?`
path=$DEVPATH
if [ $basename != "block" ] && [ -z "${device##sd*}" ] && [ $skip -eq 1 ]; then
mntpnt=$device
case "$ACTION" in
add)
mkdir -p /mnt/$mntpnt
chmod 777 /mnt/$mntpnt
# Try to be gentle on solid state devices
mount -o rw,noatime,discard /dev/$device /mnt/$mntpnt
;;
remove)
# Once the device is removed, the /dev entry disappear. We need mountpoint
mountpoint=`mount |grep /dev/$device | sed 's/.* on \(.*\) type.*/\1/'`
umount -l $mountpoint
;;
esac
fi

View File

@ -1,7 +0,0 @@
#!/bin/sh
sleep 15
mv /etc/15-automount /etc/hotplug.d/block/

View File

@ -1,35 +0,0 @@
#
# Copyright (C) 2010-2011 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=autosamba
PKG_VERSION:=1
PKG_RELEASE:=9
PKG_ARCH:=all
include $(INCLUDE_DIR)/package.mk
define Package/autosamba
TITLE:=Samba autoconfig hotplug script.
MAINTAINER:=Lean
DEPENDS:=+luci-app-samba +kmod-fs-vfat +ntfs-3g +kmod-fs-ext4
endef
define Package/autosamba/description
A hotplug script to config Samba share automatically.
endef
define Build/Compile
endef
define Package/autosamba/install
$(INSTALL_DIR) $(1)/etc/hotplug.d/block
$(INSTALL_BIN) ./files/20-smb $(1)/etc/hotplug.d/block/20-smb
endef
$(eval $(call BuildPackage,autosamba))

View File

@ -1,105 +0,0 @@
#!/bin/sh
#
# D-Team Technology Co.,Ltd. ShenZhen
# 作者:Vic
#
#
# 警告:对着屏幕的哥们,我们允许你使用此脚本,但不允许你抹去作者的信息,请保留这段话。
#
. /lib/functions.sh
. /lib/functions/service.sh
global=0
config_file="/etc/config/samba"
wait_for_init() {
for i in `seq 30`
do
[ -e /tmp/procd.done ] || {
sleep 1; continue;
}
return
done
}
smb_handle() {
config_get path $1 path
if [ "$path" = "$2" ] ;then
global=1
fi
}
chk_en() {
config_get_bool autoshare $1 autoshare 1
[ $autoshare -eq 0 ] && exit
}
config_load samba
config_foreach chk_en samba
device=`basename $DEVPATH`
case "$ACTION" in
add)
case "$device" in
sd*) ;;
md*) ;;
hd*);;
mmcblk*);;
*) return;;
esac
path="/dev/$device"
wait_for_init
cat /proc/mounts | while read j
do
str=${j%% *}
if [ "$str" == $path ];then
strr=${j#* }
target=${strr%% *}
global=0
config_foreach smb_handle sambashare $target
name=${target#*/mnt/}
if [ $global -eq 0 ] ;then
echo -e "\n\nconfig sambashare" >> $config_file
echo -e "\toption auto '1'" >> $config_file
echo -e "\toption name '$name'" >> $config_file
echo -e "\toption path '$target'" >> $config_file
echo -e "\toption read_only 'no'" >> $config_file
echo -e "\toption guest_ok 'yes'" >> $config_file
echo -e "\toption create_mask '0666'" >> $config_file
echo -e "\toption dir_mask '0777'" >> $config_file
echo -e "\toption device '$device'" >> $config_file
/etc/init.d/samba reload
return
fi
fi
done
;;
remove)
i=0
while true
do
dev=`uci get samba.@sambashare[$i].device`
[ $? -ne 0 ] && break
[ "$dev" = "$device" ] && {
auto=`uci get samba.@sambashare[$i].auto`
[ $auto = "1" ] && {
mount_dir=`uci get samba.@sambashare[$i].name`
rm -rf /mnt/$device /mnt/$mount_dir
uci delete samba.@sambashare[$i]
uci commit
/etc/init.d/samba reload
return
}
}
let i+=1
done
;;
esac

View File

@ -1,59 +0,0 @@
#
# Copyright (C) 2015-2016 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v3.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=brook
PKG_VERSION:=1.0
PKG_RELEASE:=20180227
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
SECTION:=net
CATEGORY:=Network
TITLE:=Brook is a cross-platform proxy software
DEPENDS:=
URL:=https://github.com/txthinking/brook
endef
define Package/$(PKG_NAME)/description
Brook is a cross-platform proxy software
endef
define Build/Prepare
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/bin
ifeq ($(ARCH),mipsel)
$(INSTALL_BIN) ./files/7620n/brook $(1)/usr/bin/
endif
ifeq ($(ARCH),mips)
$(INSTALL_BIN) ./files/ar71xx/brook $(1)/usr/bin/
endif
ifeq ($(ARCH),i386)
$(INSTALL_BIN) ./files/x86/brook $(1)/usr/bin/
endif
ifeq ($(ARCH),x86_64)
$(INSTALL_BIN) ./files/x86_64/brook $(1)/usr/bin/
endif
ifeq ($(ARCH),arm)
$(INSTALL_BIN) ./files/arm/brook $(1)/usr/bin/
endif
ifeq ($(ARCH),aarch64)
$(INSTALL_BIN) ./files/armv7/brook $(1)/usr/bin/
endif
endef
$(eval $(call BuildPackage,$(PKG_NAME)))

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,51 +0,0 @@
# Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=coremark
PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/eembc/coremark.git
PKG_SOURCE_VERSION:=509d8ef94ca17e527fd085c53f2a14a165a3650a
PKG_SOURCE_DATE:=2018-05-31
include $(INCLUDE_DIR)/package.mk
define Package/coremark
SECTION:=utils
CATEGORY:=Utilities
TITLE:=CoreMark Embedded Microprocessor Benchmark
URL:=https://github.com/eembc/coremark
endef
define Package/coremark/description
Embedded Microprocessor Benchmark
endef
define Build/Compile
$(SED) 's|EXE = .exe|EXE =|' $(PKG_BUILD_DIR)/linux/core_portme.mak
mkdir $(PKG_BUILD_DIR)/$(ARCH)
cp -r $(PKG_BUILD_DIR)/linux/* $(PKG_BUILD_DIR)/$(ARCH)
$(MAKE) -C $(PKG_BUILD_DIR) PORT_DIR=$(ARCH) $(MAKE_FLAGS) \
compile
endef
define Package/coremark/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/coremark $(1)/bin/
endef
$(eval $(call BuildPackage,coremark))

View File

@ -1,34 +0,0 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=dclient
PKG_VERSION=1.1
PKG_RELEASE:=170919
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
SECTION:=utils
CATEGORY:=Utilities
TITLE:=dclient -- Zte 802.1X Auth Client
DEPENDS:=+libpthread +libstdcpp +libpcap +libcurl +libjpeg
MAINTAINER:=www.zeyes.org
endef
define Package/$(PKG_NAME)/description
ZTE 802.1X Auth Client For CCDGUT.
endef
define Build/Prepare
echo "Here is Package/Prepare"
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Package/$(PKG_NAME)/install
echo "Here is Package/install"
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/bin/
endef
$(eval $(call BuildPackage,dclient))

View File

@ -1,20 +0,0 @@
20170322
优化了日志提示。
修复了ip未获取成功不工作的问题。
20170510:
优化了断线重连。
20170602:
1. 对数据帧加入CRC32校验不足64Byte的包补足64B(防止交换机丢弃)
2. 更改心跳检测网址
20170903:
处理外网登录多次重试不成功不会再试的问题
20170912:
添加自定义认证心跳的超时时间
修复了在某些情况下不能成功获取ip时程序异常退出的问题
20170914:
天翼登录页改版,重新适配了天翼自动登录模块
20170916:
修复了认证服务器通知乱码问题

View File

@ -1,76 +0,0 @@
# DClient Makefile
//CC := gcc
//CXX := g++
CFLAGS += -std=c99
CXXFLAGS += -w -std=c++11
LIBS += -lpthread -lpcap -lcurl -ljpeg
DIR_ENCRYPT = ./encrypt
DIR_CONV = ./conv
OBJECTS = main.o tprocess.o adapter.o dpcap.o msgpass.o eappacket.o \
dcurl.o docr.o dir.o docrkeys.o encrypt.o dlog.o daemon.o\
lock.o darg.o $(DIR_ENCRYPT)/md5.o $(DIR_ENCRYPT)/rc4.o $(DIR_ENCRYPT)/crc32.o\
$(DIR_ENCRYPT)/base64.o $(DIR_CONV)/conv.o
dclient : $(OBJECTS)
$(CXX) $(LDFLAGS) -o dclient $(OBJECTS) $(LIBS)
main.o : main.cpp
$(CXX) $(CXXFLAGS) -c $<
tprocess.o : tprocess.cpp tprocess.h
$(CXX) $(CXXFLAGS) -c $<
adapter.o : adapter.cpp adapter.h
$(CXX) $(CXXFLAGS) -c $<
dpcap.o : dpcap.cpp dpcap.h
$(CXX) $(CXXFLAGS) -c $<
msgpass.o : msgpass.cpp msgpass.h
$(CXX) $(CXXFLAGS) -c $<
eappacket.o : eappacket.cpp eappacket.h
$(CXX) $(CXXFLAGS) -c $<
dcurl.o : dcurl.cpp dcurl.h
$(CXX) $(CXXFLAGS) -c $<
docr.o : docr.cpp docr.h
$(CXX) $(CXXFLAGS) -c $<
dir.o : dir.cpp dir.h
$(CXX) $(CXXFLAGS) -c $<
docrkeys.o : docrkeys.cpp
$(CXX) $(CXXFLAGS) -c $<
encrypt.o : encrypt.cpp encrypt.h
$(CXX) $(CXXFLAGS) -c $<
dlog.o : dlog.cpp dlog.h
$(CXX) $(CXXFLAGS) -c $<
lock.o : lock.cpp lock.h
$(CXX) $(CXXFLAGS) -c $<
darg.o : darg.cpp darg.h
$(CXX) $(CXXFLAGS) -c $<
daemon.o : daemon.cpp daemon.h
$(CXX) $(CXXFLAGS) -c $<
$(DIR_ENCRYPT)/%.o : $(DIR_ENCRYPT)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(DIR_CONV)/%.o : $(DIR_CONV)/%.c
$(CC) $(CFLAGS) -c $< -o $@
.PHONY : clean
clean :
-rm ./*.o ./$(DIR_ENCRYPT)/*.o ./$(DIR_CONV)/*.o dclient

View File

@ -1,280 +0,0 @@
#include "adapter.h"
#include <unistd.h>
bool GetMacAddress(const char* adapterName, unsigned char* mac)
{
#ifndef WIN32
struct ifreq ifreq;
int sock;
if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
return false;
strcpy(ifreq.ifr_name, adapterName);
if(ioctl(sock, SIOCGIFHWADDR, &ifreq) < 0)
return false;
memcpy((void *)mac, (void *)(ifreq.ifr_hwaddr.sa_data), 6);
return true;
#else
PIP_ADAPTER_INFO AdapterInfo = NULL;
DWORD dwBufLen = sizeof(IP_ADAPTER_INFO);
DWORD dwStatus;
AdapterInfo = (PIP_ADAPTER_INFO)malloc(dwBufLen);
if (AdapterInfo == NULL) return false;
dwStatus = GetAdaptersInfo(AdapterInfo, &dwBufLen);
if (dwStatus == ERROR_BUFFER_OVERFLOW)
{
free(AdapterInfo);
AdapterInfo = (PIP_ADAPTER_INFO)malloc(dwBufLen);
dwStatus = GetAdaptersInfo(AdapterInfo, &dwBufLen);
if (AdapterInfo == NULL) return -1;
}
if (dwStatus != NO_ERROR)
{
if (AdapterInfo != NULL) free(AdapterInfo);
return false;
}
//if (ip) memset(ip, 0, 16);
if (mac) memset((char*)mac, 0, 6);
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
if (adapterName != NULL)
{
while (pAdapterInfo)
{
//printf("%s\n", pAdapterInfo->AdapterName);
//PrintMACaddress(pAdapterInfo->Address);
if (strcmp(adapterName, pAdapterInfo->AdapterName) == 0 || !adapterName)
{
if (mac) memcpy((char*)mac, pAdapterInfo->Address, 6);
//if (ip) strncpy(ip, pAdapterInfo->IpAddressList.IpAddress.String, 16);
break;
}
pAdapterInfo = pAdapterInfo->Next;
}
}
free(AdapterInfo);
if (pAdapterInfo == NULL) return -3;
return true;
#endif
}
bool GetAdapterName(pcap_if_t *device, char* adapterName)
{
#ifndef WIN32
char* name = device->name;
#else
char* name = device->name + 12;
#endif
strncpy(adapterName, name, 100);
return true;
}
bool GetIp(const char * adapterName, unsigned char * ip)
{
pcap_if_t *alldevs;
pcap_if_t *d;
pcap_addr_t *a;
char name[100];
u_char *p = NULL;
char errbuf[PCAP_ERRBUF_SIZE];
AdapterNameToPcap(adapterName, name);
// 获取本机设备列表
if (pcap_findalldevs(&alldevs, errbuf) == -1)
return false;
for(d=alldevs; d; d=d->next)
if(!strcmp(d->name, name)) break;
if(!d) return false;
for(a = d->addresses; a; a = a->next)
{
if(a->addr->sa_family == AF_INET)
{
if (a->addr)
{
p = (u_char *)&(((struct sockaddr_in *)a->addr)->sin_addr.s_addr);
break;
}
}
}
if(p)
{
sprintf((char *)ip, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
return true;
}
else
return false;
}
bool AdapterNameToPcap(const char * adapterName, char * pcapAdapterName)
{
pcapAdapterName[0] = '\0';
#ifdef WIN32
const char *pre = "\\Device\\NPF_";
strncpy(pcapAdapterName, pre, 14);
#endif // WIN32
strncat(pcapAdapterName, adapterName, 100);
return true;
}
int GetAdapter(char ** adapterName)
{
static char name[100];
pcap_if_t *alldevs;
pcap_if_t *d;
char errbuf[PCAP_ERRBUF_SIZE];
int i = 0, inum, t;
// 获取本机设备列表
if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
fprintf(stderr,"Error: pcap_findalldevs - %s\n", errbuf);
exit(1);
}
// 打印列表
for(d=alldevs; d; d=d->next)
{
printf("%d. %s", ++i, d->name);
if (d->description)
printf(" (%s)\n", d->description);
else
printf(" (No description available)\n");
}
if(i==0)
{
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
return -1;
}
printf("Enter the interface number (1-%d):",i);
t = scanf("%d", &inum);
if(t) { }
if(inum < 1 || inum > i)
{
printf("\nInterface number out of range.\n");
pcap_freealldevs(alldevs);
return -1;
}
// 跳转到选中的适配器
for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
GetAdapterName(d, name);
*adapterName = name;
pcap_freealldevs(alldevs);
return 0;
}
bool DhcpClient(const char *adapterName, int style, const char *dhcpScript)
{
pid_t fpid;
char * const dhclientArgv[] = {(char *)"dhclient", (char *)adapterName, 0};
char * const udhcpcArgv[] = {(char *)"udhcpc", (char *)"-p /tmp/dclient_dhcp.pid",(char *)"-n", (char *)"-i",
(char *)adapterName, (char *)"-t1", (char *)"-R", 0}; // dhcpScript暂时用不到
fpid = fork(); // 执行udhcpc会使进程退出因此fork来执行
if(fpid > 0) // 父进程返回
return true;
else if(fpid == 0)
{
// 子进程dhcp
if(style == 1)
execvp("dhclient", dhclientArgv);
else if(style == 2)
execvp("udhcpc", udhcpcArgv);
}
return true;
}
/*
// C prototype : void StrToHex(unsigned char *pbDest, unsigned char *pbSrc, int nLen)
// parameter(s): [OUT] pbDest - 输出缓冲区
// [IN] pbSrc - 字符串
// [IN] nLen - 16进制数的字节数(字符串的长度/2)
// return value:
// remarks : 将字符串转化为16进制数
*/
void StrToHex(unsigned char *pbDest, unsigned char *pbSrc, int nLen)
{
char h1,h2;
unsigned char s1,s2;
int i;
for (i=0; i<nLen; i++)
{
h1 = pbSrc[2*i];
h2 = pbSrc[2*i+1];
s1 = toupper(h1) - 0x30;
if (s1 > 9)
s1 -= 7;
s2 = toupper(h2) - 0x30;
if (s2 > 9)
s2 -= 7;
pbDest[i] = s1*16 + s2;
}
}
/*
// C prototype : void HexToStr(unsigned char *pbDest, unsigned char *pbSrc, int nLen)
// parameter(s): [OUT] pbDest - 存放目标字符串
// [IN] pbSrc - 输入16进制数的起始地址
// [IN] nLen - 16进制数的字节数
// return value:
// remarks : 将16进制数转化为字符串
*/
void HexToStr(unsigned char *pbDest, unsigned char *pbSrc, int nLen)
{
char ddl,ddh;
int i;
for (i=0; i<nLen; i++)
{
ddh = 48 + pbSrc[i] / 16;
ddl = 48 + pbSrc[i] % 16;
if (ddh > 57) ddh = ddh + 7;
if (ddl > 57) ddl = ddl + 7;
pbDest[i*2] = ddh;
pbDest[i*2+1] = ddl;
}
pbDest[nLen*2] = '\0';
}
void MD5Print(unsigned char * digest)
{
for (int i = 0; i < 16; i++)
printf("%02X", digest[i]);
printf("\n");
}
void PrintHex(unsigned char * data, int len)
{
int i = 0;
printf("\nlen : %d\n", len);
for (i = 0; i < len; i++)
{
printf("%02X ", data[i]);
if(i % 8 == 7) printf(" ");
if(i % 16 == 15) printf("\n");
}
printf("\n");
}
void PrintMACAddress(unsigned char MACData[])
{
printf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}

View File

@ -1,104 +0,0 @@
#ifndef ADAPTER_H_
#define ADAPTER_H_
#include <cstdint>
#include "global.h"
// 获取正确的设备名
bool GetAdapterName(pcap_if_t *device, char*adapterName);
// 通过设备名获取Mac地址mac变量应事先分配6unsigned chars以上
bool GetMacAddress(const char* adapterName, unsigned char* mac);
// 通过网卡名获取ipip变量应事先分配17unsigned chars以上
bool GetIp(const char * adapterName, unsigned char * ip);
// 装换成pcap识别的设备名
bool AdapterNameToPcap(const char * adapterName, char * pcapAdapterName);
int GetAdapter(char ** adapterName);
// style为0时不做任何工作为1时使用dhclient, 为2时使用udhcpc
bool DhcpClient(const char *adapterName, int style = 0, const char *dhcpScript = NULL);
// 一些调试用的函数
/*
// C prototype : void StrToHex(unsigned char *pbDest, unsigned char *pbSrc, int nLen)
// parameter(s): [OUT] pbDest - 输出缓冲区
// [IN] pbSrc - 字符串
// [IN] nLen - 16进制数的字节数(字符串的长度/2)
// return value:
// remarks : 将字符串转化为16进制数
*/
void StrToHex(unsigned char *pbDest, unsigned char *pbSrc, int nLen);
/*
// C prototype : void HexToStr(unsigned char *pbDest, unsigned char *pbSrc, int nLen)
// parameter(s): [OUT] pbDest - 存放目标字符串
// [IN] pbSrc - 输入16进制数的起始地址
// [IN] nLen - 16进制数的字节数
// return value:
// remarks : 将16进制数转化为字符串
*/
void HexToStr(unsigned char *pbDest, unsigned char *pbSrc, int nLen);
void MD5Print(unsigned char * digest);
void PrintHex(unsigned char * data, int len);
void PrintMACAddress(unsigned char MACData[]);
/*
char data[100];
unsigned char * pbSrc1 = (unsigned char *)"21690d95033620379475a9d8f8dac222";
unsigned char pbDest1[16];
data[0] = (char)192;
u_char* digest;
memcpy(data + 1, "14319Xzte142052", 6 + 9);
StrToHex(pbDest1, pbSrc1, 16);
memcpy(data + 16, pbDest1, 16);
digest = Get_Md5_Digest((u_char*)data, 32);
MD5Print(digest);
//29ed270fd8edcb087424237870d578f4
*/
//unsigned char digest[16];
/*unsigned char key[256] = {"123"};
unsigned char pData[512] = "admin";
cout << endl;
rc4_crypt(pData, 5, key, 3);
printf("%s\n", pData);*/
//unsigned char * data = (unsigned char *)"u14319x";
//md5(data, sizeof(data), digest);
//hmac_md5((unsigned char*)"admin", 5, (unsigned char*)"123", 3, digest);
//MD5Print(digest);
//cout << endl;
/*unsigned char enckey[] = { 0x02, 0x02, 0x14, 0x00 };
unsigned char wholekey[20];
unsigned char * pbSrc2 = (unsigned char *)"efa90d7da0f4b7cca1bb4067c82c9969c82c9969";
unsigned char pbDest2[20];
StrToHex(pbDest2, pbSrc2, 20);
PrintHex(pbDest2, 20);
memcpy(wholekey, pbDest2, 20);
Get_RC4(enckey, 4, wholekey, 20);
PrintHex(enckey, 4);*/
/*unsigned char * pbSrc = (unsigned char *)"323031353335303230343231"; //201535020421
unsigned char pbDest[16];
memset(pbDest, 0, 16);
StrToHex(pbDest, pbSrc, 12);
printf("%s", pbDest);*/
/*unsigned char encDat[64];
memset(encDat, 0, 64);
unsigned char * deckey;
unsigned char * pbSrc3 = (unsigned char *)"";
unsigned char pbDest3[52];
StrToHex(pbDest2, pbSrc2, 52);
memcpy(encDat, pbDest3, 52);
enckey[0] = encDat[31];
deckey = Get_Hmac_Md5_Digest(encDat, 52, enckey, 1);
memcpy(eap_life_keeping + 46, deckey, 16);
PrintHex(deckey, 16); */
#endif // ADAPTER_H_

View File

@ -1,26 +0,0 @@
### simple makefile
ifndef $(CC)
CCC = gcc
endif
ifndef $(CXX)
CXX = g++
endif
CCFLAGS += -std=c99
CXXFLAGS += -std=c++11
all : test
test : conv.o test.o
$(CXX) $(LDFLAGS) -o $@ $^
conv.o : conv.c conv.h
$(CC) $(CCFLAGS) -c $<
test.o : test.cpp
$(CXX) $(CXXFLAGS) -c $<
.PHONY clean :
-rm -rf ./*.o test

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +0,0 @@
#ifndef CONV_H_INCLUDE
#define CONV_H_INCLUDE
#ifdef __cplusplus
extern "C" {
#endif
const char* g2u(const char *inb); // gbk to utf-8
const char* u2g(const char *inb); // utf-8 to gbk
#ifdef __cplusplus
}
#endif
#endif // CONV_H_INCLUDE

View File

@ -1,18 +0,0 @@
#include <iostream>
#include "conv.h"
using namespace std;
int main(int argc, char *argv[])
{
string src = "我是谁?";
string dsc = "";
dsc = string(u2g(src.c_str()));
cout << dsc << endl;
src = dsc;
dsc = string(g2u(src.c_str()));
cout << dsc << endl;
return 0;
}

View File

@ -1,33 +0,0 @@
#include <unistd.h>
#include <signal.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include "daemon.h"
void init_daemon(void)
{
int pid;
int i;
if((pid=fork()))
exit(0); // 是父进程,结束父进程
else if(pid< 0)
exit(1); // fork失败退出
// 是第一子进程,后台继续执行
setsid(); // 第一子进程成为新的会话组长和进程组长
// 并与控制终端分离
if((pid=fork()))
exit(0); // 是第一子进程,结束第一子进程
else if(pid< 0)
exit(1); // fork失败退出
// 是第二子进程,继续
// 第二子进程不再是会话组长
for(i = 0; i< NOFILE; ++i) // 关闭打开的文件描述符
close(i);
i = chdir("/"); // 改变工作目录到/tmp i赋值只是消除warning
umask(0); // 重设文件创建掩模
return;
}

View File

@ -1,6 +0,0 @@
#ifndef DAEMON_H_INCLUDE
#define DAEMON_H_INCLUDE
void init_daemon(void); //守护进程初始化函数
#endif

View File

@ -1,207 +0,0 @@
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include "darg.h"
#include <getopt.h>
#include <cstdlib>
#include "lock.h"
#include "daemon.h"
using std::string;
using std::cout;
using std::cerr;
using std::endl;
string Version = "2017.09.19.20";
DArg::DArg()
{
m_zteUser = m_ztePass = m_adapterName = m_enetUser = m_enetPass = msg = "";
background = 0;
m_dhcpStyle = 0; // 默认不使用dhcp
m_timeout = 0; // 默认不设置超时
}
DArg::~DArg()
{
}
void DArg::showUsage()
{
cout << "\n\t\tZTE 802.1X Client For CCDGUT (Version: " << ::Version << ")\n\n";
cout << "\tUsage:\n\n";
cout << "Required arguments:\n"
"\t-u, --zteuser\t\tYour username.\n"
"\t-p, --ztepass\t\tYour password.\n"
"\t-d, --device\t\tSpecify which device to use.\n"
"\n"
"Optional arguments:\n"
"\t-e, --enetUser\t\tEnet auth username\n"
"\t-k, --enetPass\t\tEnet auth password\n"
"\t-i, --DhcpClient\tSelect DhcpClient\n"
"\t\tonly support dhclient and udhcpc, default is disable\n"
"\t-s, --dhcp script file\n"
"\t-b, --daemon\t\tRun as daemon\n"
"\t-t, --authentication timeout\n"
//"\t-r, --reconnect\t\tReconnect\n"
//"\t-l, --logoff\t\tLogoff.\n"
"\t-h, --help\t\tShow this help.\n"
"Note: Run under root privilege, usually by 'sudo'.\n"
"\n"
"\t\t\t\t\t\t\t\tBy Zeyes\n";
}
void DArg::getArguments(int argc, char *argv[])
{
int background = 0, c;
if(argc == 1)
{
showUsage();
exit(EXIT_SUCCESS);
}
const char* short_options = "u:p:d:t:be:k:i:s:rlh";
struct option long_options[] =
{
{"zteuser", required_argument, NULL, 'u'},
{"ztepass", required_argument, NULL, 'p'},
{"device", required_argument, NULL, 'd'},
{"timeout", required_argument, NULL, 't'},
{"daemon", no_argument, no_argument, 'b'},
{"enetuser", required_argument, NULL, 'e'},
{"enetpass", required_argument, NULL, 'k'},
{"reconnect", no_argument, NULL, 'r'},
{"logoff", no_argument, NULL, 'l'},
{"help", no_argument, NULL, 'h'},
{0, 0, 0, 0}
};
while((c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1)
{
switch(c)
{
case 'u':
m_zteUser = optarg;
break;
case 'p':
m_ztePass = optarg;
break;
case 'd':
m_adapterName = optarg;
break;
case 't':
m_timeout = atoi(optarg);
break;
case 'b':
background = 1;
break;
case 'e':
m_enetUser = optarg;
break;
case 'k':
m_enetPass = optarg;
break;
case 'i':
if (!strcmp(optarg, "dhclient"))
m_dhcpStyle = 1;
else if (!strcmp(optarg, "udhcpc"))
m_dhcpStyle = 2;
else
cerr << "Unknow dhcp client:" << optarg << ", use dhclient instead.\n";
break;
case 's':
m_dhcpScript = optarg;
break;
case 'h':
showUsage();
exit(EXIT_SUCCESS);
break;
case 'r':
break;
case 'l':
break;
case '?':
exit(EXIT_FAILURE);
default:
cerr << "Unrecognize option -" << optopt << "\n";
}
}
if(background == 1)
{
cout << "Running as daemon!...\n";
init_daemon(); // 守护进程
}
if(already_running())
{
cerr << "Program is running!\n";
exit(EXIT_FAILURE);
}
if(m_zteUser.empty() || m_ztePass.empty() || m_adapterName.empty())
{
cerr << "--zteuser, --ztepass, --device are vital.\n";
exit(EXIT_FAILURE);
}
if(m_timeout != 0 && m_timeout < 300)
{
cerr << "timeout value can't set, because the minimum value is 300.\n";
m_timeout = 300;
}
if(m_enetUser.empty()) m_enetAuth = false; else m_enetAuth = true;
}
string DArg::zteUser()
{
return m_zteUser;
}
string DArg::ztePass()
{
return m_ztePass;
}
string DArg::adapterName()
{
return m_adapterName;
}
string DArg::enetUser()
{
return m_enetUser;
}
string DArg::enetPass()
{
return m_enetPass;
}
int DArg::dhcpStyle()
{
// 0is disable, 1 is dhclient, 2 is udhcpc
return m_dhcpStyle;
}
string DArg::dhcpScript()
{
return m_dhcpScript;
}
string DArg::getMessage()
{
return msg;
}
bool DArg::enetAuth()
{
return m_enetAuth;
}
int DArg::timeout()
{
return m_timeout;
}

View File

@ -1,35 +0,0 @@
#ifndef DARG_H_
#define DARG_H_
#include <string>
using std::string;
class DArg
{
public:
DArg();
~DArg();
void showUsage();
void getArguments(int argc, char *argv[]);
string zteUser();
string ztePass();
string adapterName();
string enetUser();
string enetPass();
int dhcpStyle();
string dhcpScript();
int timeout();
bool enetAuth();
//void logoff();
//bool daemon();
string getMessage();
protected:
string m_zteUser, m_ztePass, m_adapterName, m_enetUser, m_enetPass, m_dhcpScript;
string msg;
int background;
int m_dhcpStyle, m_timeout;
bool m_enetAuth;
};
#endif // DARG_H_

View File

@ -1,96 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="dclient" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/dclient" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/dclient" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
<Add directory="/usr/include" />
</Compiler>
<Linker>
<Add option="-lpthread -lpcap -lcurl -ljpeg" />
<Add directory="/usr/lib" />
</Linker>
<Unit filename="adapter.cpp" />
<Unit filename="adapter.h" />
<Unit filename="conv/conv.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="conv/conv.h" />
<Unit filename="daemon.cpp" />
<Unit filename="daemon.h" />
<Unit filename="darg.cpp" />
<Unit filename="darg.h" />
<Unit filename="dcurl.cpp" />
<Unit filename="dcurl.h" />
<Unit filename="dir.cpp" />
<Unit filename="dir.h" />
<Unit filename="dlog.cpp" />
<Unit filename="dlog.h" />
<Unit filename="docr.cpp" />
<Unit filename="docr.h" />
<Unit filename="docrkeys.cpp" />
<Unit filename="dpcap.cpp" />
<Unit filename="dpcap.h" />
<Unit filename="eappacket.cpp" />
<Unit filename="eappacket.h" />
<Unit filename="encrypt.cpp" />
<Unit filename="encrypt.h" />
<Unit filename="encrypt/base64.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="encrypt/base64.h" />
<Unit filename="encrypt/crc32.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="encrypt/crc32.h" />
<Unit filename="encrypt/md5.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="encrypt/md5.h" />
<Unit filename="encrypt/rc4.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="encrypt/rc4.h" />
<Unit filename="global.h" />
<Unit filename="lock.cpp" />
<Unit filename="lock.h" />
<Unit filename="main.cpp" />
<Unit filename="msgpass.cpp" />
<Unit filename="msgpass.h" />
<Unit filename="tprocess.cpp" />
<Unit filename="tprocess.h" />
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -1,39 +0,0 @@
"/home/zeyes/cpp/dclient/src/tprocess.cpp"
"/home/zeyes/cpp/dclient/src/encrypt/rc4.c"
"/home/zeyes/cpp/dclient/src/conv/test.cpp"
"/home/zeyes/cpp/dclient/src/dlog.cpp"
"/home/zeyes/cpp/dclient/src/dlog.h"
"/home/zeyes/cpp/dclient/src/msgpass.h"
"/home/zeyes/cpp/dclient/src/encrypt/md5.c"
"/home/zeyes/cpp/dclient/src/adapter.h"
"/home/zeyes/cpp/dclient/src/conv/conv.h"
"/home/zeyes/cpp/dclient/src/dir.cpp"
"/home/zeyes/cpp/dclient/src/msgpass.cpp"
"/home/zeyes/cpp/dclient/src/encrypt.cpp"
"/home/zeyes/cpp/dclient/src/daemon.cpp"
"/home/zeyes/cpp/dclient/src/docr.h"
"/home/zeyes/cpp/dclient/src/main.cpp"
"/home/zeyes/cpp/dclient/src/dcurl.cpp"
"/home/zeyes/cpp/dclient/src/adapter.cpp"
"/home/zeyes/cpp/dclient/src/conv/conv.c"
"/home/zeyes/cpp/dclient/src/daemon.h"
"/home/zeyes/cpp/dclient/src/lock.h"
"/home/zeyes/cpp/dclient/src/encrypt/mddriver.c"
"/home/zeyes/cpp/dclient/src/eappacket.cpp"
"/home/zeyes/cpp/dclient/src/dpcap.cpp"
"/home/zeyes/cpp/dclient/src/global.h"
"/home/zeyes/cpp/dclient/src/dir.h"
"/home/zeyes/cpp/dclient/src/encrypt/rc4.h"
"/home/zeyes/cpp/dclient/src/darg.h"
"/home/zeyes/cpp/dclient/src/encrypt/crc32.h"
"/home/zeyes/cpp/dclient/src/lock.cpp"
"/home/zeyes/cpp/dclient/src/encrypt.h"
"/home/zeyes/cpp/dclient/src/encrypt/crc32.c"
"/home/zeyes/cpp/dclient/src/eappacket.h"
"/home/zeyes/cpp/dclient/src/docrkeys.cpp"
"/home/zeyes/cpp/dclient/src/encrypt/md5.h"
"/home/zeyes/cpp/dclient/src/dpcap.h"
"/home/zeyes/cpp/dclient/src/tprocess.h"
"/home/zeyes/cpp/dclient/src/darg.cpp"
"/home/zeyes/cpp/dclient/src/dcurl.h"
"/home/zeyes/cpp/dclient/src/docr.cpp"

View File

@ -1,794 +0,0 @@
# depslib dependency file v1.0
1505568918 source:/home/zeyes/cpp/dclient/src/adapter.cpp
"adapter.h"
<unistd.h>
1505219106 /home/zeyes/cpp/dclient/src/adapter.h
<cstdint>
"global.h"
1505620636 /home/zeyes/cpp/dclient/src/global.h
<iostream>
<iomanip>
<cstdio>
<cstdint>
<cstdlib>
<cstring>
<sys/types.h>
<sys/ioctl.h>
<sys/socket.h>
<netinet/in.h>
<net/if.h>
<unistd.h>
<winsock2.h>
<ws2tcpip.h>
<Windows.h>
<Iphlpapi.h>
"pcap.h"
"adapter.h"
1505568772 source:/home/zeyes/cpp/dclient/src/conv/conv.c
<stddef.h>
<stdlib.h>
<string.h>
1488867256 source:/home/zeyes/cpp/dclient/src/conv/test.cpp
<iostream>
"conv.h"
1505563425 /home/zeyes/cpp/dclient/src/conv/conv.h
1505568762 source:/home/zeyes/cpp/dclient/src/daemon.cpp
<unistd.h>
<signal.h>
<sys/param.h>
<sys/types.h>
<sys/stat.h>
<stdlib.h>
"daemon.h"
1488792242 /home/zeyes/cpp/dclient/src/daemon.h
1505620839 source:/home/zeyes/cpp/dclient/src/darg.cpp
<iostream>
<string>
<cstring>
<cstdlib>
"darg.h"
<getopt.h>
<cstdlib>
"lock.h"
"daemon.h"
1505218848 /home/zeyes/cpp/dclient/src/darg.h
<string>
1488792214 /home/zeyes/cpp/dclient/src/lock.h
1489232738 source:/home/zeyes/cpp/dclient/src/dcurl.cpp
"dcurl.h"
<cstdio>
<cstdlib>
<cstring>
<iostream>
<fstream>
1476239672 /home/zeyes/cpp/dclient/src/dcurl.h
<curl/curl.h>
<string>
"dir.h"
1476204802 /home/zeyes/cpp/dclient/src/dir.h
<string>
"global.h"
<windows.h>
1475592076 source:/home/zeyes/cpp/dclient/src/dir.cpp
"dir.h"
1496339738 source:/home/zeyes/cpp/dclient/src/dlog.cpp
<iostream>
<ctime>
"dlog.h"
1489041930 /home/zeyes/cpp/dclient/src/dlog.h
<fstream>
<pthread.h>
1489241468 source:/home/zeyes/cpp/dclient/src/docr.cpp
"docr.h"
<iomanip>
1489240914 /home/zeyes/cpp/dclient/src/docr.h
<iostream>
<fstream>
<vector>
<string>
<cstdio>
<cstdlib>
<memory.h>
"jpeglib.h"
"jerror.h"
"setjmp.h"
1475904158 source:/home/zeyes/cpp/dclient/src/docrkeys.cpp
"docr.h"
1505722152 source:/home/zeyes/cpp/dclient/src/dpcap.cpp
<ctime>
<cstring>
"global.h"
"dpcap.h"
"adapter.h"
<iostream>
1505619581 /home/zeyes/cpp/dclient/src/dpcap.h
<ctime>
<string>
<pthread.h>
"global.h"
"msgpass.h"
"eappacket.h"
1476179214 /home/zeyes/cpp/dclient/src/msgpass.h
<pthread.h>
1496334850 /home/zeyes/cpp/dclient/src/eappacket.h
<cstdint>
<string>
1505620631 source:/home/zeyes/cpp/dclient/src/eappacket.cpp
<memory.h>
"global.h"
"eappacket.h"
"encrypt.h"
"conv/conv.h"
1505382426 /home/zeyes/cpp/dclient/src/encrypt.h
1505382560 source:/home/zeyes/cpp/dclient/src/encrypt.cpp
"encrypt.h"
"encrypt/md5.h"
"encrypt/rc4.h"
"encrypt/crc32.h"
"encrypt/base64.h"
1487740952 /home/zeyes/cpp/dclient/src/encrypt/md5.h
<inttypes.h>
1487741072 /home/zeyes/cpp/dclient/src/encrypt/rc4.h
1496333656 /home/zeyes/cpp/dclient/src/encrypt/crc32.h
1505381985 /home/zeyes/cpp/dclient/src/encrypt/base64.h
1460487490 source:/home/zeyes/cpp/dclient/src/encrypt/base64.c
<stdio.h>
"base64.h"
1496338352 source:/home/zeyes/cpp/dclient/src/encrypt/crc32.c
1487740924 source:/home/zeyes/cpp/dclient/src/encrypt/md5.c
"md5.h"
1475385234 source:/home/zeyes/cpp/dclient/src/encrypt/mddriver.c
<stdio.h>
<time.h>
<string.h>
"md5.h"
1475410570 source:/home/zeyes/cpp/dclient/src/encrypt/rc4.c
1505568897 source:/home/zeyes/cpp/dclient/src/lock.cpp
<cstdio>
<cstdlib>
<cstring>
<fcntl.h>
<errno.h>
<unistd.h>
"lock.h"
1505570948 source:/home/zeyes/cpp/dclient/src/main.cpp
<iostream>
<string>
"tprocess.h"
"darg.h"
1505385223 /home/zeyes/cpp/dclient/src/tprocess.h
<ctime>
<fstream>
<pthread.h>
"dpcap.h"
"adapter.h"
"dcurl.h"
"msgpass.h"
"dlog.h"
1476179254 source:/home/zeyes/cpp/dclient/src/msgpass.cpp
"msgpass.h"
1505612253 source:/home/zeyes/cpp/dclient/src/tprocess.cpp
<stdio.h>
<iostream>
<cstdlib>
<string>
"global.h"
"dpcap.h"
"tprocess.h"
"adapter.h"
"docr.h"
"encrypt.h"
1497646312 /usr/include/sys/types.h
<features.h>
<bits/types.h>
<time.h>
<stddef.h>
<endian.h>
<sys/select.h>
<sys/sysmacros.h>
<bits/pthreadtypes.h>
1497646282 /usr/include/features.h
<stdc-predef.h>
<sys/cdefs.h>
<gnu/stubs.h>
1497646282 /usr/include/stdc-predef.h
1497646316 /usr/include/sys/cdefs.h
<features.h>
<bits/wordsize.h>
1497646305 /usr/include/bits/wordsize.h
1497646282 /usr/include/gnu/stubs.h
<gnu/stubs-32.h>
<gnu/stubs-64.h>
<gnu/stubs-x32.h>
1497646453 /usr/include/gnu/stubs-32.h
1497646344 /usr/include/gnu/stubs-64.h
1497646536 /usr/include/gnu/stubs-x32.h
1497646312 /usr/include/bits/types.h
<features.h>
<bits/wordsize.h>
<bits/typesizes.h>
1497646312 /usr/include/bits/typesizes.h
1497646310 /usr/include/time.h
<features.h>
<stddef.h>
<bits/time.h>
<bits/types.h>
<bits/types.h>
<bits/types.h>
<bits/types.h>
<bits/types.h>
<xlocale.h>
1497646310 /usr/include/bits/time.h
<bits/types.h>
<bits/types.h>
<bits/timex.h>
1497646310 /usr/include/bits/timex.h
<bits/types.h>
1497646283 /usr/include/xlocale.h
1497646309 /usr/include/endian.h
<features.h>
<bits/endian.h>
<bits/byteswap.h>
1497646309 /usr/include/bits/endian.h
1497646309 /usr/include/bits/byteswap.h
<features.h>
<bits/types.h>
<bits/wordsize.h>
<bits/byteswap-16.h>
1497646309 /usr/include/bits/byteswap-16.h
1497646316 /usr/include/sys/select.h
<features.h>
<bits/types.h>
<bits/select.h>
<bits/sigset.h>
<time.h>
<bits/time.h>
<bits/select2.h>
1497646316 /usr/include/bits/select.h
<bits/wordsize.h>
1497646304 /usr/include/bits/sigset.h
1497646316 /usr/include/bits/select2.h
1497646312 /usr/include/sys/sysmacros.h
<features.h>
1497646312 /usr/include/bits/pthreadtypes.h
<bits/wordsize.h>
1497646316 /usr/include/sys/ioctl.h
<features.h>
<bits/ioctls.h>
<bits/ioctl-types.h>
<sys/ttydefaults.h>
1497646316 /usr/include/bits/ioctls.h
<asm/ioctls.h>
1502494496 /usr/include/asm/ioctls.h
<asm-generic/ioctls.h>
1502494489 /usr/include/asm-generic/ioctls.h
<linux/ioctl.h>
1502494493 /usr/include/linux/ioctl.h
<asm/ioctl.h>
1502494496 /usr/include/asm/ioctl.h
<asm-generic/ioctl.h>
1502494489 /usr/include/asm-generic/ioctl.h
1497646316 /usr/include/bits/ioctl-types.h
<asm/ioctls.h>
1497646313 /usr/include/sys/ttydefaults.h
1497646321 /usr/include/sys/socket.h
<features.h>
<sys/uio.h>
<stddef.h>
<bits/sigset.h>
<bits/socket.h>
<bits/socket2.h>
1497646316 /usr/include/sys/uio.h
<features.h>
<sys/types.h>
<bits/uio.h>
1497646316 /usr/include/bits/uio.h
<sys/types.h>
1497646321 /usr/include/bits/socket.h
<stddef.h>
<sys/types.h>
<bits/socket_type.h>
<bits/sockaddr.h>
<asm/socket.h>
1497646317 /usr/include/bits/socket_type.h
1497646321 /usr/include/bits/sockaddr.h
1502494496 /usr/include/asm/socket.h
<asm-generic/socket.h>
1502494489 /usr/include/asm-generic/socket.h
<asm/sockios.h>
1502494496 /usr/include/asm/sockios.h
<asm-generic/sockios.h>
1502494489 /usr/include/asm-generic/sockios.h
1497646321 /usr/include/bits/socket2.h
1497646332 /usr/include/netinet/in.h
<features.h>
<stdint.h>
<sys/socket.h>
<bits/types.h>
<bits/in.h>
<endian.h>
<bits/byteswap.h>
1497646305 /usr/include/stdint.h
<features.h>
<bits/wchar.h>
<bits/wordsize.h>
1497646309 /usr/include/bits/wchar.h
1497646332 /usr/include/bits/in.h
1497646321 /usr/include/net/if.h
<features.h>
<sys/types.h>
<sys/socket.h>
1497646312 /usr/include/unistd.h
<features.h>
<bits/posix_opt.h>
<bits/environments.h>
<bits/types.h>
<stddef.h>
<bits/confname.h>
<getopt.h>
<bits/unistd.h>
1497646312 /usr/include/bits/posix_opt.h
1497646312 /usr/include/bits/environments.h
<bits/wordsize.h>
1497646312 /usr/include/bits/confname.h
1497646312 /usr/include/getopt.h
<ctype.h>
1497646299 /usr/include/ctype.h
<features.h>
<bits/types.h>
<endian.h>
<xlocale.h>
1497646312 /usr/include/bits/unistd.h
1448752290 /usr/include/pcap.h
<pcap/pcap.h>
1448752290 /usr/include/pcap/pcap.h
<pcap-stdinc.h>
<sys/types.h>
<sys/socket.h>
<sys/types.h>
<sys/time.h>
<pcap/bpf.h>
<stdio.h>
<Win32-Extensions.h>
1497646310 /usr/include/sys/time.h
<features.h>
<bits/types.h>
<time.h>
<bits/time.h>
<sys/select.h>
1448752290 /usr/include/pcap/bpf.h
1497646306 /usr/include/stdio.h
<features.h>
<stddef.h>
<bits/types.h>
<libio.h>
<stdarg.h>
<bits/stdio_lim.h>
<bits/sys_errlist.h>
<getopt.h>
<bits/stdio.h>
<bits/stdio2.h>
<bits/stdio-ldbl.h>
1497646306 /usr/include/libio.h
<_G_config.h>
<stdarg.h>
<sys/cdefs.h>
<shlib-compat.h>
<bits/libio-ldbl.h>
1497646306 /usr/include/_G_config.h
<bits/types.h>
<stddef.h>
<wchar.h>
<gconv.h>
1497646309 /usr/include/wchar.h
<features.h>
<stdio.h>
<stdarg.h>
<bits/wchar.h>
<stddef.h>
<wctype.h>
<xlocale.h>
<xlocale.h>
<xlocale.h>
<wctype.h>
<bits/wchar2.h>
<bits/wchar-ldbl.h>
1497646321 /usr/include/wctype.h
<features.h>
<bits/types.h>
<wchar.h>
<endian.h>
<xlocale.h>
1497646310 /usr/include/bits/wchar2.h
1497646310 /usr/include/bits/wchar-ldbl.h
1497646283 /usr/include/gconv.h
<features.h>
<wchar.h>
<stddef.h>
1497646306 /usr/include/bits/libio-ldbl.h
1497646305 /usr/include/bits/stdio_lim.h
1497646306 /usr/include/bits/sys_errlist.h
1497646306 /usr/include/bits/stdio.h
1497646306 /usr/include/bits/stdio2.h
1497646306 /usr/include/bits/stdio-ldbl.h
1497646304 /usr/include/signal.h
<features.h>
<bits/sigset.h>
<bits/types.h>
<bits/signum.h>
<time.h>
<bits/siginfo.h>
<bits/sigaction.h>
<bits/sigcontext.h>
<stddef.h>
<bits/sigstack.h>
<sys/ucontext.h>
<bits/pthreadtypes.h>
<bits/sigthread.h>
1497646304 /usr/include/bits/signum.h
1497646304 /usr/include/bits/siginfo.h
<bits/wordsize.h>
1497646304 /usr/include/bits/sigaction.h
1497646304 /usr/include/bits/sigcontext.h
1497646304 /usr/include/bits/sigstack.h
1497646305 /usr/include/sys/ucontext.h
<features.h>
<signal.h>
<bits/sigcontext.h>
1497646304 /usr/include/bits/sigthread.h
1497646316 /usr/include/sys/param.h
<stddef.h>
<sys/types.h>
<limits.h>
<endian.h>
<signal.h>
<bits/param.h>
1497646282 /usr/include/limits.h
<features.h>
<bits/wordsize.h>
<bits/posix1_lim.h>
<bits/posix2_lim.h>
<bits/xopen_lim.h>
1497646312 /usr/include/bits/posix1_lim.h
<bits/local_lim.h>
1497646312 /usr/include/bits/local_lim.h
<linux/limits.h>
1502494493 /usr/include/linux/limits.h
1497646312 /usr/include/bits/posix2_lim.h
1497646282 /usr/include/bits/xopen_lim.h
<bits/stdio_lim.h>
<bits/wordsize.h>
1497646316 /usr/include/bits/param.h
<linux/limits.h>
<linux/param.h>
1502494494 /usr/include/linux/param.h
<asm/param.h>
1502494496 /usr/include/asm/param.h
<asm-generic/param.h>
1502494489 /usr/include/asm-generic/param.h
1497646313 /usr/include/sys/stat.h
<features.h>
<bits/types.h>
<time.h>
<bits/stat.h>
1497646313 /usr/include/bits/stat.h
1497646305 /usr/include/stdlib.h
<features.h>
<stddef.h>
<bits/waitflags.h>
<bits/waitstatus.h>
<xlocale.h>
<sys/types.h>
<alloca.h>
<bits/stdlib-bsearch.h>
<bits/stdlib-float.h>
<bits/stdlib.h>
<bits/stdlib-ldbl.h>
1497646312 /usr/include/bits/waitflags.h
1497646312 /usr/include/bits/waitstatus.h
<endian.h>
1497646305 /usr/include/alloca.h
<features.h>
<stddef.h>
1497646305 /usr/include/bits/stdlib-bsearch.h
1497646305 /usr/include/bits/stdlib-float.h
1497646305 /usr/include/bits/stdlib.h
1497646305 /usr/include/bits/stdlib-ldbl.h
1478126754 /usr/include/curl/curl.h
"curlver.h"
"curlbuild.h"
"curlrules.h"
<stdio.h>
<limits.h>
<osreldate.h>
<sys/types.h>
<time.h>
<winsock2.h>
<ws2tcpip.h>
<sys/select.h>
<sys/socket.h>
<sys/time.h>
<support/SupportDefs.h>
"easy.h"
"multi.h"
"typecheck-gcc.h"
1478126754 /usr/include/curl/curlver.h
1478126754 /usr/include/curl/curlbuild.h
<windows.h>
<winsock2.h>
<ws2tcpip.h>
<sys/types.h>
<stdint.h>
<inttypes.h>
<sys/socket.h>
<sys/poll.h>
1497646305 /usr/include/inttypes.h
<features.h>
<stdint.h>
<stddef.h>
1497646313 /usr/include/sys/poll.h
<features.h>
<bits/poll.h>
<bits/sigset.h>
<time.h>
<bits/poll2.h>
1497646313 /usr/include/bits/poll.h
1497646313 /usr/include/bits/poll2.h
1478126754 /usr/include/curl/curlrules.h
1478126754 /usr/include/curl/easy.h
1478126754 /usr/include/curl/multi.h
"curl.h"
1478126754 /usr/include/curl/typecheck-gcc.h
1497646326 /usr/include/pthread.h
<features.h>
<endian.h>
<sched.h>
<time.h>
<bits/pthreadtypes.h>
<bits/setjmp.h>
<bits/wordsize.h>
1497646312 /usr/include/sched.h
<features.h>
<bits/types.h>
<stddef.h>
<time.h>
<bits/sched.h>
1497646312 /usr/include/bits/sched.h
1497646304 /usr/include/bits/setjmp.h
<bits/wordsize.h>
1497646309 /usr/include/memory.h
<features.h>
<string.h>
1497646309 /usr/include/string.h
<features.h>
<stddef.h>
<xlocale.h>
<bits/string.h>
<bits/string2.h>
<bits/string3.h>
1497646309 /usr/include/bits/string.h
1497646309 /usr/include/bits/string2.h
<endian.h>
<bits/types.h>
<stdlib.h>
1497646309 /usr/include/bits/string3.h
1456153293 /usr/include/jpeglib.h
"jconfig.h"
"jmorecfg.h"
"jpegint.h"
"jerror.h"
1456153293 /usr/include/jmorecfg.h
1442861312 /usr/include/jpegint.h
1456153293 /usr/include/jerror.h
1497646304 /usr/include/setjmp.h
<features.h>
<bits/setjmp.h>
<bits/sigset.h>
<bits/setjmp2.h>
1497646304 /usr/include/bits/setjmp2.h
1497646313 /usr/include/fcntl.h
<features.h>
<bits/types.h>
<bits/fcntl.h>
<time.h>
<bits/stat.h>
<bits/fcntl2.h>
1497646313 /usr/include/bits/fcntl.h
<bits/fcntl-linux.h>
1497646313 /usr/include/bits/fcntl-linux.h
<bits/fcntl-linux.h>
<bits/uio.h>
1497646313 /usr/include/bits/fcntl2.h
1497646305 /usr/include/errno.h
<features.h>
<bits/errno.h>
1497646305 /usr/include/bits/errno.h
<linux/errno.h>
1502494492 /usr/include/linux/errno.h
<asm/errno.h>
1502494496 /usr/include/asm/errno.h
<asm-generic/errno.h>
1502494489 /usr/include/asm-generic/errno.h
<asm-generic/errno-base.h>
1502494489 /usr/include/asm-generic/errno-base.h

View File

@ -1,125 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
<File name="dpcap.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="4983" topLine="0" />
</Cursor>
</File>
<File name="daemon.cpp" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="822" topLine="3" />
</Cursor>
</File>
<File name="tprocess.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1119" topLine="12" />
</Cursor>
</File>
<File name="encrypt/base64.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="123" topLine="0" />
</Cursor>
</File>
<File name="eappacket.h" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1169" topLine="0" />
</Cursor>
</File>
<File name="dcurl.cpp" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="532" topLine="186" />
</Cursor>
</File>
<File name="msgpass.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="308" topLine="0" />
</Cursor>
</File>
<File name="adapter.cpp" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="4914" topLine="0" />
</Cursor>
</File>
<File name="global.h" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="814" topLine="15" />
</Cursor>
</File>
<File name="lock.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="403" topLine="9" />
</Cursor>
</File>
<File name="darg.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="279" topLine="1" />
</Cursor>
</File>
<File name="encrypt.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="451" topLine="0" />
</Cursor>
</File>
<File name="dcurl.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1410" topLine="58" />
</Cursor>
</File>
<File name="eappacket.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="8080" topLine="174" />
</Cursor>
</File>
<File name="darg.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="274" topLine="0" />
</Cursor>
</File>
<File name="conv/conv.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="102" topLine="0" />
</Cursor>
</File>
<File name="dpcap.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2182" topLine="44" />
</Cursor>
</File>
<File name="tprocess.cpp" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="5530" topLine="319" />
</Cursor>
</File>
<File name="dlog.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="338" topLine="0" />
</Cursor>
</File>
<File name="adapter.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="574" topLine="30" />
</Cursor>
</File>
<File name="main.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="484" topLine="0" />
</Cursor>
</File>
<File name="dlog.cpp" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="341" topLine="1" />
</Cursor>
</File>
<File name="conv/conv.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="245" topLine="0" />
</Cursor>
</File>
<File name="encrypt.cpp" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1247" topLine="15" />
</Cursor>
</File>
</CodeBlocks_layout_file>

View File

@ -1,324 +0,0 @@
#include "dcurl.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <fstream>
using namespace std;
DCurl::DCurl()
{
// 获取用户临时文件夹
GetTmpDir(m_tmpDir);
// 设置cookie临时保存文件
m_cookieFile = m_tmpDir + "dcurl.tmp";
//初始化Url
m_strUrl = "";
// 初始化超时
m_connTimeout = 3L;
m_timeout = 30L;
// 初始化POST字符串
m_strPost = "";
// 初始化CA证书路径
m_pCaPath = "";
// 初始化文件指针
m_pFile = NULL;
// 初始化输出变量
m_strResponse = "";
m_sType = W_NONE;
m_rType = GET;
}
DCurl::~DCurl()
{
}
size_t DCurl::_handleWrite(void *buffer, size_t size, size_t nmemb, void *pfn)
{
DCurl *pDCurl = dynamic_cast<DCurl *>((DCurl *)pfn);
if (pDCurl)
{
return pDCurl->onWrite(buffer, size, nmemb);
}
return 0;
}
void DCurl::setOption()
{
if(NULL == m_pCurl) return;
// 远程URL支持 http, https, ftp
curl_easy_setopt(m_pCurl, CURLOPT_URL, m_strUrl.c_str());
// 设置User-Agent
std::string useragent = ("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1");
curl_easy_setopt(m_pCurl, CURLOPT_USERAGENT, useragent.c_str());
// 设置重定向的最大次数
curl_easy_setopt(m_pCurl, CURLOPT_MAXREDIRS, 5);
// 设置301、302跳转跟随location
curl_easy_setopt(m_pCurl, CURLOPT_FOLLOWLOCATION, 1L);
// 设置写入回调函数
curl_easy_setopt(m_pCurl, CURLOPT_WRITEFUNCTION, _handleWrite);
curl_easy_setopt(m_pCurl, CURLOPT_WRITEDATA, this);
// 备注:调试的时候打开
//curl_easy_setopt(m_pCurl, CURLOPT_VERBOSE, 1);
//curl_easy_setopt(m_pCurl, CURLOPT_PROXY, "127.0.0.1:8888");
// 超时设置
curl_easy_setopt(m_pCurl, CURLOPT_CONNECTTIMEOUT, m_connTimeout);
curl_easy_setopt(m_pCurl, CURLOPT_TIMEOUT, m_timeout);
// 当多个线程都使用超时处理的时候同时主线程中有sleep或是wait等操作。
// 如果不设置这个选项libcurl将会发信号打断这个wait从而导致程序退出。
curl_easy_setopt(m_pCurl, CURLOPT_NOSIGNAL, 1L);
// Cookie设置
if(!m_cookieFile.empty()) // 没有设定文件名就不使用Cookie
{
curl_easy_setopt(m_pCurl, CURLOPT_COOKIEFILE, m_cookieFile.c_str()); // 读取本地存储的cookie
curl_easy_setopt(m_pCurl, CURLOPT_COOKIEJAR, m_cookieFile.c_str()); // 在cleanup之后保存cookie到文件
}
// 设置POST数据
if(m_rType == POST)
{
curl_easy_setopt(m_pCurl, CURLOPT_POST, 1L);
curl_easy_setopt(m_pCurl, CURLOPT_POSTFIELDS, m_strPost.c_str());
}
// HTTPS相关设置
if(!m_pCaPath.empty())
{
curl_easy_setopt(m_pCurl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(m_pCurl, CURLOPT_SSL_VERIFYHOST, 0L);
}
else
{
//缺省情况就是PEM所以无需设置另外支持DER
//curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
curl_easy_setopt(m_pCurl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(m_pCurl, CURLOPT_CAINFO, m_pCaPath.c_str());
}
}
size_t DCurl::_run()
{
CURLcode res;
m_pCurl = curl_easy_init();
if(NULL == m_pCurl)
return CURLE_FAILED_INIT;
setOption();
res = curl_easy_perform(m_pCurl);
curl_easy_cleanup(m_pCurl);
return res;
}
size_t DCurl::onWrite(void *buffer, size_t size, size_t nmemb )
{
size_t return_size = 0;
if(m_sType == W_NONE) return 0;
if(m_sType == W_FILE || m_sType == W_ALL)
{
if(m_pFile)
{
return_size = fwrite(buffer, size, nmemb, m_pFile);
}
else
return_size = -1;
//std::cout << (char*) buffer << std::endl;
}
if(m_sType == W_VAR || m_sType == W_ALL)
{
m_strResponse.append((char *)buffer, size * nmemb);
}
else
m_strResponse.append((char *)buffer, size * nmemb);
return return_size;
}
bool DCurl::_openFile()
{
// 创建文件
m_pFile = fopen(m_fileName.c_str(), "wb");
if (m_pFile == NULL)
return false;
return true;
}
bool DCurl::_closeFile()
{
if(m_pFile)
{
fclose(m_pFile);
m_pFile = NULL;
}
return true;
}
int DCurl::httpDownload(const string & strUrl, const string & fileName, const RequestType rType)
{
SaveType pre_sType = m_sType;
string preFileName = m_fileName;
string preStrUrl = m_strUrl;
RequestType pre_rType = m_rType;
m_rType = rType;
m_sType = W_FILE; // 设置输出类型
if(!strUrl.empty()) m_strUrl = strUrl;
if(!fileName.empty()) m_fileName = fileName;
if(!_openFile()) { m_sType = pre_sType; return -1; }
_run();
_closeFile();
m_sType = pre_sType;
m_fileName = preFileName;
m_strUrl = preStrUrl;
m_rType = pre_rType;
return 1;
}
int DCurl::httpRequest(const string & strUrl, const RequestType rType, bool toVar)
{
SaveType pre_sType = m_sType;
RequestType pre_rType = m_rType;
string preStrUrl = m_strUrl;
m_rType = rType;
if(!strUrl.empty())
m_strUrl = strUrl;
else
if(m_strUrl.empty()) return 0;
m_strResponse.clear();
if(toVar)
m_sType = W_VAR;
else
m_sType = W_NONE;
_run();
m_sType = pre_sType;
m_rType = pre_rType;
m_strUrl = preStrUrl;
return true;
}
string DCurl::httpSuperRequest(const string & strUrl, const RequestType rType,
const SaveType sType, const string & fileName)
{
SaveType pre_sType = m_sType, tmpType = sType;
string preFileName = m_fileName;
RequestType pre_rType = m_rType;
string preStrUrl = m_strUrl;
m_rType = rType;
m_strResponse.clear();
bool f_ext = !fileName.empty();
if(m_strUrl.empty())
{
// 如果本身没有设置地址,并且没有传参,直接返回
if(strUrl.empty()) return 0;
else m_strUrl = strUrl;
}
// 处理参数为空或者是成员函数m_fileName为空的情况
if((sType == W_FILE || sType == W_ALL) && !f_ext)
{
// 如果sType是W_FILE和W_ALL中的一种而且没有传参也没有预先设置m_fileName执行W_NONE
if(m_fileName.empty()) tmpType = (sType == W_FILE) ? W_NONE : W_VAR;
}
else
if(f_ext) m_fileName = fileName;
// 处理打开文件
if((tmpType == W_FILE || tmpType == W_ALL) && !_openFile())
{
if(tmpType == W_ALL) tmpType = W_VAR;
else tmpType = W_NONE;
}
if(sType == W_VAR)
tmpType = W_VAR;
m_sType = tmpType;
_run();
if(m_pFile) _closeFile();
m_sType = pre_sType;
m_rType = pre_rType;
m_fileName = preFileName;
m_strUrl = preStrUrl;
if(tmpType == W_VAR || tmpType == W_ALL) return m_strResponse;
else return "";
}
void DCurl::getResponse(string & strResponse)
{
strResponse = m_strResponse;
m_strResponse.clear();
}
void DCurl::setUrl(const string & strUrl)
{
m_strUrl = strUrl;
}
void DCurl::setRequestType(RequestType rType)
{
m_rType = rType;
}
void DCurl::setFileName(const string & fileName)
{
m_fileName = fileName;
}
void DCurl::setCaPath(const string & pCaPath)
{
m_pCaPath = pCaPath;
}
void DCurl::setTimeout(const long connTimeout, const long timeout)
{
m_connTimeout = connTimeout;
m_timeout = timeout;
}
void DCurl::setPostData(const string & postData)
{
m_strPost = postData;
}
bool DCurl::cleanCookie()
{
using std::ofstream;
using std::ios_base;
ofstream fout(m_cookieFile, ios_base::out | ios_base::trunc);
if(!fout.is_open()) return false;
fout.close();
return true;
}

View File

@ -1,100 +0,0 @@
#ifndef DCURL_H_
#define DCURL_H_
#include <curl/curl.h>
#include <string>
#include "dir.h"
using std::string;
class DCurl
{
public:
enum SaveType //输出类型
{
W_NONE = 0, //丢弃输出
W_VAR, //保存到变量
W_FILE, //保持到文件
W_ALL //保存到变量和文件
};
enum RequestType
{
GET = 10,
POST
};
protected:
string m_cookieFile;
string m_tmpDir;
string m_strUrl;
long m_connTimeout;
long m_timeout;
string m_strPost;
string m_pCaPath;
CURL* m_pCurl;
FILE* m_pFile;
string m_fileName;
string m_strResponse;
SaveType m_sType;
RequestType m_rType;
protected:
/// 写入回调函数(静态)
static size_t _handleWrite(void *buffer, size_t size, size_t nmemb, void *pfn);
/// 执行curl
size_t _run();
/// 写入回调函数
size_t onWrite(void *buffer, size_t size, size_t nmemb);
/// 打开文件
bool _openFile();
/// 关闭文件
bool _closeFile();
public:
/// 构造函数
DCurl();
///析构函数
~DCurl();
/// 设置libcurl选项
void setOption();
/// 下载文件
int httpDownload(const string & strUrl, const string & fileName, const RequestType rType = GET);
/// 普通请求
int httpRequest(const string & strUrl, const RequestType rType = GET, const bool toVar = false);
/// 超级请求
string httpSuperRequest(const string & strUrl, const RequestType rType = GET,
const SaveType sType = W_NONE, const string & fileName = "");
/// 获取执行结果
void getResponse(string & strResponse);
/// 设置Url地址
void setUrl(const string & strUrl = "");
/// 设置请求的类型, GET/POST
void setRequestType(RequestType rType = GET);
/// 设置要保存的文件名称(含路径)
void setFileName(const string & fileName = "");
/// 设置CA证书路径
void setCaPath(const string & pCaPath = "");
/// 设置超时时间
void setTimeout(const long connTimeout, const long timeout);
/// 设置Post数据
void setPostData(const string & postData);
/// 清空Cookie
bool cleanCookie();
};
#endif // DCURL_H_

View File

@ -1,15 +0,0 @@
#include "dir.h"
bool GetTmpDir(string & tmpDir)
{
#ifndef WIN32
tmpDir = "/tmp/";
return true;
#else
//#define MAX_PATH 260
char OutPath[MAX_PATH];
int StrLen = GetTempPath(MAX_PATH, OutPath);
tmpDir = OutPath;
return true;
#endif
}

View File

@ -1,15 +0,0 @@
#ifndef DIR_H_INCLUDED
#define DIR_H_INCLUDED
#include <string>
using std::string;
#include "global.h"
#ifdef WIN32
#include <windows.h>
#endif
bool GetTmpDir(string & tmpDir);
#endif // DIR_H_INCLUDED

View File

@ -1,37 +0,0 @@
#include <iostream>
#include <ctime>
#include "dlog.h"
DLog::DLog(const std::string & file)
{
pthread_mutex_init(&mutex_log, NULL);
logFileName = file;
//fout.open(logFileName, std::ios_base::out | std::ios_base::app);
}
DLog::~DLog()
{
pthread_mutex_destroy(&mutex_log);
//fout.close();
}
bool DLog::log(const std::string & str)
{
time_t t = time(0);
char timestr[64];
strftime(timestr, sizeof(timestr), "[%m/%d %H:%M:%S] ", localtime(&t));
pthread_mutex_lock(&mutex_log);
fout.open(logFileName, std::ios_base::out | std::ios_base::app);
if(!fout.is_open())
{
pthread_mutex_unlock(&mutex_log);
return false;
}
std::cout << timestr << " " << str << std::endl << std::flush;
fout << timestr << " " << str << std::endl << std::flush;
fout.close();
pthread_mutex_unlock(&mutex_log);
return true;
}

View File

@ -1,21 +0,0 @@
#ifndef DLOG_H_INCLUDED
#define DLOG_H_INCLUDED
#include <fstream>
#include <pthread.h>
class DLog
{
public:
DLog(const std::string & file = "/tmp/dlog.txt");
~DLog();
bool log(const std::string & str);
//bool clean();
//int getSize();
private:
std::fstream fout;
std::string logFileName;
pthread_mutex_t mutex_log;
};
#endif // DLOG_H_INCLUDED

View File

@ -1,296 +0,0 @@
#include "docr.h"
#include <iomanip>
struct my_error_mgr {
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
};
typedef struct my_error_mgr * my_error_ptr;
METHODDEF(void) my_error_exit (j_common_ptr cinfo)
{
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
my_error_ptr myerr = (my_error_ptr) cinfo->err;
/* Always display the message. */
/* We could postpone this until after returning, if we chose. */
(*cinfo->err->output_message) (cinfo);
/* Return control to the setjmp point */
longjmp(myerr->setjmp_buffer, 1);
}
static unsigned int LevenshteinDistance(const string & s, const string & t)
{
unsigned int cost;
// degenerate cases
if(s.length() == 0) return t.length();
if(t.length() == 0) return s.length();
if(s.length() == t.length() && s == t) return 0;
// create two work vectors of integer distances
std::vector<unsigned int> m(t.length() + 1);
std::vector<unsigned int> n(t.length() + 1);
// initialize v0 (the previous row of distances)
// this row is A[0][i]: edit distance for an empty s
// the distance is just the number of characters to delete from t
for(unsigned int i = 0; i < m.size(); i++) m[i] = i;
for (unsigned int i = 0; i < s.length(); i++)
{
// calculate v1 (current row distances) from the previous row v0
// first element of v1 is A[i+1][0]
// edit distance is delete (i+1) chars from s to match empty t
n[0] = i + 1;
// use formula to fill in the rest of the row
for (unsigned int j = 0; j < t.length(); j++)
{
cost = (s[i] == t[j]) ? 0 : 1;
//n[j + 1] = Minimum(n[j] + 1, m[j + 1] + 1, m[j] + cost);
n[j + 1] = n[j] + 1;
if((m[j + 1] + 1) < n[j + 1]) n[j + 1] = m[j + 1] + 1;
if((m[j] + cost) < n[j + 1]) n[j + 1] = m[j] + cost;
}
// copy v1 (current row) to v0 (previous row) for next iteration
for (unsigned int j = 0; j < m.size(); j++)
m[j] = n[j];
}
return n[t.length()];
}
double LevenshteinDistancePercent(const string & s, const string & t)
{
double percent = 0.0, len = 0.5 * (s.length() + t.length());
int step = (int)LevenshteinDistance(s, t);
if(step == 0) return percent = 100.0;
else
return percent = (len - step) / len;
}
DOcr::DOcr()
{
m_mode = JPEG_FILE;
_setKeys();
}
DOcr::~DOcr()
{
vector<JSAMPROW>::iterator t;
for(t = m_img_buf.begin(); t != m_img_buf.end(); t++)
free(*t);
//vector<JSAMPARRAY>().swap(m_img_buf);
}
int DOcr::_readJpeg(const string & str)
{
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
FILE * fp = NULL;
int row_stride;
if(m_mode == JPEG_FILE)
{
if ((fp = fopen(str.c_str(), "rb")) == NULL)
return -1;
}
/* We set up the normal JPEG error routines, then override error_exit. */
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
/* Establish the setjmp return context for my_error_exit to use. */
if (setjmp(jerr.setjmp_buffer))
{
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and return.
*/
jpeg_destroy_decompress(&cinfo);
fclose(fp);
return -3;
}
jpeg_create_decompress(&cinfo);
if(m_mode == JPEG_FILE)
jpeg_stdio_src(&cinfo, fp);
else if(m_mode == JPEG_MEM)
jpeg_mem_src(&cinfo, (unsigned char *)str.c_str(), str.size());
else
return -2;
(void) jpeg_read_header(&cinfo, TRUE);
(void) jpeg_start_decompress(&cinfo);
row_stride = cinfo.output_width * cinfo.output_components;
m_img_width = cinfo.output_width;
m_img_height = cinfo.output_height;
m_img_components = cinfo.output_components;
vector<JSAMPROW>::iterator t;
for(t = m_img_buf.begin(); t != m_img_buf.end(); t++)
delete(*t);
vector<JSAMPROW>().swap(m_img_buf);
while (cinfo.output_scanline < cinfo.output_height)
{
JSAMPROW buffer = new JSAMPLE[row_stride];
(void) jpeg_read_scanlines(&cinfo, &buffer, 1);
m_img_buf.push_back(buffer);
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
if(m_mode == JPEG_FILE)
fclose(fp);
return 1;
}
int DOcr::_writeJpeg(string & str, int quality)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * fp = NULL;
unsigned char *pBuf;
long unsigned int iLen = 0;
JSAMPROW row_pointer[1];
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
if(m_mode == JPEG_FILE)
{
if((fp = fopen(str.c_str(), "wb")) == NULL)
return -1;
jpeg_stdio_dest(&cinfo, fp);
}
else if(m_mode == JPEG_MEM)
{
jpeg_mem_dest(&cinfo, &pBuf, &iLen);
}
else
return -2;
cinfo.image_width = m_img_width; // image width and height, in pixels
cinfo.image_height = m_img_height;
cinfo.input_components = 3; // # of color components per pixel
cinfo.in_color_space = JCS_YCbCr; // colorspace of input image
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE); // limit to baseline-JPEG values
jpeg_start_compress(&cinfo, TRUE);
while(cinfo.next_scanline < cinfo.image_height)
{
row_pointer[0] = m_img_buf[cinfo.next_scanline];
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
jpeg_finish_compress(&cinfo);
if(m_mode == JPEG_FILE)
fclose(fp);
else if(m_mode == JPEG_MEM)
{
str.append((char *)pBuf, iLen);
}
jpeg_destroy_compress(&cinfo);
return 1;
}
void DOcr::_findCode(const string & s)
{
int i, index = 0;
double per, mPer = -1;
//cout << "相似度:" << endl;
//std::ios_base::fmtflags old = cout.flags();
//cout.setf(std::ios_base::fixed);
//cout.precision(2);
for(i = 0; i < (int)m_keys.size(); i++)
{
per = LevenshteinDistancePercent(s, m_keys[i]);
//cout << m_value[i] << ": " << per << "% \t";
//if(i % 5 == 4) cout << endl;
if(per > mPer)
{
mPer = per;
index = i;
}
}
//cout.flags(old);
m_code += m_value[index];
//cout << "m_code: " << m_code << endl;
}
void DOcr::setMode(OcrMode mode)
{
m_mode = mode;
}
bool DOcr::readImage(const string & str, OcrMode mode)
{
m_mode = mode;
if(_readJpeg(str) > 0)
return true;
else return false;
}
bool DOcr::writeImage(string & str, OcrMode mode)
{
m_mode = mode;
if(_writeJpeg(str, 100) > 0) // The quality value is expressed on the 0..100 scale
return true;
else return false;
}
bool DOcr::run()
{
int word_width = 9; //字符宽度,像素
int word_height = 13; //字符高度
int offset_x = 7; //x偏移
int offset_y = 3; //y偏移
int word_spacing = 4; //字符间隔
int x, y, h, w;
string word;
unsigned char * row = (unsigned char *)malloc(m_img_components * sizeof(unsigned char) * word_width);
m_code = ""; // 初始化验证码
for(int i = 0; i < 4; i++)
{
word = "";
x = i * (word_width + word_spacing) + offset_x;
y = offset_y;
for(h = y; h < (offset_y + word_height); h++)
{
memcpy((void *)row, (const void *)(m_img_buf[h] + x * m_img_components),
m_img_components * word_width);
for(w = 0; w < word_width * 3; w += 3)
{
if(row[w] < 150) word += '1';
else
word += '0';
}
}
_findCode(word);
}
return true;
}
void DOcr::getCode(string & code)
{
code = m_code;
return;
}

View File

@ -1,76 +0,0 @@
#ifndef DOCR_H_
#define DOCR_H_
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <memory.h>
#include "jpeglib.h"
#include "jerror.h"
#include "setjmp.h"
using std::vector;
using std::string;
using std::cout;
using std::endl;
class DOcr
{
public:
enum OcrMode
{
JPEG_FILE = 20,
JPEG_MEM
};
protected:
OcrMode m_mode;
int m_img_width;
int m_img_height;
int m_img_components;
vector<JSAMPROW> m_img_buf;
vector<string> m_keys;
vector<char> m_value;
string m_code;
int _readJpeg(const string & str);
int _writeJpeg(string & str, int quality);
void _setKeys();
void _findCode(const string & s);
public:
DOcr();
~DOcr();
void setMode(OcrMode mode);
bool readImage(const string & str, OcrMode mode = JPEG_FILE);
bool writeImage(string & str, OcrMode mode = JPEG_FILE);
bool run();
void getCode(string & code);
};
#endif // DOCR_H_
/* 注意如果libjpeg编译中出现
* error: conflicting types for 'jpeg_suppress_tables'
* jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
*
* #undef HAVE_PROTOTYPES
* #define HAVE_PROTOTYPES
*
*
* libjpeg由于configure脚本不正确配置导致出现
* conflicting declaration 'typedef short int UINT8'
* jconfig.h中把
* #undef HAVE_UNSIGNED_CHAR
* #undef HAVE_UNSIGNED_SHORT
*
* #define HAVE_UNSIGNED_CHAR
* #define HAVE_UNSIGNED_SHORT
* 使rebuild
* MinGW32
* define了这几个 HAVE_STDDEF_H HAVE_STDLIB_H
*
*/

View File

@ -1,154 +0,0 @@
#include "docr.h"
void DOcr::_setKeys()
{
m_value.push_back('0');
m_keys.push_back("000111000"
"011111110"
"011000110"
"110000011"
"110000011"
"110000011"
"110000011"
"110000011"
"110000011"
"110000011"
"011000110"
"011111110"
"000111000");
m_value.push_back('1');
m_keys.push_back("000111000"
"011111000"
"011111000"
"000011000"
"000011000"
"000011000"
"000011000"
"000011000"
"000011000"
"000011000"
"000011000"
"011111111"
"011111111");
m_value.push_back('2');
m_keys.push_back("011111000"
"111111100"
"100000110"
"000000110"
"000000110"
"000001100"
"000011000"
"000110000"
"001100000"
"011000000"
"110000000"
"111111110"
"111111110");
m_value.push_back('3');
m_keys.push_back("011111000"
"111111110"
"100000110"
"000000110"
"000001100"
"011111000"
"011111100"
"000001110"
"000000110"
"000000110"
"100001110"
"111111100"
"011111000");
m_value.push_back('4');
m_keys.push_back("000001100"
"000011100"
"000011100"
"000111100"
"001101100"
"001101100"
"011001100"
"011001100"
"111111111"
"111111111"
"000001100"
"000001100"
"000001100");
m_value.push_back('5');
m_keys.push_back("111111110"
"111111110"
"110000000"
"110000000"
"110000000"
"111110000"
"111111100"
"000001110"
"000000110"
"000000110"
"100001110"
"111111100"
"011111000");
m_value.push_back('6');
m_keys.push_back("000111100"
"001111110"
"011000010"
"011000000"
"110000000"
"110111100"
"111111110"
"111000111"
"110000011"
"110000011"
"011000111"
"011111110"
"000111100");
m_value.push_back('7');
m_keys.push_back("011111111"
"011111111"
"000000011"
"000000010"
"000000110"
"000001100"
"000001000"
"000011000"
"000010000"
"000110000"
"000110000"
"001100000"
"001100000");
m_value.push_back('8');
m_keys.push_back("001111100"
"011111110"
"011000110"
"011000110"
"011100100"
"001111100"
"001111100"
"011001110"
"110000011"
"110000011"
"111000111"
"011111110"
"001111100");
m_value.push_back('9');
m_keys.push_back("001111000"
"011111110"
"111000110"
"110000011"
"110000011"
"111000111"
"011111111"
"001111011"
"000000011"
"000000110"
"010000110"
"011111100"
"001111000");
}

View File

@ -1,451 +0,0 @@
#include <ctime>
#include <cstring>
#include "global.h"
#include "dpcap.h"
#include "adapter.h"
#include <iostream>
using std::cout;
using std::endl;
using std::string;
//static void ReSendStartPacket(int sig) // 定时器调用
//{
// return ;
//}
static void packet_handler(u_char *lp, const struct pcap_pkthdr* header, const u_char* pkt_data)
{
DPcap * dpcap = (DPcap *)lp;
if(dpcap) dpcap->pcapProc(header, pkt_data);
return;
}
DPcap::DPcap(MsgPass * msgPass)
{
ready = false;
isOpen = false;
canRun = false;
nextTime = -1;
message = "";
if(msgPass) this->msgPass = msgPass;
pthread_mutex_init(&mutex_status, NULL);
pthread_mutex_init(&mutex_msg, NULL);
}
DPcap::~DPcap()
{
pthread_mutex_destroy(&mutex_msg);
pthread_mutex_destroy(&mutex_status);
}
void DPcap::init(const std::string & user, const std::string & passwd, const std::string & adapterName)
{
uint8_t mac[6];
this->adapterName = adapterName;
GetMacAddress(adapterName.c_str(), mac); // 获取Mac地址
EapPacket::init(user, passwd, mac); // 交给基类初始化
ready = true;
//signal(SIGALRM, ReSendStartPacket); // //注册安装定时信号
// msg在基类声明定义, char msg[300]
sprintf(msg, "[Init] Interface: %s\n"
"\t\t [Init] MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n"
"\t\t [Init] 认证模块初始化完成...",
adapterName.c_str(), mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
setMessage(msg);
return;
}
// 打开Pcap设备
bool DPcap::open()
{
char name[100];
char FilterStr[100];
char errbuf[PCAP_ERRBUF_SIZE];
struct bpf_program fcode;
if(!ready) return false; // 防止未初始化调用
if(isOpen) return true; // 防止多次调用
AdapterNameToPcap(adapterName.c_str(), name);
if(!(adhandle = pcap_open_live(name, 65536, 1, 2000, errbuf)))
{
setStatus(EAP_ERROR);
sprintf(msg,"[Pcap Error] Unable to open the adapter. %s is not supported.", name);
setMessage(msg);
return false;
}
// -------------日志记录-------------- //
sprintf(msg,"[Pcap] 正在打开设备...");
setMessage(msg);
// ---------------End---------------- //
// 确保设备正确
if(pcap_datalink(adhandle) != DLT_EN10MB)
{
setStatus(EAP_ERROR);
sprintf(msg, "[Pcap Error] %s is not an Ethernet.", name);
setMessage(msg);
return false;
}
sprintf(FilterStr, "(ether proto 0x888e) and (ether dst host %02x:%02x:%02x:%02x:%02x:%02x)",
local_mac[0], local_mac[1], local_mac[2], local_mac[3], local_mac[4], local_mac[5]);
// -------------日志记录-------------- //
//sprintf(msg,"[Pcap] 正在设置过滤器...");
//setMessage(msg);
//if(msgPass) msgPass->signal();
// ---------------End---------------- //
// 编译过滤器
if(pcap_compile(adhandle, &fcode, FilterStr, 1, 0xff) < 0 )
{
setStatus(EAP_ERROR);
sprintf(msg,"[Pcap Error] Unable to compile the packet filter.");
setMessage(msg);
return false;
}
// 设置过滤器
if(pcap_setfilter(adhandle, &fcode) < 0)
{
setStatus(EAP_ERROR);
sprintf(msg,"[Pcap Error] Error setting the filter.");
setMessage(msg);
return false;
}
canRun = true;
return isOpen = true;
}
//运行
void DPcap::run()
{
sendPacket(EapType::EAPOL_START);
pcap_loop(adhandle, 0, packet_handler, (u_char *)this);
}
bool DPcap::close()
{
pcap_close(adhandle);
isOpen = false;
canRun = false;
return true;
}
void DPcap::pcapProc(const struct pcap_pkthdr* packetinfo, const u_char* packet)
{
preRun = time(0);
this->packet = (uint8_t *)packet;
this->eap_head = (struct eap_header*)(packet + SIZE_ETHERNET);
processPacket(); // 处理报文数据
}
void DPcap::processPacket()
{
EapType type;
if(!canRun) return; // 判断是否可以处理服务器发来的报文
type = (EapType)getEapType();
if(type == EAP_ERROR) return;
std::string tmp = "";
string::size_type pos;
switch(type)
{
case EAPOL_START:
// 此类型的报文是发出去的,不会由服务器发来
// 此处在必要的时候用来调试发包是否成功
break;
case EAPOL_LOGOFF:
notificationMessage();
tmp = "[Logoff] ";
tmp.append(msg);
setMessage(tmp);
setStatus(EAPOL_LOGOFF);
// 把消息记录进日志
break;
case EAP_SUCCESS:
//suspend(1); // 成功的报文不需要回复,腾出时间给其他线程记录日志
setMessage("[Success] 中兴802.1X认证登录成功!");
setStatus(EAP_SUCCESS);
break;
case EAP_FAILURE:
severInfo();
tmp = msg; // 临时保存下msg的内容
if((pos = tmp.find(":")) != string::npos)
tmp = tmp.substr(pos + 1); // 截取冒号后面的字符串
else
tmp = "";
if(tmp.length() > 0) {
sprintf(msg, "[Failure] 认证失败,%s。将在%d秒后重试。", tmp.c_str(), getSuspendTime(false));
} else {
sprintf(msg, "[Failure] 认证失败,原因未知。将在%d秒后重试。", getSuspendTime(false));
}
tmp = msg;
setMessage(tmp);
setStatus(EAP_FAILURE);
//suspend(1); // 暂停1s让出cpu时间记录下日志注意suspend后会设置canRun为true
canRun = false;
setSuspend(); // 收到认证失败的包之后,一段时间再重试
//eapFailure();
break;
case EAP_REQUEST_IDENTITY:
responseIdentity();
sendPacket(EAP_RESPONSE_IDENTITY);
break;
case EAP_REQUEST_MD5_CHALLENGE:
responseMd5Challenge();
sendPacket(EAP_RESPONSE_MD5_CHALLENGE);
break;
case ZTE_EAPOL_MSG:
notificationMessage();
tmp = "[Notification] ";
tmp.append(msg);
//setMessage(tmp); // 由于failure通知也有相关信息必要时可屏蔽notification通知
setStatus(ZTE_EAPOL_MSG);
break;
case EAP_KEEP_ALIVE:
keepAlive();
sendPacket(EAP_RESPONSE_IDENTITY_KEEP_ALIVE);
break;
default:
break;
}
}
// 发送数据包
int DPcap::sendPacket(enum EapType send_type)
{
#ifdef DEBUG
static int cnt = 0;
#endif
static uint8_t* frame_data;
int frame_len = 0;
if(!canRun) return 0;
preRun = time(0);
std::string tmp;
switch(send_type)
{
case EAPOL_START:
frame_data = eapol_start;
frame_len = sizeof(eapol_start);
setMessage("[Start] 开始中兴802.1X认证...");
setStatus(EAPOL_START);
break;
case EAPOL_LOGOFF:
frame_data = eapol_logoff;
frame_len = sizeof(eapol_logoff);
setMessage("[Cancel] 正在取消中兴认证登录...");
setStatus(EAPOL_LOGOFF);
break;
case EAP_RESPONSE_IDENTITY:
frame_data = eap_response_ident;
frame_len = sizeof(eap_response_ident);
#ifdef DEBUG
setMessage("[Identity] 向服务器发送用户名...");
#endif
break;
case EAP_RESPONSE_MD5_CHALLENGE:
frame_data = eap_response_md5ch;
frame_len = sizeof(eap_response_md5ch);
#ifdef DEBUG
setMessage("[Md5Challenge] 正在验证身份...");
#endif
break;
case EAP_RESPONSE_IDENTITY_KEEP_ALIVE:
frame_data = eap_life_keeping;
frame_len = sizeof(eap_life_keeping);
#ifdef DEBUG
if(cnt++ % 20 == 1) setMessage("[Keep Alive] 中兴心跳包...");
#endif
break;
default:
return 3;
break;
}
if(pcap_sendpacket(adhandle, frame_data, frame_len) != 0)
{
//sprintf(msg, "Error Sending the packet: %s\n", pcap_geterr(adhandle));
tmp = "[Error] Sending the packet: ";
tmp.append(pcap_geterr(adhandle));
setMessage(tmp);
setStatus(EAP_ERROR);
setSuspend();
return 0;
}
return 1;
}
int DPcap::getEapType()
{
if (eap_head->eapol_t == EAP_KEY)
return EAP_KEEP_ALIVE;
switch (eap_head->eap_t)
{
case 0x00:
if (eap_head->eap_op == 0x1c &&
eap_head->eap_id == 0x00)
return ZTE_EAPOL_MSG;
break;
case 0x01:
if (eap_head->eap_op == 0x01)
return EAP_REQUEST_IDENTITY;
if (eap_head->eap_op == 0x02)
return ZTE_EAPOL_MSG;
if (eap_head->eap_op == 0x04)
return EAP_REQUEST_MD5_CHALLENGE;
break;
case 0x03:
return EAP_SUCCESS;
break;
case 0x04:
return EAP_FAILURE;
break;
default:
return -1;
}
return -1;
}
std::string DPcap::getAdapterName()
{
return adapterName;
}
int DPcap::getStatus()
{
int s = 0;
pthread_mutex_lock(&mutex_status);
s = status;
pthread_mutex_unlock(&mutex_status);
return s;
}
void DPcap::setStatus(EapType type)
{
pthread_mutex_lock(&mutex_status);
status = type;
pthread_mutex_unlock(&mutex_status);
return;
}
void DPcap::setStatusAndRun(EapType type)
{
switch(type)
{
case EAPOL_START:
canRun = true;
sendPacket(EapType::EAPOL_START);
break;
case EAPOL_LOGOFF:
sendPacket(EapType::EAPOL_LOGOFF);
canRun = false;
break;
case EAP_FAILURE:
canRun = false;
break;
default:
break;
}
}
void DPcap::setMessage(const std::string & msg)
{
pthread_mutex_lock(&mutex_msg);
message = msg;
if(msgPass) msgPass->signal();
pthread_mutex_unlock(&mutex_msg);
return;
}
std::string DPcap::getMessage()
{
pthread_mutex_lock(&mutex_msg);
std::string str = message;
pthread_mutex_unlock(&mutex_msg);
return str;
}
bool DPcap::suspend(int s)
{
canRun = false;
if(s <= 0) return true;
#ifndef WIN32
::sleep(s);
#else
::Sleep(s * 1000);
#endif
canRun = true;
return true;
}
void DPcap::setSuspend()
{
int s = getSuspendTime(true);
//char info[100];
//sprintf(info, "[Message] 认证失败,将在%d秒后重试...", s);
//setMessage(info);
//if(msgPass) msgPass->signal();
if(s == 0) // 0秒立即
{
canRun = true;
setStatusAndRun(EapType::EAPOL_START);
}else
{
canRun = false;
//alarm(s); //触发定时器
setReSendTime(s);
}
return ;
}
// 认证出错时,重试的间隔时间算法
int DPcap::getSuspendTime(bool increase) // 如果increase是false(默认),重试的时间不会增长
{
static time_t preTime = 0;
static int k = 0;
time_t now = time(0);
const int rank[9] = {0, 5, 15, 30, 65, 300, 600, 900, 1200}; // 各个等级需要暂停的时间
int rVal = 0;
long interval = now - preTime;
if(interval > 1800 || k < 0) k = 0;
rVal = rank[k];
if(increase)
{
if(k < 8) k++;
preTime = now;
}
return rVal;
}
bool DPcap::getRunStatus()
{
return canRun;
}
long DPcap::getPreRVal()
{
time_t now = time(0);
return (now - preRun);
}
void DPcap::setReSendTime(int s)
{
this->nextTime = time(0) + s;
}
time_t DPcap::getReSendTime()
{
time_t t;
t = this->nextTime;
this->nextTime = -1;
return t;
}

View File

@ -1,95 +0,0 @@
#ifndef DPCAP_H_
#define DPCAP_H_
#include <ctime>
#include <string>
#include <pthread.h>
//#include <signal.h>
#include "global.h"
#include "msgpass.h"
#include "eappacket.h"
class DPcap : public EapPacket
{
public:
enum EapType // 消息类型
{
EAPOL_START = 1, // EAPOL START
EAPOL_LOGOFF, // EAPOL LOGOFF
EAP_REQUEST_IDENTITY, // EAP Request, Identity
EAP_RESPONSE_IDENTITY, // EAP Response, Identity
EAP_REQUEST_IDENTITY_KEEP_ALIVE, //
EAP_RESPONSE_IDENTITY_KEEP_ALIVE, //
EAP_REQUEST_MD5_CHALLENGE, // EAP Request, MD5-Challenge
EAP_RESPONSE_MD5_CHALLENGE, // EAP Response, MD5-Challenge
EAP_SUCCESS, // EAP Success
EAP_FAILURE, // EAP Failure
EAP_KEEP_ALIVE, // EAPOL Key
ZTE_EAPOL_MSG, // EAP Request, Notification
EAP_ERROR, //
ZTE_MORE_MSG
};
enum ErrorType
{
UNKOWN = 0,
ZTE_021 = 021, // 多网卡错误
ZTE_100 = 100, // 未知错误
ZTE_101 = 101, // 不存在的用户
ZTE_102 = 102, // 密码错误
ZTE_109 = 109, // 非私有认证 10s
ZTE_110 = 110, // 用户在线限制 60s
ZTE_207 = 207, // 没有接入权限
};
enum EapolType
{
EAP_PACKET = 0,
//EAPOL_START = 1,
//EAPOL_LOGOFF = 2,
EAP_KEY = 3
};
DPcap(MsgPass * msgPass = (MsgPass *)NULL);
~DPcap();
void pcapProc(const struct pcap_pkthdr* packet_header, const u_char* pkt_data);
void init(const std::string & user, const std::string & passwd,
const std::string & adapterName);
bool open();
void run();
bool close();
int sendPacket(EapType send_type);
int getStatus();
void setStatus(EapType type);
void setStatusAndRun(EapType type);
void setMessage(const std::string & msg);
std::string getMessage();
int getEapType();
std::string getAdapterName();
bool getRunStatus();
long getPreRVal(); // 获取上次到调用时,与服务器上次交互认证信息的间隔时间
time_t getReSendTime(); // 获取下一次发送start包的时间获取之后如果没有新的再次获取会得到一个负数
void setReSendTime(int s); //参数是秒数,重新发包的时间为当前时间+秒数
protected:
bool ready; // 报文信息初始化状态
bool isOpen; // pcap状态
EapType status; // Pcap执行情况
bool canRun; // 收到包时是否回复
MsgPass * msgPass; // 日志记录
time_t preRun; // 服务器最后发包时间
time_t nextTime; // 下一次重新发包时间
std::string message; // 暂时存放的消息
pthread_mutex_t mutex_status;
pthread_mutex_t mutex_msg;
bool suspend(int s);
void setSuspend();
int getSuspendTime(bool increase = false);
void processPacket();
private:
pcap_t *adhandle;
std::string adapterName;
};
#endif // DPCAP_H_

View File

@ -1,239 +0,0 @@
#include <memory.h>
#include "global.h"
#include "eappacket.h"
#include "encrypt.h"
#include "conv/conv.h"
EapPacket::EapPacket()
{
//ZTE认证服务器多播地址
muticast_mac[0] = 0x01;
muticast_mac[1] = 0x80;
muticast_mac[2] = 0xc2;
muticast_mac[3] = 0x00;
muticast_mac[4] = 0x00;
muticast_mac[5] = 0x03;
// 初始化各个报文数组
memset(eapol_start, 0, sizeof(eapol_start));
memset(eapol_logoff, 0, sizeof(eapol_logoff));
memset(eap_response_ident, 0, sizeof(eap_response_ident));
memset(eap_response_md5ch, 0, sizeof(eap_response_md5ch));
memset(eap_life_keeping, 0, sizeof(eap_life_keeping));
// EAPOL Start
uint8_t start_data[4] = {0x01, 0x01, 0x00, 0x00};
memcpy(eapol_start + OFFSET_EAPOL, start_data, sizeof(start_data));
// EAPOL Logoff
uint8_t logoff_data[4] = {0x01, 0x02, 0x00, 0x00};
memcpy(eapol_logoff + OFFSET_EAPOL, logoff_data, sizeof(logoff_data));
// EAP RESPONSE IDENTITY
uint8_t resp_iden_head[9] =
{ 0x01, // Version: 802.1X-2001 (1)
0x00, // Type: EAP Packet (0)
0x00, 0x00, // Length: 00 (eapol_length, 以后填充)
0x02, // Code: Response (2)
0x00, // Id: 0 (以后填充, 可不填)
0x00, 0x00, // Length: 00 (eap_length, 以后填充)
0x01 // Type: Identity (1)
};
memcpy(eap_response_ident + SIZE_ETHERNET, resp_iden_head, 9);
// EAP RESPONSE MD5 Challenge
uint8_t resp_md5_head[10] =
{
0x01, // Version: 802.1X-2001 (1)
0x00, // Type: EAP Packet (0)
0x00, 0x00, // Length: 00 (eapol_length, 以后填充)
0x02, // Code: Response (2)
0x00, // Id: 0 (以后填充, 可不填)
0x00, 0x00, // Length: 00 (eap_length, 以后填充)
0x04, 0x10 // Expert Info (以后填充)
};
memcpy(eap_response_md5ch + SIZE_ETHERNET, resp_md5_head, 10);
// EAP Key
uint8_t keep_alive[52] = {
0x01, // Version: 802.1X-2001 (1)
0x03, // Type: Key (3)
0x00, 0x30, // Length: 30
0x01, // Key Descriptor Type: RC4 Descriptor (1)
0x00, 0x04, // Key Length: 4
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Replay Counter: 8字节
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 16字节的Key IV 前8字节
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 16字节的Key IV 后8字节
0x00, // Key Index: 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 16字节的Key Signature 前8字节
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 16字节的Key Signature 后8字节
0x00, 0x00, 0x00, 0x00 // 4字节的Key
};
memcpy(eap_life_keeping + SIZE_ETHERNET, keep_alive, 52);
}
EapPacket::~EapPacket()
{
}
void EapPacket::init(const std::string & user, const std::string & passwd, uint8_t* mac)
{
// 初始化用户名和密码
this->user = user;
this->passwd = passwd;
// 初始化mac
memset(local_mac, 0, ETHER_ADDR_LEN);
memcpy(local_mac, mac, ETHER_ADDR_LEN);
// 初始化Ethernet II Header
uint8_t eapol_eth_header[SIZE_ETHERNET];
struct ether_header * eth = (struct ether_header*)eapol_eth_header;
memcpy(eth->ether_dhost, muticast_mac, ETHER_ADDR_LEN); // 填充中兴认证多播地址
memcpy(eth->ether_shost, local_mac, ETHER_ADDR_LEN); // 填充本地MAC
eth->ether_type = htons(0x888e); // 填充协议类型0x888e是EAP协议
// 各个报文填入Ethernet II Header
memcpy(eapol_start, eapol_eth_header, SIZE_ETHERNET);
memcpy(eapol_logoff, eapol_eth_header, SIZE_ETHERNET);
memcpy(eap_response_ident, eapol_eth_header, SIZE_ETHERNET);
memcpy(eap_response_md5ch, eapol_eth_header, SIZE_ETHERNET);
memcpy(eap_life_keeping, eapol_eth_header, SIZE_ETHERNET);
// 完善EAP RESPONSE IDENTITY报文信息
eap_response_ident[SIZE_ETHERNET + 3] = 5 + (uint8_t)user.length();
eap_response_ident[SIZE_ETHERNET + 7] = 5 + (uint8_t)user.length();
memcpy(eap_response_ident + SIZE_ETHERNET + 9, user.c_str(), user.length());
// 完善EAP RESPONSE MD5 Challenge报文信息
eap_response_md5ch[SIZE_ETHERNET + 3] = 22 + (uint8_t)user.length();
eap_response_md5ch[SIZE_ETHERNET + 7] = 22 + (uint8_t)user.length();
memcpy(eap_response_md5ch + SIZE_ETHERNET + 10 + 16, user.c_str(), user.length());
// 完善Frame check sequence
int data_len;
unsigned char *checksum;
data_len = sizeof(eapol_start) - 4;
checksum = Get_CRC32(eapol_start, data_len); // CRC32运算
memcpy(eapol_start + data_len, checksum, 4); // 写入FCS校验码
data_len = sizeof(eapol_logoff) - 4;
checksum = Get_CRC32(eapol_logoff, data_len); // CRC32运算
memcpy(eapol_logoff + data_len, checksum, 4); // 写入FCS校验码
}
//int EapPacket::getEapType(){}
void EapPacket::eapSuccess()
{
// TODO(Zeyes) : 之后处理状态的时候用
}
void EapPacket::eapFailure()
{
// TODO(Zeyes) : 之后处理状态的时候用
}
void EapPacket::responseIdentity()
{
eap_response_ident[0x13] = eap_head->eap_id;
int data_len;
unsigned char *checksum;
data_len = sizeof(eap_response_ident) - 4;
checksum = Get_CRC32(eap_response_ident, data_len); // CRC32运算
memcpy(eap_response_ident + data_len, checksum, 4); // 写入FCS校验码
}
void EapPacket::responseMd5Challenge()
{
// MD5摘要 = MD5(REQ/MD5包ID + 用户密码 + "zte142052" + EAP-MD5 Value)
char text[] = "zte142052";
char* data = (char*)malloc((1 + passwd.length() + 9 + 16) * sizeof(char));
data[0] = eap_head->eap_id;
memcpy(data + 1, passwd.c_str(), passwd.length());
memcpy(data + 1 + passwd.length(), text, 9);
memcpy(data + 1 + passwd.length() + 9, eap_head->eap_md5_challenge, 16);
unsigned char * digest;
digest = Get_Md5_Digest((unsigned char *)data, 1 + passwd.length() + 9 + 16);
memcpy(eap_response_md5ch + 14 + 10, digest, 16);
eap_response_md5ch[0x13] = eap_head->eap_id;
free(data);
int data_len = sizeof(eap_response_md5ch) - 4;
unsigned char *checksum;
checksum = Get_CRC32(eap_response_md5ch, data_len); // CRC32运算
memcpy(eap_response_md5ch + data_len, checksum, 4); // 写入FCS校验码
}
void EapPacket::keepAlive()
{
memcpy(eap_life_keeping + 21, packet + 21, 25); // Replay Counter + Key IV + Key Index
// 使用rc4算法生成Key基于Key IV + Key IV最后四个字节== 20字节
uint8_t enckey[] = { 0x02, 0x02, 0x14, 0x00 }; // 要加密的数据,固定
uint8_t wholekey[20]; // 加密秘钥
memcpy(wholekey, packet + 29, 16);
memcpy(wholekey + 16, packet + 41, 4);
Get_RC4(enckey, 4, wholekey, 20); // 进行RC4运算
memcpy(eap_life_keeping + 62, enckey, 4);
// 使用hmac_md5算法生成Key Signature此用于包的校验
u_char encDat[64];
unsigned char * deckey;
memset(eap_life_keeping + 46, 0, 16); // Key Signature的部分先填充0
memcpy(encDat, eap_life_keeping + 14, 52); // 要加密的数据
enckey[0] = eap_life_keeping[45]; // 加密秘钥
deckey = Get_Hmac_Md5_Digest(encDat, 52, enckey, 1); // 进行HmacMD5运算
memcpy(eap_life_keeping + 46, deckey, 16);
int data_len = sizeof(eap_life_keeping) - 4;
unsigned char *checksum;
checksum = Get_CRC32(eap_life_keeping, data_len); // CRC32运算
memcpy(eap_life_keeping + data_len, checksum, 4); // 写入FCS校验码
}
void EapPacket::notificationMessage()
{
char msg_length[2] = { 0 };
int length;
memcpy(msg_length, (packet + 20), 2);
length = (int)(msg_length[0] * 10 + msg_length[1]) - 5;
if (length > 0) {
memcpy(msg, (packet + 23), length);
msg[length] = '\0';
#ifdef DEBUG
//PrintHex((unsigned char *)msg, strlen(msg));
#endif
const char * tmp = g2u(msg); // 将GBK编码转成UTF-8
memcpy((void *)msg, (void *)tmp, strlen(tmp) + 1);
}
else
memset(msg, 0, sizeof(msg));
}
void EapPacket::severInfo()
{
char msg_length[2] = {0};
int length;
memcpy(msg_length, (packet + 20), 2);
length = (int)(msg_length[0] * 10 + msg_length[1]) - 6;
if(length > 0)
{
memcpy(msg, (packet + 24), length);
if(msg[9] == '\0' && msg[10] != '\0') msg[9] = ':';
msg[length] = '\0';
#ifdef DEBUG
//PrintHex((unsigned char *)msg, strlen(msg));
#endif
const char * tmp = g2u(msg); // 将GBK编码转成UTF-8
memcpy((void *)msg, (void *)tmp, strlen(tmp) + 1);
}
else
memset(msg, 0, sizeof(msg));
}

View File

@ -1,74 +0,0 @@
#ifndef DPACKET_H_
#define DPACKET_H_
#include <cstdint>
#include <string>
/* default snap length (maximum bytes per packet to capture) */
#define SNAP_LEN 1518
/* ethernet headers are always exactly 14 bytes */
#define SIZE_ETHERNET 14
#define OFFSET_EAPOL 0X0E
#define OFFSET_EAP 0X12
#define ETHER_ADDR_LEN 6
class EapPacket
{
public:
EapPacket();
~EapPacket();
void init(const std::string & user, const std::string & passwd, uint8_t* mac);
//int getEapType();
void eapSuccess();
void eapFailure();
void responseIdentity();
void responseMd5Challenge();
void keepAlive();
void notificationMessage();
void severInfo();
protected:
uint8_t eapol_start[64]; // EAPOL Start 报文,18
uint8_t eapol_logoff[64]; // EAPOL LogOff 报文,18
uint8_t eap_response_ident[64]; // EAP RESPON/IDENTITY报文,23+userlen
uint8_t eap_response_md5ch[64]; // EAP RESPON/MD5 报文,40+userlen
uint8_t eap_life_keeping[70]; // EAP Key 报文,66
struct ether_header // Ethernet II Header
{
uint8_t ether_dhost[ETHER_ADDR_LEN]; // Destionation
uint8_t ether_shost[ETHER_ADDR_LEN]; // Source
uint16_t ether_type; // Type
};
struct eap_header
{
uint8_t eapol_v; // Version
uint8_t eapol_t; // Type
uint16_t eapol_length; // Length
uint8_t eap_t;
uint8_t eap_id;
uint16_t eap_length;
uint8_t eap_op;
uint8_t eap_v_length;
uint8_t eap_md5_challenge[16];
};
std::string user; // 用户名
std::string passwd; // 密码
uint8_t muticast_mac[ETHER_ADDR_LEN]; // 认证服务器多播地址
uint8_t local_mac[ETHER_ADDR_LEN]; // 本机网卡mac地址
struct eap_header * eap_head;
uint8_t * packet;
char msg[300]; // 服务器信息
};
#endif // DPACKET_H_

View File

@ -1,43 +0,0 @@
#include "encrypt.h"
#include "encrypt/md5.h"
#include "encrypt/rc4.h"
#include "encrypt/crc32.h"
#include "encrypt/base64.h"
unsigned char* Get_Md5_Digest(unsigned char* str, int len)
{
static unsigned char digest[16];
md5(str, len, digest);
return digest;
}
unsigned char* Get_Hmac_Md5_Digest(unsigned char* text, int text_len, unsigned char* key, int key_len)
{
static unsigned char digest[16];
hmac_md5(text, text_len, key, key_len, digest);
return digest;
}
unsigned char* Get_RC4(unsigned char *data, int data_len, unsigned char *key, int key_len)
{
rc4_crypt(data, data_len, key, key_len);
return data;
}
unsigned char* Get_CRC32(unsigned char *data, int data_len)
{
static unsigned char checksum[4];
unsigned int result;
result = crc32(data, data_len);
checksum[0] = result & 0xff;
checksum[1] = (result >> 8) & 0xff;
checksum[2] = (result >> 16) & 0xff;
checksum[3] = (result >> 24) & 0xff;
return checksum;
}
int Get_Base64_Encode(const unsigned char *data, int data_len, unsigned char * output)
{
base64_encode(data, data_len, (char *)output);
return BASE64_ENCODE_OUT_SIZE(data_len); // 返回加密后的字符串长度
}

View File

@ -1,10 +0,0 @@
#ifndef ENCRYPT_H_
#define ENCRYPT_H_
unsigned char* Get_Md5_Digest(unsigned char* str, int len);
unsigned char* Get_Hmac_Md5_Digest(unsigned char* text, int text_len, unsigned char* key, int key_len);
unsigned char* Get_RC4(unsigned char *data, int data_len, unsigned char *key, int key_len);
unsigned char* Get_CRC32(unsigned char *data, int data_len);
int Get_Base64_Encode(const unsigned char *data, int data_len, unsigned char * output);
#endif // ENCRYPT_H_

View File

@ -1,135 +0,0 @@
/* This is a public domain base64 implementation written by WEI Zhicheng. */
#include <stdio.h>
#include "base64.h"
/* BASE 64 encode table */
static const char base64en[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/',
};
#define BASE64_PAD '='
#define BASE64DE_FIRST '+'
#define BASE64DE_LAST 'z'
/* ASCII order for BASE 64 decode, -1 in unused character */
static const signed char base64de[] = {
/* '+', ',', '-', '.', '/', '0', '1', '2', */
62, -1, -1, -1, 63, 52, 53, 54,
/* '3', '4', '5', '6', '7', '8', '9', ':', */
55, 56, 57, 58, 59, 60, 61, -1,
/* ';', '<', '=', '>', '?', '@', 'A', 'B', */
-1, -1, -1, -1, -1, -1, 0, 1,
/* 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', */
2, 3, 4, 5, 6, 7, 8, 9,
/* 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', */
10, 11, 12, 13, 14, 15, 16, 17,
/* 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', */
18, 19, 20, 21, 22, 23, 24, 25,
/* '[', '\', ']', '^', '_', '`', 'a', 'b', */
-1, -1, -1, -1, -1, -1, 26, 27,
/* 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', */
28, 29, 30, 31, 32, 33, 34, 35,
/* 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', */
36, 37, 38, 39, 40, 41, 42, 43,
/* 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', */
44, 45, 46, 47, 48, 49, 50, 51,
};
int
base64_encode(const unsigned char *in, unsigned int inlen, char *out)
{
unsigned int i, j;
for (i = j = 0; i < inlen; i++) {
int s = i % 3; /* from 6/gcd(6, 8) */
switch (s) {
case 0:
out[j++] = base64en[(in[i] >> 2) & 0x3F];
continue;
case 1:
out[j++] = base64en[((in[i-1] & 0x3) << 4) + ((in[i] >> 4) & 0xF)];
continue;
case 2:
out[j++] = base64en[((in[i-1] & 0xF) << 2) + ((in[i] >> 6) & 0x3)];
out[j++] = base64en[in[i] & 0x3F];
}
}
/* move back */
i -= 1;
/* check the last and add padding */
if ((i % 3) == 0) {
out[j++] = base64en[(in[i] & 0x3) << 4];
out[j++] = BASE64_PAD;
out[j++] = BASE64_PAD;
} else if ((i % 3) == 1) {
out[j++] = base64en[(in[i] & 0xF) << 2];
out[j++] = BASE64_PAD;
}
return BASE64_OK;
}
int
base64_decode(const char *in, unsigned int inlen, unsigned char *out)
{
unsigned int i, j;
for (i = j = 0; i < inlen; i++) {
int c;
int s = i % 4; /* from 8/gcd(6, 8) */
if (in[i] == '=')
return BASE64_OK;
if (in[i] < BASE64DE_FIRST || in[i] > BASE64DE_LAST ||
(c = base64de[in[i] - BASE64DE_FIRST]) == -1)
return BASE64_INVALID;
switch (s) {
case 0:
out[j] = ((unsigned int)c << 2) & 0xFF;
continue;
case 1:
out[j++] += ((unsigned int)c >> 4) & 0x3;
/* if not last char with padding */
if (i < (inlen - 3) || in[inlen - 2] != '=')
out[j] = ((unsigned int)c & 0xF) << 4;
continue;
case 2:
out[j++] += ((unsigned int)c >> 2) & 0xF;
/* if not last char with padding */
if (i < (inlen - 2) || in[inlen - 1] != '=')
out[j] = ((unsigned int)c & 0x3) << 6;
continue;
case 3:
out[j++] += (unsigned char)c;
}
}
return BASE64_OK;
}

View File

@ -1,25 +0,0 @@
#ifndef __BASE64_H__
#define __BASE64_H__
enum {BASE64_OK = 0, BASE64_INVALID};
#define BASE64_ENCODE_OUT_SIZE(s) (((s) + 2) / 3 * 4)
#define BASE64_DECODE_OUT_SIZE(s) (((s)) / 4 * 3)
#ifdef __cplusplus
extern "C" {
#endif
int
base64_encode(const unsigned char *in, unsigned int inlen, char *out);
int
base64_decode(const char *in, unsigned int inlen, unsigned char *out);
#ifdef __cplusplus
}
#endif
#endif /* __BASE64_H__ */

View File

@ -1,23 +0,0 @@
#define POLYNOMIAL 0xEDB88320
static unsigned int table[256];
static int have_table = 0;
void make_table()
{
int i, j;
have_table = 1;
for (i = 0; i < 256; i++)
for (j = 0, table[i] = i; j < 8; j++)
table[i] = (table[i] >> 1) ^ ((table[i] & 1) ? POLYNOMIAL : 0);
}
unsigned int crc32(unsigned char *data, int len)
{
int i;
unsigned int crc = 0xFFFFFFFF;
if(!have_table) make_table();
for (i = 0; i < len; i++)
crc = (crc >> 8) ^ table[(crc ^ data[i]) & 0xFF];
return ~crc;
}

View File

@ -1,14 +0,0 @@
#ifndef CRC32_H_INCLUDED
#define CRC32_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
unsigned int crc32(unsigned char *data, int len);
#ifdef __cplusplus
}
#endif
#endif // CRC32_H_INCLUDED

View File

@ -1,412 +0,0 @@
/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
*/
/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.
License to copy and use this software is granted provided that it
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
Algorithm" in all material mentioning or referencing this software
or this function.
License is also granted to make and use derivative works provided
that such works are identified as "derived from the RSA Data
Security, Inc. MD5 Message-Digest Algorithm" in all material
mentioning or referencing the derived work.
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
These notices must be retained in any copies of any part of this
documentation and/or software.
*/
//#include "global.h"
#include "md5.h"
/* Constants for MD5Transform routine.
*/
#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
static void Decode PROTO_LIST
((UINT4 *, unsigned char *, unsigned int));
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
static unsigned char PADDING[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/* F, G, H and I are basic MD5 functions.
*/
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits.
*/
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
Rotation is separate from addition to prevent recomputation.
*/
#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
void MD5Init (context)
MD5_CTX *context; /* context */
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
}
/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
void MD5Update (context, input, inputLen)
MD5_CTX *context; /* context */
unsigned char *input; /* input block */
unsigned int inputLen; /* length of input block */
{
unsigned int i, index, partLen;
/* Compute number of bytes mod 64 */
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
if ((context->count[0] += ((UINT4)inputLen << 3))
< ((UINT4)inputLen << 3))
context->count[1]++;
context->count[1] += ((UINT4)inputLen >> 29);
partLen = 64 - index;
/* Transform as many times as possible.
*/
if (inputLen >= partLen) {
MD5_memcpy
((POINTER)&context->buffer[index], (POINTER)input, partLen);
MD5Transform (context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
MD5Transform (context->state, &input[i]);
index = 0;
}
else
i = 0;
/* Buffer remaining input */
MD5_memcpy
((POINTER)&context->buffer[index], (POINTER)&input[i],
inputLen-i);
}
/* MD5 finalization. Ends an MD5 message-digest operation, writing the
the message digest and zeroizing the context.
*/
void MD5Final (digest, context)
unsigned char digest[16]; /* message digest */
MD5_CTX *context; /* context */
{
unsigned char bits[8];
unsigned int index, padLen;
/* Save number of bits */
Encode (bits, context->count, 8);
/* Pad out to 56 mod 64.
*/
index = (unsigned int)((context->count[0] >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
MD5Update (context, PADDING, padLen);
/* Append length (before padding) */
MD5Update (context, bits, 8);
/* Store state in digest */
Encode (digest, context->state, 16);
/* Zeroize sensitive information.
*/
MD5_memset ((POINTER)context, 0, sizeof (*context));
}
/* MD5 basic transformation. Transforms state based on block.
*/
static void MD5Transform (state, block)
UINT4 state[4];
unsigned char block[64];
{
UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
Decode (x, block, 64);
/* Round 1 */
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
/* Zeroize sensitive information.
*/
MD5_memset ((POINTER)x, 0, sizeof (x));
}
/* Encodes input (UINT4) into output (unsigned char). Assumes len is
a multiple of 4.
*/
static void Encode (output, input, len)
unsigned char *output;
UINT4 *input;
unsigned int len;
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (unsigned char)(input[i] & 0xff);
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
}
}
/* Decodes input (unsigned char) into output (UINT4). Assumes len is
a multiple of 4.
*/
static void Decode (output, input, len)
UINT4 *output;
unsigned char *input;
unsigned int len;
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
}
/* Note: Replace "for loop" with standard memcpy if possible.
*/
static void MD5_memcpy (output, input, len)
POINTER output;
POINTER input;
unsigned int len;
{
unsigned int i;
for (i = 0; i < len; i++)
output[i] = input[i];
}
/* Note: Replace "for loop" with standard memset if possible.
*/
static void MD5_memset (output, value, len)
POINTER output;
int value;
unsigned int len;
{
unsigned int i;
for (i = 0; i < len; i++)
((char *)output)[i] = (char)value;
}
void md5(unsigned char* str, int len, unsigned char* digest)
{
MD5_CTX context;
MD5Init(&context);
MD5Update(&context, (unsigned char *)str, len);
MD5Final(digest, &context);
}
void hmac_md5(unsigned char* text, int text_len, unsigned char* key, int key_len, unsigned char* outPut)
{
MD5_CTX context;
unsigned char digest[16];
unsigned char k_ipad[65]; /* inner padding -key XORd with ipad */
unsigned char k_opad[65]; /* outer padding -key XORd with opad */
unsigned char tk[16];
int i;
/* if key is longer than 64 bytes reset it to key=MD5(key) */
if (key_len > 64)
{
MD5_CTX tctx;
MD5Init(&tctx);
MD5Update(&tctx, (unsigned char*)key, key_len);
MD5Final(tk, &tctx);
for (i = 0; i<16; i++)
{
key[i] = tk[i];
}
key_len = 16;
}
/*
* the HMAC_MD5 transform looks like:
*
* MD5(K XOR opad, MD5(K XOR ipad, text))
*
* where K is an n byte key
* ipad is the byte 0x36 repeated 64 times
* opad is the byte 0x5c repeated 64 times
* and text is the data being protected
*/
for (i = 0; i<65; i++)
k_ipad[i] = 0;
for (i = 0; i<65; i++)
k_opad[i] = 0;
for (i = 0; i<key_len; i++)
{
k_ipad[i] = (unsigned char)key[i];
k_opad[i] = (unsigned char)key[i];
}
for (i = 0; i<64; i++)
{
k_ipad[i] ^= 0x36;
k_opad[i] ^= 0x5c;
}
/* perform inner MD5 */
MD5Init(&context); /* init context for 1st pass */
MD5Update(&context, k_ipad, 64); /* start with inner pad */
MD5Update(&context, text, text_len); /* then text of datam */
MD5Final((unsigned char*)digest, &context); /* finish up 1st pass */
/* perform outer MD5 */
MD5Init(&context); /* init context for 2nd * pass */
MD5Update(&context, k_opad, 64); /* start with outer pad */
MD5Update(&context, digest, 16); /* then results of 1st hash */
MD5Final((unsigned char*)digest, &context); /* finish up 2nd pass */
for (i = 0; i<16; i++)
outPut[i] = digest[i];
}

View File

@ -1,80 +0,0 @@
/* GLOBAL.H - RSAREF types and constants
*/
#include <inttypes.h>
#ifdef __cplusplus
extern "C" {
#endif
/* PROTOTYPES should be set to one if and only if the compiler supports
function argument prototyping.
The following makes PROTOTYPES default to 0 if it has not already
been defined with C compiler flags.
*/
#ifndef PROTOTYPES
#define PROTOTYPES 0
#endif
/* POINTER defines a generic pointer type */
typedef unsigned char *POINTER;
/* UINT2 defines a two byte word */
typedef uint16_t UINT2;
/* UINT4 defines a four byte word */
typedef uint32_t UINT4;
/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
returns an empty list.
*/
#if PROTOTYPES
#define PROTO_LIST(list) list
#else
#define PROTO_LIST(list) ()
#endif
/* MD5.H - header file for MD5C.C
*/
/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.
License to copy and use this software is granted provided that it
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
Algorithm" in all material mentioning or referencing this software
or this function.
License is also granted to make and use derivative works provided
that such works are identified as "derived from the RSA Data
Security, Inc. MD5 Message-Digest Algorithm" in all material
mentioning or referencing the derived work.
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
These notices must be retained in any copies of any part of this
documentation and/or software.
*/
/* MD5 context. */
typedef struct {
UINT4 state[4]; /* state (ABCD) */
UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
unsigned char buffer[64]; /* input buffer */
} MD5_CTX;
void MD5Init PROTO_LIST ((MD5_CTX *));
void MD5Update PROTO_LIST
((MD5_CTX *, unsigned char *, unsigned int));
void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
void md5(unsigned char* str, int len, unsigned char* digest);
void hmac_md5(unsigned char* text, int text_len, unsigned char* key, int key_len, unsigned char* outPut);
#ifdef __cplusplus
}
#endif

View File

@ -1,200 +0,0 @@
/* MDDRIVER.C - test driver for MD2, MD4 and MD5 */
/* Copyright (C) 1990-2, RSA Data Security, Inc. Created 1990. All
rights reserved.
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
These notices must be retained in any copies of any part of this
documentation and/or software.
*/
/* The following makes MD default to MD5 if it has not already been
defined with C compiler flags. */
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "md5.h"
/* Length of test block, number of test blocks. */
#define TEST_BLOCK_LEN 1000
#define TEST_BLOCK_COUNT 1000
static void MD5String(char *);
static void MD5TimeTrial(void);
static void MD5TestSuite(void);
static void MD5File(char *);
static void MD5Filter(void);
static void MD5Print(unsigned char [16]);
/* Main driver.
Arguments (may be any combination):
-sstring - digests string
-t - runs time trial
-x - runs test script
filename - digests file
(none) - digests standard input
*/
int main (int argc, char *argv[])
{
int i;
if (argc > 1)
for (i = 1; i < argc; i++)
if (argv[i][0] == '-' && argv[i][1] == 's')
MD5String(argv[i] + 2);
else if (strcmp (argv[i], "-t") == 0)
MD5TimeTrial ();
else if (strcmp (argv[i], "-x") == 0)
MD5TestSuite ();
else
MD5File (argv[i]);
else
MD5Filter ();
return (0);
}
/* Digests a string and prints the result.
*/
static void MD5String(char *string)
{
MD5_CTX context;
unsigned char digest[16];
int len = strlen ((const char*)string);
MD5Init (&context);
MD5Update (&context, (unsigned char *)string, len);
MD5Final (digest, &context);
printf ("MD5 (\"%s\") = ", string);
MD5Print (digest);
printf ("\n");
}
/* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte
blocks.
*/
static void MD5TimeTrial ()
{
MD5_CTX context;
time_t endTime, startTime;
unsigned char block[TEST_BLOCK_LEN], digest[16];
unsigned int i;
printf("MD5 time trial. Digesting %d %d-byte blocks ...",
TEST_BLOCK_LEN, TEST_BLOCK_COUNT);
/* Initialize block */
for (i = 0; i < TEST_BLOCK_LEN; i++)
block[i] = (unsigned char)(i & 0xff);
/* Start timer */
time (&startTime);
/* Digest blocks */
MD5Init (&context);
for (i = 0; i < TEST_BLOCK_COUNT; i++)
MD5Update (&context, block, TEST_BLOCK_LEN);
MD5Final (digest, &context);
/* Stop timer */
time (&endTime);
printf(" done\n");
printf("Digest = ");
MD5Print(digest);
printf("\nTime = %ld seconds\n", (long)(endTime-startTime));
printf("Speed = %ld bytes/second\n",
(long)TEST_BLOCK_LEN * (long)TEST_BLOCK_COUNT/(endTime-startTime));
}
/* Digests a reference suite of strings and prints the results.
*/
static void MD5TestSuite ()
{
printf ("MD5 test suite:\n");
MD5String("");
MD5String("a");
MD5String("abc");
MD5String("message digest");
MD5String("abcdefghijklmnopqrstuvwxyz");
MD5String("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
MD5String("12345678901234567890123456789012345678901234567890123456789012345678901234567890");
}
/* Digests a file and prints the result. */
static void MD5File (char * filename)
{
FILE *file;
MD5_CTX context;
int len;
unsigned char buffer[1024], digest[16];
if ((file = fopen (filename, "rb")) == NULL)
printf ("%s can't be opened\n", filename);
else {
MD5Init (&context);
while (len = fread (buffer, 1, 1024, file))
MD5Update (&context, buffer, len);
MD5Final (digest, &context);
fclose (file);
printf ("MD5 (%s) = ", filename);
MD5Print (digest);
printf ("\n");
}
}
/* Digests the standard input and prints the result.
*/
static void MD5Filter ()
{
MD5_CTX context;
int len;
unsigned char buffer[16], digest[16];
MD5Init (&context);
while (len = fread (buffer, 1, 16, stdin))
MD5Update (&context, buffer, len);
MD5Final (digest, &context);
MD5Print (digest);
printf ("\n");
}
/* Prints a message digest in hexadecimal.
*/
static void MD5Print (unsigned char *digest)
{
unsigned int i;
for (i = 0; i < 16; i++)
printf ("%02x", digest[i]);
}
/*
The MD5 test suite (driver option "-x") should print the following
results:
MD5 test suite:
MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
d174ab98d277d9f5a5611c2c9f419d9f
MD5 ("123456789012345678901234567890123456789012345678901234567890123456
78901234567890") = 57edf4a22be3c955ac49da2e2107b67a
*/

View File

@ -1,25 +0,0 @@
void rc4_crypt(unsigned char *data, int data_len, unsigned char *key, int key_len)
{
int i, j, k, x, y;
unsigned char a, b, s[256];
for (i = 0; i < 256; i++){
s[i] = i;
}
for (i = j = k = 0; i < 256; i++){
a = s[i];
j = (unsigned char)(j + a + key[k]);
s[i] = s[j]; s[j] = a;
if (++k >= key_len) k = 0;
}
for (i = x = y = 0; i < data_len; i++)
{
x = (unsigned char)(x + 1); a = s[x];
y = (unsigned char)(y + a);
s[x] = b = s[y];
s[y] = a;
data[i] ^= s[(unsigned char)(a + b)];
}
}

View File

@ -1,14 +0,0 @@
#ifndef RC4_H_
#define RC4_H_
#ifdef __cplusplus
extern "C" {
#endif
void rc4_crypt(unsigned char *data, int data_len, unsigned char *key, int key_len);
#ifdef __cplusplus
}
#endif
#endif // RC4_H_

View File

@ -1,45 +0,0 @@
#ifndef GLOBAL_H_INCLUDED
#define GLOBAL_H_INCLUDED
#ifndef PCAP
#define PCAP
#endif // PCAP
#ifndef HAVE_REMOTE
#define HAVE_REMOTE
#endif // HAVE_REMOTE
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#ifndef WIN32
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <unistd.h>
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#include <Windows.h>
#include <Iphlpapi.h>
#pragma comment(lib, "iphlpapi.lib")
/* WINDOWS SDKS file C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\IPHlpApi.Lib */
#endif
#include "pcap.h"
//#include "encrypt.h"
//#include "platform.h"
//#define DEBUG 1
#ifdef DEBUG
#include "adapter.h"
#endif
#endif // GLOBAL_H_INCLUDED

View File

@ -1,53 +0,0 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include "lock.h"
#define LOCKFILE "/var/run/dclient.pid"
#define LOCKMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
int already_running(const char *filename)
{
int fd, t; // t用来消除警告
char buf[16];
if(filename == NULL) filename = LOCKFILE;
fd = open(filename, O_RDWR | O_CREAT, LOCKMODE);
if(fd < 0)
{
fprintf(stderr, "pid file open faild!");
exit(EXIT_FAILURE);
}
if (lockfile(fd) == -1)
{
if (errno == EACCES || errno == EAGAIN)
{
fprintf(stderr, "dclient already running!");
close(fd);
exit(EXIT_FAILURE);
}
fprintf(stderr, "Can't lock pid file!");
exit(EXIT_FAILURE);
}
t = ftruncate(fd, 0);
sprintf(buf, "%ld", (long)getpid());
t = write(fd, buf, strlen(buf) + 1);
if(t) { }
return 0;
}
int lockfile(int fd)
{
struct flock fl;
fl.l_type = F_WRLCK;
fl.l_start = 0;
fl.l_whence = SEEK_SET;
fl.l_len = 0;
return (fcntl(fd, F_SETLK, &fl));
}

View File

@ -1,7 +0,0 @@
#ifndef LOCK_H_INCLUDE
#define LOCK_H_INCLUDE
int already_running(const char *filename = NULL);
int lockfile(int fd);
#endif

View File

@ -1,46 +0,0 @@
#include <iostream>
#include <string>
#include "tprocess.h"
#include "darg.h"
using namespace std;
string zteUser, ztePass, enetUser, enetPass, adapterName, dhcpScript;
bool enetAuth;
int dhcpStyle, timeout;
void runProcess();
int main(int argc, char *argv[])
{
DArg *darg = new DArg();
darg->getArguments(argc, argv);
//zteUser = "201535020421";
//ztePass = "123456";
//enetUser = "201535020421";
//enetPass = "12345678";
//adapterName = "eth0.2";
zteUser = darg->zteUser();
ztePass = darg->ztePass();
adapterName = darg->adapterName();
enetAuth = darg->enetAuth();
dhcpStyle = darg->dhcpStyle();
dhcpScript = darg->dhcpScript();
timeout = darg->timeout();
if(enetAuth)
{
enetUser = darg->enetUser();
enetPass = darg->enetPass();
}
runProcess();
return 0;
}
void runProcess()
{
TProcess * tp = new TProcess(zteUser, ztePass, adapterName, dhcpStyle, dhcpScript, timeout, enetAuth, enetUser, enetPass);
printf("pthread exit with %d\n", tp->run());
}

View File

@ -1,28 +0,0 @@
#include "msgpass.h"
MsgPass::MsgPass()
{
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cond, NULL);
}
MsgPass::~MsgPass()
{
pthread_cond_destroy(&cond);
pthread_mutex_destroy(&mutex);
}
void MsgPass::signal()
{
pthread_mutex_lock(&mutex);
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
}
void MsgPass::wait(void* (*fun)(void *), void * data)
{
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond, &mutex);
fun(data);
pthread_mutex_unlock(&mutex);
}

View File

@ -1,18 +0,0 @@
#ifndef MSIGNAL_H_INCLUDED
#define MSIGNAL_H_INCLUDED
#include <pthread.h>
class MsgPass
{
public:
MsgPass();
~MsgPass();
void signal();
void wait(void* (*fun)(void *), void * data);
protected:
pthread_cond_t cond;
pthread_mutex_t mutex;
};
#endif // MSIGNAL_H_INCLUDED

View File

@ -1,470 +0,0 @@
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <string>
//#include <regex> // C++
#include "global.h"
#include "dpcap.h"
#include "tprocess.h"
#include "adapter.h"
#include "docr.h"
#include "encrypt.h"
using std::string;
using std::cout;
using std::endl;
using namespace std;
static void * RunDPcap(void * lpVoid)
{
TProcess * tp = (TProcess *)(lpVoid);
tp->runDPcap();
return NULL;
}
static void * RunDPcapWait(void * lpVoid)
{
TProcess * tp = (TProcess *)(lpVoid);
tp->runDPcapWait(); //string::size_type pos;
return NULL;
}
static void * DPcapWaitProc(void * lpVoid)
{
TProcess * tp = (TProcess *)(lpVoid);
tp->log(tp->getDPcapHandle()->getMessage());
return NULL;
}
static void * RunDCurl(void * lpVoid)
{
TProcess * tp = (TProcess *)(lpVoid);
tp->runDCurl();
return NULL;
}
static void * RunDetectActive(void *lpVoid)
{
TProcess * tp = (TProcess *)(lpVoid);
tp->runDetectActive();
return NULL;
}
TProcess::TProcess(const string & zteUser, const string & ztePass, const string & adapterName,
int dhcpStyle, string dhcpScript, int timeout, int enetAuth,
const string & enetUser, const string & enetPass)
{
this->zteUser = zteUser; this->ztePass = ztePass;
this->adapterName =adapterName; this->dhcpStyle = dhcpStyle;
this->dhcpScript = dhcpScript; this->timeout = timeout;
this->enetAuth = enetAuth; this->enetPass = enetPass; this->enetUser = enetUser;
this->change = 0;
//pthread_mutex_init(&mutex_log, NULL); //日志函数用的,已注释
// TODO(Zeyes) 在上线前,把文件改到临时目录
//logFile = "/tmp/zte.log"; // 日志文件名
dlog = new DLog("/tmp/zte.log"); // 初始化日志记录
msgPass = new MsgPass(); // 初始化中兴认证消息传递模块
}
TProcess::~TProcess()
{
//pthread_mutex_destroy(&mutex_log); //日志函数用的,已注释
}
// 多线程总调度
int TProcess::run()
{
pthread_t eThread[4];
pthread_attr_t attr[4];
int rc;
void *status;
pthread_attr_init(&attr[0]);
pthread_attr_setdetachstate(&attr[0], PTHREAD_CREATE_JOINABLE);
rc = pthread_create(&eThread[0], &attr[0], RunDPcap, (void *)this); // 中兴认证线程
pthread_create(&eThread[1], NULL, RunDPcapWait, (void *)this); // 中兴认证消息记录线程
pthread_create(&eThread[2], &attr[0], RunDCurl, (void *)this); // 天翼校园网和外网心跳进程
pthread_create(&eThread[3], &attr[0], RunDetectActive, (void *)this);// 检测中兴认证状态与重置
pthread_join(eThread[0], &status);
log("[Exit] 认证程序异常退出!");
return rc;
}
// 运行中兴认证
void TProcess::runDPcap()
{
if(msgPass) dpcap = new DPcap(msgPass); //msgPass是一个日志记录实例指针
else dpcap = new DPcap();
dpcap->init(zteUser, ztePass, adapterName);
dpcap->open();
dpcap->run();
//test->setStatus(DPcap::EAPOL_LOGOFF);
}
// 接收Pcap发来的消息并调用本类日志记录函数
void TProcess::runDPcapWait()
{
//for(int i = 0; i < 1000; i++) if(dpcap) break;
while(1)
{
if(msgPass)
{
msgPass->wait(DPcapWaitProc, (void *)this);
change = 1; // 表明收到消息,可能有状态的改变
}
}
}
void TProcess::runDCurl()
{
unsigned char ip[17]; // 保存ip地址
int nowStatus = -10, preStatus = -10; // 保存中兴认证的状态和前一次的状态
int maxLoginCount = 3; // 天翼校园网失败最大重试次数
bool loginStatus = false; // 天翼校园网登录状态
static int loginFailCount = 0; // 天翼校园网失败尝试计数
int cnt = 0; // 统计秒数,非精确值
int hcnt = 0; // 心跳错误统计次数
int rcnt = 0; // 局域网心跳计数
int ipcnt = 0; // ip获取失败计数
char temp[10];
suspend(5);
while(1)
{
suspend(1); cnt++; cnt %= 60; // 秒数计数
if(!dpcap) continue;
if(!dcurl)
{
dcurl = new DCurl();
dcurl->setTimeout(20, 5);
continue;
}
preStatus = nowStatus;
nowStatus = dpcap->getStatus(); // 获取中兴认证状态
if(nowStatus != preStatus || change) // 中兴状态发生改变或者有change信息产生
{
change = 0; // 成功调用后将change改回0
if(!loginStatus && nowStatus == DPcap::EAP_SUCCESS) // 中兴认证成功,并且外网没有登录
{
const char * name = (dpcap->getAdapterName()).c_str();
if(!GetIp(name, ip)) // 第一次检测ip是否获取成功
{
if(ipcnt % 600 == 0) log("[Proc] 等待获取ip...");
if(dhcpStyle && cnt % 3 == 0)
DhcpClient(name, dhcpStyle, dhcpScript.c_str()); // 如果没有获取ip就按照参数获取ip默认是dhcpStyle=0
}
if(!GetIp(name, ip)) // 第二次检测ip是否获取成功
{ if(ipcnt % 600 == 120) log("[Error] ip未成功获取!"); ipcnt++; change = 1; continue; }
else
{ if(loginFailCount == 0) log("[Info] 当前ip - " + string((const char *)ip)); if(ipcnt) ipcnt = 0; }
if(!loginStatus && runHeartbean(true)) // 检测需不需要登录外网
{
log("[Info] 检测到已经连通互联网...");
loginStatus = true;
loginFailCount = 0;
maxLoginCount = 3;
if(rcnt) rcnt = 0; if(hcnt) hcnt = 0;
}
if(enetAuth && !loginStatus) // 登录状态不是为真时执行
{
// 不是第一次尝试登录时打印log
if(0 < loginFailCount && loginFailCount < maxLoginCount)
{
sprintf(temp, "%d", loginFailCount + 1);
log("[Enet Retry] 进行第" + string(temp) + "次尝试...");
}
//#endif // DEBUG
// 如果天翼网尝试次数小于最大可登录次数
if(loginFailCount < maxLoginCount)
{
// 执行登录天翼外网
if(runLoginEnet(ip))
{
loginStatus = true;
loginFailCount = 0; // 将天翼校园网重试次数重置
maxLoginCount = 3;
if(rcnt) rcnt = 0; if(hcnt) hcnt = 0;
}else
{
change = 1;
loginFailCount++;
}
}
}
}
else if(nowStatus != DPcap::EAP_SUCCESS && nowStatus != DPcap::EAP_KEEP_ALIVE)
{
// 中兴状态发生改变而且不是成功的状态时
if(enetAuth && loginStatus) log("[Enet] 已重置天翼校园网登录状态...");
if(loginStatus) loginStatus = false;
if(loginFailCount) loginFailCount = 0; // 将天翼校园网重试次数重置
maxLoginCount = 3;
if(hcnt) hcnt = 0; if(rcnt) rcnt = 0;
}
}
// 只要dpcap实例存在如果天翼校园网认证成功或者已经获取到ip都进行心跳
// 实际上就算天翼校园网认证不成功也要心跳,不然中兴认证也会断(需要有数据包交换)
if(cnt == 59)
{
if(loginStatus)
{
if(!runHeartbean(true)) // 心跳60秒一次验证返回信息
{
hcnt += 1;
if(hcnt == 4) log("[Error] 天翼网心跳连接失败!");
}else
hcnt = 0;
}else if(nowStatus == DPcap::EAP_SUCCESS && loginFailCount >= maxLoginCount && GetIp(adapterName.c_str(), ip)) // 登录失败时改为内网心跳
{
rcnt += 1; // 局域网心跳计数+1
if(runHeartbean(true))
change = 1; // 用户手动登录天翼校园网的情况
else
runHeartbean(false, true); // 局域网心跳
if((rcnt % 15 == 14) && enetAuth) { maxLoginCount+=1; change = 1; }
// 如果一直没有认证成功每15分钟给一次重新认证的机会
}
// 天翼校园网无故断线重连
if(hcnt % 5 == 4)
{
if(loginFailCount == 0) log("[Retry] 天翼网可能已断开,正在重新连接...");
loginStatus = false; change = 1;
if(loginFailCount >= maxLoginCount) hcnt = 0;
else hcnt %= 5;
}
}
}
delete dcurl;
dcurl = NULL;
return ;
}
// toVar表示是否验证返回内容local表示是否局域网心跳, 默认为false
bool TProcess::runHeartbean(bool toVar, bool local)
{
std::string url = "http://www.msftncsi.com/ncsi.txt"; // 心跳网址
std::string pattern = "Microsoft NCSI"; // 心跳网址的返回内容,用于判断心跳是否成功
if(local) { url = "http://10.20.208.12/default3.aspx"; pattern = "html"; }
if(!toVar)
{
if(dcurl)
dcurl->httpRequest(url, DCurl::GET, false);
}
else
{
std::string strResponse = "";
if(dcurl)
{
dcurl->httpRequest(url, DCurl::GET, true);
dcurl->getResponse(strResponse);
if(strResponse.find(pattern) != strResponse.npos) return true;
else return false;
/*std::regex idRegex("html");
auto itBegin = std::sregex_iterator(strResponse.begin(), strResponse.end(), idRegex);
auto itEnd = std::sregex_iterator();
std::smatch match = *itBegin;
if(match.length() >= 4 && strstr(match[0].str().c_str(), "html")) return true;
else return false;*/
}
else
return false;
}
return true;
}
bool TProcess::runLoginEnet(const unsigned char * ip)
{
string strResponse = "";
string code = "";
string postStr;
string tmp;
DOcr * valite = new DOcr();
bool result = false;
bool resOcr = false;
unsigned char * password1 = (unsigned char *)enetPass.c_str();
if(dcurl)
{
string t_str;
dcurl->httpRequest("http://enet.10000.gd.cn:10001/login.jsp", DCurl::POST, true);
dcurl->getResponse(t_str);
if(t_str.find("base64") != string::npos) // 检测天翼登录页是否引入了base64.js
{
password1 = (unsigned char *) calloc((enetPass.length() + 2) / 3 * 4, sizeof(unsigned char));
Get_Base64_Encode((unsigned char *) enetPass.c_str(), enetPass.length(), password1); // 天翼密码Base64加密
}
}
for(int i = 0; !result && i < 2; i++)
{
strResponse = "";
code = "";
if(!dcurl) return false;
dcurl->httpRequest("http://enet.10000.gd.cn:10001/common/image.jsp", DCurl::GET, true);
dcurl->getResponse(strResponse);
if(!strResponse.empty() && strResponse.size() >= 800 && valite)
{
resOcr = valite->readImage(strResponse, DOcr::JPEG_MEM);
if(resOcr) valite->run();
if(resOcr) valite->getCode(code);
}
postStr = "userName1=" + enetUser + "&password1=" + string((char *)password1) + \
"&rand=" + code + "&eduuser=" + string((const char *)ip) + "&edubas=113.98.10.136";
//cout << "postStr: " << postStr << endl;
dcurl->setPostData(postStr);
dcurl->httpRequest("http://enet.10000.gd.cn:10001/login.do", DCurl::POST, true);
dcurl->getResponse(strResponse);
//log(strResponse);
// gcc 4.8的版本不支持C++ 11的正则表达式
/*
std::regex idRegex("<div id=\"(.*?)\">(.*?)<");
auto itBegin = std::sregex_iterator(strResponse.begin(), strResponse.end(), idRegex);
auto itEnd = std::sregex_iterator();
std::smatch match = *itBegin;
if(match.length() > 10 && strstr(match[0].str().c_str(), "success"))
{
tmp = "[Enet] ";
tmp.append(match[0].str() + string(" - ") + match[2].str());
log(tmp);
result = true;
}
else
{
tmp = "[Enet Faild] ";
if(match.length() > 10) tmp.append(match[0].str() + string(" - ") + match[2].str());
else tmp.append("天翼校园网登陆失败!");
log(tmp);
if(runHeartbean(true)) result = true;
}
*/
// 下面为妥协版
string::size_type pos;
if((pos = strResponse.find("success")) != string::npos)
result = true;
else
if(runHeartbean(true)) result = true;
if(!result) suspend(2);
//if(runHeartbean(true)) result = true;
}
if(valite) { delete valite; valite = NULL; } // 删除验证码识别对象内存
// 日志记录登录情况
if(result == true)
log("[Enet] 天翼校园网登录成功!");
else
{
string::size_type pos1 = string::npos, pos2 = string::npos;
if(!strResponse.empty())
{
pos1 = strResponse.find("failed") + 8;
pos2 = strResponse.find("</div>");
}
if(pos1 != string::npos && pos2 != string::npos)
log("[Enet Faild] 天翼校园网登陆失败!- " + strResponse.substr(pos1, pos2 - pos1) + "");
else
log("[Enet Faild] 天翼校园网登陆失败!- 原因未知。");
}
//free(password1);
return result;
}
bool TProcess::runDetectActive()
{
bool reset = false, retry = false;
time_t retryTime = -1;
int cnt = 0;
suspend(30);
while(1)
{
suspend(1);
cnt++; if(cnt >= 3600) cnt %= 3600;
if(!reset && cnt >= 300) reset = true; // 程序开始运行5分钟内不做检测
if(dpcap)
{
// 如果认证服务器在一定时间没有与软件交互,则重新发包
if(timeout != 0 && reset && (cnt % 10 == 0) && dpcap->getRunStatus() &&
(dpcap->getPreRVal() >= timeout) && !runHeartbean(true)) // 超时时间默认0秒可自定义
{
log("[Reset] 网络错误,重置中兴认证...");
dpcap->setStatusAndRun(DPcap::EapType::EAPOL_START);
}
// 认证错误的情况
if(!retry && (retryTime = dpcap->getReSendTime()) != -1) retry = true;
if(retry && retryTime <= time(0))
{
//log("[Debug] 正在重试发包...");
dpcap->setStatusAndRun(DPcap::EapType::EAPOL_START);
retry = false;
}
}
}
}
DPcap* TProcess::getDPcapHandle()
{
return dpcap;
}
// 日志记录实际上直接调用DLog类
// logFile和mutex_log在本类头文件中定义已注释掉
bool TProcess::log(const string & str)
{
if(dlog) return dlog->log(str);
else return false;
/*
fstream fout;
time_t t = time(0);
char timestr[64];
strftime(timestr, sizeof(timestr), "[%m/%d %H:%M:%S]", localtime(&t));
pthread_mutex_lock(&mutex_log);
fout.open(logFile, std::ios_base::out | std::ios_base::app);
if(!fout.is_open())
{
pthread_mutex_unlock(&mutex_log);
return false;
}
std::cout << timestr << " " << str << std::endl;
fout << timestr << " " << str << std::endl;
fout.close();
pthread_mutex_unlock(&mutex_log);
return true;
*/
}
// 为了日后兼容win和linux两个版本设置了个睡眠的函数
// 在linux下此函数和sleep效果相似
bool TProcess::suspend(int s)
{
if(s < 0) return true;
#ifndef WIN32
::sleep(s);
#else
::Sleep(s * 1000);
#endif
return true;
}

View File

@ -1,46 +0,0 @@
#ifndef TPROCESS_H_
#define TPROCESS_H_
#include <ctime>
#include <fstream>
#include <pthread.h>
#include "dpcap.h"
#include "adapter.h"
//#include "estatus.h"
#include "dcurl.h"
#include "msgpass.h"
#include "dlog.h"
using std::string;
using std::fstream;
class TProcess
{
public:
TProcess(const string & zteUser, const string & ztePass, const string & adapterName = "eth0",
int dhcpStyle = 0, string dhcpScript="", int timeout = 0, int enetAuth = 0, const string & enetUser = "",
const string & enetPass = "");
~TProcess();
void runDPcap();
void runDPcapWait();
DPcap* getDPcapHandle();
void runDCurl();
bool runLoginEnet(const unsigned char * ip);
bool runHeartbean(bool toVar, bool local = false);
bool runDetectActive();
int run();
bool log(const string & str);
protected:
bool suspend(int s);
private:
string zteUser, ztePass, enetUser, enetPass, adapterName, dhcpScript;
int dhcpStyle, timeout, enetAuth, change;
//pthread_mutex_t mutex_log;
//string logFile;
DPcap * dpcap;
DCurl * dcurl;
DLog * dlog;
MsgPass * msgPass;
};
#endif // TPROCESS_H_

View File

@ -1,3 +0,0 @@
[02/23 13:55:03] 当前ip - 10.20.152.198
[02/23 13:55:04] [Enet] <div id="success">登录成功1< - 登录成功1
[02/23 13:55:04] 校园网登录成功

Some files were not shown because too many files have changed in this diff Show More