summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rwxr-xr-xserver/bin/addtodhcp4
-rwxr-xr-xserver/bin/comparedhcpopengnsys4
-rwxr-xr-xserver/bin/comparemac4
-rwxr-xr-xserver/bin/listclientlive4
-rwxr-xr-xserver/bin/listclientmode6
-rwxr-xr-xserver/bin/ogagentqueue.cron4
-rwxr-xr-xserver/bin/setclientlive4
-rwxr-xr-xserver/bin/setserveraddr8
-rwxr-xr-xserver/lib/checkrest4
-rwxr-xr-xserver/lib/ogfunctions.sh12
-rwxr-xr-xserver/lib/supportsave4
11 files changed, 35 insertions, 23 deletions
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.
diff --git a/server/lib/checkrest b/server/lib/checkrest
index 3fcd8bd1..c88ff53d 100755
--- a/server/lib/checkrest
+++ b/server/lib/checkrest
@@ -12,7 +12,7 @@
PROG=$(basename "$0")
OPENGNSYS=/opt/opengnsys
-CONFIGFILE=$OPENGNSYS/etc/ogserver.cfg
+CONFIGFILE=$OPENGNSYS/etc/ogserver.json
RESTURL="https://localhost/opengnsys/rest"
source $OPENGNSYS/lib/ogfunctions.sh || exit 1
@@ -128,7 +128,7 @@ function runtests () {
# Check dependencies.
which jq &>/dev/null || raiseError notfound "Need to install \"jq\"."
-source $CONFIGFILE
+source_json_config $CONFIGFILE
deletedata
loaddata
runtests
diff --git a/server/lib/ogfunctions.sh b/server/lib/ogfunctions.sh
index 30da3107..cf701925 100755
--- a/server/lib/ogfunctions.sh
+++ b/server/lib/ogfunctions.sh
@@ -110,6 +110,18 @@ function jq() {
echo "$OUTPUT"
}
+function source_json_config() {
+ FILE=$1
+ export ServidorAdm=$(jq -r ".rest.ip" $FILE)
+ export PUERTO=$(jq -r ".rest.port" $FILE)
+ export APITOKEN=$(jq -r ".rest.api_token" $FILE)
+ export USUARIO=$(jq -r ".database.user" $FILE)
+ export PASSWORD=$(jq -r ".database.pass" $FILE)
+ export datasource=$(jq -r ".database.ip" $FILE)
+ export CATALOG=$(jq -r ".database.name" $FILE)
+ export INTERFACE=$(jq -r ".wol.interface" $FILE)
+}
+
# Private function to acts on a service (do not use directly).
function _service() {
local ACTION="$1"
diff --git a/server/lib/supportsave b/server/lib/supportsave
index 8d5c2dd9..5a20545d 100755
--- a/server/lib/supportsave
+++ b/server/lib/supportsave
@@ -180,9 +180,9 @@ fi
echo "- Directory list"
ls -Ral ${home_dir} >> $backup_dir/opengnsys_files.txt 2>&1
-if [ -r ${home_dir}/etc/ogserver.cfg ]; then
+if [ -r ${home_dir}/etc/ogserver.json ]; then
echo "- Database schema"
- source ${home_dir}/etc/ogserver.cfg
+ source_json_config ${home_dir}/etc/ogserver.json
mysqldump -u "$USUARIO" -p"$PASSWORD" -d "$CATALOG" >> ${backup_dir}/opengnsys_schema.sql 2>&1
else
echo "- WARNING: The OpenGnsys database can not be accessed" | tee ${backup_dir}/db_schema.txt