generate and show qr code
This commit is contained in:
51
ofdscene.cpp
51
ofdscene.cpp
@@ -7,11 +7,13 @@
|
||||
#include <adjustpicturedialog.h>
|
||||
#include <httplib.h>
|
||||
#include <outputdialog.h>
|
||||
#include <qpixmap.h>
|
||||
#include <solvecaptchadialog.h>
|
||||
|
||||
#include <net/net.h>
|
||||
|
||||
#include <exceptions/ofdrequestexception.h>
|
||||
#include <bits/basic_string.h>
|
||||
#include <qrencode.h>
|
||||
|
||||
#include <bits/basic_string.h>
|
||||
|
||||
@@ -46,27 +48,29 @@ void OFDScene::startHttpServer() {
|
||||
}
|
||||
this->port = rand() % (65535 - 1024) + 1024;
|
||||
|
||||
httplib::Server svr;
|
||||
std::string connectionString = "binaryeye://scan/?ret=http://"+ localIp +":"+ std::to_string(port) +"/?result={RESULT}";
|
||||
|
||||
svr.Get("/", [&](const httplib::Request &req, httplib::Response &res){
|
||||
if (req.params.size() < 6) {
|
||||
res.set_redirect("binaryeye://scan/?ret=http://"+ localIp +":"+ std::to_string(port) +"/", 301);
|
||||
server.Get("/", [&](const httplib::Request &req, httplib::Response &res){
|
||||
std::map<std::string, std::string> paramsMap;
|
||||
if (req.params.size() < 1) {
|
||||
res.set_redirect(connectionString, 301);
|
||||
std::cerr << "Too few params: " << req.params.size() << std::endl;
|
||||
return;
|
||||
}
|
||||
std::map<std::string, std::string> paramsMap;
|
||||
for (auto ¶m : req.params) {
|
||||
paramsMap.insert(std::pair<std::string, std::string>(param.first, param.second));
|
||||
std::string result = req.params.find("result")->second;
|
||||
std::vector<std::string> dataSplit = split(result, "&");
|
||||
for (std::string &pair : dataSplit) {
|
||||
std::vector<std::string> values = split(pair, "=");
|
||||
paramsMap.insert(std::pair<std::string, std::string>(values[0], values[1]));
|
||||
}
|
||||
|
||||
emit onDataDecode(paramsMap);
|
||||
|
||||
res.set_redirect("binaryeye://scan/?ret=http://"+ localIp +":"+ std::to_string(port) +"/", 301);
|
||||
res.set_redirect(connectionString, 301);
|
||||
});
|
||||
|
||||
number_of_retries ++;
|
||||
std::cerr << "Listening on port: " << this->port << std::endl;
|
||||
if (!svr.listen("0.0.0.0", this->port)) {
|
||||
if (!server.listen("0.0.0.0", this->port)) {
|
||||
std::cerr << "Random port seems to be occupied. Trying to generate another one" << std::endl;
|
||||
number_of_retries ++;
|
||||
continue;
|
||||
@@ -94,9 +98,6 @@ void OFDScene::on_choose_image_button_clicked() {
|
||||
}
|
||||
|
||||
void OFDScene::onDataDecode(std::map<std::string, std::string> data) {
|
||||
// std::vector<std::string> dataSplit = split(data, "&");
|
||||
|
||||
|
||||
ui->fn_line_edit->setText(QString::fromStdString(data["fn"]));
|
||||
ui->fd_line_edit->setText(QString::fromStdString(data["i"]));
|
||||
ui->fi_line_edit->setText(QString::fromStdString(data["fp"]));
|
||||
@@ -117,7 +118,6 @@ void OFDScene::onDataDecode(std::map<std::string, std::string> data) {
|
||||
ui->total_spin_box->setValue(std::stod(total));
|
||||
}
|
||||
|
||||
|
||||
void OFDScene::on_parse_button_clicked() {
|
||||
Net net;
|
||||
net.get_captcha_from_ofdru();
|
||||
@@ -178,9 +178,28 @@ void OFDScene::on_parse_button_clicked() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OFDScene::on_binary_eye_button_clicked() {
|
||||
http_thread = new std::thread(&OFDScene::startHttpServer, this);
|
||||
ui->binary_eye_button->setEnabled(false);
|
||||
|
||||
while (!server.is_running());
|
||||
std::string localIp;
|
||||
try {
|
||||
localIp = get_local_ip_address();
|
||||
} catch(std::exception e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
return;
|
||||
}
|
||||
std::string connectionString = "binaryeye://scan?ret=http://" + localIp + ":" + std::to_string(port) + "/?result={RESULT}";
|
||||
|
||||
generate_qr_code(connectionString);
|
||||
|
||||
QMessageBox infoDialog = QMessageBox();
|
||||
infoDialog.setText(QString::fromStdString(connectionString));
|
||||
infoDialog.setIconPixmap(QPixmap(QString::fromStdString(get_path_relative_to_home(".local/share/checks_parser/binaryeye_connection.png"))).scaled(400, 400, Qt::KeepAspectRatio));
|
||||
infoDialog.setWindowTitle(tr("QR code for binaryeye to connect"));
|
||||
infoDialog.setButtonText(1, tr("I've scanned"));
|
||||
infoDialog.exec();
|
||||
}
|
||||
|
||||
void OFDScene::notifyHttpServerFailure() {
|
||||
|
||||
Reference in New Issue
Block a user