#!/bin/sh #---------------------------------------------------------------------------- # /var/install/bin/phpmyadmin-tools-pma-user # # Creation: 2007-01-22 starwarsfan # Last Update: $Id$ # # Copyright (c) 2007-2009 the eisfair team, team(at)eisfair(dot)org # Maintained by Y. Schumann, yves(at)eisfair(dot)org # Copyright (c) 2015-@@YEAR@@ Holger Bruenjes, holgerbruenjes(at)gmx(dot)net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # include config . /etc/config.d/phpmyadmin # include eislib . /var/install/include/eislib # include helper function . /var/install/bin/phpmyadmin-tools-helper #debug=true if ${debug:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi # --------------------------------------------------------------------------- # create the sql script and execute it # --------------------------------------------------------------------------- doDBOperation() { _server=${1} # check if entered server is active eval active='${PHPMYADMIN_SERVER_'${_server}'_ACTIVE}' if [ "${active}" = "yes" ] then # check if advanced features are activated eval advancedFeaturesActive='${PHPMYADMIN_SERVER_'${_server}'_ADVANCED_FEATURES}' if [ "${advancedFeaturesActive}" == "yes" ] then eval host='${PHPMYADMIN_SERVER_'${_server}'_HOST}' eval port='${PHPMYADMIN_SERVER_'${_server}'_PORT}' eval pmadb='${PHPMYADMIN_SERVER_'${_server}'_PMADB}' eval controluser='${PHPMYADMIN_SERVER_'${_server}'_CONTROLUSER}' eval controlpass='${PHPMYADMIN_SERVER_'${_server}'_CONTROLPASS}' case "${host}" in localhost|127.0.0.1) get_defaults check_status ;; *) mysql_basedir="$(dirname $(which mysql))" get_passwd ;; esac echo mecho "Please enter host from which the pma user accesses server '${host}'." _ask_tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) ${ASK} "Normally this should be the IP or FQDN of this machine:" "" "+" > ${_ask_tmpfile} rc=${?} read pmaHost < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then exit 127 fi # pmaHost=`/var/install/bin/ask "Normally this should be the IP or FQDN of this machine: " "" "+"` mecho mecho -n "Setting rights for pma user '" mecho -n --info "${controluser}@${pmaHost}" mecho -n "' on server '" mecho -n --info "${host}" mecho "'." mecho "If the pma user is not existing, it will be created." _ask_tmpfile=$(${MKTEMP} -t .XXXXXXXXXXXXX) ${ASK} "Continue" "y" > ${_ask_tmpfile} rc=${?} read executeSQL < ${_ask_tmpfile} ${RM} -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then exit 127 fi # executeSQLScript=`/var/install/bin/ask "Continue" "y"` if [ "${executeSQL}" = "yes" ] then ${mysql_basedir}/mysql \ -h ${host} \ -u ${admin_user} ${admin_pass} \ -e "GRANT SELECT, INSERT, DELETE, UPDATE ON \ ${pmadb}.* TO '${controluser}'@'${pmaHost}' \ IDENTIFIED BY '${controlpass}';FLUSH PRIVILEGES;" print_result ${?} else mecho "Creation of pma user canceled" fi else # advanced features not activated mecho mecho --info "Advanced features on server ${_server} not active" mecho fi # end of advanced features active check else # given server number is not active mecho mecho --info "Server ${_server} is not active" mecho fi # end of server active check anykey } # --------------------------------------------------------------------------- # select server # --------------------------------------------------------------------------- select_server() { clrhome mecho mecho "This script will create or alter the pma database user. To do" mecho "this you have to choose one of the available servers and enter name" mecho "and password of a user with admin rights on the choosen server." mecho list_configured_servers case ${server} in '') exit 0 ;; 0) exit 127 ;; *) doDBOperation ${server} select_server ;; esac } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- main() { select_server exit 0 } # --------------------------------------------------------------------------- # call function main # --------------------------------------------------------------------------- main "${@}" # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------