1+ #! /bin/bash
2+ # info: enables support for single sign on PHPmyAdmin
3+ # options: [mode]
4+ # labels:
5+ #
6+ # example: v-add-sys-pma-sso
7+ #
8+ # Enables support for SSO to PHPmyAdmin
9+
10+ # ----------------------------------------------------------#
11+ # Variable&Function #
12+ # ----------------------------------------------------------#
13+
14+ MODE=$1
15+
16+ # Includes
17+ source $HESTIA /func/main.sh
18+ source $HESTIA /conf/hestia.conf
19+
20+ PMA_INSTALL=" /usr/share/phpmyadmin"
21+ PMA_CONFIG=" /etc/phpmyadmin"
22+
23+ # ----------------------------------------------------------#
24+ # Verifications #
25+ # ----------------------------------------------------------#
26+
27+ # Perform verification if read-only mode is enabled
28+ check_hestia_demo_mode
29+
30+ # Checking root permissions
31+ if [ " x$( id -u) " != ' x0' ]; then
32+ echo " Error: Script can be run executed only by root"
33+ exit 10
34+ fi
35+
36+ if [ ! -z " $PHPMYADMIN_KEY " ] && [ " $PHPMYADMIN_KEY " != " " ] ; then
37+ echo " Error: SSO has been installed before to reenable it please run v-delete-pma-sso first"
38+ exit 1;
39+ fi
40+
41+ # Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
42+ if [ -z " $HESTIA " ]; then
43+ HESTIA=" /usr/local/hestia"
44+ fi
45+
46+ if [ -z " $HOMEDIR " ] || [ -z " $HESTIA_INSTALL_DIR " ]; then
47+ echo " Error: Hestia environment vars not present"
48+ exit 2
49+ fi
50+
51+ if [ -f " /usr/share/phpmyadmin/hestia-sso.php" ]; then
52+ echo " Error: hestia-sso.php is already installed"
53+ exit 2
54+ fi
55+
56+ if [ -f " /usr/local/hesta/web/api/index.php" ]; then
57+ echo " Error: API script not installed"
58+ exit 2
59+ fi
60+
61+ if [ " $API " != " yes" ]; then
62+ echo " Error: API is not enabled"
63+ exit 2
64+ fi
65+
66+ # ----------------------------------------------------------#
67+ # Action #
68+ # ----------------------------------------------------------#
69+
70+ # Generate the keys to secure everything
71+ phpmyadminkey=$( generate_password) ;
72+ apikey=$( $BIN /v-generate-api-key) ;
73+
74+ # copy config dir to /usr/share/phpmyadmin/
75+ cp -f $HESTIA_INSTALL_DIR /phpmyadmin/hestia-sso.php $PMA_INSTALL /hestia-sso.php
76+ chmod 644 $PMA_INSTALL /hestia-sso.php
77+
78+ sed -i " s/%PHPMYADMIN_KEY%/$phpmyadminkey /g" $PMA_INSTALL /hestia-sso.php
79+ sed -i " s/%API_KEY%/$apikey /g" $PMA_INSTALL /hestia-sso.php
80+ sed -i " s/%API_HOST_NAME%/$( hostname) /g" $PMA_INSTALL /hestia-sso.php
81+ sed -i " s/%API_HESTIA_PORT%/$BACKEND_PORT /g" $PMA_INSTALL /hestia-sso.php
82+
83+
84+ # Check if config already contains the keys
85+
86+ touch $PMA_CONFIG /hestia-sso.inc.php
87+ chmod 644 $PMA_CONFIG /hestia-sso.inc.php
88+ echo " <?php
89+ if(isset(\$ _GET['hestia_token']) || isset(\$ _COOKIE['SignonSession'])){
90+ \$ cfg['Servers'][\$ i]['auth_type'] = 'signon';
91+ \$ cfg['Servers'][\$ i]['SignonSession'] = 'SignonSession';
92+ \$ cfg['Servers'][\$ i]['SignonURL'] = 'hestia-sso.php';
93+ \$ cfg['Servers'][\$ i]['LogoutURL'] = 'hestia-sso.php?logout=1';
94+ }
95+ ?>" >> $PMA_CONFIG /hestia-sso.inc.php
96+
97+ file=$( cat $PMA_CONFIG /config.inc.php)
98+ if ! [[ $file =~ " hestia-sso.inc.php" ]]; then
99+ if [[ $file =~ " //Add Hestia SSO code here" ]]; then
100+ sed -i " s|//Add Hestia SSO code here|//Add Hestia SSO code here\n include ('$PMA_CONFIG /hestia-sso.inc.php');|g" $PMA_CONFIG /config.inc.php
101+ else
102+ echo " include ('$PMA_CONFIG /hestia-sso.inc.php');" >> $PMA_CONFIG /config.inc.php
103+ fi
104+ fi
105+
106+ $BIN /v-change-sys-config-value ' PHPMYADMIN_KEY' " $phpmyadminkey "
107+
108+ # ----------------------------------------------------------#
109+ # Logging #
110+ # ----------------------------------------------------------#
111+
112+ if [ " $MODE " != " quiet" ]; then
113+ echo " PMA Hestia-SSO plugin has been succesfully installed"
114+ fi
115+
116+ log_history " PMA Hestia-SSO plugin has been succesfully installed" ' ' ' admin'
117+ log_event " $OK " " $ARGUMENTS "
0 commit comments