Merge pull request #112 from gradido/fix_lineendings

Fix lineendings
This commit is contained in:
einhornimmond 2021-03-31 12:28:17 +02:00 committed by GitHub
commit 242dfa7154
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
69 changed files with 8848 additions and 8669 deletions

View File

@ -1,17 +1,17 @@
FROM phpdockerio/php74-fpm FROM phpdockerio/php74-fpm
# install php fpm # install php fpm
RUN apt-get update \ RUN apt-get update \
&& apt-get -y --no-install-recommends install curl unzip php7.4-curl php7.4-fpm php7.4-mbstring php7.4-intl php7.4-xml php7.4-pdo php7.4-mysql \ && apt-get -y --no-install-recommends install curl unzip php7.4-curl php7.4-fpm php7.4-mbstring php7.4-intl php7.4-xml php7.4-pdo php7.4-mysql \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
WORKDIR /var/www/cakephp WORKDIR /var/www/cakephp
RUN mkdir logs && mkdir tmp && chmod 777 logs && chmod 777 tmp RUN mkdir logs && mkdir tmp && chmod 777 logs && chmod 777 tmp
COPY ./community_server/ . COPY ./community_server/ .
COPY ./configs/community_server/app.php ./config/ COPY ./configs/community_server/app.php ./config/
RUN composer update RUN composer update
RUN composer dump-autoload RUN composer dump-autoload

View File

@ -1,25 +1,25 @@
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string; fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method; fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri; fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme; fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty; fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port; fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name; fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect # PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200; fastcgi_param REDIRECT_STATUS 200;

View File

@ -1,88 +1,88 @@
types { types {
text/html html htm shtml; text/html html htm shtml;
text/css css; text/css css;
text/xml xml; text/xml xml;
image/gif gif; image/gif gif;
image/jpeg jpeg jpg; image/jpeg jpeg jpg;
application/javascript js; application/javascript js;
application/atom+xml atom; application/atom+xml atom;
application/rss+xml rss; application/rss+xml rss;
text/mathml mml; text/mathml mml;
text/plain txt; text/plain txt;
text/vnd.sun.j2me.app-descriptor jad; text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml; text/vnd.wap.wml wml;
text/x-component htc; text/x-component htc;
image/png png; image/png png;
image/tiff tif tiff; image/tiff tif tiff;
image/vnd.wap.wbmp wbmp; image/vnd.wap.wbmp wbmp;
image/x-icon ico; image/x-icon ico;
image/x-jng jng; image/x-jng jng;
image/x-ms-bmp bmp; image/x-ms-bmp bmp;
image/svg+xml svg svgz; image/svg+xml svg svgz;
image/webp webp; image/webp webp;
application/font-woff woff; application/font-woff woff;
application/java-archive jar war ear; application/java-archive jar war ear;
application/json json; application/json json;
application/mac-binhex40 hqx; application/mac-binhex40 hqx;
application/msword doc; application/msword doc;
application/pdf pdf; application/pdf pdf;
application/postscript ps eps ai; application/postscript ps eps ai;
application/rtf rtf; application/rtf rtf;
application/vnd.apple.mpegurl m3u8; application/vnd.apple.mpegurl m3u8;
application/vnd.ms-excel xls; application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot; application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt; application/vnd.ms-powerpoint ppt;
application/vnd.wap.wmlc wmlc; application/vnd.wap.wmlc wmlc;
application/vnd.google-earth.kml+xml kml; application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz; application/vnd.google-earth.kmz kmz;
application/x-7z-compressed 7z; application/x-7z-compressed 7z;
application/x-cocoa cco; application/x-cocoa cco;
application/x-java-archive-diff jardiff; application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp; application/x-java-jnlp-file jnlp;
application/x-makeself run; application/x-makeself run;
application/x-perl pl pm; application/x-perl pl pm;
application/x-pilot prc pdb; application/x-pilot prc pdb;
application/x-rar-compressed rar; application/x-rar-compressed rar;
application/x-redhat-package-manager rpm; application/x-redhat-package-manager rpm;
application/x-sea sea; application/x-sea sea;
application/x-shockwave-flash swf; application/x-shockwave-flash swf;
application/x-stuffit sit; application/x-stuffit sit;
application/x-tcl tcl tk; application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt; application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi; application/x-xpinstall xpi;
application/xhtml+xml xhtml; application/xhtml+xml xhtml;
application/xspf+xml xspf; application/xspf+xml xspf;
application/zip zip; application/zip zip;
application/octet-stream bin exe dll; application/octet-stream bin exe dll;
application/octet-stream deb; application/octet-stream deb;
application/octet-stream dmg; application/octet-stream dmg;
application/octet-stream iso img; application/octet-stream iso img;
application/octet-stream msi msp msm; application/octet-stream msi msp msm;
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx; application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx; application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx; application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;
audio/midi mid midi kar; audio/midi mid midi kar;
audio/mpeg mp3; audio/mpeg mp3;
audio/ogg ogg; audio/ogg ogg;
audio/x-m4a m4a; audio/x-m4a m4a;
audio/x-realaudio ra; audio/x-realaudio ra;
video/3gpp 3gpp 3gp; video/3gpp 3gpp 3gp;
video/mp2t ts; video/mp2t ts;
video/mp4 mp4; video/mp4 mp4;
video/mpeg mpeg mpg; video/mpeg mpeg mpg;
video/quicktime mov; video/quicktime mov;
video/webm webm; video/webm webm;
video/x-flv flv; video/x-flv flv;
video/x-m4v m4v; video/x-m4v m4v;
video/x-mng mng; video/x-mng mng;
video/x-ms-asf asx asf; video/x-ms-asf asx asf;
video/x-ms-wmv wmv; video/x-ms-wmv wmv;
video/x-msvideo avi; video/x-msvideo avi;
} }

View File

@ -1,86 +1,86 @@
server { server {
listen 80 ; listen 80 ;
listen [::]:80; listen [::]:80;
server_name 0.0.0.0; server_name 0.0.0.0;
#include /etc/nginx/common/protect.conf; #include /etc/nginx/common/protect.conf;
#include /etc/nginx/common/protect_add_header.conf; #include /etc/nginx/common/protect_add_header.conf;
#include /etc/nginx/common/ssl.conf; #include /etc/nginx/common/ssl.conf;
root /usr/share/nginx/html/webroot; root /usr/share/nginx/html/webroot;
index index.php; index index.php;
location ~* \.(png|jpg|ico|webp)\$ { location ~* \.(png|jpg|ico|webp)\$ {
expires 30d; expires 30d;
} }
location ~* \.(js|css) { location ~* \.(js|css) {
# expires 1d; # expires 1d;
expires 1d; expires 1d;
} }
location ~ \.php\$ { location ~ \.php\$ {
# regex to split $uri to $fastcgi_script_name and $fastcgi_path # regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it # Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404; try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info # Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321 # see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info; set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info; fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php; fastcgi_index index.php;
include fastcgi.conf; include fastcgi.conf;
#fastcgi_pass unix:/run/php/php7.3-fpm.sock; #fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_pass 127.0.0.1:9000; fastcgi_pass 127.0.0.1:9000;
} }
location ~ /\.ht { location ~ /\.ht {
deny all; deny all;
} }
location /account { location /account {
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade; proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade'; proxy_set_header Connection 'upgrade';
proxy_cache_bypass \$http_upgrade; proxy_cache_bypass \$http_upgrade;
proxy_set_header X-Real-IP \$remote_addr; proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$remote_addr; proxy_set_header X-Forwarded-For \$remote_addr;
proxy_set_header Host \$host; proxy_set_header Host \$host;
rewrite /account/(.*) /\$1 break; rewrite /account/(.*) /\$1 break;
#proxy_next_upstream error timeout invalid_header http_502 non_idempotent; #proxy_next_upstream error timeout invalid_header http_502 non_idempotent;
proxy_pass http://login-server:1200; proxy_pass http://login-server:1200;
proxy_redirect off; proxy_redirect off;
} }
location /login_api { location /login_api {
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade; proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade'; proxy_set_header Connection 'upgrade';
proxy_cache_bypass \$http_upgrade; proxy_cache_bypass \$http_upgrade;
proxy_set_header X-Real-IP \$remote_addr; proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$remote_addr; proxy_set_header X-Forwarded-For \$remote_addr;
proxy_set_header Host \$host; proxy_set_header Host \$host;
rewrite /login_api/(.*) /\$1 break; rewrite /login_api/(.*) /\$1 break;
proxy_pass http://login-server:1201; proxy_pass http://login-server:1201;
proxy_redirect off; proxy_redirect off;
} }
location / { location / {
try_files \$uri \$uri/ /index.php?\$args; try_files \$uri \$uri/ /index.php?\$args;
} }
# access_log /var/log/nginx/access.log main; # access_log /var/log/nginx/access.log main;
} }

View File

@ -1,8 +1,8 @@
CREATE TABLE `community_profiles` ( CREATE TABLE `community_profiles` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`state_user_id` int(10) unsigned NOT NULL, `state_user_id` int(10) unsigned NOT NULL,
`profile_img` longblob, `profile_img` longblob,
`profile_desc` varchar(2000) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `profile_desc` varchar(2000) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `state_user_id` (`state_user_id`) KEY `state_user_id` (`state_user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

View File

@ -1,71 +1,71 @@
<?php <?php
/* /*
* To change this license header, choose License Headers in Project Properties. * To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
namespace App\Controller\Component; namespace App\Controller\Component;
use Cake\Controller\Component; use Cake\Controller\Component;
use Cake\Http\Client; use Cake\Http\Client;
use Cake\Core\Configure; use Cake\Core\Configure;
use Datto\JsonRpc\Client as JsonRpcClient; use Datto\JsonRpc\Client as JsonRpcClient;
//App\Controller\Component\ComponentRegistry //App\Controller\Component\ComponentRegistry
class JsonRpcRequestClientComponent extends Component class JsonRpcRequestClientComponent extends Component
{ {
var $rpcClient = null; var $rpcClient = null;
public function __construct($registry, array $config = array()) { public function __construct($registry, array $config = array()) {
parent::__construct($registry, $config); parent::__construct($registry, $config);
$this->rpcClient = new JsonRpcClient(); $this->rpcClient = new JsonRpcClient();
} }
// @param id: if id = 0 call rand for it // @param id: if id = 0 call rand for it
public function request($method, $params = [], $id = 0) public function request($method, $params = [], $id = 0)
{ {
if(0 == $id) { if(0 == $id) {
$id = random_int(1, 12000); $id = random_int(1, 12000);
} }
$this->rpcClient->query($id, $method, $params); $this->rpcClient->query($id, $method, $params);
$message = $this->rpcClient->encode(); $message = $this->rpcClient->encode();
return $this->sendRequest($message); return $this->sendRequest($message);
// message: {"jsonrpc":"2.0","method":"add","params":[1,2],"id":1} // message: {"jsonrpc":"2.0","method":"add","params":[1,2],"id":1}
} }
public function sendRequest($message) { public function sendRequest($message) {
$http = new Client(); $http = new Client();
$response = $http->post($this->getGradidoNodeUrl(), $message, ['type' => 'json']); $response = $http->post($this->getGradidoNodeUrl(), $message, ['type' => 'json']);
$responseStatus = $response->getStatusCode(); $responseStatus = $response->getStatusCode();
if($responseStatus != 200) { if($responseStatus != 200) {
return ['state' => 'error', 'type' => 'request error', 'msg' => 'server response status code isn\'t 200', 'details' => $responseStatus]; return ['state' => 'error', 'type' => 'request error', 'msg' => 'server response status code isn\'t 200', 'details' => $responseStatus];
} }
//$responseType = $response->getType(); //$responseType = $response->getType();
//if($responseType != 'application/json') { //if($responseType != 'application/json') {
// return ['state' => 'error', 'type' => 'request error', 'msg' => 'server response isn\'t json', 'details' => $responseType]; // return ['state' => 'error', 'type' => 'request error', 'msg' => 'server response isn\'t json', 'details' => $responseType];
// } // }
$json = $response->getJson(); $json = $response->getJson();
if($json == null) { if($json == null) {
//$responseType = $response->getType(); //$responseType = $response->getType();
return ['state' => 'error', 'type' => 'request error', 'msg' => 'server response isn\'t valid json']; return ['state' => 'error', 'type' => 'request error', 'msg' => 'server response isn\'t valid json'];
} }
return $json; return $json;
//return ['state' => 'success', 'data' => $json]; //return ['state' => 'success', 'data' => $json];
} }
static public function getGradidoNodeUrl() static public function getGradidoNodeUrl()
{ {
$gradidoNode = Configure::read('GradidoNode'); $gradidoNode = Configure::read('GradidoNode');
return $gradidoNode['host'] . ':' . $gradidoNode['port']; return $gradidoNode['host'] . ':' . $gradidoNode['port'];
} }
} }

View File

@ -22,9 +22,9 @@ class Key extends \Google\Protobuf\Internal\Message
* Optional. Data for populating the Message object. * Optional. Data for populating the Message object.
* *
* @type string $ed25519 * @type string $ed25519
* ed25519 signature (libsodium default) * ed25519 signature (libsodium default)
* @type string $ed25519_ref10 * @type string $ed25519_ref10
* ed25519 ref10 signature * ed25519 ref10 signature
* } * }
*/ */
public function __construct($data = NULL) { public function __construct($data = NULL) {
@ -33,7 +33,7 @@ class Key extends \Google\Protobuf\Internal\Message
} }
/** /**
* ed25519 signature (libsodium default) * ed25519 signature (libsodium default)
* *
* Generated from protobuf field <code>bytes ed25519 = 2;</code> * Generated from protobuf field <code>bytes ed25519 = 2;</code>
* @return string * @return string
@ -44,7 +44,7 @@ class Key extends \Google\Protobuf\Internal\Message
} }
/** /**
* ed25519 signature (libsodium default) * ed25519 signature (libsodium default)
* *
* Generated from protobuf field <code>bytes ed25519 = 2;</code> * Generated from protobuf field <code>bytes ed25519 = 2;</code>
* @param string $var * @param string $var
@ -59,7 +59,7 @@ class Key extends \Google\Protobuf\Internal\Message
} }
/** /**
* ed25519 ref10 signature * ed25519 ref10 signature
* *
* Generated from protobuf field <code>bytes ed25519_ref10 = 3;</code> * Generated from protobuf field <code>bytes ed25519_ref10 = 3;</code>
* @return string * @return string
@ -70,7 +70,7 @@ class Key extends \Google\Protobuf\Internal\Message
} }
/** /**
* ed25519 ref10 signature * ed25519 ref10 signature
* *
* Generated from protobuf field <code>bytes ed25519_ref10 = 3;</code> * Generated from protobuf field <code>bytes ed25519_ref10 = 3;</code>
* @param string $var * @param string $var

View File

@ -22,7 +22,7 @@ class SenderAmount extends \Google\Protobuf\Internal\Message
*/ */
private $amount = 0; private $amount = 0;
/** /**
* sender balance after transaction, including perishability * sender balance after transaction, including perishability
* *
* Generated from protobuf field <code>sint64 senderFinalBalance = 3;</code> * Generated from protobuf field <code>sint64 senderFinalBalance = 3;</code>
*/ */
@ -37,7 +37,7 @@ class SenderAmount extends \Google\Protobuf\Internal\Message
* @type string $ed25519_sender_pubkey * @type string $ed25519_sender_pubkey
* @type int|string $amount * @type int|string $amount
* @type int|string $senderFinalBalance * @type int|string $senderFinalBalance
* sender balance after transaction, including perishability * sender balance after transaction, including perishability
* } * }
*/ */
public function __construct($data = NULL) { public function __construct($data = NULL) {
@ -90,7 +90,7 @@ class SenderAmount extends \Google\Protobuf\Internal\Message
} }
/** /**
* sender balance after transaction, including perishability * sender balance after transaction, including perishability
* *
* Generated from protobuf field <code>sint64 senderFinalBalance = 3;</code> * Generated from protobuf field <code>sint64 senderFinalBalance = 3;</code>
* @return int|string * @return int|string
@ -101,7 +101,7 @@ class SenderAmount extends \Google\Protobuf\Internal\Message
} }
/** /**
* sender balance after transaction, including perishability * sender balance after transaction, including perishability
* *
* Generated from protobuf field <code>sint64 senderFinalBalance = 3;</code> * Generated from protobuf field <code>sint64 senderFinalBalance = 3;</code>
* @param int|string $var * @param int|string $var

View File

@ -14,7 +14,7 @@ use Google\Protobuf\Internal\GPBUtil;
class SignatureMap extends \Google\Protobuf\Internal\Message class SignatureMap extends \Google\Protobuf\Internal\Message
{ {
/** /**
* Each signature pair corresponds to a unique Key required to sign the transaction. * Each signature pair corresponds to a unique Key required to sign the transaction.
* *
* Generated from protobuf field <code>repeated .model.messages.gradido.SignaturePair sigPair = 1;</code> * Generated from protobuf field <code>repeated .model.messages.gradido.SignaturePair sigPair = 1;</code>
*/ */
@ -27,7 +27,7 @@ class SignatureMap extends \Google\Protobuf\Internal\Message
* Optional. Data for populating the Message object. * Optional. Data for populating the Message object.
* *
* @type \Model\Messages\Gradido\SignaturePair[]|\Google\Protobuf\Internal\RepeatedField $sigPair * @type \Model\Messages\Gradido\SignaturePair[]|\Google\Protobuf\Internal\RepeatedField $sigPair
* Each signature pair corresponds to a unique Key required to sign the transaction. * Each signature pair corresponds to a unique Key required to sign the transaction.
* } * }
*/ */
public function __construct($data = NULL) { public function __construct($data = NULL) {
@ -36,7 +36,7 @@ class SignatureMap extends \Google\Protobuf\Internal\Message
} }
/** /**
* Each signature pair corresponds to a unique Key required to sign the transaction. * Each signature pair corresponds to a unique Key required to sign the transaction.
* *
* Generated from protobuf field <code>repeated .model.messages.gradido.SignaturePair sigPair = 1;</code> * Generated from protobuf field <code>repeated .model.messages.gradido.SignaturePair sigPair = 1;</code>
* @return \Google\Protobuf\Internal\RepeatedField * @return \Google\Protobuf\Internal\RepeatedField
@ -47,7 +47,7 @@ class SignatureMap extends \Google\Protobuf\Internal\Message
} }
/** /**
* Each signature pair corresponds to a unique Key required to sign the transaction. * Each signature pair corresponds to a unique Key required to sign the transaction.
* *
* Generated from protobuf field <code>repeated .model.messages.gradido.SignaturePair sigPair = 1;</code> * Generated from protobuf field <code>repeated .model.messages.gradido.SignaturePair sigPair = 1;</code>
* @param \Model\Messages\Gradido\SignaturePair[]|\Google\Protobuf\Internal\RepeatedField $var * @param \Model\Messages\Gradido\SignaturePair[]|\Google\Protobuf\Internal\RepeatedField $var

View File

@ -27,9 +27,9 @@ class SignaturePair extends \Google\Protobuf\Internal\Message
* *
* @type string $pubKey * @type string $pubKey
* @type string $ed25519 * @type string $ed25519
* ed25519 signature (libsodium default) * ed25519 signature (libsodium default)
* @type string $ed25519_ref10 * @type string $ed25519_ref10
* ed25519 ref10 signature * ed25519 ref10 signature
* } * }
*/ */
public function __construct($data = NULL) { public function __construct($data = NULL) {
@ -60,7 +60,7 @@ class SignaturePair extends \Google\Protobuf\Internal\Message
} }
/** /**
* ed25519 signature (libsodium default) * ed25519 signature (libsodium default)
* *
* Generated from protobuf field <code>bytes ed25519 = 2;</code> * Generated from protobuf field <code>bytes ed25519 = 2;</code>
* @return string * @return string
@ -71,7 +71,7 @@ class SignaturePair extends \Google\Protobuf\Internal\Message
} }
/** /**
* ed25519 signature (libsodium default) * ed25519 signature (libsodium default)
* *
* Generated from protobuf field <code>bytes ed25519 = 2;</code> * Generated from protobuf field <code>bytes ed25519 = 2;</code>
* @param string $var * @param string $var
@ -86,7 +86,7 @@ class SignaturePair extends \Google\Protobuf\Internal\Message
} }
/** /**
* ed25519 ref10 signature * ed25519 ref10 signature
* *
* Generated from protobuf field <code>bytes ed25519_ref10 = 3;</code> * Generated from protobuf field <code>bytes ed25519_ref10 = 3;</code>
* @return string * @return string
@ -97,7 +97,7 @@ class SignaturePair extends \Google\Protobuf\Internal\Message
} }
/** /**
* ed25519 ref10 signature * ed25519 ref10 signature
* *
* Generated from protobuf field <code>bytes ed25519_ref10 = 3;</code> * Generated from protobuf field <code>bytes ed25519_ref10 = 3;</code>
* @param string $var * @param string $var

View File

@ -9,7 +9,7 @@ use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil; use Google\Protobuf\Internal\GPBUtil;
/** /**
* need signature from this group and from parent (if it isn't zero) * need signature from this group and from parent (if it isn't zero)
* *
* Generated from protobuf message <code>model.messages.gradido.StateCreateGroup</code> * Generated from protobuf message <code>model.messages.gradido.StateCreateGroup</code>
*/ */

View File

@ -9,7 +9,7 @@ use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil; use Google\Protobuf\Internal\GPBUtil;
/** /**
* need signature from this group and from both parents (if it isn't zero) * need signature from this group and from both parents (if it isn't zero)
* *
* Generated from protobuf message <code>model.messages.gradido.StateGroupChangeParent</code> * Generated from protobuf message <code>model.messages.gradido.StateGroupChangeParent</code>
*/ */

View File

@ -16,13 +16,13 @@ use Google\Protobuf\Internal\GPBUtil;
class Timestamp extends \Google\Protobuf\Internal\Message class Timestamp extends \Google\Protobuf\Internal\Message
{ {
/** /**
* Number of complete seconds since the start of the epoch * Number of complete seconds since the start of the epoch
* *
* Generated from protobuf field <code>int64 seconds = 1;</code> * Generated from protobuf field <code>int64 seconds = 1;</code>
*/ */
private $seconds = 0; private $seconds = 0;
/** /**
* Number of nanoseconds since the start of the last second * Number of nanoseconds since the start of the last second
* *
* Generated from protobuf field <code>int32 nanos = 2;</code> * Generated from protobuf field <code>int32 nanos = 2;</code>
*/ */
@ -35,9 +35,9 @@ class Timestamp extends \Google\Protobuf\Internal\Message
* Optional. Data for populating the Message object. * Optional. Data for populating the Message object.
* *
* @type int|string $seconds * @type int|string $seconds
* Number of complete seconds since the start of the epoch * Number of complete seconds since the start of the epoch
* @type int $nanos * @type int $nanos
* Number of nanoseconds since the start of the last second * Number of nanoseconds since the start of the last second
* } * }
*/ */
public function __construct($data = NULL) { public function __construct($data = NULL) {
@ -46,7 +46,7 @@ class Timestamp extends \Google\Protobuf\Internal\Message
} }
/** /**
* Number of complete seconds since the start of the epoch * Number of complete seconds since the start of the epoch
* *
* Generated from protobuf field <code>int64 seconds = 1;</code> * Generated from protobuf field <code>int64 seconds = 1;</code>
* @return int|string * @return int|string
@ -57,7 +57,7 @@ class Timestamp extends \Google\Protobuf\Internal\Message
} }
/** /**
* Number of complete seconds since the start of the epoch * Number of complete seconds since the start of the epoch
* *
* Generated from protobuf field <code>int64 seconds = 1;</code> * Generated from protobuf field <code>int64 seconds = 1;</code>
* @param int|string $var * @param int|string $var
@ -72,7 +72,7 @@ class Timestamp extends \Google\Protobuf\Internal\Message
} }
/** /**
* Number of nanoseconds since the start of the last second * Number of nanoseconds since the start of the last second
* *
* Generated from protobuf field <code>int32 nanos = 2;</code> * Generated from protobuf field <code>int32 nanos = 2;</code>
* @return int * @return int
@ -83,7 +83,7 @@ class Timestamp extends \Google\Protobuf\Internal\Message
} }
/** /**
* Number of nanoseconds since the start of the last second * Number of nanoseconds since the start of the last second
* *
* Generated from protobuf field <code>int32 nanos = 2;</code> * Generated from protobuf field <code>int32 nanos = 2;</code>
* @param int $var * @param int $var

View File

@ -16,7 +16,7 @@ use Google\Protobuf\Internal\GPBUtil;
class TimestampSeconds extends \Google\Protobuf\Internal\Message class TimestampSeconds extends \Google\Protobuf\Internal\Message
{ {
/** /**
* Number of complete seconds since the start of the epoch * Number of complete seconds since the start of the epoch
* *
* Generated from protobuf field <code>int64 seconds = 1;</code> * Generated from protobuf field <code>int64 seconds = 1;</code>
*/ */
@ -29,7 +29,7 @@ class TimestampSeconds extends \Google\Protobuf\Internal\Message
* Optional. Data for populating the Message object. * Optional. Data for populating the Message object.
* *
* @type int|string $seconds * @type int|string $seconds
* Number of complete seconds since the start of the epoch * Number of complete seconds since the start of the epoch
* } * }
*/ */
public function __construct($data = NULL) { public function __construct($data = NULL) {
@ -38,7 +38,7 @@ class TimestampSeconds extends \Google\Protobuf\Internal\Message
} }
/** /**
* Number of complete seconds since the start of the epoch * Number of complete seconds since the start of the epoch
* *
* Generated from protobuf field <code>int64 seconds = 1;</code> * Generated from protobuf field <code>int64 seconds = 1;</code>
* @return int|string * @return int|string
@ -49,7 +49,7 @@ class TimestampSeconds extends \Google\Protobuf\Internal\Message
} }
/** /**
* Number of complete seconds since the start of the epoch * Number of complete seconds since the start of the epoch
* *
* Generated from protobuf field <code>int64 seconds = 1;</code> * Generated from protobuf field <code>int64 seconds = 1;</code>
* @param int|string $var * @param int|string $var

View File

@ -9,27 +9,27 @@ use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBUtil; use Google\Protobuf\Internal\GPBUtil;
/** /**
* need signature from group admin or * need signature from group admin or
* percent of group users another than the receiver * percent of group users another than the receiver
* *
* Generated from protobuf message <code>model.messages.gradido.TransactionCreation</code> * Generated from protobuf message <code>model.messages.gradido.TransactionCreation</code>
*/ */
class TransactionCreation extends \Google\Protobuf\Internal\Message class TransactionCreation extends \Google\Protobuf\Internal\Message
{ {
/** /**
* 40 Byte * 40 Byte
* *
* Generated from protobuf field <code>.model.messages.gradido.ReceiverAmount receiverAmount = 1;</code> * Generated from protobuf field <code>.model.messages.gradido.ReceiverAmount receiverAmount = 1;</code>
*/ */
private $receiverAmount = null; private $receiverAmount = null;
/** /**
* 4 Byte * 4 Byte
* *
* Generated from protobuf field <code>sint32 ident_hash = 2;</code> * Generated from protobuf field <code>sint32 ident_hash = 2;</code>
*/ */
private $ident_hash = 0; private $ident_hash = 0;
/** /**
* 8 Byte * 8 Byte
* *
* Generated from protobuf field <code>.model.messages.gradido.TimestampSeconds target_date = 3;</code> * Generated from protobuf field <code>.model.messages.gradido.TimestampSeconds target_date = 3;</code>
*/ */
@ -42,11 +42,11 @@ class TransactionCreation extends \Google\Protobuf\Internal\Message
* Optional. Data for populating the Message object. * Optional. Data for populating the Message object.
* *
* @type \Model\Messages\Gradido\ReceiverAmount $receiverAmount * @type \Model\Messages\Gradido\ReceiverAmount $receiverAmount
* 40 Byte * 40 Byte
* @type int $ident_hash * @type int $ident_hash
* 4 Byte * 4 Byte
* @type \Model\Messages\Gradido\TimestampSeconds $target_date * @type \Model\Messages\Gradido\TimestampSeconds $target_date
* 8 Byte * 8 Byte
* } * }
*/ */
public function __construct($data = NULL) { public function __construct($data = NULL) {
@ -55,7 +55,7 @@ class TransactionCreation extends \Google\Protobuf\Internal\Message
} }
/** /**
* 40 Byte * 40 Byte
* *
* Generated from protobuf field <code>.model.messages.gradido.ReceiverAmount receiverAmount = 1;</code> * Generated from protobuf field <code>.model.messages.gradido.ReceiverAmount receiverAmount = 1;</code>
* @return \Model\Messages\Gradido\ReceiverAmount * @return \Model\Messages\Gradido\ReceiverAmount
@ -66,7 +66,7 @@ class TransactionCreation extends \Google\Protobuf\Internal\Message
} }
/** /**
* 40 Byte * 40 Byte
* *
* Generated from protobuf field <code>.model.messages.gradido.ReceiverAmount receiverAmount = 1;</code> * Generated from protobuf field <code>.model.messages.gradido.ReceiverAmount receiverAmount = 1;</code>
* @param \Model\Messages\Gradido\ReceiverAmount $var * @param \Model\Messages\Gradido\ReceiverAmount $var
@ -81,7 +81,7 @@ class TransactionCreation extends \Google\Protobuf\Internal\Message
} }
/** /**
* 4 Byte * 4 Byte
* *
* Generated from protobuf field <code>sint32 ident_hash = 2;</code> * Generated from protobuf field <code>sint32 ident_hash = 2;</code>
* @return int * @return int
@ -92,7 +92,7 @@ class TransactionCreation extends \Google\Protobuf\Internal\Message
} }
/** /**
* 4 Byte * 4 Byte
* *
* Generated from protobuf field <code>sint32 ident_hash = 2;</code> * Generated from protobuf field <code>sint32 ident_hash = 2;</code>
* @param int $var * @param int $var
@ -107,7 +107,7 @@ class TransactionCreation extends \Google\Protobuf\Internal\Message
} }
/** /**
* 8 Byte * 8 Byte
* *
* Generated from protobuf field <code>.model.messages.gradido.TimestampSeconds target_date = 3;</code> * Generated from protobuf field <code>.model.messages.gradido.TimestampSeconds target_date = 3;</code>
* @return \Model\Messages\Gradido\TimestampSeconds * @return \Model\Messages\Gradido\TimestampSeconds
@ -118,7 +118,7 @@ class TransactionCreation extends \Google\Protobuf\Internal\Message
} }
/** /**
* 8 Byte * 8 Byte
* *
* Generated from protobuf field <code>.model.messages.gradido.TimestampSeconds target_date = 3;</code> * Generated from protobuf field <code>.model.messages.gradido.TimestampSeconds target_date = 3;</code>
* @param \Model\Messages\Gradido\TimestampSeconds $var * @param \Model\Messages\Gradido\TimestampSeconds $var

View File

@ -1,269 +1,269 @@
<?php <?php
/* /*
* To change this license header, choose License Headers in Project Properties. * To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
namespace Model\Transactions; namespace Model\Transactions;
//use Model\Messages\Gradido\Transaction; //use Model\Messages\Gradido\Transaction;
//use Model\Messages\Gradido\TransactionBody; //use Model\Messages\Gradido\TransactionBody;
use Cake\ORM\TableRegistry; use Cake\ORM\TableRegistry;
use Cake\Datasource\ConnectionManager; use Cake\Datasource\ConnectionManager;
class Transaction extends TransactionBase { class Transaction extends TransactionBase {
private $mProtoTransaction = null; private $mProtoTransaction = null;
private $mTransactionBody = null; private $mTransactionBody = null;
public function __construct($base64Data) public function __construct($base64Data)
{ {
//$transactionBin = base64_decode($base64Data, true); //$transactionBin = base64_decode($base64Data, true);
//if($transactionBin == false) { //if($transactionBin == false) {
//sodium_base64_VARIANT_URLSAFE_NO_PADDING //sodium_base64_VARIANT_URLSAFE_NO_PADDING
if(is_a($base64Data, '\Model\Messages\Gradido\Transaction')) { if(is_a($base64Data, '\Model\Messages\Gradido\Transaction')) {
$this->mProtoTransaction = $base64Data; $this->mProtoTransaction = $base64Data;
$this->mTransactionBody = new TransactionBody($this->mProtoTransaction->getBodyBytes()); $this->mTransactionBody = new TransactionBody($this->mProtoTransaction->getBodyBytes());
return; return;
} }
try { try {
$transactionBin = sodium_base642bin($base64Data, SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING); $transactionBin = sodium_base642bin($base64Data, SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING);
} catch(\SodiumException $e) { } catch(\SodiumException $e) {
//$this->addError('Transaction', $e->getMessage());// . ' ' . $base64Data); //$this->addError('Transaction', $e->getMessage());// . ' ' . $base64Data);
//return; //return;
$transactionBin = base64_decode($base64Data, true); $transactionBin = base64_decode($base64Data, true);
if($transactionBin == false) { if($transactionBin == false) {
$this->addError('Transaction', $e->getMessage());// . ' ' . $base64Data); $this->addError('Transaction', $e->getMessage());// . ' ' . $base64Data);
return; return;
} }
} }
//*/} //*/}
if($transactionBin == false) { if($transactionBin == false) {
//$this->addError('base64 decode failed'); //$this->addError('base64 decode failed');
$this->addError('Transaction', 'base64 decode error: ' . $base64Data); $this->addError('Transaction', 'base64 decode error: ' . $base64Data);
} else { } else {
//var_dump($transactionBin); //var_dump($transactionBin);
$this->mProtoTransaction = new \Model\Messages\Gradido\Transaction(); $this->mProtoTransaction = new \Model\Messages\Gradido\Transaction();
try { try {
$this->mProtoTransaction->mergeFromString($transactionBin); $this->mProtoTransaction->mergeFromString($transactionBin);
//var_dump($this->mProtoTransaction); //var_dump($this->mProtoTransaction);
// cannot catch Exception with cakePHP, I don't know why // cannot catch Exception with cakePHP, I don't know why
} catch(\Google\Protobuf\Internal\GPBDecodeException $e) { } catch(\Google\Protobuf\Internal\GPBDecodeException $e) {
//var_dump($e); //var_dump($e);
$this->addError('Transaction', $e->getMessage()); $this->addError('Transaction', $e->getMessage());
return; return;
}//*/ }//*/
//echo 'serialize to json: <br>'; //echo 'serialize to json: <br>';
//echo $this->mProtoTransaction->serializeToJsonString(); //echo $this->mProtoTransaction->serializeToJsonString();
//echo "body bytes: <br>"; //echo "body bytes: <br>";
//var_dump($this->mProtoTransaction->getBodyBytes()); //var_dump($this->mProtoTransaction->getBodyBytes());
//echo "<br>end body bytes<br>"; //echo "<br>end body bytes<br>";
$this->mTransactionBody = new TransactionBody($this->mProtoTransaction->getBodyBytes()); $this->mTransactionBody = new TransactionBody($this->mProtoTransaction->getBodyBytes());
} }
} }
static public function build(\Model\Messages\Gradido\TransactionBody $transactionBody, $senderKeyPair) static public function build(\Model\Messages\Gradido\TransactionBody $transactionBody, $senderKeyPair)
{ {
$protoTransaction = new \Model\Messages\Gradido\Transaction(); $protoTransaction = new \Model\Messages\Gradido\Transaction();
$recevied = new \Model\Messages\Gradido\TimestampSeconds(); $recevied = new \Model\Messages\Gradido\TimestampSeconds();
$recevied->setSeconds(time()); $recevied->setSeconds(time());
$protoTransaction->setReceived($recevied); $protoTransaction->setReceived($recevied);
$bodyBytes = $transactionBody->serializeToString(); $bodyBytes = $transactionBody->serializeToString();
$sigMap = SignatureMap::build($bodyBytes, [$senderKeyPair]); $sigMap = SignatureMap::build($bodyBytes, [$senderKeyPair]);
$protoTransaction->setSigMap($sigMap->getProto()); $protoTransaction->setSigMap($sigMap->getProto());
$protoTransaction->setBodyBytes($bodyBytes); $protoTransaction->setBodyBytes($bodyBytes);
return $protoTransaction; return $protoTransaction;
} }
public function getTransactionBody() { public function getTransactionBody() {
return $this->mTransactionBody; return $this->mTransactionBody;
} }
public function getFirstPublic() { public function getFirstPublic() {
$sigPairs = $this->mProtoTransaction->getSigMap()->getSigPair(); $sigPairs = $this->mProtoTransaction->getSigMap()->getSigPair();
return $sigPairs[0]->getPubKey(); return $sigPairs[0]->getPubKey();
} }
public function getId() { public function getId() {
return $this->mProtoTransaction->getId(); return $this->mProtoTransaction->getId();
} }
public function validate() { public function validate() {
$sigMap = $this->mProtoTransaction->getSigMap(); $sigMap = $this->mProtoTransaction->getSigMap();
if(!$sigMap) { if(!$sigMap) {
$this->addError('Transaction', 'signature map is zero'); $this->addError('Transaction', 'signature map is zero');
return false; return false;
} }
//var_dump($sigMap); //var_dump($sigMap);
//die(); //die();
$sigPairs = $sigMap->getSigPair(); $sigPairs = $sigMap->getSigPair();
$bodyBytes = $this->mProtoTransaction->getBodyBytes(); $bodyBytes = $this->mProtoTransaction->getBodyBytes();
if(!$sigPairs || count($sigPairs) < 1) { if(!$sigPairs || count($sigPairs) < 1) {
$this->addError('Transaction::validate', 'no signature found'); $this->addError('Transaction::validate', 'no signature found');
return false; return false;
} }
// check signature(s) // check signature(s)
foreach($sigPairs as $sigPair) { foreach($sigPairs as $sigPair) {
//echo 'sig Pair: '; var_dump($sigPair); echo "<br>"; //echo 'sig Pair: '; var_dump($sigPair); echo "<br>";
$pubkey = $sigPair->getPubKey(); $pubkey = $sigPair->getPubKey();
$signature = $sigPair->getEd25519(); $signature = $sigPair->getEd25519();
//echo "verify bodybytes: <br>" . bin2hex($bodyBytes) . '<br>'; //echo "verify bodybytes: <br>" . bin2hex($bodyBytes) . '<br>';
if (!\Sodium\crypto_sign_verify_detached($signature, $bodyBytes, $pubkey)) { if (!\Sodium\crypto_sign_verify_detached($signature, $bodyBytes, $pubkey)) {
$this->addError('Transaction::validate', 'signature for key ' . bin2hex($pubkey) . ' isn\'t valid ' ); $this->addError('Transaction::validate', 'signature for key ' . bin2hex($pubkey) . ' isn\'t valid ' );
return false; return false;
} }
} }
if(!$this->mTransactionBody->validate($sigPairs)) { if(!$this->mTransactionBody->validate($sigPairs)) {
$this->addErrors($this->mTransactionBody->getErrors()); $this->addErrors($this->mTransactionBody->getErrors());
return false; return false;
} }
return true; return true;
} }
public function save() public function save()
{ {
$connection = ConnectionManager::get('default'); $connection = ConnectionManager::get('default');
$connection->begin(); $connection->begin();
//id transaction_id signature pubkey //id transaction_id signature pubkey
if (!$this->mTransactionBody->save($this->getFirstPublic(), $this->mProtoTransaction->getSigMap())) { if (!$this->mTransactionBody->save($this->getFirstPublic(), $this->mProtoTransaction->getSigMap())) {
$this->addErrors($this->mTransactionBody->getErrors()); $this->addErrors($this->mTransactionBody->getErrors());
$connection->rollback(); $connection->rollback();
return false; return false;
} }
// save transaction signatures // save transaction signatures
$transactionsSignaturesTable = TableRegistry::getTableLocator()->get('transaction_signatures'); $transactionsSignaturesTable = TableRegistry::getTableLocator()->get('transaction_signatures');
$transactionId = $this->mTransactionBody->getTransactionID(); $transactionId = $this->mTransactionBody->getTransactionID();
//signature pubkey //signature pubkey
$sigPairs = $this->mProtoTransaction->getSigMap()->getSigPair(); $sigPairs = $this->mProtoTransaction->getSigMap()->getSigPair();
//echo "sigPairs: "; var_dump($sigPairs); //echo "sigPairs: "; var_dump($sigPairs);
$signatureEntitys = []; $signatureEntitys = [];
foreach($sigPairs as $sigPair) { foreach($sigPairs as $sigPair) {
$signatureEntity = $transactionsSignaturesTable->newEntity(); $signatureEntity = $transactionsSignaturesTable->newEntity();
$signatureEntity->transaction_id = $transactionId; $signatureEntity->transaction_id = $transactionId;
$signatureEntity->signature = $sigPair->getEd25519(); $signatureEntity->signature = $sigPair->getEd25519();
$signatureEntity->pubkey = $sigPair->getPubKey(); $signatureEntity->pubkey = $sigPair->getPubKey();
array_push($signatureEntitys, $signatureEntity); array_push($signatureEntitys, $signatureEntity);
} }
//debug($signatureEntitys); //debug($signatureEntitys);
if(!$transactionsSignaturesTable->saveMany($signatureEntitys)) { if(!$transactionsSignaturesTable->saveMany($signatureEntitys)) {
foreach($signatureEntitys as $entity) { foreach($signatureEntitys as $entity) {
$errors = $entity->getErrors(); $errors = $entity->getErrors();
if(!$errors && count($errors) > 0) { if(!$errors && count($errors) > 0) {
$pubkeyHex = bin2hex($entity->pubkey); $pubkeyHex = bin2hex($entity->pubkey);
$this->addError('Transaction::save', 'error saving signature for pubkey: ' . $pubkeyHex . ', with errors: ' . json_encode($errors) ); $this->addError('Transaction::save', 'error saving signature for pubkey: ' . $pubkeyHex . ', with errors: ' . json_encode($errors) );
} }
} }
$connection->rollback(); $connection->rollback();
return false; return false;
} }
$connection->commit(); $connection->commit();
$this->mTransactionBody->getSpecificTransaction()->sendNotificationEmail($this->mTransactionBody->getMemo()); $this->mTransactionBody->getSpecificTransaction()->sendNotificationEmail($this->mTransactionBody->getMemo());
return true; return true;
} }
static public function fromTable($id) static public function fromTable($id)
{ {
$transactionsTable = TableRegistry::getTableLocator()->get('transactions'); $transactionsTable = TableRegistry::getTableLocator()->get('transactions');
$transactionEntry = $transactionsTable $transactionEntry = $transactionsTable
->find('all') ->find('all')
->where(['id' => $id]) ->where(['id' => $id])
->contain([ ->contain([
'TransactionCreations', 'TransactionCreations',
'TransactionSendCoins', 'TransactionSendCoins',
'TransactionSignatures']) 'TransactionSignatures'])
->first(); ->first();
//var_dump($transactionEntry->toArray()); //var_dump($transactionEntry->toArray());
$protoTransaction = new \Model\Messages\Gradido\Transaction(); $protoTransaction = new \Model\Messages\Gradido\Transaction();
$protoTransaction->setId($transactionEntry->id); $protoTransaction->setId($transactionEntry->id);
$recevied = new \Model\Messages\Gradido\TimestampSeconds(); $recevied = new \Model\Messages\Gradido\TimestampSeconds();
$recevied->setSeconds($transactionEntry->received->getTimestamp()); $recevied->setSeconds($transactionEntry->received->getTimestamp());
$protoTransaction->setReceived($recevied); $protoTransaction->setReceived($recevied);
$sigMap = SignatureMap::fromEntity($transactionEntry->transaction_signatures); $sigMap = SignatureMap::fromEntity($transactionEntry->transaction_signatures);
$protoTransaction->setSigMap($sigMap->getProto()); $protoTransaction->setSigMap($sigMap->getProto());
//echo "sig map: check<br>"; //echo "sig map: check<br>";
$protoTransaction->setTxHash(stream_get_contents($transactionEntry->tx_hash)); $protoTransaction->setTxHash(stream_get_contents($transactionEntry->tx_hash));
$body = TransactionBody::fromEntity($transactionEntry->memo, $transactionEntry); $body = TransactionBody::fromEntity($transactionEntry->memo, $transactionEntry);
if(is_array($body)) { if(is_array($body)) {
return ['state' => 'error', 'msg' => 'error creating body transaction', 'details' => $body]; return ['state' => 'error', 'msg' => 'error creating body transaction', 'details' => $body];
} }
// validate signatures // validate signatures
$sigPairs = $sigMap->getProto()->getSigPair(); $sigPairs = $sigMap->getProto()->getSigPair();
if(!$sigPairs || count($sigPairs) < 1) { if(!$sigPairs || count($sigPairs) < 1) {
return ['state' => 'error', 'msg' => 'error no signatures found']; return ['state' => 'error', 'msg' => 'error no signatures found'];
} }
//echo "verify bodybytes: <br>" . bin2hex($bodyBytes) . '<br>'; //echo "verify bodybytes: <br>" . bin2hex($bodyBytes) . '<br>';
$created = new \Model\Messages\Gradido\TimestampSeconds(); $created = new \Model\Messages\Gradido\TimestampSeconds();
$created->setSeconds($recevied->getSeconds()); $created->setSeconds($recevied->getSeconds());
$body->setCreated($created); $body->setCreated($created);
$bodyBytes = $body->serializeToString(); $bodyBytes = $body->serializeToString();
$createTrys = 0; $createTrys = 0;
$createRight = false; $createRight = false;
// check signature(s) and // check signature(s) and
// try to get created field of TransactionBody right, because it wasn't saved // try to get created field of TransactionBody right, because it wasn't saved
foreach($sigPairs as $sigPair) { foreach($sigPairs as $sigPair) {
//echo 'sig Pair: '; var_dump($sigPair); echo "<br>"; //echo 'sig Pair: '; var_dump($sigPair); echo "<br>";
$pubkey = $sigPair->getPubKey(); $pubkey = $sigPair->getPubKey();
$signature = $sigPair->getEd25519(); $signature = $sigPair->getEd25519();
if(!$createRight) { if(!$createRight) {
while($createTrys < 500) { while($createTrys < 500) {
if(\Sodium\crypto_sign_verify_detached($signature, $bodyBytes, $pubkey)) { if(\Sodium\crypto_sign_verify_detached($signature, $bodyBytes, $pubkey)) {
$createRight = true; $createRight = true;
break; break;
} else { } else {
$createTrys++; $createTrys++;
$created->setSeconds($created->getSeconds() - 1); $created->setSeconds($created->getSeconds() - 1);
//$body->setCreated($created); //$body->setCreated($created);
$bodyBytes = $body->serializeToString(); $bodyBytes = $body->serializeToString();
} }
} }
} }
if (!\Sodium\crypto_sign_verify_detached($signature, $bodyBytes, $pubkey)) { if (!\Sodium\crypto_sign_verify_detached($signature, $bodyBytes, $pubkey)) {
return ['state' => 'error', 'msg' => 'signature for key ' . bin2hex($pubkey) . ' isn\'t valid ']; return ['state' => 'error', 'msg' => 'signature for key ' . bin2hex($pubkey) . ' isn\'t valid '];
} }
} }
$protoTransaction->setBodyBytes($bodyBytes); $protoTransaction->setBodyBytes($bodyBytes);
return $protoTransaction; return $protoTransaction;
} }
} }

View File

@ -1,122 +1,122 @@
<?php <?php
namespace Model\Transactions; namespace Model\Transactions;
use Cake\ORM\TableRegistry; use Cake\ORM\TableRegistry;
class TransactionBase { class TransactionBase {
private $errors = []; private $errors = [];
static $tables = []; static $tables = [];
public function getErrors() { public function getErrors() {
return $this->errors; return $this->errors;
} }
public function addError($functionName, $errorName) { public function addError($functionName, $errorName) {
array_push($this->errors, [$functionName => $errorName]); array_push($this->errors, [$functionName => $errorName]);
} }
public function addErrors($errors) { public function addErrors($errors) {
$this->errors = array_merge($this->errors, $errors); $this->errors = array_merge($this->errors, $errors);
} }
public function hasErrors() { public function hasErrors() {
return count($this->errors) > 0; return count($this->errors) > 0;
} }
public static function getTable($tableName) { public static function getTable($tableName) {
if(!isset(self::$tables[$tableName])) { if(!isset(self::$tables[$tableName])) {
self::$tables[$tableName] = TableRegistry::getTableLocator()->get($tableName); self::$tables[$tableName] = TableRegistry::getTableLocator()->get($tableName);
} }
return self::$tables[$tableName]; return self::$tables[$tableName];
} }
protected function getStateUserId($publicKey) { protected function getStateUserId($publicKey) {
$stateUsersTable = self::getTable('state_users'); $stateUsersTable = self::getTable('state_users');
$stateUser = $stateUsersTable->find('all')->select(['id'])->where(['public_key' => $publicKey])->first(); $stateUser = $stateUsersTable->find('all')->select(['id'])->where(['public_key' => $publicKey])->first();
if($stateUser) { if($stateUser) {
return $stateUser->id; return $stateUser->id;
} }
// create new entry // create new entry
$stateUserEntity = $stateUsersTable->newEntity(); $stateUserEntity = $stateUsersTable->newEntity();
$stateUserEntity->public_key = $publicKey; $stateUserEntity->public_key = $publicKey;
if($stateUsersTable->save($stateUserEntity)) { if($stateUsersTable->save($stateUserEntity)) {
return $stateUserEntity->id; return $stateUserEntity->id;
} else { } else {
$this->addError('TransactionBase::getStateUserId', 'error saving new state user with error: ' . json_encode($stateUserEntity->getErrors())); $this->addError('TransactionBase::getStateUserId', 'error saving new state user with error: ' . json_encode($stateUserEntity->getErrors()));
} }
return NULL; return NULL;
} }
protected function getStateUser($id) { protected function getStateUser($id) {
$stateUsersTable = self::getTable('state_users'); $stateUsersTable = self::getTable('state_users');
$stateUser = $stateUsersTable->get($id); $stateUser = $stateUsersTable->get($id);
if($stateUser) { if($stateUser) {
return $stateUser; return $stateUser;
} }
return NULL; return NULL;
} }
protected function updateStateBalance($stateUserId, $addAmountCent, $recordDate) { protected function updateStateBalance($stateUserId, $addAmountCent, $recordDate) {
$finalBalance = 0; $finalBalance = 0;
$stateBalancesTable = self::getTable('stateBalances'); $stateBalancesTable = self::getTable('stateBalances');
$stateBalanceQuery = $stateBalancesTable $stateBalanceQuery = $stateBalancesTable
->find('all') ->find('all')
->select(['amount', 'id']) ->select(['amount', 'id'])
->contain(false) ->contain(false)
->where(['state_user_id' => $stateUserId]);//->first(); ->where(['state_user_id' => $stateUserId]);//->first();
//debug($stateBalanceQuery); //debug($stateBalanceQuery);
if($stateBalanceQuery->count() > 0) { if($stateBalanceQuery->count() > 0) {
$stateBalanceEntry = $stateBalanceQuery->first(); $stateBalanceEntry = $stateBalanceQuery->first();
$stateBalanceEntry->amount = $stateBalanceEntry->partDecay($recordDate) + $addAmountCent; $stateBalanceEntry->amount = $stateBalanceEntry->partDecay($recordDate) + $addAmountCent;
$stateBalanceEntry->amount += $addAmountCent; $stateBalanceEntry->amount += $addAmountCent;
} else { } else {
$stateBalanceEntry = $stateBalancesTable->newEntity(); $stateBalanceEntry = $stateBalancesTable->newEntity();
$stateBalanceEntry->state_user_id = $stateUserId; $stateBalanceEntry->state_user_id = $stateUserId;
$stateBalanceEntry->amount = $addAmountCent; $stateBalanceEntry->amount = $addAmountCent;
} }
$stateBalanceEntry->record_date = $recordDate; $stateBalanceEntry->record_date = $recordDate;
$finalBalance = $stateBalanceEntry->amount; $finalBalance = $stateBalanceEntry->amount;
//echo "\ntry to save: "; var_dump($stateBalanceEntry); echo "\n"; //echo "\ntry to save: "; var_dump($stateBalanceEntry); echo "\n";
if(!$stateBalancesTable->save($stateBalanceEntry)) { if(!$stateBalancesTable->save($stateBalanceEntry)) {
$errors = $stateBalanceEntry->getErrors(); $errors = $stateBalanceEntry->getErrors();
$this->addError('TransactionBase::updateStateBalance', 'error saving state balance with: ' . json_encode($errors)); $this->addError('TransactionBase::updateStateBalance', 'error saving state balance with: ' . json_encode($errors));
return false; return false;
} }
return $finalBalance; return $finalBalance;
} }
protected function addStateUserTransaction($stateUserId, $transactionId, $transactionTypeId, $balance) { protected function addStateUserTransaction($stateUserId, $transactionId, $transactionTypeId, $balance) {
$stateUserTransactionTable = self::getTable('state_user_transactions'); $stateUserTransactionTable = self::getTable('state_user_transactions');
$stateUserTransactions = $stateUserTransactionTable $stateUserTransactions = $stateUserTransactionTable
->find('all') ->find('all')
->where(['state_user_id' => $stateUserId]) ->where(['state_user_id' => $stateUserId])
->order(['transaction_id DESC']); ->order(['transaction_id DESC']);
if($stateUserTransactions->count() > 0) { if($stateUserTransactions->count() > 0) {
$stateBalanceTable = self::getTable('state_balances'); $stateBalanceTable = self::getTable('state_balances');
$balance_entity = $stateBalanceTable->newEntity(); $balance_entity = $stateBalanceTable->newEntity();
$balance_entity->amount = $stateUserTransactions->first()->balance; $balance_entity->amount = $stateUserTransactions->first()->balance;
$balance_entity->record_date = $stateUserTransactions->first()->balance_date; $balance_entity->record_date = $stateUserTransactions->first()->balance_date;
$balance = $balance_entity->decay + $balance; $balance = $balance_entity->decay + $balance;
} }
$entity = $stateUserTransactionTable->newEntity(); $entity = $stateUserTransactionTable->newEntity();
$entity->state_user_id = $stateUserId; $entity->state_user_id = $stateUserId;
$entity->transaction_id = $transactionId; $entity->transaction_id = $transactionId;
$entity->transaction_type_id = $transactionTypeId; $entity->transaction_type_id = $transactionTypeId;
$entity->balance = $balance; $entity->balance = $balance;
if(!$stateUserTransactionTable->save($entity)) { if(!$stateUserTransactionTable->save($entity)) {
$errors = $entity->getErrors(); $errors = $entity->getErrors();
$this->addError('TransactionBase::addStateUserTransaction', 'error saving state user balance with: ' . json_encode($errors)); $this->addError('TransactionBase::addStateUserTransaction', 'error saving state user balance with: ' . json_encode($errors));
return false; return false;
} }
return true; return true;
} }
} }

View File

@ -1,149 +1,149 @@
<?php <?php
/* /*
* To change this license header, choose License Headers in Project Properties. * To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
$this->assign('title', __('Kontoübersicht')); $this->assign('title', __('Kontoübersicht'));
$header = '<h1>' . __('Aktueller Kontostand: ') . '</h1>' . $header = '<h1>' . __('Aktueller Kontostand: ') . '</h1>' .
'<h1>' . $this->element('printGradido', ['number' => $balance]) . '</h1>'; '<h1>' . $this->element('printGradido', ['number' => $balance]) . '</h1>';
if($gdtSum > 0) { if($gdtSum > 0) {
$header .= '<h1>'.$this->Html->link( $header .= '<h1>'.$this->Html->link(
$this->element('printGDT', ['number' => $gdtSum]), $this->element('printGDT', ['number' => $gdtSum]),
['action' => 'overview_gdt'], ['action' => 'overview_gdt'],
['escape' => false] ['escape' => false]
).'</h1>'; ).'</h1>';
} }
$this->assign('header', $header); $this->assign('header', $header);
//var_dump($transactions); //var_dump($transactions);
?> ?>
<?php if($transactionExecutingCount > 0) : ?> <?php if($transactionExecutingCount > 0) : ?>
<div id="transaction-execute-display" class=""> <div id="transaction-execute-display" class="">
</div> </div>
<?php endif; ?> <?php endif; ?>
<div class="content-list"> <div class="content-list">
<p class="content-list-title">Überweisungen</p> <p class="content-list-title">Überweisungen</p>
<div class="content-list-table"> <div class="content-list-table">
<div class="row"> <div class="row">
<div class="cell header-cell c4"><?= __('Absender') . ' / ' . ('Empfänger') ?></div> <div class="cell header-cell c4"><?= __('Absender') . ' / ' . ('Empfänger') ?></div>
<div class="cell header-cell c0"><?= __('Verwendungszweck') ?></div> <div class="cell header-cell c0"><?= __('Verwendungszweck') ?></div>
<div class="cell header-cell c4"><?= __('Datum') ?></div> <div class="cell header-cell c4"><?= __('Datum') ?></div>
<div class="cell header-cell c3"><?= __('Betrag') ?></div> <div class="cell header-cell c3"><?= __('Betrag') ?></div>
<div class="cell header-cell c2" title="<?= __('Transaktions Nr.') ?>"><?= __('Nr') ?></div> <div class="cell header-cell c2" title="<?= __('Transaktions Nr.') ?>"><?= __('Nr') ?></div>
</div> </div>
<?php foreach($transactions as $transaction): <?php foreach($transactions as $transaction):
$send = $transaction['type'] == 'send'; $send = $transaction['type'] == 'send';
$balance = $transaction['balance']; $balance = $transaction['balance'];
$memoShort = $transaction['memo']; $memoShort = $transaction['memo'];
if(strlen($memoShort) > 30) { if(strlen($memoShort) > 30) {
$memoShort = substr($memoShort, 0, 30) . '...'; $memoShort = substr($memoShort, 0, 30) . '...';
} }
$cellColorClass = 'success-color'; $cellColorClass = 'success-color';
if($send) { if($send) {
$balance = -$balance; $balance = -$balance;
$cellColorClass = 'alert-color'; $cellColorClass = 'alert-color';
} else if($transaction['type'] == 'creation') { } else if($transaction['type'] == 'creation') {
$cellColorClass = 'orange-color'; $cellColorClass = 'orange-color';
} }
?> ?>
<div class="row"> <div class="row">
<div class="cell c4"> <div class="cell c4">
<?= $this->Html->image('50x50.png', ['class' => 'profile-img', 'alt' => 'profile image']) ?> <?= $this->Html->image('50x50.png', ['class' => 'profile-img', 'alt' => 'profile image']) ?>
<div> <div>
<?php if(isset($transaction['email']) && $transaction['email'] != ''): ?> <?php if(isset($transaction['email']) && $transaction['email'] != ''): ?>
<a href="mailto:<?= $transaction['email'] ?>" title="<?= $transaction['email'] ?>"> <a href="mailto:<?= $transaction['email'] ?>" title="<?= $transaction['email'] ?>">
<small class="tx-email"><?= $transaction['name'] ?></small> <small class="tx-email"><?= $transaction['name'] ?></small>
</a> </a>
<?php else : ?> <?php else : ?>
<small class="tx-email"><?= $transaction['name'] ?></small> <small class="tx-email"><?= $transaction['name'] ?></small>
<?php endif; ?> <?php endif; ?>
<!-- noch ungeklärt - icon ist nicht aligned --> <!-- noch ungeklärt - icon ist nicht aligned -->
<div class="cell-icon <?= $cellColorClass ?>"> <div class="cell-icon <?= $cellColorClass ?>">
<?php if($transaction['type'] == 'creation') : ?> <?php if($transaction['type'] == 'creation') : ?>
<i class="material-icons-outlined orange-color">redeem</i> <i class="material-icons-outlined orange-color">redeem</i>
<!-- insights / redeem --> <!-- insights / redeem -->
<?= __('Geschöpft')?> <?= __('Geschöpft')?>
<?php elseif($transaction['type'] == 'send') : ?> <?php elseif($transaction['type'] == 'send') : ?>
<i class="material-icons-outlined">arrow_back</i> <i class="material-icons-outlined">arrow_back</i>
<?= __('Gesendet') ?> <?= __('Gesendet') ?>
<?php elseif($transaction['type'] == 'receive') : ?> <?php elseif($transaction['type'] == 'receive') : ?>
<i class="material-icons-outlined">arrow_forward</i> <i class="material-icons-outlined">arrow_forward</i>
<?= __('Empfangen') ?> <?= __('Empfangen') ?>
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </div>
</div> </div>
<div class="cell c0" data-toggle="tooltip" data-placement="bottom" title="<?= $transaction['memo'] ?>"> <div class="cell c0" data-toggle="tooltip" data-placement="bottom" title="<?= $transaction['memo'] ?>">
<?php if(strlen($transaction['memo']) > 30): ?> <?php if(strlen($transaction['memo']) > 30): ?>
<?= substr($memoShort, 0, 30) . '...' ?> <?= substr($memoShort, 0, 30) . '...' ?>
<?php else : ?> <?php else : ?>
<?= $transaction['memo'] ?> <?= $transaction['memo'] ?>
<?php endif;?> <?php endif;?>
</div> </div>
<div class="cell c4"><?= $transaction['date']->nice() ?></div> <div class="cell c4"><?= $transaction['date']->nice() ?></div>
<div class="cell c3"><?= $this->element('printGradido', ['number' => $balance]) ?></div> <div class="cell c3"><?= $this->element('printGradido', ['number' => $balance]) ?></div>
<div class="cell c2"> <div class="cell c2">
<?= $transaction['transaction_id'] ?> <?= $transaction['transaction_id'] ?>
</div> </div>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
</div> </div>
<!--<a class="border-top px-3 py-2 d-block text-gray" href="#"><small class="font-weight-medium"><i class="mdi mdi-chevron-down mr-2"></i>View All Order History</small></a>--> <!--<a class="border-top px-3 py-2 d-block text-gray" href="#"><small class="font-weight-medium"><i class="mdi mdi-chevron-down mr-2"></i>View All Order History</small></a>-->
<!--?= $this->Html->css(['gdt.css']) ?--> <!--?= $this->Html->css(['gdt.css']) ?-->
<?php if($transactionExecutingCount > 0) : ?> <?php if($transactionExecutingCount > 0) : ?>
<script type="text/javascript"> <script type="text/javascript">
//function getJson(basisUrl, method, successFunction, errorFunction, timeoutFunction) //function getJson(basisUrl, method, successFunction, errorFunction, timeoutFunction)
g_transactionExecutionCount = <?= $transactionExecutingCount ?>; g_transactionExecutionCount = <?= $transactionExecutingCount ?>;
function updateTransactionExecutingDisplay(count) { function updateTransactionExecutingDisplay(count) {
var display = document.getElementById('transaction-execute-display'); var display = document.getElementById('transaction-execute-display');
display.innerHTML = count + " "; display.innerHTML = count + " ";
if(count == 1) { if(count == 1) {
display.innerHTML += "<?= __('Laufende Transaktion') ?>"; display.innerHTML += "<?= __('Laufende Transaktion') ?>";
} else { } else {
display.innerHTML += "<?= __('Laufende Transaktionen') ?>"; display.innerHTML += "<?= __('Laufende Transaktionen') ?>";
} }
display.innerHTML += '&nbsp;<div class="spinner-border text-light spinner-border-sm" role="status"><span class="sr-only">Loading...</span></div>'; display.innerHTML += '&nbsp;<div class="spinner-border text-light spinner-border-sm" role="status"><span class="sr-only">Loading...</span></div>';
} }
function checkTransactionExecuting() { function checkTransactionExecuting() {
getJson('<?= $this->Url->build(["controller" => "JsonRequestHandler"]);?>', 'getRunningUserTasks', getJson('<?= $this->Url->build(["controller" => "JsonRequestHandler"]);?>', 'getRunningUserTasks',
// success // success
function(json) { function(json) {
if(json.state === 'success') { if(json.state === 'success') {
var newCount = 0; var newCount = 0;
if(json.data.runningTasks["sign transaction"] != undefined) { if(json.data.runningTasks["sign transaction"] != undefined) {
newCount = json.data.runningTasks["sign transaction"]; newCount = json.data.runningTasks["sign transaction"];
} }
if(newCount != g_transactionExecutionCount) { if(newCount != g_transactionExecutionCount) {
g_transactionExecutionCount = newCount; g_transactionExecutionCount = newCount;
location.reload(); location.reload();
//updateTransactionExecutingDisplay(g_transactionExecutionCount); //updateTransactionExecutingDisplay(g_transactionExecutionCount);
} else { } else {
setTimeout(checkTransactionExecuting, 100); setTimeout(checkTransactionExecuting, 100);
} }
} }
}, },
// error // error
function(e) { function(e) {
}, },
// timeout // timeout
function(e) { function(e) {
} }
) )
} }
(function(document, window, domIsReady, undefined) { (function(document, window, domIsReady, undefined) {
domIsReady(function() { domIsReady(function() {
updateTransactionExecutingDisplay(g_transactionExecutionCount); updateTransactionExecutingDisplay(g_transactionExecutionCount);
setTimeout(checkTransactionExecuting, 100); setTimeout(checkTransactionExecuting, 100);
//setInterval(checkTransactionExecuting, 100); //setInterval(checkTransactionExecuting, 100);
}); });
})(document, window, domIsReady); })(document, window, domIsReady);
</script> </script>
<?php endif; ?> <?php endif; ?>

View File

@ -1,29 +1,29 @@
<?php <?php
/* /*
* To change this license header, choose License Headers in Project Properties. * To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
?> ?>
<div class="grd_container_small"> <div class="grd_container_small">
<table> <table>
<thead> <thead>
<tr> <tr>
<th>first name</th><th>last name</th><th>email</th><th>identHash</th><th>Public key hex <th>first name</th><th>last name</th><th>email</th><th>identHash</th><th>Public key hex
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach($stateUsers as $user) :?> <?php foreach($stateUsers as $user) :?>
<tr> <tr>
<td><?= $user->first_name ?></td> <td><?= $user->first_name ?></td>
<td><?= $user->last_name ?></td> <td><?= $user->last_name ?></td>
<td><?= $user->email ?></td> <td><?= $user->email ?></td>
<td><?= $user->identHash ?></td> <td><?= $user->identHash ?></td>
<td><?= bin2hex(stream_get_contents($user->public_key)) ?></td> <td><?= bin2hex(stream_get_contents($user->public_key)) ?></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -1,31 +1,31 @@
<?php <?php
/* /*
* To change this license header, choose License Headers in Project Properties. * To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
$address_options = [];//__('Selbst eingeben:')]; $address_options = [];//__('Selbst eingeben:')];
foreach($receiverProposal as $i => $receiver) { foreach($receiverProposal as $i => $receiver) {
//var_dump($receiver); //var_dump($receiver);
array_push($address_options, [ array_push($address_options, [
'text' => $receiver['name'], 'text' => $receiver['name'],
'value' => $i+1, 'value' => $i+1,
'title' => $receiver['key'] 'title' => $receiver['key']
]); ]);
} }
$this->assign('title', __('Schöpfungstransaktion')); $this->assign('title', __('Schöpfungstransaktion'));
?> ?>
<div class="grd_container_small"> <div class="grd_container_small">
<?= $this->Form->create($creationForm) ?> <?= $this->Form->create($creationForm) ?>
<fieldset> <fieldset>
<?= $this->Form->control('memo'); ?> <?= $this->Form->control('memo'); ?>
<?= $this->Form->control('amount'); ?> <?= $this->Form->control('amount'); ?>
<?= $this->Form->control('receiver', ['options' => $address_options]); ?> <?= $this->Form->control('receiver', ['options' => $address_options]); ?>
<!--<?= $this->Form->control('receiver_pubkey_hex', []) ?>--> <!--<?= $this->Form->control('receiver_pubkey_hex', []) ?>-->
</fieldset> </fieldset>
<?= $this->Form->button(__('Transaktion(en) abschließen'), ['name' => 'next', 'class' => 'grd-form-bn grd-form-bn-succeed grd_clickable grd-width-200']) ?> <?= $this->Form->button(__('Transaktion(en) abschließen'), ['name' => 'next', 'class' => 'grd-form-bn grd-form-bn-succeed grd_clickable grd-width-200']) ?>
<?= $this->Form->button(__('Weitere Transaktion erstellen'), ['name' => 'add', 'class' => 'grd-form-bn grd_clickable grd-width-200']) ?> <?= $this->Form->button(__('Weitere Transaktion erstellen'), ['name' => 'add', 'class' => 'grd-form-bn grd_clickable grd-width-200']) ?>
<?= $this->Form->end() ?> <?= $this->Form->end() ?>
</div> </div>

View File

@ -1,46 +1,46 @@
<?php <?php
/* /*
* To change this license header, choose License Headers in Project Properties. * To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
?> ?>
<div class="transactions form large-9 medium-8 columns content"> <div class="transactions form large-9 medium-8 columns content">
<h1>Synchronize state_user_transactions with transactions</h1> <h1>Synchronize state_user_transactions with transactions</h1>
<p>transactions count: <?= $count1 ?></p> <p>transactions count: <?= $count1 ?></p>
<p>state_user_transaction count: <?= $count2 ?></p> <p>state_user_transaction count: <?= $count2 ?></p>
<p>Missing count: <?= count($missing_transactions); ?></p> <p>Missing count: <?= count($missing_transactions); ?></p>
<p>First 10 Missing ids: </p> <p>First 10 Missing ids: </p>
<p><?php <p><?php
foreach($missing_transactions as $i => $id) { foreach($missing_transactions as $i => $id) {
if($i > 10) break; if($i > 10) break;
if($i > 0) echo ', '; if($i > 0) echo ', ';
echo $id['id']; echo $id['id'];
} ?></p> } ?></p>
<?php if(isset($entities) && isset($results)) : ?> <?php if(isset($entities) && isset($results)) : ?>
<h2>Synchronize errors: </h2> <h2>Synchronize errors: </h2>
<ul> <ul>
<?php <?php
$succeed = 0; $succeed = 0;
//var_dump($results); //var_dump($results);
if($results) : if($results) :
foreach($results as $i => $result) : foreach($results as $i => $result) :
if(false != $result) { if(false != $result) {
$succeed++; $succeed++;
continue; continue;
} }
?> ?>
<li>Error saving entity: <?= json_encode($entities[$i]) ?> with error: <?= json_encode($entities[$i]->getErrors()) ?></li> <li>Error saving entity: <?= json_encode($entities[$i]) ?> with error: <?= json_encode($entities[$i]->getErrors()) ?></li>
<?php endforeach; ?> <?php endforeach; ?>
<?php endif; ?> <?php endif; ?>
<li><success>Succeed: <?= $succeed ?></success></li> <li><success>Succeed: <?= $succeed ?></success></li>
</ul> </ul>
<?php endif; ?> <?php endif; ?>
<?= $this->Form->create() ?> <?= $this->Form->create() ?>
<?= $this->Form->button(__('Synchronize')) ?> <?= $this->Form->button(__('Synchronize')) ?>
<?= $this->Form->end() ?> <?= $this->Form->end() ?>
</div> </div>

View File

@ -1,46 +1,46 @@
<?php <?php
namespace App\Test\TestCase\Controller; namespace App\Test\TestCase\Controller;
use App\Controller\AppController; use App\Controller\AppController;
use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase; use Cake\TestSuite\TestCase;
/** /**
* App\Controller\DashboardController Test Case * App\Controller\DashboardController Test Case
* *
* @uses \App\Controller\DashboardController * @uses \App\Controller\DashboardController
*/ */
class AppControllerTest extends TestCase class AppControllerTest extends TestCase
{ {
use IntegrationTestTrait; use IntegrationTestTrait;
/** /**
* Fixtures * Fixtures
* *
* @var array * @var array
*/ */
public $fixtures = [ public $fixtures = [
'app.StateBalances' 'app.StateBalances'
]; ];
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
} }
/** /**
* Test initialize method * Test initialize method
* *
* @return void * @return void
*/ */
public function testInitialize() public function testInitialize()
{ {
$this->session(['StateUser.id' => 1]); $this->session(['StateUser.id' => 1]);
$this->get('/'); $this->get('/');
$this->assertSession(1200, 'StateUser.balance'); $this->assertSession(1200, 'StateUser.balance');
//$this->markTestIncomplete('Not implemented yet.'); //$this->markTestIncomplete('Not implemented yet.');
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1,408 +1,408 @@
<?php <?php
use Cake\Cache\Engine\FileEngine; use Cake\Cache\Engine\FileEngine;
use Cake\Database\Connection; use Cake\Database\Connection;
use Cake\Database\Driver\Mysql; use Cake\Database\Driver\Mysql;
use Cake\Error\ExceptionRenderer; use Cake\Error\ExceptionRenderer;
use Cake\Log\Engine\FileLog; use Cake\Log\Engine\FileLog;
use Cake\Mailer\Transport\MailTransport; use Cake\Mailer\Transport\MailTransport;
return [ return [
/** /**
* Debug Level: * Debug Level:
* *
* Production Mode: * Production Mode:
* false: No error messages, errors, or warnings shown. * false: No error messages, errors, or warnings shown.
* *
* Development Mode: * Development Mode:
* true: Errors and warnings shown. * true: Errors and warnings shown.
*/ */
'debug' => filter_var(env('DEBUG', true), FILTER_VALIDATE_BOOLEAN), 'debug' => filter_var(env('DEBUG', true), FILTER_VALIDATE_BOOLEAN),
/** /**
* Configure basic information about the application. * Configure basic information about the application.
* *
* - namespace - The namespace to find app classes under. * - namespace - The namespace to find app classes under.
* - defaultLocale - The default locale for translation, formatting currencies and numbers, date and time. * - defaultLocale - The default locale for translation, formatting currencies and numbers, date and time.
* - encoding - The encoding used for HTML + database connections. * - encoding - The encoding used for HTML + database connections.
* - base - The base directory the app resides in. If false this * - base - The base directory the app resides in. If false this
* will be auto detected. * will be auto detected.
* - dir - Name of app directory. * - dir - Name of app directory.
* - webroot - The webroot directory. * - webroot - The webroot directory.
* - wwwRoot - The file path to webroot. * - wwwRoot - The file path to webroot.
* - baseUrl - To configure CakePHP to *not* use mod_rewrite and to * - baseUrl - To configure CakePHP to *not* use mod_rewrite and to
* use CakePHP pretty URLs, remove these .htaccess * use CakePHP pretty URLs, remove these .htaccess
* files: * files:
* /.htaccess * /.htaccess
* /webroot/.htaccess * /webroot/.htaccess
* And uncomment the baseUrl key below. * And uncomment the baseUrl key below.
* - fullBaseUrl - A base URL to use for absolute links. When set to false (default) * - fullBaseUrl - A base URL to use for absolute links. When set to false (default)
* CakePHP generates required value based on `HTTP_HOST` environment variable. * CakePHP generates required value based on `HTTP_HOST` environment variable.
* However, you can define it manually to optimize performance or if you * However, you can define it manually to optimize performance or if you
* are concerned about people manipulating the `Host` header. * are concerned about people manipulating the `Host` header.
* - imageBaseUrl - Web path to the public images directory under webroot. * - imageBaseUrl - Web path to the public images directory under webroot.
* - cssBaseUrl - Web path to the public css directory under webroot. * - cssBaseUrl - Web path to the public css directory under webroot.
* - jsBaseUrl - Web path to the public js directory under webroot. * - jsBaseUrl - Web path to the public js directory under webroot.
* - paths - Configure paths for non class based resources. Supports the * - paths - Configure paths for non class based resources. Supports the
* `plugins`, `templates`, `locales` subkeys, which allow the definition of * `plugins`, `templates`, `locales` subkeys, which allow the definition of
* paths for plugins, view templates and locale files respectively. * paths for plugins, view templates and locale files respectively.
*/ */
'App' => [ 'App' => [
'namespace' => 'App', 'namespace' => 'App',
'encoding' => env('APP_ENCODING', 'UTF-8'), 'encoding' => env('APP_ENCODING', 'UTF-8'),
'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_US'), 'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_US'),
'defaultTimezone' => env('APP_DEFAULT_TIMEZONE', 'UTC'), 'defaultTimezone' => env('APP_DEFAULT_TIMEZONE', 'UTC'),
'base' => false, 'base' => false,
'dir' => 'src', 'dir' => 'src',
'webroot' => 'webroot', 'webroot' => 'webroot',
'wwwRoot' => WWW_ROOT, 'wwwRoot' => WWW_ROOT,
//'baseUrl' => env('SCRIPT_NAME'), //'baseUrl' => env('SCRIPT_NAME'),
'fullBaseUrl' => false, 'fullBaseUrl' => false,
'imageBaseUrl' => 'img/', 'imageBaseUrl' => 'img/',
'cssBaseUrl' => 'css/', 'cssBaseUrl' => 'css/',
'jsBaseUrl' => 'js/', 'jsBaseUrl' => 'js/',
'paths' => [ 'paths' => [
'plugins' => [ROOT . DS . 'plugins' . DS], 'plugins' => [ROOT . DS . 'plugins' . DS],
'templates' => [APP . 'Template' . DS], 'templates' => [APP . 'Template' . DS],
'locales' => [APP . 'Locale' . DS], 'locales' => [APP . 'Locale' . DS],
], ],
], ],
/** /**
* Security and encryption configuration * Security and encryption configuration
* *
* - salt - A random string used in security hashing methods. * - salt - A random string used in security hashing methods.
* The salt value is also used as the encryption key. * The salt value is also used as the encryption key.
* You should treat it as extremely sensitive data. * You should treat it as extremely sensitive data.
*/ */
'Security' => [ 'Security' => [
'salt' => env('SECURITY_SALT', '7ddf685a27d997ef36e51bdd626e7fc6b50a3abfb2971e8e59974d421116a150'), 'salt' => env('SECURITY_SALT', '7ddf685a27d997ef36e51bdd626e7fc6b50a3abfb2971e8e59974d421116a150'),
], ],
/** /**
* Apply timestamps with the last modified time to static assets (js, css, images). * Apply timestamps with the last modified time to static assets (js, css, images).
* Will append a querystring parameter containing the time the file was modified. * Will append a querystring parameter containing the time the file was modified.
* This is useful for busting browser caches. * This is useful for busting browser caches.
* *
* Set to true to apply timestamps when debug is true. Set to 'force' to always * Set to true to apply timestamps when debug is true. Set to 'force' to always
* enable timestamping regardless of debug value. * enable timestamping regardless of debug value.
*/ */
'Asset' => [ 'Asset' => [
//'timestamp' => true, //'timestamp' => true,
// 'cacheTime' => '+1 year' // 'cacheTime' => '+1 year'
], ],
/** /**
* Configure the cache adapters. * Configure the cache adapters.
*/ */
'Cache' => [ 'Cache' => [
'default' => [ 'default' => [
'className' => FileEngine::class, 'className' => FileEngine::class,
'path' => CACHE, 'path' => CACHE,
'url' => env('CACHE_DEFAULT_URL', null), 'url' => env('CACHE_DEFAULT_URL', null),
], ],
/** /**
* Configure the cache used for general framework caching. * Configure the cache used for general framework caching.
* Translation cache files are stored with this configuration. * Translation cache files are stored with this configuration.
* Duration will be set to '+2 minutes' in bootstrap.php when debug = true * Duration will be set to '+2 minutes' in bootstrap.php when debug = true
* If you set 'className' => 'Null' core cache will be disabled. * If you set 'className' => 'Null' core cache will be disabled.
*/ */
'_cake_core_' => [ '_cake_core_' => [
'className' => FileEngine::class, 'className' => FileEngine::class,
'prefix' => 'myapp_cake_core_', 'prefix' => 'myapp_cake_core_',
'path' => CACHE . 'persistent/', 'path' => CACHE . 'persistent/',
'serialize' => true, 'serialize' => true,
'duration' => '+1 years', 'duration' => '+1 years',
'url' => env('CACHE_CAKECORE_URL', null), 'url' => env('CACHE_CAKECORE_URL', null),
], ],
/** /**
* Configure the cache for model and datasource caches. This cache * Configure the cache for model and datasource caches. This cache
* configuration is used to store schema descriptions, and table listings * configuration is used to store schema descriptions, and table listings
* in connections. * in connections.
* Duration will be set to '+2 minutes' in bootstrap.php when debug = true * Duration will be set to '+2 minutes' in bootstrap.php when debug = true
*/ */
'_cake_model_' => [ '_cake_model_' => [
'className' => FileEngine::class, 'className' => FileEngine::class,
'prefix' => 'myapp_cake_model_', 'prefix' => 'myapp_cake_model_',
'path' => CACHE . 'models/', 'path' => CACHE . 'models/',
'serialize' => true, 'serialize' => true,
'duration' => '+1 years', 'duration' => '+1 years',
'url' => env('CACHE_CAKEMODEL_URL', null), 'url' => env('CACHE_CAKEMODEL_URL', null),
], ],
/** /**
* Configure the cache for routes. The cached routes collection is built the * Configure the cache for routes. The cached routes collection is built the
* first time the routes are processed via `config/routes.php`. * first time the routes are processed via `config/routes.php`.
* Duration will be set to '+2 seconds' in bootstrap.php when debug = true * Duration will be set to '+2 seconds' in bootstrap.php when debug = true
*/ */
'_cake_routes_' => [ '_cake_routes_' => [
'className' => FileEngine::class, 'className' => FileEngine::class,
'prefix' => 'myapp_cake_routes_', 'prefix' => 'myapp_cake_routes_',
'path' => CACHE, 'path' => CACHE,
'serialize' => true, 'serialize' => true,
'duration' => '+1 years', 'duration' => '+1 years',
'url' => env('CACHE_CAKEROUTES_URL', null), 'url' => env('CACHE_CAKEROUTES_URL', null),
], ],
], ],
/** /**
* Configure the Error and Exception handlers used by your application. * Configure the Error and Exception handlers used by your application.
* *
* By default errors are displayed using Debugger, when debug is true and logged * By default errors are displayed using Debugger, when debug is true and logged
* by Cake\Log\Log when debug is false. * by Cake\Log\Log when debug is false.
* *
* In CLI environments exceptions will be printed to stderr with a backtrace. * In CLI environments exceptions will be printed to stderr with a backtrace.
* In web environments an HTML page will be displayed for the exception. * In web environments an HTML page will be displayed for the exception.
* With debug true, framework errors like Missing Controller will be displayed. * With debug true, framework errors like Missing Controller will be displayed.
* When debug is false, framework errors will be coerced into generic HTTP errors. * When debug is false, framework errors will be coerced into generic HTTP errors.
* *
* Options: * Options:
* *
* - `errorLevel` - int - The level of errors you are interested in capturing. * - `errorLevel` - int - The level of errors you are interested in capturing.
* - `trace` - boolean - Whether or not backtraces should be included in * - `trace` - boolean - Whether or not backtraces should be included in
* logged errors/exceptions. * logged errors/exceptions.
* - `log` - boolean - Whether or not you want exceptions logged. * - `log` - boolean - Whether or not you want exceptions logged.
* - `exceptionRenderer` - string - The class responsible for rendering * - `exceptionRenderer` - string - The class responsible for rendering
* uncaught exceptions. If you choose a custom class you should place * uncaught exceptions. If you choose a custom class you should place
* the file for that class in src/Error. This class needs to implement a * the file for that class in src/Error. This class needs to implement a
* render method. * render method.
* - `skipLog` - array - List of exceptions to skip for logging. Exceptions that * - `skipLog` - array - List of exceptions to skip for logging. Exceptions that
* extend one of the listed exceptions will also be skipped for logging. * extend one of the listed exceptions will also be skipped for logging.
* E.g.: * E.g.:
* `'skipLog' => ['Cake\Http\Exception\NotFoundException', 'Cake\Http\Exception\UnauthorizedException']` * `'skipLog' => ['Cake\Http\Exception\NotFoundException', 'Cake\Http\Exception\UnauthorizedException']`
* - `extraFatalErrorMemory` - int - The number of megabytes to increase * - `extraFatalErrorMemory` - int - The number of megabytes to increase
* the memory limit by when a fatal error is encountered. This allows * the memory limit by when a fatal error is encountered. This allows
* breathing room to complete logging or error handling. * breathing room to complete logging or error handling.
*/ */
'Error' => [ 'Error' => [
'errorLevel' => E_ALL, 'errorLevel' => E_ALL,
'exceptionRenderer' => ExceptionRenderer::class, 'exceptionRenderer' => ExceptionRenderer::class,
'skipLog' => [], 'skipLog' => [],
'log' => true, 'log' => true,
'trace' => true, 'trace' => true,
], ],
/** /**
* Email configuration. * Email configuration.
* *
* By defining transports separately from delivery profiles you can easily * By defining transports separately from delivery profiles you can easily
* re-use transport configuration across multiple profiles. * re-use transport configuration across multiple profiles.
* *
* You can specify multiple configurations for production, development and * You can specify multiple configurations for production, development and
* testing. * testing.
* *
* Each transport needs a `className`. Valid options are as follows: * Each transport needs a `className`. Valid options are as follows:
* *
* Mail - Send using PHP mail function * Mail - Send using PHP mail function
* Smtp - Send using SMTP * Smtp - Send using SMTP
* Debug - Do not send the email, just return the result * Debug - Do not send the email, just return the result
* *
* You can add custom transports (or override existing transports) by adding the * You can add custom transports (or override existing transports) by adding the
* appropriate file to src/Mailer/Transport. Transports should be named * appropriate file to src/Mailer/Transport. Transports should be named
* 'YourTransport.php', where 'Your' is the name of the transport. * 'YourTransport.php', where 'Your' is the name of the transport.
*/ */
'EmailTransport' => [ 'EmailTransport' => [
'default' => [ 'default' => [
'className' => MailTransport::class, 'className' => MailTransport::class,
/* /*
* The following keys are used in SMTP transports: * The following keys are used in SMTP transports:
*/ */
'host' => 'localhost', 'host' => 'localhost',
'port' => 25, 'port' => 25,
'timeout' => 30, 'timeout' => 30,
'username' => null, 'username' => null,
'password' => null, 'password' => null,
'client' => null, 'client' => null,
'tls' => null, 'tls' => null,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null), 'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
], ],
], ],
/** /**
* Email delivery profiles * Email delivery profiles
* *
* Delivery profiles allow you to predefine various properties about email * Delivery profiles allow you to predefine various properties about email
* messages from your application and give the settings a name. This saves * messages from your application and give the settings a name. This saves
* duplication across your application and makes maintenance and development * duplication across your application and makes maintenance and development
* easier. Each profile accepts a number of keys. See `Cake\Mailer\Email` * easier. Each profile accepts a number of keys. See `Cake\Mailer\Email`
* for more information. * for more information.
*/ */
'Email' => [ 'Email' => [
'default' => [ 'default' => [
'transport' => 'default', 'transport' => 'default',
'from' => 'you@localhost', 'from' => 'you@localhost',
//'charset' => 'utf-8', //'charset' => 'utf-8',
//'headerCharset' => 'utf-8', //'headerCharset' => 'utf-8',
], ],
], ],
/** /**
* Connection information used by the ORM to connect * Connection information used by the ORM to connect
* to your application's datastores. * to your application's datastores.
* *
* ### Notes * ### Notes
* - Drivers include Mysql Postgres Sqlite Sqlserver * - Drivers include Mysql Postgres Sqlite Sqlserver
* See vendor\cakephp\cakephp\src\Database\Driver for complete list * See vendor\cakephp\cakephp\src\Database\Driver for complete list
* - Do not use periods in database name - it may lead to error. * - Do not use periods in database name - it may lead to error.
* See https://github.com/cakephp/cakephp/issues/6471 for details. * See https://github.com/cakephp/cakephp/issues/6471 for details.
* - 'encoding' is recommended to be set to full UTF-8 4-Byte support. * - 'encoding' is recommended to be set to full UTF-8 4-Byte support.
* E.g set it to 'utf8mb4' in MariaDB and MySQL and 'utf8' for any * E.g set it to 'utf8mb4' in MariaDB and MySQL and 'utf8' for any
* other RDBMS. * other RDBMS.
*/ */
'Datasources' => [ 'Datasources' => [
'default' => [ 'default' => [
'className' => Connection::class, 'className' => Connection::class,
'driver' => Mysql::class, 'driver' => Mysql::class,
'persistent' => false, 'persistent' => false,
'host' => 'mariadb', 'host' => 'mariadb',
/* /*
* CakePHP will use the default DB port based on the driver selected * CakePHP will use the default DB port based on the driver selected
* MySQL on MAMP uses port 8889, MAMP users will want to uncomment * MySQL on MAMP uses port 8889, MAMP users will want to uncomment
* the following line and set the port accordingly * the following line and set the port accordingly
*/ */
//'port' => 'non_standard_port_number', //'port' => 'non_standard_port_number',
'username' => 'root', 'username' => 'root',
'password' => '', 'password' => '',
'database' => 'gradido_community', 'database' => 'gradido_community',
/* /*
* You do not need to set this flag to use full utf-8 encoding (internal default since CakePHP 3.6). * You do not need to set this flag to use full utf-8 encoding (internal default since CakePHP 3.6).
*/ */
//'encoding' => 'utf8mb4', //'encoding' => 'utf8mb4',
'timezone' => 'UTC', 'timezone' => 'UTC',
'flags' => [], 'flags' => [],
'cacheMetadata' => true, 'cacheMetadata' => true,
'log' => false, 'log' => false,
/** /**
* Set identifier quoting to true if you are using reserved words or * Set identifier quoting to true if you are using reserved words or
* special characters in your table or column names. Enabling this * special characters in your table or column names. Enabling this
* setting will result in queries built using the Query Builder having * setting will result in queries built using the Query Builder having
* identifiers quoted when creating SQL. It should be noted that this * identifiers quoted when creating SQL. It should be noted that this
* decreases performance because each query needs to be traversed and * decreases performance because each query needs to be traversed and
* manipulated before being executed. * manipulated before being executed.
*/ */
'quoteIdentifiers' => false, 'quoteIdentifiers' => false,
/** /**
* During development, if using MySQL < 5.6, uncommenting the * During development, if using MySQL < 5.6, uncommenting the
* following line could boost the speed at which schema metadata is * following line could boost the speed at which schema metadata is
* fetched from the database. It can also be set directly with the * fetched from the database. It can also be set directly with the
* mysql configuration directive 'innodb_stats_on_metadata = 0' * mysql configuration directive 'innodb_stats_on_metadata = 0'
* which is the recommended value in production environments * which is the recommended value in production environments
*/ */
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'], //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
'url' => env('DATABASE_URL', null), 'url' => env('DATABASE_URL', null),
], ],
/** /**
* The test connection is used during the test suite. * The test connection is used during the test suite.
*/ */
'test' => [ 'test' => [
'className' => Connection::class, 'className' => Connection::class,
'driver' => Mysql::class, 'driver' => Mysql::class,
'persistent' => false, 'persistent' => false,
'host' => 'localhost', 'host' => 'localhost',
//'port' => 'non_standard_port_number', //'port' => 'non_standard_port_number',
'username' => 'my_app', 'username' => 'my_app',
'password' => 'secret', 'password' => 'secret',
'database' => 'test_myapp', 'database' => 'test_myapp',
//'encoding' => 'utf8mb4', //'encoding' => 'utf8mb4',
'timezone' => 'UTC', 'timezone' => 'UTC',
'cacheMetadata' => true, 'cacheMetadata' => true,
'quoteIdentifiers' => false, 'quoteIdentifiers' => false,
'log' => false, 'log' => false,
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'], //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
'url' => env('DATABASE_TEST_URL', null), 'url' => env('DATABASE_TEST_URL', null),
], ],
], ],
/** /**
* Configures logging options * Configures logging options
*/ */
'Log' => [ 'Log' => [
'debug' => [ 'debug' => [
'className' => FileLog::class, 'className' => FileLog::class,
'path' => LOGS, 'path' => LOGS,
'file' => 'debug', 'file' => 'debug',
'url' => env('LOG_DEBUG_URL', null), 'url' => env('LOG_DEBUG_URL', null),
'scopes' => false, 'scopes' => false,
'levels' => ['notice', 'info', 'debug'], 'levels' => ['notice', 'info', 'debug'],
], ],
'error' => [ 'error' => [
'className' => FileLog::class, 'className' => FileLog::class,
'path' => LOGS, 'path' => LOGS,
'file' => 'error', 'file' => 'error',
'url' => env('LOG_ERROR_URL', null), 'url' => env('LOG_ERROR_URL', null),
'scopes' => false, 'scopes' => false,
'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
], ],
// To enable this dedicated query log, you need set your datasource's log flag to true // To enable this dedicated query log, you need set your datasource's log flag to true
'queries' => [ 'queries' => [
'className' => FileLog::class, 'className' => FileLog::class,
'path' => LOGS, 'path' => LOGS,
'file' => 'queries', 'file' => 'queries',
'url' => env('LOG_QUERIES_URL', null), 'url' => env('LOG_QUERIES_URL', null),
'scopes' => ['queriesLog'], 'scopes' => ['queriesLog'],
], ],
], ],
/** /**
* Session configuration. * Session configuration.
* *
* Contains an array of settings to use for session configuration. The * Contains an array of settings to use for session configuration. The
* `defaults` key is used to define a default preset to use for sessions, any * `defaults` key is used to define a default preset to use for sessions, any
* settings declared here will override the settings of the default config. * settings declared here will override the settings of the default config.
* *
* ## Options * ## Options
* *
* - `cookie` - The name of the cookie to use. Defaults to 'CAKEPHP'. Avoid using `.` in cookie names, * - `cookie` - The name of the cookie to use. Defaults to 'CAKEPHP'. Avoid using `.` in cookie names,
* as PHP will drop sessions from cookies with `.` in the name. * as PHP will drop sessions from cookies with `.` in the name.
* - `cookiePath` - The url path for which session cookie is set. Maps to the * - `cookiePath` - The url path for which session cookie is set. Maps to the
* `session.cookie_path` php.ini config. Defaults to base path of app. * `session.cookie_path` php.ini config. Defaults to base path of app.
* - `timeout` - The time in minutes the session should be valid for. * - `timeout` - The time in minutes the session should be valid for.
* Pass 0 to disable checking timeout. * Pass 0 to disable checking timeout.
* Please note that php.ini's session.gc_maxlifetime must be equal to or greater * Please note that php.ini's session.gc_maxlifetime must be equal to or greater
* than the largest Session['timeout'] in all served websites for it to have the * than the largest Session['timeout'] in all served websites for it to have the
* desired effect. * desired effect.
* - `defaults` - The default configuration set to use as a basis for your session. * - `defaults` - The default configuration set to use as a basis for your session.
* There are four built-in options: php, cake, cache, database. * There are four built-in options: php, cake, cache, database.
* - `handler` - Can be used to enable a custom session handler. Expects an * - `handler` - Can be used to enable a custom session handler. Expects an
* array with at least the `engine` key, being the name of the Session engine * array with at least the `engine` key, being the name of the Session engine
* class to use for managing the session. CakePHP bundles the `CacheSession` * class to use for managing the session. CakePHP bundles the `CacheSession`
* and `DatabaseSession` engines. * and `DatabaseSession` engines.
* - `ini` - An associative array of additional ini values to set. * - `ini` - An associative array of additional ini values to set.
* *
* The built-in `defaults` options are: * The built-in `defaults` options are:
* *
* - 'php' - Uses settings defined in your php.ini. * - 'php' - Uses settings defined in your php.ini.
* - 'cake' - Saves session files in CakePHP's /tmp directory. * - 'cake' - Saves session files in CakePHP's /tmp directory.
* - 'database' - Uses CakePHP's database sessions. * - 'database' - Uses CakePHP's database sessions.
* - 'cache' - Use the Cache class to save sessions. * - 'cache' - Use the Cache class to save sessions.
* *
* To define a custom session handler, save it at src/Network/Session/<name>.php. * To define a custom session handler, save it at src/Network/Session/<name>.php.
* Make sure the class implements PHP's `SessionHandlerInterface` and set * Make sure the class implements PHP's `SessionHandlerInterface` and set
* Session.handler to <name> * Session.handler to <name>
* *
* To use database sessions, load the SQL file located at config/schema/sessions.sql * To use database sessions, load the SQL file located at config/schema/sessions.sql
*/ */
'Session' => [ 'Session' => [
'defaults' => 'php', 'defaults' => 'php',
], ],
// Gradido specific configuration // Gradido specific configuration
// Login Server ip and port // Login Server ip and port
'LoginServer' => [ 'LoginServer' => [
'host' => 'http://login-server', 'host' => 'http://login-server',
'port' => 1201 'port' => 1201
], ],
'API' => [ 'API' => [
'allowedCaller' => ['login-server'] 'allowedCaller' => ['login-server']
], ],
'ServerAdminEmail' => 'info@gradido.net', 'ServerAdminEmail' => 'info@gradido.net',
'noReplyEmail' => 'no-reply@gradido.net', 'noReplyEmail' => 'no-reply@gradido.net',
'disableEmail' => true, 'disableEmail' => true,
'GroupNode' => false 'GroupNode' => false
]; ];

View File

@ -1,51 +1,51 @@
HTTPServer.port = 1200 HTTPServer.port = 1200
JSONServer.port = 1201 JSONServer.port = 1201
Gradido.group_id = 1 Gradido.group_id = 1
crypto.server_admin_public = f909a866baec97c5460b8d7a93b72d3d4d20cc45d9f15d78bd83944eb9286b7f crypto.server_admin_public = f909a866baec97c5460b8d7a93b72d3d4d20cc45d9f15d78bd83944eb9286b7f
crypto.server_key = a51ef8ac7ef1abf162fb7a65261acd7a crypto.server_key = a51ef8ac7ef1abf162fb7a65261acd7a
# TODO auto-generate in docker build step # TODO auto-generate in docker build step
crypto.app_secret = 21ffbbc616fe crypto.app_secret = 21ffbbc616fe
# Server admin Passphrase # Server admin Passphrase
# nerve execute merit pool talk hockey basic win cargo spin disagree ethics swear price purchase say clutch decrease slow half forest reform cheese able # nerve execute merit pool talk hockey basic win cargo spin disagree ethics swear price purchase say clutch decrease slow half forest reform cheese able
# #
phpServer.url = http://localhost/ phpServer.url = http://localhost/
phpServer.host = nginx phpServer.host = nginx
loginServer.path = http://localhost/account loginServer.path = http://localhost/account
loginServer.default_locale = de loginServer.default_locale = de
loginServer.db.host = mariadb loginServer.db.host = mariadb
loginServer.db.name = gradido_login loginServer.db.name = gradido_login
loginServer.db.user = root loginServer.db.user = root
loginServer.db.password = loginServer.db.password =
loginServer.db.port = 3306 loginServer.db.port = 3306
email.disable = true email.disable = true
#email.username = #email.username =
#email.sender = #email.sender =
#email.admin_receiver = #email.admin_receiver =
#email.password = #email.password =
#email.smtp.url = #email.smtp.url =
#email.smtp.port = #email.smtp.port =
# binary is default, for debugging also json is possible # binary is default, for debugging also json is possible
#hedera.consensus.message_format = json #hedera.consensus.message_format = json
# TESTNET or MAINNET, TESTNET is default # TESTNET or MAINNET, TESTNET is default
hedera.nettype = TESTNET hedera.nettype = TESTNET
# server setup types: test, staging or production # server setup types: test, staging or production
ServerSetupType=test ServerSetupType=test
# Session timeout in minutes # Session timeout in minutes
# #
session.timeout = 15 session.timeout = 15
# Disabling security features for faster develop and testing # Disabling security features for faster develop and testing
unsecure.allow_passwort_via_json_request = 1 unsecure.allow_passwort_via_json_request = 1
unsecure.allow_auto_sign_transactions = 1 unsecure.allow_auto_sign_transactions = 1
unsecure.allow_cors_all = 1 unsecure.allow_cors_all = 1
# default disable, passwords must contain a number, a lower character, a high character, special character, and be at least 8 characters long # default disable, passwords must contain a number, a lower character, a high character, special character, and be at least 8 characters long
unsecure.allow_all_passwords = 1 unsecure.allow_all_passwords = 1

View File

@ -1,20 +1,20 @@
worker_count = 2 worker_count = 2
io_worker_count = 1 io_worker_count = 1
data_root_folder = /opt/instance/.gradido data_root_folder = /opt/instance/.gradido
hedera_mirror_endpoint = hcs.testnet.mirrornode.hedera.com:5600 hedera_mirror_endpoint = hcs.testnet.mirrornode.hedera.com:5600
sibling_node_file = /opt/instance/.gradido/sibling_nodes.txt sibling_node_file = /opt/instance/.gradido/sibling_nodes.txt
#group_requests_endpoint = 0.0.0.0:13701 #group_requests_endpoint = 0.0.0.0:13701
#record_requests_endpoint = 0.0.0.0:13702 #record_requests_endpoint = 0.0.0.0:13702
#manage_network_requests_endpoint = 0.0.0.0:13703 #manage_network_requests_endpoint = 0.0.0.0:13703
grpc_endpoint = 0.0.0.0:13701 grpc_endpoint = 0.0.0.0:13701
json_rpc_port = 13702 json_rpc_port = 13702
# larger value, larger batch, less concurrency # larger value, larger batch, less concurrency
blockchain_append_batch_size = 1000 blockchain_append_batch_size = 1000
#blochchain_init_batch_size = 1000 #blochchain_init_batch_size = 1000
#block_record_outbound_batch_size = 100 #block_record_outbound_batch_size = 100
general_batch_size = 1000 general_batch_size = 1000
group_register_topic_id = 0.0.79574 group_register_topic_id = 0.0.79574
topic_reset_allowed = 1 topic_reset_allowed = 1

View File

@ -1,136 +1,138 @@
# This file defines the production settings. It is overwritten by docker-compose.override.yml, # This file defines the production settings. It is overwritten by docker-compose.override.yml,
# which defines the development settings. The override.yml is loaded by default. Therefore it # which defines the development settings. The override.yml is loaded by default. Therefore it
# is required to explicitly define if you want an production build: # is required to explicitly define if you want an production build:
# > docker-compose -f docker-compose.yml up # > docker-compose -f docker-compose.yml up
version: "3.4" version: "3.4"
services: services:
######################################################## ########################################################
# FRONTEND ############################################# # FRONTEND #############################################
######################################################## ########################################################
frontend: frontend:
image: gradido/frontend:latest image: gradido/frontend:latest
build: build:
context: ./frontend context: ./frontend
target: production target: production
networks: networks:
- external-net - external-net
ports: depends_on:
- 8080:8080 - nginx
environment: ports:
# Envs used in Dockerfile - 8080:8080
# - DOCKER_WORKDIR="/app" environment:
# - PORT="8080" # Envs used in Dockerfile
- BUILD_DATE # - DOCKER_WORKDIR="/app"
- BUILD_VERSION # - PORT="8080"
- BUILD_COMMIT - BUILD_DATE
- NODE_ENV="production" - BUILD_VERSION
# Application only envs - BUILD_COMMIT
#- HOST=0.0.0.0 # This is nuxt specific, alternative value is HOST=webapp - NODE_ENV="production"
#env_file: # Application only envs
# - ./frontend/.env #- HOST=0.0.0.0 # This is nuxt specific, alternative value is HOST=webapp
#env_file:
######################################################### # - ./frontend/.env
## MARIADB ##############################################
######################################################### #########################################################
mariadb: ## MARIADB ##############################################
build: #########################################################
context: . mariadb:
dockerfile: ./mariadb/Dockerfile build:
target: mariadb_server context: .
container_name: mariadb dockerfile: ./mariadb/Dockerfile
environment: target: mariadb_server
- MARIADB_ALLOW_EMPTY_PASSWORD=1 container_name: mariadb
- MARIADB_USER=root environment:
networks: - MARIADB_ALLOW_EMPTY_PASSWORD=1
- internal-net - MARIADB_USER=root
ports: networks:
- 3306:3306 - internal-net
volumes: ports:
- db_vol:/var/lib/mysql - 3306:3306
volumes:
######################################################### - db_vol:/var/lib/mysql
## LOGIN SERVER #########################################
######################################################### #########################################################
login-server: ## LOGIN SERVER #########################################
build: #########################################################
context: ./login_server/ login-server:
target: login_server build:
container_name: login-server context: ./login_server/
depends_on: target: login_server
- mariadb container_name: login-server
networks: depends_on:
- internal-net - mariadb
ports: networks:
- 1200:1200 - internal-net
- 1201:1201 ports:
volumes: - 1200:1200
- ./configs/login_server:/etc/grd_login - 1201:1201
volumes:
######################################################### - ./configs/login_server:/etc/grd_login
## NGINX ################################################
######################################################### #########################################################
## nginx, connect login-server and community-server together (and php-fpm to community-server) ## NGINX ################################################
nginx: #########################################################
build: ## nginx, connect login-server and community-server together (and php-fpm to community-server)
context: . nginx:
dockerfile: ./nginx/Dockerfile build:
container_name: nginx context: .
networks: dockerfile: ./nginx/Dockerfile
- external-net container_name: nginx
- internal-net networks:
depends_on: - external-net
- community-server - internal-net
- login-server depends_on:
ports: - community-server
- 80:80 - login-server
ports:
######################################################### - 80:80
## COMMUNITY SERVER (cakephp with php-fpm) ##############
######################################################### #########################################################
community-server: ## COMMUNITY SERVER (cakephp with php-fpm) ##############
build: #########################################################
context: . community-server:
dockerfile: ./community_server/Dockerfile build:
container_name: community-server context: .
environment: dockerfile: ./community_server/Dockerfile
- DB_PASSWORD='' container_name: community-server
- DB_USER='root' environment:
- DB_DATABASE='gradido_community' - DB_PASSWORD=''
depends_on: - DB_USER='root'
- mariadb - DB_DATABASE='gradido_community'
networks: depends_on:
- internal-net - mariadb
volumes: networks:
- ./community_server/config/php-fpm/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini - internal-net
volumes:
######################################################### - ./community_server/config/php-fpm/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini
## GRADIDO NODE v1 ######################################
######################################################### #########################################################
# gradido-node: ## GRADIDO NODE v1 ######################################
# build: #########################################################
# context: . # gradido-node:
# dockerfile: ./gn/docker/deprecated-hedera-node/Dockerfile # build:
# volumes: # context: .
# - ${GN_INSTANCE_FOLDER}:/opt/instance # dockerfile: ./gn/docker/deprecated-hedera-node/Dockerfile
# container_name: ${GN_CONTAINER_NAME} # volumes:
# - ${GN_INSTANCE_FOLDER}:/opt/instance
######################################################### # container_name: ${GN_CONTAINER_NAME}
## GRADIDO NODE test ###################################
######################################################### #########################################################
# gradido-node-test: ## GRADIDO NODE test ###################################
# build: #########################################################
# context: . # gradido-node-test:
# dockerfile: ./gn/docker/deprecated-hedera-node/Dockerfile # build:
# container_name: gn-test # context: .
# working_dir: /opt/gn/build # dockerfile: ./gn/docker/deprecated-hedera-node/Dockerfile
# command: ["./unit_tests"] # container_name: gn-test
# working_dir: /opt/gn/build
networks: # command: ["./unit_tests"]
external-net:
internal-net: networks:
internal: true external-net:
internal-net:
volumes: internal: true
db_vol:
volumes:
db_vol:

View File

@ -1,131 +1,131 @@
# community server api # community server api
In this examples I assume that you use gradido with or docker-compose build on your local maschine In this examples I assume that you use gradido with or docker-compose build on your local maschine
## Konto Overview ## Konto Overview
return current account balance return current account balance
GET http://localhost/state-balances/ajaxGetBalance/-127182 GET http://localhost/state-balances/ajaxGetBalance/-127182
If session is valid, return: If session is valid, return:
```json ```json
{"state":"success","balance":174500} {"state":"success","balance":174500}
``` ```
- balance: Gradido Cent, 4 Nachkommastellen (2 Reserve), 174500 = 17,45 GDD - balance: Gradido Cent, 4 Nachkommastellen (2 Reserve), 174500 = 17,45 GDD
## List Transactions ## List Transactions
List all transactions from logged in user, currently without paging List all transactions from logged in user, currently without paging
Ajax: Ajax:
GET http://localhost/state-balances/ajaxListTransactions/-127182/ GET http://localhost/state-balances/ajaxListTransactions/-127182/
or or
GET http://localhost/state-balances/ajaxListTransactions/-127182/DESC GET http://localhost/state-balances/ajaxListTransactions/-127182/DESC
to get transaction in descending order to get transaction in descending order
Antwort: Antwort:
Wenn alles okay: Wenn alles okay:
```json ```json
{"state":"success", "transactions": {"state":"success", "transactions":
[ [
{ {
"name": "Max Mustermann", "name": "Max Mustermann",
"email": "Maxim Mustermann", "email": "Maxim Mustermann",
"type": "send", "type": "send",
"transaction_id": 2, "transaction_id": 2,
"date": "2021-02-19T13:25:36+00:00", "date": "2021-02-19T13:25:36+00:00",
"balance": 1920000, "balance": 1920000,
"memo": "a piece of cake :)", "memo": "a piece of cake :)",
"pubkey": "038a6f93270dc57b91d76bf110ad3863fcb7d1b08e7692e793fcdb4467e5b6a7" "pubkey": "038a6f93270dc57b91d76bf110ad3863fcb7d1b08e7692e793fcdb4467e5b6a7"
} }
], ],
"transactionExecutingCount": 0, "transactionExecutingCount": 0,
"count": 1, "count": 1,
"gdtSum": 0, "gdtSum": 0,
"timeUsed": 0.04562687873840332 "timeUsed": 0.04562687873840332
} }
``` ```
- name: name of other involved party or empty if unknown (if other party don't belong to group) - name: name of other involved party or empty if unknown (if other party don't belong to group)
- if type is send, name is name of receiver - if type is send, name is name of receiver
- if type is receive, name is name of sender - if type is receive, name is name of sender
- if type is creation currently I use a static string ("Gradido Akademie) - if type is creation currently I use a static string ("Gradido Akademie)
- email: optional, only if type is send or receive and other user is known - email: optional, only if type is send or receive and other user is known
- pubkey: optional, only if type is send or receive and other user isn't known - pubkey: optional, only if type is send or receive and other user isn't known
- type: type of transaction - type: type of transaction
- creation: user has get gradidos created - creation: user has get gradidos created
- send: user has send another user gradidos - send: user has send another user gradidos
- receiver: user has received gradidos from another user - receiver: user has received gradidos from another user
- transaction_id: id of transaction in db, in stage2 also the hedera sequence number of transaction - transaction_id: id of transaction in db, in stage2 also the hedera sequence number of transaction
- date: date of ordering transaction (booking date) - date: date of ordering transaction (booking date)
- balance: Gradido Cent, 4 Nachkommastellen (2 Reserve), 1920000 = 192,00 GDD - balance: Gradido Cent, 4 Nachkommastellen (2 Reserve), 1920000 = 192,00 GDD
- memo: Details about transaction - memo: Details about transaction
- pubkey: optional, if other party isn't known, hexadecimal representation of 32 Byte public key of user [0-9a-f] - pubkey: optional, if other party isn't known, hexadecimal representation of 32 Byte public key of user [0-9a-f]
- transactionExecutingCount: how many transaction for this user currently pending and waiting for signing - transactionExecutingCount: how many transaction for this user currently pending and waiting for signing
- count: sum of finished transactions user is involved - count: sum of finished transactions user is involved
- gdtSum: sum of gdt of user in cent with 2 places (Nachkommastellen) - gdtSum: sum of gdt of user in cent with 2 places (Nachkommastellen)
- timeUsed: time used for getting data from db in seconds, only for analyse backend performance - timeUsed: time used for getting data from db in seconds, only for analyse backend performance
## Creation Transaction ## Creation Transaction
Make a creation transaction Make a creation transaction
With new Option set in Login-Server: With new Option set in Login-Server:
```ini ```ini
unsecure.allow_auto_sign_transactions = 1 unsecure.allow_auto_sign_transactions = 1
``` ```
transactions can be auto-signed directly with handing in transaction. transactions can be auto-signed directly with handing in transaction.
Normally a forwarding to login-server check transactions side is neccessary to minimize security risks. Normally a forwarding to login-server check transactions side is neccessary to minimize security risks.
POST http://localhost/transaction-creations/ajaxCreate POST http://localhost/transaction-creations/ajaxCreate
```json ```json
{ {
"session_id" : -127182, "session_id" : -127182,
"email": "max.musterman@gmail.de", "email": "max.musterman@gmail.de",
"amount": 10000000, "amount": 10000000,
"target_date":"2021-02-19T13:25:36+00:00", "target_date":"2021-02-19T13:25:36+00:00",
"memo":"AGE", "memo":"AGE",
"auto_sign": true "auto_sign": true
} }
``` ```
return if everything is ok: return if everything is ok:
```json ```json
{"state":"success", "timeUsed": 0.0122} {"state":"success", "timeUsed": 0.0122}
``` ```
- timeUsed: time used for getting data from db in seconds, only for analyse backend performance - timeUsed: time used for getting data from db in seconds, only for analyse backend performance
## Send Coins Transaction ## Send Coins Transaction
Make a simple GDD Transaction, send Coins from one user to other. Make a simple GDD Transaction, send Coins from one user to other.
With new Option set in Login-Server: With new Option set in Login-Server:
```ini ```ini
unsecure.allow_auto_sign_transactions = 1 unsecure.allow_auto_sign_transactions = 1
``` ```
transactions can be auto-signed directly with handing in transaction. transactions can be auto-signed directly with handing in transaction.
Normally a forwarding to login-server check transactions side is neccessary to minimize security risks. Normally a forwarding to login-server check transactions side is neccessary to minimize security risks.
POST http://localhost/transaction-send-coins/ajaxCreate POST http://localhost/transaction-send-coins/ajaxCreate
```json ```json
{ {
"session_id" : -127182, "session_id" : -127182,
"amount": 2000000, "amount": 2000000,
"email": "max.musterman@gmail.de", "email": "max.musterman@gmail.de",
"memo":"Thank you :)", "memo":"Thank you :)",
"auto_sign": true "auto_sign": true
} }
``` ```
- amout: amount to transfer, 2000000 = 200,00 GDD - amout: amount to transfer, 2000000 = 200,00 GDD
- email: receiver email address, must be differ from user email - email: receiver email address, must be differ from user email
- memo: Details about transaction - memo: Details about transaction
- auto_sign: set to true to directly sign transaction if unsecure.allow_auto_sign_transactions = 1 is set - auto_sign: set to true to directly sign transaction if unsecure.allow_auto_sign_transactions = 1 is set
return if everything is ok: return if everything is ok:
```json ```json
{"state":"success", "timeUsed": 0.0122} {"state":"success", "timeUsed": 0.0122}
``` ```
- timeUsed: time used for getting data from db in seconds, only for analyse backend performance - timeUsed: time used for getting data from db in seconds, only for analyse backend performance
Than the transaction was created on community server, send to login-server, signed (if unsecure.allow_auto_sign_transactions = 1 and auto_sign = true) Than the transaction was created on community server, send to login-server, signed (if unsecure.allow_auto_sign_transactions = 1 and auto_sign = true)
and send back to community server and put into db. and send back to community server and put into db.
After you get this answear you see the new transaction if you list transactions or call for the balance. After you get this answear you see the new transaction if you list transactions or call for the balance.
Without auto-sign the transaction is pending on login-server and waits for the user to review it at Without auto-sign the transaction is pending on login-server and waits for the user to review it at
http://localhost/account/checkTransactions http://localhost/account/checkTransactions

View File

@ -1,177 +1,177 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(Gradido_LoginServer C CXX) project(Gradido_LoginServer C CXX)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin" ) SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin" )
SET ( CMAKE_CXX_FLAGS "-std=c++17" ) SET ( CMAKE_CXX_FLAGS "-std=c++17" )
include_directories( include_directories(
"dependencies" "dependencies"
"dependencies/tinf/src/" "dependencies/tinf/src/"
"dependencies/iroha-ed25519/include" "dependencies/iroha-ed25519/include"
"dependencies/mariadb-connector-c/include" "dependencies/mariadb-connector-c/include"
"dependencies/mariadb-connector-c/build/include" "dependencies/mariadb-connector-c/build/include"
"dependencies/spirit-po/include" "dependencies/spirit-po/include"
"src/cpp/proto" "src/cpp/proto"
#"dependencies/mariadb-connector-c/build/include" #"dependencies/mariadb-connector-c/build/include"
#"dependencies/mariadb-connector-c/include" #"dependencies/mariadb-connector-c/include"
#"import/mariadb/include" #"import/mariadb/include"
) )
FILE(GLOB CONTROLLER "src/cpp/controller/*.cpp" "src/cpp/controller/*.h") FILE(GLOB CONTROLLER "src/cpp/controller/*.cpp" "src/cpp/controller/*.h")
FILE(GLOB TINF "dependencies/tinf/src/*.c" "dependencies/tinf/src/*.h") FILE(GLOB TINF "dependencies/tinf/src/*.c" "dependencies/tinf/src/*.h")
FILE(GLOB HTTPInterface "src/cpp/HTTPInterface/*.h" "src/cpp/HTTPInterface/*.cpp") FILE(GLOB HTTPInterface "src/cpp/HTTPInterface/*.h" "src/cpp/HTTPInterface/*.cpp")
FILE(GLOB JSONInterface "src/cpp/JSONInterface/*.h" "src/cpp/JSONInterface/*.cpp") FILE(GLOB JSONInterface "src/cpp/JSONInterface/*.h" "src/cpp/JSONInterface/*.cpp")
FILE(GLOB TASKS "src/cpp/tasks/*.cpp" "src/cpp/tasks/*.h") FILE(GLOB TASKS "src/cpp/tasks/*.cpp" "src/cpp/tasks/*.h")
FILE(GLOB SINGLETON_MANAGER "src/cpp/SingletonManager/*.h" "src/cpp/SingletonManager/*.cpp") FILE(GLOB SINGLETON_MANAGER "src/cpp/SingletonManager/*.h" "src/cpp/SingletonManager/*.cpp")
FILE(GLOB LIB_SRC "src/cpp/lib/*.h" "src/cpp/lib/*.cpp") FILE(GLOB LIB_SRC "src/cpp/lib/*.h" "src/cpp/lib/*.cpp")
FILE(GLOB MODEL "src/cpp/model/*.h" "src/cpp/model/*.cpp") FILE(GLOB MODEL "src/cpp/model/*.h" "src/cpp/model/*.cpp")
FILE(GLOB MODEL_TABLE "src/cpp/model/table/*.h" "src/cpp/model/table/*.cpp") FILE(GLOB MODEL_TABLE "src/cpp/model/table/*.h" "src/cpp/model/table/*.cpp")
FILE(GLOB MODEL_EMAIL "src/cpp/model/email/*.h" "src/cpp/model/email/*.cpp") FILE(GLOB MODEL_EMAIL "src/cpp/model/email/*.h" "src/cpp/model/email/*.cpp")
FILE(GLOB CRYPTO "src/cpp/Crypto/*.h" "src/cpp/Crypto/*.cpp") FILE(GLOB CRYPTO "src/cpp/Crypto/*.h" "src/cpp/Crypto/*.cpp")
FILE(GLOB MAIN "src/cpp/*.cpp" "src/cpp/*.c" "src/cpp/*.h") FILE(GLOB MAIN "src/cpp/*.cpp" "src/cpp/*.c" "src/cpp/*.h")
FILE(GLOB MYSQL "src/cpp/MySQL/*.cpp" "src/cpp/MySQL/*.h" "src/cpp/MySQL/Poco/*.h") FILE(GLOB MYSQL "src/cpp/MySQL/*.cpp" "src/cpp/MySQL/*.h" "src/cpp/MySQL/Poco/*.h")
FILE(GLOB PROTO_GRADIDO "src/cpp/proto/gradido/*.cc" "src/cpp/proto/gradido/*.h") FILE(GLOB PROTO_GRADIDO "src/cpp/proto/gradido/*.cc" "src/cpp/proto/gradido/*.h")
FILE(GLOB PROTO_HEDERA "src/cpp/proto/hedera/*.cc" "src/cpp/proto/hedera/*.h") FILE(GLOB PROTO_HEDERA "src/cpp/proto/hedera/*.cc" "src/cpp/proto/hedera/*.h")
# used only for test project # used only for test project
FILE(GLOB TEST "src/cpp/test/*.cpp" "src/cpp/test/*.h") FILE(GLOB TEST "src/cpp/test/*.cpp" "src/cpp/test/*.h")
FILE(GLOB TEST_CRYPTO "src/cpp/test/crypto/*.cpp" "src/cpp/test/crypto/*.h") FILE(GLOB TEST_CRYPTO "src/cpp/test/crypto/*.cpp" "src/cpp/test/crypto/*.h")
FILE(GLOB TEST_MODEL "src/cpp/test/model/*.cpp" "src/cpp/test/model/*.h") FILE(GLOB TEST_MODEL "src/cpp/test/model/*.cpp" "src/cpp/test/model/*.h")
FILE(GLOB TEST_MODEL_TABLE "src/cpp/test/model/table/*.cpp" "src/cpp/test/model/table/*.h") FILE(GLOB TEST_MODEL_TABLE "src/cpp/test/model/table/*.cpp" "src/cpp/test/model/table/*.h")
FILE(GLOB TEST_CONTROLLER "src/cpp/test/controller/*.cpp" "src/cpp/test/controller/*.h") FILE(GLOB TEST_CONTROLLER "src/cpp/test/controller/*.cpp" "src/cpp/test/controller/*.h")
SET(LOCAL_SRCS SET(LOCAL_SRCS
${CONTROLLER} ${TINF} ${MAIN} ${HTTPInterface} ${CONTROLLER} ${TINF} ${MAIN} ${HTTPInterface}
${JSONInterface} ${CRYPTO} ${MODEL} ${MODEL_TABLE} ${MODEL_EMAIL} ${JSONInterface} ${CRYPTO} ${MODEL} ${MODEL_TABLE} ${MODEL_EMAIL}
${SINGLETON_MANAGER} ${LIB_SRC} ${MYSQL} ${TASKS} ${SINGLETON_MANAGER} ${LIB_SRC} ${MYSQL} ${TASKS}
${PROTO_GRADIDO} ${PROTO_HEDERA} ${PROTO_GRADIDO} ${PROTO_HEDERA}
) )
SET(LOCAL_TEST_SRC SET(LOCAL_TEST_SRC
${TEST} ${TEST_CRYPTO} ${TEST_MODEL} ${TEST_MODEL_TABLE} ${TEST_CONTROLLER} ${TEST} ${TEST_CRYPTO} ${TEST_MODEL} ${TEST_MODEL_TABLE} ${TEST_CONTROLLER}
) )
aux_source_directory("src/cpp" LOCAL_SRCS) aux_source_directory("src/cpp" LOCAL_SRCS)
if(MSVC) if(MSVC)
# src # src
source_group("controller" FILES ${CONTROLLER}) source_group("controller" FILES ${CONTROLLER})
source_group("proto\\gradido" FILES ${PROTO_GRADIDO}) source_group("proto\\gradido" FILES ${PROTO_GRADIDO})
source_group("proto\\hedera" FILES ${PROTO_HEDERA}) source_group("proto\\hedera" FILES ${PROTO_HEDERA})
source_group("tinf" FILES ${TINF}) source_group("tinf" FILES ${TINF})
source_group("Crypto" FILES ${CRYPTO}) source_group("Crypto" FILES ${CRYPTO})
source_group("tasks" FILES ${TASKS}) source_group("tasks" FILES ${TASKS})
source_group("model\\table" FILES ${MODEL_TABLE}) source_group("model\\table" FILES ${MODEL_TABLE})
source_group("model\\email" FILES ${MODEL_EMAIL}) source_group("model\\email" FILES ${MODEL_EMAIL})
source_group("model" FILES ${MODEL}) source_group("model" FILES ${MODEL})
source_group("mysql" FILES ${MYSQL}) source_group("mysql" FILES ${MYSQL})
source_group("SingletonManager" FILES ${SINGLETON_MANAGER}) source_group("SingletonManager" FILES ${SINGLETON_MANAGER})
source_group("lib" FILES ${LIB_SRC}) source_group("lib" FILES ${LIB_SRC})
source_group("HTTP-Interface" FILES ${HTTPInterface}) source_group("HTTP-Interface" FILES ${HTTPInterface})
source_group("Json-Interface" FILES ${JSONInterface}) source_group("Json-Interface" FILES ${JSONInterface})
source_group("Test\\crypto" FILES ${TEST_CRYPTO}) source_group("Test\\crypto" FILES ${TEST_CRYPTO})
source_group("Test\\model\\table" FILES ${TEST_MODEL_TABLE}) source_group("Test\\model\\table" FILES ${TEST_MODEL_TABLE})
source_group("Test\\model" FILES ${TEST_MODEL}) source_group("Test\\model" FILES ${TEST_MODEL})
source_group("Test\\controller" FILES ${TEST_CONTROLLER}) source_group("Test\\controller" FILES ${TEST_CONTROLLER})
source_group("Test" FILES ${TEST}) source_group("Test" FILES ${TEST})
endif(MSVC) endif(MSVC)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup() conan_basic_setup()
#add_subdirectory("dependencies/curl") #add_subdirectory("dependencies/curl")
#add_subdirectory("dependencies/mariadb-connector-c") #add_subdirectory("dependencies/mariadb-connector-c")
add_executable(Gradido_LoginServer ${LOCAL_SRCS}) add_executable(Gradido_LoginServer ${LOCAL_SRCS})
#SUBDIRS("src/test") #SUBDIRS("src/test")
if(WIN32) if(WIN32)
find_library(MYSQL_LIBRARIES mariadbclient.lib PATHS "dependencies/mariadb-connector-c/build/libmariadb/Release" REQUIRED) find_library(MYSQL_LIBRARIES mariadbclient.lib PATHS "dependencies/mariadb-connector-c/build/libmariadb/Release" REQUIRED)
#find_library(MYSQL_LIBRARIES_DEBUG mariadbclient.lib PATHS "import/mariadb/lib/debug") #find_library(MYSQL_LIBRARIES_DEBUG mariadbclient.lib PATHS "import/mariadb/lib/debug")
find_library(COMPILED_MARIADB_CLIENT_DEBUG mariadbclient PATHS "dependencies/mariadb-connector-c/build/libmariadb/Debug" REQUIRED) find_library(COMPILED_MARIADB_CLIENT_DEBUG mariadbclient PATHS "dependencies/mariadb-connector-c/build/libmariadb/Debug" REQUIRED)
find_library(IROHA_ED25519 ed25519 PATHS "dependencies/iroha-ed25519/build/Debug" REQUIRED) find_library(IROHA_ED25519 ed25519 PATHS "dependencies/iroha-ed25519/build/Debug" REQUIRED)
set(MYSQL_INCLUDE_DIR "dependencies/mariadb-connector-c/include") set(MYSQL_INCLUDE_DIR "dependencies/mariadb-connector-c/include")
#set(POCO_DEBUG_PATH "I:/FremdCode/C++/poco/win64/lib/Debug") #set(POCO_DEBUG_PATH "I:/FremdCode/C++/poco/win64/lib/Debug")
#find_library(POCO_DEBUG_FOUNDATION PocoFoundationd PocoFoundation PATHS ${POCO_DEBUG_PATH} REQUIRED) #find_library(POCO_DEBUG_FOUNDATION PocoFoundationd PocoFoundation PATHS ${POCO_DEBUG_PATH} REQUIRED)
#find_library(POCO_DEBUG_DATA PocoDatad PocoData PATHS ${POCO_DEBUG_PATH} REQUIRED) #find_library(POCO_DEBUG_DATA PocoDatad PocoData PATHS ${POCO_DEBUG_PATH} REQUIRED)
#find_library(POCO_DEBUG_NET PocoNetd PocoNet PATHS ${POCO_DEBUG_PATH} REQUIRED) #find_library(POCO_DEBUG_NET PocoNetd PocoNet PATHS ${POCO_DEBUG_PATH} REQUIRED)
#find_library(POCO_DEBUG_NET_SSL PocoNetSSLd PocoNetSSL PATHS ${POCO_DEBUG_PATH} REQUIRED) #find_library(POCO_DEBUG_NET_SSL PocoNetSSLd PocoNetSSL PATHS ${POCO_DEBUG_PATH} REQUIRED)
#find_library(POCO_DEBUG_UTIL PocoUtild PocoUtil PATHS ${POCO_DEBUG_PATH} REQUIRED) #find_library(POCO_DEBUG_UTIL PocoUtild PocoUtil PATHS ${POCO_DEBUG_PATH} REQUIRED)
#find_library(POCO_DEBUG_CRYPTO PocoCryptod PocoCrypto PATHS ${POCO_DEBUG_PATH} REQUIRED) #find_library(POCO_DEBUG_CRYPTO PocoCryptod PocoCrypto PATHS ${POCO_DEBUG_PATH} REQUIRED)
#set(POCO_DEBUG_LIBS ${POCO_DEBUG_FOUNDATION} ${POCO_DEBUG_UTIL} ${POCO_DEBUG_DATA} ${POCO_DEBUG_NET} ${POCO_DEBUG_NET_SSL} ${POCO_DEBUG_CRYPTO}) #set(POCO_DEBUG_LIBS ${POCO_DEBUG_FOUNDATION} ${POCO_DEBUG_UTIL} ${POCO_DEBUG_DATA} ${POCO_DEBUG_NET} ${POCO_DEBUG_NET_SSL} ${POCO_DEBUG_CRYPTO})
#include_directories( #include_directories(
# "I:/FremdCode/C++/poco/Foundation/include" # "I:/FremdCode/C++/poco/Foundation/include"
# "I:/FremdCode/C++/poco/Data/include" # "I:/FremdCode/C++/poco/Data/include"
# "I:/FremdCode/C++/poco/Net/include" # "I:/FremdCode/C++/poco/Net/include"
#"I:/FremdCode/C++/poco/NetSSL_Win/include" #"I:/FremdCode/C++/poco/NetSSL_Win/include"
# "I:/FremdCode/C++/poco/NetSSL_OpenSSL/include" # "I:/FremdCode/C++/poco/NetSSL_OpenSSL/include"
# "I:/FremdCode/C++/poco/Crypto/include" # "I:/FremdCode/C++/poco/Crypto/include"
# "I:/FremdCode/C++/poco/Util/include" # "I:/FremdCode/C++/poco/Util/include"
# "I:/FremdCode/C++/ssl/include" # "I:/FremdCode/C++/ssl/include"
#) #)
set(CMAKE_CXX_FLAGS "/MP /EHsc") set(CMAKE_CXX_FLAGS "/MP /EHsc")
#set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3") #set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3")
#set(CMAKE_CXX_FLAGS_RELEASE "-O3") #set(CMAKE_CXX_FLAGS_RELEASE "-O3")
else() else()
find_library(IROHA_ED25519 ed25519 PATHS "dependencies/iroha-ed25519/build" REQUIRED) find_library(IROHA_ED25519 ed25519 PATHS "dependencies/iroha-ed25519/build" REQUIRED)
# set vars for mariadb cmake files # set vars for mariadb cmake files
set(INSTALL_BINDIR "bin") set(INSTALL_BINDIR "bin")
set(INSTALL_PLUGINDIR "bin") set(INSTALL_PLUGINDIR "bin")
add_subdirectory("dependencies/mariadb-connector-c") add_subdirectory("dependencies/mariadb-connector-c")
include_directories( include_directories(
"dependencies/mariadb-connector-c/include" "dependencies/mariadb-connector-c/include"
"build/dependencies/mariadb-connector-c/include" "build/dependencies/mariadb-connector-c/include"
) )
endif() endif()
target_link_libraries(Gradido_LoginServer ${CONAN_LIBS} ${IROHA_ED25519}) target_link_libraries(Gradido_LoginServer ${CONAN_LIBS} ${IROHA_ED25519})
if(WIN32) if(WIN32)
TARGET_LINK_LIBRARIES(Gradido_LoginServer optimized ${MYSQL_LIBRARIES} Shlwapi) TARGET_LINK_LIBRARIES(Gradido_LoginServer optimized ${MYSQL_LIBRARIES} Shlwapi)
TARGET_LINK_LIBRARIES(Gradido_LoginServer debug ${COMPILED_MARIADB_CLIENT_DEBUG} Shlwapi) TARGET_LINK_LIBRARIES(Gradido_LoginServer debug ${COMPILED_MARIADB_CLIENT_DEBUG} Shlwapi)
else() else()
target_link_libraries(Gradido_LoginServer libmariadb -pthread) target_link_libraries(Gradido_LoginServer libmariadb -pthread)
endif() endif()
# install # install
if(UNIX) if(UNIX)
install(TARGETS Gradido_LoginServer RUNTIME DESTINATION /usr/local/bin) install(TARGETS Gradido_LoginServer RUNTIME DESTINATION /usr/local/bin)
#install(FILES lib/libmariadb /usr/local/lib) #install(FILES lib/libmariadb /usr/local/lib)
install(FILES DESTINATION lib COMPONENT libmariadb) install(FILES DESTINATION lib COMPONENT libmariadb)
install(DIRECTORY src/LOCALE DESTINATION /etc/grd_login/ install(DIRECTORY src/LOCALE DESTINATION /etc/grd_login/
FILES_MATCHING PATTERN "*.po(t)") FILES_MATCHING PATTERN "*.po(t)")
endif(UNIX) endif(UNIX)
enable_testing() enable_testing()
# ---------------------- Test ----------------------------------------- # ---------------------- Test -----------------------------------------
#project(Gradido_LoginServer_Test C CXX) #project(Gradido_LoginServer_Test C CXX)
#_TEST_BUILD #_TEST_BUILD
add_executable(Gradido_LoginServer_Test ${LOCAL_SRCS} ${LOCAL_TEST_SRC}) add_executable(Gradido_LoginServer_Test ${LOCAL_SRCS} ${LOCAL_TEST_SRC})
target_compile_definitions(Gradido_LoginServer_Test PUBLIC "_TEST_BUILD") target_compile_definitions(Gradido_LoginServer_Test PUBLIC "_TEST_BUILD")
target_link_libraries(Gradido_LoginServer_Test ${CONAN_LIBS} ${IROHA_ED25519}) target_link_libraries(Gradido_LoginServer_Test ${CONAN_LIBS} ${IROHA_ED25519})
if(WIN32) if(WIN32)
TARGET_LINK_LIBRARIES(Gradido_LoginServer_Test optimized ${MYSQL_LIBRARIES} Shlwapi) TARGET_LINK_LIBRARIES(Gradido_LoginServer_Test optimized ${MYSQL_LIBRARIES} Shlwapi)
TARGET_LINK_LIBRARIES(Gradido_LoginServer_Test debug ${COMPILED_MARIADB_CLIENT_DEBUG} Shlwapi) TARGET_LINK_LIBRARIES(Gradido_LoginServer_Test debug ${COMPILED_MARIADB_CLIENT_DEBUG} Shlwapi)
else() else()
target_link_libraries(Gradido_LoginServer_Test libmariadb -pthread) target_link_libraries(Gradido_LoginServer_Test libmariadb -pthread)
endif() endif()
add_test(NAME main COMMAND Gradido_LoginServer_Test) add_test(NAME main COMMAND Gradido_LoginServer_Test)

View File

@ -1,16 +1,16 @@
CREATE TABLE `users` ( CREATE TABLE `users` (
`id` int UNSIGNED NOT NULL AUTO_INCREMENT, `id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`email` varchar(191) NOT NULL, `email` varchar(191) NOT NULL,
`first_name` varchar(150) NOT NULL, `first_name` varchar(150) NOT NULL,
`last_name` varchar(255) DEFAULT '', `last_name` varchar(255) DEFAULT '',
`password` bigint unsigned DEFAULT 0, `password` bigint unsigned DEFAULT 0,
`pubkey` binary(32) DEFAULT NULL, `pubkey` binary(32) DEFAULT NULL,
`privkey` binary(80) DEFAULT NULL, `privkey` binary(80) DEFAULT NULL,
`created` datetime NOT NULL DEFAULT current_timestamp(), `created` datetime NOT NULL DEFAULT current_timestamp(),
`email_checked` tinyint NOT NULL DEFAULT 0, `email_checked` tinyint NOT NULL DEFAULT 0,
`passphrase_shown` tinyint NOT NULL DEFAULT 0, `passphrase_shown` tinyint NOT NULL DEFAULT 0,
`language` varchar(4) NOT NULL DEFAULT 'de', `language` varchar(4) NOT NULL DEFAULT 'de',
`disabled` BOOLEAN NULL DEFAULT FALSE, `disabled` BOOLEAN NULL DEFAULT FALSE,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`) UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

View File

@ -1,267 +1,267 @@
#include "Gradido_LoginServer.h" #include "Gradido_LoginServer.h"
#include "ServerConfig.h" #include "ServerConfig.h"
#include "HTTPInterface/PageRequestHandlerFactory.h" #include "HTTPInterface/PageRequestHandlerFactory.h"
#include "JSONInterface/JsonRequestHandlerFactory.h" #include "JSONInterface/JsonRequestHandlerFactory.h"
#include "lib/Profiler.h" #include "lib/Profiler.h"
#include "SingletonManager/ConnectionManager.h" #include "SingletonManager/ConnectionManager.h"
#include "SingletonManager/SessionManager.h" #include "SingletonManager/SessionManager.h"
#include "SingletonManager/EmailManager.h" #include "SingletonManager/EmailManager.h"
#include "controller/User.h" #include "controller/User.h"
#include "Poco/Util/HelpFormatter.h" #include "Poco/Util/HelpFormatter.h"
#include "Poco/Net/ServerSocket.h" #include "Poco/Net/ServerSocket.h"
#include "Poco/Net/HTTPServer.h" #include "Poco/Net/HTTPServer.h"
#include "Poco/Net/SSLManager.h" #include "Poco/Net/SSLManager.h"
#include "Poco/Environment.h" #include "Poco/Environment.h"
#include "Poco/Logger.h" #include "Poco/Logger.h"
#include "Poco/Path.h" #include "Poco/Path.h"
#include "Poco/AsyncChannel.h" #include "Poco/AsyncChannel.h"
#include "Poco/SimpleFileChannel.h" #include "Poco/SimpleFileChannel.h"
#include "Poco/ConsoleChannel.h" #include "Poco/ConsoleChannel.h"
#include "Poco/SplitterChannel.h" #include "Poco/SplitterChannel.h"
#include "MySQL/Poco/Connector.h" #include "MySQL/Poco/Connector.h"
#include <sodium.h> #include <sodium.h>
Gradido_LoginServer::Gradido_LoginServer() Gradido_LoginServer::Gradido_LoginServer()
: _helpRequested(false) : _helpRequested(false)
{ {
} }
Gradido_LoginServer::~Gradido_LoginServer() Gradido_LoginServer::~Gradido_LoginServer()
{ {
} }
void Gradido_LoginServer::initialize(Application& self) void Gradido_LoginServer::initialize(Application& self)
{ {
loadConfiguration(); // load default configuration files, if present loadConfiguration(); // load default configuration files, if present
ServerApplication::initialize(self); ServerApplication::initialize(self);
} }
void Gradido_LoginServer::uninitialize() void Gradido_LoginServer::uninitialize()
{ {
ServerApplication::uninitialize(); ServerApplication::uninitialize();
} }
void Gradido_LoginServer::defineOptions(Poco::Util::OptionSet& options) void Gradido_LoginServer::defineOptions(Poco::Util::OptionSet& options)
{ {
ServerApplication::defineOptions(options); ServerApplication::defineOptions(options);
/*options.addOption( /*options.addOption(
Poco::Util::Option("help", "h", "display help information on command line arguments") Poco::Util::Option("help", "h", "display help information on command line arguments")
.required(false) .required(false)
.repeatable(false));*/ .repeatable(false));*/
options.addOption( options.addOption(
Poco::Util::Option("config", "c", "use non default config file (default is /etc/grd_login.properties)", false) Poco::Util::Option("config", "c", "use non default config file (default is /etc/grd_login.properties)", false)
.repeatable(false) .repeatable(false)
.argument("Gradido_LoginServer.properties", true) .argument("Gradido_LoginServer.properties", true)
.callback(Poco::Util::OptionCallback<Gradido_LoginServer>(this, &Gradido_LoginServer::handleOption))); .callback(Poco::Util::OptionCallback<Gradido_LoginServer>(this, &Gradido_LoginServer::handleOption)));
} }
void Gradido_LoginServer::handleOption(const std::string& name, const std::string& value) void Gradido_LoginServer::handleOption(const std::string& name, const std::string& value)
{ {
//printf("handle option: %s with value: %s\n", name.data(), value.data()); //printf("handle option: %s with value: %s\n", name.data(), value.data());
if (name == "config") { if (name == "config") {
mConfigPath = value; mConfigPath = value;
return; return;
} }
ServerApplication::handleOption(name, value); ServerApplication::handleOption(name, value);
if (name == "help") _helpRequested = true; if (name == "help") _helpRequested = true;
} }
void Gradido_LoginServer::displayHelp() void Gradido_LoginServer::displayHelp()
{ {
Poco::Util::HelpFormatter helpFormatter(options()); Poco::Util::HelpFormatter helpFormatter(options());
helpFormatter.setCommand(commandName()); helpFormatter.setCommand(commandName());
helpFormatter.setUsage("OPTIONS"); helpFormatter.setUsage("OPTIONS");
helpFormatter.setHeader("Gradido Login Server"); helpFormatter.setHeader("Gradido Login Server");
helpFormatter.format(std::cout); helpFormatter.format(std::cout);
} }
void Gradido_LoginServer::createConsoleFileAsyncLogger(std::string name, std::string filePath) void Gradido_LoginServer::createConsoleFileAsyncLogger(std::string name, std::string filePath)
{ {
Poco::AutoPtr<Poco::ConsoleChannel> logConsoleChannel(new Poco::ConsoleChannel); Poco::AutoPtr<Poco::ConsoleChannel> logConsoleChannel(new Poco::ConsoleChannel);
Poco::AutoPtr<Poco::SimpleFileChannel> logFileChannel(new Poco::SimpleFileChannel(filePath)); Poco::AutoPtr<Poco::SimpleFileChannel> logFileChannel(new Poco::SimpleFileChannel(filePath));
logFileChannel->setProperty("rotation", "500 K"); logFileChannel->setProperty("rotation", "500 K");
Poco::AutoPtr<Poco::SplitterChannel> logSplitter(new Poco::SplitterChannel); Poco::AutoPtr<Poco::SplitterChannel> logSplitter(new Poco::SplitterChannel);
logSplitter->addChannel(logConsoleChannel); logSplitter->addChannel(logConsoleChannel);
logSplitter->addChannel(logFileChannel); logSplitter->addChannel(logFileChannel);
Poco::AutoPtr<Poco::AsyncChannel> logAsyncChannel(new Poco::AsyncChannel(logSplitter)); Poco::AutoPtr<Poco::AsyncChannel> logAsyncChannel(new Poco::AsyncChannel(logSplitter));
Poco::Logger& log = Poco::Logger::get(name); Poco::Logger& log = Poco::Logger::get(name);
log.setChannel(logAsyncChannel); log.setChannel(logAsyncChannel);
log.setLevel("information"); log.setLevel("information");
} }
int Gradido_LoginServer::main(const std::vector<std::string>& args) int Gradido_LoginServer::main(const std::vector<std::string>& args)
{ {
Profiler usedTime; Profiler usedTime;
if (_helpRequested) if (_helpRequested)
{ {
displayHelp(); displayHelp();
} }
else else
{ {
// ********** logging ************************************ // ********** logging ************************************
std::string log_Path = "/var/log/grd_login/"; std::string log_Path = "/var/log/grd_login/";
//#ifdef _WIN32 //#ifdef _WIN32
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
log_Path = "./"; log_Path = "./";
#endif #endif
// init speed logger // init speed logger
Poco::AutoPtr<Poco::SimpleFileChannel> speedLogFileChannel(new Poco::SimpleFileChannel(log_Path + "speedLog.txt")); Poco::AutoPtr<Poco::SimpleFileChannel> speedLogFileChannel(new Poco::SimpleFileChannel(log_Path + "speedLog.txt"));
/* /*
The optional log file rotation mode: The optional log file rotation mode:
never: no rotation (default) never: no rotation (default)
<n>: rotate if file size exceeds <n> bytes <n>: rotate if file size exceeds <n> bytes
<n> K: rotate if file size exceeds <n> Kilobytes <n> K: rotate if file size exceeds <n> Kilobytes
<n> M: rotate if file size exceeds <n> Megabytes <n> M: rotate if file size exceeds <n> Megabytes
*/ */
speedLogFileChannel->setProperty("rotation", "500 K"); speedLogFileChannel->setProperty("rotation", "500 K");
Poco::AutoPtr<Poco::AsyncChannel> speedLogAsyncChannel(new Poco::AsyncChannel(speedLogFileChannel)); Poco::AutoPtr<Poco::AsyncChannel> speedLogAsyncChannel(new Poco::AsyncChannel(speedLogFileChannel));
Poco::Logger& speedLogger = Poco::Logger::get("SpeedLog"); Poco::Logger& speedLogger = Poco::Logger::get("SpeedLog");
speedLogger.setChannel(speedLogAsyncChannel); speedLogger.setChannel(speedLogAsyncChannel);
speedLogger.setLevel("information"); speedLogger.setLevel("information");
// logging for request handling // logging for request handling
createConsoleFileAsyncLogger("requestLog", log_Path + "requestLog.txt"); createConsoleFileAsyncLogger("requestLog", log_Path + "requestLog.txt");
// error logging // error logging
createConsoleFileAsyncLogger("errorLog", log_Path + "errorLog.txt"); createConsoleFileAsyncLogger("errorLog", log_Path + "errorLog.txt");
Poco::Logger& errorLog = Poco::Logger::get("errorLog"); Poco::Logger& errorLog = Poco::Logger::get("errorLog");
createConsoleFileAsyncLogger("emailLog", log_Path + "emailLog.txt"); createConsoleFileAsyncLogger("emailLog", log_Path + "emailLog.txt");
// *************** load from config ******************************************** // *************** load from config ********************************************
std::string cfg_Path = Poco::Path::config() + "grd_login/grd_login.properties"; std::string cfg_Path = Poco::Path::config() + "grd_login/grd_login.properties";
if (mConfigPath != "") { if (mConfigPath != "") {
cfg_Path = mConfigPath; cfg_Path = mConfigPath;
} }
try { try {
loadConfiguration(cfg_Path); loadConfiguration(cfg_Path);
} }
catch (Poco::Exception& ex) { catch (Poco::Exception& ex) {
errorLog.error("error loading config: %s from path: %s", ex.displayText(), cfg_Path); errorLog.error("error loading config: %s from path: %s", ex.displayText(), cfg_Path);
} }
unsigned short port = (unsigned short)config().getInt("HTTPServer.port", 9980); unsigned short port = (unsigned short)config().getInt("HTTPServer.port", 9980);
unsigned short json_port = (unsigned short)config().getInt("JSONServer.port", 1201); unsigned short json_port = (unsigned short)config().getInt("JSONServer.port", 1201);
//printf("show mnemonic list: \n"); //printf("show mnemonic list: \n");
//printf(ServerConfig::g_Mnemonic_WordLists[ServerConfig::MNEMONIC_BIP0039_SORTED_ORDER].getCompleteWordList().data()); //printf(ServerConfig::g_Mnemonic_WordLists[ServerConfig::MNEMONIC_BIP0039_SORTED_ORDER].getCompleteWordList().data());
if (!ServerConfig::initServerCrypto(config())) { if (!ServerConfig::initServerCrypto(config())) {
//printf("[Gradido_LoginServer::%s] error init server crypto\n", __FUNCTION__); //printf("[Gradido_LoginServer::%s] error init server crypto\n", __FUNCTION__);
errorLog.error("[Gradido_LoginServer::main] error init server crypto"); errorLog.error("[Gradido_LoginServer::main] error init server crypto");
return Application::EXIT_CONFIG; return Application::EXIT_CONFIG;
} }
// first check time for crypto // first check time for crypto
auto testUser = new User("email@google.de", "Max", "Mustermann"); auto testUser = new User("email@google.de", "Max", "Mustermann");
Profiler timeUsed; Profiler timeUsed;
testUser->validatePwd("haz27Newpassword", nullptr); testUser->validatePwd("haz27Newpassword", nullptr);
ServerConfig::g_FakeLoginSleepTime = (int)std::round(timeUsed.millis()); ServerConfig::g_FakeLoginSleepTime = (int)std::round(timeUsed.millis());
delete testUser; delete testUser;
Poco::Int64 i1 = randombytes_random(); Poco::Int64 i1 = randombytes_random();
Poco::Int64 i2 = randombytes_random(); Poco::Int64 i2 = randombytes_random();
ServerConfig::g_ServerKeySeed->put(1, i1 | (i2 << 8)); ServerConfig::g_ServerKeySeed->put(1, i1 | (i2 << 8));
ServerConfig::initEMailAccount(config()); ServerConfig::initEMailAccount(config());
EmailManager::getInstance()->init(config()); EmailManager::getInstance()->init(config());
// start cpu scheduler // start cpu scheduler
uint8_t worker_count = Poco::Environment::processorCount() * 2; uint8_t worker_count = Poco::Environment::processorCount() * 2;
ServerConfig::g_CPUScheduler = new UniLib::controller::CPUSheduler(worker_count, "Default Worker"); ServerConfig::g_CPUScheduler = new UniLib::controller::CPUSheduler(worker_count, "Default Worker");
ServerConfig::g_CryptoCPUScheduler = new UniLib::controller::CPUSheduler(2, "Crypto Worker"); ServerConfig::g_CryptoCPUScheduler = new UniLib::controller::CPUSheduler(2, "Crypto Worker");
// load up connection configs // load up connection configs
// register MySQL connector // register MySQL connector
Poco::Data::MySQL::Connector::registerConnector(); Poco::Data::MySQL::Connector::registerConnector();
//Poco::Data::MySQL::Connector::KEY; //Poco::Data::MySQL::Connector::KEY;
auto conn = ConnectionManager::getInstance(); auto conn = ConnectionManager::getInstance();
//conn->setConnection() //conn->setConnection()
//printf("try connect login server mysql db\n"); //printf("try connect login server mysql db\n");
try { try {
conn->setConnectionsFromConfig(config(), CONNECTION_MYSQL_LOGIN_SERVER); conn->setConnectionsFromConfig(config(), CONNECTION_MYSQL_LOGIN_SERVER);
} }
catch (Poco::Exception& ex) { catch (Poco::Exception& ex) {
// maybe we in docker environment and db needs some time to start up // maybe we in docker environment and db needs some time to start up
// let's wait 10 seconds // let's wait 10 seconds
int count = 10; int count = 10;
while (count > 0) { while (count > 0) {
printf("\rwait on mysql/mariadb %d seconds...", count); printf("\rwait on mysql/mariadb %d seconds...", count);
count--; count--;
Poco::Thread::sleep(1000); Poco::Thread::sleep(1000);
} }
conn->setConnectionsFromConfig(config(), CONNECTION_MYSQL_LOGIN_SERVER); conn->setConnectionsFromConfig(config(), CONNECTION_MYSQL_LOGIN_SERVER);
} }
//printf("try connect php server mysql \n"); //printf("try connect php server mysql \n");
//conn->setConnectionsFromConfig(config(), CONNECTION_MYSQL_PHP_SERVER); //conn->setConnectionsFromConfig(config(), CONNECTION_MYSQL_PHP_SERVER);
SessionManager::getInstance()->init(); SessionManager::getInstance()->init();
// put urandom on linux servers // put urandom on linux servers
//srand(); //srand();
Poco::Net::initializeSSL(); Poco::Net::initializeSSL();
if(!ServerConfig::initSSLClientContext()) { if(!ServerConfig::initSSLClientContext()) {
//printf("[Gradido_LoginServer::%s] error init server SSL Client\n", __FUNCTION__); //printf("[Gradido_LoginServer::%s] error init server SSL Client\n", __FUNCTION__);
errorLog.error("[Gradido_LoginServer::main] error init server SSL Client\n"); errorLog.error("[Gradido_LoginServer::main] error init server SSL Client\n");
return Application::EXIT_CONFIG; return Application::EXIT_CONFIG;
} }
// schedule email verification resend // schedule email verification resend
controller::User::checkIfVerificationEmailsShouldBeResend(ServerConfig::g_CronJobsTimer); controller::User::checkIfVerificationEmailsShouldBeResend(ServerConfig::g_CronJobsTimer);
// HTTP Interface Server // HTTP Interface Server
// set-up a server socket // set-up a server socket
Poco::Net::ServerSocket svs(port); Poco::Net::ServerSocket svs(port);
// set-up a HTTPServer instance // set-up a HTTPServer instance
Poco::ThreadPool& pool = Poco::ThreadPool::defaultPool(); Poco::ThreadPool& pool = Poco::ThreadPool::defaultPool();
Poco::Net::HTTPServer srv(new PageRequestHandlerFactory, svs, new Poco::Net::HTTPServerParams); Poco::Net::HTTPServer srv(new PageRequestHandlerFactory, svs, new Poco::Net::HTTPServerParams);
ServerConfig::g_ServerKeySeed->put(7, 918276611); ServerConfig::g_ServerKeySeed->put(7, 918276611);
// start the HTTPServer // start the HTTPServer
srv.start(); srv.start();
// JSON Interface Server // JSON Interface Server
Poco::Net::ServerSocket json_svs(json_port); Poco::Net::ServerSocket json_svs(json_port);
Poco::Net::HTTPServer json_srv(new JsonRequestHandlerFactory, json_svs, new Poco::Net::HTTPServerParams); Poco::Net::HTTPServer json_srv(new JsonRequestHandlerFactory, json_svs, new Poco::Net::HTTPServerParams);
// start the json server // start the json server
json_srv.start(); json_srv.start();
printf("[Gradido_LoginServer::main] started in %s\n", usedTime.string().data()); printf("[Gradido_LoginServer::main] started in %s\n", usedTime.string().data());
// wait for CTRL-C or kill // wait for CTRL-C or kill
waitForTerminationRequest(); waitForTerminationRequest();
// Stop the HTTPServer // Stop the HTTPServer
srv.stop(); srv.stop();
// Stop the json server // Stop the json server
json_srv.stop(); json_srv.stop();
ServerConfig::unload(); ServerConfig::unload();
Poco::Net::uninitializeSSL(); Poco::Net::uninitializeSSL();
// Optional: Delete all global objects allocated by libprotobuf. // Optional: Delete all global objects allocated by libprotobuf.
google::protobuf::ShutdownProtobufLibrary(); google::protobuf::ShutdownProtobufLibrary();
} }
return Application::EXIT_OK; return Application::EXIT_OK;
} }

View File

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

View File

@ -1,365 +1,365 @@
#include "LoginPage.h" #include "LoginPage.h"
#include "Poco/Net/HTTPServerRequest.h" #include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h" #include "Poco/Net/HTTPServerResponse.h"
#include "Poco/Net/HTMLForm.h" #include "Poco/Net/HTMLForm.h"
#include "Poco/DeflatingStream.h" #include "Poco/DeflatingStream.h"
#line 7 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 7 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
#include "../gettext.h" #include "../gettext.h"
#include "Poco/Net/HTTPCookie.h" #include "Poco/Net/HTTPCookie.h"
#include "Poco/Net/HTTPServerParams.h" #include "Poco/Net/HTTPServerParams.h"
#include "Poco/Logger.h" #include "Poco/Logger.h"
#include "../SingletonManager/SessionManager.h" #include "../SingletonManager/SessionManager.h"
#include "../SingletonManager/LanguageManager.h" #include "../SingletonManager/LanguageManager.h"
#include "../SingletonManager/ErrorManager.h" #include "../SingletonManager/ErrorManager.h"
#line 1 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp" #line 1 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp"
#include "../ServerConfig.h" #include "../ServerConfig.h"
LoginPage::LoginPage(Session* arg): LoginPage::LoginPage(Session* arg):
SessionHTTPRequestHandler(arg) SessionHTTPRequestHandler(arg)
{ {
} }
void LoginPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) void LoginPage::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{ {
response.setChunkedTransferEncoding(true); response.setChunkedTransferEncoding(true);
response.setContentType("text/html"); response.setContentType("text/html");
bool _compressResponse(request.hasToken("Accept-Encoding", "gzip")); bool _compressResponse(request.hasToken("Accept-Encoding", "gzip"));
if (_compressResponse) response.set("Content-Encoding", "gzip"); if (_compressResponse) response.set("Content-Encoding", "gzip");
Poco::Net::HTMLForm form(request, request.stream()); Poco::Net::HTMLForm form(request, request.stream());
#line 18 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 18 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
const char* pageName = "Login"; const char* pageName = "Login";
auto sm = SessionManager::getInstance(); auto sm = SessionManager::getInstance();
auto lm = LanguageManager::getInstance(); auto lm = LanguageManager::getInstance();
auto em = ErrorManager::getInstance(); auto em = ErrorManager::getInstance();
auto lang = chooseLanguage(request); auto lang = chooseLanguage(request);
//printf("choose language return: %d\n", lang); //printf("choose language return: %d\n", lang);
auto langCatalog = lm->getFreeCatalog(lang); auto langCatalog = lm->getFreeCatalog(lang);
std::string presetEmail(""); std::string presetEmail("");
if(mSession && mSession->getUser()) { if(mSession && mSession->getUser()) {
presetEmail = mSession->getUser()->getEmail(); presetEmail = mSession->getUser()->getEmail();
} }
if(!form.empty()) { if(!form.empty()) {
bool langUpdatedByBtn = false; bool langUpdatedByBtn = false;
auto langBtn = form.get("lang", ""); auto langBtn = form.get("lang", "");
if(langBtn != "") { if(langBtn != "") {
langUpdatedByBtn = true; langUpdatedByBtn = true;
} }
/* /*
auto langInput = form.get("lang", ""); auto langInput = form.get("lang", "");
auto updatedLang = LANG_NULL; auto updatedLang = LANG_NULL;
if(langBtn != "") { if(langBtn != "") {
updatedLang = chooseLanguage(request, langBtn); updatedLang = chooseLanguage(request, langBtn);
langUpdatedByBtn = true; langUpdatedByBtn = true;
} else if(langInput != "") { } else if(langInput != "") {
updatedLang = chooseLanguage(request, langInput); updatedLang = chooseLanguage(request, langInput);
} }
if(updatedLang != LANG_NULL && updatedLang != lang) { if(updatedLang != LANG_NULL && updatedLang != lang) {
lang = updatedLang; lang = updatedLang;
langCatalog = lm->getFreeCatalog(lang); langCatalog = lm->getFreeCatalog(lang);
} }
*/ */
auto email = form.get("login-email", ""); auto email = form.get("login-email", "");
auto password = form.get("login-password", ""); auto password = form.get("login-password", "");
if(email != "" && password != "") { if(email != "" && password != "") {
//auto session = sm->getSession(request); //auto session = sm->getSession(request);
//if(!mSession) mSession = sm->findByEmail(email); //if(!mSession) mSession = sm->findByEmail(email);
if(!mSession) { if(!mSession) {
mSession = sm->getNewSession(); mSession = sm->getNewSession();
mSession->setLanguageCatalog(langCatalog); mSession->setLanguageCatalog(langCatalog);
// get language // get language
// first check url, second check language header // first check url, second check language header
// for debugging client ip // for debugging client ip
auto client_host = request.clientAddress().host(); auto client_host = request.clientAddress().host();
//auto client_ip = request.clientAddress(); //auto client_ip = request.clientAddress();
// X-Real-IP forwarded ip from nginx config // X-Real-IP forwarded ip from nginx config
auto client_host_string = request.get("X-Real-IP", client_host.toString()); auto client_host_string = request.get("X-Real-IP", client_host.toString());
std::string clientIpString = "client ip: "; std::string clientIpString = "client ip: ";
client_host = Poco::Net::IPAddress(client_host_string); client_host = Poco::Net::IPAddress(client_host_string);
clientIpString += client_host_string; clientIpString += client_host_string;
Poco::Logger::get("requestLog").information(clientIpString); Poco::Logger::get("requestLog").information(clientIpString);
// debugging end // debugging end
mSession->setClientIp(client_host); mSession->setClientIp(client_host);
response.addCookie(mSession->getLoginCookie()); response.addCookie(mSession->getLoginCookie());
} else { } else {
langCatalog = mSession->getLanguageCatalog(); langCatalog = mSession->getLanguageCatalog();
} }
UserStates user_state; UserStates user_state;
try { try {
user_state = mSession->loadUser(email, password); user_state = mSession->loadUser(email, password);
} catch (Poco::Exception& ex) { } catch (Poco::Exception& ex) {
addError(new ParamError("login", "exception by calling loadUser: ", ex.displayText())); addError(new ParamError("login", "exception by calling loadUser: ", ex.displayText()));
sendErrorsAsEmail(); sendErrorsAsEmail();
addError(new Error("Error", "Intern Server error, please try again later")); addError(new Error("Error", "Intern Server error, please try again later"));
} }
auto user = mSession->getNewUser(); auto user = mSession->getNewUser();
if(user_state >= USER_LOADED_FROM_DB && !user.isNull() && !user->getModel()->getPublicKey()) { if(user_state >= USER_LOADED_FROM_DB && !user.isNull() && !user->getModel()->getPublicKey()) {
if(mSession->generateKeys(true, true)) { if(mSession->generateKeys(true, true)) {
user_state = USER_COMPLETE; user_state = USER_COMPLETE;
if(user->getModel()->isDisabled()) { if(user->getModel()->isDisabled()) {
user_state = USER_DISABLED; user_state = USER_DISABLED;
} }
} }
} else { } else {
//printf("pubkey exist: %p\n",user->getModel()->getPublicKey()); //printf("pubkey exist: %p\n",user->getModel()->getPublicKey());
} }
getErrors(mSession); getErrors(mSession);
auto uri_start = request.serverParams().getServerName(); auto uri_start = request.serverParams().getServerName();
auto lastExternReferer = mSession->getLastReferer(); auto lastExternReferer = mSession->getLastReferer();
printf("user_state: %d\n", user_state); printf("user_state: %d\n", user_state);
switch(user_state) { switch(user_state) {
case USER_EMPTY: case USER_EMPTY:
case USER_PASSWORD_INCORRECT: case USER_PASSWORD_INCORRECT:
addError(new Error(langCatalog->gettext("Login"), langCatalog->gettext("E-Mail or password isn't right, please try again!")), false); addError(new Error(langCatalog->gettext("Login"), langCatalog->gettext("E-Mail or password isn't right, please try again!")), false);
if(mSession) { if(mSession) {
getErrors(mSession); getErrors(mSession);
sm->releaseSession(mSession); sm->releaseSession(mSession);
} }
sm->deleteLoginCookies(request, response); sm->deleteLoginCookies(request, response);
break; break;
case USER_PASSWORD_ENCRYPTION_IN_PROCESS: case USER_PASSWORD_ENCRYPTION_IN_PROCESS:
addError(new Error(langCatalog->gettext("Passwort"), langCatalog->gettext("Passwort wird noch berechnet, bitte versuche es in etwa 1 Minute erneut.")), false); addError(new Error(langCatalog->gettext("Passwort"), langCatalog->gettext("Passwort wird noch berechnet, bitte versuche es in etwa 1 Minute erneut.")), false);
break; break;
case USER_KEYS_DONT_MATCH: case USER_KEYS_DONT_MATCH:
addError(new Error(langCatalog->gettext("User"), langCatalog->gettext("Error in saved data, the server admin will look at it."))); addError(new Error(langCatalog->gettext("User"), langCatalog->gettext("Error in saved data, the server admin will look at it.")));
break; break;
case USER_DISABLED: case USER_DISABLED:
addError(new Error(langCatalog->gettext("User"), langCatalog->gettext("Benutzer ist deaktiviert, kein Login möglich!"))); addError(new Error(langCatalog->gettext("User"), langCatalog->gettext("Benutzer ist deaktiviert, kein Login möglich!")));
if(mSession) { if(mSession) {
getErrors(mSession); getErrors(mSession);
sm->releaseSession(mSession); sm->releaseSession(mSession);
} }
sm->deleteLoginCookies(request, response); sm->deleteLoginCookies(request, response);
break; break;
case USER_NO_PRIVATE_KEY: case USER_NO_PRIVATE_KEY:
case USER_COMPLETE: case USER_COMPLETE:
case USER_EMAIL_NOT_ACTIVATED: case USER_EMAIL_NOT_ACTIVATED:
auto referer = request.find("Referer"); auto referer = request.find("Referer");
std::string refererString; std::string refererString;
if (referer != request.end()) { if (referer != request.end()) {
refererString = referer->second; refererString = referer->second;
} }
if(lastExternReferer != "") { if(lastExternReferer != "") {
//printf("redirect to: %s\n", lastExternReferer.data()); //printf("redirect to: %s\n", lastExternReferer.data());
response.redirect(lastExternReferer); response.redirect(lastExternReferer);
} else if(refererString != "" && } else if(refererString != "" &&
refererString.find("login") == std::string::npos && refererString.find("login") == std::string::npos &&
refererString.find("logout") == std::string::npos && refererString.find("logout") == std::string::npos &&
refererString.find("user_delete") == std::string::npos && refererString.find("user_delete") == std::string::npos &&
refererString != ServerConfig::g_serverPath + request.getURI()) { refererString != ServerConfig::g_serverPath + request.getURI()) {
std::string uri = request.getURI(); std::string uri = request.getURI();
printf("request uri: %s, redirect to: %s\n", uri.data(), refererString.data()); printf("request uri: %s, redirect to: %s\n", uri.data(), refererString.data());
response.redirect(refererString); response.redirect(refererString);
} else { } else {
//printf("redirect to: %s\n", ServerConfig::g_php_serverPath.data()); //printf("redirect to: %s\n", ServerConfig::g_php_serverPath.data());
response.redirect(ServerConfig::g_php_serverPath + "/"); response.redirect(ServerConfig::g_php_serverPath + "/");
} }
return; return;
} }
} else if(!langUpdatedByBtn) { } else if(!langUpdatedByBtn) {
addError(new Error(langCatalog->gettext("Login"), langCatalog->gettext("Username and password are needed!")), false); addError(new Error(langCatalog->gettext("Login"), langCatalog->gettext("Username and password are needed!")), false);
} }
} else { } else {
// on enter login page with empty form // on enter login page with empty form
//auto session = sm->getSession(request); //auto session = sm->getSession(request);
// remove old cookies and session if exist // remove old cookies and session if exist
if(mSession) { if(mSession) {
getErrors(mSession); getErrors(mSession);
sm->releaseSession(mSession); sm->releaseSession(mSession);
} }
sm->deleteLoginCookies(request, response); sm->deleteLoginCookies(request, response);
} }
#line 3 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp" #line 3 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp"
bool withMaterialIcons = false; bool withMaterialIcons = false;
std::ostream& _responseStream = response.send(); std::ostream& _responseStream = response.send();
Poco::DeflatingOutputStream _gzipStream(_responseStream, Poco::DeflatingStreamBuf::STREAM_GZIP, 1); Poco::DeflatingOutputStream _gzipStream(_responseStream, Poco::DeflatingStreamBuf::STREAM_GZIP, 1);
std::ostream& responseStream = _compressResponse ? _gzipStream : _responseStream; std::ostream& responseStream = _compressResponse ? _gzipStream : _responseStream;
responseStream << "\n"; responseStream << "\n";
// begin include header.cpsp // begin include header.cpsp
responseStream << "\n"; responseStream << "\n";
responseStream << "<!DOCTYPE html>\n"; responseStream << "<!DOCTYPE html>\n";
responseStream << "<html>\n"; responseStream << "<html>\n";
responseStream << "<head>\n"; responseStream << "<head>\n";
responseStream << "<meta charset=\"UTF-8\">\n"; responseStream << "<meta charset=\"UTF-8\">\n";
responseStream << "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n"; responseStream << "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n";
responseStream << "<title>Gradido Login Server: "; responseStream << "<title>Gradido Login Server: ";
#line 11 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp" #line 11 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp"
responseStream << ( pageName ); responseStream << ( pageName );
responseStream << "</title>\n"; responseStream << "</title>\n";
responseStream << "<link rel=\"stylesheet\" type=\"text/css\" href=\""; responseStream << "<link rel=\"stylesheet\" type=\"text/css\" href=\"";
#line 12 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp" #line 12 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp"
responseStream << ( ServerConfig::g_php_serverPath ); responseStream << ( ServerConfig::g_php_serverPath );
responseStream << "css/main.css\">\n"; responseStream << "css/main.css\">\n";
#line 13 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp" #line 13 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp"
if(withMaterialIcons) { responseStream << "\n"; if(withMaterialIcons) { responseStream << "\n";
responseStream << "<link rel=\"stylesheet\" type=\"text/css\" href=\""; responseStream << "<link rel=\"stylesheet\" type=\"text/css\" href=\"";
#line 14 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp" #line 14 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp"
responseStream << ( ServerConfig::g_php_serverPath ); responseStream << ( ServerConfig::g_php_serverPath );
responseStream << "css/materialdesignicons.min.css\">\n"; responseStream << "css/materialdesignicons.min.css\">\n";
#line 15 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp" #line 15 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp"
} responseStream << "\n"; } responseStream << "\n";
responseStream << "</head>\n"; responseStream << "</head>\n";
responseStream << "<body>\n"; responseStream << "<body>\n";
responseStream << " <div class=\"layout\">\n"; responseStream << " <div class=\"layout\">\n";
responseStream << " <div class=\"center-form-single\">\n"; responseStream << " <div class=\"center-form-single\">\n";
responseStream << " <div class=\"center-form-header\">\n"; responseStream << " <div class=\"center-form-header\">\n";
responseStream << " <a href=\""; responseStream << " <a href=\"";
#line 21 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp" #line 21 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp"
responseStream << ( ServerConfig::g_php_serverPath ); responseStream << ( ServerConfig::g_php_serverPath );
responseStream << "\" class=\"center-logo\">\n"; responseStream << "\" class=\"center-logo\">\n";
responseStream << " <picture>\n"; responseStream << " <picture>\n";
responseStream << " <source srcset=\""; responseStream << " <source srcset=\"";
#line 23 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp" #line 23 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp"
responseStream << ( ServerConfig::g_php_serverPath ); responseStream << ( ServerConfig::g_php_serverPath );
responseStream << "img/logo_schrift.webp\" type=\"image/webp\">\n"; responseStream << "img/logo_schrift.webp\" type=\"image/webp\">\n";
responseStream << " <source srcset=\""; responseStream << " <source srcset=\"";
#line 24 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp" #line 24 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp"
responseStream << ( ServerConfig::g_php_serverPath ); responseStream << ( ServerConfig::g_php_serverPath );
responseStream << "img/logo_schrift.png\" type=\"image/png\">\n"; responseStream << "img/logo_schrift.png\" type=\"image/png\">\n";
responseStream << " <img src=\""; responseStream << " <img src=\"";
#line 25 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp" #line 25 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\header.cpsp"
responseStream << ( ServerConfig::g_php_serverPath ); responseStream << ( ServerConfig::g_php_serverPath );
responseStream << "img/logo_schrift.png\" alt=\"logo\" />\n"; responseStream << "img/logo_schrift.png\" alt=\"logo\" />\n";
responseStream << " </picture>\n"; responseStream << " </picture>\n";
responseStream << " </a>\n"; responseStream << " </a>\n";
responseStream << " </div>"; responseStream << " </div>";
// end include header.cpsp // end include header.cpsp
responseStream << "\n"; responseStream << "\n";
#line 175 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 175 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
responseStream << ( getErrorsHtml() ); responseStream << ( getErrorsHtml() );
responseStream << "\n"; responseStream << "\n";
responseStream << "<!--<input type=\"hidden\" name=\"lang\" value=\""; responseStream << "<!--<input type=\"hidden\" name=\"lang\" value=\"";
#line 176 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 176 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
responseStream << ( LanguageManager::keyForLanguage(lang) ); responseStream << ( LanguageManager::keyForLanguage(lang) );
responseStream << "\">-->\n"; responseStream << "\">-->\n";
responseStream << "<div class=\"center-form-container\">\n"; responseStream << "<div class=\"center-form-container\">\n";
responseStream << " "; responseStream << " ";
// begin include flags.cpsp // begin include flags.cpsp
responseStream << "<div class=\"center-form-selectors\">\n"; responseStream << "<div class=\"center-form-selectors\">\n";
responseStream << "<form method=\"GET\" action=\"\">\n"; responseStream << "<form method=\"GET\" action=\"\">\n";
responseStream << "\t<button id=\"flag-england\" name=\"lang\" value=\"en\" title=\"English\" type=\"submit\" "; responseStream << "\t<button id=\"flag-england\" name=\"lang\" value=\"en\" title=\"English\" type=\"submit\" ";
#line 3 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\flags.cpsp" #line 3 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\flags.cpsp"
if(lang != LANG_EN) { responseStream << "class=\"flag-btn\""; if(lang != LANG_EN) { responseStream << "class=\"flag-btn\"";
#line 3 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\flags.cpsp" #line 3 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\flags.cpsp"
} }
else { responseStream << "class=\"flag-btn\" disabled"; else { responseStream << "class=\"flag-btn\" disabled";
#line 4 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\flags.cpsp" #line 4 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\flags.cpsp"
} responseStream << ">\n"; } responseStream << ">\n";
responseStream << "\t <span class=\"flag flag-england\"></span>\n"; responseStream << "\t <span class=\"flag flag-england\"></span>\n";
responseStream << "\t</button>\n"; responseStream << "\t</button>\n";
responseStream << "\t<button id=\"flag-germany\" name=\"lang\" value=\"de\" title=\"Deutsch\" type=\"submit\" "; responseStream << "\t<button id=\"flag-germany\" name=\"lang\" value=\"de\" title=\"Deutsch\" type=\"submit\" ";
#line 7 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\flags.cpsp" #line 7 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\flags.cpsp"
if(lang != LANG_DE) { responseStream << "class=\"flag-btn\""; if(lang != LANG_DE) { responseStream << "class=\"flag-btn\"";
#line 7 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\flags.cpsp" #line 7 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\flags.cpsp"
} }
else { responseStream << "class=\"flag-btn\" disabled"; else { responseStream << "class=\"flag-btn\" disabled";
#line 8 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\flags.cpsp" #line 8 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\flags.cpsp"
} responseStream << ">\n"; } responseStream << ">\n";
responseStream << "\t <span class=\"flag flag-germany\"></span>\n"; responseStream << "\t <span class=\"flag flag-germany\"></span>\n";
responseStream << "\t</button>\n"; responseStream << "\t</button>\n";
responseStream << "</form>\n"; responseStream << "</form>\n";
responseStream << "</div>"; responseStream << "</div>";
// end include flags.cpsp // end include flags.cpsp
responseStream << "\n"; responseStream << "\n";
responseStream << " <div class=\"center-form-form\">\n"; responseStream << " <div class=\"center-form-form\">\n";
responseStream << "\t\t<form action=\""; responseStream << "\t\t<form action=\"";
#line 180 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 180 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
responseStream << ( ServerConfig::g_serverPath ); responseStream << ( ServerConfig::g_serverPath );
responseStream << "/\" method=\"POST\">\n"; responseStream << "/\" method=\"POST\">\n";
responseStream << "\t\t\t<input class=\"form-control\" type=\"text\" name=\"login-email\" placeholder=\""; responseStream << "\t\t\t<input class=\"form-control\" type=\"text\" name=\"login-email\" placeholder=\"";
#line 181 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 181 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
responseStream << ( langCatalog->gettext("E-Mail") ); responseStream << ( langCatalog->gettext("E-Mail") );
responseStream << "\" value=\""; responseStream << "\" value=\"";
#line 181 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 181 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
responseStream << ( presetEmail ); responseStream << ( presetEmail );
responseStream << "\"/>\n"; responseStream << "\"/>\n";
responseStream << "\t\t\t<input class=\"form-control\" type=\"password\" name=\"login-password\" placeholder=\""; responseStream << "\t\t\t<input class=\"form-control\" type=\"password\" name=\"login-password\" placeholder=\"";
#line 182 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 182 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
responseStream << ( langCatalog->gettext("Password") ); responseStream << ( langCatalog->gettext("Password") );
responseStream << "\" />\n"; responseStream << "\" />\n";
responseStream << "\t\t <button type=\"submit\" name=\"submit\" class=\"center-form-submit form-button\">"; responseStream << "\t\t <button type=\"submit\" name=\"submit\" class=\"center-form-submit form-button\">";
#line 183 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 183 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
responseStream << ( langCatalog->gettext(" Login ") ); responseStream << ( langCatalog->gettext(" Login ") );
responseStream << "</button>\n"; responseStream << "</button>\n";
responseStream << "\t\t</form>\n"; responseStream << "\t\t</form>\n";
responseStream << " </div>\n"; responseStream << " </div>\n";
responseStream << " <div class=\"center-form-bottom\">\n"; responseStream << " <div class=\"center-form-bottom\">\n";
responseStream << " <div class=\"signup-link\">\n"; responseStream << " <div class=\"signup-link\">\n";
responseStream << "\t <p>"; responseStream << "\t <p>";
#line 188 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 188 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
responseStream << ( langCatalog->gettext("You haven't any account yet? Please follow the link to create one.") ); responseStream << ( langCatalog->gettext("You haven't any account yet? Please follow the link to create one.") );
responseStream << "</p>\n"; responseStream << "</p>\n";
responseStream << "\t <a href=\"https://elopage.com/s/gradido/registration-de/payment?locale=de\">\n"; responseStream << "\t <a href=\"https://elopage.com/s/gradido/registration-de/payment?locale=de\">\n";
responseStream << "\t\t\t"; responseStream << "\t\t\t";
#line 190 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 190 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
responseStream << ( langCatalog->gettext("Create New Account") ); responseStream << ( langCatalog->gettext("Create New Account") );
responseStream << "\n"; responseStream << "\n";
responseStream << "\t\t </a>\n"; responseStream << "\t\t </a>\n";
responseStream << "\t </div>\n"; responseStream << "\t </div>\n";
responseStream << "\t\t<div class=\"reset-pwd-link\">\n"; responseStream << "\t\t<div class=\"reset-pwd-link\">\n";
responseStream << "\t\t\t<a href=\""; responseStream << "\t\t\t<a href=\"";
#line 194 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 194 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
responseStream << ( ServerConfig::g_serverPath ); responseStream << ( ServerConfig::g_serverPath );
responseStream << "/resetPassword\">"; responseStream << "/resetPassword\">";
#line 194 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp" #line 194 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\login.cpsp"
responseStream << ( langCatalog->gettext("Passwort vergessen") ); responseStream << ( langCatalog->gettext("Passwort vergessen") );
responseStream << "</a>\n"; responseStream << "</a>\n";
responseStream << "\t\t</div>\n"; responseStream << "\t\t</div>\n";
responseStream << "\t</div>\n"; responseStream << "\t</div>\n";
responseStream << "</div>\n"; responseStream << "</div>\n";
responseStream << "<p>&nbsp;</p>\n"; responseStream << "<p>&nbsp;</p>\n";
responseStream << "<div class=\"container\">\n"; responseStream << "<div class=\"container\">\n";
responseStream << "\t<a href=\"https://docs.google.com/document/d/1jZp-DiiMPI9ZPNXmjsvOQ1BtnfDFfx8BX7CDmA8KKjY/edit?usp=sharing\" target=\"_blank\">Zum Whitepaper</a>\n"; responseStream << "\t<a href=\"https://docs.google.com/document/d/1jZp-DiiMPI9ZPNXmjsvOQ1BtnfDFfx8BX7CDmA8KKjY/edit?usp=sharing\" target=\"_blank\">Zum Whitepaper</a>\n";
responseStream << "\t<br>\n"; responseStream << "\t<br>\n";
responseStream << "\t<br>\n"; responseStream << "\t<br>\n";
responseStream << "\t<a href=\"https://docs.google.com/document/d/1kcX1guOi6tDgnFHD9tf7fB_MneKTx-0nHJxzdN8ygNs/edit?usp=sharing\" target=\"_blank\">To the Whitepaper</a>\n"; responseStream << "\t<a href=\"https://docs.google.com/document/d/1kcX1guOi6tDgnFHD9tf7fB_MneKTx-0nHJxzdN8ygNs/edit?usp=sharing\" target=\"_blank\">To the Whitepaper</a>\n";
responseStream << "</div>\n"; responseStream << "</div>\n";
// begin include footer.cpsp // begin include footer.cpsp
responseStream << " <div class=\"center-bottom\">\n"; responseStream << " <div class=\"center-bottom\">\n";
responseStream << " <p>Copyright © Gradido 2020</p>\n"; responseStream << " <p>Copyright © Gradido 2020</p>\n";
responseStream << " </div>\n"; responseStream << " </div>\n";
responseStream << " </div>\n"; responseStream << " </div>\n";
responseStream << " <div class=\"bottomleft\">\n"; responseStream << " <div class=\"bottomleft\">\n";
responseStream << " "; responseStream << " ";
#line 6 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\footer.cpsp" #line 6 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\footer.cpsp"
responseStream << ( mTimeProfiler.string() ); responseStream << ( mTimeProfiler.string() );
responseStream << "\n"; responseStream << "\n";
responseStream << " </div>\n"; responseStream << " </div>\n";
responseStream << " <div class=\"bottomright\">\n"; responseStream << " <div class=\"bottomright\">\n";
responseStream << " <p>Login Server in Entwicklung</p>\n"; responseStream << " <p>Login Server in Entwicklung</p>\n";
responseStream << " <p>Alpha "; responseStream << " <p>Alpha ";
#line 10 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\footer.cpsp" #line 10 "F:\\Gradido\\gradido_local\\login_server\\src\\cpsp\\footer.cpsp"
responseStream << ( ServerConfig::g_versionString ); responseStream << ( ServerConfig::g_versionString );
responseStream << "</p>\n"; responseStream << "</p>\n";
responseStream << " </div>\n"; responseStream << " </div>\n";
responseStream << " </div>\n"; responseStream << " </div>\n";
responseStream << "</body>\n"; responseStream << "</body>\n";
responseStream << "\n"; responseStream << "\n";
responseStream << "</html>"; responseStream << "</html>";
// end include footer.cpsp // end include footer.cpsp
if (_compressResponse) _gzipStream.close(); if (_compressResponse) _gzipStream.close();
} }

View File

@ -1,20 +1,20 @@
#ifndef LoginPage_INCLUDED #ifndef LoginPage_INCLUDED
#define LoginPage_INCLUDED #define LoginPage_INCLUDED
#include "Poco/Net/HTTPRequestHandler.h" #include "Poco/Net/HTTPRequestHandler.h"
#include "SessionHTTPRequestHandler.h" #include "SessionHTTPRequestHandler.h"
class LoginPage: public SessionHTTPRequestHandler class LoginPage: public SessionHTTPRequestHandler
{ {
public: public:
LoginPage(Session*); LoginPage(Session*);
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response); void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response);
}; };
#endif // LoginPage_INCLUDED #endif // LoginPage_INCLUDED

View File

@ -1,108 +1,108 @@
#include "JsonCreateUser.h" #include "JsonCreateUser.h"
#include "../model/email/Email.h" #include "../model/email/Email.h"
#include "../controller/User.h" #include "../controller/User.h"
#include "../controller/EmailVerificationCode.h" #include "../controller/EmailVerificationCode.h"
#include "../SingletonManager/EmailManager.h" #include "../SingletonManager/EmailManager.h"
#include "../SingletonManager/SessionManager.h" #include "../SingletonManager/SessionManager.h"
#include "../tasks/AuthenticatedEncryptionCreateKeyTask.h" #include "../tasks/AuthenticatedEncryptionCreateKeyTask.h"
Poco::JSON::Object* JsonCreateUser::handle(Poco::Dynamic::Var params) Poco::JSON::Object* JsonCreateUser::handle(Poco::Dynamic::Var params)
{ {
std::string email; std::string email;
std::string first_name; std::string first_name;
std::string last_name; std::string last_name;
std::string password; std::string password;
bool login_after_register = false; bool login_after_register = false;
int emailType; int emailType;
auto em = EmailManager::getInstance(); auto em = EmailManager::getInstance();
auto sm = SessionManager::getInstance(); auto sm = SessionManager::getInstance();
// if is json object // if is json object
if (params.type() == typeid(Poco::JSON::Object::Ptr)) { if (params.type() == typeid(Poco::JSON::Object::Ptr)) {
Poco::JSON::Object::Ptr paramJsonObject = params.extract<Poco::JSON::Object::Ptr>(); Poco::JSON::Object::Ptr paramJsonObject = params.extract<Poco::JSON::Object::Ptr>();
/// Throws a RangeException if the value does not fit /// Throws a RangeException if the value does not fit
/// into the result variable. /// into the result variable.
/// Throws a NotImplementedException if conversion is /// Throws a NotImplementedException if conversion is
/// not available for the given type. /// not available for the given type.
/// Throws InvalidAccessException if Var is empty. /// Throws InvalidAccessException if Var is empty.
try { try {
paramJsonObject->get("email").convert(email); paramJsonObject->get("email").convert(email);
paramJsonObject->get("first_name").convert(first_name); paramJsonObject->get("first_name").convert(first_name);
paramJsonObject->get("last_name").convert(last_name); paramJsonObject->get("last_name").convert(last_name);
paramJsonObject->get("emailType").convert(emailType); paramJsonObject->get("emailType").convert(emailType);
if ((ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_PASSWORD_REQUESTS)) { if ((ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_PASSWORD_REQUESTS)) {
paramJsonObject->get("password").convert(password); paramJsonObject->get("password").convert(password);
} }
if (!paramJsonObject->isNull("login_after_register")) { if (!paramJsonObject->isNull("login_after_register")) {
paramJsonObject->get("login_after_register").convert(login_after_register); paramJsonObject->get("login_after_register").convert(login_after_register);
} }
} }
catch (Poco::Exception& ex) { catch (Poco::Exception& ex) {
return stateError("json exception", ex.displayText()); return stateError("json exception", ex.displayText());
} }
} }
else { else {
return stateError("parameter format unknown"); return stateError("parameter format unknown");
} }
auto user = controller::User::create(); auto user = controller::User::create();
if (user->load(email) > 0) { if (user->load(email) > 0) {
return customStateError("exist", "user already exist"); return customStateError("exist", "user already exist");
} }
if (password.size()) { if (password.size()) {
ErrorList errors; ErrorList errors;
if (!sm->checkPwdValidation(password, &errors)) { if (!sm->checkPwdValidation(password, &errors)) {
Poco::JSON::Object* result = new Poco::JSON::Object; Poco::JSON::Object* result = new Poco::JSON::Object;
result->set("state", "error"); result->set("state", "error");
result->set("msg", errors.getLastError()->getString(false)); result->set("msg", errors.getLastError()->getString(false));
if (errors.errorCount()) { if (errors.errorCount()) {
result->set("details", errors.getLastError()->getString(false)); result->set("details", errors.getLastError()->getString(false));
} }
return result; return result;
} }
} }
// create user // create user
user = controller::User::create(email, first_name, last_name); user = controller::User::create(email, first_name, last_name);
auto userModel = user->getModel(); auto userModel = user->getModel();
Session* session = nullptr; Session* session = nullptr;
if (!userModel->insertIntoDB(true)) { if (!userModel->insertIntoDB(true)) {
userModel->sendErrorsAsEmail(); userModel->sendErrorsAsEmail();
return stateError("insert user failed"); return stateError("insert user failed");
} }
if (password.size()) { if (password.size()) {
session = sm->getNewSession(); session = sm->getNewSession();
session->setUser(user); session->setUser(user);
session->generateKeys(true, true); session->generateKeys(true, true);
session->setClientIp(mClientIP); session->setClientIp(mClientIP);
// calculate encryption key, could need some time, will save encrypted privkey to db // calculate encryption key, could need some time, will save encrypted privkey to db
UniLib::controller::TaskPtr create_authenticated_encrypten_key = new AuthenticatedEncryptionCreateKeyTask(user, password); UniLib::controller::TaskPtr create_authenticated_encrypten_key = new AuthenticatedEncryptionCreateKeyTask(user, password);
create_authenticated_encrypten_key->scheduleTask(create_authenticated_encrypten_key); create_authenticated_encrypten_key->scheduleTask(create_authenticated_encrypten_key);
} }
auto emailOptIn = controller::EmailVerificationCode::create(userModel->getID(), model::table::EMAIL_OPT_IN_REGISTER); auto emailOptIn = controller::EmailVerificationCode::create(userModel->getID(), model::table::EMAIL_OPT_IN_REGISTER);
auto emailOptInModel = emailOptIn->getModel(); auto emailOptInModel = emailOptIn->getModel();
if (!emailOptInModel->insertIntoDB(false)) { if (!emailOptInModel->insertIntoDB(false)) {
emailOptInModel->sendErrorsAsEmail(); emailOptInModel->sendErrorsAsEmail();
return stateError("insert emailOptIn failed"); return stateError("insert emailOptIn failed");
} }
em->addEmail(new model::Email(emailOptIn, user, model::Email::convertTypeFromInt(emailType))); em->addEmail(new model::Email(emailOptIn, user, model::Email::convertTypeFromInt(emailType)));
if (login_after_register && session) { if (login_after_register && session) {
Poco::JSON::Object* result = stateSuccess(); Poco::JSON::Object* result = stateSuccess();
result->set("session_id", session->getHandle()); result->set("session_id", session->getHandle());
return result; return result;
} }
return stateSuccess(); return stateSuccess();
} }

View File

@ -1,144 +1,144 @@
#include "JsonGetUserInfos.h" #include "JsonGetUserInfos.h"
#include "../lib/DataTypeConverter.h" #include "../lib/DataTypeConverter.h"
#include "../SingletonManager/SessionManager.h" #include "../SingletonManager/SessionManager.h"
#include "../controller/User.h" #include "../controller/User.h"
#include "../controller/EmailVerificationCode.h" #include "../controller/EmailVerificationCode.h"
#include "../ServerConfig.h" #include "../ServerConfig.h"
Poco::UInt64 JsonGetUserInfos::readOrCreateEmailVerificationCode(int user_id, model::table::EmailOptInType type) Poco::UInt64 JsonGetUserInfos::readOrCreateEmailVerificationCode(int user_id, model::table::EmailOptInType type)
{ {
try { try {
auto emailVerificationCode = controller::EmailVerificationCode::load(user_id, type); auto emailVerificationCode = controller::EmailVerificationCode::load(user_id, type);
if (!emailVerificationCode) { if (!emailVerificationCode) {
emailVerificationCode = controller::EmailVerificationCode::create(user_id, type); emailVerificationCode = controller::EmailVerificationCode::create(user_id, type);
UniLib::controller::TaskPtr insert = new model::table::ModelInsertTask(emailVerificationCode->getModel(), false); UniLib::controller::TaskPtr insert = new model::table::ModelInsertTask(emailVerificationCode->getModel(), false);
insert->scheduleTask(insert); insert->scheduleTask(insert);
} }
return emailVerificationCode->getModel()->getCode(); return emailVerificationCode->getModel()->getCode();
} }
catch (Poco::Exception& ex) { catch (Poco::Exception& ex) {
ErrorList errors; ErrorList errors;
//printf("exception: %s\n", ex.displayText().data()); //printf("exception: %s\n", ex.displayText().data());
errors.addError(new ParamError("JsonGetUserInfos::readOrCreateEmailVerificationCode", "exception: ", ex.displayText())); errors.addError(new ParamError("JsonGetUserInfos::readOrCreateEmailVerificationCode", "exception: ", ex.displayText()));
errors.sendErrorsAsEmail(); errors.sendErrorsAsEmail();
} }
return 0; return 0;
} }
Poco::JSON::Object* JsonGetUserInfos::handle(Poco::Dynamic::Var params) Poco::JSON::Object* JsonGetUserInfos::handle(Poco::Dynamic::Var params)
{ {
/* /*
'session_id' => $session_id, 'session_id' => $session_id,
'email' => $email, 'email' => $email,
'ask' => ['EmailOptIn.Register'] 'ask' => ['EmailOptIn.Register']
*/ */
// incoming // incoming
int session_id = 0; int session_id = 0;
std::string email; std::string email;
Poco::JSON::Array::Ptr askArray; Poco::JSON::Array::Ptr askArray;
auto sm = SessionManager::getInstance(); auto sm = SessionManager::getInstance();
// if is json object // if is json object
if (params.type() == typeid(Poco::JSON::Object::Ptr)) { if (params.type() == typeid(Poco::JSON::Object::Ptr)) {
Poco::JSON::Object::Ptr paramJsonObject = params.extract<Poco::JSON::Object::Ptr>(); Poco::JSON::Object::Ptr paramJsonObject = params.extract<Poco::JSON::Object::Ptr>();
/// Throws a RangeException if the value does not fit /// Throws a RangeException if the value does not fit
/// into the result variable. /// into the result variable.
/// Throws a NotImplementedException if conversion is /// Throws a NotImplementedException if conversion is
/// not available for the given type. /// not available for the given type.
/// Throws InvalidAccessException if Var is empty. /// Throws InvalidAccessException if Var is empty.
try { try {
paramJsonObject->get("email").convert(email); paramJsonObject->get("email").convert(email);
paramJsonObject->get("session_id").convert(session_id); paramJsonObject->get("session_id").convert(session_id);
askArray = paramJsonObject->getArray("ask"); askArray = paramJsonObject->getArray("ask");
} }
catch (Poco::Exception& ex) { catch (Poco::Exception& ex) {
return stateError("json exception", ex.displayText()); return stateError("json exception", ex.displayText());
} }
} }
else { else {
return stateError("parameter format unknown"); return stateError("parameter format unknown");
} }
if (!session_id) { if (!session_id) {
return stateError("session_id invalid"); return stateError("session_id invalid");
} }
if (askArray.isNull()) { if (askArray.isNull()) {
return stateError("ask is zero or not an array"); return stateError("ask is zero or not an array");
} }
auto session = sm->getSession(session_id); auto session = sm->getSession(session_id);
if (!session) { if (!session) {
return customStateError("not found", "session not found"); return customStateError("not found", "session not found");
} }
auto session_user = session->getNewUser(); auto session_user = session->getNewUser();
auto session_user_model = session_user->getModel(); auto session_user_model = session_user->getModel();
bool isAdmin = false; bool isAdmin = false;
bool emailBelongToUser = false; bool emailBelongToUser = false;
if (model::table::ROLE_ADMIN == session_user_model->getRole()) { if (model::table::ROLE_ADMIN == session_user_model->getRole()) {
isAdmin = true; isAdmin = true;
} }
if (session_user_model->getEmail() == email) { if (session_user_model->getEmail() == email) {
emailBelongToUser = true; emailBelongToUser = true;
} }
auto user = controller::User::create(); auto user = controller::User::create();
if (1 != user->load(email)) { if (1 != user->load(email)) {
return customStateError("not found", "user not found"); return customStateError("not found", "user not found");
} }
auto user_model = user->getModel(); auto user_model = user->getModel();
Poco::JSON::Object* result = new Poco::JSON::Object; Poco::JSON::Object* result = new Poco::JSON::Object;
result->set("state", "success"); result->set("state", "success");
Poco::JSON::Array jsonErrorsArray; Poco::JSON::Array jsonErrorsArray;
Poco::JSON::Object jsonUser; Poco::JSON::Object jsonUser;
Poco::JSON::Object jsonServer; Poco::JSON::Object jsonServer;
for (auto it = askArray->begin(); it != askArray->end(); it++) { for (auto it = askArray->begin(); it != askArray->end(); it++) {
auto parameter = *it; auto parameter = *it;
std::string parameterString; std::string parameterString;
try { try {
parameter.convert(parameterString); parameter.convert(parameterString);
if (parameterString == "EmailVerificationCode.Register" && isAdmin && !emailBelongToUser) { if (parameterString == "EmailVerificationCode.Register" && isAdmin && !emailBelongToUser) {
auto code = readOrCreateEmailVerificationCode(user_model->getID(), model::table::EMAIL_OPT_IN_REGISTER_DIRECT); auto code = readOrCreateEmailVerificationCode(user_model->getID(), model::table::EMAIL_OPT_IN_REGISTER_DIRECT);
if (code) { if (code) {
jsonUser.set("EmailVerificationCode.Register", std::to_string(code)); jsonUser.set("EmailVerificationCode.Register", std::to_string(code));
} }
} }
else if (parameterString == "loginServer.path") { else if (parameterString == "loginServer.path") {
jsonServer.set("loginServer.path", ServerConfig::g_serverPath); jsonServer.set("loginServer.path", ServerConfig::g_serverPath);
} }
else if (parameterString == "user.pubkeyhex") { else if (parameterString == "user.pubkeyhex") {
jsonUser.set("pubkeyhex", user_model->getPublicKeyHex()); jsonUser.set("pubkeyhex", user_model->getPublicKeyHex());
} }
else if (parameterString == "user.first_name") { else if (parameterString == "user.first_name") {
jsonUser.set("first_name", user_model->getFirstName()); jsonUser.set("first_name", user_model->getFirstName());
} }
else if (parameterString == "user.last_name") { else if (parameterString == "user.last_name") {
jsonUser.set("last_name", user_model->getLastName()); jsonUser.set("last_name", user_model->getLastName());
} }
else if (parameterString == "user.disabled") { else if (parameterString == "user.disabled") {
jsonUser.set("disabled", user_model->isDisabled()); jsonUser.set("disabled", user_model->isDisabled());
} }
else if (parameterString == "user.email_checked" && (isAdmin || emailBelongToUser)) { else if (parameterString == "user.email_checked" && (isAdmin || emailBelongToUser)) {
jsonUser.set("email_checked", user_model->isEmailChecked()); jsonUser.set("email_checked", user_model->isEmailChecked());
} }
else if (parameterString == "user.identHash") { else if (parameterString == "user.identHash") {
auto email = user_model->getEmail(); auto email = user_model->getEmail();
jsonUser.set("identHash", DRMakeStringHash(email.data(), email.size())); jsonUser.set("identHash", DRMakeStringHash(email.data(), email.size()));
} }
} }
catch (Poco::Exception& ex) { catch (Poco::Exception& ex) {
jsonErrorsArray.add("ask parameter invalid"); jsonErrorsArray.add("ask parameter invalid");
} }
} }
result->set("errors", jsonErrorsArray); result->set("errors", jsonErrorsArray);
result->set("userData", jsonUser); result->set("userData", jsonUser);
result->set("server", jsonServer); result->set("server", jsonServer);
return result; return result;
} }

View File

@ -1,44 +1,44 @@
#include "JsonLogout.h" #include "JsonLogout.h"
#include "../SingletonManager/SessionManager.h" #include "../SingletonManager/SessionManager.h"
Poco::JSON::Object* JsonLogout::handle(Poco::Dynamic::Var params) Poco::JSON::Object* JsonLogout::handle(Poco::Dynamic::Var params)
{ {
auto sm = SessionManager::getInstance(); auto sm = SessionManager::getInstance();
int session_id = 0; int session_id = 0;
// if is json object // if is json object
if (params.type() == typeid(Poco::JSON::Object::Ptr)) { if (params.type() == typeid(Poco::JSON::Object::Ptr)) {
Poco::JSON::Object::Ptr paramJsonObject = params.extract<Poco::JSON::Object::Ptr>(); Poco::JSON::Object::Ptr paramJsonObject = params.extract<Poco::JSON::Object::Ptr>();
/// Throws a RangeException if the value does not fit /// Throws a RangeException if the value does not fit
/// into the result variable. /// into the result variable.
/// Throws a NotImplementedException if conversion is /// Throws a NotImplementedException if conversion is
/// not available for the given type. /// not available for the given type.
/// Throws InvalidAccessException if Var is empty. /// Throws InvalidAccessException if Var is empty.
try { try {
paramJsonObject->get("session_id").convert(session_id); paramJsonObject->get("session_id").convert(session_id);
} }
catch (Poco::Exception& ex) { catch (Poco::Exception& ex) {
return stateError("json exception", ex.displayText()); return stateError("json exception", ex.displayText());
} }
} }
else { else {
return stateError("parameter format unknown"); return stateError("parameter format unknown");
} }
auto session = sm->getSession(session_id); auto session = sm->getSession(session_id);
if (!session) { if (!session) {
return stateError("session not found", std::to_string(session_id)); return stateError("session not found", std::to_string(session_id));
} }
if (sm->releaseSession(session_id)) { if (sm->releaseSession(session_id)) {
return stateSuccess(); return stateSuccess();
} }
return stateError("error by releasing session"); return stateError("error by releasing session");
} }

View File

@ -1,18 +1,18 @@
#ifndef __JSON_INTERFACE_JSON_LOGOUT_ #ifndef __JSON_INTERFACE_JSON_LOGOUT_
#define __JSON_INTERFACE_JSON_LOGOUT_ #define __JSON_INTERFACE_JSON_LOGOUT_
#include "JsonRequestHandler.h" #include "JsonRequestHandler.h"
class JsonLogout : public JsonRequestHandler class JsonLogout : public JsonRequestHandler
{ {
public: public:
JsonLogout(Poco::Net::IPAddress ip) : mClientIP(ip) {} JsonLogout(Poco::Net::IPAddress ip) : mClientIP(ip) {}
Poco::JSON::Object* handle(Poco::Dynamic::Var params); Poco::JSON::Object* handle(Poco::Dynamic::Var params);
protected: protected:
Poco::Net::IPAddress mClientIP; Poco::Net::IPAddress mClientIP;
}; };
#endif // __JSON_INTERFACE_JSON_LOGOUT_ #endif // __JSON_INTERFACE_JSON_LOGOUT_

View File

@ -1,141 +1,141 @@
#include "JsonRequestHandler.h" #include "JsonRequestHandler.h"
#include "Poco/Net/HTTPServerRequest.h" #include "Poco/Net/HTTPServerRequest.h"
#include "Poco/Net/HTTPServerResponse.h" #include "Poco/Net/HTTPServerResponse.h"
#include "Poco/URI.h" #include "Poco/URI.h"
#include "Poco/DeflatingStream.h" #include "Poco/DeflatingStream.h"
#include "Poco/JSON/Parser.h" #include "Poco/JSON/Parser.h"
#include "../ServerConfig.h" #include "../ServerConfig.h"
#include "../lib/DataTypeConverter.h" #include "../lib/DataTypeConverter.h"
#include "../SingletonManager/SessionManager.h" #include "../SingletonManager/SessionManager.h"
void JsonRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) void JsonRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{ {
response.setChunkedTransferEncoding(false); response.setChunkedTransferEncoding(false);
response.setContentType("application/json"); response.setContentType("application/json");
if (ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_CORS_ALL) { if (ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_CORS_ALL) {
response.set("Access-Control-Allow-Origin", "*"); response.set("Access-Control-Allow-Origin", "*");
response.set("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers"); response.set("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
} }
//bool _compressResponse(request.hasToken("Accept-Encoding", "gzip")); //bool _compressResponse(request.hasToken("Accept-Encoding", "gzip"));
//if (_compressResponse) response.set("Content-Encoding", "gzip"); //if (_compressResponse) response.set("Content-Encoding", "gzip");
std::ostream& responseStream = response.send(); std::ostream& responseStream = response.send();
//Poco::DeflatingOutputStream _gzipStream(_responseStream, Poco::DeflatingStreamBuf::STREAM_GZIP, 1); //Poco::DeflatingOutputStream _gzipStream(_responseStream, Poco::DeflatingStreamBuf::STREAM_GZIP, 1);
//std::ostream& responseStream = _compressResponse ? _gzipStream : _responseStream; //std::ostream& responseStream = _compressResponse ? _gzipStream : _responseStream;
auto method = request.getMethod(); auto method = request.getMethod();
std::istream& request_stream = request.stream(); std::istream& request_stream = request.stream();
Poco::JSON::Object* json_result = nullptr; Poco::JSON::Object* json_result = nullptr;
if (method == "POST" || method == "PUT") { if (method == "POST" || method == "PUT") {
// extract parameter from request // extract parameter from request
Poco::Dynamic::Var parsedResult = parseJsonWithErrorPrintFile(request_stream); Poco::Dynamic::Var parsedResult = parseJsonWithErrorPrintFile(request_stream);
if (parsedResult.size() != 0) { if (parsedResult.size() != 0) {
json_result = handle(parsedResult); json_result = handle(parsedResult);
} }
else { else {
json_result = stateError("empty body"); json_result = stateError("empty body");
} }
} }
else if(method == "GET") { else if(method == "GET") {
Poco::URI uri(request.getURI()); Poco::URI uri(request.getURI());
auto queryParameters = uri.getQueryParameters(); auto queryParameters = uri.getQueryParameters();
json_result = handle(queryParameters); json_result = handle(queryParameters);
} }
if (json_result) { if (json_result) {
if (!json_result->isNull("session_id")) { if (!json_result->isNull("session_id")) {
int session_id = 0; int session_id = 0;
try { try {
json_result->get("session_id").convert(session_id); json_result->get("session_id").convert(session_id);
} }
catch (Poco::Exception& e) { catch (Poco::Exception& e) {
ErrorList erros; ErrorList erros;
erros.addError(new Error("json request", "invalid session_id")); erros.addError(new Error("json request", "invalid session_id"));
erros.sendErrorsAsEmail(); erros.sendErrorsAsEmail();
} }
if (session_id) { if (session_id) {
auto session = SessionManager::getInstance()->getSession(session_id); auto session = SessionManager::getInstance()->getSession(session_id);
response.addCookie(session->getLoginCookie()); response.addCookie(session->getLoginCookie());
} }
} }
json_result->stringify(responseStream); json_result->stringify(responseStream);
delete json_result; delete json_result;
} }
//if (_compressResponse) _gzipStream.close(); //if (_compressResponse) _gzipStream.close();
} }
Poco::Dynamic::Var JsonRequestHandler::parseJsonWithErrorPrintFile(std::istream& request_stream, ErrorList* errorHandler /* = nullptr*/, const char* functionName /* = nullptr*/) Poco::Dynamic::Var JsonRequestHandler::parseJsonWithErrorPrintFile(std::istream& request_stream, ErrorList* errorHandler /* = nullptr*/, const char* functionName /* = nullptr*/)
{ {
// debugging answer // debugging answer
std::stringstream responseStringStream; std::stringstream responseStringStream;
for (std::string line; std::getline(request_stream, line); ) { for (std::string line; std::getline(request_stream, line); ) {
responseStringStream << line << std::endl; responseStringStream << line << std::endl;
} }
// extract parameter from request // extract parameter from request
Poco::JSON::Parser jsonParser; Poco::JSON::Parser jsonParser;
Poco::Dynamic::Var parsedJson; Poco::Dynamic::Var parsedJson;
try { try {
parsedJson = jsonParser.parse(responseStringStream.str()); parsedJson = jsonParser.parse(responseStringStream.str());
return parsedJson; return parsedJson;
} }
catch (Poco::Exception& ex) { catch (Poco::Exception& ex) {
if (errorHandler) { if (errorHandler) {
errorHandler->addError(new ParamError(functionName, "error parsing request answer", ex.displayText().data())); errorHandler->addError(new ParamError(functionName, "error parsing request answer", ex.displayText().data()));
errorHandler->sendErrorsAsEmail(responseStringStream.str()); errorHandler->sendErrorsAsEmail(responseStringStream.str());
} }
std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d_%m_%yT%H_%M_%S"); std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d_%m_%yT%H_%M_%S");
std::string filename = dateTimeString + "_response.html"; std::string filename = dateTimeString + "_response.html";
FILE* f = fopen(filename.data(), "wt"); FILE* f = fopen(filename.data(), "wt");
if (f) { if (f) {
std::string responseString = responseStringStream.str(); std::string responseString = responseStringStream.str();
fwrite(responseString.data(), 1, responseString.size(), f); fwrite(responseString.data(), 1, responseString.size(), f);
fclose(f); fclose(f);
} }
return Poco::Dynamic::Var(); return Poco::Dynamic::Var();
} }
return Poco::Dynamic::Var(); return Poco::Dynamic::Var();
} }
Poco::JSON::Object* JsonRequestHandler::stateError(const char* msg, std::string details) Poco::JSON::Object* JsonRequestHandler::stateError(const char* msg, std::string details)
{ {
Poco::JSON::Object* result = new Poco::JSON::Object; Poco::JSON::Object* result = new Poco::JSON::Object;
result->set("state", "error"); result->set("state", "error");
result->set("msg", msg); result->set("msg", msg);
if (details != "") { if (details != "") {
result->set("details", details); result->set("details", details);
} }
return result; return result;
} }
Poco::JSON::Object* JsonRequestHandler::stateSuccess() Poco::JSON::Object* JsonRequestHandler::stateSuccess()
{ {
Poco::JSON::Object* result = new Poco::JSON::Object; Poco::JSON::Object* result = new Poco::JSON::Object;
result->set("state", "success"); result->set("state", "success");
return result; return result;
} }
Poco::JSON::Object* JsonRequestHandler::customStateError(const char* state, const char* msg, std::string details/* = ""*/) Poco::JSON::Object* JsonRequestHandler::customStateError(const char* state, const char* msg, std::string details/* = ""*/)
{ {
Poco::JSON::Object* result = new Poco::JSON::Object; Poco::JSON::Object* result = new Poco::JSON::Object;
result->set("state", state); result->set("state", state);
result->set("msg", msg); result->set("msg", msg);
if (details != "") { if (details != "") {
result->set("details", details); result->set("details", details);
} }
return result; return result;
} }

View File

@ -1,82 +1,82 @@
#include "JsonRequestHandlerFactory.h" #include "JsonRequestHandlerFactory.h"
#include "Poco/Net/HTTPServerRequest.h" #include "Poco/Net/HTTPServerRequest.h"
#include "../SingletonManager/SessionManager.h" #include "../SingletonManager/SessionManager.h"
#include "JsonAdminEmailVerificationResend.h" #include "JsonAdminEmailVerificationResend.h"
#include "JsonCheckSessionState.h" #include "JsonCheckSessionState.h"
#include "JsonCreateUser.h" #include "JsonCreateUser.h"
#include "JsonGetLogin.h" #include "JsonGetLogin.h"
#include "JsonUnknown.h" #include "JsonUnknown.h"
#include "JsonTransaction.h" #include "JsonTransaction.h"
#include "JsonGetRunningUserTasks.h" #include "JsonGetRunningUserTasks.h"
#include "JsonGetUsers.h" #include "JsonGetUsers.h"
#include "JsonLoginViaEmailVerificationCode.h" #include "JsonLoginViaEmailVerificationCode.h"
#include "JsonGetUserInfos.h" #include "JsonGetUserInfos.h"
#include "JsonUpdateUserInfos.h" #include "JsonUpdateUserInfos.h"
#include "JsonUnsecureLogin.h" #include "JsonUnsecureLogin.h"
#include "JsonLogout.h" #include "JsonLogout.h"
JsonRequestHandlerFactory::JsonRequestHandlerFactory() JsonRequestHandlerFactory::JsonRequestHandlerFactory()
: mRemoveGETParameters("^/([a-zA-Z0-9_-]*)"), mLogging(Poco::Logger::get("requestLog")) : mRemoveGETParameters("^/([a-zA-Z0-9_-]*)"), mLogging(Poco::Logger::get("requestLog"))
{ {
} }
Poco::Net::HTTPRequestHandler* JsonRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest& request) Poco::Net::HTTPRequestHandler* JsonRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest& request)
{ {
std::string uri = request.getURI(); std::string uri = request.getURI();
std::string url_first_part; std::string url_first_part;
std::stringstream logStream; std::stringstream logStream;
mRemoveGETParameters.extract(uri, url_first_part); mRemoveGETParameters.extract(uri, url_first_part);
std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d.%m.%y %H:%M:%S"); std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d.%m.%y %H:%M:%S");
logStream << dateTimeString << " call " << uri; logStream << dateTimeString << " call " << uri;
mLogging.information(logStream.str()); mLogging.information(logStream.str());
auto client_host = request.clientAddress().host(); auto client_host = request.clientAddress().host();
//auto client_ip = request.clientAddress(); //auto client_ip = request.clientAddress();
// X-Real-IP forwarded ip from nginx config // X-Real-IP forwarded ip from nginx config
auto client_host_string = request.get("X-Real-IP", client_host.toString()); auto client_host_string = request.get("X-Real-IP", client_host.toString());
client_host = Poco::Net::IPAddress(client_host_string); client_host = Poco::Net::IPAddress(client_host_string);
if (url_first_part == "/login") { if (url_first_part == "/login") {
return new JsonGetLogin; return new JsonGetLogin;
} }
else if (url_first_part == "/checkSessionState") { else if (url_first_part == "/checkSessionState") {
return new JsonCheckSessionState; return new JsonCheckSessionState;
} }
else if (url_first_part == "/checkTransaction") { else if (url_first_part == "/checkTransaction") {
return new JsonTransaction; return new JsonTransaction;
} }
else if (url_first_part == "/getRunningUserTasks") { else if (url_first_part == "/getRunningUserTasks") {
return new JsonGetRunningUserTasks; return new JsonGetRunningUserTasks;
} }
else if (url_first_part == "/getUsers") { else if (url_first_part == "/getUsers") {
return new JsonGetUsers; return new JsonGetUsers;
} }
else if (url_first_part == "/createUser") { else if (url_first_part == "/createUser") {
return new JsonCreateUser(client_host); return new JsonCreateUser(client_host);
} }
else if (url_first_part == "/adminEmailVerificationResend") { else if (url_first_part == "/adminEmailVerificationResend") {
return new JsonAdminEmailVerificationResend; return new JsonAdminEmailVerificationResend;
} }
else if (url_first_part == "/getUserInfos") { else if (url_first_part == "/getUserInfos") {
return new JsonGetUserInfos; return new JsonGetUserInfos;
} }
else if (url_first_part == "/updateUserInfos") { else if (url_first_part == "/updateUserInfos") {
return new JsonUpdateUserInfos; return new JsonUpdateUserInfos;
} }
else if (url_first_part == "/unsecureLogin" && (ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_PASSWORD_REQUESTS)) { else if (url_first_part == "/unsecureLogin" && (ServerConfig::g_AllowUnsecureFlags & ServerConfig::UNSECURE_PASSWORD_REQUESTS)) {
return new JsonUnsecureLogin(client_host); return new JsonUnsecureLogin(client_host);
} }
else if (url_first_part == "/loginViaEmailVerificationCode") { else if (url_first_part == "/loginViaEmailVerificationCode") {
return new JsonLoginViaEmailVerificationCode(client_host); return new JsonLoginViaEmailVerificationCode(client_host);
} }
else if (url_first_part == "/logout") { else if (url_first_part == "/logout") {
return new JsonLogout(client_host); return new JsonLogout(client_host);
} }
return new JsonUnknown; return new JsonUnknown;
} }

View File

@ -1,175 +1,175 @@
#include "JsonTransaction.h" #include "JsonTransaction.h"
#include "Poco/URI.h" #include "Poco/URI.h"
#include "Poco/Dynamic/Struct.h" #include "Poco/Dynamic/Struct.h"
#include "../SingletonManager/SessionManager.h" #include "../SingletonManager/SessionManager.h"
#include "../ServerConfig.h" #include "../ServerConfig.h"
Poco::JSON::Object* JsonTransaction::handle(Poco::Dynamic::Var params) Poco::JSON::Object* JsonTransaction::handle(Poco::Dynamic::Var params)
{ {
Poco::JSON::Object* result = new Poco::JSON::Object; Poco::JSON::Object* result = new Poco::JSON::Object;
int session_id = 0; int session_id = 0;
// if is json object // if is json object
if (params.type() == typeid(Poco::JSON::Object::Ptr)) { if (params.type() == typeid(Poco::JSON::Object::Ptr)) {
Poco::JSON::Object::Ptr paramJsonObject = params.extract<Poco::JSON::Object::Ptr>(); Poco::JSON::Object::Ptr paramJsonObject = params.extract<Poco::JSON::Object::Ptr>();
try { try {
/// Throws a RangeException if the value does not fit /// Throws a RangeException if the value does not fit
/// into the result variable. /// into the result variable.
/// Throws a NotImplementedException if conversion is /// Throws a NotImplementedException if conversion is
/// not available for the given type. /// not available for the given type.
/// Throws InvalidAccessException if Var is empty. /// Throws InvalidAccessException if Var is empty.
paramJsonObject->get("session_id").convert(session_id); paramJsonObject->get("session_id").convert(session_id);
auto sm = SessionManager::getInstance(); auto sm = SessionManager::getInstance();
if (session_id != 0) { if (session_id != 0) {
auto session = sm->getSession(session_id); auto session = sm->getSession(session_id);
if (!session) { if (!session) {
result->set("state", "error"); result->set("state", "error");
result->set("msg", "session not found"); result->set("msg", "session not found");
return result; return result;
} }
int balance = 0; int balance = 0;
if (!paramJsonObject->isNull("balance")) { if (!paramJsonObject->isNull("balance")) {
paramJsonObject->get("balance").convert(balance); paramJsonObject->get("balance").convert(balance);
if (balance) { if (balance) {
auto u = session->getUser(); auto u = session->getUser();
if (u) { if (u) {
u->setBalance(balance); u->setBalance(balance);
} }
auto nu = session->getNewUser(); auto nu = session->getNewUser();
if (!nu.isNull()) { if (!nu.isNull()) {
nu->setBalance(balance); nu->setBalance(balance);
} }
} }
} }
std::string transactionBase64String; std::string transactionBase64String;
Poco::Dynamic::Var transaction_base64 = paramJsonObject->get("transaction_base64"); Poco::Dynamic::Var transaction_base64 = paramJsonObject->get("transaction_base64");
bool auto_sign = false; bool auto_sign = false;
auto auto_sign_json = paramJsonObject->get("auto_sign"); auto auto_sign_json = paramJsonObject->get("auto_sign");
if (!auto_sign_json.isEmpty()) { if (!auto_sign_json.isEmpty()) {
auto_sign_json.convert(auto_sign); auto_sign_json.convert(auto_sign);
} }
if (transaction_base64.isString()) { if (transaction_base64.isString()) {
paramJsonObject->get("transaction_base64").convert(transactionBase64String); paramJsonObject->get("transaction_base64").convert(transactionBase64String);
if (!session->startProcessingTransaction(transactionBase64String, auto_sign)) { if (!session->startProcessingTransaction(transactionBase64String, auto_sign)) {
if (auto_sign) { if (auto_sign) {
auto errorJson = session->getErrorsArray(); auto errorJson = session->getErrorsArray();
result->set("state", "error"); result->set("state", "error");
result->set("msg", "error processing transaction"); result->set("msg", "error processing transaction");
result->set("details", errorJson); result->set("details", errorJson);
return result; return result;
} }
auto lastError = session->getLastError(); auto lastError = session->getLastError();
if (lastError) delete lastError; if (lastError) delete lastError;
result->set("state", "error"); result->set("state", "error");
result->set("msg", "already enlisted"); result->set("msg", "already enlisted");
return result; return result;
} }
} else { } else {
Poco::DynamicStruct ds = *paramJsonObject; Poco::DynamicStruct ds = *paramJsonObject;
int alreadyEnlisted = 0; int alreadyEnlisted = 0;
for (int i = 0; i < ds["transaction_base64"].size(); i++) { for (int i = 0; i < ds["transaction_base64"].size(); i++) {
ds["transaction_base64"][i].convert(transactionBase64String); ds["transaction_base64"][i].convert(transactionBase64String);
if (!session->startProcessingTransaction(transactionBase64String, auto_sign)) { if (!session->startProcessingTransaction(transactionBase64String, auto_sign)) {
auto lastError = session->getLastError(); auto lastError = session->getLastError();
if (lastError) delete lastError; if (lastError) delete lastError;
alreadyEnlisted++; alreadyEnlisted++;
} }
} }
if (alreadyEnlisted > 0) { if (alreadyEnlisted > 0) {
result->set("state", "warning"); result->set("state", "warning");
result->set("msg", std::to_string(alreadyEnlisted) + " already enlisted"); result->set("msg", std::to_string(alreadyEnlisted) + " already enlisted");
return result; return result;
} }
} }
result->set("state", "success"); result->set("state", "success");
return result; return result;
} }
} }
catch (Poco::Exception& ex) { catch (Poco::Exception& ex) {
printf("[JsonTransaction::handle] try to use params as jsonObject: %s\n", ex.displayText().data()); printf("[JsonTransaction::handle] try to use params as jsonObject: %s\n", ex.displayText().data());
result->set("state", "error"); result->set("state", "error");
result->set("msg", "json exception"); result->set("msg", "json exception");
result->set("details", ex.displayText()); result->set("details", ex.displayText());
return result; return result;
} }
} }
else if (params.isVector()) { else if (params.isVector()) {
const Poco::URI::QueryParameters queryParams = params.extract<Poco::URI::QueryParameters>(); const Poco::URI::QueryParameters queryParams = params.extract<Poco::URI::QueryParameters>();
auto transactionIT = queryParams.begin(); auto transactionIT = queryParams.begin();
for (auto it = queryParams.begin(); it != queryParams.end(); it++) { for (auto it = queryParams.begin(); it != queryParams.end(); it++) {
if (it->first == "session_id") { if (it->first == "session_id") {
session_id = stoi(it->second); session_id = stoi(it->second);
//break; //break;
} }
else if (it->first == "transaction_base64") { else if (it->first == "transaction_base64") {
transactionIT = it; transactionIT = it;
} }
} }
if (session_id) { if (session_id) {
auto sm = SessionManager::getInstance(); auto sm = SessionManager::getInstance();
auto session = sm->getSession(session_id); auto session = sm->getSession(session_id);
if (!session) { if (!session) {
result->set("state", "error"); result->set("state", "error");
result->set("msg", "session not found"); result->set("msg", "session not found");
return result; return result;
} }
if (!session->startProcessingTransaction(transactionIT->second)) { if (!session->startProcessingTransaction(transactionIT->second)) {
auto lastError = session->getLastError(); auto lastError = session->getLastError();
if (lastError) delete lastError; if (lastError) delete lastError;
result->set("state", "error"); result->set("state", "error");
result->set("msg", "already enlisted"); result->set("msg", "already enlisted");
return result; return result;
} }
result->set("state", "success"); result->set("state", "success");
return result; return result;
} }
else { else {
result->set("state", "error"); result->set("state", "error");
result->set("msg", "session id not set"); result->set("msg", "session id not set");
return result; return result;
} }
} }
else if (params.isStruct()) { else if (params.isStruct()) {
result->set("state", "error"); result->set("state", "error");
result->set("msg", "struct not implemented yet"); result->set("msg", "struct not implemented yet");
} }
else if (params.isArray()) { else if (params.isArray()) {
result->set("state", "error"); result->set("state", "error");
result->set("msg", "array not implemented yet"); result->set("msg", "array not implemented yet");
} }
else if (params.isList()) { else if (params.isList()) {
result->set("state", "error"); result->set("state", "error");
result->set("msg", "list not implemented yet"); result->set("msg", "list not implemented yet");
} }
else if (params.isString()) { else if (params.isString()) {
result->set("state", "error"); result->set("state", "error");
result->set("msg", "string not implemented yet"); result->set("msg", "string not implemented yet");
} }
else if (params.isDeque()) { else if (params.isDeque()) {
result->set("state", "error"); result->set("state", "error");
result->set("msg", "deque not implemented yet"); result->set("msg", "deque not implemented yet");
} }
else { else {
result->set("state", "error"); result->set("state", "error");
result->set("msg", "format not implemented"); result->set("msg", "format not implemented");
result->set("details", std::string(params.type().name())); result->set("details", std::string(params.type().name()));
} }
return result; return result;
} }

View File

@ -1,19 +1,19 @@
#ifndef __JSON_INTERFACE_JSON_TRANSACTION_ #ifndef __JSON_INTERFACE_JSON_TRANSACTION_
#define __JSON_INTERFACE_JSON_TRANSACTION_ #define __JSON_INTERFACE_JSON_TRANSACTION_
#include "JsonRequestHandler.h" #include "JsonRequestHandler.h"
class Session; class Session;
class JsonTransaction : public JsonRequestHandler class JsonTransaction : public JsonRequestHandler
{ {
public: public:
Poco::JSON::Object* handle(Poco::Dynamic::Var params); Poco::JSON::Object* handle(Poco::Dynamic::Var params);
protected: protected:
bool startProcessingTransaction(Session* session, const std::string& transactionBase64); bool startProcessingTransaction(Session* session, const std::string& transactionBase64);
}; };
#endif // __JSON_INTERFACE_JSON_TRANSACTION_ #endif // __JSON_INTERFACE_JSON_TRANSACTION_

View File

@ -1,349 +1,349 @@
#include "ServerConfig.h" #include "ServerConfig.h"
#include "Crypto/mnemonic_german.h" #include "Crypto/mnemonic_german.h"
#include "Crypto/mnemonic_german2.h" #include "Crypto/mnemonic_german2.h"
#include "Crypto/mnemonic_bip0039.h" #include "Crypto/mnemonic_bip0039.h"
#include "Crypto/DRRandom.h" #include "Crypto/DRRandom.h"
#include "lib/DataTypeConverter.h" #include "lib/DataTypeConverter.h"
#include "sodium.h" #include "sodium.h"
#include "Poco/Net/SSLManager.h" #include "Poco/Net/SSLManager.h"
#include "Poco/Net/KeyConsoleHandler.h" #include "Poco/Net/KeyConsoleHandler.h"
#include "Poco/Net/RejectCertificateHandler.h" #include "Poco/Net/RejectCertificateHandler.h"
#include "Poco/Net/DNS.h" #include "Poco/Net/DNS.h"
#include "Poco/SharedPtr.h" #include "Poco/SharedPtr.h"
#include "Poco/Mutex.h" #include "Poco/Mutex.h"
#include "Poco/Path.h" #include "Poco/Path.h"
#include "Poco/FileStream.h" #include "Poco/FileStream.h"
#include "Poco/LocalDateTime.h" #include "Poco/LocalDateTime.h"
#include "Poco/DateTimeFormat.h" #include "Poco/DateTimeFormat.h"
#include "Poco/DateTimeFormatter.h" #include "Poco/DateTimeFormatter.h"
using Poco::Net::SSLManager; using Poco::Net::SSLManager;
using Poco::Net::Context; using Poco::Net::Context;
using Poco::Net::KeyConsoleHandler; using Poco::Net::KeyConsoleHandler;
using Poco::Net::PrivateKeyPassphraseHandler; using Poco::Net::PrivateKeyPassphraseHandler;
using Poco::Net::InvalidCertificateHandler; using Poco::Net::InvalidCertificateHandler;
using Poco::Net::RejectCertificateHandler; using Poco::Net::RejectCertificateHandler;
using Poco::SharedPtr; using Poco::SharedPtr;
namespace ServerConfig { namespace ServerConfig {
#define SESSION_TIMEOUT_DEFAULT 10 #define SESSION_TIMEOUT_DEFAULT 10
Mnemonic g_Mnemonic_WordLists[MNEMONIC_MAX]; Mnemonic g_Mnemonic_WordLists[MNEMONIC_MAX];
ObfusArray* g_ServerCryptoKey = nullptr; ObfusArray* g_ServerCryptoKey = nullptr;
ObfusArray* g_ServerKeySeed = nullptr; ObfusArray* g_ServerKeySeed = nullptr;
// std::string g_ServerAdminPublic; // std::string g_ServerAdminPublic;
UniLib::controller::CPUSheduler* g_CPUScheduler = nullptr; UniLib::controller::CPUSheduler* g_CPUScheduler = nullptr;
UniLib::controller::CPUSheduler* g_CryptoCPUScheduler = nullptr; UniLib::controller::CPUSheduler* g_CryptoCPUScheduler = nullptr;
Context::Ptr g_SSL_CLient_Context = nullptr; Context::Ptr g_SSL_CLient_Context = nullptr;
Poco::Util::Timer g_CronJobsTimer; Poco::Util::Timer g_CronJobsTimer;
EmailAccount g_EmailAccount; EmailAccount g_EmailAccount;
int g_SessionTimeout = SESSION_TIMEOUT_DEFAULT; int g_SessionTimeout = SESSION_TIMEOUT_DEFAULT;
std::string g_serverPath; std::string g_serverPath;
int g_serverPort = 0; int g_serverPort = 0;
Languages g_default_locale; Languages g_default_locale;
std::string g_php_serverPath; std::string g_php_serverPath;
std::string g_php_serverHost; std::string g_php_serverHost;
int g_phpServerPort; int g_phpServerPort;
Poco::Mutex g_TimeMutex; Poco::Mutex g_TimeMutex;
int g_FakeLoginSleepTime = 820; int g_FakeLoginSleepTime = 820;
std::string g_versionString = ""; std::string g_versionString = "";
bool g_disableEmail = false; bool g_disableEmail = false;
ServerSetupType g_ServerSetupType = SERVER_TYPE_PRODUCTION; ServerSetupType g_ServerSetupType = SERVER_TYPE_PRODUCTION;
std::string g_gRPCRelayServerFullURL; std::string g_gRPCRelayServerFullURL;
MemoryBin* g_CryptoAppSecret = nullptr; MemoryBin* g_CryptoAppSecret = nullptr;
AllowUnsecure g_AllowUnsecureFlags = NOT_UNSECURE; AllowUnsecure g_AllowUnsecureFlags = NOT_UNSECURE;
#ifdef __linux__ #ifdef __linux__
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <string.h> #include <string.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#endif //#ifdef __linux__ #endif //#ifdef __linux__
std::string getHostIpString() std::string getHostIpString()
{ {
#ifdef __linux__ #ifdef __linux__
struct ifaddrs * ifAddrStruct = NULL; struct ifaddrs * ifAddrStruct = NULL;
struct ifaddrs * ifa = NULL; struct ifaddrs * ifa = NULL;
void * tmpAddrPtr = NULL; void * tmpAddrPtr = NULL;
getifaddrs(&ifAddrStruct); getifaddrs(&ifAddrStruct);
std::string ipAddressString; std::string ipAddressString;
for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) { for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
if (!ifa->ifa_addr) { if (!ifa->ifa_addr) {
continue; continue;
} }
if (ifa->ifa_addr->sa_family == AF_INET) { // check it is IP4 if (ifa->ifa_addr->sa_family == AF_INET) { // check it is IP4
// is a valid IP4 Address // is a valid IP4 Address
tmpAddrPtr = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; tmpAddrPtr = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
char addressBuffer[INET_ADDRSTRLEN]; char addressBuffer[INET_ADDRSTRLEN];
inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN);
ipAddressString = addressBuffer; ipAddressString = addressBuffer;
printf("%s IP Address %s\n", ifa->ifa_name, addressBuffer); printf("%s IP Address %s\n", ifa->ifa_name, addressBuffer);
} }
else if (ifa->ifa_addr->sa_family == AF_INET6) { // check it is IP6 else if (ifa->ifa_addr->sa_family == AF_INET6) { // check it is IP6
// is a valid IP6 Address // is a valid IP6 Address
tmpAddrPtr = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; tmpAddrPtr = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
char addressBuffer[INET6_ADDRSTRLEN]; char addressBuffer[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN); inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN);
printf("%s IP Address %s\n", ifa->ifa_name, addressBuffer); printf("%s IP Address %s\n", ifa->ifa_name, addressBuffer);
} }
} }
if (ifAddrStruct != NULL) freeifaddrs(ifAddrStruct); if (ifAddrStruct != NULL) freeifaddrs(ifAddrStruct);
return ipAddressString; return ipAddressString;
#else //__linux__ #else //__linux__
std::string ipAddressString = ""; std::string ipAddressString = "";
auto host = Poco::Net::DNS::thisHost(); auto host = Poco::Net::DNS::thisHost();
for (auto it = host.addresses().begin(); it != host.addresses().end(); it++) { for (auto it = host.addresses().begin(); it != host.addresses().end(); it++) {
auto ipAddress = *it; auto ipAddress = *it;
if (!ipAddress.isIPv4Compatible() && !ipAddress.isIPv4Mapped()) { if (!ipAddress.isIPv4Compatible() && !ipAddress.isIPv4Mapped()) {
continue; continue;
} }
if (ipAddress.isLoopback()) { if (ipAddress.isLoopback()) {
continue; continue;
} }
ipAddressString = ipAddress.toString(); ipAddressString = ipAddress.toString();
//isIPv4Compatible //isIPv4Compatible
//!isLoopback //!isLoopback
//printf("ipaddress: %s\n", ipAddressString.data()); //printf("ipaddress: %s\n", ipAddressString.data());
break; break;
//break; //break;
} }
return ipAddressString; return ipAddressString;
#endif // __linux__ #endif // __linux__
} }
bool replaceZeroIPWithLocalhostIP(std::string& url) bool replaceZeroIPWithLocalhostIP(std::string& url)
{ {
auto pos = url.find("0.0.0.0", 0); auto pos = url.find("0.0.0.0", 0);
if (pos != std::string::npos) { if (pos != std::string::npos) {
std::string ipAddressString = getHostIpString(); std::string ipAddressString = getHostIpString();
if ("" != ipAddressString) { if ("" != ipAddressString) {
url.replace(pos, 7, ipAddressString); url.replace(pos, 7, ipAddressString);
} }
} }
//printf("ipaddress: %s\n", ipAddress.data()); //printf("ipaddress: %s\n", ipAddress.data());
return true; return true;
} }
ServerSetupType getServerSetupTypeFromString(const std::string& serverSetupTypeString) { ServerSetupType getServerSetupTypeFromString(const std::string& serverSetupTypeString) {
if ("test" == serverSetupTypeString) { if ("test" == serverSetupTypeString) {
return SERVER_TYPE_TEST; return SERVER_TYPE_TEST;
} }
if ("staging" == serverSetupTypeString) { if ("staging" == serverSetupTypeString) {
return SERVER_TYPE_STAGING; return SERVER_TYPE_STAGING;
} }
if ("production" == serverSetupTypeString) { if ("production" == serverSetupTypeString) {
return SERVER_TYPE_PRODUCTION; return SERVER_TYPE_PRODUCTION;
} }
return SERVER_TYPE_PRODUCTION; return SERVER_TYPE_PRODUCTION;
} }
bool loadMnemonicWordLists() bool loadMnemonicWordLists()
{ {
for (int i = 0; i < MNEMONIC_MAX; i++) { for (int i = 0; i < MNEMONIC_MAX; i++) {
int iResult = 0; int iResult = 0;
switch (i) { switch (i) {
case MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER: case MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER:
iResult = g_Mnemonic_WordLists[i].init(populate_mnemonic_german, g_mnemonic_german_original_size, g_mnemonic_german_compressed_size); iResult = g_Mnemonic_WordLists[i].init(populate_mnemonic_german, g_mnemonic_german_original_size, g_mnemonic_german_compressed_size);
if (iResult) { if (iResult) {
printf("[%s] error init german mnemonic set, error nr: %d\n", __FUNCTION__, iResult); printf("[%s] error init german mnemonic set, error nr: %d\n", __FUNCTION__, iResult);
return false; return false;
} }
g_Mnemonic_WordLists[i].printToFile("de_words.txt"); g_Mnemonic_WordLists[i].printToFile("de_words.txt");
break; break;
case MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER_FIXED_CASES: case MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER_FIXED_CASES:
iResult = g_Mnemonic_WordLists[i].init(populate_mnemonic_german2, g_mnemonic_german2_original_size, g_mnemonic_german2_compressed_size); iResult = g_Mnemonic_WordLists[i].init(populate_mnemonic_german2, g_mnemonic_german2_original_size, g_mnemonic_german2_compressed_size);
if (iResult) { if (iResult) {
printf("[%s] error init german mnemonic set 2, error nr: %d\n", __FUNCTION__, iResult); printf("[%s] error init german mnemonic set 2, error nr: %d\n", __FUNCTION__, iResult);
return false; return false;
} }
g_Mnemonic_WordLists[i].printToFile("de_words2.txt"); g_Mnemonic_WordLists[i].printToFile("de_words2.txt");
break; break;
case MNEMONIC_BIP0039_SORTED_ORDER: case MNEMONIC_BIP0039_SORTED_ORDER:
iResult = g_Mnemonic_WordLists[i].init(populate_mnemonic_bip0039, g_mnemonic_bip0039_original_size, g_mnemonic_bip0039_compressed_size); iResult = g_Mnemonic_WordLists[i].init(populate_mnemonic_bip0039, g_mnemonic_bip0039_original_size, g_mnemonic_bip0039_compressed_size);
if (iResult) { if (iResult) {
printf("[%s] error init bip0039 mnemonic set, error nr: %d\n", __FUNCTION__, iResult); printf("[%s] error init bip0039 mnemonic set, error nr: %d\n", __FUNCTION__, iResult);
return false; return false;
} }
//g_Mnemonic_WordLists[i].printToFile("en_words.txt"); //g_Mnemonic_WordLists[i].printToFile("en_words.txt");
break; break;
default: printf("[%s] unknown MnemonicType\n", __FUNCTION__); return false; default: printf("[%s] unknown MnemonicType\n", __FUNCTION__); return false;
} }
} }
return true; return true;
} }
bool initServerCrypto(const Poco::Util::LayeredConfiguration& cfg) bool initServerCrypto(const Poco::Util::LayeredConfiguration& cfg)
{ {
auto serverKey = cfg.getString("crypto.server_key"); auto serverKey = cfg.getString("crypto.server_key");
unsigned char key[crypto_shorthash_KEYBYTES]; unsigned char key[crypto_shorthash_KEYBYTES];
size_t realBinSize = 0; size_t realBinSize = 0;
NULLPAD_10; NULLPAD_10;
if (sodium_hex2bin(key, crypto_shorthash_KEYBYTES, serverKey.data(), serverKey.size(), nullptr, &realBinSize, nullptr)) { if (sodium_hex2bin(key, crypto_shorthash_KEYBYTES, serverKey.data(), serverKey.size(), nullptr, &realBinSize, nullptr)) {
printf("[%s] serverKey isn't valid hex: %s\n", __FUNCTION__, serverKey.data()); printf("[%s] serverKey isn't valid hex: %s\n", __FUNCTION__, serverKey.data());
return false; return false;
} }
if (realBinSize != crypto_shorthash_KEYBYTES) { if (realBinSize != crypto_shorthash_KEYBYTES) {
printf("[%s] serverKey hasn't valid size, expecting: %u, get: %lu\n", printf("[%s] serverKey hasn't valid size, expecting: %u, get: %lu\n",
__FUNCTION__, crypto_shorthash_KEYBYTES, realBinSize); __FUNCTION__, crypto_shorthash_KEYBYTES, realBinSize);
return false; return false;
} }
g_ServerCryptoKey = new ObfusArray(realBinSize, key); g_ServerCryptoKey = new ObfusArray(realBinSize, key);
g_ServerKeySeed = new ObfusArray(9*8); g_ServerKeySeed = new ObfusArray(9*8);
Poco::Int64 i1 = randombytes_random(); Poco::Int64 i1 = randombytes_random();
Poco::Int64 i2 = randombytes_random(); Poco::Int64 i2 = randombytes_random();
g_ServerKeySeed->put(0, i1 | (i2 << 8)); g_ServerKeySeed->put(0, i1 | (i2 << 8));
//g_ServerAdminPublic = cfg.getString("crypto.server_admin_public"); //g_ServerAdminPublic = cfg.getString("crypto.server_admin_public");
DISASM_FALSERET; DISASM_FALSERET;
g_SessionTimeout = cfg.getInt("session.timeout", SESSION_TIMEOUT_DEFAULT); g_SessionTimeout = cfg.getInt("session.timeout", SESSION_TIMEOUT_DEFAULT);
g_serverPath = cfg.getString("loginServer.path", ""); g_serverPath = cfg.getString("loginServer.path", "");
replaceZeroIPWithLocalhostIP(g_serverPath); replaceZeroIPWithLocalhostIP(g_serverPath);
g_default_locale = LanguageManager::languageFromString(cfg.getString("loginServer.default_locale")); g_default_locale = LanguageManager::languageFromString(cfg.getString("loginServer.default_locale"));
g_serverPort = cfg.getInt("loginServer.port", 0); g_serverPort = cfg.getInt("loginServer.port", 0);
g_phpServerPort = cfg.getInt("phpServer.port", 0); g_phpServerPort = cfg.getInt("phpServer.port", 0);
// replace 0.0.0.0 with actual server ip // replace 0.0.0.0 with actual server ip
g_php_serverPath = cfg.getString("phpServer.url", ""); g_php_serverPath = cfg.getString("phpServer.url", "");
replaceZeroIPWithLocalhostIP(g_php_serverPath); replaceZeroIPWithLocalhostIP(g_php_serverPath);
g_php_serverHost = cfg.getString("phpServer.host", ""); g_php_serverHost = cfg.getString("phpServer.host", "");
replaceZeroIPWithLocalhostIP(g_php_serverHost); replaceZeroIPWithLocalhostIP(g_php_serverHost);
//g_ServerSetupType //g_ServerSetupType
auto serverSetupTypeString = cfg.getString("ServerSetupType", ""); auto serverSetupTypeString = cfg.getString("ServerSetupType", "");
g_ServerSetupType = getServerSetupTypeFromString(serverSetupTypeString); g_ServerSetupType = getServerSetupTypeFromString(serverSetupTypeString);
// app secret for encrypt user private keys // app secret for encrypt user private keys
// TODO: encrypt with server admin key // TODO: encrypt with server admin key
auto app_secret_string = cfg.getString("crypto.app_secret", ""); auto app_secret_string = cfg.getString("crypto.app_secret", "");
if ("" != app_secret_string) { if ("" != app_secret_string) {
g_CryptoAppSecret = DataTypeConverter::hexToBin(app_secret_string); g_CryptoAppSecret = DataTypeConverter::hexToBin(app_secret_string);
} }
//g_CryptoAppSecret //g_CryptoAppSecret
g_gRPCRelayServerFullURL = cfg.getString("grpc.server", ""); g_gRPCRelayServerFullURL = cfg.getString("grpc.server", "");
// unsecure flags // unsecure flags
//g_AllowUnsecureFlags //g_AllowUnsecureFlags
if (cfg.getInt("unsecure.allow_passwort_via_json_request", 0) == 1) { if (cfg.getInt("unsecure.allow_passwort_via_json_request", 0) == 1) {
g_AllowUnsecureFlags = (AllowUnsecure)(g_AllowUnsecureFlags | UNSECURE_PASSWORD_REQUESTS); g_AllowUnsecureFlags = (AllowUnsecure)(g_AllowUnsecureFlags | UNSECURE_PASSWORD_REQUESTS);
} }
if (cfg.getInt("unsecure.allow_auto_sign_transactions", 0) == 1) { if (cfg.getInt("unsecure.allow_auto_sign_transactions", 0) == 1) {
g_AllowUnsecureFlags = (AllowUnsecure)(g_AllowUnsecureFlags | UNSECURE_AUTO_SIGN_TRANSACTIONS); g_AllowUnsecureFlags = (AllowUnsecure)(g_AllowUnsecureFlags | UNSECURE_AUTO_SIGN_TRANSACTIONS);
} }
if (cfg.getInt("unsecure.allow_cors_all", 0) == 1) { if (cfg.getInt("unsecure.allow_cors_all", 0) == 1) {
g_AllowUnsecureFlags = (AllowUnsecure)(g_AllowUnsecureFlags | UNSECURE_CORS_ALL); g_AllowUnsecureFlags = (AllowUnsecure)(g_AllowUnsecureFlags | UNSECURE_CORS_ALL);
} }
if (cfg.getInt("unsecure.allow_all_passwords", 0) == 1) { if (cfg.getInt("unsecure.allow_all_passwords", 0) == 1) {
g_AllowUnsecureFlags = (AllowUnsecure)(g_AllowUnsecureFlags | UNSECURE_ALLOW_ALL_PASSWORDS); g_AllowUnsecureFlags = (AllowUnsecure)(g_AllowUnsecureFlags | UNSECURE_ALLOW_ALL_PASSWORDS);
} }
return true; return true;
} }
bool initEMailAccount(const Poco::Util::LayeredConfiguration& cfg) bool initEMailAccount(const Poco::Util::LayeredConfiguration& cfg)
{ {
g_disableEmail = cfg.getBool("email.disable", false); g_disableEmail = cfg.getBool("email.disable", false);
if (g_disableEmail) { if (g_disableEmail) {
printf("Email is disabled!\n"); printf("Email is disabled!\n");
} }
else { else {
g_EmailAccount.sender = cfg.getString("email.sender"); g_EmailAccount.sender = cfg.getString("email.sender");
g_EmailAccount.username = cfg.getString("email.username"); g_EmailAccount.username = cfg.getString("email.username");
g_EmailAccount.password = cfg.getString("email.password"); g_EmailAccount.password = cfg.getString("email.password");
g_EmailAccount.url = cfg.getString("email.smtp.url"); g_EmailAccount.url = cfg.getString("email.smtp.url");
g_EmailAccount.port = cfg.getInt("email.smtp.port"); g_EmailAccount.port = cfg.getInt("email.smtp.port");
} }
DISASM_FALSERET; DISASM_FALSERET;
//g_ServerKeySeed->put(3, DRRandom::r64()); //g_ServerKeySeed->put(3, DRRandom::r64());
return true; return true;
} }
bool initSSLClientContext() bool initSSLClientContext()
{ {
SharedPtr<InvalidCertificateHandler> pCert = new RejectCertificateHandler(false); // reject invalid certificates SharedPtr<InvalidCertificateHandler> pCert = new RejectCertificateHandler(false); // reject invalid certificates
/* /*
Context(Usage usage, Context(Usage usage,
const std::string& certificateNameOrPath, const std::string& certificateNameOrPath,
VerificationMode verMode = VERIFY_RELAXED, VerificationMode verMode = VERIFY_RELAXED,
int options = OPT_DEFAULTS, int options = OPT_DEFAULTS,
const std::string& certificateStoreName = CERT_STORE_MY); const std::string& certificateStoreName = CERT_STORE_MY);
*/ */
try { try {
#ifdef POCO_NETSSL_WIN #ifdef POCO_NETSSL_WIN
g_SSL_CLient_Context = new Context(Context::CLIENT_USE, "cacert.pem", Context::VERIFY_RELAXED, Context::OPT_DEFAULTS); g_SSL_CLient_Context = new Context(Context::CLIENT_USE, "cacert.pem", Context::VERIFY_RELAXED, Context::OPT_DEFAULTS);
#else #else
g_SSL_CLient_Context = new Context(Context::CLIENT_USE, "", "", Poco::Path::config() + "grd_login/cacert.pem", Context::VERIFY_RELAXED, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH"); g_SSL_CLient_Context = new Context(Context::CLIENT_USE, "", "", Poco::Path::config() + "grd_login/cacert.pem", Context::VERIFY_RELAXED, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
#endif #endif
} catch(Poco::Exception& ex) { } catch(Poco::Exception& ex) {
printf("[ServerConfig::initSSLClientContext] error init ssl context, maybe no cacert.pem found?\nPlease make sure you have cacert.pem (CA/root certificates) next to binary from https://curl.haxx.se/docs/caextract.html\n"); printf("[ServerConfig::initSSLClientContext] error init ssl context, maybe no cacert.pem found?\nPlease make sure you have cacert.pem (CA/root certificates) next to binary from https://curl.haxx.se/docs/caextract.html\n");
return false; return false;
} }
DISASM_FALSERET; DISASM_FALSERET;
SSLManager::instance().initializeClient(0, pCert, g_SSL_CLient_Context); SSLManager::instance().initializeClient(0, pCert, g_SSL_CLient_Context);
g_ServerKeySeed->put(5, DRRandom::r64()); g_ServerKeySeed->put(5, DRRandom::r64());
return true; return true;
} }
void unload() { void unload() {
if (g_ServerCryptoKey) { if (g_ServerCryptoKey) {
delete g_ServerCryptoKey; delete g_ServerCryptoKey;
} }
if (g_ServerKeySeed) { if (g_ServerKeySeed) {
delete g_ServerKeySeed; delete g_ServerKeySeed;
} }
if (g_CPUScheduler) { if (g_CPUScheduler) {
delete g_CPUScheduler; delete g_CPUScheduler;
} }
if (g_CryptoCPUScheduler) { if (g_CryptoCPUScheduler) {
delete g_CryptoCPUScheduler; delete g_CryptoCPUScheduler;
} }
if (g_CryptoAppSecret) { if (g_CryptoAppSecret) {
MemoryManager::getInstance()->releaseMemory(g_CryptoAppSecret); MemoryManager::getInstance()->releaseMemory(g_CryptoAppSecret);
g_CryptoAppSecret = nullptr; g_CryptoAppSecret = nullptr;
} }
} }
void writeToFile(std::istream& datas, std::string fileName) void writeToFile(std::istream& datas, std::string fileName)
{ {
static Poco::Mutex mutex; static Poco::Mutex mutex;
mutex.lock(); mutex.lock();
Poco::FileOutputStream file(fileName, std::ios::out | std::ios::app); Poco::FileOutputStream file(fileName, std::ios::out | std::ios::app);
if (!file.good()) { if (!file.good()) {
printf("[ServerConfig::writeToFile] error creating file with name: %s\n", fileName.data()); printf("[ServerConfig::writeToFile] error creating file with name: %s\n", fileName.data());
mutex.unlock(); mutex.unlock();
return; return;
} }
Poco::LocalDateTime now; Poco::LocalDateTime now;
std::string dateTimeStr = Poco::DateTimeFormatter::format(now, Poco::DateTimeFormat::ISO8601_FORMAT); std::string dateTimeStr = Poco::DateTimeFormatter::format(now, Poco::DateTimeFormat::ISO8601_FORMAT);
file << dateTimeStr << std::endl; file << dateTimeStr << std::endl;
for (std::string line; std::getline(datas, line); ) { for (std::string line; std::getline(datas, line); ) {
file << line << std::endl; file << line << std::endl;
} }
file << std::endl; file << std::endl;
file.close(); file.close();
mutex.unlock(); mutex.unlock();
} }
} }

View File

@ -1,90 +1,90 @@
#ifndef __GRADIDO_LOGIN_SERVER_SERVER_CONFIG__ #ifndef __GRADIDO_LOGIN_SERVER_SERVER_CONFIG__
#define __GRADIDO_LOGIN_SERVER_SERVER_CONFIG__ #define __GRADIDO_LOGIN_SERVER_SERVER_CONFIG__
#include "Crypto/mnemonic.h" #include "Crypto/mnemonic.h"
#include "Crypto/Obfus_array.h" #include "Crypto/Obfus_array.h"
#include "Poco/Util/LayeredConfiguration.h" #include "Poco/Util/LayeredConfiguration.h"
#include "Poco/Net/Context.h" #include "Poco/Net/Context.h"
#include "Poco/Types.h" #include "Poco/Types.h"
#include "Poco/Util/Timer.h" #include "Poco/Util/Timer.h"
#include "tasks/CPUSheduler.h" #include "tasks/CPUSheduler.h"
#include "SingletonManager/LanguageManager.h" #include "SingletonManager/LanguageManager.h"
#include "SingletonManager/MemoryManager.h" #include "SingletonManager/MemoryManager.h"
#define DISABLE_EMAIL #define DISABLE_EMAIL
namespace ServerConfig { namespace ServerConfig {
enum Mnemonic_Types { enum Mnemonic_Types {
MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER, MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER,
MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER_FIXED_CASES, MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER_FIXED_CASES,
MNEMONIC_BIP0039_SORTED_ORDER, MNEMONIC_BIP0039_SORTED_ORDER,
MNEMONIC_MAX MNEMONIC_MAX
}; };
// depracted, moved to email manager // depracted, moved to email manager
struct EmailAccount { struct EmailAccount {
std::string sender; std::string sender;
std::string admin_receiver; std::string admin_receiver;
std::string username; std::string username;
std::string password; std::string password;
std::string url; std::string url;
int port; int port;
}; };
enum ServerSetupType { enum ServerSetupType {
SERVER_TYPE_TEST, SERVER_TYPE_TEST,
SERVER_TYPE_STAGING, SERVER_TYPE_STAGING,
SERVER_TYPE_PRODUCTION SERVER_TYPE_PRODUCTION
}; };
// used with bit-operators, so only use numbers with control exactly one bit (1,2,4,8,16...) // used with bit-operators, so only use numbers with control exactly one bit (1,2,4,8,16...)
enum AllowUnsecure { enum AllowUnsecure {
NOT_UNSECURE = 0, NOT_UNSECURE = 0,
UNSECURE_PASSWORD_REQUESTS = 1, UNSECURE_PASSWORD_REQUESTS = 1,
UNSECURE_AUTO_SIGN_TRANSACTIONS = 2, UNSECURE_AUTO_SIGN_TRANSACTIONS = 2,
UNSECURE_CORS_ALL = 4, UNSECURE_CORS_ALL = 4,
UNSECURE_ALLOW_ALL_PASSWORDS = 8 UNSECURE_ALLOW_ALL_PASSWORDS = 8
}; };
extern Mnemonic g_Mnemonic_WordLists[MNEMONIC_MAX]; extern Mnemonic g_Mnemonic_WordLists[MNEMONIC_MAX];
extern ObfusArray* g_ServerCryptoKey; extern ObfusArray* g_ServerCryptoKey;
extern ObfusArray* g_ServerKeySeed; extern ObfusArray* g_ServerKeySeed;
//extern unsigned char g_ServerAdminPublic[]; //extern unsigned char g_ServerAdminPublic[];
extern UniLib::controller::CPUSheduler* g_CPUScheduler; extern UniLib::controller::CPUSheduler* g_CPUScheduler;
extern UniLib::controller::CPUSheduler* g_CryptoCPUScheduler; extern UniLib::controller::CPUSheduler* g_CryptoCPUScheduler;
extern Poco::Net::Context::Ptr g_SSL_CLient_Context; extern Poco::Net::Context::Ptr g_SSL_CLient_Context;
extern Poco::Util::Timer g_CronJobsTimer; extern Poco::Util::Timer g_CronJobsTimer;
extern EmailAccount g_EmailAccount; extern EmailAccount g_EmailAccount;
extern int g_SessionTimeout; extern int g_SessionTimeout;
extern std::string g_serverPath; extern std::string g_serverPath;
extern int g_serverPort; extern int g_serverPort;
extern Languages g_default_locale; extern Languages g_default_locale;
extern std::string g_php_serverPath; extern std::string g_php_serverPath;
extern std::string g_php_serverHost; extern std::string g_php_serverHost;
extern int g_phpServerPort; extern int g_phpServerPort;
extern Poco::Mutex g_TimeMutex; extern Poco::Mutex g_TimeMutex;
extern int g_FakeLoginSleepTime; extern int g_FakeLoginSleepTime;
extern std::string g_versionString; extern std::string g_versionString;
extern bool g_disableEmail; extern bool g_disableEmail;
extern ServerSetupType g_ServerSetupType; extern ServerSetupType g_ServerSetupType;
extern std::string g_gRPCRelayServerFullURL; extern std::string g_gRPCRelayServerFullURL;
extern MemoryBin* g_CryptoAppSecret; extern MemoryBin* g_CryptoAppSecret;
extern AllowUnsecure g_AllowUnsecureFlags; extern AllowUnsecure g_AllowUnsecureFlags;
bool loadMnemonicWordLists(); bool loadMnemonicWordLists();
bool initServerCrypto(const Poco::Util::LayeredConfiguration& cfg); bool initServerCrypto(const Poco::Util::LayeredConfiguration& cfg);
bool initEMailAccount(const Poco::Util::LayeredConfiguration& cfg); bool initEMailAccount(const Poco::Util::LayeredConfiguration& cfg);
bool initSSLClientContext(); bool initSSLClientContext();
void writeToFile(std::istream& datas, std::string fileName); void writeToFile(std::istream& datas, std::string fileName);
void unload(); void unload();
}; };
#endif //__GRADIDO_LOGIN_SERVER_SERVER_CONFIG__ #endif //__GRADIDO_LOGIN_SERVER_SERVER_CONFIG__

File diff suppressed because it is too large Load Diff

View File

@ -1,63 +1,63 @@
/*! /*!
* *
* \author: einhornimmond * \author: einhornimmond
* *
* \date: 07.03.19 * \date: 07.03.19
* *
* \brief: error data * \brief: error data
*/ */
#ifndef DR_LUA_WEB_MODULE_ERROR_ERROR_H #ifndef DR_LUA_WEB_MODULE_ERROR_ERROR_H
#define DR_LUA_WEB_MODULE_ERROR_ERROR_H #define DR_LUA_WEB_MODULE_ERROR_ERROR_H
#include <string> #include <string>
#include <sstream> #include <sstream>
class Error class Error
{ {
public: public:
Error(const char* functionName, const char* message); Error(const char* functionName, const char* message);
~Error(); ~Error();
const char* getFunctionName() { return mFunctionName.data(); } const char* getFunctionName() { return mFunctionName.data(); }
const char* getMessage() { return mMessage.data(); } const char* getMessage() { return mMessage.data(); }
virtual std::string getString(bool withNewline = true); virtual std::string getString(bool withNewline = true);
virtual std::string getHtmlString(); virtual std::string getHtmlString();
protected: protected:
std::string mFunctionName; std::string mFunctionName;
std::string mMessage; std::string mMessage;
}; };
class ParamError : public Error class ParamError : public Error
{ {
public: public:
ParamError(const char* functionName, const char* message, const char* param) ParamError(const char* functionName, const char* message, const char* param)
: Error(functionName, message), mParam(param) {} : Error(functionName, message), mParam(param) {}
ParamError(const char* functionName, const char* message, const std::string& param) ParamError(const char* functionName, const char* message, const std::string& param)
: Error(functionName, message), mParam(param) {} : Error(functionName, message), mParam(param) {}
ParamError(const char* functioName, const char* message, int param) ParamError(const char* functioName, const char* message, int param)
: Error(functioName, message) { : Error(functioName, message) {
std::stringstream ss; std::stringstream ss;
ss << param; ss << param;
mParam = ss.str(); mParam = ss.str();
} }
virtual std::string getString(bool withNewline = true); virtual std::string getString(bool withNewline = true);
virtual std::string getHtmlString(); virtual std::string getHtmlString();
protected: protected:
std::string mParam; std::string mParam;
}; };
class IErrorCollection class IErrorCollection
{ {
public: public:
virtual void addError(Error*, bool log = true) = 0; virtual void addError(Error*, bool log = true) = 0;
}; };
#endif // DR_LUA_WEB_MODULE_ERROR_ERROR_H #endif // DR_LUA_WEB_MODULE_ERROR_ERROR_H

View File

@ -1,201 +1,201 @@
#include "ErrorList.h" #include "ErrorList.h"
#include "../ServerConfig.h" #include "../ServerConfig.h"
//#include "Poco/Net/MailMessage.h" //#include "Poco/Net/MailMessage.h"
#include "Poco/Net/MediaType.h" #include "Poco/Net/MediaType.h"
#include "../SingletonManager/EmailManager.h" #include "../SingletonManager/EmailManager.h"
SendErrorMessage::~SendErrorMessage() SendErrorMessage::~SendErrorMessage()
{ {
if (mMessage) { if (mMessage) {
delete mMessage; delete mMessage;
mMessage = nullptr; mMessage = nullptr;
} }
} }
int SendErrorMessage::run() int SendErrorMessage::run()
{ {
if (ServerConfig::g_disableEmail) return 0; if (ServerConfig::g_disableEmail) return 0;
auto mailClientSession = new Poco::Net::SecureSMTPClientSession(ServerConfig::g_EmailAccount.url, ServerConfig::g_EmailAccount.port); auto mailClientSession = new Poco::Net::SecureSMTPClientSession(ServerConfig::g_EmailAccount.url, ServerConfig::g_EmailAccount.port);
mailClientSession->login(); mailClientSession->login();
mailClientSession->startTLS(ServerConfig::g_SSL_CLient_Context); mailClientSession->startTLS(ServerConfig::g_SSL_CLient_Context);
mailClientSession->login(Poco::Net::SMTPClientSession::AUTH_LOGIN, ServerConfig::g_EmailAccount.username, ServerConfig::g_EmailAccount.password); mailClientSession->login(Poco::Net::SMTPClientSession::AUTH_LOGIN, ServerConfig::g_EmailAccount.username, ServerConfig::g_EmailAccount.password);
try { try {
mMessage->setSender(ServerConfig::g_EmailAccount.sender); mMessage->setSender(ServerConfig::g_EmailAccount.sender);
mailClientSession->sendMessage(*mMessage); mailClientSession->sendMessage(*mMessage);
mailClientSession->close(); mailClientSession->close();
} }
catch (Poco::Exception& exc) { catch (Poco::Exception& exc) {
printf("[SendErrorMessage::%s] error sending error message to admin: %s\n", printf("[SendErrorMessage::%s] error sending error message to admin: %s\n",
__FUNCTION__, exc.displayText().data()); __FUNCTION__, exc.displayText().data());
return -1; return -1;
} }
return 0; return 0;
} }
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
ErrorList::ErrorList() ErrorList::ErrorList()
: mLogging(Poco::Logger::get("errorLog")) : mLogging(Poco::Logger::get("errorLog"))
{ {
} }
ErrorList::~ErrorList() ErrorList::~ErrorList()
{ {
while (mErrorStack.size() > 0) { while (mErrorStack.size() > 0) {
delete mErrorStack.top(); delete mErrorStack.top();
mErrorStack.pop(); mErrorStack.pop();
} }
} }
void ErrorList::addError(Error* error, bool log/* = true */) void ErrorList::addError(Error* error, bool log/* = true */)
{ {
if (log) { if (log) {
std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d.%m.%y %H:%M:%S"); std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d.%m.%y %H:%M:%S");
mLogging.error("%s [ErrorList::addError] %s", dateTimeString, error->getString(false)); mLogging.error("%s [ErrorList::addError] %s", dateTimeString, error->getString(false));
} }
mErrorStack.push(error); mErrorStack.push(error);
} }
Error* ErrorList::getLastError() Error* ErrorList::getLastError()
{ {
if (mErrorStack.size() == 0) { if (mErrorStack.size() == 0) {
return nullptr; return nullptr;
} }
Error* error = mErrorStack.top(); Error* error = mErrorStack.top();
if (error) { if (error) {
mErrorStack.pop(); mErrorStack.pop();
} }
return error; return error;
} }
void ErrorList::clearErrors() void ErrorList::clearErrors()
{ {
while (mErrorStack.size()) { while (mErrorStack.size()) {
auto error = mErrorStack.top(); auto error = mErrorStack.top();
if (error) { if (error) {
delete error; delete error;
} }
mErrorStack.pop(); mErrorStack.pop();
} }
} }
int ErrorList::getErrors(ErrorList* send) int ErrorList::getErrors(ErrorList* send)
{ {
Error* error = nullptr; Error* error = nullptr;
int iCount = 0; int iCount = 0;
while (error = send->getLastError()) { while (error = send->getLastError()) {
addError(error, false); addError(error, false);
iCount++; iCount++;
} }
return iCount; return iCount;
} }
void ErrorList::printErrors() void ErrorList::printErrors()
{ {
while (mErrorStack.size() > 0) { while (mErrorStack.size() > 0) {
auto error = mErrorStack.top(); auto error = mErrorStack.top();
mErrorStack.pop(); mErrorStack.pop();
printf(error->getString().data()); printf(error->getString().data());
delete error; delete error;
} }
} }
std::vector<std::string> ErrorList::getErrorsArray() std::vector<std::string> ErrorList::getErrorsArray()
{ {
std::vector<std::string> result; std::vector<std::string> result;
result.reserve(mErrorStack.size()); result.reserve(mErrorStack.size());
while (mErrorStack.size() > 0) { while (mErrorStack.size() > 0) {
auto error = mErrorStack.top(); auto error = mErrorStack.top();
mErrorStack.pop(); mErrorStack.pop();
//result->add(error->getString()); //result->add(error->getString());
result.push_back(error->getString()); result.push_back(error->getString());
delete error; delete error;
} }
return result; return result;
} }
std::string ErrorList::getErrorsHtml() std::string ErrorList::getErrorsHtml()
{ {
std::string res; std::string res;
res = "<ul class='grd-no-style'>"; res = "<ul class='grd-no-style'>";
while (mErrorStack.size() > 0) { while (mErrorStack.size() > 0) {
auto error = mErrorStack.top(); auto error = mErrorStack.top();
mErrorStack.pop(); mErrorStack.pop();
res += "<li class='grd-error'>"; res += "<li class='grd-error'>";
res += error->getHtmlString(); res += error->getHtmlString();
res += "</li>"; res += "</li>";
delete error; delete error;
} }
res += "</ul>"; res += "</ul>";
return res; return res;
} }
std::string ErrorList::getErrorsHtmlNewFormat() std::string ErrorList::getErrorsHtmlNewFormat()
{ {
std::string html; std::string html;
while (mErrorStack.size() > 0) { while (mErrorStack.size() > 0) {
auto error = std::unique_ptr<Error>(mErrorStack.top()); auto error = std::unique_ptr<Error>(mErrorStack.top());
mErrorStack.pop(); mErrorStack.pop();
html += "<div class=\"alert alert-error\" role=\"alert\">"; html += "<div class=\"alert alert-error\" role=\"alert\">";
html += "<i class=\"material-icons-outlined\">report_problem</i>"; html += "<i class=\"material-icons-outlined\">report_problem</i>";
html += "<span>"; html += "<span>";
html += error->getHtmlString(); html += error->getHtmlString();
html += "</span>"; html += "</span>";
html += "</div>"; html += "</div>";
} }
return html; return html;
} }
/* /*
<div class="alert alert-error" role="alert"> <div class="alert alert-error" role="alert">
<i class="material-icons-outlined">report_problem</i> <i class="material-icons-outlined">report_problem</i>
<span>Der Empfänger wurde nicht auf dem Login-Server gefunden, hat er sein Konto schon angelegt?</span> <span>Der Empfänger wurde nicht auf dem Login-Server gefunden, hat er sein Konto schon angelegt?</span>
</div> </div>
*/ */
void ErrorList::sendErrorsAsEmail(std::string rawHtml/* = ""*/) void ErrorList::sendErrorsAsEmail(std::string rawHtml/* = ""*/)
{ {
auto em = EmailManager::getInstance(); auto em = EmailManager::getInstance();
/*auto message = new Poco::Net::MailMessage(); /*auto message = new Poco::Net::MailMessage();
message->setSender("gradido_loginServer@gradido.net"); message->setSender("gradido_loginServer@gradido.net");
message->addRecipient(Poco::Net::MailRecipient(Poco::Net::MailRecipient::PRIMARY_RECIPIENT, "***REMOVED***")); message->addRecipient(Poco::Net::MailRecipient(Poco::Net::MailRecipient::PRIMARY_RECIPIENT, "***REMOVED***"));
message->setSubject("Error from Gradido Login Server"); message->setSubject("Error from Gradido Login Server");
*/ */
std::string content; std::string content;
while (mErrorStack.size() > 0) { while (mErrorStack.size() > 0) {
auto error = mErrorStack.top(); auto error = mErrorStack.top();
mErrorStack.pop(); mErrorStack.pop();
content += error->getString(); content += error->getString();
delete error; delete error;
} }
auto email = new model::Email(content, model::EMAIL_ERROR); auto email = new model::Email(content, model::EMAIL_ERROR);
//message->addContent(new Poco::Net::StringPartSource(content)); //message->addContent(new Poco::Net::StringPartSource(content));
if (rawHtml != "") { if (rawHtml != "") {
Poco::Net::MediaType mt("text", "html"); Poco::Net::MediaType mt("text", "html");
mt.setParameter("charset", "utf-8"); mt.setParameter("charset", "utf-8");
email->addContent(new Poco::Net::StringPartSource(rawHtml, mt.toString())); email->addContent(new Poco::Net::StringPartSource(rawHtml, mt.toString()));
} }
em->addEmail(email); em->addEmail(email);
//UniLib::controller::TaskPtr sendErrorMessageTask(new SendErrorMessage(message, ServerConfig::g_CPUScheduler)); //UniLib::controller::TaskPtr sendErrorMessageTask(new SendErrorMessage(message, ServerConfig::g_CPUScheduler));
//sendErrorMessageTask->scheduleTask(sendErrorMessageTask); //sendErrorMessageTask->scheduleTask(sendErrorMessageTask);
} }

View File

@ -1,76 +1,76 @@
/*! /*!
* *
* \author: einhornimmond * \author: einhornimmond
* *
* \date: 07.03.19 * \date: 07.03.19
* *
* \brief: error * \brief: error
*/ */
#ifndef DR_LUA_WEB_MODULE_ERROR_ERROR_LIST_H #ifndef DR_LUA_WEB_MODULE_ERROR_ERROR_LIST_H
#define DR_LUA_WEB_MODULE_ERROR_ERROR_LIST_H #define DR_LUA_WEB_MODULE_ERROR_ERROR_LIST_H
#include "Error.h" #include "Error.h"
#include <stack> #include <stack>
#include "../tasks/CPUTask.h" #include "../tasks/CPUTask.h"
#include "Poco/Net/SecureSMTPClientSession.h" #include "Poco/Net/SecureSMTPClientSession.h"
#include "Poco/Net/StringPartSource.h" #include "Poco/Net/StringPartSource.h"
#include "Poco/Logger.h" #include "Poco/Logger.h"
#include "Poco/JSON/Array.h" #include "Poco/JSON/Array.h"
class ErrorList : public IErrorCollection class ErrorList : public IErrorCollection
{ {
public: public:
ErrorList(); ErrorList();
~ErrorList(); ~ErrorList();
// push error, error will be deleted in deconstructor // push error, error will be deleted in deconstructor
virtual void addError(Error* error, bool log = true); virtual void addError(Error* error, bool log = true);
// return error on top of stack, please delete after using // return error on top of stack, please delete after using
Error* getLastError(); Error* getLastError();
inline size_t errorCount() { return mErrorStack.size(); } inline size_t errorCount() { return mErrorStack.size(); }
// delete all errors // delete all errors
void clearErrors(); void clearErrors();
static int moveErrors(ErrorList* recv, ErrorList* send) { static int moveErrors(ErrorList* recv, ErrorList* send) {
return recv->getErrors(send); return recv->getErrors(send);
} }
int getErrors(ErrorList* send); int getErrors(ErrorList* send);
void printErrors(); void printErrors();
std::string getErrorsHtml(); std::string getErrorsHtml();
std::string getErrorsHtmlNewFormat(); std::string getErrorsHtmlNewFormat();
std::vector<std::string> getErrorsArray(); std::vector<std::string> getErrorsArray();
void sendErrorsAsEmail(std::string rawHtml = ""); void sendErrorsAsEmail(std::string rawHtml = "");
protected: protected:
std::stack<Error*> mErrorStack; std::stack<Error*> mErrorStack;
// poco logging // poco logging
Poco::Logger& mLogging; Poco::Logger& mLogging;
}; };
class SendErrorMessage : public UniLib::controller::CPUTask class SendErrorMessage : public UniLib::controller::CPUTask
{ {
public: public:
SendErrorMessage(Poco::Net::MailMessage* message, UniLib::controller::CPUSheduler* scheduler) SendErrorMessage(Poco::Net::MailMessage* message, UniLib::controller::CPUSheduler* scheduler)
: UniLib::controller::CPUTask(scheduler), mMessage(message) {} : UniLib::controller::CPUTask(scheduler), mMessage(message) {}
~SendErrorMessage(); ~SendErrorMessage();
virtual int run(); virtual int run();
const char* getResourceType() const { return "SendErrorMessage"; }; const char* getResourceType() const { return "SendErrorMessage"; };
protected: protected:
Poco::Net::MailMessage* mMessage; Poco::Net::MailMessage* mMessage;
}; };
#endif // DR_LUA_WEB_MODULE_ERROR_ERROR_LIST_H #endif // DR_LUA_WEB_MODULE_ERROR_ERROR_LIST_H

View File

@ -1,57 +1,57 @@
#include "Gradido_LoginServer.h" #include "Gradido_LoginServer.h"
#include <sodium.h> #include <sodium.h>
#include "proto/gradido/TransactionBody.pb.h" #include "proto/gradido/TransactionBody.pb.h"
#include "model/User.h" #include "model/User.h"
#include "model/Session.h" #include "model/Session.h"
#include "lib/Profiler.h" #include "lib/Profiler.h"
#include "ServerConfig.h" #include "ServerConfig.h"
#include "ImportantTests.h" #include "ImportantTests.h"
#include "model/table/User.h" #include "model/table/User.h"
#include "model/table/EmailOptIn.h" #include "model/table/EmailOptIn.h"
#include "Poco/DateTimeParser.h" #include "Poco/DateTimeParser.h"
#ifndef _TEST_BUILD #ifndef _TEST_BUILD
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
GOOGLE_PROTOBUF_VERIFY_VERSION; GOOGLE_PROTOBUF_VERIFY_VERSION;
if (sodium_init() < 0) { if (sodium_init() < 0) {
/* panic! the library couldn't be initialized, it is not safe to use */ /* panic! the library couldn't be initialized, it is not safe to use */
printf("error initializing sodium, early exit\n"); printf("error initializing sodium, early exit\n");
return -1; return -1;
} }
std::string dateTimeString = __DATE__; std::string dateTimeString = __DATE__;
//printf("Building date time string: %s\n", dateTimeString.data()); //printf("Building date time string: %s\n", dateTimeString.data());
std::string formatString("%b %d %Y"); std::string formatString("%b %d %Y");
int timeZone = 0; int timeZone = 0;
Poco::DateTime buildDateTime = Poco::DateTimeParser::parse(formatString, dateTimeString, timeZone); Poco::DateTime buildDateTime = Poco::DateTimeParser::parse(formatString, dateTimeString, timeZone);
ServerConfig::g_versionString = Poco::DateTimeFormatter::format(buildDateTime, "0.%y.%m.%d"); ServerConfig::g_versionString = Poco::DateTimeFormatter::format(buildDateTime, "0.%y.%m.%d");
//ServerConfig::g_versionString = "0.20.KW13.02"; //ServerConfig::g_versionString = "0.20.KW13.02";
printf("Version: %s\n", ServerConfig::g_versionString.data()); printf("Version: %s\n", ServerConfig::g_versionString.data());
printf("User size: %d Bytes, Session size: %d Bytes\n", sizeof(User), sizeof(Session)); printf("User size: %d Bytes, Session size: %d Bytes\n", sizeof(User), sizeof(Session));
printf("model sizes: User: %d Bytes, EmailOptIn: %d Bytes\n", sizeof(model::table::User), sizeof(model::table::EmailOptIn)); printf("model sizes: User: %d Bytes, EmailOptIn: %d Bytes\n", sizeof(model::table::User), sizeof(model::table::EmailOptIn));
// load word lists // load word lists
if (!ServerConfig::loadMnemonicWordLists()) { if (!ServerConfig::loadMnemonicWordLists()) {
//printf("[Gradido_LoginServer::%s] error loading mnemonic Word List\n", __FUNCTION__); //printf("[Gradido_LoginServer::%s] error loading mnemonic Word List\n", __FUNCTION__);
printf("[Gradido_LoginServer::main] error loading mnemonic Word List"); printf("[Gradido_LoginServer::main] error loading mnemonic Word List");
return -2; return -2;
} }
if (!ImportantTests::passphraseGenerationAndTransformation()) { if (!ImportantTests::passphraseGenerationAndTransformation()) {
printf("test passphrase generation and transformation failed\n"); printf("test passphrase generation and transformation failed\n");
return -3; return -3;
} }
Gradido_LoginServer app; Gradido_LoginServer app;
app.setUnixOptions(true); app.setUnixOptions(true);
return app.run(argc, argv); return app.run(argc, argv);
} }
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -1,282 +1,282 @@
/*! /*!
* *
* \author: einhornimmond * \author: einhornimmond
* *
* \date: 02.03.19 * \date: 02.03.19
* *
* \brief: store session data * \brief: store session data
*/ */
#ifndef DR_LUA_WEB_MODULE_SESSION_SESSION_H #ifndef DR_LUA_WEB_MODULE_SESSION_SESSION_H
#define DR_LUA_WEB_MODULE_SESSION_SESSION_H #define DR_LUA_WEB_MODULE_SESSION_SESSION_H
#include "../lib/ErrorList.h" #include "../lib/ErrorList.h"
#include "User.h" #include "User.h"
#include "../controller/User.h" #include "../controller/User.h"
#include "../lib/MultithreadContainer.h" #include "../lib/MultithreadContainer.h"
#include "../tasks/ProcessingTransaction.h" #include "../tasks/ProcessingTransaction.h"
#include "../SingletonManager/LanguageManager.h" #include "../SingletonManager/LanguageManager.h"
#include "../controller/EmailVerificationCode.h" #include "../controller/EmailVerificationCode.h"
#include "Poco/Thread.h" #include "Poco/Thread.h"
#include "Poco/Types.h" #include "Poco/Types.h"
#include "Poco/DateTime.h" #include "Poco/DateTime.h"
#include "Poco/Net/IPAddress.h" #include "Poco/Net/IPAddress.h"
#include "Poco/Net/HTTPCookie.h" #include "Poco/Net/HTTPCookie.h"
#include <mutex> #include <mutex>
class WriteEmailVerification; class WriteEmailVerification;
enum SessionStates { enum SessionStates {
SESSION_STATE_EMPTY, SESSION_STATE_EMPTY,
SESSION_STATE_CRYPTO_KEY_GENERATED, SESSION_STATE_CRYPTO_KEY_GENERATED,
SESSION_STATE_USER_WRITTEN, SESSION_STATE_USER_WRITTEN,
SESSION_STATE_EMAIL_VERIFICATION_WRITTEN, SESSION_STATE_EMAIL_VERIFICATION_WRITTEN,
SESSION_STATE_EMAIL_VERIFICATION_SEND, SESSION_STATE_EMAIL_VERIFICATION_SEND,
SESSION_STATE_EMAIL_VERIFICATION_CODE_CHECKED, SESSION_STATE_EMAIL_VERIFICATION_CODE_CHECKED,
SESSION_STATE_PASSPHRASE_GENERATED, SESSION_STATE_PASSPHRASE_GENERATED,
SESSION_STATE_PASSPHRASE_SHOWN, SESSION_STATE_PASSPHRASE_SHOWN,
SESSION_STATE_PASSPHRASE_WRITTEN, SESSION_STATE_PASSPHRASE_WRITTEN,
SESSION_STATE_KEY_PAIR_GENERATED, SESSION_STATE_KEY_PAIR_GENERATED,
SESSION_STATE_KEY_PAIR_WRITTEN, SESSION_STATE_KEY_PAIR_WRITTEN,
SESSION_STATE_RESET_PASSWORD_REQUEST, SESSION_STATE_RESET_PASSWORD_REQUEST,
SESSION_STATE_RESET_PASSWORD_SUCCEED, SESSION_STATE_RESET_PASSWORD_SUCCEED,
SESSION_STATE_COUNT SESSION_STATE_COUNT
}; };
class SessionManager; class SessionManager;
class UpdateUserPasswordPage; class UpdateUserPasswordPage;
class PassphrasePage; class PassphrasePage;
class RepairDefectPassphrase; class RepairDefectPassphrase;
class Session : public ErrorList, public UniLib::lib::MultithreadContainer class Session : public ErrorList, public UniLib::lib::MultithreadContainer
{ {
friend WriteEmailVerification; friend WriteEmailVerification;
friend SessionManager; friend SessionManager;
friend UpdateUserPasswordPage; friend UpdateUserPasswordPage;
friend PassphrasePage; friend PassphrasePage;
friend RepairDefectPassphrase; friend RepairDefectPassphrase;
public: public:
Session(int handle); Session(int handle);
~Session(); ~Session();
// get new model objects // get new model objects
Poco::AutoPtr<controller::EmailVerificationCode> getEmailVerificationCodeObject(); Poco::AutoPtr<controller::EmailVerificationCode> getEmailVerificationCodeObject();
// set new model objects // set new model objects
inline void setUser(Poco::AutoPtr<controller::User> user) { mNewUser = user; } inline void setUser(Poco::AutoPtr<controller::User> user) { mNewUser = user; }
inline Poco::AutoPtr<controller::User> getNewUser() { return mNewUser; } inline Poco::AutoPtr<controller::User> getNewUser() { return mNewUser; }
// ---------------- User functions ---------------------------- // ---------------- User functions ----------------------------
// TODO: register state: written into db, mails sended, update state only if new state is higher as old state // TODO: register state: written into db, mails sended, update state only if new state is higher as old state
// create User send e-mail activation link // create User send e-mail activation link
bool createUser(const std::string& first_name, const std::string& last_name, const std::string& email, const std::string& password); bool createUser(const std::string& first_name, const std::string& last_name, const std::string& email, const std::string& password);
//! \brief new register function, without showing user pubkeys, using controller/user //! \brief new register function, without showing user pubkeys, using controller/user
bool createUserDirect(const std::string& first_name, const std::string& last_name, const std::string& email, const std::string& password); bool createUserDirect(const std::string& first_name, const std::string& last_name, const std::string& email, const std::string& password);
// adminRegister without passwort // adminRegister without passwort
bool adminCreateUser(const std::string& first_name, const std::string& last_name, const std::string& email); bool adminCreateUser(const std::string& first_name, const std::string& last_name, const std::string& email);
// TODO: check if email exist and if not, fake waiting on password hashing with profiled times of real password hashing // TODO: check if email exist and if not, fake waiting on password hashing with profiled times of real password hashing
UserStates loadUser(const std::string& email, const std::string& password); UserStates loadUser(const std::string& email, const std::string& password);
bool ifUserExist(const std::string& email); bool ifUserExist(const std::string& email);
inline void setUser(Poco::AutoPtr<User> user) { mSessionUser = user; } inline void setUser(Poco::AutoPtr<User> user) { mSessionUser = user; }
bool deleteUser(); bool deleteUser();
Poco::AutoPtr<User> getUser() { Poco::AutoPtr<User> getUser() {
return mSessionUser; return mSessionUser;
} }
// ------------------------- Email Verification Code functions ------------------------------- // ------------------------- Email Verification Code functions -------------------------------
bool loadFromEmailVerificationCode(Poco::UInt64 emailVerificationCode); bool loadFromEmailVerificationCode(Poco::UInt64 emailVerificationCode);
//! \return 1 = konto already exist //! \return 1 = konto already exist
//! -1 = invalid code //! -1 = invalid code
//! -2 = critical error //! -2 = critical error
//! 0 = ok //! 0 = ok
int updateEmailVerification(Poco::UInt64 emailVerificationCode); int updateEmailVerification(Poco::UInt64 emailVerificationCode);
// called from page with same name // called from page with same name
//! \return 1 = reset password email already send //! \return 1 = reset password email already send
//! \return 2 = reset password email already shortly before //! \return 2 = reset password email already shortly before
//! \return 0 = ok //! \return 0 = ok
int sendResetPasswordEmail(Poco::AutoPtr<controller::User> user, bool passphraseMemorized); int sendResetPasswordEmail(Poco::AutoPtr<controller::User> user, bool passphraseMemorized);
// //
//! \return 0 = not the same //! \return 0 = not the same
//! \return 1 = same //! \return 1 = same
//! \return -1 = error //! \return -1 = error
//! \return -2 = critical error //! \return -2 = critical error
int comparePassphraseWithSavedKeys(const std::string& inputPassphrase, Mnemonic* wordSource); int comparePassphraseWithSavedKeys(const std::string& inputPassphrase, Mnemonic* wordSource);
Poco::Net::HTTPCookie getLoginCookie(); Poco::Net::HTTPCookie getLoginCookie();
inline int getHandle() { return mHandleId; } inline int getHandle() { return mHandleId; }
// ------------------------ Passphrase functions ---------------------------- // ------------------------ Passphrase functions ----------------------------
inline void setPassphrase(Poco::AutoPtr<Passphrase> passphrase) { mNewPassphrase = passphrase; } inline void setPassphrase(Poco::AutoPtr<Passphrase> passphrase) { mNewPassphrase = passphrase; }
inline Poco::AutoPtr<Passphrase> getPassphrase() { return mNewPassphrase; } inline Poco::AutoPtr<Passphrase> getPassphrase() { return mNewPassphrase; }
inline void setPassphrase(const std::string& passphrase) { mPassphrase = passphrase; } inline void setPassphrase(const std::string& passphrase) { mPassphrase = passphrase; }
inline const std::string& getOldPassphrase() { return mPassphrase; } inline const std::string& getOldPassphrase() { return mPassphrase; }
bool generatePassphrase(); bool generatePassphrase();
bool generateKeys(bool savePrivkey, bool savePassphrase); bool generateKeys(bool savePrivkey, bool savePassphrase);
inline void setClientIp(Poco::Net::IPAddress ip) { mClientLoginIP = ip; } inline void setClientIp(Poco::Net::IPAddress ip) { mClientLoginIP = ip; }
inline Poco::Net::IPAddress getClientIp() { return mClientLoginIP; } inline Poco::Net::IPAddress getClientIp() { return mClientLoginIP; }
inline bool isIPValid(Poco::Net::IPAddress ip) { return mClientLoginIP == ip; } inline bool isIPValid(Poco::Net::IPAddress ip) { return mClientLoginIP == ip; }
bool isPwdValid(const std::string& pwd); bool isPwdValid(const std::string& pwd);
void reset(); void reset();
void updateState(SessionStates newState); void updateState(SessionStates newState);
const char* getSessionStateString(); const char* getSessionStateString();
inline SessionStates getSessionState() { SessionStates s; lock("Session::getSessionState"); s = mState; unlock(); return s; } inline SessionStates getSessionState() { SessionStates s; lock("Session::getSessionState"); s = mState; unlock(); return s; }
inline Poco::UInt64 getEmailVerificationCode() { inline Poco::UInt64 getEmailVerificationCode() {
std::shared_lock<std::shared_mutex> _lock(mSharedMutex); std::shared_lock<std::shared_mutex> _lock(mSharedMutex);
if (mEmailVerificationCodeObject.isNull()) return 0; return mEmailVerificationCodeObject->getModel()->getCode(); if (mEmailVerificationCodeObject.isNull()) return 0; return mEmailVerificationCodeObject->getModel()->getCode();
} }
inline void setEmailVerificationCodeObject(Poco::AutoPtr<controller::EmailVerificationCode> emailVerficationObject) { inline void setEmailVerificationCodeObject(Poco::AutoPtr<controller::EmailVerificationCode> emailVerficationObject) {
std::unique_lock<std::shared_mutex> _lock(mSharedMutex); std::unique_lock<std::shared_mutex> _lock(mSharedMutex);
mEmailVerificationCodeObject = emailVerficationObject; mEmailVerificationCodeObject = emailVerficationObject;
} }
inline model::table::EmailOptInType getEmailVerificationType() { inline model::table::EmailOptInType getEmailVerificationType() {
std::shared_lock<std::shared_mutex> _lock(mSharedMutex); std::shared_lock<std::shared_mutex> _lock(mSharedMutex);
if (mEmailVerificationCodeObject.isNull()) { if (mEmailVerificationCodeObject.isNull()) {
return model::table::EMAIL_OPT_IN_EMPTY; return model::table::EMAIL_OPT_IN_EMPTY;
} }
return mEmailVerificationCodeObject->getModel()->getType(); return mEmailVerificationCodeObject->getModel()->getType();
} }
//! \return -1 if session is locked //! \return -1 if session is locked
//! \return 1 if session is active //! \return 1 if session is active
//! \return 0 //! \return 0
int isActive(); int isActive();
//! \return false if session is locked //! \return false if session is locked
bool setActive(bool active); bool setActive(bool active);
bool isDeadLocked(); bool isDeadLocked();
inline Poco::DateTime getLastActivity() { return mLastActivity; } inline Poco::DateTime getLastActivity() { return mLastActivity; }
// ------------------------ transactions functions ---------------------------- // ------------------------ transactions functions ----------------------------
//! \return true if succeed //! \return true if succeed
bool startProcessingTransaction(const std::string& proto_message_base64, bool autoSign = false); bool startProcessingTransaction(const std::string& proto_message_base64, bool autoSign = false);
//! \param working if set will filled with transaction running //! \param working if set will filled with transaction running
Poco::AutoPtr<ProcessingTransaction> getNextReadyTransaction(size_t* working = nullptr); Poco::AutoPtr<ProcessingTransaction> getNextReadyTransaction(size_t* working = nullptr);
bool finalizeTransaction(bool sign, bool reject); bool finalizeTransaction(bool sign, bool reject);
size_t getProcessingTransactionCount(); size_t getProcessingTransactionCount();
inline LanguageCatalog* getLanguageCatalog() { return mLanguageCatalog.isNull() ? nullptr : mLanguageCatalog; } inline LanguageCatalog* getLanguageCatalog() { return mLanguageCatalog.isNull() ? nullptr : mLanguageCatalog; }
void setLanguage(Languages lang); void setLanguage(Languages lang);
inline void setLanguageCatalog(Poco::AutoPtr<LanguageCatalog> languageCatalog) { mLanguageCatalog = languageCatalog; } inline void setLanguageCatalog(Poco::AutoPtr<LanguageCatalog> languageCatalog) { mLanguageCatalog = languageCatalog; }
Languages getLanguage(); Languages getLanguage();
inline const char* gettext(const char* text) { if (mLanguageCatalog.isNull()) return text; return mLanguageCatalog->gettext(text); } inline const char* gettext(const char* text) { if (mLanguageCatalog.isNull()) return text; return mLanguageCatalog->gettext(text); }
// last referer // last referer
inline void setLastReferer(const std::string& lastReferer) { mLastExternReferer = lastReferer; } inline void setLastReferer(const std::string& lastReferer) { mLastExternReferer = lastReferer; }
inline const std::string& getLastReferer() const { return mLastExternReferer; } inline const std::string& getLastReferer() const { return mLastExternReferer; }
protected: protected:
void updateTimeout(); void updateTimeout();
inline void setHandle(int newHandle) { mHandleId = newHandle; } inline void setHandle(int newHandle) { mHandleId = newHandle; }
void detectSessionState(); void detectSessionState();
static const char* translateSessionStateToString(SessionStates state); static const char* translateSessionStateToString(SessionStates state);
inline const std::string& getPassphrase() const { return mPassphrase; } inline const std::string& getPassphrase() const { return mPassphrase; }
private: private:
int mHandleId; int mHandleId;
Poco::AutoPtr<User> mSessionUser; Poco::AutoPtr<User> mSessionUser;
Poco::AutoPtr<controller::User> mNewUser; Poco::AutoPtr<controller::User> mNewUser;
std::string mPassphrase; std::string mPassphrase;
Poco::AutoPtr<Passphrase> mNewPassphrase; Poco::AutoPtr<Passphrase> mNewPassphrase;
Poco::DateTime mLastActivity; Poco::DateTime mLastActivity;
Poco::Net::IPAddress mClientLoginIP; Poco::Net::IPAddress mClientLoginIP;
std::string mLastExternReferer; std::string mLastExternReferer;
Poco::AutoPtr<controller::EmailVerificationCode> mEmailVerificationCodeObject; Poco::AutoPtr<controller::EmailVerificationCode> mEmailVerificationCodeObject;
std::shared_mutex mSharedMutex; std::shared_mutex mSharedMutex;
SessionStates mState; SessionStates mState;
bool mActive; bool mActive;
std::list<Poco::AutoPtr<ProcessingTransaction>> mProcessingTransactions; std::list<Poco::AutoPtr<ProcessingTransaction>> mProcessingTransactions;
Poco::AutoPtr<ProcessingTransaction> mCurrentActiveProcessingTransaction; Poco::AutoPtr<ProcessingTransaction> mCurrentActiveProcessingTransaction;
Poco::AutoPtr<LanguageCatalog> mLanguageCatalog; Poco::AutoPtr<LanguageCatalog> mLanguageCatalog;
}; };
class WriteEmailVerification : public UniLib::controller::CPUTask class WriteEmailVerification : public UniLib::controller::CPUTask
{ {
public: public:
WriteEmailVerification(Poco::AutoPtr<User> user, Poco::AutoPtr<controller::EmailVerificationCode> emailVerificationCode, UniLib::controller::CPUSheduler* cpuScheduler, size_t taskDependenceCount = 0) WriteEmailVerification(Poco::AutoPtr<User> user, Poco::AutoPtr<controller::EmailVerificationCode> emailVerificationCode, UniLib::controller::CPUSheduler* cpuScheduler, size_t taskDependenceCount = 0)
: UniLib::controller::CPUTask(cpuScheduler, taskDependenceCount), mUser(user), mEmailVerificationCode(emailVerificationCode) { : UniLib::controller::CPUTask(cpuScheduler, taskDependenceCount), mUser(user), mEmailVerificationCode(emailVerificationCode) {
#ifdef _UNI_LIB_DEBUG #ifdef _UNI_LIB_DEBUG
setName(user->getEmail()); setName(user->getEmail());
#endif #endif
} }
virtual const char* getResourceType() const { return "WriteEmailVerification"; }; virtual const char* getResourceType() const { return "WriteEmailVerification"; };
virtual int run(); virtual int run();
private: private:
Poco::AutoPtr<User> mUser; Poco::AutoPtr<User> mUser;
Poco::AutoPtr<controller::EmailVerificationCode> mEmailVerificationCode; Poco::AutoPtr<controller::EmailVerificationCode> mEmailVerificationCode;
}; };
class WritePassphraseIntoDB : public UniLib::controller::CPUTask class WritePassphraseIntoDB : public UniLib::controller::CPUTask
{ {
public: public:
WritePassphraseIntoDB(int userId, const std::string& passphrase) WritePassphraseIntoDB(int userId, const std::string& passphrase)
: mUserId(userId), mPassphrase(passphrase) { : mUserId(userId), mPassphrase(passphrase) {
#ifdef _UNI_LIB_DEBUG #ifdef _UNI_LIB_DEBUG
setName(std::to_string(userId).data()); setName(std::to_string(userId).data());
#endif #endif
} }
virtual int run(); virtual int run();
virtual const char* getResourceType() const { return "WritePassphraseIntoDB"; }; virtual const char* getResourceType() const { return "WritePassphraseIntoDB"; };
protected: protected:
int mUserId; int mUserId;
std::string mPassphrase; std::string mPassphrase;
}; };
class SessionStateUpdateCommand : public UniLib::controller::Command class SessionStateUpdateCommand : public UniLib::controller::Command
{ {
public: public:
SessionStateUpdateCommand(SessionStates state, Session* session) SessionStateUpdateCommand(SessionStates state, Session* session)
: mState(state), mSession(session) {} : mState(state), mSession(session) {}
virtual int taskFinished(UniLib::controller::Task* task) { virtual int taskFinished(UniLib::controller::Task* task) {
mSession->updateState(mState); mSession->updateState(mState);
return 0; return 0;
} }
protected: protected:
SessionStates mState; SessionStates mState;
Session* mSession; Session* mSession;
}; };
#endif // DR_LUA_WEB_MODULE_SESSION_SESSION_H #endif // DR_LUA_WEB_MODULE_SESSION_SESSION_H

View File

@ -1,72 +1,72 @@
#include "TransactionCreation.h" #include "TransactionCreation.h"
#include "Poco/DateTimeFormatter.h" #include "Poco/DateTimeFormatter.h"
#include <sodium.h> #include <sodium.h>
TransactionCreation::TransactionCreation(const std::string& memo, const model::messages::gradido::TransactionCreation& protoCreation) TransactionCreation::TransactionCreation(const std::string& memo, const model::messages::gradido::TransactionCreation& protoCreation)
: TransactionBase(memo), mProtoCreation(protoCreation), mReceiverUser(nullptr) : TransactionBase(memo), mProtoCreation(protoCreation), mReceiverUser(nullptr)
{ {
memset(mReceiverPublicHex, 0, 65); memset(mReceiverPublicHex, 0, 65);
} }
TransactionCreation::~TransactionCreation() TransactionCreation::~TransactionCreation()
{ {
if (mReceiverUser) { if (mReceiverUser) {
delete mReceiverUser; delete mReceiverUser;
mReceiverUser = nullptr; mReceiverUser = nullptr;
} }
} }
int TransactionCreation::prepare() int TransactionCreation::prepare()
{ {
const static char functionName[] = { "TransactionCreation::prepare" }; const static char functionName[] = { "TransactionCreation::prepare" };
if (!mProtoCreation.has_receiveramount()) { if (!mProtoCreation.has_receiveramount()) {
addError(new Error(functionName, "hasn't receiver amount")); addError(new Error(functionName, "hasn't receiver amount"));
return -1; return -1;
} }
auto receiverAmount = mProtoCreation.receiveramount(); auto receiverAmount = mProtoCreation.receiveramount();
if (receiverAmount.amount() <= 0) { if (receiverAmount.amount() <= 0) {
addError(new Error(functionName, "amount must be > 0")); addError(new Error(functionName, "amount must be > 0"));
return -4; return -4;
} }
if (receiverAmount.amount() > 10000000) { if (receiverAmount.amount() > 10000000) {
addError(new Error(functionName, "amount must be <= 1000 GDD")); addError(new Error(functionName, "amount must be <= 1000 GDD"));
return -5; return -5;
} }
auto receiverPublic = receiverAmount.ed25519_receiver_pubkey(); auto receiverPublic = receiverAmount.ed25519_receiver_pubkey();
if (receiverPublic.size() != 32) { if (receiverPublic.size() != 32) {
addError(new Error(functionName, "receiver public invalid (size not 32)")); addError(new Error(functionName, "receiver public invalid (size not 32)"));
return -2; return -2;
} }
mReceiverUser = new User((const unsigned char*)receiverPublic.data()); mReceiverUser = new User((const unsigned char*)receiverPublic.data());
getErrors(mReceiverUser); getErrors(mReceiverUser);
if (mReceiverUser->getUserState() == USER_EMPTY) { if (mReceiverUser->getUserState() == USER_EMPTY) {
sodium_bin2hex(mReceiverPublicHex, 65, (const unsigned char*)receiverPublic.data(), receiverPublic.size()); sodium_bin2hex(mReceiverPublicHex, 65, (const unsigned char*)receiverPublic.data(), receiverPublic.size());
delete mReceiverUser; delete mReceiverUser;
mReceiverUser = nullptr; mReceiverUser = nullptr;
} }
else { else {
memcpy(mReceiverPublicHex, mReceiverUser->getPublicKeyHex().data(), 64); memcpy(mReceiverPublicHex, mReceiverUser->getPublicKeyHex().data(), 64);
// uncomment because not correctly working // uncomment because not correctly working
/*if (!mReceiverUser->validateIdentHash(mProtoCreation.ident_hash())) { /*if (!mReceiverUser->validateIdentHash(mProtoCreation.ident_hash())) {
addError(new Error(functionName, "ident hash isn't the same")); addError(new Error(functionName, "ident hash isn't the same"));
addError(new ParamError(functionName, "hash calculated from email: ", mReceiverUser->getEmail())); addError(new ParamError(functionName, "hash calculated from email: ", mReceiverUser->getEmail()));
addError(new ParamError(functionName, "hash: ", std::to_string(mProtoCreation.ident_hash()))); addError(new ParamError(functionName, "hash: ", std::to_string(mProtoCreation.ident_hash())));
return -3; return -3;
}*/ }*/
} }
// //
return 0; return 0;
} }
std::string TransactionCreation::getTargetDateString() std::string TransactionCreation::getTargetDateString()
{ {
// proto format is seconds, poco timestamp format is microseconds // proto format is seconds, poco timestamp format is microseconds
Poco::Timestamp pocoStamp(mProtoCreation.target_date().seconds() * 1000*1000); Poco::Timestamp pocoStamp(mProtoCreation.target_date().seconds() * 1000*1000);
//Poco::DateTime(pocoStamp); //Poco::DateTime(pocoStamp);
return Poco::DateTimeFormatter::format(pocoStamp, "%d. %b %y"); return Poco::DateTimeFormatter::format(pocoStamp, "%d. %b %y");
} }

View File

@ -1,172 +1,172 @@
#include "TransactionTransfer.h" #include "TransactionTransfer.h"
const std::string TransactionTransfer::mInvalidIndexMessage("invalid index"); const std::string TransactionTransfer::mInvalidIndexMessage("invalid index");
TransactionTransfer::KontoTableEntry::KontoTableEntry(model::table::User* user, google::protobuf::int64 amount, bool negativeAmount/* = false*/) TransactionTransfer::KontoTableEntry::KontoTableEntry(model::table::User* user, google::protobuf::int64 amount, bool negativeAmount/* = false*/)
{ {
//<span class="content-cell">Normaler&nbsp;User&nbsp;&lt;info@software-labor.de&gt;</span> //<span class="content-cell">Normaler&nbsp;User&nbsp;&lt;info@software-labor.de&gt;</span>
if (!user) return; if (!user) return;
composeAmountCellString(amount, negativeAmount); composeAmountCellString(amount, negativeAmount);
/*kontoNameCell = "<td>"; /*kontoNameCell = "<td>";
kontoNameCell += user->getFirstName(); kontoNameCell += user->getFirstName();
kontoNameCell += "&nbsp;"; kontoNameCell += "&nbsp;";
kontoNameCell += user->getLastName(); kontoNameCell += user->getLastName();
kontoNameCell += "&nbsp;&lt;"; kontoNameCell += "&nbsp;&lt;";
kontoNameCell += user->getEmail(); kontoNameCell += user->getEmail();
kontoNameCell += "&gt;</td>";*/ kontoNameCell += "&gt;</td>";*/
kontoNameCell = "<span class=\"content-cell\">"; kontoNameCell = "<span class=\"content-cell\">";
kontoNameCell += user->getNameWithEmailHtml(); kontoNameCell += user->getNameWithEmailHtml();
kontoNameCell += "</span>"; kontoNameCell += "</span>";
} }
TransactionTransfer::KontoTableEntry::KontoTableEntry(const std::string& pubkeyHex, google::protobuf::int64 amount, bool negativeAmount/* = false*/) TransactionTransfer::KontoTableEntry::KontoTableEntry(const std::string& pubkeyHex, google::protobuf::int64 amount, bool negativeAmount/* = false*/)
{ {
composeAmountCellString(amount, negativeAmount); composeAmountCellString(amount, negativeAmount);
//kontoNameCell = "<td class=\"small\">0x" + pubkeyHex + "</td>"; //kontoNameCell = "<td class=\"small\">0x" + pubkeyHex + "</td>";
kontoNameCell = "<span class = \"content-cell\">" + pubkeyHex + "</span>"; kontoNameCell = "<span class = \"content-cell\">" + pubkeyHex + "</span>";
} }
void TransactionTransfer::KontoTableEntry::composeAmountCellString(google::protobuf::int64 amount, bool negativeAmount) void TransactionTransfer::KontoTableEntry::composeAmountCellString(google::protobuf::int64 amount, bool negativeAmount)
{ {
//<span class="content-cell alert-color">-10 GDD</span> //<span class="content-cell alert-color">-10 GDD</span>
//<span class="content-cell success-color">10 GDD</span> //<span class="content-cell success-color">10 GDD</span>
amountCell = "<span class=\"content-cell "; amountCell = "<span class=\"content-cell ";
if (negativeAmount) { if (negativeAmount) {
amountCell += "alert-color\">-"; amountCell += "alert-color\">-";
} }
else { else {
amountCell += "success-color\">"; amountCell += "success-color\">";
} }
amountCell += amountToString(amount); amountCell += amountToString(amount);
//amountCell += " GDD</td>"; //amountCell += " GDD</td>";
amountCell += " GDD</span>"; amountCell += " GDD</span>";
} }
// ******************************************************************************************************************************** // ********************************************************************************************************************************
TransactionTransfer::TransactionTransfer(const std::string& memo, const model::messages::gradido::Transfer& protoTransfer) TransactionTransfer::TransactionTransfer(const std::string& memo, const model::messages::gradido::Transfer& protoTransfer)
: TransactionBase(memo), mProtoTransfer(protoTransfer) : TransactionBase(memo), mProtoTransfer(protoTransfer)
{ {
} }
TransactionTransfer::~TransactionTransfer() TransactionTransfer::~TransactionTransfer()
{ {
mKontoTable.clear(); mKontoTable.clear();
} }
int TransactionTransfer::prepare() int TransactionTransfer::prepare()
{ {
lock(); lock();
const static char functionName[] = { "TransactionTransfer::prepare" }; const static char functionName[] = { "TransactionTransfer::prepare" };
if (mProtoTransfer.senderamounts_size() == 0) { if (mProtoTransfer.senderamounts_size() == 0) {
addError(new Error(functionName, "hasn't sender amount(s)")); addError(new Error(functionName, "hasn't sender amount(s)"));
unlock(); unlock();
return -1; return -1;
} }
if (mProtoTransfer.receiveramounts_size() == 0) { if (mProtoTransfer.receiveramounts_size() == 0) {
addError(new Error(functionName, "hasn't receiver amount(s)")); addError(new Error(functionName, "hasn't receiver amount(s)"));
unlock(); unlock();
return -2; return -2;
} }
mKontoTable.reserve(mProtoTransfer.senderamounts_size() + mProtoTransfer.receiveramounts_size()); mKontoTable.reserve(mProtoTransfer.senderamounts_size() + mProtoTransfer.receiveramounts_size());
//auto receiverAmount = mProtoTransfer.receiveramount(); //auto receiverAmount = mProtoTransfer.receiveramount();
//auto senderAmount //auto senderAmount
int senderSum = 0; int senderSum = 0;
int receiverSum = 0; int receiverSum = 0;
char pubkeyHexTemp[65]; char pubkeyHexTemp[65];
for (int i = 0; i < mProtoTransfer.senderamounts_size(); i++) { for (int i = 0; i < mProtoTransfer.senderamounts_size(); i++) {
auto senderAmount = mProtoTransfer.senderamounts(i); auto senderAmount = mProtoTransfer.senderamounts(i);
auto pubkey = senderAmount.ed25519_sender_pubkey(); auto pubkey = senderAmount.ed25519_sender_pubkey();
senderSum += senderAmount.amount(); senderSum += senderAmount.amount();
if (pubkey.size() != 32) { if (pubkey.size() != 32) {
addError(new ParamError(functionName, "invalid public key for sender ", i)); addError(new ParamError(functionName, "invalid public key for sender ", i));
unlock(); unlock();
return -3; return -3;
} }
//User user((const unsigned char*)pubkey.data()); //User user((const unsigned char*)pubkey.data());
auto user = controller::User::create(); auto user = controller::User::create();
if (!user->load((const unsigned char*)pubkey.data())) { if (!user->load((const unsigned char*)pubkey.data())) {
sodium_bin2hex(pubkeyHexTemp, 65, (const unsigned char*)pubkey.data(), pubkey.size()); sodium_bin2hex(pubkeyHexTemp, 65, (const unsigned char*)pubkey.data(), pubkey.size());
mKontoTable.push_back(KontoTableEntry(pubkeyHexTemp, senderAmount.amount(), true)); mKontoTable.push_back(KontoTableEntry(pubkeyHexTemp, senderAmount.amount(), true));
} }
else { else {
mKontoTable.push_back(KontoTableEntry(user->getModel(), senderAmount.amount(), true)); mKontoTable.push_back(KontoTableEntry(user->getModel(), senderAmount.amount(), true));
} }
} }
for (int i = 0; i < mProtoTransfer.receiveramounts_size(); i++) { for (int i = 0; i < mProtoTransfer.receiveramounts_size(); i++) {
auto receiverAmount = mProtoTransfer.receiveramounts(i); auto receiverAmount = mProtoTransfer.receiveramounts(i);
auto pubkey = receiverAmount.ed25519_receiver_pubkey(); auto pubkey = receiverAmount.ed25519_receiver_pubkey();
receiverSum += receiverAmount.amount(); receiverSum += receiverAmount.amount();
if (receiverAmount.ed25519_receiver_pubkey().size() != 32) { if (receiverAmount.ed25519_receiver_pubkey().size() != 32) {
addError(new ParamError(functionName, "invalid public key for receiver ", i)); addError(new ParamError(functionName, "invalid public key for receiver ", i));
unlock(); unlock();
return -4; return -4;
} }
auto user = controller::User::create(); auto user = controller::User::create();
if (!user->load((const unsigned char*)pubkey.data())) { if (!user->load((const unsigned char*)pubkey.data())) {
sodium_bin2hex(pubkeyHexTemp, 65, (const unsigned char*)pubkey.data(), pubkey.size()); sodium_bin2hex(pubkeyHexTemp, 65, (const unsigned char*)pubkey.data(), pubkey.size());
mKontoTable.push_back(KontoTableEntry(pubkeyHexTemp, receiverAmount.amount(), false)); mKontoTable.push_back(KontoTableEntry(pubkeyHexTemp, receiverAmount.amount(), false));
} }
else { else {
mKontoTable.push_back(KontoTableEntry(user->getModel(), receiverAmount.amount(), false)); mKontoTable.push_back(KontoTableEntry(user->getModel(), receiverAmount.amount(), false));
} }
} }
if (senderSum != receiverSum) { if (senderSum != receiverSum) {
addError(new Error(functionName, "sender amounts sum != receiver amounts sum")); addError(new Error(functionName, "sender amounts sum != receiver amounts sum"));
unlock(); unlock();
return -5; return -5;
} }
if (senderSum < 0) { if (senderSum < 0) {
addError(new Error(functionName, "negative amount not supported")); addError(new Error(functionName, "negative amount not supported"));
unlock(); unlock();
return -6; return -6;
} }
/* /*
mReceiverUser = new User(receiverPublic.data()); mReceiverUser = new User(receiverPublic.data());
getErrors(mReceiverUser); getErrors(mReceiverUser);
if (mReceiverUser->getUserState() == USER_EMPTY) { if (mReceiverUser->getUserState() == USER_EMPTY) {
sodium_bin2hex(mReceiverPublicHex, 65, (const unsigned char*)receiverPublic.data(), receiverPublic.size()); sodium_bin2hex(mReceiverPublicHex, 65, (const unsigned char*)receiverPublic.data(), receiverPublic.size());
delete mReceiverUser; delete mReceiverUser;
mReceiverUser = nullptr; mReceiverUser = nullptr;
} }
else { else {
memcpy(mReceiverPublicHex, mReceiverUser->getPublicKeyHex().data(), 64); memcpy(mReceiverPublicHex, mReceiverUser->getPublicKeyHex().data(), 64);
} }
//*/ //*/
unlock(); unlock();
return 0; return 0;
} }
const std::string& TransactionTransfer::getKontoNameCell(int index) const std::string& TransactionTransfer::getKontoNameCell(int index)
{ {
lock(); lock();
if (index >= mKontoTable.size()) { if (index >= mKontoTable.size()) {
unlock(); unlock();
return mInvalidIndexMessage; return mInvalidIndexMessage;
} }
unlock(); unlock();
return mKontoTable[index].kontoNameCell; return mKontoTable[index].kontoNameCell;
} }
const std::string& TransactionTransfer::getAmountCell(int index) const std::string& TransactionTransfer::getAmountCell(int index)
{ {
lock(); lock();
if (index >= mKontoTable.size()) { if (index >= mKontoTable.size()) {
unlock(); unlock();
return mInvalidIndexMessage; return mInvalidIndexMessage;
} }
unlock(); unlock();
return mKontoTable[index].amountCell; return mKontoTable[index].amountCell;
} }

View File

@ -1,40 +1,40 @@
#include "AuthenticatedEncryptionCreateKeyTask.h" #include "AuthenticatedEncryptionCreateKeyTask.h"
#include "../ServerConfig.h" #include "../ServerConfig.h"
#include "../SingletonManager/SingletonTaskObserver.h" #include "../SingletonManager/SingletonTaskObserver.h"
#include "../SingletonManager/ErrorManager.h" #include "../SingletonManager/ErrorManager.h"
#include "../lib/Profiler.h" #include "../lib/Profiler.h"
AuthenticatedEncryptionCreateKeyTask::AuthenticatedEncryptionCreateKeyTask(Poco::AutoPtr<controller::User> user, const std::string& passwd) AuthenticatedEncryptionCreateKeyTask::AuthenticatedEncryptionCreateKeyTask(Poco::AutoPtr<controller::User> user, const std::string& passwd)
: UniLib::controller::CPUTask(ServerConfig::g_CryptoCPUScheduler), mUser(user), mPassword(passwd) : UniLib::controller::CPUTask(ServerConfig::g_CryptoCPUScheduler), mUser(user), mPassword(passwd)
{ {
assert(!mUser.isNull()); assert(!mUser.isNull());
SingletonTaskObserver::getInstance()->addTask(mUser->getModel()->getEmail(), TASK_OBSERVER_PASSWORD_CREATION); SingletonTaskObserver::getInstance()->addTask(mUser->getModel()->getEmail(), TASK_OBSERVER_PASSWORD_CREATION);
} }
AuthenticatedEncryptionCreateKeyTask::~AuthenticatedEncryptionCreateKeyTask() AuthenticatedEncryptionCreateKeyTask::~AuthenticatedEncryptionCreateKeyTask()
{ {
SingletonTaskObserver::getInstance()->removeTask(mUser->getModel()->getEmail(), TASK_OBSERVER_PASSWORD_CREATION); SingletonTaskObserver::getInstance()->removeTask(mUser->getModel()->getEmail(), TASK_OBSERVER_PASSWORD_CREATION);
} }
int AuthenticatedEncryptionCreateKeyTask::run() int AuthenticatedEncryptionCreateKeyTask::run()
{ {
auto em = ErrorManager::getInstance(); auto em = ErrorManager::getInstance();
const static char* function_name = "AuthenticatedEncryptionCreateKeyTask::run"; const static char* function_name = "AuthenticatedEncryptionCreateKeyTask::run";
auto authenticated_encryption = new AuthenticatedEncryption; auto authenticated_encryption = new AuthenticatedEncryption;
Profiler timeUsed; Profiler timeUsed;
if (AuthenticatedEncryption::AUTH_ENCRYPT_OK != authenticated_encryption->createKey(mUser->getModel()->getEmail(), mPassword)) { if (AuthenticatedEncryption::AUTH_ENCRYPT_OK != authenticated_encryption->createKey(mUser->getModel()->getEmail(), mPassword)) {
em->addError(new Error(function_name, "error creating key")); em->addError(new Error(function_name, "error creating key"));
em->addError(new ParamError(function_name, "for email", mUser->getModel()->getEmail())); em->addError(new ParamError(function_name, "for email", mUser->getModel()->getEmail()));
em->addError(new ParamError(function_name, "strerror: ", strerror(errno))); em->addError(new ParamError(function_name, "strerror: ", strerror(errno)));
em->sendErrorsAsEmail(); em->sendErrorsAsEmail();
return -1; return -1;
} }
//printf("create password time: %s\n", timeUsed.string().data()); //printf("create password time: %s\n", timeUsed.string().data());
timeUsed.reset(); timeUsed.reset();
mUser->setNewPassword(authenticated_encryption); mUser->setNewPassword(authenticated_encryption);
//printf("set password time: %s\n", timeUsed.string().data()); //printf("set password time: %s\n", timeUsed.string().data());
return 0; return 0;
} }

View File

@ -0,0 +1,65 @@
#include "PrepareEmailTask.h"
#include "../lib/Profiler.h"
#include "../ServerConfig.h"
#include "../SingletonManager/ErrorManager.h"
#include "Poco/Net/SSLException.h"
PrepareEmailTask::PrepareEmailTask(UniLib::controller::CPUSheduler* cpuScheduler)
: UniLib::controller::CPUTask(cpuScheduler), mMailClientSession(nullptr)
{
}
PrepareEmailTask::~PrepareEmailTask()
{
if (mMailClientSession) {
delete mMailClientSession;
}
}
int PrepareEmailTask::run()
{
if (ServerConfig::g_disableEmail) return 0;
Profiler timeUsed;
mMailClientSession = new Poco::Net::SecureSMTPClientSession(ServerConfig::g_EmailAccount.url, ServerConfig::g_EmailAccount.port);
mMailClientSession->login();
try {
mMailClientSession->startTLS(ServerConfig::g_SSL_CLient_Context);
mMailClientSession->login(Poco::Net::SMTPClientSession::AUTH_LOGIN, ServerConfig::g_EmailAccount.username, ServerConfig::g_EmailAccount.password);
} catch(Poco::Net::SSLException& ex) {
printf("[PrepareEmailTask] ssl certificate error: %s\nPlease make sure you have cacert.pem (CA/root certificates) next to binary from https://curl.haxx.se/docs/caextract.html\n", ex.displayText().data());
return -1;
}
//printf("[PrepareEmailTask] time: %s\n", timeUsed.string().data());
/*
session.login();
session.startTLS(pContext);
if (!username.empty())
{
session.login(SMTPClientSession::AUTH_LOGIN, username, password);
}
session.sendMessage(message);
session.close();
*/
return 0;
}
int PrepareEmailTask::send(Poco::Net::MailMessage* message)
{
if (ServerConfig::g_disableEmail) return 0;
auto er = ErrorManager::getInstance();
try {
mMailClientSession->sendMessage(*message);
mMailClientSession->close();
}
catch (Poco::Exception& exc) {
er->addError(new ParamError("PrepareEmailTask::send", "error sending email", exc.displayText().data()));
printf("[PrepareEmailTask::%s] error sending email: %s\n", __FUNCTION__, exc.displayText().data());
return -1;
}
return 0;
}

View File

@ -0,0 +1,25 @@
#ifndef GRADIDO_LOGIN_SERVER_TASKS_PREPAIRE_EMAIL_TASK_INCLUDE
#define GRADIDO_LOGIN_SERVER_TASKS_PREPAIRE_EMAIL_TASK_INCLUDE
#include "CPUTask.h"
#include "Poco/Net/SecureSMTPClientSession.h"
class PrepareEmailTask : public UniLib::controller::CPUTask
{
public:
PrepareEmailTask(UniLib::controller::CPUSheduler* cpuScheduler);
virtual ~PrepareEmailTask();
virtual int run();
int send(Poco::Net::MailMessage* message);
virtual const char* getResourceType() const { return "PrepareEmailTask"; };
protected:
private:
Poco::Net::SecureSMTPClientSession* mMailClientSession;
};
#endif //GRADIDO_LOGIN_SERVER_TASKS_PREPAIRE_EMAIL_TASK_INCLUDE

View File

@ -1,4 +1,4 @@
#include "ProcessingTransaction.h" #include "ProcessingTransaction.h"
#include <sodium.h> #include <sodium.h>
#include "../model/TransactionCreation.h" #include "../model/TransactionCreation.h"

View File

@ -0,0 +1,64 @@
#include "SendEmailTask.h"
#include "PrepareEmailTask.h"
#include "../lib/Profiler.h"
#include "../SingletonManager/ErrorManager.h"
#include "../SingletonManager/EmailManager.h"
#include "../ServerConfig.h"
#include "Poco/Net/MediaType.h"
SendEmailTask::SendEmailTask(Poco::Net::MailMessage* mailMessage, UniLib::controller::CPUSheduler* cpuScheduler, size_t additionalTaskDependenceCount/* = 0*/)
: UniLib::controller::CPUTask(cpuScheduler, additionalTaskDependenceCount+1), mMailMessage(mailMessage), mEmail(nullptr)
{
}
SendEmailTask::SendEmailTask(model::Email*email, UniLib::controller::CPUSheduler* cpuScheduler, size_t additionalTaskDependenceCount/* = 0*/)
: UniLib::controller::CPUTask(cpuScheduler, additionalTaskDependenceCount), mMailMessage(nullptr), mEmail(email)
{
}
SendEmailTask::~SendEmailTask()
{
if (mMailMessage) {
delete mMailMessage;
mMailMessage = nullptr;
}
if (mEmail) {
delete mEmail;
mEmail = nullptr;
}
}
int SendEmailTask::run()
{
if(ServerConfig::g_disableEmail) return 0;
Profiler timeUsed;
auto er = ErrorManager::getInstance();
auto parent = getParent(0);
if (mMailMessage) {
if (strcmp(parent->getResourceType(), "PrepareEmailTask") != 0) {
er->addError(new Error("SendEmailTask", "first parent isn't PrepareEmailTask"));
er->sendErrorsAsEmail();
return -1;
}
PrepareEmailTask* prepare = (PrepareEmailTask*)&(*parent);
mMailMessage->setSender(ServerConfig::g_EmailAccount.sender);
if (prepare->send(mMailMessage)) {
er->sendErrorsAsEmail();
return -1;
}
}
else if (mEmail) {
auto em = EmailManager::getInstance();
em->addEmail(mEmail);
mEmail = nullptr;
}
//printf("[SendEmailTask] time: %s\n", timeUsed.string().data());
return 0;
}

View File

@ -0,0 +1,36 @@
#ifndef GRADIDO_LOGIN_SERVER_TASKS_SEND_EMAIL_TASK_INCLUDE
#define GRADIDO_LOGIN_SERVER_TASKS_SEND_EMAIL_TASK_INCLUDE
#include "CPUTask.h"
#include "Poco/Net/MailMessage.h"
#include "../model/email/Email.h"
/*
* @author: Dario Rekowski
*
* @date: 29.09.19
* @desc: Task for send an email, the first parent dependence pointer must be a prepare email task
*/
class SendEmailTask : public UniLib::controller::CPUTask
{
public:
SendEmailTask(Poco::Net::MailMessage* mailMessage, UniLib::controller::CPUSheduler* cpuScheduler, size_t additionalTaskDependenceCount = 0);
SendEmailTask(model::Email* email, UniLib::controller::CPUSheduler* cpuScheduler, size_t additionalTaskDependenceCount = 0);
virtual ~SendEmailTask();
virtual int run();
virtual const char* getResourceType() const { return "SendEmailTask"; };
protected:
private:
Poco::Net::MailMessage* mMailMessage;
model::Email* mEmail;
};
#endif //GRADIDO_LOGIN_SERVER_TASKS_SEND_EMAIL_TASK_INCLUDE

View File

@ -1,284 +1,284 @@
#include "SigningTransaction.h" #include "SigningTransaction.h"
#include <google/protobuf/text_format.h> #include <google/protobuf/text_format.h>
#include "../SingletonManager/ErrorManager.h" #include "../SingletonManager/ErrorManager.h"
#include "../SingletonManager/MemoryManager.h" #include "../SingletonManager/MemoryManager.h"
#include "../SingletonManager/SingletonTaskObserver.h" #include "../SingletonManager/SingletonTaskObserver.h"
#include "../lib/Profiler.h" #include "../lib/Profiler.h"
#include "../proto/gradido/Transaction.pb.h" #include "../proto/gradido/Transaction.pb.h"
#include "sodium.h" #include "sodium.h"
#include "../ServerConfig.h" #include "../ServerConfig.h"
#include "Poco/JSON/Object.h" #include "Poco/JSON/Object.h"
#include "Poco/JSON/Parser.h" #include "Poco/JSON/Parser.h"
#include "Poco/StreamCopier.h" #include "Poco/StreamCopier.h"
#include "Poco/Net/HTTPSClientSession.h" #include "Poco/Net/HTTPSClientSession.h"
#include "Poco/Net/HTTPRequest.h" #include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/HTTPResponse.h" #include "Poco/Net/HTTPResponse.h"
SigningTransaction::SigningTransaction( SigningTransaction::SigningTransaction(
Poco::AutoPtr<ProcessingTransaction> processingeTransaction, Poco::AutoPtr<ProcessingTransaction> processingeTransaction,
Poco::AutoPtr<controller::User> newUser Poco::AutoPtr<controller::User> newUser
, bool sendErrorsToAdmin/* = true*/) , bool sendErrorsToAdmin/* = true*/)
: mProcessingeTransaction(processingeTransaction), mNewUser(newUser), mSendErrorsToAdminEmail(sendErrorsToAdmin) : mProcessingeTransaction(processingeTransaction), mNewUser(newUser), mSendErrorsToAdminEmail(sendErrorsToAdmin)
{ {
auto ob = SingletonTaskObserver::getInstance(); auto ob = SingletonTaskObserver::getInstance();
auto email = getUserEmail(); auto email = getUserEmail();
if (email != "") { if (email != "") {
ob->addTask(email, TASK_OBSERVER_SIGN_TRANSACTION); ob->addTask(email, TASK_OBSERVER_SIGN_TRANSACTION);
} }
} }
SigningTransaction::~SigningTransaction() SigningTransaction::~SigningTransaction()
{ {
auto ob = SingletonTaskObserver::getInstance(); auto ob = SingletonTaskObserver::getInstance();
auto email = getUserEmail(); auto email = getUserEmail();
if (email != "") { if (email != "") {
ob->removeTask(email, TASK_OBSERVER_SIGN_TRANSACTION); ob->removeTask(email, TASK_OBSERVER_SIGN_TRANSACTION);
} }
} }
std::string SigningTransaction::getUserEmail() std::string SigningTransaction::getUserEmail()
{ {
model::table::User* user_model = nullptr; model::table::User* user_model = nullptr;
if (!mNewUser.isNull()) { if (!mNewUser.isNull()) {
user_model = mNewUser->getModel(); user_model = mNewUser->getModel();
} }
if (user_model) { if (user_model) {
return user_model->getEmail(); return user_model->getEmail();
} }
return ""; return "";
} }
int SigningTransaction::run() { int SigningTransaction::run() {
auto mm = MemoryManager::getInstance(); auto mm = MemoryManager::getInstance();
Error* transactionError = new Error("SigningTransaction", mProcessingeTransaction->mProtoMessageBase64.data()); Error* transactionError = new Error("SigningTransaction", mProcessingeTransaction->mProtoMessageBase64.data());
addError(transactionError, false); addError(transactionError, false);
//= new Error("SigningTransaction start", mProcessingeTransaction->g) //= new Error("SigningTransaction start", mProcessingeTransaction->g)
//if (mUser.isNull() || !mUser->hasCryptoKey()) { //if (mUser.isNull() || !mUser->hasCryptoKey()) {
if(mNewUser.isNull() || !mNewUser->hasPassword()) { if(mNewUser.isNull() || !mNewUser->hasPassword()) {
addError(new Error("SigningTransaction", "user hasn't crypto key or is null")); addError(new Error("SigningTransaction", "user hasn't crypto key or is null"));
if(mSendErrorsToAdminEmail) sendErrorsAsEmail(); if(mSendErrorsToAdminEmail) sendErrorsAsEmail();
return -1; return -1;
} }
//auto privKey = mUser->getPrivKey(); //auto privKey = mUser->getPrivKey();
//if (!mUser->hasPrivKey()) { //if (!mUser->hasPrivKey()) {
auto gradido_key_pair = mNewUser->getGradidoKeyPair(); auto gradido_key_pair = mNewUser->getGradidoKeyPair();
KeyPairEd25519* recovered_gradido_key_pair = nullptr; KeyPairEd25519* recovered_gradido_key_pair = nullptr;
if(!gradido_key_pair || !gradido_key_pair->hasPrivateKey()) { if(!gradido_key_pair || !gradido_key_pair->hasPrivateKey()) {
if (!mNewUser->tryLoadPassphraseUserBackup(&recovered_gradido_key_pair)) { if (!mNewUser->tryLoadPassphraseUserBackup(&recovered_gradido_key_pair)) {
if(mNewUser->setGradidoKeyPair(recovered_gradido_key_pair)) if(mNewUser->setGradidoKeyPair(recovered_gradido_key_pair))
{ {
mNewUser->getModel()->updatePrivkey(); mNewUser->getModel()->updatePrivkey();
} }
} }
else { else {
addError(new Error("SigningTransaction", "user cannot decrypt private key")); addError(new Error("SigningTransaction", "user cannot decrypt private key"));
if (mSendErrorsToAdminEmail) sendErrorsAsEmail(); if (mSendErrorsToAdminEmail) sendErrorsAsEmail();
return -2; return -2;
} }
} }
// get body bytes // get body bytes
model::messages::gradido::Transaction transaction; model::messages::gradido::Transaction transaction;
auto bodyBytes = transaction.mutable_bodybytes(); auto bodyBytes = transaction.mutable_bodybytes();
*bodyBytes = mProcessingeTransaction->getBodyBytes(); *bodyBytes = mProcessingeTransaction->getBodyBytes();
if (*bodyBytes == "") { if (*bodyBytes == "") {
getErrors(mProcessingeTransaction); getErrors(mProcessingeTransaction);
if (mSendErrorsToAdminEmail) sendErrorsAsEmail(); if (mSendErrorsToAdminEmail) sendErrorsAsEmail();
return -3; return -3;
} }
// sign // sign
//auto sign = mUser->sign((const unsigned char*)bodyBytes->data(), bodyBytes->size()); //auto sign = mUser->sign((const unsigned char*)bodyBytes->data(), bodyBytes->size());
MemoryBin* sign = nullptr; MemoryBin* sign = nullptr;
if (gradido_key_pair) { if (gradido_key_pair) {
sign = gradido_key_pair->sign(*bodyBytes); sign = gradido_key_pair->sign(*bodyBytes);
} }
else if (recovered_gradido_key_pair) { else if (recovered_gradido_key_pair) {
sign = recovered_gradido_key_pair->sign(*bodyBytes); sign = recovered_gradido_key_pair->sign(*bodyBytes);
} }
if (!sign) { if (!sign) {
ErrorManager::getInstance()->sendErrorsAsEmail(); ErrorManager::getInstance()->sendErrorsAsEmail();
if (mSendErrorsToAdminEmail) sendErrorsAsEmail(); if (mSendErrorsToAdminEmail) sendErrorsAsEmail();
mm->releaseMemory(sign); mm->releaseMemory(sign);
return -4; return -4;
} }
// pubkey for signature // pubkey for signature
/*auto pubkeyBin = mm->getFreeMemory(ed25519_pubkey_SIZE); /*auto pubkeyBin = mm->getFreeMemory(ed25519_pubkey_SIZE);
size_t realBin = 0; size_t realBin = 0;
if (sodium_hex2bin(*pubkeyBin, *pubkeyBin, pubkeyHex.data(), pubkeyHex.size(), nullptr, &realBin, nullptr)) { if (sodium_hex2bin(*pubkeyBin, *pubkeyBin, pubkeyHex.data(), pubkeyHex.size(), nullptr, &realBin, nullptr)) {
addError(new Error("SigningTransaction", "error in sodium_hex2bin")); addError(new Error("SigningTransaction", "error in sodium_hex2bin"));
sendErrorsAsEmail(); sendErrorsAsEmail();
mm->releaseMemory(pubkeyBin); mm->releaseMemory(pubkeyBin);
mm->releaseMemory(sign); mm->releaseMemory(sign);
return -5; return -5;
} }
*/ */
// add to message // add to message
auto sigMap = transaction.mutable_sigmap(); auto sigMap = transaction.mutable_sigmap();
auto sigPair = sigMap->add_sigpair(); auto sigPair = sigMap->add_sigpair();
auto pubkeyBytes = sigPair->mutable_pubkey(); auto pubkeyBytes = sigPair->mutable_pubkey();
auto pubkeyBin = mNewUser->getModel()->getPublicKey(); auto pubkeyBin = mNewUser->getModel()->getPublicKey();
*pubkeyBytes = std::string((const char*)pubkeyBin, crypto_sign_PUBLICKEYBYTES); *pubkeyBytes = std::string((const char*)pubkeyBin, crypto_sign_PUBLICKEYBYTES);
auto sigBytes = sigPair->mutable_ed25519(); auto sigBytes = sigPair->mutable_ed25519();
*sigBytes = std::string((char*)*sign, sign->size()); *sigBytes = std::string((char*)*sign, sign->size());
mm->releaseMemory(sign); mm->releaseMemory(sign);
/*std::string protoPrettyPrint; /*std::string protoPrettyPrint;
google::protobuf::TextFormat::PrintToString(transaction, &protoPrettyPrint); google::protobuf::TextFormat::PrintToString(transaction, &protoPrettyPrint);
printf("transaction pretty: %s\n", protoPrettyPrint.data()); printf("transaction pretty: %s\n", protoPrettyPrint.data());
model::messages::gradido::TransactionBody transactionBody; model::messages::gradido::TransactionBody transactionBody;
transactionBody.MergeFromString(transaction.bodybytes()); transactionBody.MergeFromString(transaction.bodybytes());
google::protobuf::TextFormat::PrintToString(transactionBody, &protoPrettyPrint); google::protobuf::TextFormat::PrintToString(transactionBody, &protoPrettyPrint);
printf("transaction body pretty: \n%s\n", protoPrettyPrint.data()); printf("transaction body pretty: \n%s\n", protoPrettyPrint.data());
*/ */
// finalize // finalize
//printf("sigpair size: %d\n", transaction.sigmap().sigpair_size()); //printf("sigpair size: %d\n", transaction.sigmap().sigpair_size());
std::string finalTransactionBin = transaction.SerializeAsString(); std::string finalTransactionBin = transaction.SerializeAsString();
if (finalTransactionBin == "") { if (finalTransactionBin == "") {
addError(new Error("SigningTransaction", "error serializing final transaction")); addError(new Error("SigningTransaction", "error serializing final transaction"));
if (mSendErrorsToAdminEmail) sendErrorsAsEmail(); if (mSendErrorsToAdminEmail) sendErrorsAsEmail();
return -6; return -6;
} }
// finale to base64 // finale to base64
auto finalBase64Size = sodium_base64_encoded_len(finalTransactionBin.size(), sodium_base64_VARIANT_URLSAFE_NO_PADDING); auto finalBase64Size = sodium_base64_encoded_len(finalTransactionBin.size(), sodium_base64_VARIANT_URLSAFE_NO_PADDING);
auto finalBase64Bin = mm->getFreeMemory(finalBase64Size); auto finalBase64Bin = mm->getFreeMemory(finalBase64Size);
if (!sodium_bin2base64(*finalBase64Bin, finalBase64Size, (const unsigned char*)finalTransactionBin.data(), finalTransactionBin.size(), sodium_base64_VARIANT_URLSAFE_NO_PADDING)) { if (!sodium_bin2base64(*finalBase64Bin, finalBase64Size, (const unsigned char*)finalTransactionBin.data(), finalTransactionBin.size(), sodium_base64_VARIANT_URLSAFE_NO_PADDING)) {
addError(new Error("SigningTransaction", "error convert final transaction to base64")); addError(new Error("SigningTransaction", "error convert final transaction to base64"));
if (mSendErrorsToAdminEmail) sendErrorsAsEmail(); if (mSendErrorsToAdminEmail) sendErrorsAsEmail();
mm->releaseMemory(finalBase64Bin); mm->releaseMemory(finalBase64Bin);
return -7; return -7;
} }
addError(new Error("Signing transaction final", *finalBase64Bin), false); addError(new Error("Signing transaction final", *finalBase64Bin), false);
// create json request // create json request
Poco::JSON::Object requestJson; Poco::JSON::Object requestJson;
requestJson.set("method", "putTransaction"); requestJson.set("method", "putTransaction");
requestJson.set("transaction", std::string((char*)*finalBase64Bin)); requestJson.set("transaction", std::string((char*)*finalBase64Bin));
//printf("\nbase64 transaction: \n%s\n\n", (char*)*finalBase64Bin); //printf("\nbase64 transaction: \n%s\n\n", (char*)*finalBase64Bin);
mm->releaseMemory(finalBase64Bin); mm->releaseMemory(finalBase64Bin);
//std::string request = requestJson.stringify(); //std::string request = requestJson.stringify();
// send post request via https // send post request via https
// 443 = HTTPS Default // 443 = HTTPS Default
// or http via port 80 if it is a test server // or http via port 80 if it is a test server
// TODO: adding port into ServerConfig // TODO: adding port into ServerConfig
bool choose_ssl = false; bool choose_ssl = false;
try { try {
Profiler phpRequestTime; Profiler phpRequestTime;
Poco::Net::HTTPClientSession* clientSession = nullptr; Poco::Net::HTTPClientSession* clientSession = nullptr;
if (ServerConfig::g_phpServerPort) { if (ServerConfig::g_phpServerPort) {
clientSession = new Poco::Net::HTTPSClientSession(ServerConfig::g_php_serverHost, ServerConfig::g_phpServerPort); clientSession = new Poco::Net::HTTPSClientSession(ServerConfig::g_php_serverHost, ServerConfig::g_phpServerPort);
choose_ssl = true; choose_ssl = true;
} }
else if (ServerConfig::SERVER_TYPE_PRODUCTION == ServerConfig::g_ServerSetupType || else if (ServerConfig::SERVER_TYPE_PRODUCTION == ServerConfig::g_ServerSetupType ||
ServerConfig::SERVER_TYPE_STAGING == ServerConfig::g_ServerSetupType) { ServerConfig::SERVER_TYPE_STAGING == ServerConfig::g_ServerSetupType) {
clientSession = new Poco::Net::HTTPSClientSession(ServerConfig::g_php_serverHost, 443); clientSession = new Poco::Net::HTTPSClientSession(ServerConfig::g_php_serverHost, 443);
choose_ssl = true; choose_ssl = true;
} }
else { else {
clientSession = new Poco::Net::HTTPClientSession(ServerConfig::g_php_serverHost, 80); clientSession = new Poco::Net::HTTPClientSession(ServerConfig::g_php_serverHost, 80);
choose_ssl = false; choose_ssl = false;
} }
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/JsonRequestHandler"); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/JsonRequestHandler");
request.setChunkedTransferEncoding(true); request.setChunkedTransferEncoding(true);
std::ostream& requestStream = clientSession->sendRequest(request); std::ostream& requestStream = clientSession->sendRequest(request);
requestJson.stringify(requestStream); requestJson.stringify(requestStream);
Poco::Net::HTTPResponse response; Poco::Net::HTTPResponse response;
std::istream& request_stream = clientSession->receiveResponse(response); std::istream& request_stream = clientSession->receiveResponse(response);
// debugging answer // debugging answer
std::stringstream responseStringStream; std::stringstream responseStringStream;
for (std::string line; std::getline(request_stream, line); ) { for (std::string line; std::getline(request_stream, line); ) {
responseStringStream << line << std::endl; responseStringStream << line << std::endl;
} }
Poco::Logger& speedLog= Poco::Logger::get("SpeedLog"); Poco::Logger& speedLog= Poco::Logger::get("SpeedLog");
speedLog.information("[putTransaction] php server time: %s", phpRequestTime.string()); speedLog.information("[putTransaction] php server time: %s", phpRequestTime.string());
// extract parameter from request // extract parameter from request
Poco::JSON::Parser jsonParser; Poco::JSON::Parser jsonParser;
Poco::Dynamic::Var parsedJson; Poco::Dynamic::Var parsedJson;
try { try {
parsedJson = jsonParser.parse(responseStringStream.str()); parsedJson = jsonParser.parse(responseStringStream.str());
} }
catch (Poco::Exception& ex) { catch (Poco::Exception& ex) {
//printf("[JsonRequestHandler::handleRequest] Exception: %s\n", ex.displayText().data()); //printf("[JsonRequestHandler::handleRequest] Exception: %s\n", ex.displayText().data());
addError(new ParamError("SigningTransaction", "error parsing request answer", ex.displayText().data())); addError(new ParamError("SigningTransaction", "error parsing request answer", ex.displayText().data()));
std::string log_Path = "/var/log/grd_login/"; std::string log_Path = "/var/log/grd_login/";
//#ifdef _WIN32 //#ifdef _WIN32
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
log_Path = "./"; log_Path = "./";
#endif #endif
log_Path += "response.html"; log_Path += "response.html";
FILE* f = fopen(log_Path.data(), "wt"); FILE* f = fopen(log_Path.data(), "wt");
if (f) { if (f) {
std::string responseString = responseStringStream.str(); std::string responseString = responseStringStream.str();
fwrite(responseString.data(), 1, responseString.size(), f); fwrite(responseString.data(), 1, responseString.size(), f);
fclose(f); fclose(f);
} }
// */ // */
if (mSendErrorsToAdminEmail) sendErrorsAsEmail(responseStringStream.str()); if (mSendErrorsToAdminEmail) sendErrorsAsEmail(responseStringStream.str());
return -9; return -9;
} }
//sendErrorsAsEmail("<html><head><title>Hallo</title></head><body><font color='red'>Rote Test </font></body>"); //sendErrorsAsEmail("<html><head><title>Hallo</title></head><body><font color='red'>Rote Test </font></body>");
Poco::JSON::Object object = *parsedJson.extract<Poco::JSON::Object::Ptr>(); Poco::JSON::Object object = *parsedJson.extract<Poco::JSON::Object::Ptr>();
std::string stateString = ""; std::string stateString = "";
if (!object.isNull("state")) { if (!object.isNull("state")) {
auto state = object.get("state"); auto state = object.get("state");
stateString = state.convert<std::string>(); stateString = state.convert<std::string>();
} }
if (stateString != "success") { if (stateString != "success") {
addError(new Error("SigningTransaction", "php server don't return success")); addError(new Error("SigningTransaction", "php server don't return success"));
if (!object.isNull("msg")) { if (!object.isNull("msg")) {
addError(new ParamError("SigningTransaction", "msg:", object.get("msg").convert<std::string>().data())); addError(new ParamError("SigningTransaction", "msg:", object.get("msg").convert<std::string>().data()));
} }
if (!object.isNull("details")) { if (!object.isNull("details")) {
addError(new ParamError("SigningTransaction", "details:", object.get("details").convert<std::string>().data())); addError(new ParamError("SigningTransaction", "details:", object.get("details").convert<std::string>().data()));
} }
if (!object.isNull("user_error")) { if (!object.isNull("user_error")) {
addError(new ParamError("SigningTransaction", "user_error", object.get("user_error").convert<std::string>().data())); addError(new ParamError("SigningTransaction", "user_error", object.get("user_error").convert<std::string>().data()));
} }
if (mSendErrorsToAdminEmail) sendErrorsAsEmail(); if (mSendErrorsToAdminEmail) sendErrorsAsEmail();
return -10; return -10;
} }
delete clientSession; delete clientSession;
//printf("state: %s\n", stateString.data()); //printf("state: %s\n", stateString.data());
//int zahl = 1; //int zahl = 1;
} }
catch (Poco::Exception& e) { catch (Poco::Exception& e) {
addError(new ParamError("SigningTransaction", "connect error to php server", e.displayText().data())); addError(new ParamError("SigningTransaction", "connect error to php server", e.displayText().data()));
addError(new ParamError("SigningTransaction", "url", ServerConfig::g_php_serverHost.data())); addError(new ParamError("SigningTransaction", "url", ServerConfig::g_php_serverHost.data()));
addError(new ParamError("SigningTransaction", "choose_ssl", choose_ssl)); addError(new ParamError("SigningTransaction", "choose_ssl", choose_ssl));
if (mSendErrorsToAdminEmail) sendErrorsAsEmail(); if (mSendErrorsToAdminEmail) sendErrorsAsEmail();
return -8; return -8;
} }
return 0; return 0;
} }

View File

@ -1,46 +1,46 @@
#ifndef GRADIDO_LOGIN_SERVER_TASKS_SIGNING_TRANSACTION_INCLUDE #ifndef GRADIDO_LOGIN_SERVER_TASKS_SIGNING_TRANSACTION_INCLUDE
#define GRADIDO_LOGIN_SERVER_TASKS_SIGNING_TRANSACTION_INCLUDE #define GRADIDO_LOGIN_SERVER_TASKS_SIGNING_TRANSACTION_INCLUDE
#include "CPUTask.h" #include "CPUTask.h"
#include "../lib/ErrorList.h" #include "../lib/ErrorList.h"
#include "../model/TransactionBase.h" #include "../model/TransactionBase.h"
#include "../model/User.h" #include "../model/User.h"
#include "../controller/User.h" #include "../controller/User.h"
#include "../proto/gradido/Transaction.pb.h" #include "../proto/gradido/Transaction.pb.h"
#include "ProcessingTransaction.h" #include "ProcessingTransaction.h"
/* /*
* @author: Dario Rekowski * @author: Dario Rekowski
* *
* @date: 28.10.19 * @date: 28.10.19
* @desc: Task for signing Transactions * @desc: Task for signing Transactions
*/ */
class SigningTransaction : public UniLib::controller::CPUTask, public ErrorList class SigningTransaction : public UniLib::controller::CPUTask, public ErrorList
{ {
public: public:
SigningTransaction(Poco::AutoPtr<ProcessingTransaction> processingeTransaction, Poco::AutoPtr<controller::User> newUser, bool sendErrorsToAdmin = true); SigningTransaction(Poco::AutoPtr<ProcessingTransaction> processingeTransaction, Poco::AutoPtr<controller::User> newUser, bool sendErrorsToAdmin = true);
virtual ~SigningTransaction(); virtual ~SigningTransaction();
int run(); int run();
const char* getResourceType() const { return "SigningTransaction"; }; const char* getResourceType() const { return "SigningTransaction"; };
protected: protected:
Poco::AutoPtr<ProcessingTransaction> mProcessingeTransaction; Poco::AutoPtr<ProcessingTransaction> mProcessingeTransaction;
Poco::AutoPtr<controller::User> mNewUser; Poco::AutoPtr<controller::User> mNewUser;
bool mSendErrorsToAdminEmail; bool mSendErrorsToAdminEmail;
private: private:
std::string getUserEmail(); std::string getUserEmail();
}; };
#endif //GRADIDO_LOGIN_SERVER_TASKS_SIGNING_TRANSACTION_INCLUDE #endif //GRADIDO_LOGIN_SERVER_TASKS_SIGNING_TRANSACTION_INCLUDE

View File

@ -1,205 +1,205 @@
<%@ page class="LoginPage" %> <%@ page class="LoginPage" %>
<%@ page form="true" %> <%@ page form="true" %>
<%@ page baseClass="SessionHTTPRequestHandler" %> <%@ page baseClass="SessionHTTPRequestHandler" %>
<%@ page ctorArg="Session*" %> <%@ page ctorArg="Session*" %>
<%@ header include="SessionHTTPRequestHandler.h" %> <%@ header include="SessionHTTPRequestHandler.h" %>
<%@ page compressed="true" %> <%@ page compressed="true" %>
<%! <%!
#include "../gettext.h" #include "../gettext.h"
#include "Poco/Net/HTTPCookie.h" #include "Poco/Net/HTTPCookie.h"
#include "Poco/Net/HTTPServerParams.h" #include "Poco/Net/HTTPServerParams.h"
#include "Poco/Logger.h" #include "Poco/Logger.h"
#include "../SingletonManager/SessionManager.h" #include "../SingletonManager/SessionManager.h"
#include "../SingletonManager/LanguageManager.h" #include "../SingletonManager/LanguageManager.h"
#include "../SingletonManager/ErrorManager.h" #include "../SingletonManager/ErrorManager.h"
%> %>
<%% <%%
const char* pageName = "Login"; const char* pageName = "Login";
auto sm = SessionManager::getInstance(); auto sm = SessionManager::getInstance();
auto lm = LanguageManager::getInstance(); auto lm = LanguageManager::getInstance();
auto em = ErrorManager::getInstance(); auto em = ErrorManager::getInstance();
auto lang = chooseLanguage(request); auto lang = chooseLanguage(request);
//printf("choose language return: %d\n", lang); //printf("choose language return: %d\n", lang);
auto langCatalog = lm->getFreeCatalog(lang); auto langCatalog = lm->getFreeCatalog(lang);
std::string presetEmail(""); std::string presetEmail("");
if(mSession && mSession->getUser()) { if(mSession && mSession->getUser()) {
presetEmail = mSession->getUser()->getEmail(); presetEmail = mSession->getUser()->getEmail();
} }
if(!form.empty()) { if(!form.empty()) {
bool langUpdatedByBtn = false; bool langUpdatedByBtn = false;
auto langBtn = form.get("lang", ""); auto langBtn = form.get("lang", "");
if(langBtn != "") { if(langBtn != "") {
langUpdatedByBtn = true; langUpdatedByBtn = true;
} }
/* /*
auto langInput = form.get("lang", ""); auto langInput = form.get("lang", "");
auto updatedLang = LANG_NULL; auto updatedLang = LANG_NULL;
if(langBtn != "") { if(langBtn != "") {
updatedLang = chooseLanguage(request, langBtn); updatedLang = chooseLanguage(request, langBtn);
langUpdatedByBtn = true; langUpdatedByBtn = true;
} else if(langInput != "") { } else if(langInput != "") {
updatedLang = chooseLanguage(request, langInput); updatedLang = chooseLanguage(request, langInput);
} }
if(updatedLang != LANG_NULL && updatedLang != lang) { if(updatedLang != LANG_NULL && updatedLang != lang) {
lang = updatedLang; lang = updatedLang;
langCatalog = lm->getFreeCatalog(lang); langCatalog = lm->getFreeCatalog(lang);
} }
*/ */
auto email = form.get("login-email", ""); auto email = form.get("login-email", "");
auto password = form.get("login-password", ""); auto password = form.get("login-password", "");
if(email != "" && password != "") { if(email != "" && password != "") {
//auto session = sm->getSession(request); //auto session = sm->getSession(request);
//if(!mSession) mSession = sm->findByEmail(email); //if(!mSession) mSession = sm->findByEmail(email);
if(!mSession) { if(!mSession) {
mSession = sm->getNewSession(); mSession = sm->getNewSession();
mSession->setLanguageCatalog(langCatalog); mSession->setLanguageCatalog(langCatalog);
// get language // get language
// first check url, second check language header // first check url, second check language header
// for debugging client ip // for debugging client ip
auto client_host = request.clientAddress().host(); auto client_host = request.clientAddress().host();
//auto client_ip = request.clientAddress(); //auto client_ip = request.clientAddress();
// X-Real-IP forwarded ip from nginx config // X-Real-IP forwarded ip from nginx config
auto client_host_string = request.get("X-Real-IP", client_host.toString()); auto client_host_string = request.get("X-Real-IP", client_host.toString());
std::string clientIpString = "client ip: "; std::string clientIpString = "client ip: ";
client_host = Poco::Net::IPAddress(client_host_string); client_host = Poco::Net::IPAddress(client_host_string);
clientIpString += client_host_string; clientIpString += client_host_string;
Poco::Logger::get("requestLog").information(clientIpString); Poco::Logger::get("requestLog").information(clientIpString);
// debugging end // debugging end
mSession->setClientIp(client_host); mSession->setClientIp(client_host);
response.addCookie(mSession->getLoginCookie()); response.addCookie(mSession->getLoginCookie());
} else { } else {
langCatalog = mSession->getLanguageCatalog(); langCatalog = mSession->getLanguageCatalog();
} }
UserStates user_state; UserStates user_state;
try { try {
user_state = mSession->loadUser(email, password); user_state = mSession->loadUser(email, password);
} catch (Poco::Exception& ex) { } catch (Poco::Exception& ex) {
addError(new ParamError("login", "exception by calling loadUser: ", ex.displayText())); addError(new ParamError("login", "exception by calling loadUser: ", ex.displayText()));
sendErrorsAsEmail(); sendErrorsAsEmail();
addError(new Error("Error", "Intern Server error, please try again later")); addError(new Error("Error", "Intern Server error, please try again later"));
} }
auto user = mSession->getNewUser(); auto user = mSession->getNewUser();
if(user_state >= USER_LOADED_FROM_DB && !user.isNull() && !user->getModel()->getPublicKey()) { if(user_state >= USER_LOADED_FROM_DB && !user.isNull() && !user->getModel()->getPublicKey()) {
if(mSession->generateKeys(true, true)) { if(mSession->generateKeys(true, true)) {
user_state = USER_COMPLETE; user_state = USER_COMPLETE;
if(user->getModel()->isDisabled()) { if(user->getModel()->isDisabled()) {
user_state = USER_DISABLED; user_state = USER_DISABLED;
} }
} }
} else { } else {
//printf("pubkey exist: %p\n",user->getModel()->getPublicKey()); //printf("pubkey exist: %p\n",user->getModel()->getPublicKey());
} }
getErrors(mSession); getErrors(mSession);
auto uri_start = request.serverParams().getServerName(); auto uri_start = request.serverParams().getServerName();
auto lastExternReferer = mSession->getLastReferer(); auto lastExternReferer = mSession->getLastReferer();
printf("user_state: %d\n", user_state); printf("user_state: %d\n", user_state);
switch(user_state) { switch(user_state) {
case USER_EMPTY: case USER_EMPTY:
case USER_PASSWORD_INCORRECT: case USER_PASSWORD_INCORRECT:
addError(new Error(langCatalog->gettext("Login"), langCatalog->gettext("E-Mail or password isn't right, please try again!")), false); addError(new Error(langCatalog->gettext("Login"), langCatalog->gettext("E-Mail or password isn't right, please try again!")), false);
if(mSession) { if(mSession) {
getErrors(mSession); getErrors(mSession);
sm->releaseSession(mSession); sm->releaseSession(mSession);
} }
sm->deleteLoginCookies(request, response); sm->deleteLoginCookies(request, response);
break; break;
case USER_PASSWORD_ENCRYPTION_IN_PROCESS: case USER_PASSWORD_ENCRYPTION_IN_PROCESS:
addError(new Error(langCatalog->gettext("Passwort"), langCatalog->gettext("Passwort wird noch berechnet, bitte versuche es in etwa 1 Minute erneut.")), false); addError(new Error(langCatalog->gettext("Passwort"), langCatalog->gettext("Passwort wird noch berechnet, bitte versuche es in etwa 1 Minute erneut.")), false);
break; break;
case USER_KEYS_DONT_MATCH: case USER_KEYS_DONT_MATCH:
addError(new Error(langCatalog->gettext("User"), langCatalog->gettext("Error in saved data, the server admin will look at it."))); addError(new Error(langCatalog->gettext("User"), langCatalog->gettext("Error in saved data, the server admin will look at it.")));
break; break;
case USER_DISABLED: case USER_DISABLED:
addError(new Error(langCatalog->gettext("User"), langCatalog->gettext("Benutzer ist deaktiviert, kein Login möglich!"))); addError(new Error(langCatalog->gettext("User"), langCatalog->gettext("Benutzer ist deaktiviert, kein Login möglich!")));
if(mSession) { if(mSession) {
getErrors(mSession); getErrors(mSession);
sm->releaseSession(mSession); sm->releaseSession(mSession);
} }
sm->deleteLoginCookies(request, response); sm->deleteLoginCookies(request, response);
break; break;
case USER_NO_PRIVATE_KEY: case USER_NO_PRIVATE_KEY:
case USER_COMPLETE: case USER_COMPLETE:
case USER_EMAIL_NOT_ACTIVATED: case USER_EMAIL_NOT_ACTIVATED:
auto referer = request.find("Referer"); auto referer = request.find("Referer");
std::string refererString; std::string refererString;
if (referer != request.end()) { if (referer != request.end()) {
refererString = referer->second; refererString = referer->second;
} }
if(lastExternReferer != "") { if(lastExternReferer != "") {
//printf("redirect to: %s\n", lastExternReferer.data()); //printf("redirect to: %s\n", lastExternReferer.data());
response.redirect(lastExternReferer); response.redirect(lastExternReferer);
} else if(refererString != "" && } else if(refererString != "" &&
refererString.find("login") == std::string::npos && refererString.find("login") == std::string::npos &&
refererString.find("logout") == std::string::npos && refererString.find("logout") == std::string::npos &&
refererString.find("user_delete") == std::string::npos && refererString.find("user_delete") == std::string::npos &&
refererString != ServerConfig::g_serverPath + request.getURI()) { refererString != ServerConfig::g_serverPath + request.getURI()) {
std::string uri = request.getURI(); std::string uri = request.getURI();
printf("request uri: %s, redirect to: %s\n", uri.data(), refererString.data()); printf("request uri: %s, redirect to: %s\n", uri.data(), refererString.data());
response.redirect(refererString); response.redirect(refererString);
} else { } else {
//printf("redirect to: %s\n", ServerConfig::g_php_serverPath.data()); //printf("redirect to: %s\n", ServerConfig::g_php_serverPath.data());
response.redirect(ServerConfig::g_php_serverPath + "/"); response.redirect(ServerConfig::g_php_serverPath + "/");
} }
return; return;
} }
} else if(!langUpdatedByBtn) { } else if(!langUpdatedByBtn) {
addError(new Error(langCatalog->gettext("Login"), langCatalog->gettext("Username and password are needed!")), false); addError(new Error(langCatalog->gettext("Login"), langCatalog->gettext("Username and password are needed!")), false);
} }
} else { } else {
// on enter login page with empty form // on enter login page with empty form
//auto session = sm->getSession(request); //auto session = sm->getSession(request);
// remove old cookies and session if exist // remove old cookies and session if exist
if(mSession) { if(mSession) {
getErrors(mSession); getErrors(mSession);
sm->releaseSession(mSession); sm->releaseSession(mSession);
} }
sm->deleteLoginCookies(request, response); sm->deleteLoginCookies(request, response);
} }
%><%@ include file="header.cpsp" %> %><%@ include file="header.cpsp" %>
<%= getErrorsHtml() %> <%= getErrorsHtml() %>
<!--<input type="hidden" name="lang" value="<%= LanguageManager::keyForLanguage(lang) %>">--> <!--<input type="hidden" name="lang" value="<%= LanguageManager::keyForLanguage(lang) %>">-->
<div class="center-form-container"> <div class="center-form-container">
<%@ include file="flags.cpsp" %> <%@ include file="flags.cpsp" %>
<div class="center-form-form"> <div class="center-form-form">
<form action="<%= ServerConfig::g_serverPath %>/" method="POST"> <form action="<%= ServerConfig::g_serverPath %>/" method="POST">
<input class="form-control" type="text" name="login-email" placeholder="<%= langCatalog->gettext("E-Mail") %>" value="<%= presetEmail %>"/> <input class="form-control" type="text" name="login-email" placeholder="<%= langCatalog->gettext("E-Mail") %>" value="<%= presetEmail %>"/>
<input class="form-control" type="password" name="login-password" placeholder="<%= langCatalog->gettext("Password") %>" /> <input class="form-control" type="password" name="login-password" placeholder="<%= langCatalog->gettext("Password") %>" />
<button type="submit" name="submit" class="center-form-submit form-button"><%= langCatalog->gettext(" Login ") %></button> <button type="submit" name="submit" class="center-form-submit form-button"><%= langCatalog->gettext(" Login ") %></button>
</form> </form>
</div> </div>
<div class="center-form-bottom"> <div class="center-form-bottom">
<div class="signup-link"> <div class="signup-link">
<p><%= langCatalog->gettext("You haven't any account yet? Please follow the link to create one.") %></p> <p><%= langCatalog->gettext("You haven't any account yet? Please follow the link to create one.") %></p>
<a href="https://elopage.com/s/gradido/registration-de/payment?locale=de"> <a href="https://elopage.com/s/gradido/registration-de/payment?locale=de">
<%= langCatalog->gettext("Create New Account") %> <%= langCatalog->gettext("Create New Account") %>
</a> </a>
</div> </div>
<div class="reset-pwd-link"> <div class="reset-pwd-link">
<a href="<%= ServerConfig::g_serverPath %>/resetPassword"><%= langCatalog->gettext("Passwort vergessen") %></a> <a href="<%= ServerConfig::g_serverPath %>/resetPassword"><%= langCatalog->gettext("Passwort vergessen") %></a>
</div> </div>
</div> </div>
</div> </div>
<p>&nbsp;</p> <p>&nbsp;</p>
<div class="container"> <div class="container">
<a href="https://docs.google.com/document/d/1jZp-DiiMPI9ZPNXmjsvOQ1BtnfDFfx8BX7CDmA8KKjY/edit?usp=sharing" target="_blank">Zum Whitepaper</a> <a href="https://docs.google.com/document/d/1jZp-DiiMPI9ZPNXmjsvOQ1BtnfDFfx8BX7CDmA8KKjY/edit?usp=sharing" target="_blank">Zum Whitepaper</a>
<br> <br>
<br> <br>
<a href="https://docs.google.com/document/d/1kcX1guOi6tDgnFHD9tf7fB_MneKTx-0nHJxzdN8ygNs/edit?usp=sharing" target="_blank">To the Whitepaper</a> <a href="https://docs.google.com/document/d/1kcX1guOi6tDgnFHD9tf7fB_MneKTx-0nHJxzdN8ygNs/edit?usp=sharing" target="_blank">To the Whitepaper</a>
</div> </div>
<%@ include file="footer.cpsp" %> <%@ include file="footer.cpsp" %>

View File

@ -1,20 +1,20 @@
######################################################################################################### #########################################################################################################
# mariadb server # mariadb server
######################################################################################################### #########################################################################################################
From mariadb/server:10.5 as mariadb_server From mariadb/server:10.5 as mariadb_server
ENV DOCKER_WORKDIR="/docker-entrypoint-initdb.d" ENV DOCKER_WORKDIR="/docker-entrypoint-initdb.d"
RUN mkdir -p ${DOCKER_WORKDIR} RUN mkdir -p ${DOCKER_WORKDIR}
WORKDIR ${DOCKER_WORKDIR} WORKDIR ${DOCKER_WORKDIR}
# create databases # create databases
COPY ./mariadb/setup_dbs.sql a_setup_dbs.sql COPY ./mariadb/setup_dbs.sql a_setup_dbs.sql
# login server db # login server db
COPY ./login_server/skeema/ . COPY ./login_server/skeema/ .
RUN cd ./gradido_login/ && for f in *.sql; do cp -- "$f" "../b_$f"; sed -i '1i use gradido_login;' "../b_$f"; done RUN cd ./gradido_login/ && for f in *.sql; do cp -- "$f" "../b_$f"; sed -i '1i use gradido_login;' "../b_$f"; done
# community server db # community server db
COPY ./community_server/skeema/ . COPY ./community_server/skeema/ .
RUN cd ./gradido_community/ && for f in *.sql; do cp -- "$f" "../d_$f"; sed -i '1i use gradido_community;' "../d_$f"; done RUN cd ./gradido_community/ && for f in *.sql; do cp -- "$f" "../d_$f"; sed -i '1i use gradido_community;' "../d_$f"; done
RUN cd ./gradido_community/insert && for f in *.sql; do cp -- "$f" "../../e_$f"; sed -i '1i use gradido_community;' "../../e_$f"; done RUN cd ./gradido_community/insert && for f in *.sql; do cp -- "$f" "../../e_$f"; sed -i '1i use gradido_community;' "../../e_$f"; done

View File

@ -1,10 +1,10 @@
FROM nginx:latest FROM nginx:latest
WORKDIR /var/www/cakephp WORKDIR /var/www/cakephp
COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY ./nginx/fastcgi.conf /etc/nginx/ COPY ./nginx/fastcgi.conf /etc/nginx/
COPY ./nginx/mime.types /etc/nginx/ COPY ./nginx/mime.types /etc/nginx/
COPY ./community_server/webroot webroot COPY ./community_server/webroot webroot

View File

@ -1,25 +1,25 @@
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string; fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method; fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri; fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme; fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty; fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port; fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name; fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect # PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200; fastcgi_param REDIRECT_STATUS 200;

View File

@ -1,88 +1,88 @@
types { types {
text/html html htm shtml; text/html html htm shtml;
text/css css; text/css css;
text/xml xml; text/xml xml;
image/gif gif; image/gif gif;
image/jpeg jpeg jpg; image/jpeg jpeg jpg;
application/javascript js; application/javascript js;
application/atom+xml atom; application/atom+xml atom;
application/rss+xml rss; application/rss+xml rss;
text/mathml mml; text/mathml mml;
text/plain txt; text/plain txt;
text/vnd.sun.j2me.app-descriptor jad; text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml; text/vnd.wap.wml wml;
text/x-component htc; text/x-component htc;
image/png png; image/png png;
image/tiff tif tiff; image/tiff tif tiff;
image/vnd.wap.wbmp wbmp; image/vnd.wap.wbmp wbmp;
image/x-icon ico; image/x-icon ico;
image/x-jng jng; image/x-jng jng;
image/x-ms-bmp bmp; image/x-ms-bmp bmp;
image/svg+xml svg svgz; image/svg+xml svg svgz;
image/webp webp; image/webp webp;
application/font-woff woff; application/font-woff woff;
application/java-archive jar war ear; application/java-archive jar war ear;
application/json json; application/json json;
application/mac-binhex40 hqx; application/mac-binhex40 hqx;
application/msword doc; application/msword doc;
application/pdf pdf; application/pdf pdf;
application/postscript ps eps ai; application/postscript ps eps ai;
application/rtf rtf; application/rtf rtf;
application/vnd.apple.mpegurl m3u8; application/vnd.apple.mpegurl m3u8;
application/vnd.ms-excel xls; application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot; application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt; application/vnd.ms-powerpoint ppt;
application/vnd.wap.wmlc wmlc; application/vnd.wap.wmlc wmlc;
application/vnd.google-earth.kml+xml kml; application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz; application/vnd.google-earth.kmz kmz;
application/x-7z-compressed 7z; application/x-7z-compressed 7z;
application/x-cocoa cco; application/x-cocoa cco;
application/x-java-archive-diff jardiff; application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp; application/x-java-jnlp-file jnlp;
application/x-makeself run; application/x-makeself run;
application/x-perl pl pm; application/x-perl pl pm;
application/x-pilot prc pdb; application/x-pilot prc pdb;
application/x-rar-compressed rar; application/x-rar-compressed rar;
application/x-redhat-package-manager rpm; application/x-redhat-package-manager rpm;
application/x-sea sea; application/x-sea sea;
application/x-shockwave-flash swf; application/x-shockwave-flash swf;
application/x-stuffit sit; application/x-stuffit sit;
application/x-tcl tcl tk; application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt; application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi; application/x-xpinstall xpi;
application/xhtml+xml xhtml; application/xhtml+xml xhtml;
application/xspf+xml xspf; application/xspf+xml xspf;
application/zip zip; application/zip zip;
application/octet-stream bin exe dll; application/octet-stream bin exe dll;
application/octet-stream deb; application/octet-stream deb;
application/octet-stream dmg; application/octet-stream dmg;
application/octet-stream iso img; application/octet-stream iso img;
application/octet-stream msi msp msm; application/octet-stream msi msp msm;
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx; application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx; application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx; application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;
audio/midi mid midi kar; audio/midi mid midi kar;
audio/mpeg mp3; audio/mpeg mp3;
audio/ogg ogg; audio/ogg ogg;
audio/x-m4a m4a; audio/x-m4a m4a;
audio/x-realaudio ra; audio/x-realaudio ra;
video/3gpp 3gpp 3gp; video/3gpp 3gpp 3gp;
video/mp2t ts; video/mp2t ts;
video/mp4 mp4; video/mp4 mp4;
video/mpeg mpeg mpg; video/mpeg mpeg mpg;
video/quicktime mov; video/quicktime mov;
video/webm webm; video/webm webm;
video/x-flv flv; video/x-flv flv;
video/x-m4v m4v; video/x-m4v m4v;
video/x-mng mng; video/x-mng mng;
video/x-ms-asf asx asf; video/x-ms-asf asx asf;
video/x-ms-wmv wmv; video/x-ms-wmv wmv;
video/x-msvideo avi; video/x-msvideo avi;
} }

View File

@ -1,92 +1,79 @@
server {
server {
listen 80 ;
listen [::]:80; listen 80 ;
server_name 0.0.0.0; listen [::]:80;
server_name 0.0.0.0;
#include /etc/nginx/common/protect.conf;
#include /etc/nginx/common/protect_add_header.conf; #include /etc/nginx/common/protect.conf;
#include /etc/nginx/common/ssl.conf; #include /etc/nginx/common/protect_add_header.conf;
#include /etc/nginx/common/ssl.conf;
root /var/www/cakephp/webroot;
index index.php; root /var/www/cakephp/webroot;
index index.php;
location ~ \.php$ {
fastcgi_pass community-server:9000; location ~* \.(png|jpg|ico|webp)$ {
fastcgi_index index.php; expires 30d;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
# fastcgi_param PHP_VALUE "error_log=/var/www/myapp/logs/php_errors.log";
fastcgi_buffers 16 16k; location ~* \.(js|css) {
fastcgi_buffer_size 32k; # expires 1d;
include fastcgi_params; expires 1d;
}
}
location ~ \.php$ {
location ~ /\.ht { fastcgi_pass community-server:9000;
deny all; fastcgi_index index.php;
} fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_param PHP_VALUE "error_log=/var/www/myapp/logs/php_errors.log";
location /account { fastcgi_buffers 16 16k;
proxy_http_version 1.1; fastcgi_buffer_size 32k;
proxy_set_header Upgrade $http_upgrade; include fastcgi_params;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade; }
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr; location ~ /\.ht {
proxy_set_header Host $host; deny all;
rewrite /account/(.*) /$1 break; }
#proxy_next_upstream error timeout invalid_header http_502 non_idempotent; location /account {
proxy_pass http://login-server:1200; proxy_http_version 1.1;
proxy_redirect off; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
} proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
location /login_api { proxy_set_header Host $host;
proxy_http_version 1.1; rewrite /account/(.*) /$1 break;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade'; #proxy_next_upstream error timeout invalid_header http_502 non_idempotent;
proxy_cache_bypass $http_upgrade; proxy_pass http://login-server:1200;
proxy_set_header X-Real-IP $remote_addr; proxy_redirect off;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
rewrite /login_api/(.*) /$1 break; }
proxy_pass http://login-server:1201; location /login_api {
proxy_redirect off; proxy_http_version 1.1;
} proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
location /vue { proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
location /vue/sockjs-node { proxy_set_header Host $host;
rewrite /vue/(.*) /$1; rewrite /login_api/(.*) /$1 break;
}
location ~* \.(png) { proxy_pass http://login-server:1201;
expires 1d; proxy_redirect off;
rewrite /vue/(.*) /$1; }
}
location / {
try_files $uri $uri/ /index.php?$args;
proxy_http_version 1.1; }
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade'; # access_log /var/log/nginx/access.log main;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
#rewrite /vue/(.*) /$1 break;
proxy_pass http://frontend:8080;
proxy_redirect off;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
# access_log /var/log/nginx/access.log main;
} }

View File

@ -1,9 +1,9 @@
From phpdockerio/php74-fpm as php-fpm From phpdockerio/php74-fpm as php-fpm
# Install selected extensions and other stuff # Install selected extensions and other stuff
RUN apt-get update \ RUN apt-get update \
&& apt-get -y --no-install-recommends install curl php7.4-curl php7.4-fpm php7.4-mbstring php7.4-intl php7.4-xml php7.4-pdo php7.4-mysql\ && apt-get -y --no-install-recommends install curl php7.4-curl php7.4-fpm php7.4-mbstring php7.4-intl php7.4-xml php7.4-pdo php7.4-mysql\
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
WORKDIR "/var/www/cakephp" WORKDIR "/var/www/cakephp"