1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/emailpoubelle_ynh.git synced 2024-09-03 18:26:29 +02:00
This commit is contained in:
ericgaspar 2021-06-24 10:25:02 +02:00
parent 54b3688751
commit 3d0bc0250e
No known key found for this signature in database
GPG key ID: 574F281483054D44
5 changed files with 169 additions and 113 deletions

101
conf/conf-dist.php Normal file
View file

@ -0,0 +1,101 @@
<?php
//-----------------------------------------------------------
// emailPoubelle config
// Licence : GNU GPL v3 : http://www.gnu.org/licenses/gpl.html
// Créateur : David Mercereau - david [aro] mercereau [.] info
// Home : http://poubelle.zici.fr
//-----------------------------------------------------------
// writable for script
define('DATA', '../var');
// include directory
define('INC', '../lib');
define('URLINC', './lib'); // or http://mondomaine.tld/lib
define('LANG', '../lang');
// include function
include_once(INC.'/ep_function.php');
include_once(INC.'/ep_header.php');
define('DEBUG', false);
// Domain email (separe with ; exemple : exemple.com;zici.fr;exemple.fr)
define('DOMAIN', '__DOMAIN__');
//define('DOMAIN', 'exemple.com;zici.fr;exemple.fr');
// Nombre d'alias poubelle limite par email
// define('ALIASLIMITBYMAIL', 30);
// PDO stucture
// Exemple pour MYSQL :
// define('DB', 'mysql:host=127.0.0.1;dbname=baseMysql');
// define('DBUSER', 'utilisateurMysql');
// define('DBPASS', 'motdepassedefou');
// Exemple pour Sqlite :
// define('DB', 'sqlite:./data/emailPoubelle.sqlite');
// define('DB', 'sqlite:'.DATA.'/database.sdb');
define('DB', 'mysql:host=127.0.0.1;dbname=__DB_NAME__');
define('DBUSER', '__DB_NAME__');
define('DBPASS', '__DB_PWD__');
// table prefix
define('DBTABLEPREFIX', 'ep_');
// Use cron (true/false) for life expire email (recomanded)
// If use true add in crontab :
// 0 */2 * * * /usr/bin/wget -q -t 1 -T 7200 -O /dev/null 'http://exemple.com/page.php?act=cron' >/dev/null 2>&1
define('CRON', false);
// Fichier d'alias postfix
define('FICHIERALIAS', DATA.'/virtual');
define('BIN_POSTMAP', '/usr/sbin/postmap');
define('URLPAGE', 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]);
// Email
define('EMAILTAGSUJET', '[EmailPoubelle]');
// From de l'email
define('EMAILFROM', '"NO REPLAY emailPoubelle" <emailpoubelle@__DOMAIN__>');
define('EMAILEND', 'emailPoubelle.zici.fr');
// Alisas interdit : (regex ligne par ligne) - commenter pour désactiver
define('ALIASDENY', DATA.'/aliasdeny.txt');
// Blackliste d'email : (regex ligne par ligne) - commenter pour désactiver
define('BLACKLIST', DATA.'/blacklist.txt');
// Depend pear Net/DNS2
define('CHECKMX', false);
if (CHECKMX) {
require_once('Net/DNS2.php');
// Serveur DNS pour la résolution/vérification du nom de domaine
define('NS1', 'ns1.fdn.org');
define('NS2', '8.8.8.8');
}
// A indiquer si vous utiliser les URL's rewriting
// Exemple avec un htaccess
// RewriteRule ^ep-([a-z]+)-([a-zA-Z0-9+/=]+)\.html$ switch.php?page=emailPoubelle&act=$1&value=$2 [L]
//define('URLREWRITE_START', 'http://poubelle.zici.fr/ep-');
//define('URLREWRITE_MIDDLE', '-');
//define('URLREWRITE_END', '.html');
// Désactiver
define('URLREWRITE_START', false);
define('URLREWRITE_MIDDLE', false);
define('URLREWRITE_END', false);
// check update :
// enable : in seconds
// disable : false
define('CHECKUPDATE', 86400);
// Maintenance mode
define('MAINTENANCE_MODE', false);
// No maintenance for this ip (admin ip)
define('MAINTENANCE_IP', '10.0.0.1');
// Mot de passe par défaut "admin" :
define('ADMIN_PASSWORD', '__PASSWORD__');
?>

View file

@ -1 +1 @@
0 */2 * * * www-data cd $final_path/www/; /usr/bin/php index.php > /dev/null 2>&1
0 */2 * * * www-data cd __FINALPATH__/www/; /usr/bin/php index.php > /dev/null 2>&1

View file

@ -5,12 +5,21 @@
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
@ -22,41 +31,35 @@ is_public=$YNH_APP_ARG_IS_PUBLIC
final_path=/var/www/$app
db_user=emailPoubelle
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
# Check user
ynh_user_exists "$admin"
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app admin $admin
ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app db_name $db_user
ynh_app_setting_set $app final_path $final_path
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=admin --value=$admin
ynh_app_setting_set --app=$app --key=db_name --value=$db_user
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
#=================================================
#INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=15
ynh_install_app_dependencies $pkg_dependencies
#install locale (nginx will restart at the end of the install)
@ -69,8 +72,8 @@ locale-gen
#=================================================
#INSTALL SOURCES
#===============================================
ynh_script_progression --message="Setting up source files..." --weight=5
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
cp ../conf/index_source.php $final_path/www/index.php
@ -81,43 +84,30 @@ ln -s $final_path/lang/fr $final_path/lang/fr_FR
ln -s $final_path/lang/it $final_path/lang/it_IT
ln -s $final_path/www/template-exemple $final_path/template-exemple
#===============================================
#SETTINGS & DATABASE
#===============================================
ynh_script_progression --message="Setting database & settings..."
#=================================================
# CREATE A MYSQL DATABASE
#=================================================
ynh_script_progression --message="Creating a MySQL database..." --weight=1
#generating random password for database
ynh_print_OFF
db_pwd=$(ynh_string_random)
ynh_app_setting_set $app mysqlpwd $db_pwd
ynh_print_ON
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
#configuring with given settings
cp $final_path/conf-dist.php $final_path/conf.php
#Update various conf : domain, database, user and password
ynh_replace_string "exemple.fr" "$domain" $final_path/conf.php
ynh_replace_string "exemple.com" "$domain" $final_path/conf.php
ynh_replace_string "define('DB', 'sqlite:'" "//define('DB', 'sqlite:'" $final_path/conf.php
ynh_replace_string "define('ALIASLIMITBYMAIL" "//define('ALIASLIMITBYMAIL" $final_path/conf.php
ynh_replace_string "// define('DB', 'mysql" " define('DB', 'mysql" $final_path/conf.php
ynh_replace_string "// define('DBUSER'," " define('DBUSER'," $final_path/conf.php
ynh_replace_string "// define('DBPASS'," " define('DBPASS'," $final_path/conf.php
ynh_replace_string "baseMysql" "$db_user" $final_path/conf.php
ynh_replace_string "utilisateurMysql" "$db_user" $final_path/conf.php
ynh_print_OFF
ynh_replace_string "motdepassedefou" "$db_pwd" $final_path/conf.php
ynh_replace_string "define('ADMIN_PASSWORD', 'admin');" "define('ADMIN_PASSWORD', '$password');" $final_path/conf.php
ynh_print_ON
#setting conf file not world-readable (dude, there is a plain-text password !)
chmod o-r $final_path/conf.php
#initialize database (databasename = db_user)
ynh_print_OFF
ynh_mysql_create_db $db_user $db_user $db_pwd
ynh_print_ON
ynh_add_config --template="../conf/conf-dist.php" --destination="$final_path/conf.php"
chmod 400 "$final_path/conf.php"
#chown $app:$app "$final_path/conf.php"
#setting postfix to use virtual aliases file
# Add postfix configuration hook and regen postfix conf
cp -R ../sources/hooks/conf_regen/98-postfix_emailpoubelle /usr/share/yunohost/hooks/conf_regen/
ynh_add_config --template="../sources/hooks/conf_regen/98-postfix_emailpoubelle" --destination="/usr/share/yunohost/hooks/conf_regen/"
yunohost tools regen-conf postfix
#create the virtual aliases file
@ -131,12 +121,15 @@ echo "devnull:/dev/null" | tee -a /etc/aliases
newaliases
#adding cronjob for removing expired email addresses
cp -a ../conf/$app.cron /etc/cron.d/$app
ynh_add_config --template="../conf/emailpoubelle.cron" --destination="/etc/cron.d/$app"
chown root:root /etc/cron.d/$app
chmod 644 /etc/cron.d/$app
# Create a dedicated nginx config
ynh_script_progression --message="Configuring nginx web server..." --weight=2
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
ynh_add_nginx_config
#=================================================
@ -156,4 +149,9 @@ fi
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action --service_name=postfix --action=reload
service php* reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -29,8 +29,6 @@ ynh_script_progression --message="Removing the MySQL database..."
# Remove a database if it exists, along with the associated user
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
#=================================================
# REMOVE DEPENDENCIES
#=================================================
@ -61,11 +59,13 @@ ynh_remove_nginx_config
# REMOVE THE CRON FILE
#=================================================
ynh_script_progression --message="Removing cron job and aliases..."
ynh_secure_remove --file="/etc/cron.d/$app"
#=================================================
#removing aliases
#=================================================
ynh_replace_string "devnull:/dev/null" "" /etc/aliases
newaliases

View file

@ -5,21 +5,22 @@
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..."
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
admin=$(ynh_app_setting_get $app admin)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
admin=$(ynh_app_setting_get --app=$app --key=admin)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# CHECK VERSION
@ -54,69 +55,25 @@ fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
#check for matlink's version - DEPRECATED - uninstall & reinstall
#=================================================
#deprecated - not maintained for more than a year...
#cat /etc/yunohost/apps/$app/status.json | grep "matlink"
#if [[ $?==0 ]]; then
#add missing info in settings
# final_path=/var/www/$app
# db_name=emailPoubelle
# ynh_app_setting_set $app db_name $db_name
# ynh_app_setting_set $app final_path $final_path
#install geoip dependencies
# ynh_install_app_dependencies $pkg_dependencies
#install locale packages
# for i in $lang ; do
# ynh_replace_string "# $i" "$i" /etc/locale.gen
# done
# locale-gen
#change folder locale => lang as per src2.0
# rm -rf $final_path/locale
# mkdir -p $final_path/lang
#add new index.php
# cp ../conf/index_source.php $final_path/www/index.php
#switch from previous (modified) conf.php to new one (emailpoubelle original)
# cp ../src/conf-dist.php $final_path/conf-dist.new.php
#insert domain in line 24, DB in line 31, DBUSER in line 32, etc.
# rep=$(cat $final_path/conf.php | grep "^[^//]" | grep "define('DOMAIN',")
# sed -i "24s/.*/${rep}/" $final_path/conf-dist.new.php
# rep=$(cat $final_path/conf.php | grep "^[^//]" | grep "define('DB',")
# sed -i "31s/.*/${rep}/" $final_path/conf-dist.new.php
# rep=$(cat $final_path/conf.php | grep "^[^//]" | grep "define('DBUSER',")
# sed -i "32s/.*/${rep}/" $final_path/conf-dist.new.php
# rep=$(cat $final_path/conf.php | grep "^[^//]" | grep "define('DBPASS',")
# sed -i "33s/.*/${rep}/" $final_path/conf-dist.new.php
#replace old conf and process with install command
# mv $final_path/conf.php $final_path/conf.php.old
# mv $final_path/conf-dist.new.php $final_path/conf.php
# ynh_replace_string "define('DB', 'sqlite:'" "//define('DB', 'sqlite:'" $final_path/conf.php
# ynh_replace_string "define('ALIASLIMITBYMAIL" "//define('ALIASLIMITBYMAIL" $final_path/conf.php
# #setting conf file not world-readable (dude, there is a plain-text password !)
# sudo chmod o-r $final_path/conf.php
#fi
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading nginx web server configuration..."
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
ynh_backup_if_checksum_is_different "/etc/nginx/conf.d/$domain.d/$app.conf"
# Create a dedicated nginx config
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
@ -142,8 +99,8 @@ fi
#=================================================
#INSTALL SOURCES
#===============================================
ynh_script_progression --message="Upgrading source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
cp ../conf/index_source.php $final_path/www/index.php