Commit 26ef70d4 authored by jan.koester's avatar jan.koester
Browse files

test

parent 0e33f070
Loading
Loading
Loading
Loading
+82 −0
Changes for data/index.html: 82 added lines, 0 removed lines.
Original line number Diff line number Diff line
<!DOCTYPE html>
<html lang="en">
    <head>
        <style>
            body {
                background:#222528;
                color:#ffffff;
                margin:0;
                padding:0;
                min-width:1024px;
            }

            #header {
                width:100vw;
                height:4em;
                background: #2F363B;
                padding:0;
                min-width:1024px;
            }

            #header .head {
                padding:2vh;
                margin:0;
                font-size:2em;
                padding:1em;
            }

            #maintable{
                display: table;
                min-width:700px;
                min-height:100vh;
            }

            #navbar {
                display: table-cell;
                min-width:150px;
                width:5vw;
                background:#2F363B;
                font-size:1em;
            }

            #navbar li {
                list-style:none;
            }


            #navbar a {
                color:#ffffff;
                text-decoration:none;
            }

            #navbar a:visited {
                color:#ffffff;
            }

            #content{
                display: table-cell;
                border:solid 10px #222528;
                width:100%;
                background:#2F363B;
            }
        </style>
    </head>
    <body>
        <div id="header">
            <span class="head" >AuthDB</span>
        </div>
        <div id="maintable">
            <div id="navbar">
                <ul>
                    <li><a href="#" >Domains</a></li>
                    <li><a href="/admin/listusers" >Users</a></li>
                    <li><a href="#" >Groups</a></li>
                    <li><a href="#" >Clients</a></li>
                    <li><a href="#" >Policies</a></li>
                    <li><a href="#" >Sessions</a></li>
                </ul>
            </div>
            <div id="content">
            </div>
        </div>
    </body>
</html>
+75 −32
Changes for src/authdb.cpp: 75 added lines, 32 removed lines.
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@
#include "user.h"

namespace authdb {

    bool initalized=true;

    class AuthDB : public libhttppp::HttpEvent{
    public:
        AuthDB(authdb::AuthBackend &backend,netplus::socket *ssock) : HttpEvent(ssock), _Backend(backend){
@@ -50,13 +53,26 @@ namespace authdb {
        void listUsers(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
            _Backend.lock();

            authdb::AuthData *cur=new AuthData;;
            authdb::AuthData *cur=new AuthData;

            size_t rd=sizeof(authdb::AuthHeader),end=_Backend.end();

            _Backend.setPos(rd);

            std::string userlist="UserList:\r\n";


            libhtmlpp::HtmlElement root;
            libhtmlpp::HtmlPage page;

            page.loadFile(root,"../data/index.html");

            libhtmlpp::HtmlString userlist,out;

            libhtmlpp::HtmlElement *content=root.getElementbyID("content");



            userlist <<"<div><p>UserList:</p>";

            while(rd<end){
                std::cout << rd << std::endl;
@@ -80,7 +96,7 @@ namespace authdb {
                            userlist+=": ";
                            std::copy(curec->Data->data,curec->Data->data+curec->Data->datasize,
                                      std::back_inserter(userlist));
                            userlist+= "\r\n";
                            userlist+= "<br>";
                        }
                    }
                }
@@ -90,10 +106,13 @@ namespace authdb {

            _Backend.unlock();

            content->insertChild(userlist.parse());

            libhtmlpp::print(&root,out,true);

            libhttppp::HttpResponse rep;
            rep.setContentType("text/txt");
            rep.setContentLength(userlist.length());
            rep.send(curreq,userlist.c_str(),userlist.length());
            rep.setContentType("text/html");
            rep.send(curreq,out.c_str(),out.size());
        }

        void createUser(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
@@ -128,7 +147,7 @@ namespace authdb {
                            udat.setLastName(tmp.data());
                        }else if(strcmp(curdispo->getValue(),"mail")==0){
                            udat.setMail(tmp.data());
                        }else if(strcmp(curdispo->getValue(),"avatar")==0){
                        }else if(strcmp(curdispo->getValue(),"avatar")==0 && !curformdat->Value.empty()){
                            udat.setAvatar(curformdat->Value);
                        }
                    }
@@ -139,32 +158,34 @@ namespace authdb {
                std::cout << "user created!" << std::endl;
            }

            libhtmlpp::HtmlElement *root;
            libhtmlpp::HtmlElement root;
            libhtmlpp::HtmlPage page;

            libhtmlpp::HtmlString content,out;

            content << "<!DOCTYPE HTML>\r\n"
                    << "<html>"
                    << "<body>"
                    << "<form method=\"post\" enctype=\"multipart/form-data\"><ul>"
                    << "<li><label for=\"username\">username:</label>"
                    << "<input type=\"text\" name=\"username\"></li>"
                    << "<li><label for=\"firstname\">firstname:</label>"
                    << "<input type=\"text\" name=\"firstname\"></li>"
                    << "<li><label for=\"lastname\">lastname:</label>"
                    << "<input type=\"text\" name=\"lastname\"></li>"
                    << "<li><label for=\"mail\">mail:</label>"
                    << "<input type=\"text\" name=\"mail\"></li>"
                    << "<li><label for=\"avatar\">ProfilBild:</label>"
                    << "<input type=\"file\" name=\"avatar\"></li>"
                    << "<li><input type=\"submit\"></li>"
                    << "<ul></form>"
                    << "</body>";

            root=(libhtmlpp::HtmlElement*)content.parse();

            libhtmlpp::print(root,out,true);
            page.loadFile(root,"../data/index.html");

            libhtmlpp::HtmlString form,out;

            form  << "<form method=\"post\" enctype=\"multipart/form-data\">"
                  << "<table>"
                  << "<tr><td><label for=\"username\">username:</label></td>"
                  << "<td><input type=\"text\" name=\"username\"></td></tr>"
                  << "<tr><td><label for=\"firstname\">firstname:</label></td>"
                  << "<td><input type=\"text\" name=\"firstname\"></td></tr>"
                  << "<tr><td><label for=\"lastname\">lastname:</label></td>"
                  << "<td><input type=\"text\" name=\"lastname\"></td></tr>"
                  << "<tr><td><label for=\"mail\">mail:</label></td>"
                  << "<td><input type=\"text\" name=\"mail\"></td></tr>"
                  << "<tr><td><label for=\"avatar\">ProfilBild:</label></td>"
                  << "<td><input type=\"file\" name=\"avatar\"></td></tr>"
                  << "<tr><td></td><td><input type=\"submit\"></td></tr>"
                  << "</table>"
                  << "</form";

            libhtmlpp::HtmlElement *content=root.getElementbyID("content");

            content->insertChild(form.parse());

            libhtmlpp::print(&root,out,true);

            rep.setContentType("text/html");
            rep.setContentLength(out.size());
@@ -176,12 +197,32 @@ namespace authdb {
                listUsers(curreq,tid,args);
            }else if(strncmp(curreq->getRequestURL(),"/admin/createuser",17)==0){
                createUser(curreq,tid,args);
            }else{
                libhtmlpp::HtmlElement root;
                libhtmlpp::HtmlPage page;
                page.loadFile(root,"../data/index.html");
                libhtmlpp::HtmlString out;
                libhtmlpp::print(&root,out,true);

                libhttppp::HttpResponse rep;
                rep.setContentType("text/html");
                rep.setContentLength(out.size());
                rep.send(curreq,out.c_str(),out.size());
            }
        }

        void RequestEvent(libhttppp::HttpRequest *curreq, const int tid, ULONG_PTR args){
            if(strncmp(curreq->getRequestURL(),"/admin",6)==0){
                AdminController(curreq,tid,args);
            }else if(strncmp(curreq->getRequestURL(),"/api",4)==0){

            }else{
                libhttppp::HttpResponse rep;
                rep.setState(HTTP307);
                rep.setVersion(HTTPVERSION(1.1));
                rep.setHeaderData("Location")->push_back("/admin");
                rep.setContentType("text/html");
                rep.send(curreq,nullptr,0);
            }
        };
    private:
@@ -211,6 +252,8 @@ namespace authdb {
    AuthDataRecord::AuthDataRecord(){
         Data = new AuthData;
         memset((void*)Data,0,sizeof(AuthData));
         Data->start=0xFE;
         Data->end=0xFF;
        _next=nullptr;
    }

@@ -284,7 +327,7 @@ int main(int argc, char *argv[]){
                                );
    try {
        if(backend.end()<=sizeof(authdb::AuthHeader)){

            authdb::initalized=false;
        }

        libhttppp::HttpD httpd(
+5 −4
Changes for src/authdb.h: 5 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -33,21 +33,22 @@

namespace authdb {
    struct AuthHeader{
        const  short start=0xFE;
        unsigned char start;
        char   domain[255];
        size_t Version;
        size_t Revesion;
        const  short end=0xFF;
        unsigned char end;
    };

    struct AuthData {
        const  short start=0xFE;
        unsigned char start;
        char   uuid[255];
        int    type;
        int    storage;
        char   fieldname[255];
        size_t datasize = 0;
        char  *data;
        const  short end=0xFF;
        unsigned char end;
    };

    int searchValue(authdb::AuthBackend &backend,const char*fieldname,const char *value);

src/types.h

0 → 100644
+47 −0
Changes for src/types.h: 47 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2025, Jan Koester jan.koester@gmx.net
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 * Neither the name of the <organization> nor the
 *      names of its contributors may be used to endorse or promote products
 *      derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

#pragma once

namespace authdb{

    enum DataType {
        EmptyData = 0,
        UserData = 1,
        DomainData = 2,
        GroupData = 3,
        PolicyData = 4,
        ClientData = 5
    };

    enum StorageType {
        EmptyStorage=0,
        TextStorage=1,
        BinaryStorage=2
    };

};
+21 −9
Changes for src/user.cpp: 21 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

#include "types.h"
#include "user.h"

authdb::UserData::UserData(uuid_t id){
@@ -74,7 +75,9 @@ void authdb::UserData::setFirstName(const char* src){
            }
        }
    }
    target->Data->type=1;

    target->Data->type=DataType::UserData;
    target->Data->storage=StorageType::TextStorage;

    memcpy(target->Data->uuid,uid,strlen(uid)+1);
    snprintf(target->Data->fieldname,255,"%s","firstname");
@@ -113,7 +116,9 @@ void authdb::UserData::setLastName(const char* src){
            }
        }
    }
    target->Data->type=1;

    target->Data->type=DataType::UserData;
    target->Data->storage=StorageType::TextStorage;

    memcpy(target->Data->uuid,uid,strlen(uid)+1);
    snprintf(target->Data->fieldname,255,"%s","lastname");
@@ -152,7 +157,9 @@ void authdb::UserData::setMail(const char* src){
            }
        }
    }
    target->Data->type=1;

    target->Data->type=DataType::UserData;
    target->Data->storage=StorageType::TextStorage;

    memcpy(target->Data->uuid,uid,strlen(uid)+1);
    snprintf(target->Data->fieldname,255,"%s","mail");
@@ -191,7 +198,9 @@ void authdb::UserData::setPwHash(const char* src){
            }
        }
    }
    target->Data->type=1;

    target->Data->type=DataType::UserData;
    target->Data->storage=StorageType::TextStorage;

    memcpy(target->Data->uuid,uid,strlen(uid)+1);
    snprintf(target->Data->fieldname,255,"%s","password");
@@ -231,7 +240,9 @@ void authdb::UserData::setUserName(const char* src){
        }
    }

    target->Data->type=1;
    target->Data->type=DataType::UserData;
    target->Data->storage=StorageType::TextStorage;

    memcpy(target->Data->uuid,uid,strlen(uid)+1);
    snprintf(target->Data->fieldname,255,"%s","username");
    target->Data->datasize=strlen(src);
@@ -270,7 +281,8 @@ void authdb::UserData::setAvatar(const std::vector<char>& src){
        }
    }

    target->Data->type=1;
    target->Data->type=DataType::UserData;
    target->Data->storage=StorageType::BinaryStorage;

    memcpy(target->Data->uuid,uid,strlen(uid)+1);
    snprintf(target->Data->fieldname,255,"%s","avatar");
@@ -282,7 +294,7 @@ void authdb::UserData::setAvatar(const std::vector<char>& src){
}

#include<iostream>
void authdb::User::create(AuthBackend &backend,UserData* dat){
void authdb::User::create(AuthBackend &backend,class UserData* dat){
    authdb::AuthData *cur=new AuthData;

    int rd=sizeof(authdb::AuthHeader),end=backend.end();
@@ -318,13 +330,13 @@ void authdb::User::create(AuthBackend &backend,UserData* dat){

}

void authdb::User::edit(AuthBackend &backend, uuid_t uid,UserData& dat, size_t pos){
void authdb::User::edit(AuthBackend &backend, uuid_t uid,class UserData& dat, size_t pos){
}

void authdb::User::remove(AuthBackend &backend, uuid_t uid){
}

void authdb::User::info(AuthBackend &backend, uuid_t uid,UserData& dat, size_t pos)
void authdb::User::info(AuthBackend &backend, uuid_t uid,class UserData& dat, size_t pos)
{
}

Loading