mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-21 11:20:49 +08:00
parent
20ca9cef23
commit
fa08f03fec
11
Hv2ray.pro
11
Hv2ray.pro
@ -31,29 +31,26 @@ SOURCES += \
|
||||
main.cpp \
|
||||
MainWindow.cpp \
|
||||
ConnectionEditWindow.cpp \
|
||||
importconf.cpp \
|
||||
ImportConfig.cpp \
|
||||
PrefrencesWindow.cpp \
|
||||
vinteract.cpp \
|
||||
import_vmess.cpp \
|
||||
utils.cpp \
|
||||
runguard.cpp
|
||||
|
||||
HEADERS += \
|
||||
MainWindow.h \
|
||||
ConnectionEditWindow.h \
|
||||
importconf.h \
|
||||
ImportConfig.h \
|
||||
PrefrencesWindow.h \
|
||||
vinteract.h \
|
||||
import_vmess.h \
|
||||
utils.h \
|
||||
runguard.h
|
||||
|
||||
FORMS += \
|
||||
MainWindow.ui \
|
||||
ConnectionEditWindow.ui \
|
||||
importconf.ui \
|
||||
PrefrencesWindow.ui \
|
||||
import_vmess.ui
|
||||
ImportConfig.ui \
|
||||
PrefrencesWindow.ui
|
||||
|
||||
TRANSLATIONS += ./translations/zh-CN.ts
|
||||
|
||||
|
128
src/ImportConfig.cpp
Normal file
128
src/ImportConfig.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
#include <QFileDialog>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
#pragma push_macro("slots")
|
||||
#undef slots
|
||||
#include "Python.h"
|
||||
#pragma pop_macro("slots")
|
||||
|
||||
#include "ConnectionEditWindow.h"
|
||||
#include "vinteract.h"
|
||||
#include "utils.h"
|
||||
#include "ImportConfig.h"
|
||||
#include "ui_ImportConfig.h"
|
||||
|
||||
ImportConfig::ImportConfig(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ImportConfig)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(this, SIGNAL(updateConfTable()), parentWidget(), SLOT(updateConfTable()));
|
||||
}
|
||||
|
||||
ImportConfig::~ImportConfig()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ImportConfig::on_pushButton_clicked()
|
||||
{
|
||||
QString dir = QFileDialog::getOpenFileName(this, tr("Open Config File"), "~/");
|
||||
ui->fileLineTxt->setText(dir);
|
||||
}
|
||||
|
||||
void ImportConfig::savefromFile(QString path, QString alias)
|
||||
{
|
||||
vConfig newConf;
|
||||
newConf.alias = alias;
|
||||
QFile configFile(path);
|
||||
if(!configFile.open(QIODevice::ReadOnly)) {
|
||||
qDebug() << "Couldn't open config json";
|
||||
return;
|
||||
}
|
||||
QByteArray allData = configFile.readAll();
|
||||
configFile.close();
|
||||
QJsonDocument v2conf(QJsonDocument::fromJson(allData));
|
||||
QJsonObject rootobj = v2conf.object();
|
||||
QJsonObject outbound;
|
||||
if(rootobj.contains("outbounds")) {
|
||||
outbound = rootobj.value("outbounds").toArray().first().toObject();
|
||||
} else {
|
||||
outbound = rootobj.value("outbound").toObject();
|
||||
}
|
||||
QJsonObject vnext = switchJsonArrayObject(outbound.value("settings").toObject(), "vnext");
|
||||
QJsonObject user = switchJsonArrayObject(vnext, "users");
|
||||
newConf.host = vnext.value("address").toString();
|
||||
newConf.port = QString::number(vnext.value("port").toInt());
|
||||
newConf.alterid = QString::number(user.value("alterId").toInt());
|
||||
newConf.uuid = user.value("id").toString();
|
||||
newConf.security = user.value("security").toString();
|
||||
if (newConf.security.isNull()) {
|
||||
newConf.security = "auto";
|
||||
}
|
||||
newConf.isCustom = 1;
|
||||
int id = newConf.save();
|
||||
if(id < 0)
|
||||
{
|
||||
showWarnMessageBox(this, "Database Error", "Failed to open database while saving");
|
||||
return;
|
||||
}
|
||||
emit updateConfTable();
|
||||
QString newFile = "conf/" + QString::number(id) + ".conf";
|
||||
if(!QFile::copy(path, newFile)) {
|
||||
showWarnMessageBox(this, "Copy error", "Failed to copy custom config file.");
|
||||
}
|
||||
}
|
||||
|
||||
void ImportConfig::on_buttonBox_accepted()
|
||||
{
|
||||
QString alias = ui->nameTxt->text();
|
||||
if(ui->importSourceCombo->currentIndex() == 0) // From File...
|
||||
{
|
||||
QString path = ui->fileLineTxt->text();
|
||||
bool isValid = validationCheck(path);
|
||||
if(isValid) {
|
||||
savefromFile(path, alias);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QString vmess = ui->vmessConnectionStringTxt->toPlainText();
|
||||
Py_Initialize();
|
||||
if ( !Py_IsInitialized() ) {
|
||||
qDebug() << "Python is not initialized";
|
||||
}
|
||||
QString param = "--inbound socks:1080 " + vmess + " -o config.json.tmp";
|
||||
PyRun_SimpleString("import sys");
|
||||
PyRun_SimpleString("sys.path.append('./utils')");
|
||||
PyObject *pModule = PyImport_ImportModule("vmess2json");
|
||||
PyObject *pFunc = PyObject_GetAttrString(pModule, "main");
|
||||
PyObject *arg = PyTuple_New(1);
|
||||
PyObject *arg1 = Py_BuildValue("s", param.toStdString().c_str());
|
||||
PyTuple_SetItem(arg, 0, arg1);
|
||||
PyObject_CallObject(pFunc, arg);
|
||||
Py_Finalize();
|
||||
if(QFile::exists(QCoreApplication::applicationDirPath() + "/config.json.tmp")) {
|
||||
ImportConfig *im = new ImportConfig(this->parentWidget());
|
||||
if (validationCheck(QCoreApplication::applicationDirPath() + "/config.json.tmp")) {
|
||||
im->savefromFile("config.json.tmp", alias);
|
||||
}
|
||||
QFile::remove("config.json.tmp");
|
||||
} else {
|
||||
showWarnMessageBox(this, "Error occured", "Failed to generate config file.");
|
||||
}
|
||||
}
|
||||
|
||||
if(ui->useCurrentSettingRidBtn->isChecked())
|
||||
{
|
||||
// TODO: Use Current Settings...
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Override Inbound....
|
||||
}
|
||||
}
|
@ -5,17 +5,17 @@
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class importConf;
|
||||
class ImportConfig;
|
||||
}
|
||||
|
||||
class importConf : public QDialog
|
||||
class ImportConfig : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit importConf(QWidget *parent = nullptr);
|
||||
explicit ImportConfig(QWidget *parent = nullptr);
|
||||
void savefromFile(QString path, QString alias);
|
||||
~importConf();
|
||||
~ImportConfig();
|
||||
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
@ -24,7 +24,7 @@ signals:
|
||||
void updateConfTable();
|
||||
|
||||
private:
|
||||
Ui::importConf *ui;
|
||||
Ui::ImportConfig *ui;
|
||||
};
|
||||
|
||||
#endif // IMPORTCONF_H
|
186
src/ImportConfig.ui
Normal file
186
src/ImportConfig.ui
Normal file
@ -0,0 +1,186 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ImportConfig</class>
|
||||
<widget class="QDialog" name="ImportConfig">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>650</width>
|
||||
<height>350</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>650</width>
|
||||
<height>350</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Import file</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,6">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Import From</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="importSourceCombo">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Existing File</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>VMess Connection String</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QGroupBox" name="fromFileGroupBox">
|
||||
<property name="title">
|
||||
<string>From File</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="fileLabel">
|
||||
<property name="text">
|
||||
<string>Path</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="fileLineTxt">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="selectFileBtn">
|
||||
<property name="text">
|
||||
<string>Select File</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="aliasLabel">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="nameTxt"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Inbound</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="useCurrentSettingRidBtn">
|
||||
<property name="text">
|
||||
<string>Use Current</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="useImportedRidBtn">
|
||||
<property name="text">
|
||||
<string>Use Imported</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QGroupBox" name="fromVMessGroupBox">
|
||||
<property name="title">
|
||||
<string>From VMess Connection String</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>VMess Connection String</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="vmessConnectionStringTxt"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ImportConfig</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ImportConfig</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -8,12 +8,11 @@
|
||||
#include <QFileInfo>
|
||||
#include <QInputDialog>
|
||||
|
||||
#include "import_vmess.h"
|
||||
#include "PrefrencesWindow.h"
|
||||
#include "MainWindow.h"
|
||||
#include <ui_MainWindow.h>
|
||||
#include "ConnectionEditWindow.h"
|
||||
#include "importconf.h"
|
||||
#include "ImportConfig.h"
|
||||
#include "vinteract.h"
|
||||
#include "utils.h"
|
||||
|
||||
@ -23,17 +22,17 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
{
|
||||
this->setWindowIcon(QIcon("Himeki.ico"));
|
||||
ui->setupUi(this);
|
||||
updateConfTable();
|
||||
UpdateConfigTable();
|
||||
// ui->configTable->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
// connect(ui->configTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint)));
|
||||
this->v2Inst = new v2Instance();
|
||||
this->v2instance = new v2Instance();
|
||||
hTray = new QSystemTrayIcon();
|
||||
hTray->setToolTip("Hv2ray");
|
||||
hTray->setIcon(QIcon("Himeki.ico"));
|
||||
connect(hTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(on_activatedTray(QSystemTrayIcon::ActivationReason)));
|
||||
createTrayAction();
|
||||
if(QFileInfo("config.json").exists()) {
|
||||
v2Inst->start(this);
|
||||
v2instance->start(this);
|
||||
}
|
||||
|
||||
// QAction *select = new QAction("Select", ui->configTable);
|
||||
@ -52,7 +51,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
delete this->v2Inst;
|
||||
delete this->v2instance;
|
||||
}
|
||||
|
||||
void MainWindow::on_actionEdit_triggered()
|
||||
@ -64,10 +63,11 @@ void MainWindow::on_actionEdit_triggered()
|
||||
|
||||
void MainWindow::on_actionExisting_config_triggered()
|
||||
{
|
||||
importConf *f = new importConf(this);
|
||||
ImportConfig *f = new ImportConfig(this);
|
||||
f->setAttribute(Qt::WA_DeleteOnClose);
|
||||
f->show();
|
||||
}
|
||||
|
||||
void MainWindow::showMenu(QPoint pos)
|
||||
{
|
||||
// if(ui->configTable->indexAt(pos).column() != -1) {
|
||||
@ -85,18 +85,18 @@ void MainWindow::select_triggered()
|
||||
// }
|
||||
}
|
||||
|
||||
void MainWindow::delConf()
|
||||
void MainWindow::DeleteConfig()
|
||||
{
|
||||
|
||||
}
|
||||
void MainWindow::updateConfTable()
|
||||
void MainWindow::UpdateConfigTable()
|
||||
{
|
||||
|
||||
}
|
||||
void MainWindow::generateConfig(int idIntable)
|
||||
void MainWindow::GenerateConfig(int idIntable)
|
||||
{
|
||||
vConfig tmpConf;
|
||||
emit updateConfTable();
|
||||
emit UpdateConfigTable();
|
||||
if (tmpConf.isCustom == 1) {
|
||||
QString src = "conf/" + QString::number(idIntable) + ".conf";
|
||||
overrideInbounds(src);
|
||||
@ -108,15 +108,15 @@ void MainWindow::generateConfig(int idIntable)
|
||||
// TODO: Config generator
|
||||
}
|
||||
}
|
||||
void MainWindow::updateLog()
|
||||
void MainWindow::UpdateLog()
|
||||
{
|
||||
ui->logText->insertPlainText(this->v2Inst->v2Process->readAllStandardOutput());
|
||||
ui->logText->insertPlainText(this->v2instance->vProcess->readAllStandardOutput());
|
||||
}
|
||||
|
||||
void MainWindow::on_startButton_clicked()
|
||||
{
|
||||
ui->logText->clear();
|
||||
bool startFlag = this->v2Inst->start(this);
|
||||
bool startFlag = this->v2instance->start(this);
|
||||
trayMenu->actions()[2]->setEnabled(!startFlag);
|
||||
trayMenu->actions()[3]->setEnabled(startFlag);
|
||||
trayMenu->actions()[4]->setEnabled(startFlag);
|
||||
@ -124,7 +124,7 @@ void MainWindow::on_startButton_clicked()
|
||||
|
||||
void MainWindow::on_stopButton_clicked()
|
||||
{
|
||||
this->v2Inst->stop();
|
||||
this->v2instance->stop();
|
||||
ui->logText->clear();
|
||||
trayMenu->actions()[2]->setEnabled(true);
|
||||
trayMenu->actions()[3]->setEnabled(false);
|
||||
@ -144,13 +144,7 @@ void MainWindow::on_clbutton_clicked()
|
||||
|
||||
void MainWindow::on_rtButton_clicked()
|
||||
{
|
||||
emit updateConfTable();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionVmess_triggered()
|
||||
{
|
||||
import_vmess *inVmess = new import_vmess(this);
|
||||
inVmess->show();
|
||||
emit UpdateConfigTable();
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
@ -205,7 +199,7 @@ void MainWindow::on_activatedTray(QSystemTrayIcon::ActivationReason reason)
|
||||
case QSystemTrayIcon::MiddleClick:
|
||||
// TODO: Check if an alert message box is present.
|
||||
// If so, do nothing but please wait for the message box to be closed.
|
||||
if(this->v2Inst->v2Process->state() == QProcess::ProcessState::Running) {
|
||||
if(this->v2instance->vProcess->state() == QProcess::ProcessState::Running) {
|
||||
on_stopButton_clicked();
|
||||
} else {
|
||||
on_startButton_clicked();
|
||||
|
@ -8,7 +8,8 @@
|
||||
#include <QMenu>
|
||||
#include <QScrollBar>
|
||||
|
||||
class v2Instance;
|
||||
#include "vinteract.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindow;
|
||||
@ -20,7 +21,7 @@ class MainWindow : public QMainWindow
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
v2Instance *v2Inst;
|
||||
v2Instance *v2instance;
|
||||
QSystemTrayIcon *hTray;
|
||||
QMenu *trayMenu = new QMenu(this);
|
||||
QMenu *popMenu = new QMenu(this);
|
||||
@ -31,17 +32,16 @@ private slots:
|
||||
void on_restartButton_clicked();
|
||||
void on_actionEdit_triggered();
|
||||
void on_actionExisting_config_triggered();
|
||||
void updateConfTable();
|
||||
void delConf();
|
||||
void UpdateConfigTable();
|
||||
void DeleteConfig();
|
||||
void showMenu(QPoint pos);
|
||||
void updateLog();
|
||||
void UpdateLog();
|
||||
void on_startButton_clicked();
|
||||
void on_stopButton_clicked();
|
||||
void select_triggered();
|
||||
void on_clbutton_clicked();
|
||||
void on_rtButton_clicked();
|
||||
void generateConfig(int idIntable);
|
||||
void on_actionVmess_triggered();
|
||||
void GenerateConfig(int idIntable);
|
||||
void on_activatedTray(QSystemTrayIcon::ActivationReason reason);
|
||||
void toggleMainWindowVisibility();
|
||||
void quit();
|
||||
|
@ -255,17 +255,10 @@
|
||||
</property>
|
||||
<widget class="QMenu" name="menuNew">
|
||||
<property name="title">
|
||||
<string>New</string>
|
||||
<string>New Connection</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFrom">
|
||||
<property name="title">
|
||||
<string>From</string>
|
||||
</property>
|
||||
<addaction name="actionVmess"/>
|
||||
<addaction name="actionExisting_config"/>
|
||||
</widget>
|
||||
<addaction name="actionExisting_config"/>
|
||||
<addaction name="actionEdit"/>
|
||||
<addaction name="menuFrom"/>
|
||||
</widget>
|
||||
<addaction name="menuNew"/>
|
||||
<addaction name="actionPreferences"/>
|
||||
@ -283,17 +276,12 @@
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<action name="actionEdit">
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionVmess">
|
||||
<property name="text">
|
||||
<string>Vmess</string>
|
||||
<string>Manual</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExisting_config">
|
||||
<property name="text">
|
||||
<string>Existing config</string>
|
||||
<string>Import</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExit">
|
||||
|
@ -1,53 +0,0 @@
|
||||
#include "import_vmess.h"
|
||||
#pragma push_macro("slots")
|
||||
#undef slots
|
||||
#include "Python.h"
|
||||
#pragma pop_macro("slots")
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
||||
#include "vinteract.h"
|
||||
#include "utils.h"
|
||||
#include "importconf.h"
|
||||
#include "ui_import_vmess.h"
|
||||
|
||||
import_vmess::import_vmess(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::import_vmess)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
import_vmess::~import_vmess()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void import_vmess::on_buttonBox_accepted()
|
||||
{
|
||||
QString vmess = ui->vmessTextEdit->toPlainText();
|
||||
QString alias = ui->aliasLineEdit->text();
|
||||
Py_Initialize();
|
||||
if ( !Py_IsInitialized() ) {
|
||||
qDebug() << "Python is not initialized";
|
||||
}
|
||||
QString param = "--inbound socks:1080 " + vmess + " -o config.json.tmp";
|
||||
PyRun_SimpleString("import sys");
|
||||
PyRun_SimpleString("sys.path.append('./utils')");
|
||||
PyObject *pModule = PyImport_ImportModule("vmess2json");
|
||||
PyObject *pFunc = PyObject_GetAttrString(pModule, "main");
|
||||
PyObject *arg = PyTuple_New(1);
|
||||
PyObject *arg1 = Py_BuildValue("s", param.toStdString().c_str());
|
||||
PyTuple_SetItem(arg, 0, arg1);
|
||||
PyObject_CallObject(pFunc, arg);
|
||||
Py_Finalize();
|
||||
if(QFile::exists(QCoreApplication::applicationDirPath() + "/config.json.tmp")) {
|
||||
importConf *im = new importConf(this->parentWidget());
|
||||
if (validationCheck(QCoreApplication::applicationDirPath() + "/config.json.tmp")) {
|
||||
im->savefromFile("config.json.tmp", alias);
|
||||
}
|
||||
QFile::remove("config.json.tmp");
|
||||
} else {
|
||||
showWarnMessageBox(this, "Error occured", "Failed to generate config file.");
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
#ifndef VMESS_H
|
||||
#define VMESS_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class import_vmess;
|
||||
}
|
||||
|
||||
class import_vmess : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit import_vmess(QWidget *parent = nullptr);
|
||||
~import_vmess();
|
||||
|
||||
private slots:
|
||||
void on_buttonBox_accepted();
|
||||
|
||||
private:
|
||||
Ui::import_vmess *ui;
|
||||
};
|
||||
|
||||
#endif // VMESS_H
|
@ -1,100 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>import_vmess</class>
|
||||
<widget class="QDialog" name="import_vmess">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>733</width>
|
||||
<height>446</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Vmess</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>350</x>
|
||||
<y>380</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="vmessTextEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>681</width>
|
||||
<height>321</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>370</y>
|
||||
<width>241</width>
|
||||
<height>51</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Alias:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="aliasLineEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>import_vmess</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>import_vmess</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -1,84 +0,0 @@
|
||||
#include <QFileDialog>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include "ConnectionEditWindow.h"
|
||||
#include "vinteract.h"
|
||||
#include "utils.h"
|
||||
#include "importconf.h"
|
||||
#include "ui_importconf.h"
|
||||
|
||||
importConf::importConf(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::importConf)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(this, SIGNAL(updateConfTable()), parentWidget(), SLOT(updateConfTable()));
|
||||
}
|
||||
|
||||
importConf::~importConf()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void importConf::on_pushButton_clicked()
|
||||
{
|
||||
QString dir = QFileDialog::getOpenFileName(this, tr("Open Config File"), "~/");
|
||||
ui->fileLinedit->setText(dir);
|
||||
}
|
||||
|
||||
void importConf::savefromFile(QString path, QString alias)
|
||||
{
|
||||
vConfig newConf;
|
||||
newConf.alias = alias;
|
||||
QFile configFile(path);
|
||||
if(!configFile.open(QIODevice::ReadOnly)) {
|
||||
qDebug() << "Couldn't open config json";
|
||||
return;
|
||||
}
|
||||
QByteArray allData = configFile.readAll();
|
||||
configFile.close();
|
||||
QJsonDocument v2conf(QJsonDocument::fromJson(allData));
|
||||
QJsonObject rootobj = v2conf.object();
|
||||
QJsonObject outbound;
|
||||
if(rootobj.contains("outbounds")) {
|
||||
outbound = rootobj.value("outbounds").toArray().first().toObject();
|
||||
} else {
|
||||
outbound = rootobj.value("outbound").toObject();
|
||||
}
|
||||
QJsonObject vnext = switchJsonArrayObject(outbound.value("settings").toObject(), "vnext");
|
||||
QJsonObject user = switchJsonArrayObject(vnext, "users");
|
||||
newConf.host = vnext.value("address").toString();
|
||||
newConf.port = QString::number(vnext.value("port").toInt());
|
||||
newConf.alterid = QString::number(user.value("alterId").toInt());
|
||||
newConf.uuid = user.value("id").toString();
|
||||
newConf.security = user.value("security").toString();
|
||||
if (newConf.security.isNull()) {
|
||||
newConf.security = "auto";
|
||||
}
|
||||
newConf.isCustom = 1;
|
||||
int id = newConf.save();
|
||||
if(id < 0)
|
||||
{
|
||||
showWarnMessageBox(this, "Database Error", "Failed to open database while saving");
|
||||
return;
|
||||
}
|
||||
emit updateConfTable();
|
||||
QString newFile = "conf/" + QString::number(id) + ".conf";
|
||||
if(!QFile::copy(path, newFile)) {
|
||||
showWarnMessageBox(this, "Copy error", "Failed to copy custom config file.");
|
||||
}
|
||||
}
|
||||
|
||||
void importConf::on_buttonBox_accepted()
|
||||
{
|
||||
QString path = ui->fileLinedit->text();
|
||||
QString alias = ui-> aliasLinedit->text();
|
||||
bool isValid = validationCheck(path);
|
||||
if(isValid) {
|
||||
savefromFile(path, alias);
|
||||
}
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>importConf</class>
|
||||
<widget class="QDialog" name="importConf">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Import file</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>190</x>
|
||||
<y>240</y>
|
||||
<width>181</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>90</y>
|
||||
<width>318</width>
|
||||
<height>68</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="fileLabel">
|
||||
<property name="text">
|
||||
<string>File name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="fileLinedit">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>open</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="aliasLabel">
|
||||
<property name="text">
|
||||
<string>Alias:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="aliasLinedit"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>importConf</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>importConf</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -35,7 +35,7 @@ bool validationCheck(QString path)
|
||||
|
||||
v2Instance::v2Instance()
|
||||
{
|
||||
this->v2Process = new QProcess();
|
||||
this->vProcess = new QProcess();
|
||||
}
|
||||
|
||||
v2Instance::~v2Instance()
|
||||
@ -43,18 +43,18 @@ v2Instance::~v2Instance()
|
||||
this->stop();
|
||||
}
|
||||
|
||||
bool v2Instance::start(MainWindow *parent)
|
||||
bool v2Instance::start(QWidget *parent)
|
||||
{
|
||||
if(this->v2Process->state() == QProcess::Running) {
|
||||
if(this->vProcess->state() == QProcess::Running) {
|
||||
this->stop();
|
||||
}
|
||||
if (checkVCoreExes()) {
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
env.insert("V2RAY_LOCATION_ASSET", QDir::currentPath());
|
||||
this->v2Process->setProcessEnvironment(env);
|
||||
this->v2Process->start("./v2ray", QStringList() << "-config" << "config.json", QIODevice::ReadWrite | QIODevice::Text);
|
||||
this->v2Process->waitForStarted();
|
||||
QObject::connect(v2Process, SIGNAL(readyReadStandardOutput()), parent, SLOT(updateLog()));
|
||||
this->vProcess->setProcessEnvironment(env);
|
||||
this->vProcess->start("./v2ray", QStringList() << "-config" << "config.json", QIODevice::ReadWrite | QIODevice::Text);
|
||||
this->vProcess->waitForStarted();
|
||||
QObject::connect(vProcess, SIGNAL(readyReadStandardOutput()), parent, SLOT(updateLog()));
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
@ -62,5 +62,5 @@ bool v2Instance::start(MainWindow *parent)
|
||||
|
||||
void v2Instance::stop()
|
||||
{
|
||||
this->v2Process->close();
|
||||
this->vProcess->close();
|
||||
}
|
||||
|
@ -2,21 +2,18 @@
|
||||
#define VINTERACT_H
|
||||
#include <QString>
|
||||
#include <QProcess>
|
||||
#include "MainWindow.h"
|
||||
|
||||
bool validationCheck(QString path);
|
||||
|
||||
class v2Instance
|
||||
{
|
||||
public:
|
||||
explicit v2Instance();
|
||||
bool start(MainWindow *parent);
|
||||
bool start(QWidget *parent);
|
||||
void stop();
|
||||
void restart();
|
||||
QProcess *v2Process;
|
||||
QProcess *vProcess;
|
||||
~v2Instance();
|
||||
private:
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // VINTERACT_H
|
||||
|
Loading…
Reference in New Issue
Block a user