Added CURLgui test utility

parent 55bf0570
#-------------------------------------------------
#
# Project created by QtCreator 2016-03-15T14:53:07
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = CURLgui
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QSplitter>
#include <stdio.h>
#include <stdlib.h>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->comboBox->addItem(tr("GET"));
ui->comboBox->addItem(tr("PUT"));
ui->comboBox->addItem(tr("POST"));
ui->comboBox->addItem(tr("DELETE"));
ui->certLineEdit->setText(tr("/home/pspirek/sslclient/pavel_curl.pem"));
ui->urlPlainTextEdit->setPlainText("https://127.0.0.1:8443/restconf/data/dns-server:dns-server/zones/zone=example.com");
ui->splitter->setStretchFactor(0,0);
ui->splitter->setStretchFactor(1,1);
hist_filename = tr("history.txt");
QFile hist_file(hist_filename);
if(hist_file.open(QIODevice::ReadOnly)) {
QByteArray l;
bool eof = false;
do {
l = hist_file.readLine();
if(l.isEmpty()) {
eof = true;
}
else {
ui->urlListWidget->addItem(QString(l.left(l.length() - 1)));
}
} while(!eof);
}
QFile post_file(tr("post.txt"));
if(post_file.open(QIODevice::ReadOnly)) {
QByteArray l;
l = post_file.readAll();
if(!l.isEmpty()) {
ui->postDataPlainTextEdit->setPlainText(QString(l));
}
}
updateGui();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::loadTextFile()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open client certificate"), "/home/pspirek/sslclient", tr("Cert files (*.pem)"));
this->ui->certLineEdit->setText(fileName);
}
void MainWindow::on_pushButton_clicked()
{
FILE *fp;
int bytes_read;
char *buf;
fp = popen(cmd.toStdString().c_str(), "r");
buf = (char*)malloc(16384);
bytes_read = fread(buf, 1, 16383, fp);
buf[bytes_read] = '\0';
QString str = QString(buf);
ui->outputPlainTextEdit->setPlainText(str);
free(buf);
pclose(fp);
QString url = ui->urlPlainTextEdit->toPlainText();
if(ui->urlListWidget->findItems(url, Qt::MatchExactly).isEmpty()) {
ui->urlListWidget->addItem(url);
QFile hist_file(hist_filename);
if(hist_file.open(QIODevice::Append)) {
hist_file.write(url.toUtf8());
hist_file.write("\n");
}
}
}
void MainWindow::on_pushButton_2_clicked()
{
this->loadTextFile();
}
void MainWindow::updateGui()
{
cmd = "curl ";
if(ui->checkBox->isChecked()) {
cmd += "-v ";
}
cmd += "--http2 -k --cert-type PEM -E ";
cmd += ui->certLineEdit->text() + " ";
cmd += "-X " + ui->comboBox->currentText() + " ";
if(ui->postDataPlainTextEdit->toPlainText().length() > 0) {
cmd += "-d '" + ui->postDataPlainTextEdit->toPlainText() + "' ";
}
cmd += ui->urlPlainTextEdit->toPlainText();
if(ui->checkBox->isChecked()) {
cmd += " 2>&1";
}
else {
cmd += " 2>/dev/null";
}
ui->cmdPlainTextEdit->setPlainText(cmd);
}
void MainWindow::on_postDataPlainTextEdit_textChanged()
{
updateGui();
}
void MainWindow::on_comboBox_currentIndexChanged(const QString &arg1)
{
Q_UNUSED(arg1)
updateGui();
}
void MainWindow::on_urlPlainTextEdit_textChanged()
{
updateGui();
}
void MainWindow::on_certLineEdit_textChanged(const QString &arg1)
{
Q_UNUSED(arg1)
updateGui();
}
void MainWindow::on_checkBox_toggled(bool checked)
{
Q_UNUSED(checked)
updateGui();
}
void MainWindow::on_urlListWidget_itemClicked(QListWidgetItem *item)
{
ui->urlPlainTextEdit->setPlainText(item->text());
updateGui();
}
void MainWindow::on_urlListWidget_itemDoubleClicked(QListWidgetItem *item)
{
on_urlListWidget_itemClicked(item);
on_pushButton_clicked();
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QListWidgetItem>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void on_pushButton_2_clicked();
void on_postDataPlainTextEdit_textChanged();
void on_comboBox_currentIndexChanged(const QString &arg1);
void on_urlPlainTextEdit_textChanged();
void on_certLineEdit_textChanged(const QString &arg1);
void on_checkBox_toggled(bool checked);
void on_urlListWidget_itemClicked(QListWidgetItem *item);
void on_urlListWidget_itemDoubleClicked(QListWidgetItem *item);
private:
QString cmd;
QString hist_filename;
Ui::MainWindow *ui;
void loadTextFile();
void updateGui();
};
#endif // MAINWINDOW_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1024</width>
<height>640</height>
</rect>
</property>
<property name="windowTitle">
<string>CURL gui</string>
</property>
<widget class="QWidget" name="centralWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="opaqueResize">
<bool>true</bool>
</property>
<property name="handleWidth">
<number>4</number>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="QWidget" name="verticalLayoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0,0,0,0,0,0,0,0,0,0">
<property name="spacing">
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Client certificate:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="certLineEdit"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Open</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Method:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox"/>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>URL:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="urlPlainTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>64</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="urlListWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>3</verstretch>
</sizepolicy>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>POST data:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="postDataPlainTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Command:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="cmdPlainTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>450</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>64</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>205</red>
<green>205</green>
<blue>205</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>205</red>
<green>205</green>
<blue>205</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>252</red>
<green>252</green>
<blue>252</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="backgroundVisible">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="pushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Run CURL</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Verbose</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="verticalLayoutWidget_2">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>CURL output:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="outputPlainTextEdit">
<property name="font">
<font>
<family>Monospace</family>
<pointsize>9</pointsize>
</font>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment