From d876d274d417b9070bccde4404415f395084d448 Mon Sep 17 00:00:00 2001 From: AuxXxilium Date: Mon, 11 Nov 2024 18:54:25 +0100 Subject: [PATCH 1/4] functions: add new Signed-off-by: AuxXxilium --- files/initrd/opt/arc/arc-functions.sh | 10 ++++++---- files/initrd/opt/arc/include/functions.sh | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/files/initrd/opt/arc/arc-functions.sh b/files/initrd/opt/arc/arc-functions.sh index c22cc98b..1fd1db70 100755 --- a/files/initrd/opt/arc/arc-functions.sh +++ b/files/initrd/opt/arc/arc-functions.sh @@ -911,6 +911,7 @@ function sysinfo() { # Get System Informations [ -d /sys/firmware/efi ] && BOOTSYS="UEFI" || BOOTSYS="BIOS" CPU="$(cat /proc/cpuinfo 2>/dev/null | grep 'model name' | uniq | awk -F':' '{print $2}')" + HWID="$(genHWID)" SECURE=$(dmesg 2>/dev/null | grep -i "Secure Boot" | awk -F'] ' '{print $2}') VENDOR=$(dmesg 2>/dev/null | grep -i "DMI:" | head -1 | sed 's/\[.*\] DMI: //i') ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)" @@ -959,6 +960,7 @@ function sysinfo() { TEXT="" # Print System Informations TEXT+="\n\n\Z4> System: ${MACHINE} | ${BOOTSYS} | ${BUS}\Zn" + TEXT+="\n HardwareID: \Zb${HWID}\Zn" TEXT+="\n Vendor: \Zb${VENDOR}\Zn" TEXT+="\n CPU: \Zb${CPU}\Zn" if [ $(lspci -d ::300 | wc -l) -gt 0 ]; then @@ -1172,8 +1174,8 @@ function getCMDline () { function uploadDiag () { if [ -f "${TMP_PATH}/diag" ]; then - GENHASH=$(cat "${TMP_PATH}/diag" | curl -s -F "content=<-" http://dpaste.com/api/v2/ | cut -c 19-) - dialog --backtitle "$(backtitle)" --title "Sysinfo Upload" --msgbox "Your Code: ${GENHASH}" 5 30 + GENHASH=$(cat "${TMP_PATH}/diag" | curl -s -F "content=<-" "http://arc.auxxxilium.tech?sysinfo=${HWID}") + dialog --backtitle "$(backtitle)" --title "Sysinfo Upload" --msgbox "Your Code: ${HWID}" 5 30 else dialog --backtitle "$(backtitle)" --title "Sysinfo Upload" --msgbox "No Diag File found!" 0 0 fi @@ -2198,7 +2200,7 @@ function getpatfiles() { # Generate HardwareID function genHardwareID() { while true; do - HWID="$(echo $(ifconfig | grep eth0 | awk '{print $NF}' | sed 's/://g') $(cat /proc/cpuinfo | grep "model name" | cut -d':' -f2 | head -1) | sha256sum | awk '{print $1}' | cut -c1-16)" 2>/dev/null + HWID="$(genHWID)" if [ -n "${HWID}" ]; then USERID="$(curl -skL "https://arc.auxxxilium.tech?hwid=${HWID}")" if echo "${USERID}" | grep -vq "Hardware ID"; then @@ -2228,7 +2230,7 @@ function genHardwareID() { ############################################################################### # Check HardwareID function checkHardwareID() { - HWID="$(echo $(ifconfig | grep eth0 | awk '{print $NF}' | sed 's/://g') $(cat /proc/cpuinfo | grep "model name" | cut -d':' -f2 | head -1) | sha256sum | awk '{print $1}' | cut -c1-16)" 2>/dev/null + HWID="$(genHWID)" USERID="$(curl -skL "https://arc.auxxxilium.tech?hwid=${HWID}")" if echo "${USERID}" | grep -vq "Hardware ID"; then writeConfigKey "arc.hwid" "${HWID}" "${USER_CONFIG_FILE}" diff --git a/files/initrd/opt/arc/include/functions.sh b/files/initrd/opt/arc/include/functions.sh index 1ad9822e..b90aa551 100755 --- a/files/initrd/opt/arc/include/functions.sh +++ b/files/initrd/opt/arc/include/functions.sh @@ -560,4 +560,11 @@ function systemCheck () { # Check for Arc Patch ARCCONF="$(readConfigKey "${MODEL:-SA6400}.serial" "${S_FILE}")" [ -z "${ARCCONF}" ] && writeConfigKey "arc.patch" "false" "${USER_CONFIG_FILE}" +} + +############################################################################### +# Generate HardwareID +function genHWID () { + HWID="$(echo $(ifconfig | grep eth0 | awk '{print $NF}' | sed 's/://g') $(cat /proc/cpuinfo | grep "model name" | cut -d':' -f2 | head -1) | sha256sum | awk '{print $1}' | cut -c1-16)" 2>/dev/null + echo "${HWID}" } \ No newline at end of file From d890c54a1b37dd7732cf9eef1f84acf50201462f Mon Sep 17 00:00:00 2001 From: AuxXxilium Date: Mon, 11 Nov 2024 21:05:07 +0100 Subject: [PATCH 2/4] arc: add more features for online Signed-off-by: AuxXxilium --- files/initrd/opt/arc/arc-functions.sh | 47 ++++++++++++++++++++++----- files/initrd/opt/arc/arc.sh | 14 ++++++-- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/files/initrd/opt/arc/arc-functions.sh b/files/initrd/opt/arc/arc-functions.sh index 1fd1db70..e22b9200 100755 --- a/files/initrd/opt/arc/arc-functions.sh +++ b/files/initrd/opt/arc/arc-functions.sh @@ -695,8 +695,10 @@ function backupMenu() { while true; do dialog --backtitle "$(backtitle)" --title "Backup" --cancel-label "Exit" --menu "Choose an Option" 0 0 0 \ 1 "Restore Arc Config from DSM" \ - 2 "Restore HW Encryption Key from DSM" \ - 3 "Backup HW Encryption Key to DSM" \ + 2 "Restore Arc Config online" \ + 3 "Backup Arc Config online" \ + 4 "Restore HW Encryption Key from DSM" \ + 5 "Backup HW Encryption Key to DSM" \ 2>"${TMP_PATH}/resp" [ $? -ne 0 ] && break case "$(cat ${TMP_PATH}/resp)" in @@ -755,6 +757,30 @@ function backupMenu() { exec init.sh ;; 2) + [ -f "${USER_CONFIG_FILE}" ] && mv -f "${USER_CONFIG_FILE}" "${USER_CONFIG_FILE}.bak" + HWID="$(genHWID)" + USERID="$(readConfigKey "arc.userid" "${USER_CONFIG_FILE}")" + if curl -skL "https://arc.auxxxilium.tech?cdown=${HWID}" -o "${USER_CONFIG_FILE}" 2>/dev/null; then + dialog --backtitle "$(backtitle)" --title "Online Restore" --msgbox "Online Restore successful!" 5 40 + else + dialog --backtitle "$(backtitle)" --title "Online Restore" --msgbox "Online Restore failed!" 5 40 + mv -f "${USER_CONFIG_FILE}.bak" "${USER_CONFIG_FILE}" + fi + ;; + 3) + if [ -f "${USER_CONFIG_FILE}" ]; then + HWID="$(genHWID)" + USERID="$(readConfigKey "arc.userid" "${USER_CONFIG_FILE}")" + if curl -sk -X POST -F "file=@${USER_CONFIG_FILE}" "https://arc.auxxxilium.tech?cup=${HWID}&userid=${USERID}"; then + dialog --backtitle "$(backtitle)" --title "Online Backup" --msgbox "Online Backup successful!" 5 40 + else + dialog --backtitle "$(backtitle)" --title "Online Backup" --msgbox "Online Backup failed!" 5 40 + fi + else + dialog --backtitle "$(backtitle)" --title "Online Backup" --msgbox "No User Config found!" 5 40 + fi + ;; + 4) DSMROOTS="$(findDSMRoot)" if [ -z "${DSMROOTS}" ]; then dialog --backtitle "$(backtitle)" --title "Restore Encryption Key" \ @@ -779,7 +805,7 @@ function backupMenu() { --msgbox "No Encryption Key found!" 0 0 fi ;; - 3) + 5) BACKUPKEY="false" DSMROOTS="$(findDSMRoot)" if [ -z "${DSMROOTS}" ]; then @@ -911,7 +937,6 @@ function sysinfo() { # Get System Informations [ -d /sys/firmware/efi ] && BOOTSYS="UEFI" || BOOTSYS="BIOS" CPU="$(cat /proc/cpuinfo 2>/dev/null | grep 'model name' | uniq | awk -F':' '{print $2}')" - HWID="$(genHWID)" SECURE=$(dmesg 2>/dev/null | grep -i "Secure Boot" | awk -F'] ' '{print $2}') VENDOR=$(dmesg 2>/dev/null | grep -i "DMI:" | head -1 | sed 's/\[.*\] DMI: //i') ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)" @@ -960,7 +985,6 @@ function sysinfo() { TEXT="" # Print System Informations TEXT+="\n\n\Z4> System: ${MACHINE} | ${BOOTSYS} | ${BUS}\Zn" - TEXT+="\n HardwareID: \Zb${HWID}\Zn" TEXT+="\n Vendor: \Zb${VENDOR}\Zn" TEXT+="\n CPU: \Zb${CPU}\Zn" if [ $(lspci -d ::300 | wc -l) -gt 0 ]; then @@ -1137,7 +1161,7 @@ function sysinfo() { fi TEXT+="\n Total Disks: \Zb${NUMPORTS}\Zn" [ -f "${TMP_PATH}/diag" ] && rm -f "${TMP_PATH}/diag" >/dev/null - echo -e "${TEXT}" >"${TMP_PATH}/diag" + echo -e "${TEXT}" >"${TMP_PATH}/sysinfo.yml" while true; do dialog --backtitle "$(backtitle)" --colors --ok-label "Exit" --help-button --help-label "Show Cmdline" \ --extra-button --extra-label "Upload" --title "Sysinfo" --msgbox "${TEXT}" 0 0 @@ -1173,9 +1197,14 @@ function getCMDline () { } function uploadDiag () { - if [ -f "${TMP_PATH}/diag" ]; then - GENHASH=$(cat "${TMP_PATH}/diag" | curl -s -F "content=<-" "http://arc.auxxxilium.tech?sysinfo=${HWID}") - dialog --backtitle "$(backtitle)" --title "Sysinfo Upload" --msgbox "Your Code: ${HWID}" 5 30 + if [ -f "${TMP_PATH}/sysinfo.yml" ]; then + HWID="$(genHWID)" + USERID="$(readConfigKey "arc.userid" "${USER_CONFIG_FILE}")" + if curl -sk -X POST -F "file=@${TMP_PATH}/sysinfo.yml" "https://arc.auxxxilium.tech?sysinfo=${HWID}&userid=${USERID}"; then + dialog --backtitle "$(backtitle)" --title "Sysinfo Upload" --msgbox "Your Code: ${HWID}" 5 40 + else + dialog --backtitle "$(backtitle)" --title "Sysinfo Upload" --msgbox "Failed to upload diag file!" 0 0 + fi else dialog --backtitle "$(backtitle)" --title "Sysinfo Upload" --msgbox "No Diag File found!" 0 0 fi diff --git a/files/initrd/opt/arc/arc.sh b/files/initrd/opt/arc/arc.sh index 87690691..eb8f0a7a 100755 --- a/files/initrd/opt/arc/arc.sh +++ b/files/initrd/opt/arc/arc.sh @@ -698,7 +698,17 @@ function make() { # Max Memory for DSM RAMCONFIG="$((${RAMTOTAL} * 1024 * 2))" writeConfigKey "synoinfo.mem_max_mb" "${RAMCONFIG}" "${USER_CONFIG_FILE}" - getpatfiles + if [ -n "${IPCON}" ]; then + getpatfiles + else + dialog --backtitle "$(backtitle)" --title "Build Loader" --aspect 18 \ + --infobox "Could not build Loader!\nNetwork Connection needed." 4 40 + # Set Build to false + writeConfigKey "arc.builddone" "false" "${USER_CONFIG_FILE}" + BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")" + sleep 2 + return 1 + fi if [ -f "${ORI_ZIMAGE_FILE}" ] && [ -f "${ORI_RDGZ_FILE}" ] && [ "${CONFDONE}" == "true" ] && [ -n "${PAT_URL}" ] && [ -n "${PAT_HASH}" ]; then ( livepatch @@ -829,7 +839,7 @@ else echo "0 \"HardwareID for Arc Patch\" " >>"${TMP_PATH}/menu" fi echo "1 \"Choose Model \" " >>"${TMP_PATH}/menu" - if [ "${CONFDONE}" == "true" ]; then + if [ "${CONFDONE}" == "true" ] && [ -n "${IPCON}" ]; then echo "2 \"Build Loader \" " >>"${TMP_PATH}/menu" fi if [ "${BUILDDONE}" == "true" ]; then From 1bde43ca662e6a6a8ba51f621cb516a3e5a45a47 Mon Sep 17 00:00:00 2001 From: AuxXxilium Date: Mon, 11 Nov 2024 21:26:44 +0100 Subject: [PATCH 3/4] functions: make hwid unique Signed-off-by: AuxXxilium --- files/initrd/opt/arc/arc-functions.sh | 139 +++++++++++++--------- files/initrd/opt/arc/include/functions.sh | 2 +- 2 files changed, 84 insertions(+), 57 deletions(-) diff --git a/files/initrd/opt/arc/arc-functions.sh b/files/initrd/opt/arc/arc-functions.sh index e22b9200..b820c4a5 100755 --- a/files/initrd/opt/arc/arc-functions.sh +++ b/files/initrd/opt/arc/arc-functions.sh @@ -692,14 +692,23 @@ function sequentialIOMenu() { # Shows backup menu to user function backupMenu() { NEXT="1" + USERID="$(readConfigKey "arc.userid" "${USER_CONFIG_FILE}")" while true; do - dialog --backtitle "$(backtitle)" --title "Backup" --cancel-label "Exit" --menu "Choose an Option" 0 0 0 \ - 1 "Restore Arc Config from DSM" \ - 2 "Restore Arc Config online" \ - 3 "Backup Arc Config online" \ - 4 "Restore HW Encryption Key from DSM" \ - 5 "Backup HW Encryption Key to DSM" \ - 2>"${TMP_PATH}/resp" + if [ -n "${USERID}" ]; then + dialog --backtitle "$(backtitle)" --title "Backup" --cancel-label "Exit" --menu "Choose an Option" 0 0 0 \ + 1 "Restore Arc Config from DSM" \ + 2 "Restore HW Encryption Key from DSM" \ + 3 "Backup HW Encryption Key to DSM" \ + 4 "Restore Arc Config from Online" \ + 5 "Backup Arc Config to Online" \ + 2>"${TMP_PATH}/resp" + else + dialog --backtitle "$(backtitle)" --title "Backup" --cancel-label "Exit" --menu "Choose an Option" 0 0 0 \ + 1 "Restore Arc Config from DSM" \ + 2 "Restore HW Encryption Key from DSM" \ + 3 "Backup HW Encryption Key to DSM" \ + 2>"${TMP_PATH}/resp" + fi [ $? -ne 0 ] && break case "$(cat ${TMP_PATH}/resp)" in 1) @@ -757,30 +766,6 @@ function backupMenu() { exec init.sh ;; 2) - [ -f "${USER_CONFIG_FILE}" ] && mv -f "${USER_CONFIG_FILE}" "${USER_CONFIG_FILE}.bak" - HWID="$(genHWID)" - USERID="$(readConfigKey "arc.userid" "${USER_CONFIG_FILE}")" - if curl -skL "https://arc.auxxxilium.tech?cdown=${HWID}" -o "${USER_CONFIG_FILE}" 2>/dev/null; then - dialog --backtitle "$(backtitle)" --title "Online Restore" --msgbox "Online Restore successful!" 5 40 - else - dialog --backtitle "$(backtitle)" --title "Online Restore" --msgbox "Online Restore failed!" 5 40 - mv -f "${USER_CONFIG_FILE}.bak" "${USER_CONFIG_FILE}" - fi - ;; - 3) - if [ -f "${USER_CONFIG_FILE}" ]; then - HWID="$(genHWID)" - USERID="$(readConfigKey "arc.userid" "${USER_CONFIG_FILE}")" - if curl -sk -X POST -F "file=@${USER_CONFIG_FILE}" "https://arc.auxxxilium.tech?cup=${HWID}&userid=${USERID}"; then - dialog --backtitle "$(backtitle)" --title "Online Backup" --msgbox "Online Backup successful!" 5 40 - else - dialog --backtitle "$(backtitle)" --title "Online Backup" --msgbox "Online Backup failed!" 5 40 - fi - else - dialog --backtitle "$(backtitle)" --title "Online Backup" --msgbox "No User Config found!" 5 40 - fi - ;; - 4) DSMROOTS="$(findDSMRoot)" if [ -z "${DSMROOTS}" ]; then dialog --backtitle "$(backtitle)" --title "Restore Encryption Key" \ @@ -805,7 +790,7 @@ function backupMenu() { --msgbox "No Encryption Key found!" 0 0 fi ;; - 5) + 3) BACKUPKEY="false" DSMROOTS="$(findDSMRoot)" if [ -z "${DSMROOTS}" ]; then @@ -836,6 +821,28 @@ function backupMenu() { --msgbox "No Encryption Key found!" 0 0 fi ;; + 4) + [ -f "${USER_CONFIG_FILE}" ] && mv -f "${USER_CONFIG_FILE}" "${USER_CONFIG_FILE}.bak" + HWID="$(genHWID)" + if curl -skL "https://arc.auxxxilium.tech?cdown=${HWID}" -o "${USER_CONFIG_FILE}" 2>/dev/null; then + dialog --backtitle "$(backtitle)" --title "Online Restore" --msgbox "Online Restore successful!" 5 40 + else + dialog --backtitle "$(backtitle)" --title "Online Restore" --msgbox "Online Restore failed!" 5 40 + mv -f "${USER_CONFIG_FILE}.bak" "${USER_CONFIG_FILE}" + fi + ;; + 5) + if [ -f "${USER_CONFIG_FILE}" ]; then + HWID="$(genHWID)" + if curl -sk -X POST -F "file=@${USER_CONFIG_FILE}" "https://arc.auxxxilium.tech?cup=${HWID}&userid=${USERID}"; then + dialog --backtitle "$(backtitle)" --title "Online Backup" --msgbox "Online Backup successful!" 5 40 + else + dialog --backtitle "$(backtitle)" --title "Online Backup" --msgbox "Online Backup failed!" 5 40 + fi + else + dialog --backtitle "$(backtitle)" --title "Online Backup" --msgbox "No User Config found!" 5 40 + fi + ;; esac done } @@ -936,6 +943,7 @@ function networkMenu() { function sysinfo() { # Get System Informations [ -d /sys/firmware/efi ] && BOOTSYS="UEFI" || BOOTSYS="BIOS" + USERID="$(readConfigKey "arc.userid" "${USER_CONFIG_FILE}")" CPU="$(cat /proc/cpuinfo 2>/dev/null | grep 'model name' | uniq | awk -F':' '{print $2}')" SECURE=$(dmesg 2>/dev/null | grep -i "Secure Boot" | awk -F'] ' '{print $2}') VENDOR=$(dmesg 2>/dev/null | grep -i "DMI:" | head -1 | sed 's/\[.*\] DMI: //i') @@ -1160,29 +1168,49 @@ function sysinfo() { NUMPORTS=$((${NUMPORTS} + ${PORTNUM})) fi TEXT+="\n Total Disks: \Zb${NUMPORTS}\Zn" - [ -f "${TMP_PATH}/diag" ] && rm -f "${TMP_PATH}/diag" >/dev/null - echo -e "${TEXT}" >"${TMP_PATH}/sysinfo.yml" - while true; do - dialog --backtitle "$(backtitle)" --colors --ok-label "Exit" --help-button --help-label "Show Cmdline" \ - --extra-button --extra-label "Upload" --title "Sysinfo" --msgbox "${TEXT}" 0 0 - RET=$? - case ${RET} in - 0) # ok-button - return 0 - break - ;; - 2) # help-button - getCMDline - ;; - 3) # extra-button - uploadDiag - ;; - 255) # ESC-button - return 0 - break - ;; - esac - done + if [ -n "${USERID}" ]; then + echo -e "${TEXT}" >"${TMP_PATH}/sysinfo.yml" + while true; do + dialog --backtitle "$(backtitle)" --colors --ok-label "Exit" --help-button --help-label "Show Cmdline" \ + --extra-button --extra-label "Upload" --title "Sysinfo" --msgbox "${TEXT}" 0 0 + RET=$? + case ${RET} in + 0) # ok-button + return 0 + break + ;; + 2) # help-button + getCMDline + ;; + 3) # extra-button + uploadDiag + ;; + 255) # ESC-button + return 0 + break + ;; + esac + done + else + while true; do + dialog --backtitle "$(backtitle)" --colors --ok-label "Exit" --help-button --help-label "Show Cmdline" \ + --title "Sysinfo" --msgbox "${TEXT}" 0 0 + RET=$? + case ${RET} in + 0) # ok-button + return 0 + break + ;; + 2) # help-button + getCMDline + ;; + 255) # ESC-button + return 0 + break + ;; + esac + done + fi return } @@ -1199,7 +1227,6 @@ function getCMDline () { function uploadDiag () { if [ -f "${TMP_PATH}/sysinfo.yml" ]; then HWID="$(genHWID)" - USERID="$(readConfigKey "arc.userid" "${USER_CONFIG_FILE}")" if curl -sk -X POST -F "file=@${TMP_PATH}/sysinfo.yml" "https://arc.auxxxilium.tech?sysinfo=${HWID}&userid=${USERID}"; then dialog --backtitle "$(backtitle)" --title "Sysinfo Upload" --msgbox "Your Code: ${HWID}" 5 40 else diff --git a/files/initrd/opt/arc/include/functions.sh b/files/initrd/opt/arc/include/functions.sh index b90aa551..cb0f3df4 100755 --- a/files/initrd/opt/arc/include/functions.sh +++ b/files/initrd/opt/arc/include/functions.sh @@ -565,6 +565,6 @@ function systemCheck () { ############################################################################### # Generate HardwareID function genHWID () { - HWID="$(echo $(ifconfig | grep eth0 | awk '{print $NF}' | sed 's/://g') $(cat /proc/cpuinfo | grep "model name" | cut -d':' -f2 | head -1) | sha256sum | awk '{print $1}' | cut -c1-16)" 2>/dev/null + HWID="$(echo $(dmidecode -t 4 | grep ID | sed 's/.*ID://;s/ //g' | head -1) $(ifconfig | grep eth1 | awk '{print $NF}' | sed 's/://g') | sha256sum | awk '{print $1}' | cut -c1-16)" 2>/dev/null echo "${HWID}" } \ No newline at end of file From fb938806a2bd1dfbde797808eb5c42b7aa270c9c Mon Sep 17 00:00:00 2001 From: AuxXxilium Date: Tue, 12 Nov 2024 16:02:28 +0100 Subject: [PATCH 4/4] functions: finalize hwid Signed-off-by: AuxXxilium --- files/initrd/opt/arc/include/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/initrd/opt/arc/include/functions.sh b/files/initrd/opt/arc/include/functions.sh index cb0f3df4..3989c7a6 100755 --- a/files/initrd/opt/arc/include/functions.sh +++ b/files/initrd/opt/arc/include/functions.sh @@ -565,6 +565,6 @@ function systemCheck () { ############################################################################### # Generate HardwareID function genHWID () { - HWID="$(echo $(dmidecode -t 4 | grep ID | sed 's/.*ID://;s/ //g' | head -1) $(ifconfig | grep eth1 | awk '{print $NF}' | sed 's/://g') | sha256sum | awk '{print $1}' | cut -c1-16)" 2>/dev/null + HWID="$(echo $(dmidecode -t 4 | grep ID | sed 's/.*ID://;s/ //g' | head -1) $(ifconfig | grep eth0 | awk '{print $NF}' | sed 's/://g') | sha256sum | awk '{print $1}' | cut -c1-16)" 2>/dev/null echo "${HWID}" } \ No newline at end of file