diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..2f3c0412a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM phpdockerio/php74-fpm + +# install php fpm +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 clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* + +WORKDIR /var/www/cakephp +RUN mkdir logs && mkdir tmp && chmod 777 logs && chmod 777 tmp +COPY ./community_server/ . +COPY ./configs/community_server/app.php ./config/ +RUN composer update + diff --git a/composer.json b/composer.json index cc75b73d8..7eeb26887 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,6 @@ "scripts": { "post-install-cmd": "App\\Console\\Installer::postInstall", "post-create-project-cmd": "App\\Console\\Installer::postInstall", - "post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump", "check": [ "@test", "@cs-check" diff --git a/config/app.default.php b/config/app.default.php index 6e53da67e..04c8cede2 100644 --- a/config/app.default.php +++ b/config/app.default.php @@ -397,6 +397,11 @@ return [ 'host' => 'http://127.0.0.1', 'port' => 1201 ], + 'API' => [ + 'allowedCaller' => [''] // insert domains or ips from login-server and gdt if they not at localhost + ], + 'ServerAdminEmail' => 'info@gradido.net', // email 'from' field for transfer notification emails + 'noReplyEmail' => 'no-replay@gradido.net', // email sender for creation notification emails to user 'GroupNode' => false ]; diff --git a/config/nginx/fastcgi.conf b/config/nginx/fastcgi.conf new file mode 100644 index 000000000..c2976fe91 --- /dev/null +++ b/config/nginx/fastcgi.conf @@ -0,0 +1,25 @@ +fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; +fastcgi_param QUERY_STRING $query_string; +fastcgi_param REQUEST_METHOD $request_method; +fastcgi_param CONTENT_TYPE $content_type; +fastcgi_param CONTENT_LENGTH $content_length; + +fastcgi_param SCRIPT_NAME $fastcgi_script_name; +fastcgi_param REQUEST_URI $request_uri; +fastcgi_param DOCUMENT_URI $document_uri; +fastcgi_param DOCUMENT_ROOT $document_root; +fastcgi_param SERVER_PROTOCOL $server_protocol; +fastcgi_param REQUEST_SCHEME $scheme; +fastcgi_param HTTPS $https if_not_empty; + +fastcgi_param GATEWAY_INTERFACE CGI/1.1; +fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; + +fastcgi_param REMOTE_ADDR $remote_addr; +fastcgi_param REMOTE_PORT $remote_port; +fastcgi_param SERVER_ADDR $server_addr; +fastcgi_param SERVER_PORT $server_port; +fastcgi_param SERVER_NAME $server_name; + +# PHP only, required if PHP was built with --enable-force-cgi-redirect +fastcgi_param REDIRECT_STATUS 200; \ No newline at end of file diff --git a/config/nginx/mime.types b/config/nginx/mime.types new file mode 100644 index 000000000..84c644fc7 --- /dev/null +++ b/config/nginx/mime.types @@ -0,0 +1,88 @@ +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/javascript js; + application/atom+xml atom; + application/rss+xml rss; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/png png; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + image/svg+xml svg svgz; + image/webp webp; + + application/font-woff woff; + application/java-archive jar war ear; + application/json json; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.apple.mpegurl m3u8; + application/vnd.ms-excel xls; + application/vnd.ms-fontobject eot; + application/vnd.ms-powerpoint ppt; + application/vnd.wap.wmlc wmlc; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/xspf+xml xspf; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + application/vnd.openxmlformats-officedocument.wordprocessingml.document docx; + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx; + application/vnd.openxmlformats-officedocument.presentationml.presentation pptx; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mp2t ts; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} diff --git a/config/nginx/nginx.conf b/config/nginx/nginx.conf new file mode 100644 index 000000000..5aa5c3095 --- /dev/null +++ b/config/nginx/nginx.conf @@ -0,0 +1,86 @@ + +server { + + listen 80 ; + 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/ssl.conf; + + + root /usr/share/nginx/html/webroot; + index index.php; + + location ~* \.(png|jpg|ico|webp)\$ { + expires 30d; + } + + location ~* \.(js|css) { + # expires 1d; + expires 1d; + } + + location ~ \.php\$ { + # regex to split $uri to $fastcgi_script_name and $fastcgi_path + fastcgi_split_path_info ^(.+\.php)(/.+)$; + + # Check that the PHP script exists before passing it + try_files $fastcgi_script_name =404; + + # Bypass the fact that try_files resets $fastcgi_path_info + # see: http://trac.nginx.org/nginx/ticket/321 + set $path_info $fastcgi_path_info; + fastcgi_param PATH_INFO $path_info; + + fastcgi_index index.php; + include fastcgi.conf; + + #fastcgi_pass unix:/run/php/php7.3-fpm.sock; + fastcgi_pass 127.0.0.1:9000; + + } + + location ~ /\.ht { + deny all; + } + + location /account { + proxy_http_version 1.1; + 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; + proxy_set_header Host \$host; + rewrite /account/(.*) /\$1 break; + + #proxy_next_upstream error timeout invalid_header http_502 non_idempotent; + proxy_pass http://login-server:1200; + proxy_redirect off; + + + } + + location /login_api { + proxy_http_version 1.1; + 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; + proxy_set_header Host \$host; + rewrite /login_api/(.*) /\$1 break; + + proxy_pass http://login-server:1201; + proxy_redirect off; + } + + location / { + try_files \$uri \$uri/ /index.php?\$args; + } + +# access_log /var/log/nginx/access.log main; + +} \ No newline at end of file diff --git a/config/php-fpm/php-ini-overrides.ini b/config/php-fpm/php-ini-overrides.ini new file mode 100644 index 000000000..6b1325362 --- /dev/null +++ b/config/php-fpm/php-ini-overrides.ini @@ -0,0 +1,2 @@ +#upload_max_filesize = 100M +#post_max_size = 108M diff --git a/config/routes.php b/config/routes.php index ffbe4e504..27d998f2c 100644 --- a/config/routes.php +++ b/config/routes.php @@ -58,6 +58,7 @@ Router::scope('/', function (RouteBuilder $routes) { // Skip token check for API URLs. //die($request->getParam('controller')); $whitelist = ['JsonRequestHandler', 'ElopageWebhook']; + foreach($whitelist as $entry) { if($request->getParam('controller') === $entry) { if($entry == 'ElopageWebhook') { diff --git a/mithril_client b/mithril_client index 21d4a0a5e..f0b1d113c 160000 --- a/mithril_client +++ b/mithril_client @@ -1 +1 @@ -Subproject commit 21d4a0a5e9a19f251e26c0ae07ce74be2fa99bbf +Subproject commit f0b1d113cee2a76e9dbb098b315f4acaf38410d0 diff --git a/skeema/gradido_community/community_profiles.sql b/skeema/gradido_community/community_profiles.sql index 07d475fdf..ea857bebf 100644 --- a/skeema/gradido_community/community_profiles.sql +++ b/skeema/gradido_community/community_profiles.sql @@ -1,9 +1,8 @@ -CREATE TABLE `community_profiles` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `state_user_id` int(10) unsigned NOT NULL, - `profile_img` longblob, - `profile_desc` varchar(2000) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `state_user_id` (`state_user_id`), - CONSTRAINT `community_profiles_ibfk_1` FOREIGN KEY (`state_user_id`) REFERENCES `state_users` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +CREATE TABLE `community_profiles` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `state_user_id` int(10) unsigned NOT NULL, + `profile_img` longblob, + `profile_desc` varchar(2000) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `state_user_id` (`state_user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/skeema/gradido_community/insert/transaction_types.sql b/skeema/gradido_community/insert/insert_transaction_types.sql similarity index 100% rename from skeema/gradido_community/insert/transaction_types.sql rename to skeema/gradido_community/insert/insert_transaction_types.sql diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 94b99da73..2c59a17e0 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -139,13 +139,15 @@ class AppController extends Controller } } - protected function requestLogin() + protected function requestLogin($session_id = 0) { $session = $this->getRequest()->getSession(); // check login // disable encryption for cookies //$this->Cookie->configKey('User', 'encryption', false); - $session_id = intval($this->request->getCookie('GRADIDO_LOGIN', '')); + if(!$session_id) { + $session_id = intval($this->request->getCookie('GRADIDO_LOGIN', '')); + } $ip = $this->request->clientIp(); if (!$session->check('client_ip')) { $session->write('client_ip', $ip); @@ -156,8 +158,9 @@ class AppController extends Controller if ($session_id != 0) { $userStored = $session->read('StateUser'); + - $transactionPendings = $session->read('Transactions.pending'); + $transactionPendings = $session->read('Transaction.pending'); $transactionExecutings = $session->read('Transaction.executing'); if ($session->read('session_id') != $session_id || ( $userStored && (!isset($userStored['id']) || !$userStored['email_checked'])) || @@ -185,7 +188,7 @@ class AppController extends Controller $transactionPendings = $json['Transaction.pending']; $transactionExecuting = $json['Transaction.executing']; //echo "read transaction pending: $transactionPendings
"; - $session->write('Transactions.pending', $transactionPendings); + $session->write('Transaction.pending', $transactionPendings); $session->write('Transaction.executing', $transactionExecuting); $session->write('session_id', $session_id); $stateUserTable = TableRegistry::getTableLocator()->get('StateUsers'); diff --git a/src/Controller/JsonRequestHandlerController.php b/src/Controller/JsonRequestHandlerController.php index f72d5d947..e5823397e 100644 --- a/src/Controller/JsonRequestHandlerController.php +++ b/src/Controller/JsonRequestHandlerController.php @@ -248,10 +248,14 @@ class JsonRequestHandlerController extends AppController { $stateErrorEntity->transaction_type_id = $transaction->getTransactionBody()->getTransactionTypeId(); $stateErrorEntity->message_json = $json; $stateErrorsTable->save($stateErrorEntity); + } else { + $errorArray['user_error'] = "user with $pub not found"; + $json = json_encode($errorArray); } + return $this->returnJsonEncoded($json); } -} \ No newline at end of file +} diff --git a/src/Controller/ServerUsersController.php b/src/Controller/ServerUsersController.php index 52165bb3b..236e35b7f 100644 --- a/src/Controller/ServerUsersController.php +++ b/src/Controller/ServerUsersController.php @@ -15,7 +15,7 @@ class ServerUsersController extends AppController public function initialize() { parent::initialize(); - //$this->Auth->allow(['add', 'edit']); + $this->Auth->allow(['add', 'edit']); $this->Auth->deny('index'); } diff --git a/src/Controller/StateBalancesController.php b/src/Controller/StateBalancesController.php index 17b1d3f9f..5164dce4b 100644 --- a/src/Controller/StateBalancesController.php +++ b/src/Controller/StateBalancesController.php @@ -21,7 +21,7 @@ class StateBalancesController extends AppController { parent::initialize(); //$this->Auth->allow(['add', 'edit']); - $this->Auth->allow(['overview', 'overviewGdt']); + $this->Auth->allow(['overview', 'overviewGdt', 'ajaxGetBalance']); $this->loadComponent('JsonRequestClient'); } /** @@ -38,6 +38,8 @@ class StateBalancesController extends AppController $this->set(compact('stateBalances')); } + + public function overview() { @@ -174,6 +176,155 @@ class StateBalancesController extends AppController $this->set('timeUsed', microtime(true) - $startTime); $this->set('gdtSum', $gdtSum); } + + public function ajaxGetBalance($session_id) + { + if(!isset($session_id) || !$session_id) { + return $this->returnJson(['state' => 'error', 'msg' => 'invalid session']); + } + $startTime = microtime(true); + $session = $this->getRequest()->getSession(); + $result = $this->requestLogin($session_id); + if ($result !== true) { + return $this->returnJson(['state' => 'error', 'msg' => 'session not found']); + } + $user = $session->read('StateUser'); + //var_dump($user); + return $this->returnJson(['state' => 'success', 'balance' => $user['balance']]); + + } + + public function ajaxListTransactions($session_id, $page, $count) + { + if(!isset($session_id) || !$session_id) { + return $this->returnJson(['state' => 'error', 'msg' => 'invalid session']); + } + $startTime = microtime(true); + $session = $this->getRequest()->getSession(); + $result = $this->requestLogin($session_id); + if ($result !== true) { + return $this->returnJson(['state' => 'error', 'msg' => 'session not found']); + } + $user = $session->read('StateUser'); + + $gdtSum = 0; + + $gdtEntries = $this->JsonRequestClient->sendRequestGDT(['email' => $user['email']], 'GdtEntries' . DS . 'sumPerEmailApi'); + + if('success' == $gdtEntries['state'] && 'success' == $gdtEntries['data']['state']) { + $gdtSum = intval($gdtEntries['data']['sum']); + } else { + if($user) { + + $this->addAdminError('StateBalancesController', 'overview', $gdtEntries, $user['id']); + } else { + $this->addAdminError('StateBalancesController', 'overview', $gdtEntries, 0); + } + } + + + $creationsTable = TableRegistry::getTableLocator()->get('TransactionCreations'); + $creationTransactions = $creationsTable + ->find('all') + ->where(['state_user_id' => $user['id']]) + ->contain(['Transactions']); + + $transferTable = TableRegistry::getTableLocator()->get('TransactionSendCoins'); + $transferTransactions = $transferTable + ->find('all') + ->where(['OR' => ['state_user_id' => $user['id'], 'receiver_user_id' => $user['id']]]) + ->contain(['Transactions']); + + $involvedUserIds = []; + + foreach ($transferTransactions as $sendCoins) { + //var_dump($sendCoins); + if ($sendCoins->state_user_id != $user['id']) { + array_push($involvedUserIds, intval($sendCoins->state_user_id)); + } elseif ($sendCoins->receiver_user_id != $user['id']) { + array_push($involvedUserIds, intval($sendCoins->receiver_user_id)); + } + } + + /*echo "state user from sendCoins: $sendCoins->state_user_id
"; + echo "receiver user from sendCoins: $sendCoins->receiver_user_id
"; + echo "user id from logged in user: ".$user['id']. '
'; + */ + //var_dump($involvedUserIds); + // exchange key with values and drop duplicates + $involvedUser_temp = array_flip($involvedUserIds); + // exchange back + $involvedUserIds = array_flip($involvedUser_temp); + $userTable = TableRegistry::getTableLocator()->get('StateUsers'); + $involvedUser = $userTable->find('all', [ + 'contain' => false, + 'where' => ['id IN' => $involvedUserIds], + 'fields' => ['id', 'first_name', 'last_name', 'email'] + ]); + //var_dump($involvedUser->toArray()); + $involvedUserIndices = []; + foreach ($involvedUser as $involvedUser) { + $involvedUserIndices[$involvedUser->id] = $involvedUser; + } + + // sender or receiver when user has sended money + // group name if creation + // type: gesendet / empfangen / geschöpft + // transaktion nr / id + // date + // balance + + $transactions = []; + foreach ($creationTransactions as $creation) { + //var_dump($creation); + array_push($transactions, [ + 'name' => 'Gradido Akademie', + 'type' => 'creation', + 'transaction_id' => $creation->transaction_id, + 'date' => $creation->transaction->received, + 'balance' => $creation->amount, + 'memo' => $creation->transaction->memo + ]); + } + + foreach ($transferTransactions as $sendCoins) { + $type = ''; + $otherUser = null; + if ($sendCoins->state_user_id == $user['id']) { + $type = 'send'; + + if(isset($involvedUserIndices[$sendCoins->receiver_user_id])) { + $otherUser = $involvedUserIndices[$sendCoins->receiver_user_id]; + } + } else if ($sendCoins->receiver_user_id == $user['id']) { + $type = 'receive'; + if(isset($involvedUserIndices[$sendCoins->state_user_id])) { + $otherUser = $involvedUserIndices[$sendCoins->state_user_id]; + } + } + if(null == $otherUser) { + $otherUser = $this->StateBalances->StateUsers->newEntity(); + } + array_push($transactions, [ + 'name' => $otherUser->first_name . ' ' . $otherUser->last_name, + 'email' => $otherUser->email, + 'type' => $type, + 'transaction_id' => $sendCoins->transaction_id, + 'date' => $sendCoins->transaction->received, + 'balance' => $sendCoins->amount, + 'memo' => $sendCoins->transaction->memo + ]); + } + uasort($transactions, array($this, 'sortTransactions')); + return $this->returnJson([ + 'state' => 'success', + 'transactions' => $transactions, + 'transactionExecutingCount' => $session->read('Transaction.executing'), + 'count' => count($transactions), + 'gdtSum' => $gdtSum, + 'timeUsed' => microtime(true) - $startTime + ]); + } public function overviewGdt() { diff --git a/src/Controller/StateUsersController.php b/src/Controller/StateUsersController.php index c960bc05c..d85f8b449 100644 --- a/src/Controller/StateUsersController.php +++ b/src/Controller/StateUsersController.php @@ -5,6 +5,8 @@ use Cake\Routing\Router; use Cake\I18n\I18n; use Cake\I18n\FrozenTime; use Cake\ORM\TableRegistry; +use Cake\Http\Client; +use Cake\Core\Configure; use App\Controller\AppController; use App\Form\UserSearchForm; @@ -43,7 +45,7 @@ class StateUsersController extends AppController $this->Auth->allow([ 'search', 'ajaxCopyLoginToCommunity', 'ajaxCopyCommunityToLogin', 'ajaxDelete', 'ajaxCountTransactions', 'ajaxVerificationEmailResend', - 'ajaxGetUserEmailVerificationCode' + 'ajaxGetUserEmailVerificationCode', 'ajaxGetCSFRToken' ]); $this->set( 'naviHierarchy', @@ -433,6 +435,40 @@ class StateUsersController extends AppController } return $this->returnJson(['state' => 'error', 'msg' => 'no post request']); } + + public function ajaxGetCSFRToken($session_id) + { + if(!isset($session_id) || $session_id == 0) { + $this->returnJson(['state' => 'error', 'msg' => 'no session id']); + } + + $client_ip = $this->request->clientIp(); + + $loginServer = Configure::read('LoginServer'); + $url = $loginServer['host'] . ':' . $loginServer['port']; + + $http = new Client(); + $response = $http->get($url . '/login', ['session_id' => $session_id]); + $json = $response->getJson(); + + if (isset($json) && count($json) > 0) { + if ($json['state'] === 'success') { + if($json['clientIP'] == $client_ip) { + return $this->returnJson(['state' => 'success', 'csfr' => $this->request->getParam('_csrfToken')]); + } else { + return $this->returnJson([ + 'state' => 'error', + 'msg' => 'client ip mismatch', + 'details' => ['login_server' => $json['clientIP'], 'caller' => $client_ip]]); + } + } else { + return $this->returnJson($json); + } + } else { + return $this->returnJson(['state' => 'error', 'invalid response form logins server']); + } + + } /* getField(vnode, 'receive'), diff --git a/src/Controller/TransactionCreationsController.php b/src/Controller/TransactionCreationsController.php index abce4e63e..9b05c1782 100644 --- a/src/Controller/TransactionCreationsController.php +++ b/src/Controller/TransactionCreationsController.php @@ -247,9 +247,9 @@ class TransactionCreationsController extends AppController ['AND' => [ 'disabled' => 0, 'OR' => [ - 'LOWER(first_name)' => strtolower($requestData['searchText']), - 'LOWER(last_name)' => strtolower($requestData['searchText']), - 'LOWER(email)' => strtolower($requestData['searchText']) + 'LOWER(first_name) LIKE' => '%'.strtolower($requestData['searchText']).'%', + 'LOWER(last_name) LIKE' => '%'.strtolower($requestData['searchText']).'%', + 'LOWER(email) LIKE' => '%'.strtolower($requestData['searchText']).'%' ] ] ] diff --git a/src/Template/StateUsers/view.ctp b/src/Template/StateUsers/view.ctp index b3616601c..c2bb33c2b 100644 --- a/src/Template/StateUsers/view.ctp +++ b/src/Template/StateUsers/view.ctp @@ -23,6 +23,7 @@

first_name) ?> last_name) ?> <email) ?>>

+ Konto-Adresse: public_key))) ?>