Introduce EesyPHP framework

This commit is contained in:
Benjamin Renard 2024-01-30 18:40:00 +01:00
parent 958598b07c
commit 81b902ea5d
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
43 changed files with 585 additions and 53 deletions

15
.gitignore vendored Normal file
View file

@ -0,0 +1,15 @@
# Ignore vim temporary/backup files
*~
.*.swp
# Exclude composer installed libs
/vendor
/composer.lock
# Common UNIX user home directory files
/.bash*
/.vim*
/.composer
/.gitconfig
/.vim*
/.less*
/.ssh
/.phplint-cache

7
bin/manage Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/php
<?php
use EesyPHP\Cli;
require realpath(dirname(__FILE__).'/..')."/includes/core.php";
Cli :: handle_args();

26
composer.json Normal file
View file

@ -0,0 +1,26 @@
{
"name": "brenard/mysc",
"description": "My Sweetcase",
"type": "project",
"require": {
"brenard/eesyphp": "dev-master"
},
"license": "GPL3",
"autoload": {
"psr-4": {
"Brenard\\Mysc\\": "src/"
}
},
"authors": [
{
"name": "Benjamin Renard",
"email": "brenard@zionetrix.net"
}
],
"minimum-stability": "dev",
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}

370
config.yml Normal file
View file

@ -0,0 +1,370 @@
# Public root URL
public_root_url: "/"
# Application root data directory
data_directory: "${root_directory_path}/data"
# Temporary files root directory
tmp_root_directory: "${data_directory}/tmp"
# Temporary uploading files directory (optional, default: PHP ini default)
upload_tmp_directory: ${tmp_root_directory}/uploading"
# Uploading file size limit (in bytes, example: 104857600 == 100Mb)
# (optional, default: PHP ini default)
upload_max_filesize: 104857600
# Main pagetitle
main_pagetitle: "Eesyphp"
# Debug Ajax request/response
debug_ajax: false
#
# Log configuration
#
log:
# Logs directory path
directory_path: "${data_directory}/logs"
# CLI log file path
cli_file_path: "${log.directory_path}/cli.log"
# Log file path
file_path: "${log.directory_path}/app.log"
# Log level (TRACE / DEBUG / INFO / WARNING / ERROR / FATAL)
level: "INFO"
# Log PHP errors levels (as specified to set_error_handler())
# Note: expected a list of PHP error level constants that will be resolved and combine
# with a bitwise operator. After the first value, the bitwise operator "|" (OR) or "^" (XOR)
# could be specified as contanst name prefix, otherwise the "&" (AND) operator will be used.
# The constant name could also be prefix with "~" or "!" (NOT) bitwise operator.
#
# Default:
# - In TRACE or DEBUG: E_ALL & ~E_STRICT
# - Otherwise: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
#log_php_errors_levels:
# - E_ALL
# - ~E_NOTICE
# - ~E_STRICT
# - ~E_DEPRECATED
#
# Sentry configuration
#
sentry:
# Sentry DSN
#dsn: null
# Log PHP errors in Sentry: list of errors types to logs
# See: https://www.php.net/manual/fr/errorfunc.constants.php
php_error_types:
- "E_ERROR"
- "E_PARSE"
- "E_CORE_ERROR"
- "E_COMPILE_ERROR"
- "E_USER_ERROR"
- "E_RECOVERABLE_ERROR"
- "E_DEPRECATED"
# Traces sample rate (between 0 and 1)
# Note: this parameter permit to determine how many transactions (=~ access) are traced and
# sent to Sentry, for instance, 0.2 meen that 20% of the transactions will be traced. In dev
# mode, set to 1 if you want all transactions are sent to Sentry.
# Default: 0.2
traces_sample_rate: 0.2
#
# Smarty templates configuration
#
templates:
# Smarty directories
directory: "${root_directory_path}/templates"
cache_directory: "${tmp_root_directory}/templates_c"
# Theme CSS file
included_css_files:
#- css/custom.css
included_js_files:
#- js/custom.js
#
# Translations
#
i18n:
# Default locale (see locales directory for available languages list)
default_locale: "en_US.UTF8"
#
# Session
#
session:
# Session timeout due to inactivity (in seconds)
timeout: 1800
# Session max duration (in seconds, default : 12h)
max_duration: 43200
# Directory path where to store PHP sessions data (optional, default: use system default)
directory_path: "${data_directory}/sessions"
#
# Database configuration
#
db:
# Sqlite
#dsn: "sqlite:${data_directory}/db.sqlite3"
#options: null
# Date/Datetime format in database (strptime format)
#date_format: '%s'
#datetime_format: '%s'
# Postgresql
#dsn: "pgsql:host=localhost;port=5432;dbname=items"
#user: "items"
#pwd: "items"
#options: null
# Date/Datetime format in database (strptime format)
#date_format: '%Y-%m-%d' # Example : 2018-10-12
#datetime_format: '%Y-%m-%d %H:%M:%S' # Example : 2018-10-12 18:06:59
# MariaDB / MySQL
#dsn: "mysql:host=localhost;dbname=items"
#user: "items"
#pwd: "items"
#options: null
# Date/Datetime format in database (strptime format)
#date_format: '%Y-%m-%d' # Example : 2018-10-12
#datetime_format: '%Y-%m-%d %H:%M:%S' # Example : 2018-10-12 18:06:59
#
# Authentication
#
auth:
# Enabled authentication
enabled: false
# Methods to authenticate users
methods:
- form
- http
#- cas
# User backends
backends:
#- ldap
#- db
#- casuser
#
# Login form
#
login_form:
# Include application navbar (default: true)
include_navbar: true
# Display link for other authentication methods
# Note: method as key and label as value
display_other_methods:
http: "HTTP"
cas: "SSO"
# Remember username
# Enable the feature (default: true)
# remember_username: true
# Cookie name (default: remember_username)
# remember_username_cookie_name: "remember_username"
#
# HTTP Authentication Configuration
#
http:
# HTTP Auth methods :
# * AUTHORIZATION : use HTTP_AUTHORIZATION environment. This mode could be use with PHP FPM.
# Specific configuration is need in Apache to use this mode :
# RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# * REMOTE_USER : use REMOTE_USER environment variable to retrieve authenticated user's login
# This method could be only used with $http_auth_trust_without_password_challenge
# enabled.
# * PHP_AUTH : use PHP_AUTH_USER and PHP_AUTH_PW environment variables (only available
# using mod_php with Apache. (default)
method: "PHP_AUTH"
# Trust HTTP server authentication
# If enabled, the application will no check user credentials and only retrieve user's login
# from HTTP server.
#trust_without_password_challenge: true
# Realm (use when force HTTP login, optional)
#realm: "Authentication required"
#
# CAS Configuration
#
cas:
# CAS host (just the domain name)
host: "idp.example.com"
# CAS context (the root path, default: '/idp/cas')
# Example: for 'http://idp.example.com/idp/cas', put '/idp/cas'
context: "/idp/cas"
# CAS HTTP port (default: 443)
#port: 443
# CAS procotol version
# Possible values: "1.0", "2.0" (default), "3.0" or "S1" (SAML1)
#version: '2.0'
# CAS server SSL certificate validation (set to false to disable)
ca_cert_certificate_path: "/etc/ssl/certs/ca-certificates.crt"
# CAS Debug log file
#debug_log_file: "${root_directory_path}/data/logs/cas.log"
# CAS Logout
#logout: true # Enable CAS logout on app logout
#logout_url: "https://my.example.fr/logout/" # Specify custom CAS logout URL
# CAS Fake authenticated user
#fake_authenticated_user: 'myusername'
# CAS user attributes to retrieve with their properties:
# [attr name]:
# # CAS attribute name (optional, default: [attr name])
# cas_name: [CAS attr name]
# # Alternative CAS attribute name to retrieve if the first one is not defined (optional)
# alt_cas_name: [alternative CAS attr name]
# # Type of value (optional, default: 'string', possible values: string, bool, int, float)
# type: [type of value]
# # Default attribute value (optional, default: null)
# default: null
# Note: only used by casuser auth backend.
user_attributes:
login:
cas_name: "uid"
default: null
name:
cas_name: "displayName"
cas_ldap_name: "cn"
default: null
mail:
type: "string"
#
# Database user backend
#
db:
# DSN (required)
dsn: "${db.dsn}"
# Username (optional but could be required with some PDO drivers)
user: "${db.user}"
# Password (optional)
password: "${db.password}"
# PDO options (optional)
options: "${db.options}"
# Users table name (optional, default: users)
#users_table: "users"
# Username field name (optional, default: username)
#username_field: "username"
# Password field name (optional, default: password)
#password_field: "password"
# Exposed users table fields in resulting EesyPHP\Auth\User object
# (optional, default: name, mail)
#exposed_fields:
# - "name"
# - "mail"
#
# LDAP user backend
#
ldap:
# LDAP host (required, multiple hosts could be specified with comma separator)
host: "ldap://localhost"
# LDAP port (optional)
#port: 389
# Enable STARTTLS (optional, default: false)
#starttls: false
# LDAP directory base DN (required)
basedn: "o=example"
# LDAP bind DN (optional)
#bind_dn: 'uid=eesyphp,ou=sysaccounts,${auth.ldap.basedn}'
# LDAP bind password (optional)
#bind_password: 'secret'
# User search filter by username. The keyword "[username]" will be replace before search by
# the looked username (default: "uid=[username]")
#user_filter_by_uid: 'uid=[username]'
# User base DN
user_basedn: "ou=people,${auth.ldap.basedn}"
# Bind with username instead of user DN (optional, default: false)
#bind_with_username: true
# LDAP user attributes to retrieve with their properties:
# [attr name]:
# # LDAP attribute name (optional, default: [attr name])
# ldap_name: [LDAP attr name]
# # Alternative LDAP attribute name to retrieve if the first one is not defined (optional)
# alt_ldap_name: [alternative LDAP attr name]
# # Type of value (optional, default: 'string', possible values: string, bool, int, float)
# type: [type of value]
# # Multivalued attribute (optional, default: false)
# multivalued: true
# # Default attribute value (optional, default: null)
# default: null
user_attributes:
login:
ldap_name: "uid"
multivalued: false
default: null
name:
ldap_name: "displayName"
alt_ldap_name: "cn"
multivalued: false
default: null
mail:
type: "string"
# PEAR Net_LDAP2 library path (optional, default: Net/LDAP2.php)
#netldap2_path: 'Net/LDAP2.php'
#
# Email configuration
#
email:
# PHP PEAR Mail and Mail_Mine paths
php_mail_path: "Mail.php"
php_mail_mime_path: "Mail/mime.php"
# Sending method :
# - mail : use PHP mail function
# - sendmail : use sendmail system command
# - smtp : use an SMTP server (PHP PEAR Net_SMTP required)
send_method: "smtp"
# Sending parameters
# See : http:#pear.php.net/manual/en/package.mail.mail.factory.php
send_params: NULL
# Headers add to all e-mails sent
headers:
#- "CC: support@example.com"
# Email sender address (for all emails sent by the application)
sender: "noreply@example.org"
# Catch all e-mails sent to a configured e-mail address
catch_all: false
# Web Stats JS code
#webstats_js_code: ''
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab

2
data/logs/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*.log
*.log.*

1
data/sessions/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
sess_*

1
data/tmp/templates_c/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.tpl.php

56
includes/core.php Normal file
View file

@ -0,0 +1,56 @@
<?php
use EesyPHP\App;
use EesyPHP\I18n;
use EesyPHP\SentrySpan;
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
// Root directory path
$script = null;
if (defined('__FILE__') && constant('__FILE__')) { // @phpstan-ignore-line
$script = __FILE__;
}
else {
// Fallback method : detect path from core.php path
foreach(get_included_files() as $script)
if (basename($script) == 'core.php')
break;
}
if (!$script) die('Fail to detect root directory path');
$root_dir_path = realpath(dirname($script).'/../');
// Include App's includes and vendor directories to PHP include paths
set_include_path($root_dir_path.'/includes' . PATH_SEPARATOR . get_include_path());
// Load composer autoload.php
require("$root_dir_path/vendor/autoload.php");
// Initialize EesyPHP application
App::init(
"$root_dir_path/config.yml",
array(
'overwrite_config_files' => array(
"$root_dir_path/config.local.yml",
),
'templates' => array(
'static_directories' => array(
"$root_dir_path/static"
),
),
'default' => array(
// Set here your configuration parameters default value
),
),
$root_dir_path
);
$sentry_span = new SentrySpan('core.init', 'Core initialization');
// Put here your own initialization stuff
require 'views/index.php';
$sentry_span->finish();
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab

64
includes/views/index.php Normal file
View file

@ -0,0 +1,64 @@
<?php
use EesyPHP\Tpl;
use EesyPHP\Url;
/**
* Redirect to homepage
* @param EesyPHP\UrlRequest $request
* @return void
*/
function handle_redirect_homepage($request) {
Url::redirect("home");
}
Url :: add_url_handler(null, 'handle_redirect_homepage');
/**
* Homepage
* @param EesyPHP\UrlRequest $request
* @return void
*/
function handle_homepage($request) {
Tpl :: display("index.tpl");
}
Url :: add_url_handler("#^home$#", 'handle_homepage');
function _list_static_directory_files($root_dir, $dir, &$result, &$last_updated) {
foreach (array_diff(scandir($dir), array('.','..')) as $file) {
$path = "$dir/$file";
if (is_dir($path)) {
_list_static_directory_files($root_dir, $path, $result, $last_updated);
}
else {
$result[] = Tpl::static_url(substr($path, strlen($root_dir)+1));
$file_last_updated = filemtime($path);
if ($file_last_updated > $last_updated)
$last_updated = $file_last_updated;
}
}
}
/**
* Cache manifest file
* @param EesyPHP\UrlRequest $request
* @return void
*/
function handle_cache_manifest($request) {
$cache = ["home"];
$last_updated = filemtime(Tpl::resolve_templates_path("index.tpl"));
foreach (Tpl::static_directories() as $static_directory)
_list_static_directory_files($static_directory, $static_directory, $cache, $last_updated);
Tpl::assign("cache", $cache);
Tpl::assign("last_updated", date("Y/m/d H:i:s", $last_updated));
header("Content-type: text/plain");
$content = Tpl::fetch("cache_manifest.tpl");
$etag = md5($content);
header("Cache-Control: max-age=3000, must-revalidate");
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_updated)." GMT");
header("Etag: $etag");
print($content);
exit();
}
Url :: add_url_handler("#^cache\.manifest$#", 'handle_cache_manifest');
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab

4
locales/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
headers.pot
js-*-messages.pot
php-messages.pot
templates-*-messages.pot

8
public_html/.htaccess Normal file
View file

@ -0,0 +1,8 @@
RewriteEngine On
#RewriteBase /app
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid link
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php [L]

View file

@ -1,39 +0,0 @@
CACHE MANIFEST
# Date : 2018/06/18 - Version : 1
CACHE:
index.html
favicon.png
icon-196x196.png
icon-128x128.png
inc/main.css
inc/main.js
inc/mysc_objects.js
inc/mydialog.js
# Bootstrap
inc/lib/bootstrap/css/bootstrap.min.css
inc/lib/bootstrap/css/bootstrap-theme.min.css
inc/lib/bootstrap/css/bootstrap.css
inc/lib/bootstrap/css/bootstrap-theme.css
inc/lib/bootstrap/css/bootstrap.css.map
inc/lib/bootstrap/css/bootstrap-theme.min.css.map
inc/lib/bootstrap/css/bootstrap-theme.css.map
inc/lib/bootstrap/css/bootstrap.min.css.map
inc/lib/bootstrap/js/bootstrap.js
inc/lib/bootstrap/js/npm.js
inc/lib/bootstrap/js/bootstrap.min.js
inc/lib/bootstrap/fonts/glyphicons-halflings-regular.eot
inc/lib/bootstrap/fonts/glyphicons-halflings-regular.woff2
inc/lib/bootstrap/fonts/glyphicons-halflings-regular.woff
inc/lib/bootstrap/fonts/glyphicons-halflings-regular.svg
inc/lib/bootstrap/fonts/glyphicons-halflings-regular.ttf
# jQuery
inc/lib/jquery.min.js
NETWORK:
*

9
public_html/index.php Normal file
View file

@ -0,0 +1,9 @@
<?php
include '../includes/core.php';
use EesyPHP\Url;
Url :: handle_request('');
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab

0
static/.gitignore vendored Normal file
View file

View file

Before

Width:  |  Height:  |  Size: 763 B

After

Width:  |  Height:  |  Size: 763 B

View file

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

View file

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View file

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

0
templates/.gitignore vendored Normal file
View file

View file

@ -0,0 +1,8 @@
CACHE MANIFEST
# Last updated: {$last_updated} GMT
CACHE:
{"\n"|implode:$cache}
NETWORK:
*

View file

@ -5,20 +5,20 @@
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=0"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=0">
<link rel="shortcut icon" href="favicon.png"> <link rel="shortcut icon" href="{static_url path="favicon.png"}">
<link rel="shortcut icon" sizes="196x196" href="icon-196x196.png"> <link rel="shortcut icon" sizes="196x196" href="{static_url path="icon-196x196.png"}">
<link rel="shortcut icon" sizes="128x128" href="icon-128x128.png"> <link rel="shortcut icon" sizes="128x128" href="{static_url path="icon-128x128.png"}">
<link rel="apple-touch-icon" sizes="128x128" href="icon-128x128.png"> <link rel="apple-touch-icon" sizes="128x128" href="{static_url path="icon-128x128.png"}">
<link rel="apple-touch-icon-precomposed" sizes="128x128" href="icon-128x128.png"> <link rel="apple-touch-icon-precomposed" sizes="128x128" href="{static_url path="icon-128x128.png"}">
<!-- Bootstrap --> <!-- Bootstrap -->
<!-- Latest compiled and minified CSS --> <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="inc/lib/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="{static_url path="lib/bootstrap/css/bootstrap.min.css"}">
<!-- Optional theme --> <!-- Optional theme -->
<link rel="stylesheet" href="inc/lib/bootstrap/css/bootstrap.superhero.min.css"> <link rel="stylesheet" href="{static_url path="lib/bootstrap/css/bootstrap.superhero.min.css"}">
<link rel="stylesheet" href="inc/main.css"> <link rel="stylesheet" href="{static_url path="main.css"}">
</head> </head>
<body> <body>
@ -266,18 +266,18 @@
</div> </div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="inc/lib/jquery.min.js"></script> <script src="{static_url path="lib/jquery.min.js"}"></script>
<!-- Latest compiled and minified JavaScript --> <!-- Latest compiled and minified JavaScript -->
<script src="inc/lib/bootstrap/js/bootstrap.js"></script> <script src="{static_url path="lib/bootstrap/js/bootstrap.js"}"></script>
<script> <script>
</script> </script>
<script src="inc/lib/uuid.js"></script> <script src="{static_url path="lib/uuid.js"}"></script>
<script src="inc/mydialog.js"></script> <script src="{static_url path="mydialog.js"}"></script>
<script src="inc/mysc_objects.js"></script> <script src="{static_url path="mysc_objects.js"}"></script>
<script src="inc/main.js"></script> <script src="{static_url path="main.js"}"></script>
</body> </body>
</html> </html>