Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
authdb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jan.koester
authdb
Commits
f3d20271
Commit
f3d20271
authored
5 days ago
by
jan.koester
Browse files
Options
Downloads
Patches
Plain Diff
fninished
parent
07eba8b5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#108
failed
5 days ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Dockerfile
+1
-0
1 addition, 0 deletions
Dockerfile
src/authdb.cpp
+87
-106
87 additions, 106 deletions
src/authdb.cpp
with
88 additions
and
106 deletions
Dockerfile
+
1
−
0
View file @
f3d20271
...
@@ -46,5 +46,6 @@ COPY --from=build /usr/local/lib /usr/local/lib
...
@@ -46,5 +46,6 @@ COPY --from=build /usr/local/lib /usr/local/lib
COPY
data/docker-config.yaml /etc/authdb/config.yaml
COPY
data/docker-config.yaml /etc/authdb/config.yaml
USER
authdb
CMD
["authdb","-c","yaml://etc/authdb/config.yaml"]
CMD
["authdb","-c","yaml://etc/authdb/config.yaml"]
This diff is collapsed.
Click to expand it.
src/authdb.cpp
+
87
−
106
View file @
f3d20271
...
@@ -75,7 +75,94 @@ namespace authdb {
...
@@ -75,7 +75,94 @@ namespace authdb {
cssfs
.
read
(
_AuthCss
.
data
(),
csssize
);
cssfs
.
read
(
_AuthCss
.
data
(),
csssize
);
};
};
void
WizzardEvent
(
libhttppp
::
HttpRequest
*
curreq
,
const
int
tid
,
ULONG_PTR
args
){
std
::
lock_guard
<
std
::
mutex
>
wlock
(
g_wizzard
);
libhttppp
::
HttpForm
form
;
form
.
parse
(
curreq
);
std
::
string
username
,
password
,
pwhash
;
for
(
libhttppp
::
HttpForm
::
UrlcodedForm
::
Data
*
curformdat
=
form
.
UrlFormData
.
getFormData
();
curformdat
;
curformdat
=
curformdat
->
nextData
()){
if
(
strcmp
(
curformdat
->
getKey
(),
"username"
)
==
0
)
username
=
curformdat
->
getValue
();
else
if
(
strcmp
(
curformdat
->
getKey
(),
"password"
)
==
0
)
password
=
curformdat
->
getValue
();
}
if
(
!
password
.
empty
()
&&
!
username
.
empty
()){
sha512
hash
;
hash
.
hash
(
password
,
pwhash
);
authdb
::
User
user
;
uuid_t
adminid
,
admingid
;
uuid_generate
(
adminid
);
uuid_generate
(
admingid
);
class
authdb
::
UserData
udat
(
adminid
);
udat
.
setUserName
(
username
.
c_str
());
authdb
::
sha512
sha
;
sha
.
hash
(
password
,
pwhash
);
udat
.
setPwHash
(
pwhash
.
c_str
());
user
.
create
(
_AdminBackend
,
&
udat
);
authdb
::
Group
group
;
class
authdb
::
GroupData
gdat
(
admingid
);
gdat
.
setName
(
"SuperAdmin"
);
authdb
::
GroupData
::
MemberUids
muid
;
muid
.
count
=
1
;
muid
.
uid
=&
adminid
;
gdat
.
addMember
(
muid
);
group
.
create
(
_AdminBackend
,
&
gdat
);
libhttppp
::
HTTPException
exp
;
exp
[
999
]
<<
"wizzard finished"
;
throw
exp
;
}
libhtmlpp
::
HtmlElement
index
;
libhtmlpp
::
HtmlPage
page
;
page
.
loadFile
(
index
,
GETDATA
(
wizzard
.
html
));
libhttppp
::
HttpResponse
rep
;
libhtmlpp
::
HtmlString
sendat
;
libhtmlpp
::
print
((
libhtmlpp
::
Element
*
)
&
index
,
sendat
,
false
);
rep
.
setState
(
HTTP200
);
rep
.
setVersion
(
HTTPVERSION
(
1.1
));
rep
.
setContentType
(
"text/html"
);
rep
.
send
(
curreq
,
sendat
.
c_str
(),
sendat
.
size
());
}
void
RequestEvent
(
libhttppp
::
HttpRequest
*
curreq
,
const
int
tid
,
ULONG_PTR
args
){
void
RequestEvent
(
libhttppp
::
HttpRequest
*
curreq
,
const
int
tid
,
ULONG_PTR
args
){
if
(
_AdminBackend
.
end
()
<=
sizeof
(
authdb
::
AuthHeader
)){
try
{
WizzardEvent
(
curreq
,
tid
,
args
);
return
;
}
catch
(
libhttppp
::
HTTPException
&
e
){
if
(
e
.
getErrorType
()
!=
999
)
throw
e
;
}
}
if
(
strncmp
(
"/settings"
,
curreq
->
getRequestURL
(),
9
)
==
0
){
if
(
strncmp
(
"/settings"
,
curreq
->
getRequestURL
(),
9
)
==
0
){
_AdminBackend
.
lock
();
_AdminBackend
.
lock
();
try
{
try
{
...
@@ -446,99 +533,6 @@ VALUEFOUND:
...
@@ -446,99 +533,6 @@ VALUEFOUND:
DomainBackend
::~
DomainBackend
(){
DomainBackend
::~
DomainBackend
(){
delete
_domainbck
;
delete
_domainbck
;
}
}
class
AuthWizzard
:
public
libhttppp
::
HttpEvent
{
public:
AuthWizzard
(
netplus
::
socket
*
ssock
)
:
HttpEvent
(
ssock
){
_Page
.
loadFile
(
_Index
,
GETDATA
(
wizzard
.
html
));
}
void
RequestEvent
(
libhttppp
::
HttpRequest
*
curreq
,
const
int
tid
,
ULONG_PTR
args
){
std
::
lock_guard
<
std
::
mutex
>
wlock
(
g_wizzard
);
AuthBackend
*
backend
=
(
AuthBackend
*
)
args
;
if
(
backend
->
end
()
>
sizeof
(
authdb
::
AuthHeader
)){
libhttppp
::
HTTPException
exp
;
exp
[
999
]
<<
"wizzard already done!"
;
throw
exp
;
}
libhttppp
::
HttpForm
form
;
form
.
parse
(
curreq
);
std
::
string
username
,
password
,
pwhash
;
for
(
libhttppp
::
HttpForm
::
UrlcodedForm
::
Data
*
curformdat
=
form
.
UrlFormData
.
getFormData
();
curformdat
;
curformdat
=
curformdat
->
nextData
()){
if
(
strcmp
(
curformdat
->
getKey
(),
"username"
)
==
0
)
username
=
curformdat
->
getValue
();
else
if
(
strcmp
(
curformdat
->
getKey
(),
"password"
)
==
0
)
password
=
curformdat
->
getValue
();
}
if
(
!
password
.
empty
()
&&
!
username
.
empty
()){
sha512
hash
;
hash
.
hash
(
password
,
pwhash
);
authdb
::
User
user
;
uuid_t
adminid
,
admingid
;
uuid_generate
(
adminid
);
uuid_generate
(
admingid
);
class
authdb
::
UserData
udat
(
adminid
);
udat
.
setUserName
(
username
.
c_str
());
authdb
::
sha512
sha
;
sha
.
hash
(
password
,
pwhash
);
udat
.
setPwHash
(
pwhash
.
c_str
());
user
.
create
(
*
backend
,
&
udat
);
authdb
::
Group
group
;
class
authdb
::
GroupData
gdat
(
admingid
);
gdat
.
setName
(
"SuperAdmin"
);
authdb
::
GroupData
::
MemberUids
muid
;
muid
.
count
=
1
;
muid
.
uid
=&
adminid
;
gdat
.
addMember
(
muid
);
group
.
create
(
*
backend
,
&
gdat
);
libhttppp
::
HTTPException
exp
;
exp
[
999
]
<<
"wizzard finished"
;
throw
exp
;
}
libhtmlpp
::
HtmlElement
index
=
_Index
;
libhttppp
::
HttpResponse
rep
;
libhtmlpp
::
HtmlString
sendat
;
libhtmlpp
::
print
((
libhtmlpp
::
Element
*
)
&
index
,
sendat
,
false
);
rep
.
setState
(
HTTP200
);
rep
.
setVersion
(
HTTPVERSION
(
1.1
));
rep
.
setContentType
(
"text/html"
);
rep
.
send
(
curreq
,
sendat
.
c_str
(),
sendat
.
size
());
}
private
:
libhtmlpp
::
HtmlPage
_Page
;
libhtmlpp
::
HtmlElement
_Index
;;
};
};
};
int
main
(
int
argc
,
char
*
argv
[]){
int
main
(
int
argc
,
char
*
argv
[]){
...
@@ -569,19 +563,6 @@ int main(int argc, char *argv[]){
...
@@ -569,19 +563,6 @@ int main(int argc, char *argv[]){
nullptr
nullptr
);
);
if
(
backend
.
end
()
<=
sizeof
(
authdb
::
AuthHeader
)){
try
{
authdb
::
AuthWizzard
wizzard
(
httpd
.
getServerSocket
());
wizzard
.
threads
=
1
;
wizzard
.
runEventloop
((
ULONG_PTR
)
&
backend
);
}
catch
(
libhttppp
::
HTTPException
&
e
){
if
(
e
.
getErrorType
()
==
999
)
std
::
cout
<<
e
.
what
()
<<
std
::
endl
;
else
throw
e
;
}
}
authdb
::
AuthDB
authdb
(
backend
,
httpd
.
getServerSocket
());
authdb
::
AuthDB
authdb
(
backend
,
httpd
.
getServerSocket
());
// authdb.threads=2;
// authdb.threads=2;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment