Skip to content

Commit 7ec9f40

Browse files
committed
Plugins: Add ftp server
1 parent 422c958 commit 7ec9f40

67 files changed

Lines changed: 1567 additions & 246 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Authors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ See: https://github.com/KangLin/RabbitRemoteControl/graphs/contributors
4444
- [OPTIONAL] FFMPEG: [https://ffmpeg.org/](https://ffmpeg.org/) Multimedia capabilities required
4545
- [OPTIONAL] qtkeychain: [https://github.com/KangLin/qtkeychain](https://github.com/KangLin/qtkeychain)
4646
- [OPTIONAL] libcurl: [https://curl.se](https://curl.se)
47+
- [OPTIONAL] QFtpServer: https://github.com/sashoalm/QFtpServer

Authors_zh_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@
4646
- [可选] FFMPEG: [https://ffmpeg.org/](https://ffmpeg.org/) 多媒体功能需要
4747
- [可选] qtkeychain: [https://github.com/KangLin/qtkeychain](https://github.com/KangLin/qtkeychain)
4848
- [可选] libcurl: [https://curl.se](https://curl.se)
49+
- [可选] QFtpServer: https://github.com/sashoalm/QFtpServer

Plugins/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ if(WITH_QTERMWIDGET)
9696
endif()
9797
endif()
9898

99+
## Server
100+
option(BUILD_FTP_SERVER "Build ftp server" ON)
101+
if(BUILD_FTP_SERVER)
102+
add_subdirectory(FtpServer)
103+
endif()
104+
99105
message(STATUS "BUILD_RABBITVNC: ${BUILD_RABBITVNC}")
100106
message(STATUS "BUILD_TigerVNC: ${BUILD_TigerVNC}")
101107
message(STATUS "BUILD_LibVNCServer: ${BUILD_LibVNCServer}")
@@ -108,3 +114,5 @@ message(STATUS "BUILD_TERMINAL_TELNET: ${BUILD_TERMINAL_TELNET}")
108114
message(STATUS "BUILD_TERMINAL_SSH: ${BUILD_TERMINAL_SSH}")
109115
message(STATUS "BUILD_FILE_TRANSFER: ${BUILD_FILE_TRANSFER}")
110116
message(STATUS "BUILD_WEB_BROWSER: ${BUILD_WEB_BROWSER}; Qt${QT_VERSION_MAJOR}WebEngineWidgets: ${Qt${QT_VERSION_MAJOR}WebEngineWidgets_FOUND}")
117+
118+
message(STATUS "BUILD_FTP_SERVER: ${BUILD_FTP_SERVER}")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright Copyright (c) Kang Lin studio, All Rights Reserved
2+
// Author: Kang Lin <kl222@126.com>
3+
4+
#include <QLoggingCategory>
5+
#include "BackendFtpServer.h"
6+
#include "OperateFtpServer.h"
7+
static Q_LOGGING_CATEGORY(log, "FtpServer.Backend")
8+
CBackendFtpServer::CBackendFtpServer(COperate *pOperate) : CBackend(pOperate)
9+
, m_pServer(nullptr)
10+
{
11+
qDebug(log) << Q_FUNC_INFO;
12+
m_Para = ((COperateFtpServer*)pOperate)->GetParameter();
13+
}
14+
15+
CBackendFtpServer::~CBackendFtpServer()
16+
{
17+
qDebug(log) << Q_FUNC_INFO;
18+
}
19+
20+
CBackend::OnInitReturnValue CBackendFtpServer::OnInit()
21+
{
22+
qDebug(log) << Q_FUNC_INFO;
23+
if(m_pServer) {
24+
qCritical(log) << "Server is exist";
25+
return OnInitReturnValue::Fail;
26+
}
27+
m_pServer = new FtpServer(this, m_Para->GetRoot(), m_Para->GetPort(),
28+
m_Para->GetUser(), m_Para->GetPassword(),
29+
m_Para->GetReadOnly(), m_Para->GetAnonymousLogin());
30+
if(m_pServer->isListening()) {
31+
qInfo(log) << "The ftp server listen in" << m_Para->GetPort();
32+
emit sigRunning();
33+
} else {
34+
QString szErr = tr("The ftp server is not listening in %1").arg(m_Para->GetPort());
35+
emit sigError(-1, szErr);
36+
}
37+
return OnInitReturnValue::NotUseOnProcess;
38+
}
39+
40+
int CBackendFtpServer::OnClean()
41+
{
42+
qDebug(log) << Q_FUNC_INFO;
43+
44+
if(m_pServer)
45+
delete m_pServer;
46+
47+
return 0;
48+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright Copyright (c) Kang Lin studio, All Rights Reserved
2+
// Author: Kang Lin <kl222@126.com>
3+
4+
#pragma once
5+
6+
#include "Backend.h"
7+
#include "ftpserver.h"
8+
#include "ParameterFtpServer.h"
9+
10+
class CBackendFtpServer : public CBackend
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
explicit CBackendFtpServer(COperate *pOperate = nullptr);
16+
~CBackendFtpServer() override;
17+
18+
protected:
19+
virtual OnInitReturnValue OnInit() override;
20+
virtual int OnClean() override;
21+
22+
private:
23+
FtpServer* m_pServer;
24+
QSharedPointer<CParameterFtpServer> m_Para;
25+
};

Plugins/FtpServer/CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Author: Kang Lin <kl222@126.com>
2+
3+
project(FtpServer
4+
DESCRIPTION "Ftp service plugin"
5+
)
6+
7+
find_package(QFtpServerLib)
8+
if(NOT QFtpServerLib_FOUND)
9+
return()
10+
endif()
11+
12+
option(INSTALL_QFtpServer "Install QFtpServer libraries" OFF)
13+
if(INSTALL_QFtpServer)
14+
INSTALL_TARGETS(TARGETS QFtpServerLib)
15+
endif()
16+
17+
SET(FtpServer_PRIVATE_LIBS Plugin QFtpServerLib)
18+
SET(SOURCE_FILES
19+
PluginFtpServer.cpp
20+
OperateFtpServer.cpp
21+
BackendFtpServer.cpp
22+
DlgSettings.cpp
23+
ParameterFtpServer.cpp
24+
)
25+
26+
SET(HEADER_FILES
27+
PluginFtpServer.h
28+
OperateFtpServer.h
29+
BackendFtpServer.h
30+
DlgSettings.h
31+
ParameterFtpServer.h
32+
)
33+
34+
SET(RCC_FILES DlgSettings.ui)
35+
if(WITH_GUI)
36+
37+
endif()
38+
39+
ADD_PLUGIN_TARGET(NAME PluginService${PROJECT_NAME}
40+
ISPLUGIN
41+
SOURCE_FILES ${SOURCE_FILES} ${HEADER_FILES} ${RCC_FILES}
42+
PRIVATE_LIBS ${FtpServer_PRIVATE_LIBS}
43+
PRIVATE_INCLUDE_DIRS ${FtpServer_INCLUDE_DIR} ${WinPR_INCLUDE_DIR}
44+
PRIVATE_DEFINITIONS FtpServer_VERSION_MAJOR=${FtpServer_MAJOR}
45+
PRIVATE_OPTIONS ${FtpServer_OPTIONS}
46+
INSTALL_DIR ${PLUGIN_PATH}
47+
OUTPUT_DIR ${CMAKE_BINARY_DIR}/${PLUGIN_PATH}
48+
INSTALL_RPATH ${INSTALL_RPATH}
49+
VERSION ${RabbitRemoteControl_VERSION}
50+
)

Plugins/FtpServer/DlgSettings.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright Copyright (c) Kang Lin studio, All Rights Reserved
2+
// Author: Kang Lin <kl222@126.com>
3+
4+
#include <QFileDialog>
5+
#include "DlgSettings.h"
6+
#include "ui_DlgSettings.h"
7+
8+
CDlgSettings::CDlgSettings(QSharedPointer<CParameterFtpServer> para, QWidget *parent)
9+
: QDialog(parent)
10+
, ui(new Ui::CDlgSettings)
11+
, m_Para(para)
12+
{
13+
ui->setupUi(this);
14+
Q_ASSERT(m_Para);
15+
16+
ui->sbPort->setValue(m_Para->GetPort());
17+
ui->leUser->setText(m_Para->GetUser());
18+
ui->lePassword->setText(m_Para->GetPassword());
19+
ui->leRoot->setText(m_Para->GetRoot());
20+
ui->cbAnonmousLogin->setChecked(m_Para->GetAnonymousLogin());
21+
ui->cbReadOnly->setChecked(m_Para->GetReadOnly());
22+
}
23+
24+
CDlgSettings::~CDlgSettings()
25+
{
26+
delete ui;
27+
}
28+
29+
void CDlgSettings::on_pbRoot_clicked()
30+
{
31+
QString szDir = QFileDialog::getExistingDirectory(this, QString(), ui->leRoot->text());
32+
if(szDir.isEmpty())
33+
return;
34+
ui->leRoot->setText(szDir);
35+
}
36+
37+
void CDlgSettings::accept()
38+
{
39+
m_Para->SetPort(ui->sbPort->value());
40+
m_Para->SetUser(ui->leUser->text());
41+
m_Para->SetPassword(ui->lePassword->text());
42+
m_Para->SetRoot(ui->leRoot->text());
43+
m_Para->SetAnonymousLogin(ui->cbAnonmousLogin->isChecked());
44+
m_Para->SetReadOnly(ui->cbReadOnly->isChecked());
45+
QDialog::accept();
46+
}

Plugins/FtpServer/DlgSettings.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright Copyright (c) Kang Lin studio, All Rights Reserved
2+
// Author: Kang Lin <kl222@126.com>
3+
4+
#pragma once
5+
#include <QDialog>
6+
#include "ParameterFtpServer.h"
7+
8+
namespace Ui {
9+
class CDlgSettings;
10+
}
11+
12+
class CDlgSettings : public QDialog
13+
{
14+
Q_OBJECT
15+
16+
public:
17+
explicit CDlgSettings(QSharedPointer<CParameterFtpServer> para, QWidget *parent = nullptr);
18+
~CDlgSettings();
19+
20+
public slots:
21+
virtual void accept() override;
22+
private slots:
23+
void on_pbRoot_clicked();
24+
25+
private:
26+
Ui::CDlgSettings *ui;
27+
QSharedPointer<CParameterFtpServer> m_Para;
28+
};

Plugins/FtpServer/DlgSettings.ui

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>CDlgSettings</class>
4+
<widget class="QDialog" name="CDlgSettings">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>300</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Dialog</string>
15+
</property>
16+
<layout class="QGridLayout" name="gridLayout">
17+
<item row="1" column="0">
18+
<layout class="QHBoxLayout" name="horizontalLayout_7">
19+
<item>
20+
<widget class="QLabel" name="label_6">
21+
<property name="text">
22+
<string>User name:</string>
23+
</property>
24+
</widget>
25+
</item>
26+
<item>
27+
<widget class="QLineEdit" name="leUser"/>
28+
</item>
29+
</layout>
30+
</item>
31+
<item row="3" column="0">
32+
<layout class="QHBoxLayout" name="horizontalLayout_9">
33+
<item>
34+
<widget class="QLabel" name="label_8">
35+
<property name="text">
36+
<string>Root directory:</string>
37+
</property>
38+
</widget>
39+
</item>
40+
<item>
41+
<widget class="QLineEdit" name="leRoot"/>
42+
</item>
43+
<item>
44+
<widget class="QPushButton" name="pbRoot">
45+
<property name="text">
46+
<string>Browser</string>
47+
</property>
48+
</widget>
49+
</item>
50+
</layout>
51+
</item>
52+
<item row="6" column="0">
53+
<widget class="QDialogButtonBox" name="buttonBox">
54+
<property name="orientation">
55+
<enum>Qt::Orientation::Horizontal</enum>
56+
</property>
57+
<property name="standardButtons">
58+
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
59+
</property>
60+
</widget>
61+
</item>
62+
<item row="2" column="0">
63+
<layout class="QHBoxLayout" name="horizontalLayout_8">
64+
<item>
65+
<widget class="QLabel" name="label_7">
66+
<property name="text">
67+
<string>Password:</string>
68+
</property>
69+
</widget>
70+
</item>
71+
<item>
72+
<widget class="QLineEdit" name="lePassword"/>
73+
</item>
74+
</layout>
75+
</item>
76+
<item row="0" column="0">
77+
<layout class="QHBoxLayout" name="horizontalLayout_5">
78+
<item>
79+
<widget class="QLabel" name="label_5">
80+
<property name="text">
81+
<string>Port:</string>
82+
</property>
83+
</widget>
84+
</item>
85+
<item>
86+
<widget class="QSpinBox" name="sbPort">
87+
<property name="sizePolicy">
88+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
89+
<horstretch>0</horstretch>
90+
<verstretch>0</verstretch>
91+
</sizepolicy>
92+
</property>
93+
<property name="maximum">
94+
<number>65536</number>
95+
</property>
96+
</widget>
97+
</item>
98+
</layout>
99+
</item>
100+
<item row="4" column="0">
101+
<layout class="QHBoxLayout" name="horizontalLayout_10">
102+
<item>
103+
<widget class="QCheckBox" name="cbAnonmousLogin">
104+
<property name="text">
105+
<string>Aollow anonymous login</string>
106+
</property>
107+
</widget>
108+
</item>
109+
<item>
110+
<widget class="QCheckBox" name="cbReadOnly">
111+
<property name="text">
112+
<string>Read-only</string>
113+
</property>
114+
</widget>
115+
</item>
116+
</layout>
117+
</item>
118+
<item row="5" column="0">
119+
<spacer name="verticalSpacer">
120+
<property name="orientation">
121+
<enum>Qt::Orientation::Vertical</enum>
122+
</property>
123+
<property name="sizeHint" stdset="0">
124+
<size>
125+
<width>20</width>
126+
<height>40</height>
127+
</size>
128+
</property>
129+
</spacer>
130+
</item>
131+
</layout>
132+
</widget>
133+
<resources/>
134+
<connections>
135+
<connection>
136+
<sender>buttonBox</sender>
137+
<signal>accepted()</signal>
138+
<receiver>CDlgSettings</receiver>
139+
<slot>accept()</slot>
140+
<hints>
141+
<hint type="sourcelabel">
142+
<x>248</x>
143+
<y>254</y>
144+
</hint>
145+
<hint type="destinationlabel">
146+
<x>157</x>
147+
<y>274</y>
148+
</hint>
149+
</hints>
150+
</connection>
151+
<connection>
152+
<sender>buttonBox</sender>
153+
<signal>rejected()</signal>
154+
<receiver>CDlgSettings</receiver>
155+
<slot>reject()</slot>
156+
<hints>
157+
<hint type="sourcelabel">
158+
<x>316</x>
159+
<y>260</y>
160+
</hint>
161+
<hint type="destinationlabel">
162+
<x>286</x>
163+
<y>274</y>
164+
</hint>
165+
</hints>
166+
</connection>
167+
</connections>
168+
</ui>

0 commit comments

Comments
 (0)