diff --git a/README.md b/README.md new file mode 100644 index 0000000..07e8731 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +emailpoubelle +============= +A Yunohost version of Email Poubelle by David Mercereau. All thanks to David. +http://www.mercereau.info/sortie-de-la-version-1-0-demailpoubelle-php-email-jetable-auto-hebergeable/ +============= + +WARNING +========= +Using this will cause to disable the Yunohost ldap aliases ! Once installed, you won't be able to use the aliasses settings that you can see when you modify your personnal settings in the SSOWAT pannel. +Of course, once uninstalled, everything get back to normal. + +TODO : +------ +Test it ! (and check if that doesn't interfer with postfix and its aliases) + +Test Translate ! +Translate it to other languages ! + +cron job to remove redirections (0 */2 * * * /usr/bin/wget -q -t 1 -T 7200 -O /dev/null 'https://domain/poubelle/index.php?act=cron' >/dev/null 2>&1) conflict with SSOWAT + non-public app diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..8a587a5 --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,18 @@ +location YNH_EXAMPLE_PATH { + # Path to source + alias YNH_EXAMPLE_ALIAS ; + # Example PHP configuration + index index.php; + try_files $uri $uri/ index.php; + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param REMOTE_USER $remote_user; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param SCRIPT_FILENAME $request_filename; + } + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..3e8e7d9 --- /dev/null +++ b/manifest.json @@ -0,0 +1,55 @@ +{ + "name": "EmailPoubelle", + "id": "emailpoubelle", + "description": { + "en": "Create throwable email address redirected to your real one", + "fr": "Créez des adresses email jetables qui redirigent les mails vers votre adresse réelle" + }, + "developer": { + "name": "David Mercereau", + "email": "david@mercereau.info", + "url": "http://www.mercereau.info/sortie-de-la-version-1-0-demailpoubelle-php-email-jetable-auto-hebergeable/" + }, + "multi_instance": "false", + "license": "Beerware", + "arguments": { + "install" : [ + { + "name": "domain", + "ask": { + "en": "Choose a domain for emailpoubelle", + "fr": "Choisissez un domaine pour emailpoubelle" + }, + "example": "domain.org" + }, + { + "name": "path", + "ask": { + "en": "Choose a path for emailpoubelle", + "fr": "Choisissez un chemin pour emailpoubelle" + }, + "example": "/poubelle", + "default": "/poubelle" + }, + { + "name": "admin", + "ask": { + "en": "Choose an admin user for emailpoubelle", + "fr": "Choisissez un administrateur pour emailpoubelle" + }, + "example": "homer" + }, + { + "name": "public_site", + "ask": { + "en": "Should this application be public ?", + "fr": "Est-ce que cette application doit être visible publiquement ?" + }, + "choices": ["Yes", "No"], + "default": "No" + } + + + ] + } +} diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..6d511fd --- /dev/null +++ b/scripts/install @@ -0,0 +1,96 @@ +#!/bin/bash +# Write all logs to file +#exec > >(tee /tmp/emailpoubelle.log) +#exec 2>&1 +app=emailpoubelle + +# Retrieve arguments +domain=$1 +path=$2 +admin=$3 +is_public=$4 +final_path=/var/www/$app + +postfix=/etc/postfix/main.cf + +cronline="0 */2 * * * www-data cd $final_path/www/; /usr/bin/php index.php > /dev/null 2>&1" + +# Check domain/path availability +sudo yunohost app checkurl $domain$path -a $app +if [[ ! $? -eq 0 ]]; then +exit 1 +fi + +# Check user +sudo yunohost user list --json | grep -q "\"username\": \"$admin\"" +if [[ ! $? -eq 0 ]]; then +echo "Wrong user" +exit 1 +fi + +# Save app settings +sudo yunohost app setting $app admin -v "$admin" +sudo yunohost app setting $app is_public -v "$is_public" + + + +# Copy source files +sudo mkdir -p $final_path +sudo cp -R ../src/* $final_path + +#configuring with given settings +sudo cp $final_path/conf-dist.php $final_path/conf.php +sudo chown -R www-data:www-data $final_path +sudo sed -i "s@exemple.fr@$domain@g" $final_path/conf.php +sudo sed -i "s@exemple.com@$domain@g" $final_path/conf.php + +#generating random password for database +db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p') +db_user=emailPoubelle + +#write password to the conf file +sudo sed -i "s@motdepassedefou@$db_pwd@g" $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 + +#initialize database +sudo yunohost app initdb $db_user -p $db_pwd + +#setting postfix to use virtual aliases file +sudo cp $postfix $postfix.emailpoubelle.bak #backup it eventually if that causes some issues +sudo sed -i "s/^virtual_alias_maps/#virtual_alias_maps/g" $postfix +echo "virtual_alias_maps = hash:$final_path/var/virtual" | sudo tee -a $postfix + +#create the virtual aliases file +sudo touch $final_path/var/virtual +sudo postmap $final_path/var/virtual +sudo chown www-data $final_path/var/virtual +sudo chown www-data $final_path/var/virtual.db + +#create an alias for deleted junk adresses +sudo cp /etc/aliases /etc/aliases.emailpoubelle.bak #backup it +sudo echo "devnull:/dev/null" | sudo tee -a /etc/aliases +sudo newaliases + +# Modify Nginx configuration file and copy it to Nginx conf directory +sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf +sudo sed -i "s@YNH_EXAMPLE_ALIAS@$final_path/www/@g" ../conf/nginx.conf +sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf +# If app is public, add url to SSOWat conf as skipped_uris +if [ "$is_public" = "Yes" ]; +then +sudo yunohost app setting $app skipped_uris -v "/" +fi + +#adding php-cli for cron +sudo apt-get update -qq +sudo apt-get install -yqq php5-cli +#adding cronjob for removing expired email addresses +sudo echo "$cronline" | sudo tee -a /etc/cron.d/emailpoubelle +sudo chmod 644 /etc/cron.d/emailpoubelle + +# Restart services +sudo service nginx reload +sudo service postfix reload +sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove new file mode 100644 index 0000000..e673a00 --- /dev/null +++ b/scripts/remove @@ -0,0 +1,23 @@ +#!/bin/bash + +db_user=emailPoubelle +db_name=$db_user +root_pwd=$(sudo cat /etc/yunohost/mysql) +domain=$(sudo yunohost app setting emailpoubelle domain) +postfix=/etc/postfix/main.cf +#removing emailpoubelle database +sudo mysql -u root -p$root_pwd -e "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;" +#removing emailpoubelle directory +sudo rm -rf /var/www/emailpoubelle +#removing nginx conf +sudo rm -f /etc/nginx/conf.d/$domain.d/emailpoubelle.conf +#removing aliases +sudo sed -i "/devnull:\/dev\/null/d" /etc/aliases +sudo newaliases +sudo sed -i "/virtual_alias_maps = hash:\/var\/www\/emailpoubelle\/var\/virtual/d" $postfix +sudo sed -i "s/^#virtual_alias_maps/virtual_alias_maps/g" $postfix +#remove cronjob +sudo rm -f /etc/cron.d/emailpoubelle +sudo service postfix reload +sudo service nginx reload +sudo yunohost app ssowatconf \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade new file mode 100644 index 0000000..4546060 --- /dev/null +++ b/scripts/upgrade @@ -0,0 +1,31 @@ +#!/bin/bash +# Write all logs to file +#exec > >(tee /tmp/emailpoubelle.log) +#exec 2>&1 +app=emailpoubelle + + +final_path=/var/www/emailpoubelle + +cronline="0 */2 * * * www-data cd $final_path/www/; /usr/bin/php index.php > /dev/null 2>&1" + +# Copy source files +sudo mkdir -p $final_path +sudo cp -R ../src/bin/ $final_path/bin +sudo cp -R ../src/lib/ $final_path/lib +sudo cp -R ../src/locale/ $final_path/locale +sudo cp -R ../src/www/ $final_path/www +sudo cp ../src/emailPoubelle.php $final_path/emailPoubelle.php +sudo chown -R www-data:www-data $final_path + +#adding php-cli for cron +sudo apt-get update -qq +sudo apt-get install -yqq php5-cli +#adding cronjob for removing expired email addresses +sudo echo "$cronline" | sudo tee -a /etc/cron.d/emailpoubelle +sudo chmod 644 /etc/cron.d/emailpoubelle + +# Restart services +sudo service nginx reload +sudo service postfix reload +sudo yunohost app ssowatconf