diff --git a/composer.json b/composer.json index 5938ea5..6cc0b77 100644 --- a/composer.json +++ b/composer.json @@ -4,60 +4,59 @@ "minimum-stability": "stable", "prefer-stable": true, "require": { - "php": ">=7.2.5", + "php": ">=7.2.0", "ext-ctype": "*", "ext-iconv": "*", - "doctrine/annotations": "^2.0", - "doctrine/doctrine-bundle": "^2.11", - "doctrine/doctrine-migrations-bundle": "^3.3", - "doctrine/orm": "^2.17", - "phpdocumentor/reflection-docblock": "^5.3", - "phpstan/phpdoc-parser": "^1.24", - "zircote/swagger-php": "dev-master", - "symfony/asset": "5.4.*", - "symfony/console": "5.4.*", - "symfony/doctrine-messenger": "5.4.*", - "symfony/dotenv": "5.4.*", - "symfony/expression-language": "5.4.*", - "symfony/flex": "^1.17|^2", - "symfony/form": "5.4.*", - "symfony/framework-bundle": "5.4.*", - "symfony/http-client": "5.4.*", - "symfony/intl": "5.4.*", - "symfony/mailer": "5.4.*", - "symfony/mime": "5.4.*", + "doctrine/annotations": "^1.6", + "doctrine/doctrine-bundle": "^2.0", + "doctrine/doctrine-migrations-bundle": "^3.0", + "doctrine/orm": "^2.7", + "phpdocumentor/reflection-docblock": "^5.0", + "phpstan/phpdoc-parser": "^0.4", + "zircote/swagger-php": "3.*", + "symfony/runtime": "5.*", + "symfony/asset": "5.*", + "symfony/console": "5.*", + "symfony/doctrine-messenger": "5.*", + "symfony/dotenv": "5.*", + "symfony/expression-language": "5.*", + "symfony/flex": "^1.17", + "symfony/form": "5.*", + "symfony/framework-bundle": "5.*", + "symfony/http-client": "5.*", + "symfony/intl": "5.*", + "symfony/mailer": "5.*", + "symfony/mime": "5.*", "symfony/monolog-bundle": "^3.0", - "symfony/notifier": "5.4.*", - "symfony/process": "5.4.*", - "symfony/property-access": "5.4.*", - "symfony/property-info": "5.4.*", - "symfony/runtime": "5.4.*", - "symfony/security-bundle": "5.4.*", - "symfony/serializer": "5.4.*", - "symfony/string": "5.4.*", - "symfony/translation": "5.4.*", - "symfony/twig-bundle": "5.4.*", - "symfony/validator": "5.4.*", - "symfony/web-link": "5.4.*", - "symfony/yaml": "5.4.*", + "symfony/notifier": "5.*", + "symfony/process": "5.*", + "symfony/property-access": "5.*", + "symfony/property-info": "5.*", + "symfony/security-bundle": "5.*", + "symfony/serializer": "5.*", + "symfony/string": "5.*", + "symfony/translation": "5.*", + "symfony/twig-bundle": "5.*", + "symfony/validator": "5.*", + "symfony/web-link": "5.*", + "symfony/yaml": "5.*", "twig/extra-bundle": "^2.12|^3.0", "twig/twig": "^2.12|^3.0" }, "require-dev": { - "phpunit/phpunit": "^9.5", - "symfony/browser-kit": "5.4.*", - "symfony/css-selector": "5.4.*", - "symfony/debug-bundle": "5.4.*", + "phpunit/phpunit": "^8.5", + "symfony/browser-kit": "5.*", + "symfony/css-selector": "5.*", + "symfony/debug-bundle": "5.*", "symfony/maker-bundle": "^1.0", - "symfony/phpunit-bridge": "^7.0", - "symfony/stopwatch": "5.4.*", - "symfony/web-profiler-bundle": "5.4.*" + "symfony/phpunit-bridge": "^5.0", + "symfony/stopwatch": "5.*", + "symfony/web-profiler-bundle": "5.*" }, "config": { "allow-plugins": { "composer/package-versions-deprecated": true, - "symfony/flex": true, - "symfony/runtime": true + "symfony/flex": true }, "optimize-autoloader": true, "preferred-install": { @@ -98,7 +97,7 @@ "extra": { "symfony": { "allow-contrib": false, - "require": "5.4.*" + "require": "5.*" } } } diff --git a/etc/apache.conf.tmpl b/etc/apache.conf.tmpl new file mode 100644 index 0000000..9cb8589 --- /dev/null +++ b/etc/apache.conf.tmpl @@ -0,0 +1,25 @@ +# OpenGnsys ogdhcp configuration for Apache. + +Alias /opengnsys3/rest OGHDPCDIR + +# PHP-FPM configuration + + + SetHandler "proxy:fcgi://127.0.0.1:9000" + + + +RewriteEngine On + +# Default configuration. + + Require all granted + Options -Indexes +FollowSymLinks + DirectoryIndex index.php + AddType octet/stream .pkg + Header set Access-Control-Allow-Origin "*" + Header set Access-Control-Allow-Methods "GET,POST,OPTIONS,DELETE,PUT" + Header set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token" + FallbackResource /index.php + + diff --git a/installer/isc-kea-2.0.sh b/installer/isc-kea-2.0.sh new file mode 100755 index 0000000..7b6d79d --- /dev/null +++ b/installer/isc-kea-2.0.sh @@ -0,0 +1,571 @@ +#!/usr/bin/env bash +# +# The core commands execute start from the "MAIN" section below. +# + +test -z "$BASH_SOURCE" && { + self="sudo -E bash" + prefix=" |" +} || { + self=$(readlink -f ${BASH_SOURCE:-$0}) + prefix="" +} + +tmp_log=$(mktemp .csm_setup_XXXXXXXXX) + +colours=$(tput colors 2>/dev/null || echo "256") +no_colour="\e[39;49m" +green_colour="\e[32m" +red_colour="\e[41;97m" +bold="\e[1m" +reset="\e[0m" +use_colours=$(test -n "$colours" && test $colours -ge 8 && echo "yes") +test "$use_colours" == "yes" || { + no_colour="" + green_colour="" + red_colour="" + bold="" + reset="" +} + + +example_name="Ubuntu/Xenial (16.04)" +example_distro="ubuntu" +example_codename="xenial" +example_version="16.04" + + +function echo_helptext { + local help_text="$*" + echo " ^^^^: ... $help_text" +} + +function die { + local text="$@" + test ! -z "$text" && { + echo_helptext "$text" 1>&2 + } + + local prefix="${red_colour} !!!!${no_colour}" + + echo -e "$prefix: Oh no, your setup failed! :-( ... But we might be able to help. :-)" + echo -e "$prefix: " + echo -e "$prefix: ${bold}You can contact ISC - Internet Systems Consortium for further assistance.${reset}" + echo -e "$prefix: " + + echo -e "$prefix: ${bold}URL: https://www.isc.org${reset}" + echo -e "$prefix: " + + + test -f "$tmp_log" && { + local n=20 + echo -e "$prefix: Last $n log lines from $tmp_log (might not be errors, nor even relevant):" + echo -e "$prefix:" + check_tool_silent "xargs" && { + check_tool_silent "fmt" && { + tail -n $n $tmp_log | fmt -t | xargs -Ilog echo -e "$prefix: > log" + } || { + tail -n $n $tmp_log | xargs -Ilog echo -e "$prefix: > log" + } + } || { + echo + tail -n $n $tmp_log + } + } + exit 1 +} + +function echo_colour { + local colour="${1:-"no"}_colour"; shift + echo -e "${!colour}$@${no_colour}" +} + +function echo_green_or_red { + local rc="$1" + local good="${2:-YES}" + local bad="${3:-NO}" + + test "$rc" -eq 0 && { + echo_colour "green" "$good" + } || { + echo_colour "red" "$bad" + } + return $rc +} + +function echo_clearline { + local rc="$?" + echo -e -n "\033[1K\r" + return $rc +} + +function echo_status { + local rc="$1" + local good="$2" + local bad="$3" + local text="$4" + local help_text="$5" + local newline=$(test "$6" != "no" && echo "\n" || echo "") + local status_text=$(echo_green_or_red "$rc" "$good" "$bad") + + echo_clearline + local width=$(test "$use_colours" == "yes" && echo "16" || echo "5") + printf "%${width}s %s${newline}" "${status_text}:" "$text" + test $rc -ne 0 && test ! -z "$help_text" && { + echo_helptext "$help_text" + echo + } + + return $rc +} + +function echo_running { + local rc=$? + local text="$1" + echo_status 0 " RUN" " RUN" "$text" "" "no" + return $rc +} + +function echo_okfail_rc { + local rc=$1 + local text="$2" + local help_text="$3" + echo_clearline + echo_status $rc " OK" " NOPE" "$text" "$help_text" + return $rc +} + +function echo_okfail { + echo_okfail_rc $? "$@" + return $? +} + +function check_tool_silent { + local tool=${1} + command -v $tool &>/dev/null || which $tool &>/dev/null + return $? +} + +function check_tool { + local tool=${1} + local optional=${2:-false} + local required_text="optional" + if ! $optional; then required_text="required"; fi + local text="Checking for $required_text executable '$tool' ..." + echo_running "$text" + check_tool_silent "$tool" + echo_okfail "$text" || { + if ! $optional; then + die "$tool is not installed, but is required by this script." + fi + return 1 + } + return 0 +} + +function cleanup { + echo + + + rm -rf $tmp_log +} + +function shutdown { + echo_colour "red" " !!!!: Operation cancelled by user!" + exit 2 +} + + + +function check_os { + test ! -z "$distro" && test ! -z "${version}${codename}" + return $? +} + +function detect_os_system { + check_os && return 0 + echo_running "$text" + local text="Detecting your OS distribution and release using system methods ..." + + local tool_rc=1 + test -f '/etc/os-release' && { + . /etc/os-release + distro=${distro:-$ID} + codename=${codename:-$VERSION_CODENAME} + codename=${codename:-$(echo $VERSION | cut -d '(' -f 2 | cut -d ')' -f 1)} + version=${version:-$VERSION_ID} + + test -z "${version}${codename}" && test -f '/etc/debian_version' && { + # Workaround for Debian unstable releases; get the codename from debian_version + codename=$(cat /etc/debian_version | cut -d '/' -f1) + } + + tool_rc=0 + } + + check_os + local rc=$? + echo_okfail_rc $rc "$text" + + test $tool_rc -eq 0 && { + report_os_expanded + } + + return $rc +} + +function report_os_attribute { + local name=$1 + local value=$2 + local coloured="" + echo -n "$name=" + test -z "$value" && { + echo -e -n "${red_colour}${no_colour} " + } || { + echo -e -n "${green_colour}${value}${no_colour} " + } +} + +function report_os_expanded { + echo_helptext "Detected/provided for your OS/distribution, version and architecture:" + echo " >>>>:" + report_os_values +} + +function report_os_values { + echo -n " >>>>: ... " + report_os_attribute "distro" $distro + report_os_attribute "version" $version + report_os_attribute "codename" $codename + report_os_attribute "arch" $arch + echo + echo " >>>>:" +} + +function detect_os_legacy_python { + check_os && return 0 + + local text="Detecting your OS distribution and release using legacy python ..." + echo_running "$text" + + IFS='' read -r -d '' script <<-'EOF' +from __future__ import unicode_literals, print_function +import platform; +info = platform.linux_distribution() or ('', '', ''); +for key, value in zip(('distro', 'version', 'codename'), info): + print("local guess_%s=\"%s\"\n" % (key, value.lower().replace(' ', ''))); +EOF + + local tool_rc=1 + check_tool_silent "python" && { + eval $(python -c "$script") + distro=${distro:-$guess_distro} + codename=${codename:-$guess_codename} + version=${version:-$guess_version} + tool_rc=$? + } + + check_os + local rc=$? + echo_okfail_rc $rc "$text" + + check_tool_silent "python" || { + echo_helptext "Python isn't available, so skipping detection method (hint: install python)" + } + + test $tool_rc -eq 0 && { + report_os + } + + return $rc +} + +function detect_os_modern_python { + check_os && return 0 + + check_tool_silent "python" && { + local text="Ensuring python-pip is installed ..." + echo_running "$text" + check_tool_silent "pip" + echo_okfail "$text" || { + local text="Checking if pip can be bootstrapped without get-pip ..." + echo_running "$text" + python -m ensurepip --default-pip &>$tmp_log + echo_okfail "$text" || { + local text="Installing pip via get-pip bootstrap ..." + echo_running "$text" + curl -1sLf https://bootstrap.pypa.io/get-pip.py 2>$tmp/log | python &>$tmp_log + echo_okfail "$text" || die "Failed to install pip!" + } + } + + # FIXME(ls): Install distro into a temporary virtualenv + local text="Installing 'distro' python library ..." + echo_running "$text" + python -c 'import distro' &>$tmp_log || python -m pip install distro &>$tmp_log + echo_okfail "$text" || die "Failed to install required 'distro' python library!" + } + + IFS='' read -r -d '' script <<-'EOF' +from __future__ import unicode_literals, print_function +import distro; +info = distro.linux_distribution(full_distribution_name=False) or ('', '', ''); +for key, value in zip(('distro', 'version', 'codename'), info): + print("local guess_%s=\"%s\"\n" % (key, value.lower().replace(' ', ''))); +EOF + + local text="Detecting your OS distribution and release using modern python ..." + echo_running "$text" + + local tool_rc=1 + check_tool_silent "python" && { + eval $(python -c "$script") + distro=${distro:-$guess_distro} + codename=${codename:-$guess_codename} + version=${version:-$guess_version} + tool_rc=$? + } + + check_os + local rc=$? + echo_okfail_rc $rc "$text" + + check_tool_silent "python" || { + echo_helptext "Python isn't available, so skipping detection method (hint: install python)" + } + + test $tool_rc -eq 0 && { + report_os_expanded + } + + return $rc +} + +function detect_os { + # Backwards compat for old distribution parameter names + distro=${distro:-$os} + codename=${codename:-$dist} + + arch=${arch:-$(arch || uname -m)} + + detect_os_system || + detect_os_legacy_python || + detect_os_modern_python + + (test -z "$distro" || test -z "${version}${codename}") && { + echo_okfail_rc "1" "Unable to detect your OS distribution and/or release!" + cat <>>>: + >>>>: The 'distro' value is required, and either 'version' or 'codename' values, + >>>>: or both. Without these, the install script cannot retrieve the correct + >>>>: configuration for this system. + >>>>: + >>>>: You can force this script to use a particular value by specifying distro, + >>>>: version, or codename via environment variable. E.g., to specify a distro + >>>>: such as $example_name, use the following: + >>>>: + >>>>: $prefix distro=$example_distro version=$example_version codename=$example_codename $self + >>>>: +EOF + die + } +} + + +function config_url { + echo "https://dl.cloudsmith.io/public/isc/kea-2-0/config.deb.txt?distro=${distro}&codename=${codename}&version=${version}&arch=${arch}" | sed 's/ /%20/g' +} + +function check_fetch_config { + local text="Checking if upstream install config is OK ..." + echo_running "$text" + local code="$(curl -1IsL -w "%{http_code}\\n" "$(config_url)" -o /dev/null --connect-timeout 15 --max-time 60)" + test "$code" == "200" && { + echo_okfail_rc 0 "$text" + return 0 + } || { + echo_okfail_rc 1 "$text" + echo_helptext "Failed to fetch configuration for your OS distribution release/version." + cat <>>>: +EOF + test "$code" == "404" && { + cat <>>>: It looks like we don't currently support your distribution release and + >>>>: version. This is something that we can fix by adding it to our list of + >>>>: supported versions (see contact us below), or you can manually override + >>>>: the values below to an equivalent distribution that we do support: + >>>>: +EOF + report_os_values + } || { + cat <>>>: It looks like it might be because the configuration endpoint is not + >>>>: currently available. Please try again in 10-15 minutes. If it still + >>>>: doesn't work after an hour, please contact ISC - Internet Systems Consortium + >>>>: for assistance. + >>>>: +EOF + } + + cat <>>>: You can force this script to use a particular value by specifying distro, + >>>>: version, or codename via environment variable. E.g., to specify a distro + >>>>: such as $example_name, use the following: + >>>>: + >>>>: $prefix distro=$example_distro version=$example_version codename=$example_codename $self + >>>>: +EOF + die + } +} + +function fetch_config { + curl -1sLf "$(config_url)" +} + + +function check_dpkg_tool { + local tool=${1} + local required=${2:-true} + local install=${3:-true} + + local text="Checking for apt dependency '$tool' ..." + echo_running "$text" + dpkg -l | grep "$tool\>" &>$tmp_log + echo_okfail "$text" || { + if $install; then + test "$apt_updated" == "yes" || update_apt + local text="Attempting to install '$tool' ..." + echo_running "$text" + apt-get install -y "$tool" &>$tmp_log + echo_okfail "$text" || { + if $required; then + die "Could not install '$tool', check your permissions, etc." + fi + } + else + if $required; then + die "$tool is not installed, but is required by this script." + fi + fi + } + return 0 +} + +function update_apt { + local text="Updating apt repository metadata cache ..." + local tmp_log=$(mktemp .csm_deb_output_XXXXXXXXX.log) + echo_running "$text" + apt-get update &>$tmp_log + echo_okfail "$text" || { + echo_colour "red" "Failed to update via apt-get update" + cat $tmp_log + rm -rf $tmp_log + die "Failed to update via apt-get update - Context above." + } + rm -rf $tmp_log + apt_updated="yes" +} + +function install_apt_prereqs { + # Debian-archive-keyring has to be installed for apt-transport-https. + test "${os}" == "debian" && { + check_dpkg_tool "debian-keyring" + check_dpkg_tool "debian-archive-keyring" + } + + check_dpkg_tool "apt-transport-https" + check_dpkg_tool "ca-certificates" false + check_dpkg_tool "gnupg" +} + +function import_gpg_key { + local text="Importing 'isc/kea-2-0' repository GPG keys ..." + echo_running "$text" + + local gpg_keyring_path="/usr/share/keyrings/isc-kea-2-0-archive-keyring.gpg" + + curl -1sLf "https://dl.cloudsmith.io/public/isc/kea-2-0/gpg.8029D4AFA58CBB5E.key" | gpg --dearmor >> $gpg_keyring_path + + local signed_by_version="1.1" + local detected_version=$(dpkg -s apt | grep Version | cut -d' ' -f2) + + [ "$(printf "%s\n" $detected_version $signed_by_version | sort -V | head -n 1)" == "$signed_by_version" ] + + echo_okfail "Checking for apt signed-by key support ..." || { + mv ${gpg_keyring_path} /etc/apt/trusted.gpg.d/isc-kea-2-0.gpg + } + + echo_okfail "$text" || die "Could not import the GPG key for this repository" +} + +function setup_repository { + local repo_path="/etc/apt/sources.list.d/isc-kea-2-0.list" + check_fetch_config + + local text="Installing 'isc/kea-2-0' repository via apt ..." + echo_running "$text" + fetch_config > "$repo_path" + echo_okfail "$text" || die "Could not install the repository, do you have permissions?" +} + + + +function usage () { + cat < -##################################################################### - -function globalSetup () -{ - PROGRAMDIR=$(readlink -e "$(dirname "$0")") - PROGRAMNAME=$(basename "$0") - - # Comprobar si se ha descargado el paquete comprimido (REMOTE=0) o sólo el instalador (REMOTE=1). - OPENGNSYS_SERVER="opengnsys.es" - if [ -d "$PROGRAMDIR/../installer" ]; then - echo REMOTE=0 - REMOTE=0 - else - echo REMOTE=1 - REMOTE=1 - fi - BRANCH=$1 - if [[ -z $BRANCH ]]; then - BRANCH="main" - fi - GIT_REPO="ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogdhcp.git" - - # Directorios de instalación y destino de OpenGnsys. - WORKDIR=/tmp/ogclient_installer - INSTALL_TARGET=/opt/ogclient - PATH=$PATH:$INSTALL_TARGET/bin - - # Registro de incidencias. - OGLOGFILE=$INSTALL_TARGET/log/${PROGRAMNAME%.sh}.log - LOG_FILE=/tmp/$(basename $OGLOGFILE) - -} - - - -# Función para instalar los paquetes necesarios para KEA-DHCP -install_kea() { - sudo apt-get install -y kea-dhcp4-server kea-dhcp6-server -} - -# Función para instalar PHP y las extensiones necesarias para Symfony -install_php() { - sudo apt-get install -y php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath -} - -# Función para instalar Composer -install_composer() { - curl -sS https://getcomposer.org/installer | php - sudo mv composer.phar /usr/local/bin/composer -} - -# Función para instalar Symfony -install_symfony() { - composer global require symfony - echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc - source ~/.bashrc -} - - -# Función para instalar Swagger UI -install_swagger() { - sudo apt-get install -y unzip - wget https://github.com/swagger-api/swagger-ui/archive/master.zip - unzip master.zip -d /var/www/html/ - sudo mv /var/www/html/swagger-ui-master /var/www/html/swagger-ui -} - -# Función para instalar el componente ogdhcp -install_ogdhcp() { - git clone - sudo mv ogdhcp /opt/ - cd /opt/ogdhcp - composer install -} - - -# Obtiene el código fuente del proyecto desde el repositorio de GitHub. -function downloadCode() -{ - if [ $# -ne 1 ]; then - errorAndLog "${FUNCNAME}(): invalid number of parameters" - exit 1 - fi - - local url="$1" - - echoAndLog "${FUNCNAME}(): downloading code from '$url'..." - - GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=accept-new" git archive --remote=$url --format zip --output opengnsys.zip --prefix=opengnsys/ $BRANCH && unzip opengnsys.zip - if [ $? -ne 0 ]; then - errorAndLog "${FUNCNAME}(): error getting OpenGnsys code from $url" - return 1 - fi - rm -f opengnsys.zip - echoAndLog "${FUNCNAME}(): code was downloaded" - return 0 -} - -# Crea la estructura base de la instalación de opengnsys -function createDirs() -{ - if [ $# -ne 1 ]; then - errorAndLog "${FUNCNAME}(): invalid number of parameters" - exit 1 - fi - - local path_opengnsys_base="$1" - - # Crear estructura de directorios. - echoAndLog "${FUNCNAME}(): creating directory paths in $path_opengnsys_base" - mkdir -p $path_opengnsys_base - mkdir -p $path_opengnsys_base/bin - mkdir -p $path_opengnsys_base/config - mkdir -p $path_opengnsys_base/docs # Swagger documentation - mkdir -p $path_opengnsys_base/public - mkdir -p $path_opengnsys_base/src - mkdir -p $path_opengnsys_base/templates - mkdir -p $path_opengnsys_base/var/{cache,log} - mkdir -p $path_opengnsys_base/vendor - if [ $? -ne 0 ]; then - errorAndLog "${FUNCNAME}(): error while creating dirs. Do you have write permissions?" - return 1 - fi - - # Crear usuario ficticio. - if id -u $OPENGNSYS_CLIENT_USER &>/dev/null; then - echoAndLog "${FUNCNAME}(): user \"$OPENGNSYS_CLIENT_USER\" is already created" - else - echoAndLog "${FUNCNAME}(): creating OpenGnsys user" - useradd $OPENGNSYS_CLIENT_USER 2>/dev/null - if [ $? -ne 0 ]; then - errorAndLog "${FUNCNAME}(): error creating OpenGnsys user" - return 1 - fi - fi - - # Mover el fichero de registro de instalación al directorio de logs. - echoAndLog "${FUNCNAME}(): moving installation log file" - mv $LOG_FILE $path_opengnsys_base/var/log && LOG_FILE=$path_opengnsys_base/var/log - chmod 600 $LOG_FILE - - echoAndLog "${FUNCNAME}(): directory paths created" - return 0 -} - - -##################################################################### -####### Algunas funciones útiles de propósito general: -##################################################################### - -function getDateTime() -{ - date "+%Y%m%d-%H%M%S" -} - -# Escribe a fichero y muestra por pantalla -function echoAndLog() -{ - local DATETIME=`getDateTime` - echo "$1" - echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE -} - -# Escribe a fichero y muestra mensaje de error -function errorAndLog() -{ - local DATETIME=`getDateTime` - echo "ERROR: $1" - echo "$DATETIME;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE -} - -# Escribe a fichero y muestra mensaje de aviso -function warningAndLog() -{ - local DATETIME=`getDateTime` - echo "Warning: $1" - echo "$DATETIME;$SSH_CLIENT;Warning: $1" >> $LOG_FILE -} - -########################################################################## -################################main###################################### - - -# Sólo ejecutable por usuario root -if [ "$(whoami)" != 'root' ]; then - echo "ERROR: this program must run under root privileges!!" - exit 1 -fi - - - -# Si es necesario, descarga el repositorio de código en directorio temporal -if [ $REMOTE -eq 1 ]; then - downloadCode $GIT_REPO - if [ $? -ne 0 ]; then - errorAndLog "Error while getting code from the repository" - exit 1 - fi -else - ln -fs "$(dirname $PROGRAMDIR)" opengnsys -fi - -globalSetup - -# Arbol de directorios de OpenGnsys. -createDirs ${INSTALL_TARGET} -if [ $? -ne 0 ]; then - errorAndLog "Error while creating directory paths!" - exit 1 -fi - - -sudo apt-get update -# install_kea -# install_php -# install_composer -# install_symfony -# install_swagger -# Ahora puedes clonar e instalar el componente ogDhcp -# git clone -# cd -# composer install - diff --git a/installer/ogdhcp_installer.sh b/installer/ogdhcp_installer.sh index 4212a91..8fb7e79 100755 --- a/installer/ogdhcp_installer.sh +++ b/installer/ogdhcp_installer.sh @@ -9,7 +9,7 @@ function globalSetup () { PROGRAMDIR=$(readlink -e "$(dirname "$0")") PROGRAMNAME=$(basename "$0") - + OPENGNSYS_CLIENT_USER="ogdhcp" # Comprobar si se ha descargado el paquete comprimido (REMOTE=0) o sólo el instalador (REMOTE=1). OPENGNSYS_SERVER="opengnsys.es" if [ -d "$PROGRAMDIR/../installer" ]; then @@ -29,7 +29,26 @@ function globalSetup () WORKDIR=/tmp/ogdhcp_installer INSTALL_TARGET=/opt/ogdhcp PATH=$PATH:$INSTALL_TARGET/bin - + if which service &>/dev/null; then + STARTSERVICE="eval service \$service restart" + STOPSERVICE="eval service \$service stop" + else + STARTSERVICE="eval /etc/init.d/\$service restart" + STOPSERVICE="eval /etc/init.d/\$service stop" + fi + ENABLESERVICE="eval update-rc.d \$service defaults" + DISABLESERVICE="eval update-rc.d \$service disable" + APACHESERV=apache2 + APACHECFGDIR=/etc/apache2 + APACHESITESDIR=sites-available + APACHEOGSITE=ogdhcp + APACHEUSER="www-data" + APACHEGROUP="www-data" + APACHEENABLEMODS="a2enmod headers ssl rewrite proxy_fcgi fastcgi actions alias" + APACHEENABLESSL="a2ensite default-ssl" + APACHEENABLEOG="a2ensite $APACHEENABLEOG" + APACHEMAKECERT="make-ssl-cert generate-default-snakeoil --force-overwrite" + PHPFPMSERV=php7.2-fpm # Registro de incidencias. OGLOGFILE=$INSTALL_TARGET/log/${PROGRAMNAME%.sh}.log LOG_FILE=/tmp/$(basename $OGLOGFILE) @@ -54,6 +73,25 @@ function checkDependencies() { echoAndLog "Dependencies checked." } +function checkDependencies() { + echoAndLog "Checking dependencies..." + + # Lista de dependencias + local DEPENDENCIES=(php php-cli php-fpm php-json php-pdo php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath composer unzip apache2 libapache2-mod-php) + + # Comprobar cada dependencia + for dep in "${DEPENDENCIES[@]}"; do + if ! dpkg -s $dep >/dev/null 2>&1; then + echoAndLog "$dep is not installed. Installing..." + sudo apt-get install -y $dep + else + echoAndLog "$dep is already installed." + fi + done + + echoAndLog "Dependencies checked." +} + # Instalar dependencias para Symfony y Swagger function install_symfony_swagger_dependencies() { @@ -76,7 +114,7 @@ function install_apache_dependencies() { # Función para instalar los paquetes necesarios para KEA-DHCP install_kea() { - sudo apt-get install -y kea-dhcp4-server kea-dhcp6-server + sudo apt-get install -y isc-kea-common isc-kea-ctrl-agent isc-kea-dhcp4-server isc-kea-dhcp6-server isc-kea-admin } # Función para instalar PHP y las extensiones necesarias para Symfony @@ -106,14 +144,6 @@ install_swagger() { sudo mv /var/www/html/swagger-ui-master /var/www/html/swagger-ui } -# Función para instalar el componente ogdhcp -install_ogdhcp() { - git clone - sudo mv ogdhcp /opt/ - cd /opt/ogdhcp - composer install -} - # Obtiene el código fuente del proyecto desde el repositorio de GitHub. function downloadCode() @@ -155,6 +185,7 @@ function createDirs() mkdir -p $path_opengnsys_base/docs # Swagger documentation mkdir -p $path_opengnsys_base/public mkdir -p $path_opengnsys_base/src + mkdir -p $path_opengnsys_base/src mkdir -p $path_opengnsys_base/templates mkdir -p $path_opengnsys_base/var/{cache,log} mkdir -p $path_opengnsys_base/vendor @@ -175,13 +206,16 @@ function createDirs() fi fi + # Mover el fichero de registro de instalación al directorio de logs. echoAndLog "${FUNCNAME}(): moving installation log file" - mv $LOG_FILE $path_opengnsys_base/var/log && LOG_FILE=$path_opengnsys_base/var/log - chmod 600 $LOG_FILE + mv $LOG_FILE $path_opengnsys_base/var/log && LOG_FILE=$OGLOGFILE + chmod 777 $LOG_FILE echoAndLog "${FUNCNAME}(): directory paths created" return 0 + echoAndLog "Changing user permission" + chown -R $OPENGNSYS_CLIENT_USER:$OPENGNSYS_CLIENT_USER $INSTALL_TARGET } @@ -199,6 +233,7 @@ function copyServerFiles () config \ public \ src \ + etc \ templates \ tests \ vendor \ @@ -211,6 +246,7 @@ function copyServerFiles () config \ public \ src \ + etc \ templates \ tests \ vendor \ @@ -241,10 +277,125 @@ function copyServerFiles () warningAndLog "Unable to copy ${SOURCES[$i]} to $path_opengnsys_base/${TARGETS[$i]}" fi done + echoAndLog "Changing user permission" + chown -R $OPENGNSYS_CLIENT_USER:$OPENGNSYS_CLIENT_USER $INSTALL_TARGET + popd } +function downloadComposer() { + echoAndLog "Downloading composer.phar..." + + # Crear el directorio de trabajo si no existe + mkdir -p $WORKDIR/ogdhcp/bin + + # Cambiar al directorio de trabajo + pushd $WORKDIR/ogdhcp/bin + + # Descargar composer.phar + curl -sS https://getcomposer.org/installer | php + + # Comprobar si la descarga fue exitosa + if [ ! -f composer.phar ]; then + errorAndLog "Failed to download composer.phar" + popd + return 1 + fi + + # Crear el directorio de destino si no existe + mkdir -p /opt/ogdhcp/bin + + # Mover composer.phar a /opt/ogdhcp/bin + mv composer.phar /opt/ogdhcp/bin/ + + # Comprobar si el movimiento fue exitoso + if [ ! -f /opt/ogdhcp/bin/composer.phar ]; then + errorAndLog "Failed to move composer.phar to /opt/ogdhcp/bin" + popd + return 1 + fi + + # Volver al directorio original + popd + + echoAndLog "composer.phar downloaded and moved to /opt/ogdhcp/bin" + return 0 +} + +function runComposer() { + echoAndLog "Running composer.phar to install dependencies..." + + # Cambiar al directorio donde está composer.phar + pushd /opt/ogdhcp/bin + + # Ejecutar composer.phar + sudo -u $OPENGNSYS_CLIENT_USER php composer.phar install + + # Comprobar si la ejecución fue exitosa + if [ $? -ne 0 ]; then + errorAndLog "Failed to run composer.phar" + popd + return 1 + fi + + # Volver al directorio original + popd + + echoAndLog "composer.phar ran successfully and dependencies were installed" + return 0 +} + +function installWebConsoleApacheConf() +{ + if [ $# -ne 2 ]; then + errorAndLog "${FUNCNAME}(): invalid number of parameters" + exit 1 + fi + + local path_opengnsys_base="$1" + local path_apache2_confd="$2" + local OGHDPCDIR=${path_opengnsys_base}/public + local sockfile + + if [ ! -d $path_apache2_confd ]; then + errorAndLog "${FUNCNAME}(): path to apache2 conf.d can not found, verify your server installation" + return 1 + fi + + mkdir -p $path_apache2_confd/{sites-available,sites-enabled} + + echoAndLog "${FUNCNAME}(): creating apache2 config file.." + + # Avtivar PHP-FPM. + echoAndLog "${FUNCNAME}(): configuring PHP-FPM" + service=$PHPFPMSERV + $ENABLESERVICE; $STARTSERVICE + sockfile=$(find /run/php -name "php*.sock" -type s -print 2>/dev/null | tail -1) + + # Activar módulos de Apache. + $APACHEENABLEMODS + + # Genera configuración de consola web a partir del fichero plantilla. + if [ -n "$sockfile" ]; then + sed -e "s,OGHDPCDIR,$OGHDPCDIR,g" \ + -e "s,proxy:fcgi:.*,proxy:unix:${sockfile%% *}|fcgi://localhost\",g" \ + $WORKDIR/ogdhcp/etc/apache.conf.tmpl > $path_apache2_confd/$APACHESITESDIR/${APACHEOGSITE}.conf + else + sed -e "s,OGHDPCDIR,$OGHDPCDIR,g" \ + $WORKDIR/ogdhcp/server/etc/apache.conf.tmpl > $path_apache2_confd/$APACHESITESDIR/${APACHEOGSITE}.conf + fi + $APACHEENABLEOG + if [ $? -ne 0 ]; then + errorAndLog "${FUNCNAME}(): config file can't be linked to apache conf, verify your server installation" + return 1 + fi + echoAndLog "${FUNCNAME}(): config file created and linked, restarting apache daemon" + service=$APACHESERV + $ENABLESERVICE; $STARTSERVICE + return 0 +} + ##################################################################### ####### Algunas funciones útiles de propósito general: @@ -260,6 +411,7 @@ function echoAndLog() { local DATETIME=`getDateTime` echo "$1" + echo $LOG_FILE echo "$DATETIME;$SSH_CLIENT;$1" >> $LOG_FILE } @@ -289,8 +441,15 @@ if [ "$(whoami)" != 'root' ]; then exit 1 fi +globalSetup +echoAndLog "OpenGnsys installation begins at $(date)" +mkdir -p $WORKDIR +pushd $WORKDIR + +checkDependencies +install_kea # Si es necesario, descarga el repositorio de código en directorio temporal if [ $REMOTE -eq 1 ]; then downloadCode $GIT_REPO @@ -299,15 +458,9 @@ if [ $REMOTE -eq 1 ]; then exit 1 fi else - ln -fs "$(dirname $PROGRAMDIR)" opengnsys + ln -fs "$(dirname $PROGRAMDIR)" ogdhcp fi -globalSetup - -echoAndLog "OpenGnsys installation begins at $(date)" - -mkdir -p $WORKDIR -pushd $WORKDIR # Arbol de directorios de OpenGnsys. createDirs ${INSTALL_TARGET} @@ -323,6 +476,17 @@ if [ $? -ne 0 ]; then exit 1 fi +downloadComposer + +runComposer + +# Creando configuración de Apache. +installWebConsoleApacheConf $INSTALL_TARGET $APACHECFGDIR +if [ $? -ne 0 ]; then + errorAndLog "Error configuring Apache for OpenGnsys Admin" + exit 1 +fi + sudo apt-get update # install_kea # install_php diff --git a/installer/uninstall_php.sh b/installer/uninstall_php.sh new file mode 100755 index 0000000..4ee0863 --- /dev/null +++ b/installer/uninstall_php.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +function purge_php_packages { + PACKAGES=(libapache2-mod-php php php-bcmath php-cli php-cli-prompt php-common php-composer-ca-bundle php-composer-semver php-composer-spdx-licenses php-curl php-fpm php-gd php-json php-json-schema php-mbstring php-mysql php-pear php-psr-log php-symfony-console php-symfony-debug php-symfony-filesystem php-symfony-finder php-symfony-polyfill-mbstring php-symfony-process php-xml php-zip php7.2 php7.2-bcmath php7.2-cli php7.2-common php7.2-curl php7.2-fpm php7.2-gd php7.2-json php7.2-mbstring php7.2-mysql php7.2-opcache php7.2-readline php7.2-xml php7.2-zip) + + for PACKAGE in "${PACKAGES[@]}" + do + sudo apt-get purge -y $PACKAGE + done +} + +# Call the function +purge_php_packages + +# Verify that all PHP packages have been removed +dpkg --get-selections | grep -i php diff --git a/public/swagger-initializer.js b/public/swagger-initializer.js index f5b63ea..837ff5f 100644 --- a/public/swagger-initializer.js +++ b/public/swagger-initializer.js @@ -3,7 +3,7 @@ window.onload = function() { // the following lines will be replaced by docker/configurator, when it runs in a docker-container window.ui = SwaggerUIBundle({ - url: "http://localhost:8001/swagger.json", + url: "http://192.168.0.27:8080/swagger.json", dom_id: '#swagger-ui', deepLinking: true, presets: [