diff --git a/malik/.gitignore b/malik/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/malik/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/malik/conf/config.inc.php b/malik/conf/config.inc.php new file mode 100644 index 0000000..df7b67f --- /dev/null +++ b/malik/conf/config.inc.php @@ -0,0 +1,163 @@ +. + * + * @package PhpMyAdmin + */ + +/* + * This is needed for cookie based authentication to encrypt password in + * cookie + */ +$cfg['blowfish_secret'] = 'YNH_COOKIE_PASSWD'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */ + +/* + * Servers configuration + */ +$i = 0; + +/* + * First server + */ +$i++; +/* Authentication type */ +$cfg['Servers'][$i]['auth_type'] = 'config'; +$cfg['Servers'][$i]['user'] = 'root'; +$cfg['Servers'][$i]['password'] = 'YNH_MYSQL_ROOT_PASSWORD'; +/* Server parameters */ + +/* +$cfg['Servers'][$i]['host'] = 'localhost'; +$cfg['Servers'][$i]['connect_type'] = 'tcp'; +$cfg['Servers'][$i]['compress'] = false; +*/ + +/* Select mysql if your server does not have mysqli */ +$cfg['Servers'][$i]['extension'] = 'mysqli'; +$cfg['Servers'][$i]['AllowNoPassword'] = false; + +/* + * phpMyAdmin configuration storage settings. + */ + +/* User used to manipulate with storage */ +// $cfg['Servers'][$i]['controlhost'] = ''; +// $cfg['Servers'][$i]['controlport'] = ''; +$cfg['Servers'][$i]['controluser'] = 'YNH_PMA_USER'; +$cfg['Servers'][$i]['controlpass'] = 'YNH_PMA_PASSWORD'; + +/* Storage database and tables */ +$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; +$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark'; +$cfg['Servers'][$i]['relation'] = 'pma__relation'; +$cfg['Servers'][$i]['table_info'] = 'pma__table_info'; +$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords'; +$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages'; +$cfg['Servers'][$i]['column_info'] = 'pma__column_info'; +$cfg['Servers'][$i]['history'] = 'pma__history'; +$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs'; +$cfg['Servers'][$i]['tracking'] = 'pma__tracking'; +$cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords'; +$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig'; +$cfg['Servers'][$i]['recent'] = 'pma__recent'; +$cfg['Servers'][$i]['users'] = 'pma__users'; +$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups'; +$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding'; +$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches'; +$cfg['Servers'][$i]['favorite'] = 'pma__favorite'; +$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns'; +$cfg['Servers'][$i]['tracking'] = 'pma__tracking'; + +/* Contrib / Swekey authentication */ +// $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf'; + +/* + * End of servers configuration + */ + +/* + * Directories for saving/loading files from server + */ +$cfg['UploadDir'] = ''; +$cfg['SaveDir'] = ''; + +/** + * Defines whether a user should be displayed a "show all (records)" + * button in browse mode or not. + * default = false + */ +//$cfg['ShowAll'] = true; + +/** + * Number of rows displayed when browsing a result set. If the result + * set contains more rows, "Previous" and "Next". + * default = 30 + */ +//$cfg['MaxRows'] = 50; + +/** + * disallow editing of binary fields + * valid values are: + * false allow editing + * 'blob' allow editing except for BLOB fields + * 'noblob' disallow editing except for BLOB fields + * 'all' disallow editing + * default = blob + */ +//$cfg['ProtectBinary'] = 'false'; + +/** + * Default language to use, if not browser-defined or user-defined + * (you find all languages in the locale folder) + * uncomment the desired line: + * default = 'en' + */ +//$cfg['DefaultLang'] = 'en'; +//$cfg['DefaultLang'] = 'de'; + +/** + * default display direction (horizontal|vertical|horizontalflipped) + */ +//$cfg['DefaultDisplay'] = 'vertical'; + + +/** + * How many columns should be used for table display of a database? + * (a value larger than 1 results in some information being hidden) + * default = 1 + */ +//$cfg['PropertiesNumColumns'] = 2; + +/** + * Set to true if you want DB-based query history.If false, this utilizes + * JS-routines to display query history (lost by window close) + * + * This requires configuration storage enabled, see above. + * default = false + */ +//$cfg['QueryHistoryDB'] = true; + +/** + * When using DB-based query history, how many entries should be kept? + * + * default = 25 + */ +//$cfg['QueryHistoryMax'] = 100; + +/** + * Should error reporting be enabled for JavaScript errors + * + * default = 'ask' + */ +//$cfg['SendErrorReports'] = 'ask'; + +/* + * You can find more configuration options in the documentation + * in the doc/ folder or at . + */ +?> diff --git a/malik/conf/create_db.sql b/malik/conf/create_db.sql new file mode 100644 index 0000000..aaf4d14 --- /dev/null +++ b/malik/conf/create_db.sql @@ -0,0 +1,27 @@ +-- -------------------------------------------------------- +-- SQL Commands to set up the pmadb as described in the documentation. +-- +-- This file is meant for use with MySQL 5 and above! +-- +-- This script expects the user pma to already be existing. If we would put a +-- line here to create him too many users might just use this script and end +-- up with having the same password for the controluser. +-- +-- This user "pma" must be defined in config.inc.php (controluser/controlpass) +-- +-- Please don't forget to set up the tablenames in config.inc.php +-- + +-- -------------------------------------------------------- + +DROP DATABASE `phpmyadmin`; + +-- +-- Database : `phpmyadmin` +-- +CREATE DATABASE IF NOT EXISTS `phpmyadmin` + DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; +USE phpmyadmin; + +GRANT SELECT, INSERT, DELETE, UPDATE ON `phpmyadmin`.* TO + 'YNH_PMA_USER'@localhost; diff --git a/malik/conf/nginx.conf b/malik/conf/nginx.conf new file mode 100644 index 0000000..c5870f3 --- /dev/null +++ b/malik/conf/nginx.conf @@ -0,0 +1,20 @@ +location YNH_WWW_PATH { + alias YNH_WWW_ALIAS ; + if ($scheme = http) { + rewrite ^ https://$server_name$request_uri? permanent; + } + 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/malik/manifest.json b/malik/manifest.json new file mode 100644 index 0000000..efaa7ac --- /dev/null +++ b/malik/manifest.json @@ -0,0 +1,46 @@ +{ + "name": "phpMyAdmin", + "id": "phpmyadmin", + "description": { + "en": "Manage MySQL databases over the web", + "fr": "Application web de gestion des bases de données MySQL" + }, + "url": "http://www.phpmyadmin.net", + "maintainer": { + "name": "julien", + "email": "julien.malik@paraiso.me" + }, + "multi_instance": "false", + "arguments": { + "install" : [ + { + "name": "domain", + "type": "domain", + "ask": { + "en": "Choose a domain for phpMyAdmin", + "fr": "Choisissez un domaine pour phpMyAdmin" + }, + "example": "domain.org" + }, + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for phpMyAdmin", + "fr": "Choisissez un chemin pour phpMyAdmin" + }, + "example": "/phpmyadmin", + "default": "/phpmyadmin" + }, + { + "name": "admin", + "type": "user", + "ask": { + "en": "Choose the only allowed admin user", + "fr": "Choisissez l'unique utilisateur autorisé" + }, + "example": "johndoe" + } + ] + } +} diff --git a/malik/scripts/install b/malik/scripts/install new file mode 100755 index 0000000..73afc81 --- /dev/null +++ b/malik/scripts/install @@ -0,0 +1,74 @@ +#!/bin/bash + +# Retrieve arguments +domain=$1 +path=$2 +admin=$3 + +# Check domain/path availability +sudo yunohost app checkurl $domain$path -a phpmyadmin +if [[ ! $? -eq 0 ]]; then + exit 1 +fi + +# Check that admin user is an existing account +sudo yunohost user list --json | grep -q "\"username\": \"$admin\"" +if [[ ! $? -eq 0 ]]; then + echo "Error : the chosen admin user does not exist" + exit 1 +fi + +# Copy files to the right place +version=$(cat upstream_version) +final_path=/var/www/phpmyadmin +sudo rm -rf $final_path +sudo mkdir -p $final_path +echo "Downloading phpMyAdmin $version..." +sudo wget -O ../phpMyAdmin.tar.gz http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/$version/phpMyAdmin-$version-all-languages.tar.gz/download > /dev/null 2>&1 +echo "Extracting to $final_path..." +sudo tar xvzf ../phpMyAdmin.tar.gz -C .. > /dev/null 2>&1 +sudo cp -r ../phpMyAdmin-$version-all-languages/* $final_path + +# Create db +echo "Setting up database..." +db_user=phpmyadmin +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') +cookie_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') +sed -i "s@YNH_PMA_USER@$db_user@g" ../conf/create_db.sql +sudo yunohost app initdb $db_user -p $db_pwd +mysql -u root -p$(sudo cat /etc/yunohost/mysql) < ../conf/create_db.sql +mysql -u $db_user -p$db_pwd < $final_path/examples/create_tables.sql +sudo yunohost app setting phpmyadmin mysqlpwd -v $db_pwd + +# Configuration +echo "Configuring application..." +sed -i "s@YNH_DOMAIN@$domain@g" ../conf/config.inc.php +sed -i "s@YNH_PMA_USER@$db_user@g" ../conf/config.inc.php +sed -i "s@YNH_PMA_PASSWORD@$db_pwd@g" ../conf/config.inc.php +sed -i "s@YNH_MYSQL_ROOT_PASSWORD@$(sudo cat /etc/yunohost/mysql)@g" ../conf/config.inc.php +sed -i "s@YNH_COOKIE_PASSWD@$cookie_pwd@g" ../conf/config.inc.php +sudo cp ../conf/config.inc.php $final_path + +sudo yunohost app addaccess phpmyadmin -u $admin +sudo yunohost app setting phpmyadmin admin -v $admin + +# Files owned by root, www-data can just read +echo "Setting permission..." +sudo chown -R root: $final_path +sudo find $final_path -type f | xargs sudo chmod 644 +sudo find $final_path -type d | xargs sudo chmod 755 +# config.inc.php contains sensitive data, restrict its access +sudo chown root:www-data $final_path/config.inc.php +sudo chmod 640 $final_path/config.inc.php + +# Modify Nginx configuration file and copy it to Nginx conf directory +echo "Setting up nginx configuration..." +sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf +sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf +nginxconf=/etc/nginx/conf.d/$domain.d/phpmyadmin.conf +sudo cp ../conf/nginx.conf $nginxconf +sudo chown root: $nginxconf +sudo chmod 600 $nginxconf + +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/malik/scripts/remove b/malik/scripts/remove new file mode 100755 index 0000000..e43e1a9 --- /dev/null +++ b/malik/scripts/remove @@ -0,0 +1,13 @@ +#!/bin/bash + +domain=$(sudo yunohost app setting phpmyadmin domain) + +sudo rm -rf /var/www/phpmyadmin +sudo rm -f /etc/nginx/conf.d/$domain.d/phpmyadmin.conf + +sudo service nginx reload + +db_user=phpmyadmin +db_name=phpmyadmin +root_pwd=$(sudo cat /etc/yunohost/mysql) +mysql -u root -p$root_pwd -e "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;" diff --git a/malik/scripts/upgrade b/malik/scripts/upgrade new file mode 100644 index 0000000..0a83cad --- /dev/null +++ b/malik/scripts/upgrade @@ -0,0 +1,68 @@ +#!/bin/bash + +# Retrieve arguments +domain=$(sudo yunohost app setting phpmyadmin domain) +path=$(sudo yunohost app setting phpmyadmin path) +admin=$(sudo yunohost app setting phpmyadmin admin) + +# Remove trailing "/" for next commands +path=${path%/} + +# In older version, the admin setting was admin_user +if [[ -z "$admin" ]]; then + admin=$(sudo yunohost app setting phpmyadmin admin_user) + sudo yunohost app setting phpmyadmin admin_user -d + sudo yunohost app setting phpmyadmin admin -v $admin +fi + +# Copy files to the right place +final_path=/var/www/phpmyadmin +version=$(cat upstream_version) +sudo rm -rf $final_path +sudo mkdir -p $final_path +echo "Downloading phpMyAdmin $version..." +sudo wget -O ../phpMyAdmin.tar.gz http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/$version/phpMyAdmin-$version-all-languages.tar.gz/download > /dev/null 2>&1 +echo "Extracting to $final_path..." +sudo tar xvzf ../phpMyAdmin.tar.gz -C .. > /dev/null 2>&1 +sudo cp -r ../phpMyAdmin-$version-all-languages/* $final_path + +# Database settings +echo "Setting up database..." +db_user=phpmyadmin +db_pwd=$(sudo yunohost app setting phpmyadmin mysqlpwd) + +# Update tables +mysql -u $db_user -p$db_pwd < $final_path/examples/upgrade_column_info_4_3_0+.sql +mysql -u $db_user -p$db_pwd < $final_path/examples/create_tables.sql + +# Configuration +echo "Configuring application..." +sed -i "s@YNH_DOMAIN@$domain@g" ../conf/config.inc.php +sed -i "s@YNH_PMA_USER@$db_user@g" ../conf/config.inc.php +sed -i "s@YNH_PMA_PASSWORD@$db_pwd@g" ../conf/config.inc.php +sed -i "s@YNH_MYSQL_ROOT_PASSWORD@$(sudo cat /etc/yunohost/mysql)@g" ../conf/config.inc.php +sudo cp ../conf/config.inc.php $final_path + +sudo yunohost app addaccess phpmyadmin -u $admin +sudo yunohost app setting phpmyadmin admin -v $admin + +# Files owned by root, www-data can just read +echo "Setting permission..." +sudo chown -R root: $final_path +sudo find $final_path -type f | xargs sudo chmod 644 +sudo find $final_path -type d | xargs sudo chmod 755 +# config.inc.php contains sensitive data, restrict its access +sudo chown root:www-data $final_path/config.inc.php +sudo chmod 640 $final_path/config.inc.php + +# Modify Nginx configuration file and copy it to Nginx conf directory +echo "Setting up nginx configuration..." +sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf +sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf +nginxconf=/etc/nginx/conf.d/$domain.d/phpmyadmin.conf +sudo cp ../conf/nginx.conf $nginxconf +sudo chown root: $nginxconf +sudo chmod 600 $nginxconf + +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/malik/scripts/upstream_version b/malik/scripts/upstream_version new file mode 100644 index 0000000..5d72fe4 --- /dev/null +++ b/malik/scripts/upstream_version @@ -0,0 +1 @@ +4.3.10