[new] 新增正则表达式和管理员密码输入
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "json/jsonobject.h"
|
||||
#include <QProcess>
|
||||
#include <QDebug>
|
||||
#include <QRegularExpression>
|
||||
|
||||
//NetworkManager* NetworkManager::instance = nullptr;
|
||||
|
||||
@@ -72,7 +73,7 @@ bool NetworkManager::restart(QString& err_info)
|
||||
connect(myProcess, SIGNAL(finished(int)), myProcess, SLOT(deleteLater()));
|
||||
myProcess->start("/bin/sh", args);
|
||||
|
||||
if (!myProcess->waitForFinished()) {
|
||||
if (!myProcess->waitForFinished(60000)) {
|
||||
err_info.append("failed...\n");
|
||||
return false;
|
||||
}
|
||||
@@ -81,7 +82,7 @@ bool NetworkManager::restart(QString& err_info)
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -120,6 +121,17 @@ bool NetworkManager::setDefaultIpAddr(const IpAddr& addr, QString& err_info)
|
||||
|
||||
}
|
||||
|
||||
bool NetworkManager::validate(const QString& addr)
|
||||
{
|
||||
QRegularExpression ipFormat("^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");
|
||||
QRegularExpressionMatch mre = ipFormat.match(addr);
|
||||
if (mre.hasMatch())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString NetworkManager::NewExp(QString ip, QString mask)
|
||||
{
|
||||
QStringList list = mask.split(".");
|
||||
@@ -163,7 +175,7 @@ bool NetworkManager::setIpAddrList(const QList<QStringList>& list, QString& err_
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -188,7 +200,7 @@ bool NetworkManager::setDefaultGateway(const QString& gw, QString& err_info)
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -221,9 +233,9 @@ bool NetworkManager::setIpRouteList(const QList<QStringList>& list, QString& err
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
err_info.append(cmd);
|
||||
err_info.append("\n");
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
err_info.append(cmd);
|
||||
err_info.append("\n");
|
||||
err_info.append(myProcess->readAllStandardError());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
static bool setIpRouteList(const QList<QStringList>& list, QString& err_info);
|
||||
static QString NewExp(QString ip, QString mask);
|
||||
|
||||
static bool validate(const QString& addr);
|
||||
|
||||
static bool testSetMode(QString& err_info);
|
||||
static void testGetMode();
|
||||
|
||||
Reference in New Issue
Block a user