From 4972d15ecd21a6f8dfe6f8451d19ac678fa2865b Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Mon, 19 Oct 2020 13:38:11 +0200 Subject: #988 Read json config file in scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch implements the function source_json_config() that is used to read the new ogserver.json config file in the scripts. This replaces the old 'source .../ogserver.cfg'. Co-authored-by: Javier Sánchez Parra --- server/bin/addtodhcp | 4 ++-- server/bin/comparedhcpopengnsys | 4 ++-- server/bin/comparemac | 4 ++-- server/bin/listclientlive | 4 ++-- server/bin/listclientmode | 6 ++---- server/bin/ogagentqueue.cron | 4 ++-- server/bin/setclientlive | 4 ++-- server/bin/setserveraddr | 8 +++++--- 8 files changed, 19 insertions(+), 19 deletions(-) (limited to 'server/bin') diff --git a/server/bin/addtodhcp b/server/bin/addtodhcp index 42fe7f8e..80fc5fac 100755 --- a/server/bin/addtodhcp +++ b/server/bin/addtodhcp @@ -15,7 +15,7 @@ # Variables. PROG="$(basename "$0")" OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} -SERVERCONF=$OPENGNSYS/etc/ogserver.cfg +SERVERCONF=$OPENGNSYS/etc/ogserver.json DHCPCONF=/etc/dhcp/dhcpd.conf DHCPCONFBCK="$DHCPCONF-$(date +"%Y%m%d")" @@ -26,7 +26,7 @@ source $OPENGNSYS/lib/ogfunctions.sh || exit 1 [ "$*" == "version" ] && version # Error control. [ "$USER" != "root" ] && raiseError access "Need to be root" -source $SERVERCONF 2>/dev/null || raiseError access "Cannot read OpenGnsys Server configuration file" +source_json_config $SERVERCONF 2>/dev/null || raiseError access "Cannot read OpenGnsys Server configuration file" # Processing parameters. opts=$(getopt -n "$PROG" -l exam,file:,restart -o 'ef:r' -- "$@" ) || raiseError usage diff --git a/server/bin/comparedhcpopengnsys b/server/bin/comparedhcpopengnsys index b4743e42..64ccfbdc 100755 --- a/server/bin/comparedhcpopengnsys +++ b/server/bin/comparedhcpopengnsys @@ -16,7 +16,7 @@ PROG="$(basename "$0")" OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} -SERVERCONF=$OPENGNSYS/etc/ogserver.cfg +SERVERCONF=$OPENGNSYS/etc/ogserver.json DHCPFILE=${DHCPFILE:-/etc/dhcp/dhcpd.conf} TMP_DHCP=/tmp/$PROG-dhcp$$ TMP_MYSQL=/tmp/$PROG-mysql$$ @@ -29,7 +29,7 @@ source $OPENGNSYS/lib/ogfunctions.sh || exit 1 [ -r $DHCPFILE ] || raiseError access "No tenemos acceso al fichero de configuracion del dhcp" # Obtener datos de acceso a la Base de datos. -source $SERVERCONF 2> /dev/null || raiseError access "Fichero de configuración del servidor" +source_json_config $SERVERCONF 2> /dev/null || raiseError access "Fichero de configuración del servidor" trap "rm -f $TMP_DHCP $TMP_MYSQL" 1 2 3 9 15 # Genero fichero temporal de dhcp recorriendo la configuración del dhcp cadena a cadena. diff --git a/server/bin/comparemac b/server/bin/comparemac index 6b1c6eff..7d893ec7 100755 --- a/server/bin/comparemac +++ b/server/bin/comparemac @@ -12,7 +12,7 @@ # Variables. OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} -SERVERCONF=$OPENGNSYS/etc/ogserver.cfg +SERVERCONF=$OPENGNSYS/etc/ogserver.json # Funciones globales. source $OPENGNSYS/lib/ogfunctions.sh || exit 1 @@ -26,7 +26,7 @@ source $OPENGNSYS/lib/ogfunctions.sh || exit 1 which arp-scan &>/dev/null || raiseError notfound "Need to install \"arp-scan\"" # Obtener datos de acceso a la base de datos. -source $SERVERCONF +source_json_config $SERVERCONF # Borrar ficheros temporales si termina el proceso. trap "rm -f $TMPSQL $TMPSCAN" 0 1 2 3 6 9 15 diff --git a/server/bin/listclientlive b/server/bin/listclientlive index 0e7f1c4a..d8104d7a 100755 --- a/server/bin/listclientlive +++ b/server/bin/listclientlive @@ -12,7 +12,7 @@ # Variables. OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} -SERVERCONF=$OPENGNSYS/etc/ogserver.cfg +SERVERCONF=$OPENGNSYS/etc/ogserver.json TFTPDIR=$OPENGNSYS/tftpboot source $OPENGNSYS/lib/ogfunctions.sh || exit 1 @@ -22,7 +22,7 @@ source $OPENGNSYS/lib/ogfunctions.sh || exit 1 [ "$*" == "version" ] && version [ $# -eq 1 ] || raiseError usage [ "$USER" != "root" ] && raiseError access "Need to be root" -source $SERVERCONF 2>/dev/null || raiseError access "Sin acceso a fichero de configuración" +source_json_config $SERVERCONF 2>/dev/null || raiseError access "Sin acceso a fichero de configuración" # Sustituir caracteres ' por \' para evitar inyección SQL. RESOURCE="${1//\'/\\\'}" diff --git a/server/bin/listclientmode b/server/bin/listclientmode index d4bac228..656ece99 100755 --- a/server/bin/listclientmode +++ b/server/bin/listclientmode @@ -15,7 +15,7 @@ # Variables. OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} -SERVERCONF=$OPENGNSYS/etc/ogserver.cfg +SERVERCONF=$OPENGNSYS/etc/ogserver.json TMPLDIR=$OPENGNSYS/tftpboot/menu.lst/templates source $OPENGNSYS/lib/ogfunctions.sh || exit 1 @@ -25,10 +25,8 @@ source $OPENGNSYS/lib/ogfunctions.sh || exit 1 [ "$*" == "version" ] && version [ $# -eq 1 ] || raiseError usage [ "$USER" != "root" ] && raiseError access "Need to be root" -source $SERVERCONF 2>/dev/null || raiseError access "Sin acceso a fichero de configuración" +source_json_config $SERVERCONF 2>/dev/null || raiseError access "Sin acceso a fichero de configuración" -# Obtener datos de acceso a la Base de datos. -source $SERVERCONF # Sustituir caracteres ' por \' para evitar inyección SQL. RESOURCE="${1//\'/\\\'}" # Obtener nombre de ordenador individual o todos los de una aula e indicar su plantilla asociada. diff --git a/server/bin/ogagentqueue.cron b/server/bin/ogagentqueue.cron index 16f7c67e..80dc2a84 100755 --- a/server/bin/ogagentqueue.cron +++ b/server/bin/ogagentqueue.cron @@ -13,13 +13,13 @@ # Variables. PROG=$(basename "$0") OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} -SERVERCONF=$OPENGNSYS/etc/ogserver.cfg +SERVERCONF=$OPENGNSYS/etc/ogserver.json LOGFILE=$OPENGNSYS/log/remotepc.log source $OPENGNSYS/lib/ogfunctions.sh || exit 1 # Basic error control -source $SERVERCONF 2> /dev/null || raiseError access "Server configuration file" +source_json_config $SERVERCONF 2> /dev/null || raiseError access "Server configuration file" touch "$LOGFILE" 2> /dev/null || raiseError access "Cannot write in the log file" # Reading pending operations. diff --git a/server/bin/setclientlive b/server/bin/setclientlive index 0424e605..64eedabf 100755 --- a/server/bin/setclientlive +++ b/server/bin/setclientlive @@ -17,7 +17,7 @@ PROG="$(basename "$0")" OPENGNSYS=${OPENGNSYS:-"/opt/opengnsys"} PATH=$PATH:$OPENGNSYS/bin -SERVERCONF=$OPENGNSYS/etc/ogserver.cfg +SERVERCONF=$OPENGNSYS/etc/ogserver.json TFTPDIR=$OPENGNSYS/tftpboot LOGFILE=$OPENGNSYS/log/opengnsys.log @@ -28,7 +28,7 @@ source $OPENGNSYS/lib/ogfunctions.sh || exit 1 [ "$*" == "version" ] && version [ $# -eq 2 ] || raiseError usage [ "$USER" != "root" ] && raiseError access "Need to be root" -source $SERVERCONF 2>/dev/null || raiseError access "Sin acceso a fichero de configuración" +source_json_config $SERVERCONF 2>/dev/null || raiseError access "Sin acceso a fichero de configuración" case "$1" in [0-9]*) DIR=$(oglivecli search $1 2>/dev/null) ;; diff --git a/server/bin/setserveraddr b/server/bin/setserveraddr index b5092ae5..b9249af7 100755 --- a/server/bin/setserveraddr +++ b/server/bin/setserveraddr @@ -33,7 +33,7 @@ source $OPENGNSYS/lib/ogfunctions.sh || exit 1 [ "$USER" != "root" ] && raiseError access "Need to be root" [ $# -ne 1 ] && raiseError usage [ -r $DEFAULTFILE ] || raiseError access "Cannot read default configuration file" -for f in $OPENGNSYS/{etc/{ogserver,ogAdmRepo}.cfg,www/controlacceso.php,client/ogClient/cfg/ogclient.json}; do +for f in $OPENGNSYS/{etc/ogserver.json,etc/ogAdmRepo.cfg,www/controlacceso.php,client/ogClient/cfg/ogclient.json}; do [ -w $f ] || raiseError access "Cannot write to file: $f" done @@ -84,15 +84,17 @@ if [ -n "$SERVERIP" ]; then fi # Saving old IP address. - source $OPENGNSYS/etc/ogserver.cfg + source_json_config $OPENGNSYS/etc/ogserver.json OLDSERVERIP=$ServidorAdm # Checking if configuration files need to be modified. CHANGE=0 - for f in $OPENGNSYS/{etc/{ogserver,ogAdmRepo}.cfg,www/controlacceso.php}; do + for f in $OPENGNSYS/{etc/ogserver.json,etc/ogAdmRepo.cfg,www/controlacceso.php}; do # Updating configuration variables (if URL does not contain "localhost"). sed -e "s,\(ServidorAdm\|IPlocal\)=.*,\1=$SERVERIP," \ -e "s,^INTERFACE=.*,INTERFACE=$SERVERDEV," \ -e "s,UrlMenu=https?://\([^/]*\)/\(.*\),UrlMenu=https://$SERVERIP/\2," \ + -e "s/\"ip\": \".*\"/\"ip\": \"$SERVERIP\"/" $SERVERCFG \ + -e "s/\"interface\": \".*\"/\"interface\": \"$SERVERDEV\"/" $SERVERCFG \ -e '/localhost/!s,https\?://[^/]*/\(.*\),https://'$SERVERIP'/\1,' $f >$tmpfile file="${f/./-$SERVERDEV.}" # Copying updated file, if needed. -- cgit v1.2.3-18-g5258