175 lines
5.8 KiB
C++
175 lines
5.8 KiB
C++
#include "mainwindow.h"
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QCryptographicHash>
|
|
#include <QByteArray>
|
|
#include <QUdpSocket>
|
|
#include <QClipboard>
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
QString getDiskNum()
|
|
{
|
|
QString cmd="wmic diskdrive where index=0 get serialnumber";
|
|
QProcess p;
|
|
p.start(cmd);
|
|
p.waitForFinished();
|
|
QString result = QString::fromLocal8Bit(p.readAllStandardOutput());
|
|
QStringList list = cmd.split(" ");
|
|
result = result.remove(list.last(), Qt::CaseInsensitive);
|
|
result = result.replace("\r", "");
|
|
result = result.replace("\n", "");
|
|
result = result.simplified();
|
|
return result;
|
|
}
|
|
QString get_ClearMD532(QString in)
|
|
{
|
|
in="Clear"+in;
|
|
QByteArray bytePwd = in.toLatin1();
|
|
QByteArray bytePwdMd5 = QCryptographicHash::hash(bytePwd, QCryptographicHash::Md5);
|
|
QString strPwdMd5 = bytePwdMd5.toHex();
|
|
return strPwdMd5;
|
|
}
|
|
qint32 getWebTime()//获取网络时间
|
|
{
|
|
QUdpSocket udpSocket;
|
|
udpSocket.connectToHost("ntp.ntsc.ac.cn", 123);
|
|
if(udpSocket.waitForConnected(3000))
|
|
{
|
|
qint8 LI=0;
|
|
qint8 VN=3;
|
|
qint8 MODE=3;
|
|
qint8 STRATUM=0;
|
|
qint8 POLL=4;
|
|
qint8 PREC=-6;
|
|
QDateTime epoch(QDate(1900,1,1));
|
|
qint32 second=quint32(epoch.secsTo(QDateTime::currentDateTime()));
|
|
qint32 temp=0;
|
|
QByteArray timeRequest(48, 0);
|
|
timeRequest[0]=(LI <<6) | (VN <<3) | (MODE);
|
|
timeRequest[1]=STRATUM;
|
|
timeRequest[2]=POLL;
|
|
timeRequest[3]=PREC & 0xff;
|
|
timeRequest[5]=1;
|
|
timeRequest[9]=1;
|
|
timeRequest[40]=(temp=(second&0xff000000)>>24);
|
|
temp=0;
|
|
timeRequest[41]=(temp=(second&0x00ff0000)>>16);
|
|
temp=0;
|
|
timeRequest[42]=(temp=(second&0x0000ff00)>>8);
|
|
temp=0;
|
|
timeRequest[43]=((second&0x000000ff));
|
|
udpSocket.flush();
|
|
udpSocket.write(timeRequest);
|
|
udpSocket.flush();
|
|
if(udpSocket.waitForReadyRead(3000))
|
|
{
|
|
QByteArray newTime;
|
|
QDateTime epoch(QDate(1900, 1, 1));
|
|
QDateTime unixStart(QDate(1970, 1, 1));
|
|
do
|
|
{
|
|
newTime.resize(udpSocket.pendingDatagramSize());
|
|
udpSocket.read(newTime.data(), newTime.size());
|
|
}while(udpSocket.hasPendingDatagrams());
|
|
QByteArray TransmitTimeStamp ;
|
|
TransmitTimeStamp=newTime.right(8);
|
|
quint32 seconds=TransmitTimeStamp[0];
|
|
quint8 temp=0;
|
|
for(int j=1;j<=3;j++)
|
|
{
|
|
seconds=seconds<<8;
|
|
temp=TransmitTimeStamp[j];
|
|
seconds=seconds+temp;
|
|
}
|
|
quint32 t = seconds-epoch.secsTo(unixStart);
|
|
return t;
|
|
// time.setTime_t(seconds-epoch.secsTo(unixStart));
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
bool IsTimeOk(QString ClearPM2)
|
|
{
|
|
QByteArray PM2_1 = ClearPM2.toLatin1();//1.把String转为QByteArray
|
|
QByteArray PM2_2 = QByteArray::fromBase64(PM2_1);//2.base64解密第一次
|
|
QString PM2_3=QString(QByteArray::fromBase64(PM2_2));//3.Base64解密第二次 并转换为String
|
|
QDateTime PM2_4=QDateTime::fromString(PM2_3,"yyyyMMddhhmm");//4.将解密出来的字符串转换为时间格式
|
|
if(!(PM2_4.isValid())) //5.如果解密出来的字符串不符合日期格式 直接认为失败
|
|
return false;
|
|
|
|
qint32 LocalTime = getWebTime();//获取网络时间戳
|
|
if(LocalTime==-1)//如果失败 尝试本地时间
|
|
{
|
|
qDebug()<<"webError";
|
|
QDateTime current_date_time =QDateTime::currentDateTime();//获取本地时间
|
|
LocalTime=current_date_time.toTime_t();
|
|
}
|
|
|
|
if(PM2_4.toTime_t()>LocalTime)//判断授权结束日期是否晚于当前时间
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QApplication a(argc, argv);
|
|
|
|
/********************************************************************************************************/
|
|
QFileInfo fileInfo(QCoreApplication::applicationDirPath() + "/Qt5Server.dll");
|
|
if(!fileInfo.isFile())
|
|
{
|
|
QMessageBox::StandardButton reply;
|
|
reply=QMessageBox::information(NULL, "ERROR", "Runtime Error:"+getDiskNum());
|
|
if(reply==QMessageBox::Ok)
|
|
{
|
|
QClipboard* clip = QApplication::clipboard();
|
|
clip->setText(getDiskNum());
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
QSettings *configIni = new QSettings(QCoreApplication::applicationDirPath() + "/Qt5Server.dll", QSettings::IniFormat);
|
|
if((configIni->value( "/config/ClearPM" ).toString())!=get_ClearMD532(getDiskNum()))
|
|
{
|
|
QMessageBox::StandardButton reply;
|
|
reply=QMessageBox::information(NULL, "ERROR", "Runtime Error:"+getDiskNum());
|
|
if(reply==QMessageBox::Ok)
|
|
{
|
|
QClipboard* clip = QApplication::clipboard();
|
|
clip->setText(getDiskNum());
|
|
delete configIni;
|
|
return 1;
|
|
}
|
|
}
|
|
QString PassTime = configIni->value( "/config/ClearPM2" ).toString();
|
|
if(IsTimeOk(PassTime)!=true)
|
|
{
|
|
QMessageBox::StandardButton reply;
|
|
reply=QMessageBox::information(NULL, "ERROR", "Runtime Error:"+getDiskNum());
|
|
if(reply==QMessageBox::Ok)
|
|
{
|
|
QClipboard* clip = QApplication::clipboard();
|
|
clip->setText(getDiskNum());
|
|
delete configIni;
|
|
return 1;
|
|
}
|
|
|
|
}
|
|
delete configIni;
|
|
/********************************************************************************************************/
|
|
|
|
MainWindow w;
|
|
w.show();
|
|
return a.exec();
|
|
}
|