Browse Source

initial

master
o.moresis 7 months ago
parent
commit
10363fc17d
  1. 8
      .docker/caddy/Dockerfile
  2. 9
      .docker/config/Caddyfile
  3. 55
      .docker/php-fpm/Dockerfile
  4. 41
      .docker/php-fpm/Dockerfileold
  5. 1
      .gitignore
  6. 17
      composer.lock
  7. 65
      docker-compose.yml
  8. 9
      gulpfile.js
  9. 3
      public/index.old
  10. 33
      src/Config.php
  11. 8
      src/Controllers/AuthController.php
  12. 9
      src/Services/PgSql.php
  13. 4
      src/Services/PoseidonAPI.php
  14. 10
      src/Services/WfdAPI.php

8
.docker/caddy/Dockerfile

@ -0,0 +1,8 @@
FROM caddy:latest
# Ensure the www-data user and group match the host system
# RUN groupadd -g 1000 www-data && useradd -u 1000 -g www-data -s /bin/bash www-data
# Set permissions for /var/www/html
# RUN chown -R www-data:www-data /var/www/html

9
.docker/config/Caddyfile

@ -0,0 +1,9 @@
localhost {
root * /var/www/html/public
file_server
php_fastcgi php_backend:9000
log {
output file /var/log/caddy.log
}
}

55
.docker/php-fpm/Dockerfile

@ -0,0 +1,55 @@
FROM php:8.2-fpm-alpine
# Install system dependencies and PostgreSQL libraries
RUN apk add --no-cache \
libpng-dev \
libjpeg-turbo-dev \
freetype-dev \
postgresql-dev \
libpq \
unzip \
git
# Configure and install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd pdo pdo_pgsql pgsql
ENV REPO_URL=
ENV GEOSERVER_URL=
ENV GEOSERVER_USERNAME=
ENV GEOSERVER_PASSWORD=
ENV GEONETWORK_URL=
ENV GEONETWORK_API_KEY=
ENV GEONETWORK_API_VERSION=
ENV PG_USER=
ENV PG_PASS=
ENV PG_NAME=
ENV PG_HOST=
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Ensure the www-data user and group match the host system
# RUN addgroup -g 1000 www-data && adduser -u 1000 -G www-data -s /bin/sh -D www-data
# RUN addgroup -g 1000 nobody && adduser -u 1000 -G nobody -s /bin/sh -D nobody
# Set permissions for /var/www/html
# RUN mkdir -p /var/www/html && chown -R www-data:www-data /var/www/html
RUN chown -R nobody:nobody /var/www/html /run
# Copy project files
COPY --chown=nobody . /var/www/html/
# Switch to the www-data user
# USER www-data
USER nobody
# Set the working directory
WORKDIR /var/www/html
EXPOSE 9000
# Run Composer install
CMD sh -c "composer install --no-dev --optimize-autoloader && php-fpm"
USER root

41
.docker/php-fpm/Dockerfileold

@ -0,0 +1,41 @@
FROM php:8.2-fpm
# EXPOSE 9000
# Install any PHP extensions or packages you need
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libpq-dev \
libjpeg-dev \
libfreetype6-dev \
zip \
unzip \
&& docker-php-ext-configure gd \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install pdo pdo_pgsql pgsql mbstring exif bcmath pcntl
# Ensure the www-data user and group match the host system
# RUN groupadd -g 1000 www-data && useradd -u 1000 -g www-data -s /bin/bash
# RUN useradd -u 1000 -g www-data -s /bin/bash
# Copy composer from the official image
COPY --from=composer /usr/bin/composer /usr/bin/composer
WORKDIR /var/www/html
# ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
# Install PHP extensions
RUN chmod +x /usr/local/bin/install-php-extensions; \
# Set permissions for /var/www/html
COPY --chown=www-data:www-data . /var/www/html
# Copy project files
USER www-data
# Run Composer install
CMD bash -c "composer install --no-dev --optimize-autoloader"

1
.gitignore vendored

@ -1,5 +1,6 @@
.htaccess .htaccess
.env .env
.docker/data/*
node_modules/ node_modules/
package-lock.json package-lock.json
composer.phar composer.phar

17
composer.lock generated

@ -68,16 +68,16 @@
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "v1.27.0", "version": "v1.29.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git", "url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "5bbc823adecdae860bb64756d639ecfec17b050a" "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a", "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ef4d7e442ca910c4764bce785146269b30cb5fc4",
"reference": "5bbc823adecdae860bb64756d639ecfec17b050a", "reference": "ef4d7e442ca910c4764bce785146269b30cb5fc4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -91,9 +91,6 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": {
"dev-main": "1.27-dev"
},
"thanks": { "thanks": {
"name": "symfony/polyfill", "name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill" "url": "https://github.com/symfony/polyfill"
@ -130,7 +127,7 @@
"portable" "portable"
], ],
"support": { "support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0" "source": "https://github.com/symfony/polyfill-ctype/tree/v1.29.0"
}, },
"funding": [ "funding": [
{ {
@ -146,7 +143,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2022-11-03T14:55:06+00:00" "time": "2024-01-29T20:11:03+00:00"
}, },
{ {
"name": "vlucas/phpdotenv", "name": "vlucas/phpdotenv",
@ -233,5 +230,5 @@
"prefer-lowest": false, "prefer-lowest": false,
"platform": [], "platform": [],
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.3.0" "plugin-api-version": "2.6.0"
} }

65
docker-compose.yml

@ -0,0 +1,65 @@
version: '3'
services:
caddy:
container_name: spa_caddy
build: .docker/caddy
ports:
- 80:80
- 443:443
volumes:
- ./:/var/www/html
- .docker/config/Caddyfile:/etc/caddy/Caddyfile
- .docker/data/logs/caddy:/var/log/caddy:delegated
depends_on:
- php-fpm
networks:
- internal
php-fpm:
container_name: php_backend
build:
context: .docker/php-fpm
volumes:
- ./:/var/www/html:delegated
- .docker/data/logs/php:/var/log/php:delegated
env_file:
- .env
environment:
- REPO_URL=
- GEOSERVER_URL=geoserver_service
- GEOSERVER_USERNAME=admin
- GEOSERVER_PASSWORD=myawesomepw123
- GEONETWORK_URL=
- GEONETWORK_API_KEY=
- GEONETWORK_API_VERSION=
- PG_USER=
- PG_PASS=
- PG_NAME=
- PG_HOST=
restart: unless-stopped
expose:
- 9000
networks:
- internal
geoserver:
container_name: geoserver_service
image: kartoza/geoserver
environment:
- GEOSERVER_ADMIN_USER=admin
- GEOSERVER_ADMIN_PASSWORD=myawesomepw123
volumes:
- geoserver_data:/opt/geoserver/data_dir
expose:
- 8081
ports:
- "8081:8081"
networks:
- internal
volumes:
geoserver_data:
networks:
internal:

9
gulpfile.js

@ -1,9 +0,0 @@
gulp.task('modules', function() {
sources = [
'./node_modules/prismjs/prism.js',
'./node_modules/prismjs/themes/prism-dark.css',
]
gulp.src( sources ).pipe(gulp.dest('./public/modules/'));
});
gulp.task('copy-modules', ['modules']);

3
public/index.old

@ -0,0 +1,3 @@
<?php
phpinfo();
?>

33
src/Config.php

@ -11,18 +11,25 @@ define('BASE_PATH', realpath(__DIR__.'/../'));
*/ */
require_once __DIR__.'/../vendor/autoload.php'; require_once __DIR__.'/../vendor/autoload.php';
/**
* Init DotEnv.
*/
// $dotEnv = new \Dotenv\Dotenv(BASE_PATH);
// $dotEnv->load();
if (file_exists(BASE_PATH . '/.env')) {
/** /**
* Init DotEnv. * Init DotEnv.
*/ */
$dotEnv = new \Dotenv\Dotenv(BASE_PATH); $dotEnv = new \Dotenv\Dotenv(BASE_PATH);
$dotEnv->load(); $dotEnv->load();
}
class Config { class Config {
const LINE_READ_LIMIT = 500; const LINE_READ_LIMIT = 500;
const BYTE_READ_LIMIT = 450000000; const BYTE_READ_LIMIT = 450000000;
const MODE = 1; const MODE = 1;
const API_BASE_URL = "https://geoserver.hcmr.gr/geoserver/rest/"; // const API_BASE_URL = "https://geoserver.hcmr.gr/geoserver/rest/";
// const API_BASE_URL = getenv("https://geoserver.hcmr.gr/geoserver/rest/");
const API_CREDENTIALS = ["portal", "@dm!n322"]; const API_CREDENTIALS = ["portal", "@dm!n322"];
/* const REPO_API = "http://msfd-repo.ath.hcmr.gr"; */ /* const REPO_API = "http://msfd-repo.ath.hcmr.gr"; */
const API_URL = array( const API_URL = array(
@ -41,13 +48,6 @@ class Config {
"WFD" => "" "WFD" => ""
); );
const DB_CREDS = array(
"HOST" => "192.168.11.45",
"NAME" => "newschema",
"USER" => "vaslak",
"PASS" => "postgre2020"
);
// Header translations // Header translations
const HEADER_TRANSLATIONS = [ const HEADER_TRANSLATIONS = [
'Cruise' => 'cruise', 'Cruise' => 'cruise',
@ -94,15 +94,20 @@ class Config {
public static function getDatabaseCreds($mode = self::MODE) public static function getDatabaseCreds($mode = self::MODE)
{ {
return array(self::DB_CREDS['HOST'], self::DB_CREDS['NAME'], self::DB_CREDS['USER'], self::DB_CREDS['PASS']); $host = getenv("DB_HOST") ?: "192.168.11.45";
$name = getenv("DB_NAME") ?: "newschema";
$user = getenv("DB_USER") ?: "vaslak";
$pass = getenv("DB_PASS") ?: "postgre2020";
return array($host, $name, $user, $pass); //self::DB_CREDS['USER'], self::DB_CREDS['PASS']);
} }
// GEOSERVER API CONSTANTS // GEOSERVER API CONSTANTS
public static function getAPIBaseURL($api_name) { // public static function getAPIBaseURL($api_name) {
return self::API_URL[$api_name]; // return self::API_URL[$api_name];
} // }
//
public static function getAPICredentials($api_name) public static function getAPICredentials($api_name)
{ {

8
src/Controllers/AuthController.php

@ -30,10 +30,10 @@ class AuthController {
// $res = $api->getUser($user_id); // $res = $api->getUser($user_id);
$sql_groups = "SELECT group_id FROM webapp.users u $sql_groups = "SELECT group_id FROM webapp.users u
JOIN webapp.users__groups ug ON u.geo_id = ug.user_id JOIN webapp.users__groups ug ON u.geo_id = ug.user_id
WHERE geo_id = '${user_id}'"; WHERE geo_id = '{$user_id}'";
$user_groups = Pgsql::getColValues($sql_groups); $user_groups = Pgsql::getColValues($sql_groups);
$sql_name = "SELECT fname FROM webapp.users u $sql_name = "SELECT fname FROM webapp.users u
WHERE geo_id = '${user_id}'"; WHERE geo_id = '{$user_id}'";
$user_name = PgSql::getCol($sql_name); $user_name = PgSql::getCol($sql_name);
$_SESSION['user_id'] = $user_id; $_SESSION['user_id'] = $user_id;
@ -110,7 +110,7 @@ class AuthController {
private function insertGuestUser($email) { private function insertGuestUser($email) {
$sql = "INSERT INTO webapp.users (email, origin, password) $sql = "INSERT INTO webapp.users (email, origin, password)
VALUES ('${email}', 'GUEST', '') VALUES ('{$email}', 'GUEST', '')
ON CONFLICT (email) DO UPDATE ON CONFLICT (email) DO UPDATE
SET last_login = now()"; SET last_login = now()";
@ -120,7 +120,7 @@ class AuthController {
private function insertGuestGroup($id) { private function insertGuestGroup($id) {
$sql = "INSERT INTO webapp.users__groups (user_id, group_id) $sql = "INSERT INTO webapp.users__groups (user_id, group_id)
VALUES ('${id}', 1) ON CONFLICT DO NOTHING"; VALUES ('{$id}', 1) ON CONFLICT DO NOTHING";
PgSql::insert($sql, 'NULL'); PgSql::insert($sql, 'NULL');
} }

9
src/Services/PgSql.php

@ -12,9 +12,12 @@ class PgSql
public static $error; public static $error;
public function close() public static function close()
{ {
if (self::$db) {
pg_close(self::$db); pg_close(self::$db);
self::$db = null;
}
} }
@ -23,7 +26,6 @@ class PgSql
self::$db = pg_connect("host={$dbhost} dbname={$dbname} user={$dbuser} password={$dbpass}"); self::$db = pg_connect("host={$dbhost} dbname={$dbname} user={$dbuser} password={$dbpass}");
} }
// For SELECT // For SELECT
// Returns one row as object // Returns one row as object
public static function getRow($sql) public static function getRow($sql)
@ -34,7 +36,6 @@ class PgSql
return $row; return $row;
} }
// For SELECT // For SELECT
// Returns an array of row objects // Returns an array of row objects
// Gets number of rows // Gets number of rows
@ -108,7 +109,7 @@ class PgSql
$excluded_columns = implode(',', $exc); $excluded_columns = implode(',', $exc);
if ($ret != 'NULL') { if ($ret != 'NULL') {
$sql = rtrim($sql, ';'); $sql = rtrim($sql, ';');
$sql .= "\nON CONFLICT (${conf}) DO UPDATE $sql .= "\nON CONFLICT ({$conf}) DO UPDATE
SET "; SET ";
$sql .= ' RETURNING '; $sql .= ' RETURNING ';
$sql .= implode(',', $ret); $sql .= implode(',', $ret);

4
src/Services/PoseidonAPI.php

@ -19,8 +19,8 @@ class PoseidonAPI extends API {
$url = Config::getAPIbaseURL($this->apiName); $url = Config::getAPIbaseURL($this->apiName);
parent::__construct($url); parent::__construct($url);
$this->username = "y3wvvYKquktkZZALk49utvYeJPikNQFRWzE7A4Wx"; $this->username = Config::getAPIusername($this->apiName);
$this->password = "OXR6RfTbp1UuFHwGAyBeolIYzoVfGP69UBd3KXmVzO1B3gW6Ck9yt2jCipAJT5DCWnhBMcB5sx0EUPEcfy8dcGZjinUyRphLSCIQ72NrdkmiY2lhIv2utjUSq1t3B0pD"; $this->password = Config::getAPIpassword($this->apiName);
} }
// POST request to get access token // POST request to get access token

10
src/Services/WfdAPI.php

@ -17,8 +17,10 @@ class WfdAPI extends API {
$url = Config::getAPIbaseURL($this->apiName); $url = Config::getAPIbaseURL($this->apiName);
parent::__construct($url); parent::__construct($url);
$this->username = "ct_api_user"; $this->username = Config::getAPIusername($this->apiName);
$this->password = "@p1u$3rct"; $this->password = Config::getAPIpassword($this->apiName);
$this->client_id = Config::getAPIclientID($this->apiName);
$this->client_secret = Config::getAPIclientSecret($this->apiName);
} }
// POST request to get access token // POST request to get access token
@ -26,8 +28,8 @@ class WfdAPI extends API {
$endpoint = "token"; $endpoint = "token";
/* $authStr = base64_encode($this->username.":".$this->password); */ /* $authStr = base64_encode($this->username.":".$this->password); */
$data[] = 'grant_type=password'; $data[] = 'grant_type=password';
$data[] = 'client_id=watermonitoring'; $data[] = "client_id=i{$this->client_id}";
$data[] = 'client_secret=8067649c-c5dc-4bf3-922a-d10f44413d68'; $data[] = "client_secret={$this->client_secret}";
$data[] = "username={$this->username}"; $data[] = "username={$this->username}";
$data[] = "password={$this->password}"; $data[] = "password={$this->password}";
/* $this->headers["Accept"] = "x-www-form-urlencoded"; */ /* $this->headers["Accept"] = "x-www-form-urlencoded"; */

Loading…
Cancel
Save