1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/aeneria_ynh.git synced 2024-09-03 18:06:15 +02:00

Apapt for aeneria v2

This commit is contained in:
Simon Mellerin 2023-12-22 17:26:06 +01:00
parent f215c960b0
commit b00356262d
13 changed files with 87 additions and 95 deletions

View file

@ -26,7 +26,7 @@ The idea of [æneria](https://aeneria.com) is to display energy consumption and
## Screenshots
![Screenshot of æneria](./doc/screenshots/screenshot1.png)
![Capture décran de æneria](./doc/screenshots/preview-1.png)
## Documentation and resources

View file

@ -25,7 +25,7 @@ L'idée de [æneria](https://aeneria.com) est d'afficher la consommation d'éner
## Captures décran
![Capture décran de æneria](./doc/screenshots/screenshot1.png)
![Capture décran de æneria](./doc/screenshots/preview-1.png)
## Documentations et ressources

View file

@ -32,10 +32,23 @@ AENERIA_DEMO_MODE=0
# Welcome message
AENERIA_WELCOME_MESSAGE='<h1>Bienvenue sur æneria</h1>'
### Enedis Data Hub ###
# æneria proxy URL (no trailing slash !)
AENERIA_PROXY_URL=https://proxy.aeneria.com
# should the app use æneria proxy (1 for yes, 0 for no)
AENERIA_PROXY_FOR_ENEDIS=1
AENERIA_PROXY_FOR_GRDF=1
# Enedis Data Hub
ENEDIS_CLIENT_ID=noneed
ENEDIS_CLIENT_SECRET=noneed
ENEDIS_REDIRECT_URI=noneed
ENEDIS_ENDPOINT_AUTH=https://proxy.aeneria.com/enedis-data-connect
ENEDIS_ENDPOINT_TOKEN=https://proxy.aeneria.com/enedis-data-connect
ENEDIS_ENDPOINT_AUTH=https://mon-compte-particulier.enedis.fr
ENEDIS_ENDPOINT_TOKEN=https://gw.prd.api.enedis.fr
ENEDIS_ENDPOINT_DATA=https://gw.prd.api.enedis.fr
# Grdf adict
GRDF_CLIENT_ID=noneed
GRDF_CLIENT_SECRET=noneed
GRDF_REDIRECT_URI=noneed
GRDF_ENDPOINT_AUTH=https://sofit-sso-oidc.grdf.fr
GRDF_ENDPOINT_DATA=https://api.grdf.fr

View file

@ -1,2 +1,2 @@
__MINUTES__ __HOUR__-23/3 * * * __APP__ /usr/bin/php__PHPVERSION__ __INSTALL_DIR__/bin/console aeneria:fetch-data
*/15 * * * * __APP__ /usr/bin/php__PHPVERSION__ __INSTALL_DIR__/bin/console aeneria:pending-action:process-expired
__MINUTES__ __HOUR__-23/3 * * * __APP__ /usr/bin/php__PHPVERSION__ __INSTALL_DIR__/app/bin/console aeneria:fetch-data
*/15 * * * * __APP__ /usr/bin/php__PHPVERSION__ __INSTALL_DIR__/app/bin/console aeneria:pending-action:process-expired

View file

@ -2,7 +2,7 @@
location __PATH__/ {
# Path to source
alias __INSTALL_DIR__/public/;
alias __INSTALL_DIR__/app/public/;
client_body_timeout 60m;
proxy_read_timeout 60m;

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

View file

@ -2,10 +2,10 @@ packaging_format = 2
id = "aeneria"
name = "æneria"
description.en = "Dashboard to analyse your energy consumption data from Linky & weather"
description.fr = "Tableau de bord pour analyser votre consomation d'énergie à partir des données d'un Linky et de la météo"
description.en = "Dashboard to analyse your energy consumption data from Linky, Gazpar & weather"
description.fr = "Tableau de bord pour analyser votre consomation d'énergie à partir des données d'un compteur Linky et/ou Gazpar et de la météo"
version = "1.1.6~ynh5"
version = "2.0.0~ynh1"
maintainers = ["Simon Mellerin"]
@ -20,9 +20,9 @@ yunohost = ">= 11.2"
architectures = "all"
multi_instance = true
ldap = false
ldap = true
sso = false
sso = true
disk = "50M"
ram.build = "50M"
@ -46,10 +46,9 @@ ram.runtime = "50M"
default = false
[resources]
[resources.sources.main]
url = "https://statics.aeneria.com/aeneria-app-1.1.6.tar.gz"
sha256 = "2923c3aee79a02154c2168537a18250abe6a3a84fd7b4a5f0309bd7ad604a98b"
[resources.sources.main]
url = "https://statics.aeneria.com/aeneria-app-2.0.0.tar.gz"
sha256 = "8a36dc2634178e6f087893aca6459ef7cbe7ad9e436c829a7f05f88a8a304571"
[resources.system_user]
@ -59,7 +58,7 @@ ram.runtime = "50M"
main.url = "/"
[resources.apt]
packages = "postgresql, apt-transport-https, postgresql-contrib, php7.4-zip, php7.4-pgsql, php7.4-xml, php7.4-intl, php7.4-mbstring, php7.4-gd, php7.4-curl, php7.4-bcmath, php7.4-opcache"
packages = "postgresql, apt-transport-https, postgresql-contrib, php8.2-zip, php8.2-pgsql, php8.2-xml, php8.2-intl, php8.2-gd, php8.2-curl, php8.2-bcmath, php8.2-opcache"
[resources.database]
type = "postgresql"

View file

@ -45,10 +45,10 @@ ynh_add_fpm_config
#=================================================
ynh_script_progression --message="Configuring $app..." --weight=1
ynh_add_config --template=".env" --destination="$install_dir/.env"
ynh_add_config --template=".env" --destination="$install_dir/app/.env"
# Restrict rights to aeneria user only
chmod 600 "$install_dir/.env"
chmod 600 "$install_dir/app/.env"
#=================================================
# INSTALL AENERIA
@ -56,7 +56,7 @@ chmod 600 "$install_dir/.env"
ynh_script_progression --message="Installing aeneria..." --weight=1
# Install aeneria
pushd $install_dir
pushd $install_dir/app
ynh_exec_as $app php$phpversion bin/console aeneria:install "$app" -n
# Create admin user
mail=$(ynh_user_get_info --username="$admin" --key='mail')

View file

@ -79,10 +79,10 @@ chmod 644 "/etc/cron.d/$app"
#=================================================
ynh_script_progression --message="Configuring $app..." --weight=1
ynh_add_config --template=".env" --destination="$install_dir/.env"
ynh_add_config --template=".env" --destination="$install_dir/app/.env"
# Restrict rights to aeneria user only
chmod 600 "$install_dir/.env"
chmod 600 "$install_dir/app/.env"
#=================================================
# UPGRADE AENERIA
@ -90,7 +90,7 @@ chmod 600 "$install_dir/.env"
ynh_script_progression --message="Upgrading $app..." --weight=1
# Install dependencies and aeneria
pushd $install_dir
pushd $install_dir/app
ynh_exec_as $app php$phpversion bin/console cache:clear -n
ynh_exec_as $app php$phpversion bin/console doctrine:migrations:migrate -n
@ -104,7 +104,7 @@ pushd $install_dir
fi
# Regenerate RSA keys
ynh_exec_as $app php$phpversion bin/console aeneria:generate-key --force -n
ynh_exec_as $app php$phpversion bin/console aeneria:generate-key -n
popd
#=================================================

View file

@ -1,12 +1,14 @@
commit c7a763a0fae7e1933f280b29bd2a1911b01f7170
commit 19648694faaf973e7b4b0de1dbe49710e14a8ce7
Author: Simon Mellerin <simon.mellerin@makina-corpus.com>
Date: Fri Nov 27 12:19:02 2020 +0100
Date: Fri Dec 22 17:22:41 2023 +0100
diff --git a/config/packages/security.yaml b/config/packages/security.yaml
index 15ef608..8516775 100644
--- a/config/packages/security.yaml
+++ b/config/packages/security.yaml
@@ -10,6 +10,8 @@ security:
Yunohost ldap
diff --git a/app/config/packages/security.yaml b/app/config/packages/security.yaml
index 6c4457f1..ea1f3dc9 100644
--- a/app/config/packages/security.yaml
+++ b/app/config/packages/security.yaml
@@ -11,6 +11,8 @@ security:
entity:
class: App\Entity\User
property: username
@ -15,10 +17,10 @@ index 15ef608..8516775 100644
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
@@ -20,6 +22,10 @@ security:
provider: app_user_provider
authenticators:
- App\Security\LoginFormAuthenticator
@@ -23,6 +25,10 @@ security:
login_path: security.login
check_path: security.login
enable_csrf: true
+ http_basic_ldap:
+ provider: user_provider_yunohost
+ service: yunohost.ldap
@ -26,14 +28,14 @@ index 15ef608..8516775 100644
logout:
path: security.logout
target: security.login
diff --git a/config/services.yaml b/config/services.yaml
index 533c244..9362ef5 100644
--- a/config/services.yaml
+++ b/config/services.yaml
@@ -70,3 +70,16 @@ services:
diff --git a/app/config/services.yaml b/app/config/services.yaml
index 4410bfc5..71b9ba86 100644
--- a/app/config/services.yaml
+++ b/app/config/services.yaml
@@ -105,3 +105,16 @@ services:
Aeneria\EnedisDataConnectApi\Service\DataConnectServiceInterface:
alias: Aeneria\EnedisDataConnectApi\Service\DataConnectService
Aeneria\GrdfAdictApi\Client\GrdfAdictClientInterface:
alias: Aeneria\GrdfAdictApi\Client\GrdfAdictClient
+
+ yunohost.provider.ldap:
+ class: App\Security\YunohostLdapUserProvider
@ -47,14 +49,16 @@ index 533c244..9362ef5 100644
+ class: Symfony\Component\Ldap\Adapter\ExtLdap\Adapter
+ arguments:
+ - host: "localhost"
diff --git a/src/Security/YunohostLdapUserProvider.php b/src/Security/YunohostLdapUserProvider.php
diff --git a/app/src/Security/YunohostLdapUserProvider.php b/app/src/Security/YunohostLdapUserProvider.php
new file mode 100644
index 0000000..39ba1e8
index 00000000..09ad20c6
--- /dev/null
+++ b/src/Security/YunohostLdapUserProvider.php
@@ -0,0 +1,123 @@
+++ b/app/src/Security/YunohostLdapUserProvider.php
@@ -0,0 +1,102 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Security;
+
+use App\Entity\User;
@ -64,85 +68,62 @@ index 0000000..39ba1e8
+use Symfony\Component\Ldap\LdapInterface;
+use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
+use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
+use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
+use Symfony\Component\Security\Core\Exception\UserNotFoundException;
+use Symfony\Component\Security\Core\User\UserInterface;
+use Symfony\Component\Security\Core\User\UserProviderInterface;
+
+/**
+ * Adapted from LdapUserProvider.
+ *
+ * @author Grégoire Pineau <lyrixx@lyrixx.info>
+ * @author Charles Sarrazin <charles@sarraz.in>
+ * @author Robin Chalas <robin.chalas@gmail.com>
+ */
+class YunohostLdapUserProvider implements UserProviderInterface
+{
+ /** @var LdapInterface */
+ private $ldap;
+ /** @var string */
+ private $baseDn;
+ /** @var string */
+ private $searchDn;
+ /** @var string */
+ private $searchPassword;
+ /** @var string[] */
+ private $defaultRoles;
+ /** @var string */
+ private $uidKey;
+ /** @var string */
+ private $defaultSearch;
+ /** @var UserRepository */
+ private $userRepository;
+ private string $defaultSearch = '(uid={username})';
+
+ public function __construct(
+ LdapInterface $ldap,
+ string $baseDn,
+ string $searchDn = null,
+ string $searchPassword = null,
+ array $defaultRoles = [],
+ UserRepository $userRepository
+ ) {
+ $this->ldap = $ldap;
+ $this->baseDn = $baseDn;
+ $this->searchDn = $searchDn;
+ $this->searchPassword = $searchPassword;
+ $this->defaultRoles = $defaultRoles;
+ $this->defaultSearch = '(uid={username})';
+
+ $this->userRepository = $userRepository;
+ }
+ private LdapInterface $ldap,
+ private string $baseDn,
+ private UserRepository $userRepository,
+ private ?string $searchDn = null,
+ private ?string $searchPassword = null,
+ ) {}
+
+ /**
+ * {@inheritdoc}
+ */
+ public function loadUserByUsername(string $username)
+ {
+ trigger_deprecation('symfony/security-core', '5.3', 'Method "%s()" is deprecated, use loadUserByIdentifier() instead.', __METHOD__);
+
+ return $this->loadUserByIdentifier($username);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function loadUserByIdentifier(string $identifier): UserInterface
+ {
+ try {
+ $this->ldap->bind($this->searchDn, $this->searchPassword);
+ $username = $this->ldap->escape($username, '', LdapInterface::ESCAPE_FILTER);
+ $query = str_replace('{username}', $username, $this->defaultSearch);
+ $username = $this->ldap->escape($identifier, '', LdapInterface::ESCAPE_FILTER);
+ $query = str_replace('{username}', $identifier, $this->defaultSearch);
+ $search = $this->ldap->query($this->baseDn, $query);
+ } catch (ConnectionException $e) {
+ throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username), 0, $e);
+ throw new UserNotFoundException(sprintf('User "%s" not found.', $identifier), 0, $e);
+ }
+
+ $entries = $search->execute();
+ $count = \count($entries);
+
+ if (!$count) {
+ die($username . 'ldap pas trouvé');
+ throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username));
+ }
+
+ if ($count > 1) {
+ throw new UsernameNotFoundException('More than one user found.');
+ throw new UserNotFoundException('More than one user found.');
+ }
+
+ $entry = $entries[0];
+
+ $username = $this->getAttributeValue($entry, 'mail');
+ $identifier = $this->getAttributeValue($entry, 'mail');
+
+ return $this->userRepository->findOneBy(['username' => $username]);
+ return $this->userRepository->findOneBy(['username' => $identifier]);
+ }
+
+ /**
@ -176,4 +157,3 @@ index 0000000..39ba1e8
+ return $values[0];
+ }
+}
--