Commit b9dba437 authored by Frederic Logier's avatar Frederic Logier
Browse files

added ftpauth http api

parent 16b427d0
......@@ -279,6 +279,10 @@ Service::~Service()
api_app->deleteLater();
thread_api_app->wait();
qDebug() << "api_ftpauth->deleteLater();";
api_ftpauth->deleteLater();
thread_api_ftpauth->wait();
/* delete(api_node);
delete(api_workflow);
delete(api_user);*/
......@@ -386,6 +390,16 @@ void Service::Http_api_init()
api_app->moveToThread(thread_api_app);
thread_api_app->start();
thread_api_ftpauth = new QThread(this);
api_ftpauth = new Api_ftpauth(m_ncs_params.base_directory, port + 105);
connect(thread_api_ftpauth, SIGNAL(started()), api_ftpauth, SLOT(init()));
connect(api_ftpauth, SIGNAL(destroyed()), thread_api_ftpauth, SLOT(quit()), Qt::DirectConnection);
api_ftpauth->moveToThread(thread_api_ftpauth);
thread_api_ftpauth->start();
}
......
......@@ -97,6 +97,7 @@ public:
Api_user *api_user;
Api_session *api_session;
Api_app *api_app;
Api_ftpauth *api_ftpauth;
private:
......@@ -108,6 +109,7 @@ private:
QThread *thread_api_user;
QThread *thread_api_session;
QThread *thread_api_app;
QThread *thread_api_ftpauth;
QThread *thread_xmpp_server;
......
Server:
max-requests: 100
zmq-io-threads: 1
disk-io-threads: 1
zmq-io-threads: 2
disk-io-threads: 2
network-timeout: 600
listen:
- host: 0.0.0.0
port: 8000
......@@ -58,7 +59,7 @@ Routing:
count: 3
"/payload*":
limits:
max-body-size: 512Mi
max-body-size: 256Mi
zmq-forward:
enabled: yes
socket:
......@@ -75,7 +76,7 @@ Routing:
- !Header X-payload-mime
- !Header X-payload-action
- !Body ~
timeout: 120
timeout: 600
"/node*":
zmq-forward:
enabled: yes
......@@ -87,7 +88,7 @@ Routing:
- !Header X-user-token
- !Header X-node-name
- !Body ~
timeout: 2
timeout: 5
retry: !RetryFirst
count: 3
"/workflow*":
......@@ -101,7 +102,7 @@ Routing:
- !Header X-user-token
- !Header X-workflow-name
- !Body ~
timeout: 2
timeout: 5
retry: !RetryFirst
count: 3
"/user*":
......@@ -114,6 +115,46 @@ Routing:
- !Uri
- !Header X-admin-token
- !Body ~
timeout: 5
retry: !RetryFirst
count: 3
"/session*":
zmq-forward:
enabled: yes
socket:
- !zmq.Connect "tcp://127.0.0.1:2605"
contents:
- !Method
- !Uri
- !Header X-user-token
- !Body ~
timeout: 2
retry: !RetryFirst
count: 3
"/app*":
zmq-forward:
enabled: yes
socket:
- !zmq.Connect "tcp://127.0.0.1:2606"
contents:
- !Method
- !Uri
- !Header X-admin-token
- !Body ~
timeout: 2
retry: !RetryFirst
count: 3
"/ftpauth*":
zmq-forward:
enabled: yes
socket:
- !zmq.Connect "tcp://127.0.0.1:2607"
contents:
- !Method
- !Uri
- !Header X-user-email
- !Header X-user-password
- !Body ~
timeout: 2
retry: !RetryFirst
count: 3
......
......@@ -1394,3 +1394,149 @@ void Api_app::receive_http_payload()
/******************************/
/*********************/
Api_ftpauth::Api_ftpauth(QString basedirectory, int port) : Zerogw(basedirectory, port)
{
std::cout << "Api_ftpauth::Api_ftpauth constructeur" << std::endl;
enumToZerogwHeaderSession.insert(0, HTTP_METHOD);
enumToZerogwHeaderSession.insert(1, URI);
enumToZerogwHeaderSession.insert(2, X_user_email);
enumToZerogwHeaderSession.insert(3, X_user_password);
}
void Api_ftpauth::receive_http_payload()
{
check_http_data->setEnabled(false);
std::cout << "Api_ftpauth::receive_payload" << std::endl;
QHash <QString, QString> zerogw;
QString key;
int counter=0;
QString bodyMessage="";
while (true)
{
zmq::message_t request;
bool res = m_socket_zerogw->recv(&request, ZMQ_NOBLOCK);
if (!res && zmq_errno () == EAGAIN) break;
qint32 events = 0;
std::size_t eventsSize = sizeof(events);
m_socket_zerogw->getsockopt(ZMQ_RCVMORE, &events, &eventsSize);
std::cout << "Api_ftpauth::receive_payload received request: [" << (char*) request.data() << "]" << std::endl;
BSONObjBuilder session_builder;
session_builder.genOID();
QString data_from_zerogw;
switch(enumToZerogwHeaderSession[counter])
{
case HTTP_METHOD:
// check METHOD
if (request.size() == 0) bodyMessage ="header METHOD is empty";
else
{
data_from_zerogw = QString::fromAscii((char*)request.data(), request.size());
zerogw["METHOD"] = data_from_zerogw;
if (zerogw["METHOD"] != "GET")
bodyMessage = "BAD REQUEST : " + zerogw["METHOD"];
}
break;
case URI:
if (!bodyMessage.isEmpty()) break;
// Check URI
if (request.size() == 0) bodyMessage ="header URI is empty";
else
{
data_from_zerogw = QString::fromAscii((char*)request.data(), request.size());
zerogw["URI"] = data_from_zerogw;
}
break;
case X_user_email:
if (!bodyMessage.isEmpty()) break;
// Check X-user-email
if (request.size() == 0) bodyMessage ="header X-user-email is empty";
else
{
data_from_zerogw = QString::fromAscii((char*)request.data(), request.size());
zerogw["X-user-email"] = data_from_zerogw;
}
break;
case X_user_password:
if (!bodyMessage.isEmpty()) break;
// Check X-user-password
if (request.size() == 0) bodyMessage ="header X-user-password is empty";
else
{
data_from_zerogw = QString::fromAscii((char*)request.data(), request.size());
zerogw["X-user-password"] = data_from_zerogw;
}
break;
}
if (!(events & ZMQ_RCVMORE))
{
qDebug() << "ZMQ_RCVMORE";
if (bodyMessage.isEmpty())
{
QCryptographicHash cipher( QCryptographicHash::Sha1 );
cipher.addData(zerogw["X-user-password"].simplified().toAscii());
QByteArray password_hash = cipher.result();
qDebug() << "Api_ftpauth::receive_payload password_hash : " << password_hash.toHex();
BSONObj bauth = BSON("email" << zerogw["X-user-email"].toStdString() << "password" << QString::fromLatin1(password_hash.toHex()).toStdString());
BSONObj l_user = mongodb_->Find("users", bauth);
if (l_user.nFields() == 0)
{
qDebug() << "Api_ftpauth::receive_payload auth failed !";
bodyMessage = buildResponse("error", "auth", "unknown user");
}
else
{
bodyMessage = buildResponse("token", QString::fromStdString(l_user.getFieldDotted("ftp.token").str()));
qDebug() << "Api_ftpauth::receive_payload TOKEN : " << bodyMessage;
}
}
zmq::message_t m_message(bodyMessage.length());
memcpy(m_message.data(), bodyMessage.toAscii(), bodyMessage.length());
m_socket_zerogw->send(m_message, 0);
qDebug() << "returning : " << bodyMessage;
}
counter++;
}
qDebug() << "ZEROGW : " << zerogw;
check_http_data->setEnabled(true);
}
/******************************/
......@@ -35,6 +35,7 @@
#include <QCryptographicHash>
#include <QRunnable>
#include <QThreadPool>
#include <QCryptographicHash>
#include <zmq.hpp>
#include "mongodb.h"
......@@ -47,6 +48,8 @@ enum ZerogwHeader {
HTTP_METHOD,
URI,
X_user_token,
X_user_email,
X_user_password,
X_node_uuid,
X_node_password,
X_workflow_uuid,
......@@ -202,5 +205,18 @@ private slots:
};
class Api_ftpauth : public Zerogw
{
Q_OBJECT
public:
Api_ftpauth(QString basedirectory, int port);
private:
IntToZerogwHeaderSession enumToZerogwHeaderSession;
private slots:
void receive_http_payload();
};
#endif // ZEROGW_H
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