diff --git a/simpleadmin/www/cgi-bin/get_sms b/simpleadmin/www/cgi-bin/get_sms index d999351..a341832 100644 --- a/simpleadmin/www/cgi-bin/get_sms +++ b/simpleadmin/www/cgi-bin/get_sms @@ -1,20 +1,12 @@ #!/bin/bash - -# This is a simple scrip that fetches the SMS messages from the device -SMS_MESSAGE_INDICATION="AT+CNMI=2,1" SMS_FORMAT="AT+CMGF=1" SMS_LIST="AT+CMGL=\"ALL\"" +send_at_command() { + local command="$1" + echo -en "$command\r\n" | microcom -t 2000 /dev/ttyOUT2 +} +send_at_command "$SMS_FORMAT" +runcmd=$(send_at_command "$SMS_LIST") -while true; do - runcmd=$(echo -en "$SMS_LIST\r\n" | microcom -t 2000 /dev/ttyOUT2) - if [[ $runcmd =~ "OK" ]] || [[ $runcmd =~ "ERROR" ]]; then - break - fi - ((wait_time++)) -done - - -# Print the list of SMS messages as JSON plain text echo "Content-type: text/plain" -echo "" -echo $runcmd \ No newline at end of file +echo "$runcmd" \ No newline at end of file diff --git a/simpleadmin/www/cgi-bin/get_watchcat_status b/simpleadmin/www/cgi-bin/get_watchcat_status new file mode 100644 index 0000000..7180948 --- /dev/null +++ b/simpleadmin/www/cgi-bin/get_watchcat_status @@ -0,0 +1,18 @@ +#!/bin/bash + +# Content type header +echo "Content-type: application/json" +echo "" + +# This script fetches the watchCat parameters from the /tmp/watchCatParams.json file and returns it as JSON + +# Check if the file exists +if [ -f /tmp/watchCatParams.json ]; then + # Read the file and return the content + cat /tmp/watchCatParams.json +else + # Return an empty JSON object + echo "{}" +fi + +exit 0 \ No newline at end of file diff --git a/simpleadmin/www/cgi-bin/send_sms b/simpleadmin/www/cgi-bin/send_sms index 2d631b7..2e8f316 100644 --- a/simpleadmin/www/cgi-bin/send_sms +++ b/simpleadmin/www/cgi-bin/send_sms @@ -1,44 +1,54 @@ #!/bin/bash QUERY_STRING=$(echo "${QUERY_STRING}" | sed 's/;//g') -function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } +urldecode() { + local data + data="${*//+/ }" + echo -e "${data//%/\\x}" +} if [ "${QUERY_STRING}" ]; then export IFS="&" for cmd in ${QUERY_STRING}; do - if [ "$(echo $cmd | grep '=')" ]; then - key=$(echo $cmd | awk -F '=' '{print $1}') - value=$(echo $cmd | awk -F '=' '{print $2}') - eval $key=$value + if [[ "$cmd" == *=* ]]; then + key=$(echo "$cmd" | awk -F '=' '{print $1}') + value=$(echo "$cmd" | awk -F '=' '{print $2}') + eval "$key"="$(urldecode "$value")" fi done fi -# Extract phone number and message from inputs phone_number="$number" -message="$msg" +message_encoded="$msg" -# Prepare AT command with phone number and message -ATCMD="AT+CMGS=\"$phone_number\"" +phone_number="+86$phone_number" -MYATCMD=$(printf '%b\n' "${ATCMD//%/\\x}") -if [ -n "${MYATCMD}" ]; then - x=$(urldecode "$ATCMD") - # Send the AT command to initiate message sending - echo -en "$x\r\n" | microcom /dev/ttyOUT2 - # Wait for a brief moment (assuming the message sending is instantaneous) - sleep 1 -fi +send_at_command() { + local cmd=$1 + echo "Sending command: $cmd" >&2 + echo -en "$cmd\r" | microcom -t 1000 /dev/ttyOUT2 + sleep 2 + local response=$(microcom -t 1000 /dev/ttyOUT2) + echo "Response: $response" >&2 + echo "$response" +} -# Send the message -echo -en "$message\c" +send_at_command "AT+CMGF=1" +send_at_command "AT+CSCS=\"UCS2\"" -# Send Ctrl+Z to terminate the message -echo -en "\032" +encode_ucs2() { + local input="$1" + local output="" + local i + for ((i=0; i<${#input}; i++)); do + hex=$(printf "%04X" "'${input:$i:1}") + output="$output$hex" + done + echo "$output" +} -# Ensure microcom reads the response (assuming microcom will show response instantly) -sleep 1 +phone_number_ucs2=$(encode_ucs2 "$phone_number") +ATCMD="AT+CMGS=\"$phone_number_ucs2\"" +send_at_command "$ATCMD" -# Capture and output the response -runcmd=$(microcom /dev/ttyOUT2) -echo "Content-type: text/plain" +runcmd=$((echo -en "$message_encoded"; sleep 1; echo -en "\x1A") | microcom -t 1000 /dev/ttyOUT2) echo "$runcmd" \ No newline at end of file diff --git a/simpleadmin/www/cgi-bin/set_watchcat b/simpleadmin/www/cgi-bin/set_watchcat new file mode 100644 index 0000000..0abf798 --- /dev/null +++ b/simpleadmin/www/cgi-bin/set_watchcat @@ -0,0 +1,125 @@ +#!/bin/bash + +QUERY_STRING=$(echo "${QUERY_STRING}" | sed 's/;//g') +function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } + +if [ "${QUERY_STRING}" ]; then + export IFS="&" + for cmd in ${QUERY_STRING}; do + if [[ "$cmd" == *"="* ]]; then + key=$(echo $cmd | awk -F '=' '{print $1}') + value=$(echo $cmd | awk -F '=' '{print $2}') + eval $key=$(urldecode $value) + fi + done +fi + +if [ -z "$status" ] || [ -z "$IpDNS" ] || [ -z "$cooldown" ] || [ -z "$failures" ] || [ -z "$action" ]; then + response="Missing parameters. Please provide the following parameters: IpDNS, cooldown, failures, action." + echo "Content-type: text/plain" + echo "" + echo "$response" + exit 1 +fi + +if [ "$status" == "enabled" ]; then + watch_script="/usrdata/simpleadmin/script/watchat.sh" + mount -o remount,rw / + + cat < $watch_script +#!/bin/bash + +ip_or_dns="$IpDNS" +cooldown=$cooldown +action="$action" +fail_count=0 +max_failures=$failures + +# Process the action variable. + +# Create a JSON file containing the parameters of the script +echo -n '{"ip_or_dns":"$ip_or_dns","cooldown":$cooldown,"action":"$action","fail_count":$fail_count,"max_failures":$max_failures}' > /tmp/watchatParams.json + + +while true; do + if ping -c 1 -W 1 \$ip_or_dns > /dev/null; then + fail_count=0 + echo "Success at \$(date)" >> /tmp/watchat.log + # Convert /tmp/watchat.log to json format + echo -n '{"log":[' > /tmp/watchat.json + cat /tmp/watchat.log | sed 's/$/,/' | tr -d '\n' | sed 's/,$//' >> /tmp/watchat.json + echo -n ']}' >> /tmp/watchat.json + else + ((fail_count++)) + if [ \$fail_count -ge \$max_failures ]; then + case "\$action" in + reboot) + echo "Rebooting system..." + /sbin/reboot + ;; + switch_sim) + echo "Switching SIM..." + echo -ne "AT+CNMI=2,1\r" > /dev/ttyOUT2 + sleep 1 + echo "Switching SIM at \$(date)" >> /tmp/watchat.log + ;; + none) + echo "No action taken." + echo "No action taken at \$(date)" >> /tmp/watchat.log + ;; + *) + echo "Unknown action: \$action" + ;; + esac + # Reset fail count + fail_count=0 + fi + fi + echo "Fail count: \$fail_count at \$(date)" >> /tmp/watchat.log + # Convert /tmp/watchat.log to json format + echo -n '{"log":[' > /tmp/watchat.json + cat /tmp/watchat.log | sed 's/$/,/' | tr -d '\n' | sed 's/,$//' >> /tmp/watchat.json + echo -n ']}' >> /tmp/watchat.json + sleep \$cooldown +done +EOF + + chmod +x $watch_script + + cat < /lib/systemd/system/watchcat.service +[Unit] +Description=Ping Watcher Service + +[Service] +ExecStart=$watch_script +Restart=always + +[Install] +WantedBy=multi-user.target +EOF + + ln -s /lib/systemd/system/watchcat.service /etc/systemd/system/multi-user.target.wants/watchcat.service + + systemctl daemon-reload + systemctl start watchcat.service + + response="Script created at $watch_script and made executable. Service created and started." + +elif [ "$status" == "disabled" ]; then + watch_script="/usrdata/simpleadmin/script/watchat.sh" + rm -f $watch_script + + systemctl stop watchcat.service + rm -f /lib/systemd/system/watchcat.service + rm -f /etc/systemd/system/multi-user.target.wants/watchcat.service + + systemctl daemon-reload + + response="Script removed at $watch_script. Service stopped and removed." +else + response="Invalid status. Please provide either enabled or disabled." +fi + +echo "Content-type: text/plain" +echo "" +echo "$response" \ No newline at end of file diff --git a/simpleadmin/www/deviceinfo.html b/simpleadmin/www/deviceinfo.html index 739074a..07cbd01 100644 --- a/simpleadmin/www/deviceinfo.html +++ b/simpleadmin/www/deviceinfo.html @@ -139,7 +139,99 @@ Simple Admin Version - SimpleAdminRev-Alpha-0.8 + SimpleAdminRev-Alpha-0.9 + + + Project Contributors + + + + + + + diff --git a/simpleadmin/www/settings.html b/simpleadmin/www/settings.html index 51a1442..da6e108 100644 --- a/simpleadmin/www/settings.html +++ b/simpleadmin/www/settings.html @@ -315,17 +315,18 @@
- - @@ -525,30 +526,23 @@ if (this.usbNetMode != "Unspecified") { if (this.usbNetMode == "RMNET") { this.atcmd = 'AT+QCFG="usbnet",0;'; - this.sendATCommand().then(() => { - this.rebootDevice(); - }); + this.sendATCommand(); } else if (this.usbNetMode == "ECM") { this.atcmd = 'AT+QCFG="usbnet",1;'; - this.sendATCommand().then(() => { - this.rebootDevice(); - }); + this.sendATCommand(); } else if (this.usbNetMode == "MBIM") { this.atcmd = 'AT+QCFG="usbnet",2;'; - this.sendATCommand().then(() => { - this.rebootDevice(); - }); + this.sendATCommand(); } else if (this.usbNetMode == "RNDIS") { this.atcmd = 'AT+QCFG="usbnet",3;'; - this.sendATCommand().then(() => { - this.rebootDevice(); - }); + this.sendATCommand(); } else { console.log("USB Net Mode Invalid"); } } else { console.error("USB Net Mode not specified"); } + this.rebootDevice(); }, fetchCurrentSettings() { diff --git a/simpleadmin/www/sms.html b/simpleadmin/www/sms.html index 1595275..5806604 100644 --- a/simpleadmin/www/sms.html +++ b/simpleadmin/www/sms.html @@ -1,302 +1,422 @@ - - - - - Simple Admin - - - - - - - + + + + + Simple Admin + + + + + + + + - - - - - - -
-
- -
-
-
-
SMS Manager
-
-
-
-
- - -
-

Fetching SMS...

-
- - - - -
-
-
-
- + + - -
-
-
- -
-
-
-
-
- - + - + // 删除选中的短信 + // Delete selected SMS + deleteSelectedSMS() { + if (this.selectedMessages.length === 0) { + console.warn("No SMS selected"); + return; + } + + if (!this.messageIndices || this.messageIndices.length === 0) { + console.error("SMS index is not correctly initialized or is empty"); + return; + } + + // 检查是否全选 + // Check if all are selected + const isAllSelected = + this.selectedMessages.length === this.messages.length; + + if (isAllSelected) { + // 如果全选,则调用删除所有短信的方法 + // If all are selected, call the method to delete all SMS + this.deleteAllSMS(); + } else { + // 否则,删除选中的短信 + // Otherwise, delete the selected SMS + const deletePromises = this.selectedMessages.map((index) => { + if (index >= this.messageIndices.length) { + console.error("SMS index out of range"); + return Promise.resolve(); // 返回已解决的Promise,防止进一步错误 + // Return a resolved Promise to prevent further errors + } + const actualIndex = this.messageIndices[index]; + return fetch( + `/cgi-bin/get_atcommand?${new URLSearchParams({ + atcmd: `AT+CMGD=${actualIndex}`, + })}` + ); + }); + + Promise.all(deletePromises).finally(() => { + this.selectedMessages = []; + this.requestSMS(); + }); + } + }, + + // 将十六进制转换为文本(假设使用 UTF-16BE 编码) + // Convert hexadecimal to text (assuming UTF-16BE encoding) + convertHexToText(hex) { + const bytes = new Uint8Array( + hex.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)) + ); + return new TextDecoder("utf-16be").decode(bytes); + }, + + // 删除所有短信 + // Delete all SMS + deleteAllSMS() { + fetch( + `/cgi-bin/get_atcommand?${new URLSearchParams({ + atcmd: "AT+CMGD=,4", + })}` + ).finally(() => { + this.init(); + }); + }, + // 发送短信 + // Send SMS + toUCS2(message) { + let ucs2Message = ""; + for (let i = 0; i < message.length; i++) { + const code = message.charCodeAt(i).toString(16).toUpperCase(); + ucs2Message += ("0000" + code).slice(-4); // Ensure each code is 4 digits + } + return ucs2Message; + }, + + sendSMS() { + const ucs2Message = this.toUCS2(this.messageToSend); + const encodedMessage = encodeURIComponent(ucs2Message); + const params = new URLSearchParams({ + number: this.phoneNumber, + msg: encodedMessage, + }); + fetch(`/cgi-bin/send_sms?${params.toString()}`) + .then((response) => response.text()) + .then((data) => { + console.log("Response from server:", data); + // 检查返回的数据中是否包含 '+CMS ERROR' + // Check if the returned data contains '+CMS ERROR' + if (data.includes("+CMS ERROR")) { + // 解析错误代码,如果存在,获取更具体的错误信息 + // Parse the error code, if it exists, get more specific error information + const errorCode = data.match(/\+CMS ERROR: (\d+)/)?.[1]; + console.error("SMS send error:", data); + alert(`SMS sending failed!: ${errorCode}`); + + } else { + alert("SMS sent successfully!"); + } + }); + }, + + // 初始化 + // Initialize + init() { + this.clearData(); + this.requestSMS(); + }, + + // 全选/取消全选 + // Select all/deselect all + toggleAll(event) { + this.selectedMessages = event.target.checked + ? this.messages.map((_, index) => index) + : []; + }, + }; + } + + diff --git a/simpleadmin/www/watchat.html b/simpleadmin/www/watchat.html deleted file mode 100644 index 8d4e985..0000000 --- a/simpleadmin/www/watchat.html +++ /dev/null @@ -1,200 +0,0 @@ - - - - - - Simple Admin - - - - - - - - - - - - - -
-
- -
-
-
-
Simple Watchcat
-
-
-
- - - - - - - -
-
- IP or DNS to Ping - -
- -
- Ping Timeout in Seconds - -
- -
- Ping Failure Amount - -
- -
- - -
-
-
- -
-
-
-
-
- - - - diff --git a/simpleadmin/www/watchcat.html b/simpleadmin/www/watchcat.html new file mode 100644 index 0000000..ed2a6cf --- /dev/null +++ b/simpleadmin/www/watchcat.html @@ -0,0 +1,363 @@ + + + + + + Simple Admin + + + + + + + + + + + + + + + +
+
+ +
+
+
+
Simple Watchcat
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+ +
+ +
+ +
+ +
+
+ +
+
+ +
+ +
+ +
+ +
+ +
+
+
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+
+ +
+
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ +
+
+
+
+
+ +
+
+
+
+
+ + + + diff --git a/simpleupdates/scripts/update_simpleadmin.sh b/simpleupdates/scripts/update_simpleadmin.sh index 1a9f13c..a2fabe6 100644 --- a/simpleupdates/scripts/update_simpleadmin.sh +++ b/simpleupdates/scripts/update_simpleadmin.sh @@ -184,6 +184,8 @@ echo -e "\e[1;31m2) Installing simpleadmin from the $GITTREE branch\e[0m" wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/cgi-bin/set_ttl wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/cgi-bin/send_sms wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/cgi-bin/get_uptime + wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/cgi-bin/get_watchcat_status + wget https://raw.githubusercontent.com/$GITUSER/quectel-rgmii-toolkit/$GITTREE/simpleadmin/www/cgi-bin/set_watchcat sleep 1 cd / chmod +x $SIMPLE_ADMIN_DIR/www/cgi-bin/*