Skip to content

Commit

Permalink
Update the file path from .config to /tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
handsome-feng committed Apr 15, 2020
1 parent 4499bdf commit 117ecc6
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 81 deletions.
9 changes: 9 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
kylin-nm (1.2.4-1) unstable; urgency=medium

* New upstream bugfix release:
- Fix that the UI stuck under multiple user.
- Fix that the wired network disconnected after docker started.
- Fix the wrong device object path.

-- handsome_feng <jianfengli@ubuntukylin.com> Wed, 15 Apr 2020 23:07:10 +0800

kylin-nm (1.2.3-1) unstable; urgency=medium

* New upstream bugfix release:
Expand Down
38 changes: 16 additions & 22 deletions src/backthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include <QFile>
#include <QRegExp>
#include <QStandardPaths>
#include <QDir>

BackThread::BackThread(QObject *parent) : QObject(parent){
cmdConnWifi = new QProcess(this);
Expand All @@ -45,16 +45,14 @@ BackThread::~BackThread()
IFace* BackThread::execGetIface(){
IFace *iface = new IFace();

QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-iface";

QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli -f TYPE,DEVICE,STATE device > " + localPath;
QString tmpPath = "/tmp/kylin-nm-iface-" + QDir::home().dirName();
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli -f TYPE,DEVICE,STATE device > " + tmpPath;
Utils::m_system(cmd.toUtf8().data());

// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device' in function 'execGetIface' failed");}

QFile file(localPath);
QFile file(tmpPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-iface!");
Expand Down Expand Up @@ -230,15 +228,14 @@ void BackThread::execConnLan(QString connName){
void BackThread::execConnWifiPWD(QString connName, QString password){
disConnLanOrWifi("wifi");

QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-btoutput";
QString tmpPath = "/tmp/kylin-nm-btoutput-" + QDir::home().dirName();

QString cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli device wifi connect '" + connName + "' password '" + password + "' > " + localPath;
QString cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli device wifi connect '" + connName + "' password '" + password + "' > " + tmpPath;
Utils::m_system(cmdStr.toUtf8().data());
// int status = system(cmdStr.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'execConnWifiPWD' failed");}

QFile file(localPath);
QFile file(tmpPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
syslog(LOG_DEBUG, "Can't open the file /tmp/kylin-nm-btoutput !");
qDebug()<<"Can't open the file /tmp/kylin-nm-btoutput !"<<endl;
Expand Down Expand Up @@ -298,15 +295,14 @@ void BackThread::on_readerror()
}

QString BackThread::getConnProp(QString connName){
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-connprop";
QString tmpPath = "/tmp/kylin-nm-connprop-" + QDir::home().dirName();

QString cmd = "nmcli connection show '" + connName + "' > " + localPath;
QString cmd = "nmcli connection show '" + connName + "' > " + tmpPath;
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'getConnProp' failed");}

QFile file(localPath);
QFile file(tmpPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-connprop!");
qDebug()<<"Can't open the file /tmp/kylin-nm-connprop!"<<endl;
Expand Down Expand Up @@ -355,15 +351,14 @@ QString BackThread::getConnProp(QString connName){
}

bool BackThread::execChkWifiExist(QString connName){
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-chkwifiexist";
QString tmpPath = "/tmp/kylin-nm-chkwifiexist-" + QDir::home().dirName();

QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection show '" + connName + "' > " + localPath;
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection show '" + connName + "' > " + tmpPath;
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'execChkWifiExist' failed");}

QFile file(localPath);
QFile file(tmpPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-chkwifiexist!");
Expand All @@ -380,15 +375,14 @@ bool BackThread::execChkWifiExist(QString connName){
}

QString BackThread::execChkLanWidth(QString ethName){
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-bandwidth";
QString tmpPath = "/tmp/kylin-nm-bandwidth-" + QDir::home().dirName();

QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';ethtool '" + ethName + "' | grep Speed > " + localPath;
QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';ethtool '" + ethName + "' | grep Speed > " + tmpPath;
Utils::m_system(cmd.toUtf8().data());
// int status = system(cmd.toUtf8().data());
// if (status != 0){ syslog(LOG_ERR, "execute 'ethtool' in function 'execChkLanWidth' failed");}

QFile file(localPath);
QFile file(tmpPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-bandwidth!");
Expand Down
24 changes: 17 additions & 7 deletions src/kylin-network-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/syslog.h>
#include <pwd.h>


//获取网络接口名
Expand Down Expand Up @@ -186,23 +187,30 @@ conlist *kylin_network_get_conlist_info()
}

//获取当前活动网络连接
activecon *kylin_network_get_activecon_info(char *path)
activecon *kylin_network_get_activecon_info()
{
struct passwd *pwd;
pwd = getpwuid(getuid());
char *name = pwd->pw_name;
char *tmpPrefix = "/tmp/kylin-nm-activecon-";
char *chr = "nmcli connection show -active > ";
char *cmd = (char *) malloc(strlen(chr) + strlen(path));
strcpy(cmd, chr);
strcat(cmd, path);
char *cmd;
asprintf(&cmd, "%s%s%s", chr, tmpPrefix, name);
char *path;
asprintf(&path, "%s%s", tmpPrefix, name);
int status = system(cmd);
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show -active' in function 'kylin_network_get_activecon_info' failed");}
if (status != 0)
syslog(LOG_ERR, "execute 'nmcli connection show -active' in function 'kylin_network_get_activecon_info' failed");
free(cmd);

char *filename = path;

FILE *activefp;
int activenum=0;
char activeStrLine[1024];
if((activefp=fopen(filename,"r"))==NULL)
if ((activefp=fopen(filename,"r"))==NULL)
{
printf("error!");

}
fgets(activeStrLine,1024,activefp);
while(!feof(activefp))
Expand All @@ -222,6 +230,8 @@ activecon *kylin_network_get_activecon_info(char *path)
printf("error!");

}
free(path);

fgets(StrLine,1024,fp);
while(!feof(fp))
{
Expand Down
2 changes: 1 addition & 1 deletion src/kylin-network-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ conlist *kylin_network_get_conlist_info();
* Get the active network connection.
* return the struct pointer.
*/
activecon *kylin_network_get_activecon_info(char *path);
activecon *kylin_network_get_activecon_info();

/*
* Create a new Ethernet connection.
Expand Down
13 changes: 3 additions & 10 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,10 +892,7 @@ void MainWindow::getActiveInfo()
QString actLanName = "--";
QString actWifiName = "--";

QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString lockPath = homePath.at(0) + "/.config/kylin-nm-activecon";

activecon *act = kylin_network_get_activecon_info(lockPath.toUtf8().data());
activecon *act = kylin_network_get_activecon_info();
int index = 0;
while(act[index].con_name != NULL){
if(QString(act[index].type) == "ethernet"){
Expand Down Expand Up @@ -1394,10 +1391,8 @@ void MainWindow::getLanListDone(QStringList slist)

// 获取当前连接的lan name
QString actLanName = "--";
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString lockPath = homePath.at(0) + "/.config/kylin-nm-activecon";

activecon *act = kylin_network_get_activecon_info(lockPath.toUtf8().data());
activecon *act = kylin_network_get_activecon_info();
int index = 0;
while(act[index].con_name != NULL){
if(QString(act[index].type) == "ethernet"){
Expand Down Expand Up @@ -1529,10 +1524,8 @@ void MainWindow::loadWifiListDone(QStringList slist)

// 获取当前连接的wifi name
QString actWifiName = "--";
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString lockPath = homePath.at(0) + "/.config/kylin-nm-activecon";

activecon *act = kylin_network_get_activecon_info(lockPath.toUtf8().data());
activecon *act = kylin_network_get_activecon_info();
int index = 0;
while(act[index].con_name != NULL){
if(QString(act[index].type) == "wifi"){
Expand Down
47 changes: 23 additions & 24 deletions wireless-security/dlgconnhidwifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <unistd.h>

#include <QStandardItemModel>
#include <QDir>

DlgConnHidWifi::DlgConnHidWifi(int type, MainWindow *mainWindow, QWidget *parent) :
isUsed(type),
Expand Down Expand Up @@ -74,12 +75,11 @@ DlgConnHidWifi::DlgConnHidWifi(int type, MainWindow *mainWindow, QWidget *parent
ui->btnConnect->setText(tr("Connect")); //连接

ui->cbxConn->addItem(tr("C_reate…")); //新建...
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-connshow";
QString cmd = "nmcli connection show>" + localPath;
QString tmpPath = "/tmp/kylin-nm-connshow-" + QDir::home().dirName();
QString cmd = "nmcli connection show>" + tmpPath;
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifi' failed");}
QFile file(localPath);
QFile file(tmpPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
}
Expand Down Expand Up @@ -198,13 +198,12 @@ void DlgConnHidWifi::changeWindow(){
ui->cbxSecurity->setEnabled(true);
ui->btnConnect->setEnabled(false);
}else if (ui->cbxConn->currentIndex() >= 1){
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-connshow";
QString tmpPath = "/tmp/kylin-nm-connshow-" + QDir::home().dirName();
QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " >" + tmpPath;

QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " >" + localPath;
int status = system(currStr.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'changeWindow' failed");}
QFile file(localPath);
QFile file(tmpPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
}
Expand Down Expand Up @@ -247,24 +246,24 @@ void DlgConnHidWifi::on_btnConnect_clicked()
//点击连接按钮以连接隐藏WiFi
if (isUsed == 0){
int x = 0;
do{
do {
sleep(1);

QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-btoutput";

QString cmd = "nmcli device wifi connect " + wifiName + " password '' hidden yes > " + localPath;
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_btnConnect_clicked' failed");}

QFile file(localPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug()<<"Can't open the file!"<<endl;
}
QString text = file.readAll();
file.close();
if(text.indexOf("Scanning not allowed") != -1){x = 1;} else { x = 0;}
QString tmpPath = "/tmp/kylin-nm-btoutput-" + QDir::home().dirName();

QString cmd = "nmcli device wifi connect " + wifiName + " password '' hidden yes > " + tmpPath;
int status = system(cmd.toUtf8().data());
if (status != 0)
syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_btnConnect_clicked' failed");

QFile file(tmpPath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "Can't open the file!" << endl;
}
QString text = file.readAll();
file.close();
if(text.indexOf("Scanning not allowed") != -1){x = 1;} else { x = 0;}
} while(x);

connect(this, SIGNAL(execSecConn()), this,SLOT(on_execSecConn() ));
Expand Down
34 changes: 17 additions & 17 deletions wireless-security/dlgconnhidwifiwpa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <unistd.h>
#include <stdlib.h>

#include <QDir>

DlgConnHidWifiWpa::DlgConnHidWifiWpa(int type, MainWindow *mainWindow, QWidget *parent) :
isUsed(type),
QDialog(parent),
Expand Down Expand Up @@ -80,12 +82,12 @@ DlgConnHidWifiWpa::DlgConnHidWifiWpa(int type, MainWindow *mainWindow, QWidget *
ui->btnConnect->setText(tr("Connect")); //连接

ui->cbxConn->addItem(tr("C_reate…")); //新建...
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-connshow";
QString cmd = "nmcli connection show> " + localPath;
QString tmpPath = "/tmp/kylin-nm-connshow-" + QDir::home().dirName();
QString cmd = "nmcli connection show > " + tmpPath;
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifiWpa' failed");}
QFile file(localPath);
if (status != 0)
syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifiWpa' failed");
QFile file(tmpPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
}
Expand Down Expand Up @@ -205,13 +207,12 @@ void DlgConnHidWifiWpa::changeWindow(){
connHidWifi->show();
connect(connHidWifi, SIGNAL(reSetWifiList() ), mw, SLOT(on_btnWifiList_clicked()) );
}else if (ui->cbxConn->currentIndex() >= 1){
QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-connshow";

QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " > " + localPath;
QString tmpPath = "/tmp/kylin-nm-connshow-" + QDir::home().dirName();
QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " > " + tmpPath;
int status = system(currStr.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'changeWindow' failed");}
QFile file(localPath);
if (status != 0)
syslog(LOG_ERR, "execute 'nmcli connection show' in function 'changeWindow' failed");
QFile file(tmpPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"Can't open the file!";
}
Expand Down Expand Up @@ -261,14 +262,13 @@ void DlgConnHidWifiWpa::on_btnConnect_clicked()
do{
sleep(1);

QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
QString localPath = homePath.at(0) + "/.config/kylin-nm-btoutput";

QString cmd = "nmcli device wifi connect " + wifiName + " password " + wifiPassword + " hidden yes > " + localPath;
QString tmpPath = "/tmp/kylin-nm-btoutput-" + QDir::home().dirName();
QString cmd = "nmcli device wifi connect " + wifiName + " password " + wifiPassword + " hidden yes > " + tmpPath;
int status = system(cmd.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_btnConnect_clicked' failed");}
if (status != 0)
syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_btnConnect_clicked' failed");

QFile file(localPath);
QFile file(tmpPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug()<<"Can't open the file!"<<endl;
Expand Down

0 comments on commit 117ecc6

Please sign in to comment.