Skip to content

Commit 3e9f554

Browse files
committed
Plugins::FtpServer: add white and black list
1 parent e603079 commit 3e9f554

4 files changed

Lines changed: 224 additions & 142 deletions

File tree

Plugins/FtpServer/BackendFtpServer.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,36 @@ int CBackendFtpServer::OnClean()
7575

7676
bool CBackendFtpServer::onFilter(QSslSocket *socket)
7777
{
78+
bool bFilte = false;
7879
if(!socket) return true;
80+
QString szIP = socket->peerAddress().toString();
81+
82+
QStringList white = m_Para->GetWhitelist();
83+
QStringList black = m_Para->GetBlacklist();
84+
bool bInWhite = false;
85+
if(!white.isEmpty()) {
86+
foreach(auto i, white) {
87+
QHostAddress addr(szIP);
88+
auto sub = QHostAddress::parseSubnet(i);
89+
if(addr.isInSubnet(sub.first, sub.second)) {
90+
bInWhite = true;
91+
break;
92+
}
93+
}
94+
}
95+
96+
if(!bInWhite && !black.isEmpty()) {
97+
foreach(auto i, black) {
98+
QHostAddress addr(szIP);
99+
auto sub = QHostAddress::parseSubnet(i);
100+
if(addr.isInSubnet(sub.first, sub.second)) {
101+
return true;
102+
}
103+
}
104+
}
105+
106+
if(bFilte) return true;
107+
79108
if(m_Para->GetConnectCount() >= 0 && m_Para->GetConnectCount() <= m_Sockets.size()) {
80109
qDebug(log) << "Exceeded the allowed number of connections:" << m_Para->GetConnectCount();
81110
return true;
@@ -85,14 +114,14 @@ bool CBackendFtpServer::onFilter(QSslSocket *socket)
85114
check = connect(socket, SIGNAL(disconnected()),
86115
this, SLOT(slotDisconnected()));
87116
Q_ASSERT(check);
88-
QString ip = socket->peerAddress().toString();
117+
89118
quint16 port = socket->peerPort();
90119
m_Sockets.append(socket);
91120
m_nTotal++;
92121
emit sigConnectCount(m_nTotal, m_Sockets.size(), m_nDisconnect);
93-
emit sigConnected(ip, port);
122+
emit sigConnected(szIP, port);
94123
qDebug(log) << "Current connect count:" << m_Sockets.size()
95-
<< "; new connect from:" << ip + ":" + QString::number(port);
124+
<< "; new connect from:" << szIP + ":" + QString::number(port);
96125
return false;
97126
}
98127

Plugins/FtpServer/DlgSettings.ui

Lines changed: 160 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -6,156 +6,177 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>400</width>
10-
<height>300</height>
9+
<width>600</width>
10+
<height>450</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Dialog</string>
1515
</property>
16-
<layout class="QGridLayout" name="gridLayout">
17-
<item row="8" column="0">
18-
<widget class="QDialogButtonBox" name="buttonBox">
19-
<property name="orientation">
20-
<enum>Qt::Orientation::Horizontal</enum>
21-
</property>
22-
<property name="standardButtons">
23-
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
24-
</property>
25-
</widget>
26-
</item>
27-
<item row="4" column="0">
28-
<layout class="QHBoxLayout" name="horizontalLayout_10">
29-
<item>
30-
<widget class="QCheckBox" name="cbAnonmousLogin">
31-
<property name="text">
32-
<string>Aollow anonymous login</string>
33-
</property>
34-
</widget>
35-
</item>
36-
<item>
37-
<widget class="QCheckBox" name="cbReadOnly">
38-
<property name="text">
39-
<string>Read-only</string>
40-
</property>
41-
</widget>
42-
</item>
43-
</layout>
44-
</item>
45-
<item row="3" column="0">
46-
<layout class="QHBoxLayout" name="horizontalLayout_9">
47-
<item>
48-
<widget class="QLabel" name="label_8">
49-
<property name="text">
50-
<string>Root directory:</string>
51-
</property>
52-
</widget>
53-
</item>
54-
<item>
55-
<widget class="QLineEdit" name="leRoot"/>
56-
</item>
57-
<item>
58-
<widget class="QPushButton" name="pbRoot">
59-
<property name="text">
60-
<string>Browser</string>
61-
</property>
62-
</widget>
63-
</item>
64-
</layout>
65-
</item>
16+
<layout class="QGridLayout" name="gridLayout_2">
6617
<item row="0" column="0">
67-
<layout class="QHBoxLayout" name="horizontalLayout_5">
68-
<item>
69-
<widget class="QLabel" name="label_5">
70-
<property name="text">
71-
<string>Port:</string>
72-
</property>
73-
</widget>
74-
</item>
75-
<item>
76-
<widget class="QSpinBox" name="sbPort">
77-
<property name="sizePolicy">
78-
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
79-
<horstretch>0</horstretch>
80-
<verstretch>0</verstretch>
81-
</sizepolicy>
82-
</property>
83-
<property name="maximum">
84-
<number>65536</number>
85-
</property>
86-
</widget>
87-
</item>
88-
<item>
89-
<widget class="QLabel" name="label">
90-
<property name="text">
91-
<string>Connect count:</string>
92-
</property>
93-
</widget>
94-
</item>
95-
<item>
96-
<widget class="QSpinBox" name="sbConnectCount">
97-
<property name="minimum">
98-
<number>-1</number>
99-
</property>
100-
<property name="maximum">
101-
<number>65536</number>
102-
</property>
103-
</widget>
104-
</item>
105-
</layout>
106-
</item>
107-
<item row="1" column="0">
108-
<layout class="QHBoxLayout" name="horizontalLayout_7">
109-
<item>
110-
<widget class="QLabel" name="label_6">
111-
<property name="text">
112-
<string>User name:</string>
113-
</property>
114-
</widget>
115-
</item>
116-
<item>
117-
<widget class="QLineEdit" name="leUser"/>
118-
</item>
119-
</layout>
120-
</item>
121-
<item row="5" column="0">
122-
<widget class="QCheckBox" name="cbListenAll">
123-
<property name="text">
124-
<string>Enable listen at all network interface</string>
18+
<widget class="QTabWidget" name="tabWidget">
19+
<property name="currentIndex">
20+
<number>0</number>
12521
</property>
22+
<widget class="QWidget" name="tab_3">
23+
<attribute name="title">
24+
<string>General</string>
25+
</attribute>
26+
<layout class="QGridLayout" name="gridLayout">
27+
<item row="0" column="0">
28+
<layout class="QHBoxLayout" name="horizontalLayout_5">
29+
<item>
30+
<widget class="QLabel" name="label_5">
31+
<property name="text">
32+
<string>Port:</string>
33+
</property>
34+
</widget>
35+
</item>
36+
<item>
37+
<widget class="QSpinBox" name="sbPort">
38+
<property name="sizePolicy">
39+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
40+
<horstretch>0</horstretch>
41+
<verstretch>0</verstretch>
42+
</sizepolicy>
43+
</property>
44+
<property name="maximum">
45+
<number>65536</number>
46+
</property>
47+
</widget>
48+
</item>
49+
<item>
50+
<widget class="QLabel" name="label">
51+
<property name="text">
52+
<string>Connect count:</string>
53+
</property>
54+
</widget>
55+
</item>
56+
<item>
57+
<widget class="QSpinBox" name="sbConnectCount">
58+
<property name="minimum">
59+
<number>-1</number>
60+
</property>
61+
<property name="maximum">
62+
<number>65536</number>
63+
</property>
64+
</widget>
65+
</item>
66+
</layout>
67+
</item>
68+
<item row="1" column="0">
69+
<layout class="QHBoxLayout" name="horizontalLayout_7">
70+
<item>
71+
<widget class="QLabel" name="label_6">
72+
<property name="text">
73+
<string>User name:</string>
74+
</property>
75+
</widget>
76+
</item>
77+
<item>
78+
<widget class="QLineEdit" name="leUser"/>
79+
</item>
80+
</layout>
81+
</item>
82+
<item row="2" column="0">
83+
<layout class="QHBoxLayout" name="horizontalLayout_8">
84+
<item>
85+
<widget class="QLabel" name="label_7">
86+
<property name="text">
87+
<string>Password:</string>
88+
</property>
89+
</widget>
90+
</item>
91+
<item>
92+
<widget class="QLineEdit" name="lePassword"/>
93+
</item>
94+
</layout>
95+
</item>
96+
<item row="3" column="0">
97+
<layout class="QHBoxLayout" name="horizontalLayout_9">
98+
<item>
99+
<widget class="QLabel" name="label_8">
100+
<property name="text">
101+
<string>Root directory:</string>
102+
</property>
103+
</widget>
104+
</item>
105+
<item>
106+
<widget class="QLineEdit" name="leRoot"/>
107+
</item>
108+
<item>
109+
<widget class="QPushButton" name="pbRoot">
110+
<property name="text">
111+
<string>Browser</string>
112+
</property>
113+
</widget>
114+
</item>
115+
</layout>
116+
</item>
117+
<item row="4" column="0">
118+
<layout class="QHBoxLayout" name="horizontalLayout_10">
119+
<item>
120+
<widget class="QCheckBox" name="cbAnonmousLogin">
121+
<property name="text">
122+
<string>Aollow anonymous login</string>
123+
</property>
124+
</widget>
125+
</item>
126+
<item>
127+
<widget class="QCheckBox" name="cbReadOnly">
128+
<property name="text">
129+
<string>Read-only</string>
130+
</property>
131+
</widget>
132+
</item>
133+
</layout>
134+
</item>
135+
<item row="5" column="0">
136+
<widget class="QCheckBox" name="cbListenAll">
137+
<property name="text">
138+
<string>Enable listen at all network interface</string>
139+
</property>
140+
</widget>
141+
</item>
142+
<item row="6" column="0">
143+
<widget class="QListView" name="lvListen">
144+
<property name="editTriggers">
145+
<set>QAbstractItemView::EditTrigger::NoEditTriggers</set>
146+
</property>
147+
</widget>
148+
</item>
149+
</layout>
150+
</widget>
151+
<widget class="QWidget" name="tab_4">
152+
<attribute name="title">
153+
<string>Whitelist</string>
154+
</attribute>
155+
<layout class="QGridLayout" name="gridLayout_4">
156+
<item row="0" column="0">
157+
<widget class="QListView" name="lvWhtelist"/>
158+
</item>
159+
</layout>
160+
</widget>
161+
<widget class="QWidget" name="tab_5">
162+
<attribute name="title">
163+
<string>Blacklist</string>
164+
</attribute>
165+
<layout class="QGridLayout" name="gridLayout_3">
166+
<item row="0" column="0">
167+
<widget class="QListView" name="lvBlacklist"/>
168+
</item>
169+
</layout>
170+
</widget>
126171
</widget>
127172
</item>
128-
<item row="7" column="0">
129-
<spacer name="verticalSpacer">
173+
<item row="1" column="0">
174+
<widget class="QDialogButtonBox" name="buttonBox">
130175
<property name="orientation">
131-
<enum>Qt::Orientation::Vertical</enum>
132-
</property>
133-
<property name="sizeHint" stdset="0">
134-
<size>
135-
<width>20</width>
136-
<height>40</height>
137-
</size>
176+
<enum>Qt::Orientation::Horizontal</enum>
138177
</property>
139-
</spacer>
140-
</item>
141-
<item row="2" column="0">
142-
<layout class="QHBoxLayout" name="horizontalLayout_8">
143-
<item>
144-
<widget class="QLabel" name="label_7">
145-
<property name="text">
146-
<string>Password:</string>
147-
</property>
148-
</widget>
149-
</item>
150-
<item>
151-
<widget class="QLineEdit" name="lePassword"/>
152-
</item>
153-
</layout>
154-
</item>
155-
<item row="6" column="0">
156-
<widget class="QListView" name="lvListen">
157-
<property name="editTriggers">
158-
<set>QAbstractItemView::EditTrigger::NoEditTriggers</set>
178+
<property name="standardButtons">
179+
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
159180
</property>
160181
</widget>
161182
</item>

0 commit comments

Comments
 (0)