1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/teampass_ynh.git synced 2024-09-03 20:26:37 +02:00

Add config

This commit is contained in:
ericgaspar 2021-07-11 16:37:26 +02:00
parent b29118eaca
commit 23c9ecea64
4 changed files with 29 additions and 43 deletions

View file

@ -108,7 +108,7 @@ INSERT INTO `teampass_misc` (`type`, `intitule`, `valeur`) VALUES
('admin', 'enable_email_notification_on_user_pw_change', '1'),
('admin', 'custom_logo', ''),
('admin', 'custom_login_text', ''),
('admin', 'default_language', '__LANG__'),
('admin', 'default_language', '__LANGUE__'),
('admin', 'send_stats', '0'),
('admin', 'send_statistics_items', 'stat_country;stat_users;stat_items;stat_items_shared;stat_folders;stat_folders_shared;stat_admins;stat_managers;stat_ro;stat_mysqlversion;stat_phpversion;stat_teampassversion;stat_languages;stat_kb;stat_suggestion;stat_customfields;stat_api;stat_2fa;stat_agses;stat_duo;stat_ldap;stat_syslog;stat_stricthttps;stat_fav;stat_pf;'),
('admin', 'send_stats_time', '3600'),

View file

@ -12,7 +12,7 @@ $port = 3306;
$encoding = "utf8";
@date_default_timezone_set($_SESSION['settings']['timezone']);
@define('SECUREPATH', '__SKPATH__');
if (file_exists("__SKPATH__sk.php")) {
require_once "__SKPATH__sk.php";
@define('SECUREPATH', '__PATH_SK_FILE__');
if (file_exists("__PATH_SK_FILE__sk.php")) {
require_once "__PATH_SK_FILE__sk.php";
}

View file

@ -56,6 +56,14 @@ db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=2
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
@ -76,14 +84,6 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=2
# Create a system user
ynh_system_user_create --username=$app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
@ -98,6 +98,11 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
# FILL THE DATABASE
#=================================================
version="$(sed -n 3p $final_path/changelog.txt)"
bcrypt_mdp="$(php $final_path/mdphash.php $password_admin)"
timezone="$(cat /etc/timezone)"
time="$(date +%s)"
# Remplacement des variables dans le fichier sql
if [ $(echo $LANG | cut -c1-2) == "fr" ]
then
@ -109,23 +114,15 @@ else
folders=shared
roles=users
fi
ynh_replace_string "__APP__" "$app" ../conf/populate.sql
ynh_replace_string "__FINALPATH__" "$final_path" ../conf/populate.sql
ynh_replace_string "__DOMAIN__" "$domain" ../conf/populate.sql
ynh_replace_string "__PATH__" "$path_url" ../conf/populate.sql
ynh_replace_string "__FOLDERS__" "$folders" ../conf/populate.sql
ynh_replace_string "__ROLES__" "$roles" ../conf/populate.sql
ynh_replace_string "__VERSION__" "$(sed -n 3p $final_path/changelog.txt)" ../conf/populate.sql
ynh_replace_string "__TIMEZONE__" "$(cat /etc/timezone)" ../conf/populate.sql
ynh_replace_string "__BCRYPT_MDP__" "$(php $final_path/mdphash.php $password_admin)" ../conf/populate.sql
ynh_replace_string "__LANG__" "$langue" ../conf/populate.sql
ynh_replace_string "__TIME__" "$(date +%s)" ../conf/populate.sql
ynh_add_config --template="../conf/populate.sql" --destination="$final_path/populate.sql"
# Enregistre les infos dans la config YunoHost
ynh_app_setting_set $app langue $langue
ynh_app_setting_set --app=$app --key=langue --value=$langue
# Import du fichier SQL
ynh_mysql_connect_as $db_name $db_pwd $db_name < ../conf/populate.sql
ynh_mysql_connect_as $db_name $db_pwd $db_name < $final_path/populate.sql
ynh_secure_remove --file="$final_path/populate.sql"
#=================================================
# CREATE TP.CONFIG.PHP FILE
@ -149,13 +146,10 @@ echo ");" >> $tp_config_file
# CONFIGURE TEAMPASS
#=================================================
# Remplacement des variables dans les fichier settings.php et sk.php
ynh_replace_string "__DB_USER__" "$db_name" ../conf/settings.php
ynh_replace_string "__DB_PWD__" "$db_pwd" ../conf/settings.php
ynh_replace_string "__FINALPATH__" "$final_path" ../conf/settings.php
path_sk_file=/etc/$app/
mkdir $path_sk_file
ynh_replace_string "__SKPATH__" "$path_sk_file" ../conf/settings.php
ynh_add_config --template="../conf/settings.php" --destination="$final_path/includes/config/settings.php"
#=================================================
# CREATE A SALTKEY
@ -163,16 +157,15 @@ ynh_replace_string "__SKPATH__" "$path_sk_file" ../conf/settings.php
saltkey=$(ynh_string_random --length=32)
ynh_replace_string "__SALTKEY__" "$saltkey" ../conf/sk.php
ynh_add_config --template="../conf/sk.php" --destination="$path_sk_file/sk.php"
#=================================================
# COPY THE FILES
#=================================================
cp ../conf/sk.php $path_sk_file/sk.php
chown -R $app $path_sk_file
chmod 750 $path_sk_file
cp ../conf/settings.php $final_path/includes/config/settings.php
ynh_store_file_checksum "$final_path/includes/config/settings.php" # Enregistre la somme de contrôle du fichier de config
cp $final_path/includes/libraries/csrfp/libs/csrfp.config.sample.php $final_path/includes/libraries/csrfp/libs/csrfp.config.php # Créer le fichier de config de csrfp
ynh_replace_string "CSRFP_TOKEN\" => \"" "&$(head -n40 /dev/urandom | tr -c -d 'a-f0-9' | head -c50)" $final_path/includes/libraries/csrfp/libs/csrfp.config.php # Renseigne un token, valide en hexadécimal
ynh_replace_string "jsUrl\" => \"" "&includes/libraries/csrfp/js/csrfprotector.js" $final_path/includes/libraries/csrfp/libs/csrfp.config.php # Renseigne l'adresse de csrfprotector.js

View file

@ -19,6 +19,7 @@ domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
#=================================================
# CHECK VERSION
@ -153,17 +154,9 @@ fi
# UPDATE SETTINGS.PHP
#=================================================
# Remplacement des variables dans le fichier settings.php
ynh_replace_string "__DB_USER__" "$db_name" ../conf/settings.php
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_replace_string "__DB_PWD__" "$db_pwd" ../conf/settings.php
ynh_replace_string "__FINALPATH__" "$final_path" ../conf/settings.php
path_sk_file=/etc/$app/
ynh_replace_string "__SKPATH__" "$path_sk_file" ../conf/settings.php
path_sk_file="/etc/$app/"
ynh_backup_if_checksum_is_different "$final_path/includes/config/settings.php"
cp ../conf/settings.php $final_path/includes/config/settings.php
ynh_store_file_checksum "$final_path/includes/config/settings.php" # Enregistre la somme de contrôle du fichier de config
ynh_add_config --template="../conf/settings.php" --destination="$final_path/includes/config/settings.php"
#=================================================
# GENERIC FINALISATION