Prevent manual chaging in modified inbounds.

This commit is contained in:
Hork 2019-05-10 22:51:17 +08:00
parent 7abbea4f57
commit 4b5b384a37
3 changed files with 25 additions and 0 deletions

View File

@ -53,6 +53,15 @@ void hvConf::on_buttonBox_accepted()
if(ui->httpPortLE->text().toInt() != ui->socksPortLE->text().toInt()) { if(ui->httpPortLE->text().toInt() != ui->socksPortLE->text().toInt()) {
QJsonArray inbounds; QJsonArray inbounds;
QJsonDocument modifiedDoc; QJsonDocument modifiedDoc;
inbounds = rootObj.value("inbounds").toArray();
int socksId = getIndexInArrayByValue(inbounds, "tag", "socks-in");
if(socksId != -1) {
inbounds.removeAt(socksId);
}
int httpId = getIndexInArrayByValue(inbounds, "tag", "http-in");
if(httpId != -1) {
inbounds.removeAt(httpId);
}
rootObj.remove("inbounds"); rootObj.remove("inbounds");
rootObj.remove("v2suidEnabled"); rootObj.remove("v2suidEnabled");
if(ui->socksCB->isChecked()) { if(ui->socksCB->isChecked()) {
@ -114,6 +123,7 @@ void hvConf::on_httpCB_stateChanged(int arg1)
ui->httpPortLE->setDisabled(true); ui->httpPortLE->setDisabled(true);
} else { } else {
ui->httpPortLE->setEnabled(true); ui->httpPortLE->setEnabled(true);
ui->httpPortLE->setText("6666");
} }
} }
@ -123,5 +133,6 @@ void hvConf::on_socksCB_stateChanged(int arg1)
ui->socksPortLE->setDisabled(true); ui->socksPortLE->setDisabled(true);
} else { } else {
ui->socksPortLE->setEnabled(true); ui->socksPortLE->setEnabled(true);
ui->socksPortLE->setText("1080");
} }
} }

View File

@ -83,3 +83,16 @@ void overrideInbounds(QString path)
confFile.write(conf); confFile.write(conf);
confFile.close(); confFile.close();
} }
int getIndexInArrayByValue(QJsonArray array, QString key, QString val)
{
QJsonArray::iterator it;
int index = 0;
for(it = array.begin(); it != array.end(); it ++) {
if(it->toObject().value(key) == val) {
return index;
}
index ++;
}
return -1;
}

View File

@ -9,5 +9,6 @@ QJsonArray getInbounds();
bool testCoreFiles(); bool testCoreFiles();
void alterMessage(QString title, QString text); void alterMessage(QString title, QString text);
void overrideInbounds(QString path); void overrideInbounds(QString path);
int getIndexInArrayByValue(QJsonArray array, QString key, QString val);
#endif // UTILS_H #endif // UTILS_H