diff --git a/scripts/postinst b/scripts/postinst index da7c9c6..ad8ed91 100755 --- a/scripts/postinst +++ b/scripts/postinst @@ -1,39 +1,44 @@ #!/bin/sh -after_upgrade() { - : +DEBSYSTEMCTL=$(command -v deb-systemd-invoke || echo systemctl) +after_upgrade() { if command -v systemctl >/dev/null; then systemctl --system daemon-reload >/dev/null || true - debsystemctl=$(command -v deb-systemd-invoke || echo systemctl) - if ! systemctl is-enabled pve-fake-subscription.timer >/dev/null - then - : # Ensure this if-clause is not empty. If it were empty, and we had an 'else', then it is an error in shell syntax - systemctl preset pve-fake-subscription.timer >/dev/null || true - $debsystemctl start pve-fake-subscription.timer >/dev/null || true + + if ! systemctl is-enabled fake-proxmox-subscription.timer >/dev/null; then + # Ensure this if-clause is not empty. + # If it was empty, and we had an 'else', then it is an error in shell syntax. + systemctl preset fake-proxmox-subscription.timer >/dev/null || true + $DEBSYSTEMCTL start fake-proxmox-subscription.timer >/dev/null || true + else - $debsystemctl restart pve-fake-subscription.timer >/dev/null || true + $DEBSYSTEMCTL restart fake-proxmox-subscription.timer >/dev/null || true + fi + else - ln -sf /usr/bin/pve-fake-subscription /etc/cron.hourly/pve-fake-subscription + ln -sf /usr/bin/fake-proxmox-subscription /etc/cron.hourly/fake-proxmox-subscription + fi - pve-fake-subscription + # Execute the fake-proxmox-subscription script: + /usr/bin/fake-proxmox-subscription } after_install() { - : - if command -v systemctl >/dev/null; then systemctl --system daemon-reload >/dev/null || true - debsystemctl=$(command -v deb-systemd-invoke || echo systemctl) - systemctl preset pve-fake-subscription.timer >/dev/null || true - $debsystemctl start pve-fake-subscription.timer >/dev/null || true + systemctl preset fake-proxmox-subscription.timer >/dev/null || true + $DEBSYSTEMCTL start fake-proxmox-subscription.timer >/dev/null || true + else - ln -sf /usr/bin/pve-fake-subscription /etc/cron.hourly/pve-fake-subscription + ln -sf /usr/bin/fake-proxmox-subscription /etc/cron.hourly/fake-proxmox-subscription + fi - pve-fake-subscription + # Execute the fake-proxmox-subscription script: + /usr/bin/fake-proxmox-subscription } if { [ "${1}" = "configure" ] && [ -z "${2}" ]; } || [ "${1}" = "abort-remove" ]; then @@ -42,15 +47,18 @@ if { [ "${1}" = "configure" ] && [ -z "${2}" ]; } || [ "${1}" = "abort-remove" ] # In that case, this script, which should be idemptoent, is run # to ensure a clean roll-back of the removal. after_install + elif [ "${1}" = "configure" ] && [ -n "${2}" ]; then - upgradeFromVersion="${2}" + UPGRADEDFROMVERSION="${2}" # "after upgrade" here # NOTE: This slot is also used when deb packages are removed, # but their config files aren't, but a newer version of the # package is installed later, called "Config-Files" state. # basically, that still looks a _lot_ like an upgrade to me. after_upgrade "${2}" + elif echo "${1}" | grep -E -q "(abort|fail)"; then echo "Failed to install before the post-installation script was run." >&2 exit 1 + fi diff --git a/scripts/postrm b/scripts/postrm index 77de063..003c242 100755 --- a/scripts/postrm +++ b/scripts/postrm @@ -1,21 +1,18 @@ #!/bin/sh after_remove() { - : - rm -f /etc/subscription rm -f /etc/pmg/subscription rm -f /etc/proxmox-backup/subscription - - rm -f /etc/cron.hourly/pve-fake-subscription + rm -f /etc/cron.hourly/fake-proxmox-subscription } after_purge() { - : + true } dummy() { - : + true } if [ "${1}" = "remove" ] || [ "${1}" = "abort-install" ]; then @@ -24,11 +21,13 @@ if [ "${1}" = "remove" ] || [ "${1}" = "abort-install" ]; then # In that case, this script, which should be idemptoent, is run # to ensure a clean roll-back of the installation. after_remove + elif [ "${1}" = "purge" ] && [ -z "${2}" ]; then # like "on remove", but executes after dpkg deletes config files # 'apt-get purge' runs 'on remove' section, then this section. # There is no equivalent in RPM or ARCH. after_purge + elif [ "${1}" = "upgrade" ]; then # This represents the case where the old package's postrm is called after # the 'preinst' script is called. @@ -37,7 +36,9 @@ elif [ "${1}" = "upgrade" ]; then # upgrade, not the uninstalled one, since it can't anticipate what new # things it will have to do to upgrade for the new version. dummy + elif echo "${1}" | grep -E -q '(fail|abort)'; then echo "Failed to install before the post-removal script was run." >&2 exit 1 + fi diff --git a/scripts/prerm b/scripts/prerm index fdb3552..9b8b9d0 100755 --- a/scripts/prerm +++ b/scripts/prerm @@ -1,29 +1,31 @@ #!/bin/sh -before_remove() { - : +DEBSYSTEMCTL=$(command -v deb-systemd-invoke || echo systemctl) - debsystemctl=$(command -v deb-systemd-invoke || echo systemctl) - $debsystemctl stop pve-fake-subscription.timer >/dev/null || true - systemctl disable pve-fake-subscription.timer >/dev/null || true +before_remove() { + $DEBSYSTEMCTL stop fake-proxmox-subscription.timer >/dev/null || true + systemctl disable fake-proxmox-subscription.timer >/dev/null || true systemctl --system daemon-reload >/dev/null || true } dummy() { - : + true } if [ "${1}" = "remove" ] && [ -z "${2}" ]; then - # "before remove" goes here + # "before remove" goes here: before_remove + elif [ "${1}" = "upgrade" ]; then - # Executed before the old version is removed - # upon upgrade. - # We should generally not do anything here. The newly installed package - # should do the upgrade, not the uninstalled one, since it can't anticipate - # what new things it will have to do to upgrade for the new version. + # This section is executed before the old version is removed upon upgrade. + # Generally, we should not be doing anything here for the purposes of this + # package. The newly installed package should do the upgrade, not the + # uninstalled one. This is mainly because the uninstalled one cannot + # anticipate what the updated package will change. dummy + elif echo "${1}" | grep -E -q "(fail|abort)"; then echo "Failed to install before the pre-removal script was run." >&2 exit 1 + fi diff --git a/usr/bin/pve-fake-subscription b/usr/bin/fake-proxmox-subscription similarity index 62% rename from usr/bin/pve-fake-subscription rename to usr/bin/fake-proxmox-subscription index 41e1798..550fb25 100755 --- a/usr/bin/pve-fake-subscription +++ b/usr/bin/fake-proxmox-subscription @@ -1,8 +1,16 @@ #!/usr/bin/env python3 -# Pollute Proxmox software subscription cache so it won't alert you on dashboard login -# Should be scheduled to run every few hours with a timer to prevent cache from expiring -# If you need to prevent it checking keys against a server, please block "shop.maurer-it.com" in your hosts file +""" +Pollutes the Proxmox software subscription cache so it won't doesn't nag you +on login. + +The script should be scheduled to run every few hours using a timer to prevent +the cache from expiring. + +If you need to prevent it from checking keys against a server, block +"shop.maurer-it.com" in your /etc/hosts file (or block network traffic to the +host) +""" from __future__ import print_function import hashlib @@ -14,38 +22,46 @@ import sys import os from datetime import datetime, timedelta + # PVE & PMG: /usr/share/perl5/PVE/Subscription.pm -# PBS: /usr/lib/x86_64-linux-gnu/proxmox-backup/* (source code at `https://git.proxmox.com/git/proxmox-backup.git`) +# PBS: /usr/lib/x86_64-linux-gnu/proxmox-backup/* +# (Source code available at https://git.proxmox.com/?p=proxmox-backup.git) shared_key_data = "kjfdlskfhiuewhfk947368" server_key_file = "/etc/ssh/ssh_host_rsa_key.pub" -# Default license keys -lic_pve = "pve8p-1145141919" -lic_pmg = "pmgp-1145141919" -lic_pbs = "pbst-1145141919" +# Default license keys: +license_pve = "pve8p-1145141919" +license_pmg = "pmgp-1145141919" +license_pbs = "pbst-1145141919" + +# UI customization: +ui_product_name = "Proxmox" +ui_message = "Jamesits and Arszilla has got your back" +ui_url = "https://github.com/Arszilla/fake-proxmox-subscription" -# UI customization -ui_product_name = "YajuuSenpai" -ui_message = "Yajuu Senpai has got your back" -ui_url = "https://github.com/Jamesits/pve-fake-subscription" def get_timestamp(): return int(time.time()) -# Perl's md5_base64 implementation -def md5_base64_perl(x): - return base64.b64encode(hashlib.md5(x.encode()).digest()).strip(b'=').decode() -# Rust's `base64::encode(tools::md5sum("something")?);` +# Perl's md5_base64 implementation: +def md5_base64_perl(x): + return base64.b64encode(hashlib.md5(x.encode()).digest()).strip(b"=").decode() + + +# Rust's 'base64::encode(tools::md5sum("something")?);': def md5_base64_rs(x): return base64.b64encode(hashlib.md5(x.encode()).digest()).decode() + def generate_server_id(key): return hashlib.md5(key.encode()).hexdigest().upper() + def dt_string(format, offset_secs=0): return (datetime.now() + timedelta(seconds=offset_secs)).strftime(format) + def generate_subscription_pve_pmg(key, server_ids, product_name=ui_product_name): localinfo = { "checktime": get_timestamp(), @@ -63,74 +79,84 @@ def generate_subscription_pve_pmg(key, server_ids, product_name=ui_product_name) return key + "\n" + csum + "\n" + data + "\n" -# key_pattern can be find in /usr/share/perl5/{PVE,PMG}/API2/Subscription.pm -# PVE5+: r'pve([1248])([cbsp])-[0-9a-f]{10}' -# PVE3/4: r'pve([124])([cbsp])-[0-9a-f]{10}' -# PMG: r'pmg([cbsp])-[0-9a-f]{10}' + +# key_pattern can be found in /usr/share/perl5/{PVE,PMG}/API2/Subscription.pm +# PVE5+: r'pve([1248])([cbsp])-[0-9a-f]{10}' +# PVE3/4: r'pve([124])([cbsp])-[0-9a-f]{10}' +# PMG: r'pmg([cbsp])-[0-9a-f]{10}' def activate_pve_pmg(key, subscription_file, *args, **kwargs): - # check if the key format is correct + # Check if the key format is correct: # pattern = re.compile(key_pattern) # if not pattern.match(key): # print("key format error", file=sys.stderr) # sys.exit(1) - # get machine ID + # Get machine ID: server_id = "" with open(server_key_file, "r") as f: server_id = generate_server_id(f.read()) - # generate a license file + # Generate a license file: subscription = generate_subscription_pve_pmg(key, [server_id], *args, **kwargs) - # write license file + # Write the license file: with open(subscription_file, "w") as f: f.write(subscription) + def generate_subscription_pbs(key, server_ids, product_name=ui_product_name, message=ui_message, url=ui_url): localinfo = { - "status": "active", # PBS: `new`, `notfound`, `active`, `invalid` + # Possible values for "status" in PBS: + # - new + # - notfound + # - active + # - invalid + "status": "active", "serverid": ",".join(server_ids), "checktime": get_timestamp(), "key": key, "message": message, "productname": product_name, "regdate": dt_string("%Y-%m-%d %H:%M:%S"), - "nextduedate": dt_string("%Y-%m-%d", 1296000), # 1296000: MAX_LOCAL_KEY_AGE in src/tools/subscription.rs + # 1296000 is the MAX_LOCAL_KEY_AGE in src/tools/subscription.rs + "nextduedate": dt_string("%Y-%m-%d", 1296000), "url": url, } data = base64.standard_b64encode(json.dumps(localinfo).encode()).decode() cat = str(localinfo["checktime"]) + data + shared_key_data - csum = md5_base64_rs(cat) + checksum = md5_base64_rs(cat) + + return key + "\n" + checksum + "\n" + data + "\n" - return key + "\n" + csum + "\n" + data + "\n" # Key pattern: pbst-xxxxxxxxxx def activate_pbs(key, subscription_file, *args, **kwargs): - # get machine ID + # Get machine ID: server_id = "" with open(server_key_file, "r") as f: server_id = generate_server_id(f.read()) - # generate a license file + # Generate a license file: subscription = generate_subscription_pbs(key, [server_id], *args, **kwargs) - # write license file + # Write the license file: with open(subscription_file, "w") as f: f.write(subscription) + if __name__ == "__main__": # Proxmox VE if os.path.exists("/etc/pve"): print("Activating Proxmox VE...") - activate_pve_pmg(lic_pve, "/etc/subscription") + activate_pve_pmg(license_pve, "/etc/subscription") # Proxmox Mail Gateway if os.path.exists("/etc/pmg"): print("Activating Proxmox Mail Gateway...") - activate_pve_pmg(lic_pmg, "/etc/pmg/subscription") + activate_pve_pmg(license_pmg, "/etc/pmg/subscription") # Proxmox Backup Server if os.path.exists("/etc/proxmox-backup"): print("Activating Proxmox Backup Server...") - activate_pbs(lic_pbs, "/etc/proxmox-backup/subscription") + activate_pbs(license_pbs, "/etc/proxmox-backup/subscription") diff --git a/usr/lib/systemd/system-preset/fake-proxmox-subscription.preset b/usr/lib/systemd/system-preset/fake-proxmox-subscription.preset new file mode 100644 index 0000000..7a0e5f1 --- /dev/null +++ b/usr/lib/systemd/system-preset/fake-proxmox-subscription.preset @@ -0,0 +1 @@ +enable fake-proxmox-subscription.timer diff --git a/usr/lib/systemd/system-preset/pve-fake-subscription.preset b/usr/lib/systemd/system-preset/pve-fake-subscription.preset deleted file mode 100644 index b9e8888..0000000 --- a/usr/lib/systemd/system-preset/pve-fake-subscription.preset +++ /dev/null @@ -1 +0,0 @@ -enable pve-fake-subscription.timer diff --git a/usr/lib/systemd/system/fake-proxmox-subscription.service b/usr/lib/systemd/system/fake-proxmox-subscription.service new file mode 100644 index 0000000..34289b6 --- /dev/null +++ b/usr/lib/systemd/system/fake-proxmox-subscription.service @@ -0,0 +1,6 @@ +[Unit] +Description=Fake Proxmox Subscription - Service + +[Service] +Type=oneshot +ExecStart=/usr/bin/fake-proxmox-subscription diff --git a/usr/lib/systemd/system/pve-fake-subscription.timer b/usr/lib/systemd/system/fake-proxmox-subscription.timer similarity index 67% rename from usr/lib/systemd/system/pve-fake-subscription.timer rename to usr/lib/systemd/system/fake-proxmox-subscription.timer index f609151..2589e75 100644 --- a/usr/lib/systemd/system/pve-fake-subscription.timer +++ b/usr/lib/systemd/system/fake-proxmox-subscription.timer @@ -1,5 +1,5 @@ [Unit] -Description=Refresh fake Proxmox VE subscription cache every day +Description=Fake Proxmox Subscription - Refresher [Timer] OnActiveSec=0s diff --git a/usr/lib/systemd/system/pve-fake-subscription.service b/usr/lib/systemd/system/pve-fake-subscription.service deleted file mode 100644 index 46eb64d..0000000 --- a/usr/lib/systemd/system/pve-fake-subscription.service +++ /dev/null @@ -1,6 +0,0 @@ -[Unit] -Description=Fake a Proxmox VE subscription - -[Service] -Type=oneshot -ExecStart=/usr/bin/pve-fake-subscription