18,357
社区成员
发帖
与我相关
我的任务
分享
BOOL CSrvManager::CheckLicenseOk(CString sLicenseIn)
{
m_bTryVersion = FALSE;
m_bTryFull = FALSE;
USES_CONVERSION;
CEncryption decode;
CString sLicense;
char in[500];
char out[500];
memset(in, 0, 500);
memset(out, 0, 500);
strcpy(in,sLicenseIn);
decode.Decrypt(in,out);
sLicense = out;
CString sLIp,sLSessionNumb,sLMaxSessionUsers,sFreeUsers;
CString sTryDays,sTryStart;
int pos;
pos = sLicense.Find(_T('|'));
if (pos >= 0)
{
sLIp = sLicense.Left(pos);
}
if (pos >= 0)
{
sLicense = sLicense.Mid(pos+1);
pos = sLicense.Find(_T('|'));
if (pos >= 0)
{
sLSessionNumb = sLicense.Left(pos);
}
}
if (pos >= 0)
{
sLicense = sLicense.Mid(pos+1);
pos = sLicense.Find(_T('|'));
if (pos >= 0 )
{
sLMaxSessionUsers = sLicense.Left(pos);
m_nLMaxSessionUsers = atoi(sLMaxSessionUsers);//最大用户数
}
}
if (pos >= 0)
{
sLicense = sLicense.Mid(pos+1);
pos = sLicense.Find(_T('|'));
if (pos >= 0)
{
sFreeUsers = sLicense.Left(pos);
sFreeUsers.TrimLeft();
sFreeUsers.TrimRight();
}
}
if (pos >= 0)
{
sLicense = sLicense.Mid(pos+1);
pos = sLicense.Find(_T('|'));
if (pos >= 0 )
{
sTryDays = sLicense.Left(pos);
sTryDays.TrimLeft();
sTryDays.TrimRight();
m_nTryDay = atoi(sTryDays);
if ( m_nTryDay> 0)
m_bTryVersion = TRUE;
}
}
if (pos >= 0)
{
sLicense = sLicense.Mid(pos+1);
pos = sLicense.Find(_T('|'));
if (pos >= 0)
{
sTryStart = sLicense.Left(pos);
sTryStart.TrimLeft();
sTryStart.TrimRight();
m_sTryStart = sTryStart;
CString str = m_sTryStart.Left(4);
int years = atoi(str);
str = m_sTryStart.Mid(4);
int m = atoi(str.Mid(2));
str = m_sTryStart.Mid(6);
int d = atoi(str);
CTime t1(years,m,d,0,0,0);
CTime t2 = CTime::GetCurrentTime();
CTimeSpan ts = t2 - t1;
if (ts.GetDays() - m_nTryDay > 0)
m_bTryFull = TRUE;
}
}
sLIp.TrimLeft();
sLIp.TrimRight();
sLIp.MakeLower();
if (m_bTryFull)
{
m_nLMaxSessionUsers = 4;//最大用户数
}
BOOL bMatch = FALSE;
CStringArray macArr;
GetAllLocalAdapterMacAddr(macArr);
for (int i =0; i < macArr.GetSize(); i ++)
{
CString sMac = macArr.GetAt(i);
if (sMac == sLIp)
{
bMatch = TRUE;
break;
}
}
return bMatch;
}BOOL CSrvManager::CheckLicense()
{
try
{
long nAppID = 0x410541; //应用程序ID, 4字节,通过设号工具设置
long Keys[8]= {0};
long nKeyNum = 0;
BOOL ret = 1;
if( 0 != NoxFind(nAppID,Keys, &nKeyNum))
{
ret = 0 ;
return FALSE;
}
//打开第一只加密锁
char * userPin = "F6822DC1D06944FC"; //用户密码,通过设号工具设置
if( 0 != NoxOpen(Keys[0],userPin))
{
ret = 0 ;
return FALSE;
}
//存储区读(16字节)
unsigned char readStorage[16] = {0};
if( 0 != NoxReadStorage(Keys[0],readStorage))
{
ret = 0 ;
return FALSE;
}
CString sLicense = readStorage;
sLicense.MakeLower();
//关闭加密锁
NoxClose(Keys[0]);
if (!ret)
{
return FALSE;
}
CString sLSessionNumb,sLMaxSessionUsers,sLFreeUsers;
int pos;
pos = sLicense.Find(_T('|'));
if (pos >= 0)
{
sLSessionNumb = sLicense.Left(pos);
}
sLicense = sLicense.Mid(pos+1);
pos = sLicense.Find(_T('|'));
if (pos >= 0)
{
sLMaxSessionUsers = sLicense.Left(pos);
}
sLicense = sLicense.Mid(pos+1);
pos = sLicense.Find(_T('|'));
if (pos >= 0)
{
sLFreeUsers = sLicense.Left(pos);
}
if (sLSessionNumb.IsEmpty() || sLMaxSessionUsers.IsEmpty())
return FALSE;
m_nLMaxSessionUsers = atoi(sLMaxSessionUsers);//最大用户数量
m_bTryVersion = FALSE;
}
catch (...)
{
return FALSE;
}
return TRUE;
}
void CServerManagerDlg::CheckLicenseStatus()
{
CSrvManager&s = CSrvManager::GetInstance();
BOOL ret = s.CheckLicense();
if (!ret)
ret = s.CheckLicenseOk(s.GetLicenseStr());
if (ret)
{
CString str;
if (s.m_nLMaxSessionUsers < 0)
{
str.Format("服务器管理器 - 注册版(无限制会议数和人数)");
}
else
{
if (!s.m_bTryVersion)
str.Format("服务器管理器 - 注册版(%d)",s.m_nLMaxSessionUsers);
else
{
if (s.m_bTryFull)
str.Format("服务器管理器 - 试用版已到期 试用了%d天",s.m_nTryDay);
else
str.Format("服务器管理器 - 试用版(%d) 试用%d天",s.m_nLMaxSessionUsers,s.m_nTryDay);
}
}
SetWindowText(str);
}
else
SetWindowText("服务器管理器 - 非注册版(会议允许最大4人)");
}
int GetAllLocalAdapterMacAddr(CStringArray& mac)
{
NCB ncb;
LANA_ENUM AdapterList;
memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char *)&AdapterList;
ncb.ncb_length = sizeof(AdapterList);
Netbios(&ncb);
mac.RemoveAll();
for (int i = 0; i < AdapterList.length ; ++i )
{
struct ASTAT
{
ADAPTER_STATUS adapt;
NAME_BUFFER psz_name[30];
} Adapter;
// Reset the LAN adapter so that we can begin querying it
NCB Ncb;
memset( &Ncb, 0, sizeof (Ncb));
Ncb.ncb_command = NCBRESET;
Ncb.ncb_lana_num = AdapterList.lana[i];
if (Netbios(&Ncb) != NRC_GOODRET)
continue;
// Prepare to get the adapter status block
memset(&Ncb, 0, sizeof(Ncb)) ;
Ncb.ncb_command = NCBASTAT;
Ncb.ncb_lana_num = AdapterList.lana[ i ];
strcpy((char *)Ncb.ncb_callname, "*" );
memset(&Adapter, 0, sizeof (Adapter));
Ncb.ncb_buffer = (unsigned char *)&Adapter;
Ncb.ncb_length = sizeof (Adapter);
// Get the adapter's info and, if this works, return it in standard,
// colon-delimited form.
CString sMac;
CString str;
if ( Netbios( &Ncb ) == 0 )
{
for (int i=0; i<6; i++)
{
Adapter.adapt.adapter_address[i];
str.Format("%02x",(int)(Adapter.adapt.adapter_address[i]));
sMac += str;
sMac += "-";
}
}
else
break;
sMac = sMac.Left(sMac.GetLength() - 1);
sMac.MakeLower();
mac.Add(sMac);
}
return 0;
}