mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-18 17:33:31 +00:00
add ZhongXing 802.1x client package
This commit is contained in:
parent
5df52e159e
commit
3de1658c40
34
package/lean/dclient/Makefile
Executable file
34
package/lean/dclient/Makefile
Executable file
@ -0,0 +1,34 @@
|
||||
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))
|
20
package/lean/dclient/log.txt
Executable file
20
package/lean/dclient/log.txt
Executable file
@ -0,0 +1,20 @@
|
||||
20170322:
|
||||
优化了日志提示。
|
||||
修复了ip未获取成功,不工作的问题。
|
||||
|
||||
20170510:
|
||||
优化了断线重连。
|
||||
|
||||
20170602:
|
||||
1. 对数据帧加入CRC32校验,不足64Byte的包补足64B(防止交换机丢弃)
|
||||
2. 更改心跳检测网址
|
||||
|
||||
20170903:
|
||||
处理外网登录多次重试不成功不会再试的问题
|
||||
20170912:
|
||||
添加自定义认证心跳的超时时间
|
||||
修复了在某些情况下不能成功获取ip时程序异常退出的问题
|
||||
20170914:
|
||||
天翼登录页改版,重新适配了天翼自动登录模块
|
||||
20170916:
|
||||
修复了认证服务器通知乱码问题
|
76
package/lean/dclient/src/Makefile
Executable file
76
package/lean/dclient/src/Makefile
Executable file
@ -0,0 +1,76 @@
|
||||
# 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
|
280
package/lean/dclient/src/adapter.cpp
Executable file
280
package/lean/dclient/src/adapter.cpp
Executable file
@ -0,0 +1,280 @@
|
||||
#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]);
|
||||
}
|
104
package/lean/dclient/src/adapter.h
Executable file
104
package/lean/dclient/src/adapter.h
Executable file
@ -0,0 +1,104 @@
|
||||
#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);
|
||||
|
||||
// 通过网卡名获取ip,ip变量应事先分配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_
|
26
package/lean/dclient/src/conv/Makefile_test
Executable file
26
package/lean/dclient/src/conv/Makefile_test
Executable file
@ -0,0 +1,26 @@
|
||||
### 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
|
8668
package/lean/dclient/src/conv/conv.c
Executable file
8668
package/lean/dclient/src/conv/conv.c
Executable file
File diff suppressed because it is too large
Load Diff
15
package/lean/dclient/src/conv/conv.h
Executable file
15
package/lean/dclient/src/conv/conv.h
Executable file
@ -0,0 +1,15 @@
|
||||
#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
|
18
package/lean/dclient/src/conv/test.cpp
Executable file
18
package/lean/dclient/src/conv/test.cpp
Executable file
@ -0,0 +1,18 @@
|
||||
#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;
|
||||
}
|
33
package/lean/dclient/src/daemon.cpp
Executable file
33
package/lean/dclient/src/daemon.cpp
Executable file
@ -0,0 +1,33 @@
|
||||
#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;
|
||||
}
|
6
package/lean/dclient/src/daemon.h
Executable file
6
package/lean/dclient/src/daemon.h
Executable file
@ -0,0 +1,6 @@
|
||||
#ifndef DAEMON_H_INCLUDE
|
||||
#define DAEMON_H_INCLUDE
|
||||
|
||||
void init_daemon(void); //守护进程初始化函数
|
||||
|
||||
#endif
|
207
package/lean/dclient/src/darg.cpp
Executable file
207
package/lean/dclient/src/darg.cpp
Executable file
@ -0,0 +1,207 @@
|
||||
#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;
|
||||
}
|
35
package/lean/dclient/src/darg.h
Executable file
35
package/lean/dclient/src/darg.h
Executable file
@ -0,0 +1,35 @@
|
||||
#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_
|
96
package/lean/dclient/src/dclient.cbp
Normal file
96
package/lean/dclient/src/dclient.cbp
Normal file
@ -0,0 +1,96 @@
|
||||
<?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>
|
39
package/lean/dclient/src/dclient.cscope_file_list
Normal file
39
package/lean/dclient/src/dclient.cscope_file_list
Normal file
@ -0,0 +1,39 @@
|
||||
"/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"
|
794
package/lean/dclient/src/dclient.depend
Normal file
794
package/lean/dclient/src/dclient.depend
Normal file
@ -0,0 +1,794 @@
|
||||
# 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
|
||||
|
125
package/lean/dclient/src/dclient.layout
Normal file
125
package/lean/dclient/src/dclient.layout
Normal file
@ -0,0 +1,125 @@
|
||||
<?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>
|
324
package/lean/dclient/src/dcurl.cpp
Executable file
324
package/lean/dclient/src/dcurl.cpp
Executable file
@ -0,0 +1,324 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
|
100
package/lean/dclient/src/dcurl.h
Executable file
100
package/lean/dclient/src/dcurl.h
Executable file
@ -0,0 +1,100 @@
|
||||
#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_
|
15
package/lean/dclient/src/dir.cpp
Executable file
15
package/lean/dclient/src/dir.cpp
Executable file
@ -0,0 +1,15 @@
|
||||
#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
|
||||
}
|
15
package/lean/dclient/src/dir.h
Executable file
15
package/lean/dclient/src/dir.h
Executable file
@ -0,0 +1,15 @@
|
||||
#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
|
37
package/lean/dclient/src/dlog.cpp
Executable file
37
package/lean/dclient/src/dlog.cpp
Executable file
@ -0,0 +1,37 @@
|
||||
#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;
|
||||
}
|
21
package/lean/dclient/src/dlog.h
Executable file
21
package/lean/dclient/src/dlog.h
Executable file
@ -0,0 +1,21 @@
|
||||
#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
|
296
package/lean/dclient/src/docr.cpp
Executable file
296
package/lean/dclient/src/docr.cpp
Executable file
@ -0,0 +1,296 @@
|
||||
#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;
|
||||
}
|
76
package/lean/dclient/src/docr.h
Executable file
76
package/lean/dclient/src/docr.h
Executable file
@ -0,0 +1,76 @@
|
||||
#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
|
||||
* 不知道会不会影响大局
|
||||
*/
|
154
package/lean/dclient/src/docrkeys.cpp
Executable file
154
package/lean/dclient/src/docrkeys.cpp
Executable file
@ -0,0 +1,154 @@
|
||||
#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");
|
||||
}
|
451
package/lean/dclient/src/dpcap.cpp
Executable file
451
package/lean/dclient/src/dpcap.cpp
Executable file
@ -0,0 +1,451 @@
|
||||
#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;
|
||||
}
|
95
package/lean/dclient/src/dpcap.h
Executable file
95
package/lean/dclient/src/dpcap.h
Executable file
@ -0,0 +1,95 @@
|
||||
#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_
|
239
package/lean/dclient/src/eappacket.cpp
Executable file
239
package/lean/dclient/src/eappacket.cpp
Executable file
@ -0,0 +1,239 @@
|
||||
|
||||
#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));
|
||||
}
|
74
package/lean/dclient/src/eappacket.h
Executable file
74
package/lean/dclient/src/eappacket.h
Executable file
@ -0,0 +1,74 @@
|
||||
#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_
|
43
package/lean/dclient/src/encrypt.cpp
Executable file
43
package/lean/dclient/src/encrypt.cpp
Executable file
@ -0,0 +1,43 @@
|
||||
#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); // 返回加密后的字符串长度
|
||||
}
|
10
package/lean/dclient/src/encrypt.h
Executable file
10
package/lean/dclient/src/encrypt.h
Executable file
@ -0,0 +1,10 @@
|
||||
#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_
|
135
package/lean/dclient/src/encrypt/base64.c
Executable file
135
package/lean/dclient/src/encrypt/base64.c
Executable file
@ -0,0 +1,135 @@
|
||||
/* 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;
|
||||
}
|
||||
|
25
package/lean/dclient/src/encrypt/base64.h
Executable file
25
package/lean/dclient/src/encrypt/base64.h
Executable file
@ -0,0 +1,25 @@
|
||||
#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__ */
|
||||
|
23
package/lean/dclient/src/encrypt/crc32.c
Executable file
23
package/lean/dclient/src/encrypt/crc32.c
Executable file
@ -0,0 +1,23 @@
|
||||
#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;
|
||||
}
|
14
package/lean/dclient/src/encrypt/crc32.h
Executable file
14
package/lean/dclient/src/encrypt/crc32.h
Executable file
@ -0,0 +1,14 @@
|
||||
#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
|
412
package/lean/dclient/src/encrypt/md5.c
Executable file
412
package/lean/dclient/src/encrypt/md5.c
Executable file
@ -0,0 +1,412 @@
|
||||
/* 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];
|
||||
}
|
80
package/lean/dclient/src/encrypt/md5.h
Executable file
80
package/lean/dclient/src/encrypt/md5.h
Executable file
@ -0,0 +1,80 @@
|
||||
/* 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
|
||||
|
200
package/lean/dclient/src/encrypt/mddriver.c
Executable file
200
package/lean/dclient/src/encrypt/mddriver.c
Executable file
@ -0,0 +1,200 @@
|
||||
/* 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
|
||||
*/
|
||||
|
||||
|
25
package/lean/dclient/src/encrypt/rc4.c
Executable file
25
package/lean/dclient/src/encrypt/rc4.c
Executable file
@ -0,0 +1,25 @@
|
||||
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)];
|
||||
}
|
||||
}
|
14
package/lean/dclient/src/encrypt/rc4.h
Executable file
14
package/lean/dclient/src/encrypt/rc4.h
Executable file
@ -0,0 +1,14 @@
|
||||
#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_
|
45
package/lean/dclient/src/global.h
Executable file
45
package/lean/dclient/src/global.h
Executable file
@ -0,0 +1,45 @@
|
||||
#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
|
53
package/lean/dclient/src/lock.cpp
Executable file
53
package/lean/dclient/src/lock.cpp
Executable file
@ -0,0 +1,53 @@
|
||||
#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));
|
||||
}
|
||||
|
7
package/lean/dclient/src/lock.h
Executable file
7
package/lean/dclient/src/lock.h
Executable file
@ -0,0 +1,7 @@
|
||||
#ifndef LOCK_H_INCLUDE
|
||||
#define LOCK_H_INCLUDE
|
||||
|
||||
int already_running(const char *filename = NULL);
|
||||
int lockfile(int fd);
|
||||
|
||||
#endif
|
46
package/lean/dclient/src/main.cpp
Executable file
46
package/lean/dclient/src/main.cpp
Executable file
@ -0,0 +1,46 @@
|
||||
#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());
|
||||
}
|
28
package/lean/dclient/src/msgpass.cpp
Executable file
28
package/lean/dclient/src/msgpass.cpp
Executable file
@ -0,0 +1,28 @@
|
||||
#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);
|
||||
}
|
18
package/lean/dclient/src/msgpass.h
Executable file
18
package/lean/dclient/src/msgpass.h
Executable file
@ -0,0 +1,18 @@
|
||||
#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
|
470
package/lean/dclient/src/tprocess.cpp
Executable file
470
package/lean/dclient/src/tprocess.cpp
Executable file
@ -0,0 +1,470 @@
|
||||
#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;
|
||||
}
|
46
package/lean/dclient/src/tprocess.h
Executable file
46
package/lean/dclient/src/tprocess.h
Executable file
@ -0,0 +1,46 @@
|
||||
#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_
|
3
package/lean/dclient/src/zte_status.log
Executable file
3
package/lean/dclient/src/zte_status.log
Executable file
@ -0,0 +1,3 @@
|
||||
[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] 校园网登录成功
|
61
package/lean/luci-app-dclient/Makefile
Executable file
61
package/lean/luci-app-dclient/Makefile
Executable file
@ -0,0 +1,61 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-dclient
|
||||
PKG_VERSION=1.1
|
||||
PKG_RELEASE:=170914
|
||||
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/$(PKG_NAME)
|
||||
SECTION:=luci
|
||||
CATEGORY:=LuCI
|
||||
SUBMENU:=3. Applications
|
||||
TITLE:=LuCI support for dclient
|
||||
PKGARCH:=all
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/description
|
||||
This package contains LuCI configuration pages for ZTE 802.1x Client(CCDGUT).
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
$(foreach po,$(wildcard ${CURDIR}/src/i18n/zh-cn/*.po), \
|
||||
po2lmo $(po) $(PKG_BUILD_DIR)/$(patsubst %.po,%.lmo,$(notdir $(po)));)
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/view
|
||||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n
|
||||
|
||||
$(INSTALL_CONF) ./src/etc/config/dclient $(1)/etc/config/dclient
|
||||
$(INSTALL_BIN) ./src/etc/init.d/dclient $(1)/etc/init.d/dclient
|
||||
$(INSTALL_DATA) ./src/luci/model/cbi/dclient.lua $(1)/usr/lib/lua/luci/model/cbi/dclient.lua
|
||||
$(INSTALL_DATA) ./src/luci/controller/dclient.lua $(1)/usr/lib/lua/luci/controller/dclient.lua
|
||||
$(INSTALL_DATA) ./src/luci/view/dclient_viewer.htm $(1)/usr/lib/lua/luci/view/dclient_viewer.htm
|
||||
$(INSTALL_DATA) $(PKG_BUILD_DIR)/dclient.*.lmo $(1)/usr/lib/lua/luci/i18n/
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/postinst
|
||||
#!/bin/sh
|
||||
/etc/init.d/dclient enable
|
||||
rm -rf /tmp/luci*
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/prerm
|
||||
#!/bin/sh
|
||||
/etc/init.d/dclient disable
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,luci-app-dclient))
|
10
package/lean/luci-app-dclient/src/etc/config/dclient
Executable file
10
package/lean/luci-app-dclient/src/etc/config/dclient
Executable file
@ -0,0 +1,10 @@
|
||||
config login
|
||||
option enable ''
|
||||
option zteuser ''
|
||||
option ztepass ''
|
||||
option ifname 'eth0.2'
|
||||
option timeout '0'
|
||||
option dhcpclient 'auto'
|
||||
option enet ''
|
||||
option enetuser ''
|
||||
option enetpass ''
|
68
package/lean/luci-app-dclient/src/etc/init.d/dclient
Executable file
68
package/lean/luci-app-dclient/src/etc/init.d/dclient
Executable file
@ -0,0 +1,68 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
START=80
|
||||
|
||||
run_dclient()
|
||||
{
|
||||
local enable
|
||||
config_get_bool enable $1 enable
|
||||
|
||||
if [ $enable ]; then
|
||||
local zteuser
|
||||
local ztepass
|
||||
local ifname
|
||||
local enetuser
|
||||
local enetpass
|
||||
local timeout
|
||||
local dhcpclient
|
||||
|
||||
config_get zteuser $1 zteuser
|
||||
config_get ztepass $1 ztepass
|
||||
config_get ifname $1 ifname
|
||||
config_get timeout $1 timeout
|
||||
config_get_bool enet $1 enet
|
||||
config_get dhcpclient $1 dhcpclient
|
||||
|
||||
if [ -z $timeout ]; then
|
||||
timeout='0'
|
||||
fi
|
||||
|
||||
if [ -z $dhcpclient ] || [ "$dhcpclient" = "auto" ]; then
|
||||
dhcpclient=''
|
||||
else
|
||||
dhcpclient="-i $dhcpclient"
|
||||
fi
|
||||
|
||||
|
||||
if [ $enet ]; then
|
||||
config_get enetuser $1 enetuser
|
||||
config_get enetpass $1 enetpass
|
||||
echo -e "欢迎使用凌点时代D客户端(中兴802.1X认证)\n微信公众号:凌点时代(DotTimes)\n有问题可以到公众号里面留言哦!\n" >> /tmp/zte.log
|
||||
# 这里调用程序
|
||||
dclient -u $zteuser -p $ztepass -d $ifname -t $timeout $dhcpclient -e $enetuser -k $enetpass >/dev/null 2>&1 &
|
||||
else
|
||||
dclient -u $zteuser -p $ztepass -d $ifname -t $timeout $dhcpclient >/dev/null 2>&1 &
|
||||
fi
|
||||
|
||||
echo "ZTE Client has started."
|
||||
fi
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
# /etc/config/dclient
|
||||
config_load /etc/config/dclient
|
||||
config_foreach run_dclient login
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
# 配置停止调用
|
||||
local pid=$( ps | grep "dclient -u" | grep -v "grep" | awk '{print $1}' )
|
||||
|
||||
if [ -n "$pid" ]; then
|
||||
kill -9 $pid
|
||||
fi
|
||||
|
||||
echo "ZTE Client has stoped."
|
||||
}
|
||||
|
45
package/lean/luci-app-dclient/src/i18n/zh-cn/dclient.zh-cn.po
Executable file
45
package/lean/luci-app-dclient/src/i18n/zh-cn/dclient.zh-cn.po
Executable file
@ -0,0 +1,45 @@
|
||||
msgid "ZTE 802.1X"
|
||||
msgstr "中兴802.1X"
|
||||
|
||||
msgid "802.1X Config"
|
||||
msgstr "配置帐号信息"
|
||||
|
||||
msgid "View Logfile"
|
||||
msgstr "显示日志文件"
|
||||
|
||||
msgid "Dlient Log"
|
||||
msgstr "中兴认证日志"
|
||||
|
||||
msgid "Interface"
|
||||
msgstr "网卡接口"
|
||||
|
||||
msgid "ZTE User"
|
||||
msgstr "中兴帐号"
|
||||
|
||||
msgid "ZTE Pass"
|
||||
msgstr "中兴密码"
|
||||
|
||||
msgid "Choice a Auth Interface"
|
||||
msgstr "选择需要认证的网卡"
|
||||
|
||||
msgid "Enet Auth"
|
||||
msgstr "天翼校园网"
|
||||
|
||||
msgid "Enet User"
|
||||
msgstr "天翼帐号"
|
||||
|
||||
msgid "Enet Pass"
|
||||
msgstr "天翼密码"
|
||||
|
||||
msgid "Timeout(s)"
|
||||
msgstr "超时时间(秒)"
|
||||
|
||||
msgid "Timeout interval"
|
||||
msgstr "心跳超时重试时间间隔"
|
||||
|
||||
msgid "DHCP Client"
|
||||
msgstr "DHCP客户端"
|
||||
|
||||
msgid "auto"
|
||||
msgstr "自动"
|
||||
|
16
package/lean/luci-app-dclient/src/luci/controller/dclient.lua
Executable file
16
package/lean/luci-app-dclient/src/luci/controller/dclient.lua
Executable file
@ -0,0 +1,16 @@
|
||||
|
||||
-- Author: Zeyes <lixize8888@qq.com>
|
||||
|
||||
module("luci.controller.dclient", package.seeall)
|
||||
|
||||
function index()
|
||||
entry({"admin", "network", "dclient"}, firstchild(), _("ZTE 802.1X"), 100).dependent = false
|
||||
entry({"admin", "network", "dclient", "config"}, cbi("dclient"), _("802.1X Config"), 1)
|
||||
entry({"admin", "network", "dclient", "log_view"}, call("dclient_log"), _("View Logfile"), 2)
|
||||
end
|
||||
|
||||
|
||||
function dclient_log()
|
||||
local logfile = luci.sys.exec("cat /tmp/zte.log")
|
||||
luci.template.render("dclient_viewer", { title=luci.i18n.translate("Dlient Log"), content=logfile})
|
||||
end
|
55
package/lean/luci-app-dclient/src/luci/model/cbi/dclient.lua
Executable file
55
package/lean/luci-app-dclient/src/luci/model/cbi/dclient.lua
Executable file
@ -0,0 +1,55 @@
|
||||
--[[
|
||||
LuCI - Lua Configuration Interface
|
||||
|
||||
Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
|
||||
|
||||
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
|
||||
]]--
|
||||
|
||||
require("luci.sys")
|
||||
|
||||
m = Map("dclient", translate("中兴802.1X认证"), translate("配置中兴802.1X和电信天翼认证.(关注微信公众号:DotTimes)"))
|
||||
|
||||
s = m:section(TypedSection, "login", "")
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
zteenable = s:option(Flag, "enable", translate("Enable"))
|
||||
zteuser = s:option(Value, "zteuser", translate("ZTE User"))
|
||||
ztepass = s:option(Value, "ztepass", translate("ZTE Pass"))
|
||||
ztepass.password = true
|
||||
|
||||
ifname = s:option(ListValue, "ifname", translate("Interface"), translate("Choice a Auth Interface"))
|
||||
for k, v in ipairs(luci.sys.net.devices()) do
|
||||
if v ~= "lo" then
|
||||
ifname:value(v)
|
||||
end
|
||||
end
|
||||
timeout = s:option(ListValue, "timeout", translate("Timeout(s)"), translate("Timeout interval"))
|
||||
timeout:value(0,translate("Disable"))
|
||||
timeout:value(300)
|
||||
timeout:value(420)
|
||||
timeout:value(600)
|
||||
timeout:value(900)
|
||||
timeout:value(1800)
|
||||
timeout:value(3600)
|
||||
|
||||
dhcpclient = s:option(ListValue, "dhcpclient", translate("DHCP Client"))
|
||||
dhcpclient:value('auto',translate('auto'))
|
||||
dhcpclient:value('udhcpc')
|
||||
|
||||
enet = s:option(Flag, "enet", translate("Enet Auth"))
|
||||
enetuser = s:option(Value, "enetuser", translate("Enet User"))
|
||||
enetpass = s:option(Value, "enetpass", translate("Enet Pass"))
|
||||
enetpass.password = true
|
||||
|
||||
local apply = luci.http.formvalue("cbi.apply")
|
||||
if apply then
|
||||
io.popen("/etc/init.d/dclient restart")
|
||||
end
|
||||
|
||||
return m
|
10
package/lean/luci-app-dclient/src/luci/view/dclient_viewer.htm
Executable file
10
package/lean/luci-app-dclient/src/luci/view/dclient_viewer.htm
Executable file
@ -0,0 +1,10 @@
|
||||
<%# Author: Zeyes <lixize8888@qq.com> -%>
|
||||
|
||||
<%+header%>
|
||||
<h3 name="title"><%=title%></h3>
|
||||
<div id="content_fileviewer">
|
||||
<textarea style="width: 100%; " readonly="readonly" wrap="off" rows="<%=content:cmatch("\n")+10%>" id="content_id"><%=content:pcdata()%>
|
||||
<%-:No log data...-%>
|
||||
</textarea>
|
||||
</div>
|
||||
<%+footer%>
|
4
package/lean/luci-app-dclient/src/usr/bin/rm_dclient_log.sh
Executable file
4
package/lean/luci-app-dclient/src/usr/bin/rm_dclient_log.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
# 用来删除dclient产生的日志
|
||||
rm -rf /tmp/zte.log
|
Loading…
Reference in New Issue
Block a user