Skip to content

Instantly share code, notes, and snippets.

@ngadmini
Last active November 13, 2023 09:32
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ngadmini/7f9df377999cc78c1b58e361d5425ac4 to your computer and use it in GitHub Desktop.
Save ngadmini/7f9df377999cc78c1b58e361d5425ac4 to your computer and use it in GitHub Desktop.
remove naged subscription message on proxmox 7.x-x

remove naged subscription message on proxmox 7.x-x

TL;DR

there are 2 files that are targeted for modification, i.e:

  1. /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js coming from proxmox-widget-toolkit package
  2. /usr/share/perl5/PVE/API2/Subscription.pm coming from pve-manager package
root@pve:~# grep -n 'notfound' /usr/share/perl5/PVE/API2/Subscription.pm 
117:            status => "notfound",
root@pve:~# grep -PnB1 -A1 '^\t.*.toLowerCase.*{$' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js 
513-                if (res === null || res === undefined || !res || res
514:                    .data.status.toLowerCase() !== 'active') {
515-                    Ext.Msg.show({

use this to get rid nag message manually :

by running this below you will get 3 scripts, i.e:

  • pve_proxjs_sed.sh
  • pve_proxjs_patch.sh
  • pve_API2Subs_sed.sh
#!/usr/bin/env bash
# TAGS
#   /usr/local/bin/grab_no_hook.sh
# VERSION
#   v10.1
# AUTHOR
#   ngadimin@warnet-ersa.net
#   https://github.com/ngadmini
#   https://gist.github.com/ngadmini
# TL;DR
#   grab 'pve_proxjs_sed.sh, pve_proxjs_patch.sh and pve_API2Sub_sed.sh' from "https://gist.github.com/ngadmini/7f9df377999cc78c1b58e361d5425ac4"
#   choose one from above to get rid of nag messages
#+  you may run everytime 'proxmox-widget-toolkit or pve-manager' updated

set -e
PATH=/usr/local/bin:/usr/bin:/bin:${PATH}
_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
_API="https://api.github.com/gists/7f9df377999cc78c1b58e361d5425ac4"

clear
cd "${_DIR}"
printf "\n[INFO] starting %s ...\n" "${0##*/}"

for _x in {pve_proxjs_sed.sh,pve_proxjs_patch.sh,pve_API2Subs_sed.sh}; do
   _RAW=$(curl -s "${_API}" | grep -E "\"raw_.*$_x\",$" | awk -F\" '{print $4}')
   printf "[INFO] grabbing %s\n" "${_x}"
   curl -s "${_RAW}" > "${_x}"
   response=$?

   if [ $response -ne 0 ]; then
      printf "[FAIL] could not download file from %s\n" "${_RAW}"
      exit 1
   else
      chmod +x "${_x}"
   fi
done

printf "[DONE] bye!\n\n"
exit 0

use this to get rid nag message by APT-invocation :

by running this below you will get 3 scripts, i.e:

  • pve_proxjs_sed_hook.sh
  • pve_proxjs_patch_hook.sh
  • pve_API2Subs_sed_hook.sh

by APT-invocation :

  • script was executed via sh -c after the dpkg run
  • front-ends might call dpkg several times per invocation, which might run the hooks more times than expected
#!/usr/bin/env bash
# TAGS
#   /usr/local/bin/grab_hook.sh
# VERSION
#   v10.1
# AUTHOR
#   ngadimin@warnet-ersa.net
#   https://github.com/ngadmini
#   https://gist.github.com/ngadmini
# TL;DR
#   grab pve_proxjs_sed_hook.sh, pve_proxjs_patch_hook.sh and pve_API2Subs_sed_hook.sh from : "https://gist.github.com/ngadmini/7f9df377999cc78c1b58e361d5425ac4"
#   choose one from above to get rid of nag messages

set -e
PATH=/usr/local/bin:/usr/bin:/bin:${PATH}
_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
_API="https://api.github.com/gists/7f9df377999cc78c1b58e361d5425ac4"

clear
cd "${_DIR}"
printf "\n[INFO] starting %s ...\n" "${0##*/}"

for _x in {pve_proxjs_sed.sh,pve_proxjs_patch.sh,pve_API2Subs_sed.sh}; do
   _RAW=$(curl -s "${_API}" | grep -E "\"raw_.*$_x\",$" | awk -F\" '{print $4}')
   HOOK="${_x/./_hook.}"
   _tee="tee -a /etc/apt/apt.conf.d/99_${HOOK/.sh/}"
   _tag="\/usr\/local\/bin\/${HOOK}"      # you can change to another dir location
   comment="// remove naging proxmox subscription message"
   hook="DPkg::Post-Invoke { \"${_tag/\\/}\"; };"

   printf "[INFO] grabbing %s\n" "${HOOK}"
   curl -s "${_RAW}" > "${HOOK}"
   response=$?

   if [ $response -ne 0 ]; then
      printf "[FAIL] could not download file from %s\n" "${_RAW}"
      exit 1
   else
      sed -i 's/] starting/] Running hook script/g' "${HOOK}"
      sed -i "3s/^.*$/#   ${_tag}/;s/\; exit 1$//g;s/#.*NO.*$/#   howto:/" "${HOOK}"
      sed -i "/.*howto:$/a#   ~ echo '${comment}' | ${_tee}" "${HOOK}"
      sed -i "/.*echo '.*/a#   ~ echo '${hook}' | ${_tee}" "${HOOK}"
      sed -i "/.*echo 'D.*/a#   ~ mv ${_x} ${_tag/${HOOK}/}" "${HOOK}"
      sed -i "/.*mv .*/a#   ~ chmod +x ${_tag}" "${HOOK}"

      if [[ ${_x} == pve_API2Subs_sed.sh ]]; then
         sed -i "/.*chmod .*/a#   ~ apt install --reinstall pve-manager" "${HOOK}"
      else
         sed -i "/.*chmod .*/a#   ~ apt install --reinstall proxmox-widget-toolkit" "${HOOK}"
      fi
      sed -i "/#   ~ apt.*/a#   ~ apt-config dump | grep '${HOOK}'" "${HOOK}"
   fi
done

printf "[HINT] You must create a file in '%s' first,\n" "/etc/apt/apt.conf.d/"
printf "\tto auto-execute one of the following hook-scripts:\n"
printf "\tpve_API2Subs_sed_hook.sh, pve_proxjs_sed_hook.sh, OR pve_proxjs_patch_hook.sh\n"
printf "[HINT] Please see 'TL;DR' section at each script above\n"
printf "[DONE] bye!\n\n"

exit 0

revert the changes

you have four options to revert the changes:

  • manually edit proxmoxlib.js or Subscription.pm to undo the changes you made, depending your methode.
  • if using pve_proxjs_patch.sh for proxmoxlib.js, run: patch -R proxmoxlib.js < nag_patch
  • restore the backup file *.dpkg-dist from directory:
    • /usr/share/perl5/PVE/API2/Subscription.pm.dpkg-dist
    • /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js.dpkg-dist
  • if your methode are APT-invocation, delete the appropriate file: /etc/apt/apt.conf.d/99_pve_* then run apt-get install --reinstall proxmox-widget-toolkit or apt-get install --reinstall pve-manager

disclaimer

do it with your own risk

#!/usr/bin/env bash
# TAGS
# /usr/local/bin/pve-API2Subs_sed.sh
# https://gist.github.com/ngadmini/7f9df377999cc78c1b58e361d5425ac4#file-pve_api2subs-sh
# AUTHOR
# ngadimin@warnet-ersa.net
# https://github.com/ngadmini
# https://gist.github.com/ngadmini
# VERSION
# v10.5
# TL;DR
# NOT intended to apt invocation
set -e
PATH=/usr/local/bin:/usr/bin:/bin:${PATH}
_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
_PVE=/usr/share/perl5/PVE/API2/Subscription.pm
cd "${_DIR}"; printf "\n[INFO] Running hook script: %s ...\n" "${0##*/}"
if [[ -f ${_PVE} ]]; then
if grep -q 'active\",$' "${_PVE}"; then
printf "[INFO] %s has been modified since installation. exiting ...\n\n" "${_PVE##*/}"; exit 1
else
sed -i.dpkg-dist 's/notfound/active/g' "${_PVE}"
_ACT=$(grep -n 'active\",$' ${_PVE} | cut -d: -f1)
printf "[INFO] modifying %s at line %s\n" "${_PVE##*/}" "${_ACT}"
printf "please check: ~ nano +%s %s\n" "${_ACT}" "${_PVE}"
printf "[DONE] please try login to %s after\n" "$(hostname -I | sed 's/ $/:8006/')"
printf "[INFO] restarting pveproxy.service with:\n\tsystemctl restart pveproxy.service\n"
fi
else
printf "[INFO] %s NOT installed. exiting ...\n\n" "${_PVE##*/}"; exit 1
fi
exit 0
#!/usr/bin/env bash
# TAGS
# /usr/local/bin/pve_proxjs_patch.sh
# https://gist.github.com/ngadmini/7f9df377999cc78c1b58e361d5425ac4#file-pve_proxjs_patch-sh
# AUTHOR
# ngadimin@warnet-ersa.net
# https://github.com/ngadmini
# https://gist.github.com/ngadmini
# VERSION
# v10.5
# TL;DR
# based on: https://www.geekdecoder.com/how-to-remove-you-do-not-have-a-valid-subscription-for-this-server-on-proxmox/
# NOT intended to apt invocation
set -e
PATH=/usr/local/bin:/usr/bin:/bin:${PATH}
_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
_PVE=/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
cd "${_DIR}"; printf "\n[INFO] starting %s ...\n" "${0##*/}"
if [[ -f ${_PVE} ]]; then
if grep -Pq '^(//.*({|res)|\t.*if \(fa.*{)$' "${_PVE}"; then
printf "[INFO] %s modified since installation. exiting ...\n\n" "${_PVE##*/}"; exit 1
else
if ! [[ -f nag_patch ]]; then
# proxmox-widget-toolkit.3.5.2 to 3.5.4 --use--> @@ -510,8 +510,9 @@
# proxmox-widget-toolkit.3.5.5 --use--> @@ -516,8 +516,9 @@
# proxmox-widget-toolkit.3.6.3 to 3.6.5 --use--> @@ -543,8 +543,9 @@
# proxmox-widget-toolkit.3.7.0 to 3.7.3 --use--> @@ -543,8 +543,9 @@
cat <<eof>> nag_patch
@@ -543,8 +543,9 @@
},
success: function(response, opts) {
let res = response.result;
- if (res === null || res === undefined || !res || res
- .data.status.toLowerCase() !== 'active') {
+// if (res === null || res === undefined || !res || res
+// .data.status.toLowerCase() !== 'active') {
+ if (false) {
Ext.Msg.show({
title: gettext('No valid subscription'),
icon: Ext.Msg.WARNING,
eof
fi
mapfile -t ar_num < <(grep -PnB1 -A1 '^\t.*.toLowerCase.*{$' "${_PVE}" | awk -F'-|:' '{print $1}')
patch "${_PVE}" < nag_patch
printf "[INFO] patching %s at line %s-%s\n" "${_PVE##*/}" "${ar_num[0]}" "${ar_num[1]}"
printf "please check: ~ nano +%s %s\n" "${ar_num[2]}" "${_PVE}"
printf "[INFO] restarting pveproxy.service ...\n"
systemctl restart pveproxy.service
printf "[DONE] please try login to %s\n\n" "$(hostname -I | sed 's/ $/:8006/')"
unset -v ar_num
fi
else
printf "[FAIL] %s NOT found. exiting ...\n\n" "${_PVE##*/}"; exit 1
fi
exit 0
#!/usr/bin/env bash
# TAGS
# /usr/local/bin/pve_proxjs_sed.sh
# https://gist.github.com/ngadmini/7f9df377999cc78c1b58e361d5425ac4#file-pve_proxjs_sed-sh
# AUTHOR
# ngadimin@warnet-ersa.net
# https://github.com/ngadmini
# https://gist.github.com/ngadmini
# VERSION
# v10.5
# TL;DR
# based on: https://www.geekdecoder.com/how-to-remove-you-do-not-have-a-valid-subscription-for-this-server-on-proxmox/
# NOT intended to apt invocation.
set -e
PATH=/usr/local/bin:/usr/bin:/bin:${PATH}
_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
_PVE=/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
cd "${_DIR}"; printf "\n[INFO] starting %s ...\n" "${0##*/}"
if [[ -f ${_PVE} ]]; then
if grep -q '^/.*\({\|res\)$' "${_PVE}"; then
printf "[INFO] %s modified since installation. exiting ...\n\n" "${_PVE##*/}"; exit 1
else
mapfile -t ar_num < <(grep -PnB1 -A1 '^\t.*.toLowerCase.*{$' "${_PVE}" | awk -F'-|:' '{print $1}')
sed -i.dpkg-dist "${ar_num[0]},${ar_num[1]}s/^/\/\//;${ar_num[2]} i \\\t\t\tif (false) {" "${_PVE}"
printf "[INFO] modifying %s at line %s-%s\n" "${_PVE##*/}" "${ar_num[0]}" "${ar_num[1]}"
printf "please check: ~ nano +%s %s\n" "${ar_num[2]}" "${_PVE}"
printf "[INFO] restarting pveproxy.service ...\n"
systemctl restart pveproxy.service
printf "[DONE] please try login to %s\n\n" "$(hostname -I | sed 's/ $/:8006/')"
unset -v ar_num
fi
else
printf "[FAIL] %s NOT found. exiting ...\n\n" "${_PVE##*/}"; exit 1
fi
exit 0
@ngadmini
Copy link
Author

ngadmini commented Feb 21, 2023

mini how-to

grabing scripts in readme.md :

  • grab_no_hook.sh if you want getting rid nag message manually

    • save (and as) in dir: /usr/local/bin/grab_no_hook.sh
      ~# gist_1="7f9df377999cc78c1b58e361d5425ac4"
      ~# gist_2="ecf373c9b1597ee173c64d0862f8eed3318d71ca"
      ~# _file="/usr/local/bin/grab_no_hook.sh"
      ~# target="https://gist.githubusercontent.com/ngadmini/${gist_1}/raw/${gist_2}/readme.md"
      ~# curl -s "${target}" | sed '62,$d;1,22d' > ${_file}
    • run it
      ~# bash ${_file}
      ~# unset _file gist_1 gist_2 target
    • you will get 3 files, ie:
      • pve_proxjs_sed.sh
      • pve_proxjs_patch.sh
      • pve_API2Subs_sed.sh
    • run one of the scripts above, to get rid nag message manually
  • grab_hook.sh if you want getting rid nag message by APT-invocation

    • save (and as) in dir: /usr/local/bin/grab_hook.sh
      ~# gist_1="7f9df377999cc78c1b58e361d5425ac4"
      ~# gist_2="ecf373c9b1597ee173c64d0862f8eed3318d71ca"
      ~# _file="/usr/local/bin/grab_hook.sh"
      ~# target="https://gist.githubusercontent.com/ngadmini/${gist_1}/raw/${gist_2}/readme.md"
      ~# curl -s "${target}" | sed '134,$d;1,72d' > ${_file}
    • run it
      ~# bash ${_file} 
      ~# unset _file gist_1 gist_2 target
    • you will get 3 files, ie:
      • pve_proxjs_sed_hook.sh
      • pve_proxjs_patch_hook.sh
      • pve_API2Subs_sed_hook.sh
    • select one and see TL;DR section at selected script to get rid nag message by APT-invocation
  • total 6 scripts, but you just need one

  • other way is (but not checked):

    ~ grep -n 'checked_command:\sfunction(orig_cmd)\s{$' *_proxmoxlib.js
    proxmox-widget-toolkit-3.5.2_proxmoxlib.js:503:    checked_command: function(orig_cmd) {
    proxmox-widget-toolkit-3.5.3_proxmoxlib.js:503:    checked_command: function(orig_cmd) {
    proxmox-widget-toolkit-3.5.5_proxmoxlib.js:509:    checked_command: function(orig_cmd) {
    proxmox-widget-toolkit-3.6.3_proxmoxlib.js:536:    checked_command: function(orig_cmd) {
    ~ sed -i 's/checked_command:\s*function(orig_cmd)\s*{\s*$/& orig_cmd(); return;/' proxmoxlib.js 

good luck, bro.

@oskardotglobal
Copy link

oskardotglobal commented Mar 26, 2023

pve_API2Subs_sed_hook.sh works fine on PVE 7.4-3
I tried the proxmoxlib.js version (not this exact script) and it didn't work

@chron0
Copy link

chron0 commented Mar 27, 2023

sames for me with pve_proxjs_patch_hook.sh:

Setting up proxmox-widget-toolkit (3.6.4) ...

[INFO] Running hook script: pve_API2Subs_sed_hook.sh ...
[INFO] Subscription.pm has been modified since installation. exiting ...


[INFO] Running hook script pve_proxjs_patch_hook.sh ...
patching file /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
Hunk #1 FAILED at 543.
1 out of 1 hunk FAILED -- saving rejects to file /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js.rej
E: Problem executing scripts DPkg::Post-Invoke '/usr/local/bin/pve_proxjs_patch_hook.sh'
E: Sub-process returned an error code

with the following reject:

--- /dev/null
+++ /dev/null
@@ -543,8 +543,9 @@
      },
      success: function(response, opts) {
          let res = response.result;
-         if (res === null || res === undefined || !res || res
-        .data.status.toLowerCase() !== 'active') {
+//          if (res === null || res === undefined || !res || res
+//         .data.status.toLowerCase() !== 'active') {
+        if (false) {
         Ext.Msg.show({
             title: gettext('No valid subscription'),
             icon: Ext.Msg.WARNING,

@chron0
Copy link

chron0 commented Mar 27, 2023

guessing there is a shift in 3.6.4 going by the script:

# proxmox-widget-toolkit.3.6.3 --use--> @@ -543,8 +543,9 @@

dont have the older ones so I could compare, but will try to figure it out...

@chron0
Copy link

chron0 commented Mar 27, 2023

this seems to work now:

@@ -543,9 +543,8 @@
                },
                success: function(response, opts) {
                    let res = response.result;
-                   if (res === null || res === undefined || !res || res
-                       .data.status.toLowerCase() !== 'active') {
-                       Ext.Msg.show({
+                   if (false) {
+                   Ext.Msg.show({
                            title: gettext('No valid subscription'),
                            icon: Ext.Msg.WARNING,
                            message: Proxmox.Utils.getNoSubKeyHtml(res.data.url),

@chron0
Copy link

chron0 commented Mar 27, 2023

what I am currently still unsure of - should all 3 of these hooks be installed?

@ngadmini
Copy link
Author

what I am currently still unsure of - should all 3 of these hooks be installed?

You just need one

@ngadmini
Copy link
Author

ngadmini commented Mar 28, 2023

this seems to work now:

@@ -543,9 +543,8 @@
                },
                success: function(response, opts) {
                    let res = response.result;
-                   if (res === null || res === undefined || !res || res
-                       .data.status.toLowerCase() !== 'active') {
-                       Ext.Msg.show({
+                   if (false) {
+                   Ext.Msg.show({
                            title: gettext('No valid subscription'),
                            icon: Ext.Msg.WARNING,
                            message: Proxmox.Utils.getNoSubKeyHtml(res.data.url),

there are little difference with your patch. we use comment then insert for patch-file.

~ diff -u proxmoxlib.js.dpkg-dist proxmoxlib.js > PatchFile
~ less PatchFile
--- proxmoxlib.js.dpkg-dist     2023-03-28 17:37:59.566978288 +0700
+++ proxmoxlib.js       2023-03-28 17:39:31.664716139 +0700
@@ -543,8 +543,9 @@
                },
                success: function(response, opts) {
                    let res = response.result;
-                   if (res === null || res === undefined || !res || res
-                       .data.status.toLowerCase() !== 'active') {
+//                 if (res === null || res === undefined || !res || res
+//                     .data.status.toLowerCase() !== 'active') {
+                       if (false) {
                        Ext.Msg.show({
                            title: gettext('No valid subscription'),
                            icon: Ext.Msg.WARNIN

it's still work fine on proxmox-widget-toolkit-3.6.4

[INFO] Running hook script pve_proxjs_patch_hook.sh ...
patching file /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
Hunk #1 succeeded at 543 (offset 27 lines).
[INFO] patching proxmoxlib.js at line 546-547
please check: ~ nano +548 /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
[INFO] restarting pveproxy.service ...
[DONE] please try login to 172.30.253.250:8006

maybe you run 2 hook-script in /etc/apt/apt.conf.d. You need just one hook-script.
writing format nag_patch use Spaces not Tabs, causes patching FAILED. it's fixed by switch to Tabs in writing format

@ngadmini
Copy link
Author

ngadmini commented Mar 28, 2023

I tried the proxmoxlib.js version (not this exact script) and it didn't work

it's still work regarding to line 546 - 547 in proxmoxlib.js ( proxmox-widget-toolkit-3.6.4 ) =

~ grep -PnB1 -A1 '^\t.*.toLowerCase.*{$' proxmoxlib.js.dpkg-dist
546-                if (res === null || res === undefined || !res || res
547:                    .data.status.toLowerCase() !== 'active') {
548-                    Ext.Msg.show({

changing to =

~ grep -PnB3 -A1 'if \(false\) {$' proxmoxlib.js
545-                let res = response.result;
546-//              if (res === null || res === undefined || !res || res
547-//                  .data.status.toLowerCase() !== 'active') {
548:                    if (false) {
549-                    Ext.Msg.show({

@chron0
Copy link

chron0 commented Mar 28, 2023

ah, that makes sense - so is the api (subscription.pm) method the preferred/most clean one?

@ngadmini
Copy link
Author

ah, that makes sense - so is the api (subscription.pm) method the preferred/most clean one?

i'm not sure it's clean or not. but my preferring is pve_API2Subs_sed_hook.sh and it's work on pve-manager: 7.4-3 (running version: 7.4-3/9002ab8a)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment