adding files from other projects, adding http interface pages

This commit is contained in:
Dario 2019-09-22 08:10:39 +02:00
parent 866b4faedb
commit 86a83e3e00
21 changed files with 1217 additions and 11 deletions

View File

@ -11,12 +11,17 @@ include_directories(
)
FILE(GLOB TINF "dependencies/tinf/src/*.c" "dependencies/tinf/src/*.h")
SET(LOCAL_SRCS ${TINF})
FILE(GLOB HTTPInterface "src/cpp/HTTPInterface/*.h" "src/cpp/HTTPInterface/*.cpp")
FILE(GLOB CRYPTO "src/cpp/Crypto/*.h" "src/cpp/Crypto/*.cpp")
FILE(GLOB MAIN "src/cpp/*.cpp" "src/cpp/*.c" "src/cpp/*.h")
SET(LOCAL_SRCS ${TINF} ${MAIN} ${HTTPInterface} ${CRYPTO})
aux_source_directory("src/cpp" LOCAL_SRCS)
if(MSVC)
# src
source_group("tinf" FILES ${TINF})
source_group("crypto" FILES ${CRYPTO})
source_group("HTTP-Interface" FILES ${HTTPInterface})
endif(MSVC)

134
src/cpp/Crypto/DRHash.h Normal file
View File

@ -0,0 +1,134 @@
/*/*************************************************************************
* *
* Core, Core-Lib for my programs, Core doesn't need any libraries *
* Copyright (C) 2012, 2013, 2014 Dario Rekowski *
* Email: ***REMOVED*** Web: ***REMOVED*** *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
//---------------------------------------------------------
// hashing header file
// aus dem Buch "Goldene Regeln der Spieleprogrammierung" von Martin Brownlow
//---------------------------------------------------------
#ifndef __DR_CORE2_HASH__
#define __DR_CORE2_HASH__
#include <stdio.h>
typedef unsigned int HASH;
typedef unsigned long DHASH;
#ifndef u32
typedef unsigned long u32;
#endif
#ifndef s32
typedef long s32;
#endif
//---------------------------------------------------------
// sample hash creation functions
//---------------------------------------------------------
inline HASH DRHashRotateLeft( HASH hash, const unsigned int rotateBy )
{
return (hash<<rotateBy)|(hash>>(32-rotateBy));
}
//---------------------------------------------------------
// create a hash from a string
//---------------------------------------------------------
inline HASH DRMakeStringHash( const char *pString )
{
HASH ret = 0;
char c;
if( pString )
{
while( (c=*(pString++)) != '\0' )
ret = DRHashRotateLeft(ret,7) + c;
}
return ret;
}
inline HASH DRMakeStringHash(const char *pString, unsigned int str_size)
{
HASH ret = 0;
if (pString)
{
for (unsigned int i = 0; i < str_size; i++) {
ret = DRHashRotateLeft(ret, 7) + pString[i];
}
}
return ret;
}
//---------------------------------------------------------
// create a hash from a filename
//---------------------------------------------------------
inline HASH DRMakeFilenameHash( const char *pString )
{
HASH ret = 0;
char c;
if( pString )
{
while( (c=*(pString++)) != '\0' )
{
if( c>='A' && c<='Z' )
c ^= 32;
else if( c=='/' )
c = '\\';
ret = DRHashRotateLeft(ret,7) + c;
}
}
return ret;
}
//-----------------------------------------------------------------------------------
//einen Hash aus zwei Werten erstellen
inline DHASH DRMakeDoubleHash(const char* pTypeName, const char* pFileName)
{
HASH hTemp1 = DRMakeStringHash(pTypeName);
DHASH hTemp2 = DRMakeFilenameHash(pFileName);
hTemp2 = hTemp2 << 16;
return ((DHASH)(hTemp1)|(DHASH)(hTemp2));
}
//einen Hash aus 3 Int-Werten generiren
inline DHASH DRMakeThreeIntHash(int i1, int i2, int i3)
{
DHASH h1 = DRHashRotateLeft(i1, 24);
h1 = h1 | DRHashRotateLeft(i2, 16);
return h1 | i3;
}
/*
//ein hash aus einem Vector2D
inline CORE2_API DHASH DRMakeVector2Hash(DRVector2 vVector)
{
DHASH h1 = DRHashRotateLeft((int)vVector.x, 16);
return h1 | (int)vVector.y;
}
//ein hash aus einem Vector3D
inline CORE2_API DHASH DRMakeVector3Hash(DRVector3 vector)
{
return DRMakeThreeIntHash((int)vector.x, (int)vector.y, (int)vector.z);
}
*/
#endif //__DR_CORE2_HASH__

View File

@ -0,0 +1,282 @@
//------------------------------------------------------------------
// hash list implementation
//------------------------------------------------------------------
#include "DRHashList.h"
#include <memory>
#include <cstring>
using namespace std;
//------------------------------------------------------------------
// DRStaticHashList
// set the data
//------------------------------------------------------------------
void DRStaticHashList::setData( u32 nItems, DRHashListItem *pItems)
{
m_nItems = nItems;
m_pItems = pItems;
}
//------------------------------------------------------------------
// DRStaticHashList
// does an item exist
//------------------------------------------------------------------
bool DRStaticHashList::itemExists( DHASH hashValue, u32 *outIndex ) const
{
s32 window[3];
// empty???
if( m_nItems==0 )
return false;
// simple binary search
// divide and conquer is maybe faster?
window[0] = 0;
window[2] = m_nItems-1;
while( window[0]<=window[2] )
{
window[1] = (window[0]+window[2])/2;
// is this the item we're looking for?
if( m_pItems[window[1]].hashValue==hashValue )
{
if( outIndex )
outIndex[0] = window[1];
return true;
}
// check whether to search top or bottom half of list
if( m_pItems[window[1]].hashValue<hashValue )
window[0] = window[1]+1;
else
window[2] = window[1]-1;
}
return false;
}
//------------------------------------------------------------------
// DRStaticHashList
// find an entry by hash
//------------------------------------------------------------------
void *DRStaticHashList::findByHash( DHASH hashValue ) const
{
s32 window[3];
// empty???
if( m_nItems==0 )
return 0;
// simple binary search
// divide and conquer is maybe faster?
window[0] = 0;
window[2] = m_nItems-1;
while( window[0]<=window[2] )
{
window[1] = (window[0]+window[2])/2;
// is this the item we're looking for?
if( m_pItems[window[1]].hashValue==hashValue )
return m_pItems[window[1]].data;
// check whether to search top or bottom half of list
if( m_pItems[window[1]].hashValue<hashValue )
window[0] = window[1]+1;
else
window[2] = window[1]-1;
}
return 0;
}
//------------------------------------------------------------------
// DRStaticHashList
// find an entry by index
//------------------------------------------------------------------
void *DRStaticHashList::findByIndex( u32 index ) const
{
if( index>=m_nItems )
return 0;
return m_pItems[index].data;
}
//------------------------------------------------------------------
// DRStaticHashList
// find a hash by index
//------------------------------------------------------------------
DHASH DRStaticHashList::findHashByIndex( u32 index ) const
{
if( index>=m_nItems )
return 0;
return m_pItems[index].hashValue;
}
void DRStaticHashList::setDataByIndex(u32 index, void* data)
{
if (index >= m_nItems)
return;
m_pItems[index].data = data;
}
//------------------------------------------------------------------
// DRStaticHashList
// find the index where a given hash value should go
// this is very similar to the FindByHash routine
//------------------------------------------------------------------
u32 DRStaticHashList::findIndexForHash( DHASH hashValue )
{
s32 window[3];
if( m_nItems==0 )
return 0;
// simple binary search
// divide and conquer is maybe faster?
window[0] = 0;
window[2] = m_nItems-1;
while( window[0]<=window[2] )
{
window[1] = (window[0]+window[2])/2;
// is this the item we're looking for?
if( m_pItems[window[1]].hashValue==hashValue )
return window[1];
// check whether to search top or bottom half of list
if( m_pItems[window[1]].hashValue<hashValue )
window[0] = window[1]+1;
else
window[2] = window[1]-1;
}
// do we belong after this item?
if( m_pItems[window[1]].hashValue<hashValue )
window[1]++;
return window[1];
}
//------------------------------------------------------------------
// DRHashList
// sort items (static member function)
//------------------------------------------------------------------
#ifdef _WIN32
int __cdecl hashSortFn( const void *a, const void *b )
#else
int hashSortFn( const void *a, const void *b )
#endif
{
if( (((DRHashListItem*)a)->hashValue) > (((DRHashListItem*)b)->hashValue) )
return 1;
if( (((DRHashListItem*)a)->hashValue) < (((DRHashListItem*)b)->hashValue) )
return -1;
return 0;
}
void DRHashList::sortItems( u32 numItems, DRHashListItem *pItems )
{
qsort(pItems,numItems,getSizeOfItem(),hashSortFn);
}
//------------------------------------------------------------------
// DRHashList
// destructor
//------------------------------------------------------------------
DRHashList::~DRHashList()
{
clear(true);
}
//------------------------------------------------------------------
// DRHashList
// clear the hash list out
//------------------------------------------------------------------
void DRHashList::clear( bool freeMemory )
{
m_nItems = 0;
if( freeMemory && m_pItems )
{
m_maxItems = 0;
free(m_pItems);
m_pItems = 0;
}
}
//------------------------------------------------------------------
// DRHashList
// add an item to the DRHashList
//------------------------------------------------------------------
bool DRHashList::addByHash( DHASH hashValue, void *pData )
{
u32 toIndex;
DRHashListItem *pMe;
// find where this hashValue goes
toIndex = findIndexForHash(hashValue);
// is an item with this hash already here?
if( toIndex!=m_nItems && m_pItems[toIndex].hashValue==hashValue )
return false;
// create room in the hash table
if( m_nItems==m_maxItems )
{ // need to reallocate some data
m_maxItems += 32; // allocate some more items
m_pItems = (DRHashListItem*)realloc(m_pItems,m_maxItems*getSizeOfItem());
}
pMe = &m_pItems[toIndex];
// make a hole for me to go
if( toIndex!=m_nItems )
{
memmove( &pMe[1],pMe,(m_nItems-toIndex)*getSizeOfItem());
}
pMe->hashValue = hashValue;
pMe->data = pData;
m_nItems++;
return true;
}
void DRHashList::resize(u32 newSize)
{
if (newSize > m_maxItems) {
m_maxItems = newSize;
if (m_pItems) {
m_pItems = (DRHashListItem*)realloc(m_pItems, m_maxItems*getSizeOfItem());
}
else {
m_pItems = (DRHashListItem *)malloc(m_maxItems*getSizeOfItem());
}
}
}
//------------------------------------------------------------------
// DRHashList
// remove an item to the DRHashList
//------------------------------------------------------------------
bool DRHashList::removeByHash( DHASH hashValue )
{
u32 toIndex;
// find where this hashValue goes
toIndex = findIndexForHash(hashValue);
// is an item with this hash here?
if( toIndex==m_nItems || m_pItems[toIndex].hashValue!=hashValue )
return false;
// remove this item from the list
m_nItems-=1;
if( toIndex!=m_nItems )
{
memmove(&m_pItems[toIndex],&m_pItems[toIndex+1],(m_nItems-toIndex)*getSizeOfItem());
}
return true;
}

116
src/cpp/Crypto/DRHashList.h Normal file
View File

@ -0,0 +1,116 @@
/*/*************************************************************************
* *
* Core, Core-Lib for my programs, Core doesn't need any libraries *
* Copyright (C) 2012, 2013, 2014 Dario Rekowski *
* Email: ***REMOVED*** Web: ***REMOVED*** *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
//---------------------------------------------------------
// hash list definition
// aus dem Buch "Goldene Regeln der Spieleprogrammierung" von Martin Brownlow
//---------------------------------------------------------
#ifndef __DR_CORE2_HASH_LIST__
#define __DR_CORE2_HASH_LIST__
#include "DRHash.h"
//---------------------------------------------------------
// an item in the hash list
//---------------------------------------------------------
class DRHashListItem
{
public:
DHASH hashValue;
void *data;
};
//---------------------------------------------------------
// static hash list implementation
//---------------------------------------------------------
class DRStaticHashList
{
public:
DRStaticHashList() : m_nItems(0),m_pItems(0) { /*empty*/ }
~DRStaticHashList() { /*empty*/ }
void setData( u32 nItems, DRHashListItem *pItems);
const void *getData() const { return m_pItems; }
u32 getDataSize( ) const { return m_nItems*sizeof(DRHashListItem); }
u32 getNItems( ) const { return m_nItems; }
void *findByHash( DHASH hashValue ) const;
void *findByIndex( u32 index ) const;
DHASH findHashByIndex( u32 index ) const;
void setDataByIndex(u32 index, void* data);
bool itemExists( DHASH hashValue, u32 *outIndex=0 ) const;
protected:
// find the index where a hash value should go
u32 findIndexForHash( DHASH hashValue );
inline static size_t getSizeOfItem() {return sizeof(DRHashListItem);}
protected:
u32 m_nItems;
DRHashListItem *m_pItems;
};
//---------------------------------------------------------
// general case hash list implementation
//---------------------------------------------------------
class DRHashList : public DRStaticHashList
{
public:
static void sortItems( u32 numItems, DRHashListItem *pItems );
public:
DRHashList() : DRStaticHashList(), m_maxItems(0) { /*empty*/ }
~DRHashList();
// inherited functionality
//void *FindByHash( DHASH hashValue ) const;
// clear the list
void clear( bool freeMemory=false );
// functions by hash
bool addByHash( DHASH hashValue, void *pData );
bool removeByHash( DHASH hashValue );
void resize(u32 newSize);
// functions by type
template <class X>
inline bool add( X *pData )
{
return addByHash(pData->makeHash(),pData);
}
template <class X>
inline bool remove( const X *pData )
{
return removeByHash(pData->makeHash());
}
protected:
u32 m_maxItems;
};
#endif //__DR_CORE2_HASH_LIST__

View File

@ -0,0 +1,98 @@
#include "mnemonic.h"
#include <memory>
#include <cstring>
#include "../dependencies/tinf/src/tinf.h"
Mnemonic::Mnemonic()
{
memset(mWords, 0, 2048);
mWordHashIndices.resize(2048);
}
Mnemonic::~Mnemonic()
{
for (int i = 0; i < 2048; i++) {
if (mWords[i]) {
free(mWords[i]);
}
}
memset(mWords, 0, 2048);
mWordHashIndices.clear(true);
}
int Mnemonic::init(void(*fill_words_func)(unsigned char*), unsigned int original_size, unsigned int compressed_size)
{
unsigned char* buffer = (unsigned char*)malloc(compressed_size);
unsigned char* uncompressed_buffer = (unsigned char*)malloc(original_size + 1);
memset(uncompressed_buffer, 0, original_size + 1);
fill_words_func(buffer);
// uncompress
unsigned int original_size_cpy = original_size;
if (tinf_gzip_uncompress(uncompressed_buffer, &original_size_cpy, buffer, compressed_size) != TINF_OK) {
free(buffer);
free(uncompressed_buffer);
return -1;
}
if (original_size_cpy != original_size) {
free(buffer);
free(uncompressed_buffer);
return -2;
}
else {
free(buffer);
//printf("c[Mnemonic::%s] uncompressing success\n", __FUNCTION__);
// fill words in array and hashList
int cursor = 0;
u32 word_begin = 0, word_end = 0;
for (unsigned int i = 0; i < original_size; i++) {
if (cursor >= 2048) {
return -3;
}
if (uncompressed_buffer[i] == ',') {
word_end = i;
u32 word_size = word_end - word_begin;
if (word_end < word_begin) {
//printf("%c %c %c\n", uncompressed_buffer[i - 1], uncompressed_buffer[i], uncompressed_buffer[i + 1]);
//printf("%s\n", uncompressed_buffer);
continue;
}
// + 1 for null terminating
mWords[cursor] = (char*)malloc(word_size + 1);
// fill hash list for fast reverse lookup
memset(mWords[cursor], 0, word_size + 1);
if (word_begin + word_size >= original_size) {
printf("c[Mnemonic::%s] word goes out of array bounds\n", __FUNCTION__);
free(uncompressed_buffer);
return -4;
}
memcpy(mWords[cursor], &uncompressed_buffer[word_begin], word_size);
//char bu[256]; memset(bu, 0, 256);
//memcpy(bu, &uncompressed_buffer[word_begin - 1], 10);
//printf("word (%d): %s\n", cursor, bu);
DHASH word_hash = DRMakeStringHash(mWords[cursor]);
mWordHashIndices.addByHash(word_hash, (void*)cursor);
word_begin = i + 1;
cursor++;
}
}
//printf("c[Mnemonic::%s] before freeing uncompressed buffer \n", __FUNCTION__);
free(uncompressed_buffer);
return 0;
}
//printf("c[Mnemonic::%s] before freeing buffer \n", __FUNCTION__);
free(buffer);
}

34
src/cpp/Crypto/mnemonic.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef DR_MNEMONIC_H
#define DR_MNEMONIC_H
/*!
*
* @author: einhornimmond
*
* @date: 16.06.19
*
* @desc: Class for handling mnemonic word list, unpacking, reverse lookup
*
*/
#include "DRHashList.h"
class Mnemonic
{
public:
Mnemonic();
~Mnemonic();
int init(void(*fill_words_func)(unsigned char*), unsigned int original_size, unsigned int compressed_size);
inline const char* getWord(unsigned int index) { if (index < 2048) return mWords[index]; return nullptr; }
inline unsigned long getWordIndex(const char* word) { DHASH word_hash = DRMakeStringHash(word); return (long)mWordHashIndices.findByHash(word_hash); }
protected:
char* mWords[2048];
DRHashList mWordHashIndices;
};
#endif //DR_MNEMONIC_H

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,81 @@
#include "Gradido_LoginServer.h"
#include "HTTPInterface/PageRequestHandlerFactory.h"
#include "Poco/Util/HelpFormatter.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/Net/HTTPServer.h"
#include <sodium.h>
Gradido_LoginServer::Gradido_LoginServer()
: _helpRequested(false)
{
}
Gradido_LoginServer::~Gradido_LoginServer()
{
}
void Gradido_LoginServer::initialize(Application& self)
{
loadConfiguration(); // load default configuration files, if present
ServerApplication::initialize(self);
}
void Gradido_LoginServer::uninitialize()
{
ServerApplication::uninitialize();
}
void Gradido_LoginServer::defineOptions(Poco::Util::OptionSet& options)
{
ServerApplication::defineOptions(options);
options.addOption(
Poco::Util::Option("help", "h", "display help information on command line arguments")
.required(false)
.repeatable(false));
}
void Gradido_LoginServer::handleOption(const std::string& name, const std::string& value)
{
ServerApplication::handleOption(name, value);
if (name == "help") _helpRequested = true;
}
void Gradido_LoginServer::displayHelp()
{
Poco::Util::HelpFormatter helpFormatter(options());
helpFormatter.setCommand(commandName());
helpFormatter.setUsage("OPTIONS");
helpFormatter.setHeader("A web server that shows how to work with HTML forms.");
helpFormatter.format(std::cout);
}
int Gradido_LoginServer::main(const std::vector<std::string>& args)
{
if (_helpRequested)
{
displayHelp();
}
else
{
unsigned short port = (unsigned short)config().getInt("HTTPServer.port", 9980);
// set-up a server socket
Poco::Net::ServerSocket svs(port);
// set-up a HTTPServer instance
Poco::Net::HTTPServer srv(new PageRequestHandlerFactory, svs, new Poco::Net::HTTPServerParams);
// start the HTTPServer
srv.start();
// wait for CTRL-C or kill
waitForTerminationRequest();
// Stop the HTTPServer
srv.stop();
}
return Application::EXIT_OK;
}

View File

@ -0,0 +1,39 @@
#ifndef Gradido_LoginServer_INCLUDED
#define Gradido_LoginServer_INCLUDED
#include "Poco/Util/ServerApplication.h"
class Gradido_LoginServer : public Poco::Util::ServerApplication
{
/// The main application class.
///
/// This class handles command-line arguments and
/// configuration files.
/// Start the Gradido_LoginServer executable with the help
/// option (/help on Windows, --help on Unix) for
/// the available command line options.
///
public:
Gradido_LoginServer();
~Gradido_LoginServer();
protected:
void initialize(Application& self);
void uninitialize();
void defineOptions(Poco::Util::OptionSet& options);
void handleOption(const std::string& name, const std::string& value);
void displayHelp();
int main(const std::vector<std::string>& args);
private:
bool _helpRequested;
};
#endif //Gradido_LoginServer_INCLUDED

View File

@ -0,0 +1,105 @@
#include "ConfigPage.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/Net/HTMLForm.h"
#include "Poco/DeflatingStream.h"
#line 4 "I:\\Code\\C++\\Eigene_Projekte\\Gradido_LoginServer\\src\\cpsp\\config.cpsp"
void ConfigPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
response.setChunkedTransferEncoding(true);
response.setContentType("text/html");
bool _compressResponse(request.hasToken("Accept-Encoding", "gzip"));
if (_compressResponse) response.set("Content-Encoding", "gzip");
Poco::Net::HTMLForm form(request, request.stream());
std::ostream& _responseStream = response.send();
Poco::DeflatingOutputStream _gzipStream(_responseStream, Poco::DeflatingStreamBuf::STREAM_GZIP, 1);
std::ostream& responseStream = _compressResponse ? _gzipStream : _responseStream;
responseStream << "\n";
responseStream << "<!DOCTYPE html>\n";
responseStream << "<html>\n";
responseStream << "<head>\n";
responseStream << "<meta charset=\"UTF-8\">\n";
responseStream << "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n";
responseStream << "<title>Gradido Login Server: Config</title>\n";
responseStream << "<!--<link rel=\"stylesheet\" type=\"text/css\" href=\"css/styles.min.css\">-->\n";
responseStream << "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://gradido2.dario-rekowski.de/css/styles.css\">\n";
responseStream << "</head>\n";
responseStream << "<body>\n";
responseStream << "<h1>Config</h1>\n";
responseStream << "<form method=\"POST\">\n";
responseStream << "\t<div class=\"grd_container\">\n";
responseStream << "\n";
responseStream << "\t\t<fieldset class=\"grd_container_small\">\n";
responseStream << "\t\t\t<legend>Server Admin Key</legend>\n";
responseStream << "\t\t\t<p>Möchtest du einen neuen Server Key generieren oder einen existierenden verwenden?</p>\n";
responseStream << "\t\t\t<p>Wenn du bereits einen besitzt kopiere bitte den Merksatz dafür in die Textarea.</p>\n";
responseStream << "\t\t\t<p class=\"grd_small\">\n";
responseStream << "\t\t\t\t<input id=\"server-admin-key-new-yes\" type=\"radio\" name=\"new-server-admin-key\" value=\"yes\" checked/>\n";
responseStream << "\t\t\t\t<label for=\"server-admin-key-new-yes\">Einen neuen generieren!</label>\n";
responseStream << "\t\t\t</p>\n";
responseStream << "\t\t\t<p class=\"grd_small\">\n";
responseStream << "\t\t\t\t<input id=\"server-admin-key-new-no\" type=\"radio\" name=\"new-server-admin-key\" value=\"no\"/>\n";
responseStream << "\t\t\t\t<label for=\"server-admin-key-new-no\">Einen existierenden verwenden!</label>\n";
responseStream << "\t\t\t</p>\n";
responseStream << "\t\t\t<textarea style=\"width:100%;height:100px\" name=\"server-admin-key-existing\"></textarea>\n";
responseStream << "\t\t</fieldset>\n";
responseStream << "\t\t<fieldset class=\"grd_container_small\">\n";
responseStream << "\t\t\t<legend>Login-Server (dieser Server)</legend>\n";
responseStream << "\t\t\t<p>Bitte gebe die Daten für diesen Server an. </p>\n";
responseStream << "\t\t\t<fieldset>\n";
responseStream << "\t\t\t\t<legend>Datenbank</legend>\n";
responseStream << "\t\t\t\t<div class=\"grd-input\">\n";
responseStream << "\t\t\t\t\t<label for=\"server-db-user\">Benutzernamen: </label>\n";
responseStream << "\t\t\t\t\t<input id=\"server-db-user\" type=\"text\" name=\"server-db-user\" value=\"root\">\n";
responseStream << "\t\t\t\t</div>\n";
responseStream << "\t\t\t\t<div class=\"grd-input\">\n";
responseStream << "\t\t\t\t\t<label for=\"server-db-pwd\">Passwort: </label>\n";
responseStream << "\t\t\t\t\t<input id=\"server-db-pwd\" type=\"password\" name=\"server-db-pwd\" value=\"\">\n";
responseStream << "\t\t\t\t</div>\n";
responseStream << "\t\t\t\t<div class=\"grd-input\">\n";
responseStream << "\t\t\t\t\t<label for=\"server-db-name\">Datenbank Name: </label>\n";
responseStream << "\t\t\t\t\t<input id=\"server-db-name\" name=\"server-db-name\" value=\"\">\n";
responseStream << "\t\t\t\t</div>\n";
responseStream << "\t\t\t</fieldset>\n";
responseStream << "\t\t\t<div class=\"grd-input\">\n";
responseStream << "\t\t\t\t<label for=\"server-domain\">Server Name (Domain)</label>\n";
responseStream << "\t\t\t\t<input id=\"server-domain\" name=\"server-domain\" type=\"text\">\n";
responseStream << "\t\t\t</div>\n";
responseStream << "\t\t</fieldset>\n";
responseStream << "\t\t<fieldset class=\"grd_container_small\">\n";
responseStream << "\t\t\t<legend>PHP-Server</legend>\n";
responseStream << "\t\t\t<p>Bitte gebe hier die Daten des php-Servers an.</p>\n";
responseStream << "\t\t\t<fieldset>\n";
responseStream << "\t\t\t\t<legend>Datenbank</legend>\n";
responseStream << "\t\t\t\t<div class=\"grd-input\">\n";
responseStream << "\t\t\t\t\t<label for=\"php-server-db-user\">Benutzernamen: </label>\n";
responseStream << "\t\t\t\t\t<input id=\"php-server-db-user\" type=\"text\" name=\"php-server-db-user\" value=\"root\">\n";
responseStream << "\t\t\t\t</div>\n";
responseStream << "\t\t\t\t<div class=\"grd-input\">\n";
responseStream << "\t\t\t\t\t<label for=\"php-server-db-pwd\">Passwort: </label>\n";
responseStream << "\t\t\t\t\t<input id=\"php-server-db-pwd\" type=\"password\" name=\"php-server-db-pwd\" value=\"\">\n";
responseStream << "\t\t\t\t</div>\n";
responseStream << "\t\t\t\t<div class=\"grd-input\">\n";
responseStream << "\t\t\t\t\t<label for=\"php-server-db-name\">Datenbank Name: </label>\n";
responseStream << "\t\t\t\t\t<input id=\"php-server-db-name\" name=\"php-server-db-name\" value=\"\">\n";
responseStream << "\t\t\t\t</div>\n";
responseStream << "\t\t\t</fieldset>\n";
responseStream << "\t\t\t<div class=\"grd-input\">\n";
responseStream << "\t\t\t\t<label for=\"php-server-url\">PHP-Server Url (mit Port)</label>\n";
responseStream << "\t\t\t\t<input id=\"php-server-url\" name=\"php-server-url\" type=\"text\">\n";
responseStream << "\t\t\t</div>\n";
responseStream << "\t\t</fieldset>\n";
responseStream << "\t\t<input class=\"grd_bn_succeed\" type=\"submit\" name=\"submit\" value=\"Absenden\">\n";
responseStream << "\t</div>\n";
responseStream << "</form>\n";
responseStream << "</body>\n";
responseStream << "</html>\n";
if (_compressResponse) _gzipStream.close();
}

View File

@ -0,0 +1,15 @@
#ifndef ConfigPage_INCLUDED
#define ConfigPage_INCLUDED
#include "Poco/Net/HTTPRequestHandler.h"
class ConfigPage: public Poco::Net::HTTPRequestHandler
{
public:
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response);
};
#endif // ConfigPage_INCLUDED

View File

@ -0,0 +1,41 @@
#include "HandleFileRequest.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h"
#include "Poco/DeflatingStream.h"
#include "Poco/FileStream.h"
void HandleFileRequest::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
response.setChunkedTransferEncoding(true);
std::string uri = request.getURI();
// check endung
size_t last_point = uri.find_last_of('.');
std::string endung = uri.substr(last_point+1);
std::string mediaType;
//printf("endung: %s\n", endung.data());
if (endung == "css") {
mediaType = "text/css";
}
else if (endung == "js") {
mediaType = "text/javascript";
}
else if (endung == "ico") {
mediaType = "image/x-icon";
}
std::string path = "data" + uri;
printf("file path: %s\n", path.data());
response.sendFile(path, mediaType);
/*
bool _compressResponse(request.hasToken("Accept-Encoding", "gzip"));
if (_compressResponse) response.set("Content-Encoding", "gzip");
std::ostream& _responseStream = response.send();
Poco::DeflatingOutputStream _gzipStream(_responseStream, Poco::DeflatingStreamBuf::STREAM_GZIP, 1);
std::ostream& responseStream = _compressResponse ? _gzipStream : _responseStream;
responseStream << new Poco::FileInputStream("./data/" + uri);
if (_compressResponse) _gzipStream.close();
*/
}

View File

@ -0,0 +1,15 @@
#ifndef HandleFileRequest_INCLUDED
#define HandleFileRequest_INCLUDED
#include "Poco/Net/HTTPRequestHandler.h"
class HandleFileRequest : public Poco::Net::HTTPRequestHandler
{
public:
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response);
};
#endif // HandleFileRequest_INCLUDED

View File

@ -0,0 +1,31 @@
#include "PageRequestHandlerFactory.h"
#include "Poco/Net/HTTPServerRequest.h"
#include "ConfigPage.h"
#include "LoginPage.h"
#include "RegisterPage.h"
#include "HandleFileRequest.h"
PageRequestHandlerFactory::PageRequestHandlerFactory()
{
}
Poco::Net::HTTPRequestHandler* PageRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest& request)
{
printf("request uri: %s\n", request.getURI().data());
std::string uri = request.getURI();
if (uri == "/") {
return new ConfigPage;
}
else if (uri == "/login") {
return new LoginPage;
}
else if (uri == "/register") {
return new RegisterPage;
}
return new HandleFileRequest;
//return new PageRequestHandlerFactory;
}

View File

@ -0,0 +1,19 @@
#ifndef __DR_PAGE_REQUEST_HANDLER_FACTORY_H
#define __DR_PAGE_REQUEST_HANDLER_FACTORY_H
#include "Poco/Net/HTTPRequestHandlerFactory.h"
#define HTTP_PAGES_COUNT 1
class PageRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory
{
public:
PageRequestHandlerFactory();
Poco::Net::HTTPRequestHandler* createRequestHandler(const Poco::Net::HTTPServerRequest& request);
protected:
};
#endif // __DR_PAGE_REQUEST_HANDLER_FACTORY_H

View File

@ -0,0 +1 @@
#include "ServerConfig.h"

View File

@ -1,16 +1,14 @@
#include <stdio.h>
#include "Gradido_LoginServer.h"
#include <sodium.h>
int main(int argc, char* argv[]) {
printf("hallo Welt\n");
int main(int argc, char** argv)
{
if (sodium_init() < 0) {
/* panic! the library couldn't be initialized, it is not safe to use */
}
else {
printf("sodium initalized\n");
printf("error initing sodium, early exit\n");
return -1;
}
return 42;
}
Gradido_LoginServer app;
return app.run(argc, argv);
}

85
src/cpsp/config.cpsp Normal file
View File

@ -0,0 +1,85 @@
<%@ page class="ConfigPage" %>
<%@ page form="true" %>
<%@ page compressed="true" %>
<%!
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gradido Login Server: Config</title>
<!--<link rel="stylesheet" type="text/css" href="css/styles.min.css">-->
<link rel="stylesheet" type="text/css" href="https://gradido2.dario-rekowski.de/css/styles.css">
</head>
<body>
<h1>Config</h1>
<form method="POST">
<div class="grd_container">
<fieldset class="grd_container_small">
<legend>Server Admin Key</legend>
<p>Möchtest du einen neuen Server Key generieren oder einen existierenden verwenden?</p>
<p>Wenn du bereits einen besitzt kopiere bitte den Merksatz dafür in die Textarea.</p>
<p class="grd_small">
<input id="server-admin-key-new-yes" type="radio" name="new-server-admin-key" value="yes" checked/>
<label for="server-admin-key-new-yes">Einen neuen generieren!</label>
</p>
<p class="grd_small">
<input id="server-admin-key-new-no" type="radio" name="new-server-admin-key" value="no"/>
<label for="server-admin-key-new-no">Einen existierenden verwenden!</label>
</p>
<textarea style="width:100%;height:100px" name="server-admin-key-existing"></textarea>
</fieldset>
<fieldset class="grd_container_small">
<legend>Login-Server (dieser Server)</legend>
<p>Bitte gebe die Daten für diesen Server an. </p>
<fieldset>
<legend>Datenbank</legend>
<div class="grd-input">
<label for="server-db-user">Benutzernamen: </label>
<input id="server-db-user" type="text" name="server-db-user" value="root">
</div>
<div class="grd-input">
<label for="server-db-pwd">Passwort: </label>
<input id="server-db-pwd" type="password" name="server-db-pwd" value="">
</div>
<div class="grd-input">
<label for="server-db-name">Datenbank Name: </label>
<input id="server-db-name" name="server-db-name" value="">
</div>
</fieldset>
<div class="grd-input">
<label for="server-domain">Server Name (Domain)</label>
<input id="server-domain" name="server-domain" type="text">
</div>
</fieldset>
<fieldset class="grd_container_small">
<legend>PHP-Server</legend>
<p>Bitte gebe hier die Daten des php-Servers an.</p>
<fieldset>
<legend>Datenbank</legend>
<div class="grd-input">
<label for="php-server-db-user">Benutzernamen: </label>
<input id="php-server-db-user" type="text" name="php-server-db-user" value="root">
</div>
<div class="grd-input">
<label for="php-server-db-pwd">Passwort: </label>
<input id="php-server-db-pwd" type="password" name="php-server-db-pwd" value="">
</div>
<div class="grd-input">
<label for="php-server-db-name">Datenbank Name: </label>
<input id="php-server-db-name" name="php-server-db-name" value="">
</div>
</fieldset>
<div class="grd-input">
<label for="php-server-url">PHP-Server Url (mit Port)</label>
<input id="php-server-url" name="php-server-url" type="text">
</div>
</fieldset>
<input class="grd_bn_succeed" type="submit" name="submit" value="Absenden">
</div>
</form>
</body>
</html>

39
src/cpsp/login.cpsp Normal file
View File

@ -0,0 +1,39 @@
<%@ page class="LoginPage" %>
<%@ page form="true" %>
<%@ page compressed="true" %>
<%!
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gradido Login Server: Login</title>
<!--<link rel="stylesheet" type="text/css" href="css/styles.min.css">-->
<link rel="stylesheet" type="text/css" href="https://gradido2.dario-rekowski.de/css/styles.css">
</head>
<body>
<h1>Login</h1>
<form method="POST">
<div class="grd_container">
<fieldset class="grd_container_small">
<legend>Login</legend>
<p>Bitte gebe deine Zugangsdaten ein um dich einzuloggen.</p>
<p class="grd_small">
<label for="login-username">Benutzernamen</label>
<input id="login-username" type="text" name="login-username"/>
</p>
<p class="grd_small">
<label for="login-password">Passwort</label>
<input id="login-password" type="password" name="login-password"/>
</p>
</fieldset>
<input class="grd_bn_succeed" type="submit" name="submit" value="Einloggen">
<p>Du hast noch keinen Account? Dann folge dem Link um dir einen anzulegen</p>
<a href="/register">Neuen Account anlegen</a>
</div>
</form>
</body>
</html>

46
src/cpsp/register.cpsp Normal file
View File

@ -0,0 +1,46 @@
<%@ page class="RegisterPage" %>
<%@ page form="true" %>
<%@ page compressed="true" %>
<%!
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gradido Login Server: Register</title>
<!--<link rel="stylesheet" type="text/css" href="css/styles.min.css">-->
<link rel="stylesheet" type="text/css" href="https://gradido2.dario-rekowski.de/css/styles.css">
</head>
<body>
<h1>Login</h1>
<form method="POST">
<div class="grd_container">
<fieldset class="grd_container_small">
<legend>Account anlegen</legend>
<p>Bitte gebe deine Daten um einen Account anzulegen</p>
<p class="grd_small">
<label for="register-username">Benutzernamen</label>
<input id="register-username" type="text" name="register-username"/>
</p>
<p class="grd_small">
<label for="register-password">Passwort</label>
<input id="register-password" type="password" name="register-password"/>
</p>
<p>Hast du bereits schonmal ein Gradido Konto besessen?</p>
<p class="grd_small">
<input id="register-key-new-yes" type="radio" name="register-key" value="yes" checked/>
<label for="register-key-new-yes">Nein, bitte ein neues erstellen!</label>
</p>
<p class="grd_small">
<input id="register-key-new-no" type="radio" name="register-key" value="no"/>
<label for="register-key-new-no">Ja, bitte wiederherstellen!</label>
</p>
<textarea style="width:100%;height:100px" name="register-key-existing"></textarea>
</fieldset>
<input class="grd_bn_succeed" type="submit" name="submit" value="Einloggen">
</div>
</form>
</body>
</html>