fix(wpa-wifi): PwdFlag in wpa-dialog is not sync with network manager
Description: 修复是否询问密码设置与NetwordManager不互通的bug Log: 修复连接企业wifi显示未提供密码的bug Bug: http://172.17.66.192/biz/bug-view-27649.html http://172.17.66.192/biz/bug-view-31120.html
This commit is contained in:
parent
7b8dc8b0ac
commit
d879048699
|
@ -713,6 +713,7 @@ void OneConnForm::on_btnInfo_clicked()
|
||||||
// Wifi连接结果,0成功 1失败 2没有配置文件
|
// Wifi连接结果,0成功 1失败 2没有配置文件
|
||||||
void OneConnForm::slotConnWifiResult(int connFlag)
|
void OneConnForm::slotConnWifiResult(int connFlag)
|
||||||
{
|
{
|
||||||
|
mw->is_stop_check_net_state = 0;
|
||||||
qDebug()<<"Function slotConnWifiResult receives a number: "<<connFlag;
|
qDebug()<<"Function slotConnWifiResult receives a number: "<<connFlag;
|
||||||
|
|
||||||
if (!connType.isEmpty()) {
|
if (!connType.isEmpty()) {
|
||||||
|
@ -743,12 +744,12 @@ void OneConnForm::slotConnWifiResult(int connFlag)
|
||||||
ui->btnConnPWD->show();
|
ui->btnConnPWD->show();
|
||||||
|
|
||||||
this->isSelected = true;
|
this->isSelected = true;
|
||||||
if (connFlag == 2) {
|
// if (connFlag == 2) {
|
||||||
mw->is_stop_check_net_state = 0;
|
// mw->is_stop_check_net_state = 0;
|
||||||
} else {
|
// } else {
|
||||||
mw->is_stop_check_net_state = 0;
|
// mw->is_stop_check_net_state = 0;
|
||||||
//connType = "RequestPassword";
|
// //connType = "RequestPassword";
|
||||||
}
|
// }
|
||||||
|
|
||||||
//设置输入密码框被选中
|
//设置输入密码框被选中
|
||||||
ui->lePassword->setFocus();
|
ui->lePassword->setFocus();
|
||||||
|
@ -770,7 +771,7 @@ void OneConnForm::slotConnWifiResult(int connFlag)
|
||||||
syslog(LOG_ERR, "execute 'nmcli connection delete' in function 'slotConnWifiResult' failed");
|
syslog(LOG_ERR, "execute 'nmcli connection delete' in function 'slotConnWifiResult' failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
mw->is_stop_check_net_state = 0;
|
// mw->is_stop_check_net_state = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置全局变量,当前连接Wifi的信号强度
|
// 设置全局变量,当前连接Wifi的信号强度
|
||||||
|
|
|
@ -27,20 +27,32 @@
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
#include <QCompleter>
|
#include <QCompleter>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QIODevice>
|
||||||
|
|
||||||
const QString CONFIG_FILE = "/tmp/wpaconf.ini";
|
const QString CONFIG_FILE = "/tmp/wpaconf.ini";
|
||||||
|
|
||||||
UpConnThread::UpConnThread()
|
UpConnThread::UpConnThread(const QString& user, const QString& pwd)
|
||||||
{
|
{
|
||||||
|
m_user = user;
|
||||||
|
m_pwd = pwd;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpConnThread::~UpConnThread() {
|
UpConnThread::~UpConnThread() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpConnThread::run() {
|
void UpConnThread::run() {
|
||||||
QString cmdStr = "nmcli connection up " + this->conn_name;
|
QString cmdStr = 0;
|
||||||
|
QFile::remove(QString("/tmp/%1.txt").arg(conn_name).toUtf8());
|
||||||
|
QFile *passwdFile = new QFile(QString("/tmp/%1.txt").arg(conn_name));
|
||||||
|
if (passwdFile->open(QIODevice::ReadWrite)) {
|
||||||
|
passwdFile->write(QString("802-1x.identity:%1\n802-1x.password:%2").arg(m_user).arg(m_pwd).toUtf8());
|
||||||
|
passwdFile->close();
|
||||||
|
cmdStr = "nmcli connection up " + this->conn_name + " passwd-file /tmp/" + conn_name + ".txt";
|
||||||
|
} else {
|
||||||
|
cmdStr = "nmcli connection up " + this->conn_name;
|
||||||
|
}
|
||||||
qDebug()<<"qDebug: 激活连接: \n"<<
|
qDebug()<<"qDebug: 激活连接: \n"<<
|
||||||
"qDebug: nmcli connection up " + this->conn_name;
|
"qDebug: " + cmdStr;
|
||||||
int res = Utils::m_system(cmdStr.toUtf8().data());
|
int res = Utils::m_system(cmdStr.toUtf8().data());
|
||||||
emit connRes(res);
|
emit connRes(res);
|
||||||
}
|
}
|
||||||
|
@ -273,6 +285,7 @@ void WpaWifiDialog::initCombox() {
|
||||||
}
|
}
|
||||||
// //读配置文件
|
// //读配置文件
|
||||||
wifi_info = getWifiInfo(connectionName);
|
wifi_info = getWifiInfo(connectionName);
|
||||||
|
// qDebug() << wifi_info << wifi_info.length();
|
||||||
if (wifi_info.length() < 4) {
|
if (wifi_info.length() < 4) {
|
||||||
askPwdBtn->setChecked(true);
|
askPwdBtn->setChecked(true);
|
||||||
has_config = false;
|
has_config = false;
|
||||||
|
@ -281,16 +294,17 @@ void WpaWifiDialog::initCombox() {
|
||||||
//读配置信息
|
//读配置信息
|
||||||
eapCombox->setCurrentIndex(eapCombox->findData(wifi_info.at(0)));
|
eapCombox->setCurrentIndex(eapCombox->findData(wifi_info.at(0)));
|
||||||
innerCombox->setCurrentIndex(innerCombox->findData(wifi_info.at(1)));
|
innerCombox->setCurrentIndex(innerCombox->findData(wifi_info.at(1)));
|
||||||
if (wifi_info.at(wifi_info.length() - 1) == "true") {
|
getPwdFlag();
|
||||||
|
if (pwd_flag == 2) {
|
||||||
askPwdBtn->setChecked(true);
|
askPwdBtn->setChecked(true);
|
||||||
for (int i = 2; i < wifi_info.length() - 1; i++) {
|
for (int i = 2; i < wifi_info.length() - 1; i++) {
|
||||||
user_list << wifi_info.at(i);
|
user_list << wifi_info.at(i);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
askPwdBtn->setChecked(false);
|
askPwdBtn->setChecked(false);
|
||||||
pwdEditor->setText(wifi_info.at(wifi_info.length() - 2));
|
pwdEditor->setText(wifi_info.at(wifi_info.length() - 1));
|
||||||
this->connectBtn->setEnabled(true);
|
this->connectBtn->setEnabled(true);
|
||||||
for (int i = 2; i < wifi_info.length() - 2; i++) {
|
for (int i = 2; i < wifi_info.length() - 1; i++) {
|
||||||
user_list << wifi_info.at(i);
|
user_list << wifi_info.at(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,6 +317,47 @@ void WpaWifiDialog::initCombox() {
|
||||||
userEditor->setCompleter(completer);
|
userEditor->setCompleter(completer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief WpaWifiDialog::getPwdFlag 获取是否每次询问密码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void WpaWifiDialog::getPwdFlag() {
|
||||||
|
QProcess * process = new QProcess(this);
|
||||||
|
QString ssid = nameEditor->text();
|
||||||
|
if (ssid.contains(" ")) {
|
||||||
|
ssid.replace(QRegExp("[\\s]"), "\\\ "); //防止名字包含空格导致指令识别错误,需要转义
|
||||||
|
}
|
||||||
|
process->start(QString("nmcli -f 802-1x.password-flags connection show %1").arg(ssid));
|
||||||
|
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
|
||||||
|
process->deleteLater();
|
||||||
|
});
|
||||||
|
connect(process, &QProcess::readyReadStandardOutput, this, [ = ]() {
|
||||||
|
QString str = process->readAllStandardOutput();
|
||||||
|
pwd_flag = str.mid(str.lastIndexOf(" ") - 1, 1).toInt();
|
||||||
|
});
|
||||||
|
process->waitForFinished();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief WpaWifiDialog::setPwdFlag 设置是否每次询问密码
|
||||||
|
* @param flag 0不询问, 2询问
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool WpaWifiDialog::setPwdFlag(const int & flag) {
|
||||||
|
QProcess * process = new QProcess;
|
||||||
|
QString ssid = nameEditor->text();
|
||||||
|
if (ssid.contains(" ")) {
|
||||||
|
ssid.replace(QRegExp("[\\s]"), "\\\ "); //防止名字包含空格导致指令识别错误,需要转义
|
||||||
|
}
|
||||||
|
process->start(QString("nmcli connection modify %1 802-1x.password-flags %2").arg(ssid).arg(QString::number(flag)));
|
||||||
|
connect(process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, [ = ]() {
|
||||||
|
process->deleteLater();
|
||||||
|
});
|
||||||
|
process->waitForFinished();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void WpaWifiDialog::initConnect() {
|
void WpaWifiDialog::initConnect() {
|
||||||
//取消按钮
|
//取消按钮
|
||||||
connect(cancelBtn, &QPushButton::clicked, this, [ = ]() {
|
connect(cancelBtn, &QPushButton::clicked, this, [ = ]() {
|
||||||
|
@ -332,7 +387,7 @@ void WpaWifiDialog::slot_line_edit_changed() {
|
||||||
|
|
||||||
void WpaWifiDialog::slot_on_connectBtn_clicked() {
|
void WpaWifiDialog::slot_on_connectBtn_clicked() {
|
||||||
qDebug()<<"Clicked on connect Btn!";
|
qDebug()<<"Clicked on connect Btn!";
|
||||||
//先写配置文件
|
//写/tmp/wpaconfig.ini配置文件
|
||||||
if (has_config) {
|
if (has_config) {
|
||||||
appendWifiUser(nameEditor->text(), userEditor->text());
|
appendWifiUser(nameEditor->text(), userEditor->text());
|
||||||
} else {
|
} else {
|
||||||
|
@ -350,6 +405,8 @@ void WpaWifiDialog::slot_on_connectBtn_clicked() {
|
||||||
QString cmdStr_1 = "nmcli connection modify " + nameEditor->text() + " 802-1x.eap " + eapCombox->currentData().toString()+ " 802-1x.phase2-auth "
|
QString cmdStr_1 = "nmcli connection modify " + nameEditor->text() + " 802-1x.eap " + eapCombox->currentData().toString()+ " 802-1x.phase2-auth "
|
||||||
+ innerCombox->currentData().toString() + " 802-1x.identity " + userEditor->text() + " 802-1x.password " + pwdEditor->text();
|
+ innerCombox->currentData().toString() + " 802-1x.identity " + userEditor->text() + " 802-1x.password " + pwdEditor->text();
|
||||||
Utils::m_system(cmdStr_1.toUtf8().data());
|
Utils::m_system(cmdStr_1.toUtf8().data());
|
||||||
|
if (askPwdBtn->isChecked()) setPwdFlag(2);
|
||||||
|
else setPwdFlag(0);
|
||||||
//激活连接
|
//激活连接
|
||||||
activateConnection();
|
activateConnection();
|
||||||
} else {
|
} else {
|
||||||
|
@ -376,6 +433,8 @@ void WpaWifiDialog::slot_on_connectBtn_clicked() {
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
syslog(LOG_DEBUG, "In function slot_on_connectBtn_clicked, created a wifi config named %s", nameEditor->text());
|
syslog(LOG_DEBUG, "In function slot_on_connectBtn_clicked, created a wifi config named %s", nameEditor->text());
|
||||||
qDebug() << "qDebug: created a wifi config successfully";
|
qDebug() << "qDebug: created a wifi config successfully";
|
||||||
|
if (askPwdBtn->isChecked()) setPwdFlag(2);
|
||||||
|
else setPwdFlag(0);
|
||||||
//创建成功,激活连接
|
//创建成功,激活连接
|
||||||
activateConnection();
|
activateConnection();
|
||||||
} else {
|
} else {
|
||||||
|
@ -400,7 +459,7 @@ void WpaWifiDialog::setEditorEnable(bool is_checking) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WpaWifiDialog::activateConnection() {
|
void WpaWifiDialog::activateConnection() {
|
||||||
UpConnThread * upThread = new UpConnThread();
|
UpConnThread * upThread = new UpConnThread(userEditor->text(), pwdEditor->text());
|
||||||
upThread->conn_name = nameEditor->text();
|
upThread->conn_name = nameEditor->text();
|
||||||
//超时计时器
|
//超时计时器
|
||||||
QTimer * timeout = new QTimer(this);
|
QTimer * timeout = new QTimer(this);
|
||||||
|
@ -462,10 +521,7 @@ QStringList WpaWifiDialog::getWifiInfo(QString wifiName) {
|
||||||
wlist << autoSettings.get()->value("user").toString();
|
wlist << autoSettings.get()->value("user").toString();
|
||||||
}
|
}
|
||||||
autoSettings.get()->endArray();
|
autoSettings.get()->endArray();
|
||||||
if (!autoSettings.get()->value("askpwd").toBool()) {
|
wlist << autoSettings.get()->value("pwd").toString();
|
||||||
wlist << autoSettings.get()->value("pwd").toString();
|
|
||||||
}
|
|
||||||
wlist << autoSettings.get()->value("askpwd").toString();
|
|
||||||
autoSettings.get()->endGroup();
|
autoSettings.get()->endGroup();
|
||||||
return wlist;
|
return wlist;
|
||||||
}
|
}
|
||||||
|
@ -482,11 +538,8 @@ bool WpaWifiDialog::appendWifiInfo(QString name, QString eap, QString inner, QSt
|
||||||
autoSettings.get()->setValue("user", user);
|
autoSettings.get()->setValue("user", user);
|
||||||
user_list << user;
|
user_list << user;
|
||||||
autoSettings.get()->endArray();
|
autoSettings.get()->endArray();
|
||||||
autoSettings.get()->setValue("askpwd", ask);
|
// autoSettings.get()->setValue("askpwd", ask);
|
||||||
//保存密码
|
autoSettings.get()->setValue("pwd", this->pwdEditor->text());
|
||||||
if (!ask) {
|
|
||||||
autoSettings.get()->setValue("pwd", this->pwdEditor->text());
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,10 +552,8 @@ bool WpaWifiDialog::appendWifiUser(QString name, QString user) {
|
||||||
autoSettings.get()->beginGroup(name);
|
autoSettings.get()->beginGroup(name);
|
||||||
autoSettings.get()->setValue("eap", eapCombox->currentData().toString());
|
autoSettings.get()->setValue("eap", eapCombox->currentData().toString());
|
||||||
autoSettings.get()->setValue("inner", innerCombox->currentData().toString());
|
autoSettings.get()->setValue("inner", innerCombox->currentData().toString());
|
||||||
autoSettings.get()->setValue("askpwd", askPwdBtn->isChecked());
|
// autoSettings.get()->setValue("askpwd", askPwdBtn->isChecked());
|
||||||
if (!askPwdBtn->isChecked()) {
|
autoSettings.get()->setValue("pwd", this->pwdEditor->text());
|
||||||
autoSettings.get()->setValue("pwd", this->pwdEditor->text());
|
|
||||||
}
|
|
||||||
if (user_list.contains(user)) {
|
if (user_list.contains(user)) {
|
||||||
autoSettings.get()->endGroup();
|
autoSettings.get()->endGroup();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -43,12 +43,14 @@ class UpConnThread : public QThread
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit UpConnThread();
|
explicit UpConnThread(const QString &, const QString &);
|
||||||
~UpConnThread();
|
~UpConnThread();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void run();
|
void run();
|
||||||
QString conn_name = 0;
|
QString conn_name = 0;
|
||||||
|
QString m_user = 0;
|
||||||
|
QString m_pwd = 0;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void connRes(int respond);
|
void connRes(int respond);
|
||||||
|
@ -67,11 +69,15 @@ private:
|
||||||
void initUI(); //初始化UI界面
|
void initUI(); //初始化UI界面
|
||||||
void initCombox(); //初始化所有下拉框
|
void initCombox(); //初始化所有下拉框
|
||||||
void initConnect(); //初始化连接
|
void initConnect(); //初始化连接
|
||||||
|
void getPwdFlag(); //获取是否每次询问密码
|
||||||
|
bool setPwdFlag(const int&); //设置是否每次询问密码
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int pwd_flag = 2; //是否每次询问密码,0保存密码,2询问,默认不保存密码
|
||||||
|
|
||||||
QString connectionName;
|
QString connectionName;
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
void mouseReleaseEvent(QMouseEvent *event);
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
|
|
Loading…
Reference in New Issue