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. 37
      src/Config.php
  11. 8
      src/Controllers/AuthController.php
  12. 11
      src/Services/PgSql.php
  13. 4
      src/Services/PoseidonAPI.php
  14. 10
      src/Services/WfdAPI.php

8
.docker/caddy/Dockerfile

@ -0,0 +1,8 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -1,5 +1,6 @@
.htaccess
.env
.docker/data/*
node_modules/
package-lock.json
composer.phar

17
composer.lock generated

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

65
docker-compose.yml

@ -0,0 +1,65 @@ @@ -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 @@ @@ -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 @@ @@ -0,0 +1,3 @@
<?php
phpinfo();
?>

37
src/Config.php

@ -14,15 +14,22 @@ require_once __DIR__.'/../vendor/autoload.php'; @@ -14,15 +14,22 @@ require_once __DIR__.'/../vendor/autoload.php';
/**
* Init DotEnv.
*/
$dotEnv = new \Dotenv\Dotenv(BASE_PATH);
$dotEnv->load();
// $dotEnv = new \Dotenv\Dotenv(BASE_PATH);
// $dotEnv->load();
if (file_exists(BASE_PATH . '/.env')) {
/**
* Init DotEnv.
*/
$dotEnv = new \Dotenv\Dotenv(BASE_PATH);
$dotEnv->load();
}
class Config {
const LINE_READ_LIMIT = 500;
const BYTE_READ_LIMIT = 450000000;
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 REPO_API = "http://msfd-repo.ath.hcmr.gr"; */
const API_URL = array(
@ -41,13 +48,6 @@ class Config { @@ -41,13 +48,6 @@ class Config {
"WFD" => ""
);
const DB_CREDS = array(
"HOST" => "192.168.11.45",
"NAME" => "newschema",
"USER" => "vaslak",
"PASS" => "postgre2020"
);
// Header translations
const HEADER_TRANSLATIONS = [
'Cruise' => 'cruise',
@ -94,15 +94,20 @@ class Config { @@ -94,15 +94,20 @@ class Config {
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
public static function getAPIBaseURL($api_name) {
return self::API_URL[$api_name];
}
// public static function getAPIBaseURL($api_name) {
// return self::API_URL[$api_name];
// }
//
public static function getAPICredentials($api_name)
{

8
src/Controllers/AuthController.php

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

11
src/Services/PgSql.php

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

4
src/Services/PoseidonAPI.php

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

10
src/Services/WfdAPI.php

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

Loading…
Cancel
Save