separate search by string and regexp

master
const an teen 2021-12-24 13:29:52 -05:00
parent aed027c21c
commit 2d6a6e4fd1
6 changed files with 57 additions and 21 deletions

View File

@ -36,11 +36,11 @@ QString getValue(const QString &string, const QString &key, Type type)
result.remove(QRegularExpression("^.*"+key+"\\s*=", QRegularExpression::DotMatchesEverythingOption));
}
QString separator {"\n"};
QString separator {'\n'};
if (type == eForTriggers) {
separator = ":::";
} else if (type == eForWeb) {
separator = " ";
separator = '&';
} else if (type == eHttpHeader) {
separator = "\r\n";
}
@ -49,6 +49,13 @@ QString getValue(const QString &string, const QString &key, Type type)
if (valueEnd != -1) {
result.remove(valueEnd, result.size()-valueEnd);
}
else if (valueEnd == -1 and type == eForWeb) {
separator = ' ';
valueEnd = result.indexOf(separator);
if (valueEnd != -1) {
result.remove(valueEnd, result.size()-valueEnd);
}
}
if (type == eForWeb) {
result = QByteArray::fromPercentEncoding(result.toUtf8());

View File

@ -20,9 +20,17 @@
</div>
<div class="main_header__search">
<form class="main_header__search_form" method="get">
<input class="main_header__search_input" type="search" name="toSearch" placeholder="{{SEARCH_PLACEHOLDER}}">
<div class="main_header__search_button">
<input class="main_header__search_button__img" type="submit" value="">
<div class="main_header__search_block">
<input class="main_header__search_input" type="search" name="toSearch" placeholder="{{SEARCH_PLACEHOLDER}}">
<div class="main_header__search_button">
<input class="main_header__search_button__img" type="submit" value="">
</div>
</div>
<div class="main_header__search_checkbox">
<input id="main_header__search_checkbox__button" type="checkbox" name="isRegexp">
<label style="cursor: pointer;" for="main_header__search_checkbox__button">
Regular expression
</label>
</div>
</form>
</div>

View File

@ -104,11 +104,18 @@ body {
width: 100%;
height: 70%;
display: flex;
flex-direction: column;
}
.main_header__search_block {
flex: 90%;
width: 100%;
display: flex;
flex-direction: row;
}
.main_header__search_input {
width: 75%;
width: 80%;
height: 100%;
border: 2px solid #b6c7d6;
font-size: 18px;
@ -119,7 +126,7 @@ body {
.main_header__search_button {
width: 20%;
margin-left: 2%;
height: 84%;
height: 87%;
border: 2px solid #b6c7d6;
}
@ -138,6 +145,10 @@ body {
border: 2px solid #6493bc;
}
.main_header__search_checkbox {
color: #6493bc;
}
.main_middle {
flex: 3%;
display: flex;

View File

@ -70,10 +70,7 @@ std::pair<QString, QString> HttpServer::splitUserNameAndMessage(const QString &r
return result;
}
nick.replace('&', "&amp;");
nick.replace('<', "&lt;");
nick.replace('>', "&gt;");
nick.replace('\"', "&quot;");
nick = nick.toHtmlEscaped();
// long nicks
if (nick.size() > MAX_NICKNAME_LENGTH_WITHOUT_WBR) {
@ -86,10 +83,7 @@ std::pair<QString, QString> HttpServer::splitUserNameAndMessage(const QString &r
}
}
text.replace('&', "&amp;");
text.replace('<', "&lt;");
text.replace('>', "&gt;");
text.replace('\"', "&quot;");
text = text.toHtmlEscaped();
// http links
while (QRegularExpression("(^|\\s)http.?://").match(text).hasMatch()) {
@ -391,9 +385,11 @@ void HttpServer::replaceTag(QString &page, const QString &tag, const QString &pa
void HttpServer::writeMainPage(QTcpSocket *socket, QString &urlPath, bool isHeadRequest)
{
QString searchRequest;
bool isRegexp {false};
int specSymbol = urlPath.indexOf('?'); // any actions like a ?toSearch=
if (specSymbol != -1) {
searchRequest = global::getValue(urlPath, "toSearch", global::eForWeb);
isRegexp = global::getValue(urlPath, "isRegexp", global::eForWeb) == "on";
urlPath.remove(specSymbol, urlPath.size()-specSymbol);
}
if (urlPath == "/") {
@ -409,10 +405,15 @@ void HttpServer::writeMainPage(QTcpSocket *socket, QString &urlPath, bool isHead
else {
if (socket->isOpen()) {
socket->write(HEADER_404.toUtf8());
if (not isHeadRequest) socket->write("<title>Critical error</title><center><h1>NOT FOUND</H1><p>Maybe it is compilation error</p></center>");
if (not isHeadRequest) socket->write("<title>Critical error</title><center><h1>NOT FOUND</H1><p>Maybe it's compile time error</p></center>");
}
}
if (isRegexp) {
page.replace("<input id=\"main_header__search_checkbox__button\" type=\"checkbox\" name=\"isRegexp\">",
"<input id=\"main_header__search_checkbox__button\" type=\"checkbox\" name=\"isRegexp\" checked>");
}
QString server = getWordFromPath(urlPath);
QDir fsPath(m_logFolder+server);
if (not fsPath.exists()) {
@ -609,7 +610,10 @@ void HttpServer::writeMainPage(QTcpSocket *socket, QString &urlPath, bool isHead
replaceTag(page, "ONLINE", QString::number(currentOnline));
replaceTag(page, "ONLINE_LIST", onlineUserS);
if (middlePath == "/") {
if (not searchRequest.isEmpty()) {
page.replace("<input class=\"main_header__search_input\" type=\"search\" name=\"toSearch\" placeholder=\"{{SEARCH_PLACEHOLDER}}\">",
"<input class=\"main_header__search_input\" type=\"search\" name=\"toSearch\" value=\"" + searchRequest + "\">");
} else if (middlePath == "/") {
replaceTag(page, "SEARCH_PLACEHOLDER", originalChannelName);
} else if (month.isEmpty()) {
replaceTag(page, "SEARCH_PLACEHOLDER", originalChannelName + "/" + year);
@ -625,7 +629,9 @@ void HttpServer::writeMainPage(QTcpSocket *socket, QString &urlPath, bool isHead
uint counter = 0;
QRegularExpression userRgx(searchRequest, QRegularExpression::CaseInsensitiveOption);
bool rgxIsValid = false;
if (userRgx.isValid()) rgxIsValid = true;
if (isRegexp and userRgx.isValid()) {
rgxIsValid = true;
}
consoleLog("Search request (" + server + "): " + searchRequest);
if (not day.isEmpty()) {
@ -898,7 +904,9 @@ void HttpServer::writeMainPage(QTcpSocket *socket, QString &urlPath, bool isHead
}
}
}
middlePath += " [" + searchRequest + "]: " + QString::number(counter);
middlePath += " " + searchRequest + " ";
if (rgxIsValid) middlePath += "rgx";
middlePath += "(" + QString::number(counter) + ")";
}
// Plain log explorer

View File

@ -5,7 +5,7 @@
#include <QTcpServer>
#include <map>
const QString HTTP_ACTUAL_ETAG {"2021-12-15"}; // Change it if svg, css or ico was modified
const QString HTTP_ACTUAL_ETAG {"2021-12-24"}; // Change it if svg, css or ico was modified
class HttpServer : public QObject
{
@ -25,6 +25,7 @@ private:
void replaceTag(QString& page, const QString& tag, const QString& payload);
void consoleLog(const QString &message);
void debugLog(const QString &url);
QTcpServer* m_TcpServer;
QString m_mainChannel;
QString m_logFolder;

View File

@ -10,6 +10,7 @@
const int NICK_RECOVER_TIMER = 60000; // 1 minute
const int THREAD_SLEEP_ON_RECONNECT = 3; // seconds
const int USER_LIST_ACTIALIZE = 1800000; // 30 minutes
IrcClient::IrcClient(const ConnectionData& config, QObject *parent) :
QObject(parent),
@ -265,7 +266,7 @@ void IrcClient::onRead()
if (not m_connected) {
consoleLog("Connected to server!");
m_timerToJoin.start(1000);
m_usersActualize.start(1800000); // 30 munites
m_usersActualize.start(USER_LIST_ACTIALIZE);
m_connected = true;
emit myOnline(m_connectionData.displayName, m_connected);
}