From 6f6fb58a920dfec6a08f6ddf2b2d6cd8a950ddee Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 16 Jan 2019 14:06:38 +0100 Subject: [PATCH 01/54] Update upgrade to import template --- scripts/upgrade | 67 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index e3c7182..ef6b34c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -51,6 +51,66 @@ if [ -z $final_path ]; then ynh_app_setting_set $app final_path $final_path fi +#================================================= +# Enable default admin temporaly +#================================================= +haveDefaultAdminDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") + +if [ "$haveDefaultAdminDisabled" -eq 0 ] ;then + echo "Enable default admin" + #enable default admin temporaly + mysql -u$db_user -p$db_pwd $db_name -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" +else + echo "default admin already enabled" +fi + +#================================================= +# Import Yunohost template +#================================================= +zabbixFullpath=https://$domain/$path_url +localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") + +curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + --form "enter=Enter" \ + --form "name=Admin" \ + --form "password=zabbix" \ + '$zabbixFullpath/index.php?login=1' + # 0 - update , 1 - skip, 0 - add + +sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + "$zabbixFullpath/conf.import.php" \ + |grep sid |head -n 1 \ + |awk -Fsid= '{print $2}' \ + |awk -F\" '{print $1}' \ + |cut -c -16 ) + +curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + --form "config=1" \ + --form "import_file=@$localpath" \ + --form rules[groups][createMissing]=1 \ + --form rules[templates][updateExisting]=1 \ + --form rules[templates][createMissing]=1 \ + --form rules[templateScreens][updateExisting]=1 \ + --form rules[templateScreens][createMissing]=1 \ + --form rules[templateLinkage][createMissing]=1 \ + --form rules[applications][createMissing]=1 \ + --form rules[items][updateExisting]=1 \ + --form rules[items][createMissing]=1 \ + --form rules[discoveryRules][updateExisting]=1 \ + --form rules[discoveryRules][createMissing]=1 \ + --form rules[triggers][updateExisting]=1 \ + --form rules[triggers][createMissing]=1 \ + --form rules[graphs][updateExisting]=1 \ + --form rules[graphs][createMissing]=1 \ + --form rules[httptests][updateExisting]=1 \ + --form rules[httptests][createMissing]=1 \ + --form rules[valueMaps][createMissing]=1 \ + --form "import=Import" \ + --form "backurl=templates.php" \ + --form "form_refresh=1" \ + --form "sid=${sid}" \ \ + 'https://$zabbixFullpath/zabbix/conf.import.php?rules_preset=template' + #================================================= # Disable default admin for security issue #================================================= @@ -66,6 +126,9 @@ else echo "default admin already disabled" fi + + + #================================================= # CHECK THE PATH #================================================= @@ -129,8 +192,8 @@ then systemctl reload nginx else - ynh_print_info "Nothing to update ! (Already up to date)" + ynh_print_info "No update from repo ! (Already up to date)" fi else - ynh_print_info "Nothing to update ! (Trusted version)" + ynh_print_info ""No update from repo ! (Trusted version)" fi From 22d8f452aa2ce4703958270bac621fcc7841466d Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 13:03:36 +0100 Subject: [PATCH 02/54] Update upgrade --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index ef6b34c..96d9cc9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -56,7 +56,7 @@ fi #================================================= haveDefaultAdminDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") -if [ "$haveDefaultAdminDisabled" -eq 0 ] ;then +if [ "$haveDefaultAdminDisabled" -eq 1 ] ;then echo "Enable default admin" #enable default admin temporaly mysql -u$db_user -p$db_pwd $db_name -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" From c9b412c141668eef9b2e7781d987762e3e48c650 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 13:04:08 +0100 Subject: [PATCH 03/54] Update upgrade --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 96d9cc9..0b4e921 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -195,5 +195,5 @@ then ynh_print_info "No update from repo ! (Already up to date)" fi else - ynh_print_info ""No update from repo ! (Trusted version)" + ynh_print_info "No update from repo ! (Trusted version)" fi From 530e986fdc77c651f88db12c03a74da2499ce091 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 13:04:44 +0100 Subject: [PATCH 04/54] Update upgrade --- scripts/upgrade | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 0b4e921..4130fb7 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -117,18 +117,16 @@ curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ haveDefaultAdminDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") if [ "$haveDefaultAdminDisabled" -eq 0 ] ;then - echo "Disable default admin" + ynh_print_info "Disable default admin" #disable default admin lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") lastid=$(($lastid + 1 )) mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" else - echo "default admin already disabled" + ynh_print_info "default admin already disabled" fi - - #================================================= # CHECK THE PATH #================================================= From e5fe78512c0c30fb53a2e81dbefe29f12e46a850 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 13:16:53 +0100 Subject: [PATCH 05/54] Update upgrade --- scripts/upgrade | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 4130fb7..9432a41 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -71,11 +71,10 @@ zabbixFullpath=https://$domain/$path_url localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - --form "enter=Enter" \ + --form "enter=Sign+in" \ --form "name=Admin" \ --form "password=zabbix" \ - '$zabbixFullpath/index.php?login=1' - # 0 - update , 1 - skip, 0 - add + '$zabbixFullpath/index.php' sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ "$zabbixFullpath/conf.import.php" \ @@ -109,7 +108,7 @@ curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "backurl=templates.php" \ --form "form_refresh=1" \ --form "sid=${sid}" \ \ - 'https://$zabbixFullpath/zabbix/conf.import.php?rules_preset=template' + 'https://$zabbixFullpath/conf.import.php?rules_preset=template' #================================================= # Disable default admin for security issue From bc7b6aa50789f4e4b194ec7726cb221aedbd7365 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 13:18:17 +0100 Subject: [PATCH 06/54] Update upgrade --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 9432a41..46324eb 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -74,7 +74,7 @@ curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "enter=Sign+in" \ --form "name=Admin" \ --form "password=zabbix" \ - '$zabbixFullpath/index.php' + "$zabbixFullpath/index.php" sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ "$zabbixFullpath/conf.import.php" \ From 34e4e9fee73f93de3a12d617255db08f252ec461 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 13:22:53 +0100 Subject: [PATCH 07/54] Update upgrade --- scripts/upgrade | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 46324eb..9f195e2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -74,14 +74,11 @@ curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "enter=Sign+in" \ --form "name=Admin" \ --form "password=zabbix" \ - "$zabbixFullpath/index.php" + "${zabbixFullpath}index.php" sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - "$zabbixFullpath/conf.import.php" \ - |grep sid |head -n 1 \ - |awk -Fsid= '{print $2}' \ - |awk -F\" '{print $1}' \ - |cut -c -16 ) + "${zabbixFullpath}/import.php" \ + | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "config=1" \ @@ -108,7 +105,7 @@ curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "backurl=templates.php" \ --form "form_refresh=1" \ --form "sid=${sid}" \ \ - 'https://$zabbixFullpath/conf.import.php?rules_preset=template' + 'https://${zabbixFullpath}conf.import.php?rules_preset=template' #================================================= # Disable default admin for security issue From ee2c2612f9daf1b9c6628000c1734c8571bc004e Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 13:26:49 +0100 Subject: [PATCH 08/54] Update upgrade --- scripts/upgrade | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 9f195e2..ee9be6b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -74,10 +74,10 @@ curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "enter=Sign+in" \ --form "name=Admin" \ --form "password=zabbix" \ - "${zabbixFullpath}index.php" + "$zabbixFullpath/index.php" sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - "${zabbixFullpath}/import.php" \ + "$zabbixFullpath/import.php" \ | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ @@ -105,7 +105,7 @@ curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "backurl=templates.php" \ --form "form_refresh=1" \ --form "sid=${sid}" \ \ - 'https://${zabbixFullpath}conf.import.php?rules_preset=template' + "${zabbixFullpath}conf.import.php?rules_preset=template" #================================================= # Disable default admin for security issue From f81c6b7021f7f12ebb0ddf14f6a3ea455c83acca Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 13:31:53 +0100 Subject: [PATCH 09/54] Update upgrade --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index ee9be6b..0240d26 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -77,7 +77,7 @@ curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ "$zabbixFullpath/index.php" sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - "$zabbixFullpath/import.php" \ + "$zabbixFullpath/conf.import.php?rules_preset=template" \ | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ From 9587c5c59cf10b664b75551571ee672844436af3 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 13:32:53 +0100 Subject: [PATCH 10/54] Update upgrade --- scripts/upgrade | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 0240d26..219c98e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -67,7 +67,7 @@ fi #================================================= # Import Yunohost template #================================================= -zabbixFullpath=https://$domain/$path_url +zabbixFullpath=https://$domain$path_url localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ @@ -105,7 +105,7 @@ curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "backurl=templates.php" \ --form "form_refresh=1" \ --form "sid=${sid}" \ \ - "${zabbixFullpath}conf.import.php?rules_preset=template" + "${zabbixFullpath}/conf.import.php?rules_preset=template" #================================================= # Disable default admin for security issue From 9af92b1050d489806cf2aad405014fe1fed90d0b Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 13:38:45 +0100 Subject: [PATCH 11/54] Update upgrade --- scripts/upgrade | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 219c98e..d613e8c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -80,7 +80,7 @@ sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ "$zabbixFullpath/conf.import.php?rules_preset=template" \ | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) -curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ +importState=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "config=1" \ --form "import_file=@$localpath" \ --form rules[groups][createMissing]=1 \ @@ -105,7 +105,14 @@ curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "backurl=templates.php" \ --form "form_refresh=1" \ --form "sid=${sid}" \ \ - "${zabbixFullpath}/conf.import.php?rules_preset=template" + "${zabbixFullpath}/conf.import.php?rules_preset=template" \ + | grep -c "Imported successfully") + +if [ "$importState" -eq "1" ];then + ynh_print_info "Template Yunohost imported !" +else + ynh_print_warn "Template Yunohost imported !" +fi #================================================= # Disable default admin for security issue From a0ba5d5537edd0c4168de8e9187d0e864a15ef44 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 13:39:35 +0100 Subject: [PATCH 12/54] Update install --- scripts/install | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/scripts/install b/scripts/install index ee24abe..87ff0d6 100644 --- a/scripts/install +++ b/scripts/install @@ -165,6 +165,57 @@ do fi done +#================================================= +# Import Yunohost template +#================================================= +zabbixFullpath=https://$domain$path_url +localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") + +curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + --form "enter=Sign+in" \ + --form "name=Admin" \ + --form "password=zabbix" \ + "$zabbixFullpath/index.php" + +sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + "$zabbixFullpath/conf.import.php?rules_preset=template" \ + | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) + +importState=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + --form "config=1" \ + --form "import_file=@$localpath" \ + --form rules[groups][createMissing]=1 \ + --form rules[templates][updateExisting]=1 \ + --form rules[templates][createMissing]=1 \ + --form rules[templateScreens][updateExisting]=1 \ + --form rules[templateScreens][createMissing]=1 \ + --form rules[templateLinkage][createMissing]=1 \ + --form rules[applications][createMissing]=1 \ + --form rules[items][updateExisting]=1 \ + --form rules[items][createMissing]=1 \ + --form rules[discoveryRules][updateExisting]=1 \ + --form rules[discoveryRules][createMissing]=1 \ + --form rules[triggers][updateExisting]=1 \ + --form rules[triggers][createMissing]=1 \ + --form rules[graphs][updateExisting]=1 \ + --form rules[graphs][createMissing]=1 \ + --form rules[httptests][updateExisting]=1 \ + --form rules[httptests][createMissing]=1 \ + --form rules[valueMaps][createMissing]=1 \ + --form "import=Import" \ + --form "backurl=templates.php" \ + --form "form_refresh=1" \ + --form "sid=${sid}" \ \ + "${zabbixFullpath}/conf.import.php?rules_preset=template" \ + | grep -c "Imported successfully") + +if [ "$importState" -eq "1" ];then + ynh_print_info "Template Yunohost imported !" +else + ynh_print_warn "Template Yunohost imported !" +fi + + #disable default admin lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") lastid=$(($lastid + 1 )) From bf07c0a9845be123050dff8793291916ccf05f9d Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 13:45:49 +0100 Subject: [PATCH 13/54] Update install --- scripts/install | 112 +++++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 54 deletions(-) diff --git a/scripts/install b/scripts/install index 87ff0d6..f9a3d8d 100644 --- a/scripts/install +++ b/scripts/install @@ -165,61 +165,7 @@ do fi done -#================================================= -# Import Yunohost template -#================================================= -zabbixFullpath=https://$domain$path_url -localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") -curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - --form "enter=Sign+in" \ - --form "name=Admin" \ - --form "password=zabbix" \ - "$zabbixFullpath/index.php" - -sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - "$zabbixFullpath/conf.import.php?rules_preset=template" \ - | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) - -importState=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - --form "config=1" \ - --form "import_file=@$localpath" \ - --form rules[groups][createMissing]=1 \ - --form rules[templates][updateExisting]=1 \ - --form rules[templates][createMissing]=1 \ - --form rules[templateScreens][updateExisting]=1 \ - --form rules[templateScreens][createMissing]=1 \ - --form rules[templateLinkage][createMissing]=1 \ - --form rules[applications][createMissing]=1 \ - --form rules[items][updateExisting]=1 \ - --form rules[items][createMissing]=1 \ - --form rules[discoveryRules][updateExisting]=1 \ - --form rules[discoveryRules][createMissing]=1 \ - --form rules[triggers][updateExisting]=1 \ - --form rules[triggers][createMissing]=1 \ - --form rules[graphs][updateExisting]=1 \ - --form rules[graphs][createMissing]=1 \ - --form rules[httptests][updateExisting]=1 \ - --form rules[httptests][createMissing]=1 \ - --form rules[valueMaps][createMissing]=1 \ - --form "import=Import" \ - --form "backurl=templates.php" \ - --form "form_refresh=1" \ - --form "sid=${sid}" \ \ - "${zabbixFullpath}/conf.import.php?rules_preset=template" \ - | grep -c "Imported successfully") - -if [ "$importState" -eq "1" ];then - ynh_print_info "Template Yunohost imported !" -else - ynh_print_warn "Template Yunohost imported !" -fi - - -#disable default admin -lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") -lastid=$(($lastid + 1 )) -mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -425,3 +371,61 @@ fi #================================================= systemctl reload nginx + +#================================================= +# Import Yunohost template +#================================================= +zabbixFullpath=https://$domain$path_url +localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") + +curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + --form "enter=Sign+in" \ + --form "name=Admin" \ + --form "password=zabbix" \ + "$zabbixFullpath/index.php" + +sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + "$zabbixFullpath/conf.import.php?rules_preset=template" \ + | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) + +importState=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + --form "config=1" \ + --form "import_file=@$localpath" \ + --form rules[groups][createMissing]=1 \ + --form rules[templates][updateExisting]=1 \ + --form rules[templates][createMissing]=1 \ + --form rules[templateScreens][updateExisting]=1 \ + --form rules[templateScreens][createMissing]=1 \ + --form rules[templateLinkage][createMissing]=1 \ + --form rules[applications][createMissing]=1 \ + --form rules[items][updateExisting]=1 \ + --form rules[items][createMissing]=1 \ + --form rules[discoveryRules][updateExisting]=1 \ + --form rules[discoveryRules][createMissing]=1 \ + --form rules[triggers][updateExisting]=1 \ + --form rules[triggers][createMissing]=1 \ + --form rules[graphs][updateExisting]=1 \ + --form rules[graphs][createMissing]=1 \ + --form rules[httptests][updateExisting]=1 \ + --form rules[httptests][createMissing]=1 \ + --form rules[valueMaps][createMissing]=1 \ + --form "import=Import" \ + --form "backurl=templates.php" \ + --form "form_refresh=1" \ + --form "sid=${sid}" \ \ + "${zabbixFullpath}/conf.import.php?rules_preset=template" \ + | grep -c "Imported successfully") + +if [ "$importState" -eq "1" ];then + ynh_print_info "Template Yunohost imported !" +else + ynh_print_warn "Template Yunohost imported !" +fi + +#================================================= +# disable default admin +#================================================= + +lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") +lastid=$(($lastid + 1 )) +mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" From 64fe109fa057b6d63d050adda5d19a984a7242b2 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 14:01:34 +0100 Subject: [PATCH 14/54] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index f9a3d8d..9c93c1a 100644 --- a/scripts/install +++ b/scripts/install @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST From 6900e5747fcbfa7a874be11bf15bb0e6dc8fb848 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 14:05:45 +0100 Subject: [PATCH 15/54] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 9c93c1a..511b81f 100644 --- a/scripts/install +++ b/scripts/install @@ -419,7 +419,7 @@ importState=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ if [ "$importState" -eq "1" ];then ynh_print_info "Template Yunohost imported !" else - ynh_print_warn "Template Yunohost imported !" + ynh_print_warn "Template Yunohost not imported !" fi #================================================= From 54aeb2167c9ec611b8b2daf72cecba1f1504f66d Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 17 Jan 2019 14:06:02 +0100 Subject: [PATCH 16/54] Update upgrade --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index d613e8c..b28c419 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -111,7 +111,7 @@ importState=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ if [ "$importState" -eq "1" ];then ynh_print_info "Template Yunohost imported !" else - ynh_print_warn "Template Yunohost imported !" + ynh_print_warn "Template Yunohost not imported !" fi #================================================= From 0e82dad4ced0c06c4d931af74f03b920d7080407 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 18 Jan 2019 13:26:46 +0100 Subject: [PATCH 17/54] Update install --- scripts/install | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/install b/scripts/install index 511b81f..da238f2 100644 --- a/scripts/install +++ b/scripts/install @@ -371,6 +371,7 @@ fi #================================================= systemctl reload nginx +( tail -f -n0 /var/log/syslog & ) | grep -q "Reloaded A high performance web server and a reverse proxy server." #================================================= # Import Yunohost template From 5aba417fe02343e60e7577872ee09b29dae91564 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 22 Jan 2019 13:55:00 +0100 Subject: [PATCH 18/54] Revert "Update install" This reverts commit 0e82dad4ced0c06c4d931af74f03b920d7080407 --- scripts/install | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/install b/scripts/install index da238f2..511b81f 100644 --- a/scripts/install +++ b/scripts/install @@ -371,7 +371,6 @@ fi #================================================= systemctl reload nginx -( tail -f -n0 /var/log/syslog & ) | grep -q "Reloaded A high performance web server and a reverse proxy server." #================================================= # Import Yunohost template From 16d1e8c7fdb17e79179007d5927e49ec4978c056 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Mon, 28 Jan 2019 13:33:38 +0100 Subject: [PATCH 19/54] Update install --- scripts/install | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 511b81f..06437b5 100644 --- a/scripts/install +++ b/scripts/install @@ -426,6 +426,6 @@ fi # disable default admin #================================================= -lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") -lastid=$(($lastid + 1 )) -mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" +#lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") +#lastid=$(($lastid + 1 )) +#mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" From 845e754d9e3f0011f47dff5e89ebdd31ab8e54ba Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Mon, 28 Jan 2019 13:49:37 +0100 Subject: [PATCH 20/54] Update install --- scripts/install | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 06437b5..9a7128e 100644 --- a/scripts/install +++ b/scripts/install @@ -379,9 +379,9 @@ zabbixFullpath=https://$domain$path_url localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - --form "enter=Sign+in" \ - --form "name=Admin" \ - --form "password=zabbix" \ + --form enter=Sign+in \ + --form name=Admin \ + --form password=zabbix \ "$zabbixFullpath/index.php" sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ From de7a56274ef68d46fad7037c1b2915a2986c897b Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 13:32:00 +0100 Subject: [PATCH 21/54] Update install --- scripts/install | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 9a7128e..31a326a 100644 --- a/scripts/install +++ b/scripts/install @@ -252,8 +252,6 @@ ynh_add_fpm_config # Set the app as temporarily public for curl call #ynh_app_setting_set $app skipped_uris "/" -# Reload SSOwat config -yunohost app ssowatconf # Reload Nginx systemctl reload nginx @@ -372,6 +370,9 @@ fi systemctl reload nginx +# Reload SSOwat config +yunohost app ssowatconf + #================================================= # Import Yunohost template #================================================= From 8841e53c4a0a16facd77b1ae611c20d5776f29d8 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 13:56:16 +0100 Subject: [PATCH 22/54] Update install --- scripts/install | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 31a326a..229a89a 100644 --- a/scripts/install +++ b/scripts/install @@ -423,10 +423,23 @@ else ynh_print_warn "Template Yunohost not imported !" fi +#apply template to host +tokenapi=$(curl -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result') +zabbixHostID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result[0].hostid') +zabbixTemplateID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":[" Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result[0].templateid') +applyTemplate=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.update","params":{"hostid":"'$zabbixHostID'","templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result.hostids[]') + +if [ "$applyTemplate" -eq "$zabbixHostID" ];then + ynh_print_info "Template Yunohost linked to Zabbix server !" +else + ynh_print_warn "Template Yunohost no linked to Zabbix server !" +fi + + #================================================= # disable default admin #================================================= -#lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") -#lastid=$(($lastid + 1 )) -#mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" +lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") +lastid=$(($lastid + 1 )) +mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" From aa65a4ba2b3bc1a0a9ce7d42c71bd3b440f6719c Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 13:57:52 +0100 Subject: [PATCH 23/54] Update install --- scripts/install | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index 229a89a..cf817c5 100644 --- a/scripts/install +++ b/scripts/install @@ -424,10 +424,10 @@ else fi #apply template to host -tokenapi=$(curl -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result') -zabbixHostID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result[0].hostid') -zabbixTemplateID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":[" Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result[0].templateid') -applyTemplate=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.update","params":{"hostid":"'$zabbixHostID'","templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result.hostids[]') +tokenapi=$(curl -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result') +zabbixHostID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') +zabbixTemplateID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":[" Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') +applyTemplate=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.update","params":{"hostid":"'$zabbixHostID'","templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/zabbix/api_jsonrpc.php | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then ynh_print_info "Template Yunohost linked to Zabbix server !" From 1afa9c9ebb966a7d1a29b806d0e2b1e59ce6741b Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 14:01:20 +0100 Subject: [PATCH 24/54] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index cf817c5..4e3dfbd 100644 --- a/scripts/install +++ b/scripts/install @@ -426,7 +426,7 @@ fi #apply template to host tokenapi=$(curl -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result') zabbixHostID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') -zabbixTemplateID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":[" Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') +zabbixTemplateID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') applyTemplate=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.update","params":{"hostid":"'$zabbixHostID'","templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/zabbix/api_jsonrpc.php | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then From 94fcaee28bd200e28b78bace0e425c7643b1be4b Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 14:05:44 +0100 Subject: [PATCH 25/54] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 4e3dfbd..79ba3c6 100644 --- a/scripts/install +++ b/scripts/install @@ -427,7 +427,7 @@ fi tokenapi=$(curl -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result') zabbixHostID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') zabbixTemplateID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') -applyTemplate=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.update","params":{"hostid":"'$zabbixHostID'","templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/zabbix/api_jsonrpc.php | jq -r '.result.hostids[]') +applyTemplate=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.update","params":{"hostid":"'$zabbixHostID'","templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then ynh_print_info "Template Yunohost linked to Zabbix server !" From 331689bcda7640d98a1a6e4a599756a9e3d21196 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 18:19:06 +0100 Subject: [PATCH 26/54] Update install --- scripts/install | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 79ba3c6..5a81a0d 100644 --- a/scripts/install +++ b/scripts/install @@ -427,8 +427,7 @@ fi tokenapi=$(curl -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result') zabbixHostID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') zabbixTemplateID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') -applyTemplate=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.update","params":{"hostid":"'$zabbixHostID'","templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') - +applyTemplate=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then ynh_print_info "Template Yunohost linked to Zabbix server !" else From 6bd8bf69fb35efb57ba540db01fdf304f287824d Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 18:28:18 +0100 Subject: [PATCH 27/54] Update install --- scripts/install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 5a81a0d..499fcf2 100644 --- a/scripts/install +++ b/scripts/install @@ -425,8 +425,8 @@ fi #apply template to host tokenapi=$(curl -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result') -zabbixHostID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') -zabbixTemplateID=$(curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') +zabbixHostID=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') +zabbixTemplateID=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') applyTemplate=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then ynh_print_info "Template Yunohost linked to Zabbix server !" From 62fbfe5cf0f4f448b619a6059625874c42b5e494 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 18:29:21 +0100 Subject: [PATCH 28/54] Update upgrade to update template --- scripts/upgrade | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index b28c419..f6a2247 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -71,9 +71,9 @@ zabbixFullpath=https://$domain$path_url localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - --form "enter=Sign+in" \ - --form "name=Admin" \ - --form "password=zabbix" \ + --form enter=Sign+in \ + --form name=Admin \ + --form password=zabbix \ "$zabbixFullpath/index.php" sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ @@ -114,6 +114,18 @@ else ynh_print_warn "Template Yunohost not imported !" fi +#apply template to host +tokenapi=$(curl -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result') +zabbixHostID=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') +zabbixTemplateID=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') +applyTemplate=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result.hostids[]') +if [ "$applyTemplate" -eq "$zabbixHostID" ];then + ynh_print_info "Template Yunohost linked to Zabbix server !" +else + ynh_print_warn "Template Yunohost no linked to Zabbix server !" +fi + + #================================================= # Disable default admin for security issue #================================================= From d2841d026315cbd10811ad96efac22835370b72c Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 18:44:11 +0100 Subject: [PATCH 29/54] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 499fcf2..b468c1b 100644 --- a/scripts/install +++ b/scripts/install @@ -427,7 +427,7 @@ fi tokenapi=$(curl -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result') zabbixHostID=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') zabbixTemplateID=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') -applyTemplate=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result.hostids[]') +applyTemplate=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then ynh_print_info "Template Yunohost linked to Zabbix server !" else From 516da9e03643bda51858736552b931d2f0802cc8 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 18:44:42 +0100 Subject: [PATCH 30/54] Update upgrade --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index f6a2247..479dc21 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -118,7 +118,7 @@ fi tokenapi=$(curl -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result') zabbixHostID=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') zabbixTemplateID=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') -applyTemplate=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' http://mike.test/zabbix/api_jsonrpc.php | jq -r '.result.hostids[]') +applyTemplate=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then ynh_print_info "Template Yunohost linked to Zabbix server !" else From 716beeb9d70f56fe22a2c3884150913bc6402ec1 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 18:50:05 +0100 Subject: [PATCH 31/54] add sudoers file --- sources/extra_files/app/etc_sudoers.d_zabbix | 1 + 1 file changed, 1 insertion(+) create mode 100644 sources/extra_files/app/etc_sudoers.d_zabbix diff --git a/sources/extra_files/app/etc_sudoers.d_zabbix b/sources/extra_files/app/etc_sudoers.d_zabbix new file mode 100644 index 0000000..de296b5 --- /dev/null +++ b/sources/extra_files/app/etc_sudoers.d_zabbix @@ -0,0 +1 @@ +zabbix ALL=(root) NOPASSWD: /etc/zabbix/zabbix_agentd.d/yunohost.sh \ No newline at end of file From 3159f07ad44844944ce2a7fc6d0cf19d8eb32a42 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 18:52:24 +0100 Subject: [PATCH 32/54] Add file UserP for zabbix agent --- .../etc_zabbix_zabbix_agentd.d_userP_yunohost.conf | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 sources/extra_files/app/etc_zabbix_zabbix_agentd.d_userP_yunohost.conf diff --git a/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_userP_yunohost.conf b/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_userP_yunohost.conf new file mode 100644 index 0000000..3070897 --- /dev/null +++ b/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_userP_yunohost.conf @@ -0,0 +1,12 @@ +UserParameter=yunohost.users.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.users.discover +UserParameter=yunohost.user.quota[*],sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.user.quota "$1" +UserParameter=yunohost.domains.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.domains.discover +UserParameter=yunohost.domain.cert[*],sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.domain.cert "$1" +UserParameter=yunohost.services.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.services.discover +UserParameter=yunohost.service.status[*],sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.service.status "$1" +UserParameter=yunohost.backups.number,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.backups.number +UserParameter=yunohost.backups.ageoflastbackup,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.backups.ageoflastbackup +UserParameter=yunohost.ports.tcp.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.tcp.discovery +UserParameter=yunohost.ports.udp.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.udp.discovery +UserParameter=yunohost.migrations.lastinstalled,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.migrations.lastinstalled +UserParameter=yunohost.migrations.lastavailable,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.migrations.lastavailable \ No newline at end of file From 685017f656f550ff0320d0e17d98ed964025a973 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 18:53:11 +0100 Subject: [PATCH 33/54] Add bash file for userP --- .../etc_zabbix_zabbix_agentd.d_yunohost.sh | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh diff --git a/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh b/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh new file mode 100644 index 0000000..fdbf017 --- /dev/null +++ b/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh @@ -0,0 +1,56 @@ +#!/bin/bash +yunobin=$(which yunohost) + +if [ "$1" == "yunohost.users.discover" ];then + users=$($yunobin user list --fields 'uid' | awk -F ': ' '/username: / {print $2}');echo -n "{\"data\":[";for user in $users;do echo -n "{\"{#USERNAME}\":\"$user\"},";done | sed 's/,$//' ;echo "]}" +fi + +if [ "$1" == "yunohost.user.quota" ] ;then + quota=$($yunobin user info "$2" | grep -Po "use:.*\(\K([0-9]{1,3})");if [ -z "$quota" ];then echo 0 ; else echo "$quota" ;fi +fi + +if [ "$1" == "yunohost.domains.discover" ] ;then + domains=$($yunobin domain list --plain);echo -n "{\"data\":[";for domain in $domains;do echo -n "{\"{#DOMAIN}\":\"$domain\"},";done | sed 's/,$//' ;echo "]}" +fi + +if [ "$1" == "yunohost.domain.cert" ] ;then + $yunobin domain cert-status "$2" --plain --full| awk '/#/{ next;} {printf "%s;",$0} END {print ""}' +fi + +if [ "$1" == "yunohost.services.discover" ] ;then + services=$($yunobin service status 2>/dev/null| grep -Po '^([A-Za-z]+)(?=(:))');echo -n "{\"data\":[";for service in $services;do echo -n "{\"{#SERVICE}\":\"$service\"},";done | sed 's/,$//' ;echo "]}" +fi + +if [ "$1" == "yunohost.service.status" ] ;then + service=$($yunobin service status "$2" --plain 2>/dev/null | awk '/#/{ next;} {printf "%s;",$0} END {print ""}') + if [[ "$service" == *"doesn't exists for systemd"* ]] ;then + echo "$service" | sed 's/\(.*;.*;.*;.*;.*;\).*\(;.*;\)/\1disabled\2/g' + else + echo "$service" + fi +fi + +if [ "$1" == "yunohost.backups.number" ] ;then + $yunobin backup list --plain | wc -l +fi + +if [ "$1" == "yunohost.backups.ageoflastbackup" ] ;then + timestamp=$(date +"%d/%m/%Y %H:%M" -d"$($yunobin backup list -i | tail -n 4 | head -n 1 | grep -Po 'created_at: \K(.*)')") + echo $(( ($(date +%s) - $(date -d"$timestamp" +%s))/(60*60*24) )) +fi + +if [ "$1" == "yunohost.ports.tcp.discovery" ] ;then + ports=$($yunobin firewall list -r --plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##TCP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" +fi + +if [ "$1" == "yunohost.ports.udp.discovery" ] ;then + ports=$($yunobin firewall list -r --plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##UDP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" +fi + +if [ "$1" == "yunohost.migrations.lastinstalled" ] ;then + $yunobin tools migrations state | grep -Po " number: \K(.*)" +fi + +if [ "$1" == "yunohost.migrations.lastavailable" ] ;then + $yunobin tools migrations list | tail -n 1 | grep -Po " number: \K(.*)" +fi From db7e7df4bf681a5ac371f0002a9062b82e5101fb Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 18:57:24 +0100 Subject: [PATCH 34/54] add conf file for template --- scripts/install | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/install b/scripts/install index b468c1b..e55ffce 100644 --- a/scripts/install +++ b/scripts/install @@ -378,6 +378,14 @@ yunohost app ssowatconf #================================================= zabbixFullpath=https://$domain$path_url localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") +sudoUserPpath=$(find /var/cache/yunohost/ -name "etc_sudoers.d_zabbix") +confUserPpath=$(find /var/cache/yunohost/ -name "etc_zabbix_zabbix_agentd.d_userP_yunohost.conf") +bashUserPpath=$(find /var/cache/yunohost/ -name "etc_zabbix_zabbix_agentd.d_yunohost.sh") + +cp $sudoUserPpath /etc/sudoers.d/zabbix +cp $confUserPpath /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf +cp $bashUserPpath /etc/zabbix/zabbix_agentd.d/yunohost.sh +chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form enter=Sign+in \ From e32c602f3b5fd656cc1d95364660b34e75129d7a Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 29 Jan 2019 19:03:45 +0100 Subject: [PATCH 35/54] Update upgrade to import conf file userp template --- scripts/upgrade | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index 479dc21..e72b94a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -69,6 +69,15 @@ fi #================================================= zabbixFullpath=https://$domain$path_url localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") +sudoUserPpath=$(find /var/cache/yunohost/ -name "etc_sudoers.d_zabbix") +confUserPpath=$(find /var/cache/yunohost/ -name "etc_zabbix_zabbix_agentd.d_userP_yunohost.conf") +bashUserPpath=$(find /var/cache/yunohost/ -name "etc_zabbix_zabbix_agentd.d_yunohost.sh") + +cp $sudoUserPpath /etc/sudoers.d/zabbix +cp $confUserPpath /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf +cp $bashUserPpath /etc/zabbix/zabbix_agentd.d/yunohost.sh +chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh + curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form enter=Sign+in \ From d615ebcfdbbff9fff207fd47c520cee53a1ddbf4 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 30 Jan 2019 08:46:07 +0100 Subject: [PATCH 36/54] Update remove --- scripts/remove | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/remove b/scripts/remove index e0b99b8..e052f78 100644 --- a/scripts/remove +++ b/scripts/remove @@ -115,6 +115,9 @@ ynh_secure_remove "/var/log/zabbix" # Remove the pid/socket files ynh_secure_remove "/run/zabbix" +# Remove the sudoers file +ynh_secure_remove "/etc/sudoers.d/zabbix" + #================================================= # GENERIC FINALIZATION #================================================= From 3e5329db85a1c76a9f4d3bdd778b74988b078fa7 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 30 Jan 2019 08:47:25 +0100 Subject: [PATCH 37/54] Update remove --- scripts/remove | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/remove b/scripts/remove index e052f78..125aa58 100644 --- a/scripts/remove +++ b/scripts/remove @@ -83,6 +83,12 @@ ynh_mysql_remove_db $db_user $db_name # Remove the dedicated nginx config ynh_remove_nginx_config +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx + #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= @@ -126,3 +132,4 @@ ynh_secure_remove "/etc/sudoers.d/zabbix" # Delete a system user ynh_system_user_delete zabbix + From 02990feee07b9d871532eb29128e11601d73b222 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 30 Jan 2019 08:48:27 +0100 Subject: [PATCH 38/54] Update remove --- scripts/remove | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/remove b/scripts/remove index 125aa58..bc13f0e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -50,6 +50,8 @@ fi # Remove the dedicated php-fpm config ynh_remove_fpm_config +systemctl reload php7.0-fpm + #================================================= # REMOVE DEPENDENCIES #================================================= From e57d2399f1866c61aa9a2c47e048f8beb420d163 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 30 Jan 2019 13:03:02 +0100 Subject: [PATCH 39/54] Update manifest.json --- manifest.json | 1 + 1 file changed, 1 insertion(+) diff --git a/manifest.json b/manifest.json index efd1a08..4381359 100644 --- a/manifest.json +++ b/manifest.json @@ -21,6 +21,7 @@ "services": [ "nginx", "mysql", + "php7.0-fpm", "snmpd" ], "arguments": { From 998b46448c8498bd08bbd94467ebf3ce70909aa3 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 30 Jan 2019 13:03:33 +0100 Subject: [PATCH 40/54] Update install to add jq --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index e55ffce..579e318 100644 --- a/scripts/install +++ b/scripts/install @@ -96,7 +96,7 @@ dpkg -i zabbix-release_*.deb rm zabbix-release_*.deb echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list ynh_package_update -ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype zabbix-server-mysql zabbix-agent +ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype zabbix-server-mysql zabbix-agent jq yunohost service add snmpd -d "Management of SNMP Daemon" DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php ar x *.deb From 32e4130d9c70e5b03159a62caa553c542c486eef Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 30 Jan 2019 13:49:37 +0100 Subject: [PATCH 41/54] Update install --- scripts/install | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 579e318..0af3da2 100644 --- a/scripts/install +++ b/scripts/install @@ -365,10 +365,11 @@ then fi #================================================= -# RELOAD NGINX +# RELOAD NGINX AND PHP-FPM #================================================= systemctl reload nginx +systemctl reload php7.0-fpm # Reload SSOwat config yunohost app ssowatconf From f23f89722e922f129e72b2f3a0832c8210ac5d1b Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 30 Jan 2019 13:54:29 +0100 Subject: [PATCH 42/54] Update install --- scripts/install | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/install b/scripts/install index 0af3da2..cd6676e 100644 --- a/scripts/install +++ b/scripts/install @@ -388,17 +388,17 @@ cp $confUserPpath /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf cp $bashUserPpath /etc/zabbix/zabbix_agentd.d/yunohost.sh chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh -curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ +curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form enter=Sign+in \ --form name=Admin \ --form password=zabbix \ "$zabbixFullpath/index.php" -sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ +sid=$(curl-k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ "$zabbixFullpath/conf.import.php?rules_preset=template" \ | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) -importState=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ +importState=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "config=1" \ --form "import_file=@$localpath" \ --form rules[groups][createMissing]=1 \ @@ -433,10 +433,10 @@ else fi #apply template to host -tokenapi=$(curl -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result') -zabbixHostID=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') -zabbixTemplateID=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') -applyTemplate=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') +tokenapi=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result') +zabbixHostID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') +zabbixTemplateID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') +applyTemplate=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then ynh_print_info "Template Yunohost linked to Zabbix server !" else From 956f29b68dedd751bcd41bbb28fdd24d961baf42 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 30 Jan 2019 13:55:03 +0100 Subject: [PATCH 43/54] Update upgrade --- scripts/upgrade | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index e72b94a..f69c382 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -79,17 +79,17 @@ cp $bashUserPpath /etc/zabbix/zabbix_agentd.d/yunohost.sh chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh -curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ +curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form enter=Sign+in \ --form name=Admin \ --form password=zabbix \ "$zabbixFullpath/index.php" -sid=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ +sid=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ "$zabbixFullpath/conf.import.php?rules_preset=template" \ | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) -importState=$(curl -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ +importState=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "config=1" \ --form "import_file=@$localpath" \ --form rules[groups][createMissing]=1 \ @@ -124,10 +124,10 @@ else fi #apply template to host -tokenapi=$(curl -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result') -zabbixHostID=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') -zabbixTemplateID=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') -applyTemplate=$(curl -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') +tokenapi=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result') +zabbixHostID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].hostid') +zabbixTemplateID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') +applyTemplate=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then ynh_print_info "Template Yunohost linked to Zabbix server !" else From e4347412387c6dfc34850cfff1ea142bbb00e6a5 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 30 Jan 2019 13:59:24 +0100 Subject: [PATCH 44/54] Update install --- scripts/install | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/install b/scripts/install index cd6676e..d5a9347 100644 --- a/scripts/install +++ b/scripts/install @@ -300,6 +300,10 @@ sed -i "126a DBPassword=$db_pwd" /etc/zabbix/zabbix_server.conf systemctl enable zabbix-server && systemctl start zabbix-server +yunohost service add zabbix-server -d "Management of Zabbix Server - Monitoring server" +yunohost service add zabbix-agent -d "Management of Zabbix Agent" + + #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= From 7453a94c110332a37f6e9de488ac7b5dcdd9cf73 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 30 Jan 2019 13:59:47 +0100 Subject: [PATCH 45/54] Update install --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index d5a9347..6f16f7c 100644 --- a/scripts/install +++ b/scripts/install @@ -398,7 +398,7 @@ curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form password=zabbix \ "$zabbixFullpath/index.php" -sid=$(curl-k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ +sid=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ "$zabbixFullpath/conf.import.php?rules_preset=template" \ | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) From 93f837a401c0bd5d22e676056ca774fa7d4af014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl?= Date: Wed, 30 Jan 2019 18:07:09 +0100 Subject: [PATCH 46/54] Multiples modif pour le template --- README.md | 9 ++++++--- scripts/backup | 3 +++ scripts/install | 15 +++++++++++---- scripts/remove | 7 ++----- scripts/restore | 5 +++++ scripts/upgrade | 1 + sources/extra_files/app/etc_sudoers.d_zabbix | 2 +- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 98ba18e..05a9156 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,14 @@ Are LDAP auth supported Only Debian - Stretch 64b supported actually. ## Limitations - +Do not change admin password. ## Additional information -* Other information you would add about this application +* Do not change the default admin user password. The user is disabled juste after the install but used to update templates. +* The Zabbix server port is not opened by default for external monitoring (active agent). +* Install or update apply a template yunohost on the host "Zabbix-server" (127.0.0.1) for basic monitoring for Yunohost. +* If you want more information about Yunohost in the template, please open an issue on git. **More information on the documentation page:** https://yunohost.org/packaging_apps @@ -39,4 +42,4 @@ got to https://framagit.org/Mickael-Martin/zabbix_ynh/blob/master/LICENSE ## Links * Report a bug: https://framagit.org/Mickael-Martin/zabbix_ynh/issues - * YunoHost website: https://yunohost.org/ \ No newline at end of file + * YunoHost website: https://yunohost.org/ diff --git a/scripts/backup b/scripts/backup index 0999145..a5bd1ad 100644 --- a/scripts/backup +++ b/scripts/backup @@ -46,6 +46,9 @@ ynh_backup "/etc/zabbix/zabbix_server.conf" ynh_backup "/etc/zabbix/zabbix_agentd.conf" ynh_backup "/etc/zabbix/zabbix_agentd.d" +#backup sudo file +ynh_backup "/etc/sudoers.d/zabbix" + #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= diff --git a/scripts/install b/scripts/install index 6f16f7c..0b69a65 100644 --- a/scripts/install +++ b/scripts/install @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # Exit if an error occurs during the execution of the script -#ynh_abort_if_errors +ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST @@ -74,6 +74,9 @@ ynh_app_setting_set $app language $language ### If you're not using these lines: ### - Remove the section "CLOSE A PORT" in the remove script +### Zabbix server is not opened by default for external usage. +### if you want use zabbix server with external agent (in active mode), setup the listen address in server configuration and open port on firewall via the cmd yunohost firewall + # Find a free port #port=$(ynh_find_port 8095) # Open this port @@ -153,7 +156,7 @@ name=$(ynh_user_get_info $admin firstname) mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users\` (\`userid\`,\`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES (3,'"$admin"', '"$admin"', '"$admin"', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '"$lang"', '30s', 3, 'default', 0, '', 0, 50);" mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\`, \`usrgrpid\`, \`userid\`) VALUES (5, 7, 3);" -#users creation +#users creation in zabbix database i=4 for u in $(ynh_user_list); do @@ -165,8 +168,6 @@ do fi done - - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -194,6 +195,8 @@ ynh_add_nginx_config # Create a system user #ynh_system_user_create $app +# +### zabbix user created in zabbix server dpkg install #================================================= # PHP-FPM CONFIGURATION @@ -237,6 +240,8 @@ ynh_add_fpm_config # Create a dedicated systemd config #ynh_add_systemd_config +### Systemd service created when dpkg install + #================================================= # SETUP APPLICATION WITH CURL #================================================= @@ -392,6 +397,8 @@ cp $confUserPpath /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf cp $bashUserPpath /etc/zabbix/zabbix_agentd.d/yunohost.sh chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh +systemctl restart zabbix-agent + curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form enter=Sign+in \ --form name=Admin \ diff --git a/scripts/remove b/scripts/remove index bc13f0e..cd95114 100644 --- a/scripts/remove +++ b/scripts/remove @@ -37,11 +37,8 @@ yunohost service remove snmpd #================================================= # Remove a service from the admin panel, added by `yunohost service add` -if yunohost service status | grep -q $app -then - echo "Remove $app service" - yunohost service remove $app -fi +yunohost service remove zabbix-server +yunohost service remove zabbix-agent #================================================= # REMOVE PHP-FPM CONFIGURATION diff --git a/scripts/restore b/scripts/restore index f712ca0..4409c8a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -75,6 +75,9 @@ rm $final_path/conf/zabbix.conf.php ynh_app_setting_set $app final_path $final_path +yunohost service add zabbix-server -d "Management of Zabbix Server - Monitoring server" +yunohost service add zabbix-agent -d "Management of Zabbix Agent" + #================================================= # NGINX CONFIGURATION #================================================= @@ -91,6 +94,8 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" +# Restore sudo file +ynh_restore_file "/etc/sudoers.d/zabbix" # Reload SSOwat config yunohost app ssowatconf diff --git a/scripts/upgrade b/scripts/upgrade index f69c382..ca00b43 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -78,6 +78,7 @@ cp $confUserPpath /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf cp $bashUserPpath /etc/zabbix/zabbix_agentd.d/yunohost.sh chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh +systemctl restart zabbix-agent curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form enter=Sign+in \ diff --git a/sources/extra_files/app/etc_sudoers.d_zabbix b/sources/extra_files/app/etc_sudoers.d_zabbix index de296b5..ce70ecb 100644 --- a/sources/extra_files/app/etc_sudoers.d_zabbix +++ b/sources/extra_files/app/etc_sudoers.d_zabbix @@ -1 +1 @@ -zabbix ALL=(root) NOPASSWD: /etc/zabbix/zabbix_agentd.d/yunohost.sh \ No newline at end of file +zabbix ALL=(ALL) NOPASSWD: /etc/zabbix/zabbix_agentd.d/yunohost.sh From 814220c095fb92d741ed7510c98686eda61469cf Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 31 Jan 2019 13:45:43 +0100 Subject: [PATCH 47/54] Update etc_zabbix_zabbix_agentd.d_yunohost.sh --- .../etc_zabbix_zabbix_agentd.d_yunohost.sh | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh b/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh index fdbf017..c6859d3 100644 --- a/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh +++ b/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh @@ -10,11 +10,11 @@ if [ "$1" == "yunohost.user.quota" ] ;then fi if [ "$1" == "yunohost.domains.discover" ] ;then - domains=$($yunobin domain list --plain);echo -n "{\"data\":[";for domain in $domains;do echo -n "{\"{#DOMAIN}\":\"$domain\"},";done | sed 's/,$//' ;echo "]}" + domains=$($yunobin domain list --output-as plain);echo -n "{\"data\":[";for domain in $domains;do echo -n "{\"{#DOMAIN}\":\"$domain\"},";done | sed 's/,$//' ;echo "]}" fi if [ "$1" == "yunohost.domain.cert" ] ;then - $yunobin domain cert-status "$2" --plain --full| awk '/#/{ next;} {printf "%s;",$0} END {print ""}' + $yunobin domain cert-status "$2" --output-as plain --full| awk '/#/{ next;} {printf "%s;",$0} END {print ""}' fi if [ "$1" == "yunohost.services.discover" ] ;then @@ -22,29 +22,33 @@ if [ "$1" == "yunohost.services.discover" ] ;then fi if [ "$1" == "yunohost.service.status" ] ;then - service=$($yunobin service status "$2" --plain 2>/dev/null | awk '/#/{ next;} {printf "%s;",$0} END {print ""}') - if [[ "$service" == *"doesn't exists for systemd"* ]] ;then - echo "$service" | sed 's/\(.*;.*;.*;.*;.*;\).*\(;.*;\)/\1disabled\2/g' - else - echo "$service" - fi + service=$($yunobin service status "$2" --output-as json 2>/dev/null) + if [[ "$(echo $service | jq -r '.description')" == *"doesn't exists for systemd"* ]] ;then + echo "$service" | jq -c '.active = "disabled"' + else + echo "$service" + fi fi if [ "$1" == "yunohost.backups.number" ] ;then - $yunobin backup list --plain | wc -l + $yunobin backup list --output-as plain | wc -l fi if [ "$1" == "yunohost.backups.ageoflastbackup" ] ;then - timestamp=$(date +"%d/%m/%Y %H:%M" -d"$($yunobin backup list -i | tail -n 4 | head -n 1 | grep -Po 'created_at: \K(.*)')") - echo $(( ($(date +%s) - $(date -d"$timestamp" +%s))/(60*60*24) )) + if [ $($yunobin backup list --output-as plain | wc -l) -ne 0 ] ;then + timestamp=$(date +"%d/%m/%Y %H:%M" -d"$($yunobin backup list -i | tail -n 4 | head -n 1 | grep -Po 'created_at: \K(.*)')") + echo $(( ($(date +%s) - $(date -d"$timestamp" +%s))/(60*60*24) )) + else + echo "No backup detected" + fi fi if [ "$1" == "yunohost.ports.tcp.discovery" ] ;then - ports=$($yunobin firewall list -r --plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##TCP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" + ports=$($yunobin firewall list -r --output-as plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##TCP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" fi if [ "$1" == "yunohost.ports.udp.discovery" ] ;then - ports=$($yunobin firewall list -r --plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##UDP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" + ports=$($yunobin firewall list -r --output-as plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##UDP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" fi if [ "$1" == "yunohost.migrations.lastinstalled" ] ;then @@ -53,4 +57,4 @@ fi if [ "$1" == "yunohost.migrations.lastavailable" ] ;then $yunobin tools migrations list | tail -n 1 | grep -Po " number: \K(.*)" -fi +fi \ No newline at end of file From 563e034d3f0b6337915ef913306b26ec539f074f Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 31 Jan 2019 13:46:17 +0100 Subject: [PATCH 48/54] Update Template_Yunohost.xml --- sources/extra_files/app/Template_Yunohost.xml | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/sources/extra_files/app/Template_Yunohost.xml b/sources/extra_files/app/Template_Yunohost.xml index f7121a0..49d5bd1 100644 --- a/sources/extra_files/app/Template_Yunohost.xml +++ b/sources/extra_files/app/Template_Yunohost.xml @@ -1,7 +1,7 @@ 4.0 - 2019-01-15T12:48:48Z + 2019-01-31T12:45:57Z Templates/Applications @@ -32,7 +32,6 @@ cat /etc/zabbix/zabbix_agentd.d/yunohost.sh #!/bin/bash yunobin=$(which yunohost) - if [ "$1" == "yunohost.users.discover" ];then users=$($yunobin user list --fields 'uid' | awk -F ': ' '/username: / {print $2}');echo -n "{\"data\":[";for user in $users;do echo -n "{\"{#USERNAME}\":\"$user\"},";done | sed 's/,$//' ;echo "]}" fi @@ -42,37 +41,45 @@ if [ "$1" == "yunohost.user.quota" ] ;then fi if [ "$1" == "yunohost.domains.discover" ] ;then - domains=$($yunobin domain list --plain);echo -n "{\"data\":[";for domain in $domains;do echo -n "{\"{#DOMAIN}\":\"$domain\"},";done | sed 's/,$//' ;echo "]}" + domains=$($yunobin domain list --output-as plain);echo -n "{\"data\":[";for domain in $domains;do echo -n "{\"{#DOMAIN}\":\"$domain\"},";done | sed 's/,$//' ;echo "]}" fi if [ "$1" == "yunohost.domain.cert" ] ;then - $yunobin domain cert-status "$2" --plain | awk '/#/{ next;} {printf "%s;",$0} END {print ""}' + $yunobin domain cert-status "$2" --output-as plain --full| awk '/#/{ next;} {printf "%s;",$0} END {print ""}' fi if [ "$1" == "yunohost.services.discover" ] ;then - services=$($yunobin service status | grep -Po '^([A-Za-z]+)(?=(:))');echo -n "{\"data\":[";for service in $services;do echo -n "{\"{#SERVICE}\":\"$service\"},";done | sed 's/,$//' ;echo "]}" + services=$($yunobin service status 2>/dev/null| grep -Po '^([A-Za-z]+)(?=(:))');echo -n "{\"data\":[";for service in $services;do echo -n "{\"{#SERVICE}\":\"$service\"},";done | sed 's/,$//' ;echo "]}" fi if [ "$1" == "yunohost.service.status" ] ;then - $yunobin service status "$2" --plain | awk '/#/{ next;} {printf "%s;",$0} END {print ""}' + service=$($yunobin service status "$2" --output-as json 2>/dev/null) + if [[ "$(echo $service | jq -r '.description')" == *"doesn't exists for systemd"* ]] ;then + echo "$service" | jq -c '.active = "disabled"' + else + echo "$service" + fi fi if [ "$1" == "yunohost.backups.number" ] ;then - $yunobin backup list --plain | wc -l + $yunobin backup list --output-as plain | wc -l fi if [ "$1" == "yunohost.backups.ageoflastbackup" ] ;then - timestamp=$(date +"%d/%m/%Y %H:%M" -d"$($yunobin backup list -i | tail -n 4 | head -n 1 | grep -Po 'created_at: \K(.*)')") - echo $(( ($(date +%s) - $(date -d"$timestamp" +%s))/(60*60*24) )) + if [ $($yunobin backup list --output-as plain | wc -l) -ne 0 ] ;then + timestamp=$(date +"%d/%m/%Y %H:%M" -d"$($yunobin backup list -i | tail -n 4 | head -n 1 | grep -Po 'created_at: \K(.*)')") + echo $(( ($(date +%s) - $(date -d"$timestamp" +%s))/(60*60*24) )) + else + echo "No backup detected" + fi fi - if [ "$1" == "yunohost.ports.tcp.discovery" ] ;then - ports=$($yunobin firewall list -r --plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##TCP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" + ports=$($yunobin firewall list -r --output-as plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##TCP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" fi if [ "$1" == "yunohost.ports.udp.discovery" ] ;then - ports=$($yunobin firewall list -r --plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##UDP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" + ports=$($yunobin firewall list -r --output-as plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##UDP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" fi if [ "$1" == "yunohost.migrations.lastinstalled" ] ;then @@ -962,10 +969,14 @@ fi + + 12 + $.active + 5 - (.*);(.*);(.*);(.*);(.*);(.*);(.*); -\6:inactive=0:active=1:unknown=2;disabled=3 + (.*) +\1:inactive=0:active=1:unknown=2;disabled=3 5 @@ -1399,4 +1410,4 @@ fi - + \ No newline at end of file From 6010120f83085c8a512161ff41816d635c0638ca Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Feb 2019 13:21:26 +0100 Subject: [PATCH 49/54] Update upgrade for importing without sso --- scripts/upgrade | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index ca00b43..6134482 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -67,6 +67,9 @@ fi #================================================= # Import Yunohost template #================================================= +#disable sso temporaly +ynh_app_setting_set $app unprotected_uris "/" +systemctl reload nginx zabbixFullpath=https://$domain$path_url localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") sudoUserPpath=$(find /var/cache/yunohost/ -name "etc_sudoers.d_zabbix") @@ -212,8 +215,20 @@ then cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/ rm -fr /tmp/zabbix* - + + #================================================= + # SETUP SSOWAT + #================================================= + + # Make app public if necessary + if [ $is_public -eq 1 ] + then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set $app unprotected_uris "/" + fi + systemctl reload nginx + yunohost app ssowatconf else ynh_print_info "No update from repo ! (Already up to date)" fi From 24bce62673134f1f882b857c7cb52b52ce5f3c90 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Feb 2019 13:21:58 +0100 Subject: [PATCH 50/54] Update upgrade --- scripts/upgrade | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index 6134482..afc881d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -225,6 +225,8 @@ then then # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set $app unprotected_uris "/" + else + ynh_app_setting_set $app unprotected_uris "" fi systemctl reload nginx From 96e192de6e82926d7d2cb0e7a9f0f2770ec3dd0f Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Feb 2019 13:23:21 +0100 Subject: [PATCH 51/54] Update upgrade --- scripts/upgrade | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index afc881d..e09694c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -70,6 +70,8 @@ fi #disable sso temporaly ynh_app_setting_set $app unprotected_uris "/" systemctl reload nginx +yunohost app ssowatconf + zabbixFullpath=https://$domain$path_url localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") sudoUserPpath=$(find /var/cache/yunohost/ -name "etc_sudoers.d_zabbix") From 6d9b9aaf76df52d8f26f3e4f64b1dcecca3d9aaa Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Feb 2019 13:24:45 +0100 Subject: [PATCH 52/54] Update upgrade --- scripts/upgrade | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index e09694c..b8af9f6 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -217,25 +217,26 @@ then cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/ rm -fr /tmp/zabbix* - - #================================================= - # SETUP SSOWAT - #================================================= - - # Make app public if necessary - if [ $is_public -eq 1 ] - then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" - else - ynh_app_setting_set $app unprotected_uris "" - fi - - systemctl reload nginx - yunohost app ssowatconf + else ynh_print_info "No update from repo ! (Already up to date)" fi else ynh_print_info "No update from repo ! (Trusted version)" fi + +#================================================= +# RE-ENABLE SSOWAT +#================================================= + +# Make app public if necessary +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set $app unprotected_uris "/" +else + ynh_app_setting_set $app unprotected_uris "" +fi + +systemctl reload nginx +yunohost app ssowatconf \ No newline at end of file From fcee0467a06b1ffe9ebca7fc7fcf74656b669b15 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Feb 2019 13:29:14 +0100 Subject: [PATCH 53/54] Update upgrade --- scripts/upgrade | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index b8af9f6..839c396 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -57,16 +57,17 @@ fi haveDefaultAdminDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") if [ "$haveDefaultAdminDisabled" -eq 1 ] ;then - echo "Enable default admin" + ynh_print_info "Enable default admin" #enable default admin temporaly mysql -u$db_user -p$db_pwd $db_name -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" else - echo "default admin already enabled" + ynh_print_info "default admin already enabled" fi #================================================= # Import Yunohost template #================================================= +ynh_print_info "Import Yunohost template" #disable sso temporaly ynh_app_setting_set $app unprotected_uris "/" systemctl reload nginx @@ -167,7 +168,7 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= # STANDARD UPGRADE STEPS #================================================= - +ynh_print_info "Check if new zabbix version is available on repo" ynh_package_update zabbixServerInstalledVersion=$(apt-cache policy zabbix-server-mysql | grep -Po "Installed: \K(.*)") @@ -228,7 +229,7 @@ fi #================================================= # RE-ENABLE SSOWAT #================================================= - +ynh_print_info "re-enable SSOWAT" # Make app public if necessary if [ $is_public -eq 1 ] then From 69370c2e5d8b089592477e311863f6e16caf3612 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Feb 2019 13:52:33 +0100 Subject: [PATCH 54/54] Update upgrade to allow 1:4.0.4-1+stretch zabbix version --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 839c396..9acf0ca 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= app=$YNH_APP_INSTANCE_NAME -trustedversion="4.0.3-1+stretch" +trustedversion="1:4.0.4-1+stretch" domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) admin=$(ynh_app_setting_get $app admin)