This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| sdk:scripts:sms-control [2015/08/27 07:25] – hess | sdk:scripts:sms-control [2022/08/26 11:04] (current) – created dodenhoeft | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== |
| - | For further information on how to configure see [[configuration: | + | |
| <code c sms-control.are> | <code c sms-control.are> | ||
| + | |||
| /* DESC: This script will execute commands received by SMS. | /* DESC: This script will execute commands received by SMS. | ||
| * Copyright (C) 2012 NetModule AG, Switzerland | * Copyright (C) 2012 NetModule AG, Switzerland | ||
| + | | ||
| + | * sms-commands: | ||
| + | * < | ||
| + | * < | ||
| + | * < | ||
| + | * < | ||
| + | * <output [1|2] [on|off]> | ||
| */ | */ | ||
| Line 9: | Line 17: | ||
| MAXMSG | MAXMSG | ||
| MAXAGE | MAXAGE | ||
| - | MAXLINES = 32; /* max. number of lines in msg (incl. header) | + | MAXLINES |
| AUTH = 1; /* perform authentication | AUTH = 1; /* perform authentication | ||
| ADMPWD | ADMPWD | ||
| Line 34: | Line 42: | ||
| } | } | ||
| if (IGNORECASE) ADMPWD = tolower(ADMPWD); | if (IGNORECASE) ADMPWD = tolower(ADMPWD); | ||
| + | } | ||
| + | |||
| + | /* split a message into an array */ | ||
| + | array split(string msg) { | ||
| + | args=mkarray(); | ||
| + | pos=strchr(msg, | ||
| + | if(pos==0) msg=""; | ||
| + | if(pos> | ||
| + | pos=strchr(msg, | ||
| + | if(pos==0) msg=""; | ||
| + | if(pos> | ||
| + | for(n=0;;) { | ||
| + | pos=strchr(msg, | ||
| + | if(is_void(pos)) pos=strchr(msg, | ||
| + | if(is_void(pos)) pos=strchr(msg, | ||
| + | if(pos==0) { | ||
| + | msg=trim(msg); | ||
| + | } else if(pos> | ||
| + | args[n++]=trim(left(msg, | ||
| + | msg=trim(substr(msg, | ||
| + | } else { | ||
| + | if(msg!="" | ||
| + | break; | ||
| + | } | ||
| + | } | ||
| + | return args; | ||
| } | } | ||
| /* parse message */ | /* parse message */ | ||
| - | string | + | array parse (string msg) |
| { | { | ||
| /* read by line */ | /* read by line */ | ||
| Line 48: | Line 82: | ||
| for (lnr = 0; lnr < MAXLINES && strlen(lp) > 0; lnr++) { | for (lnr = 0; lnr < MAXLINES && strlen(lp) > 0; lnr++) { | ||
| pos = strchr(lp, " | pos = strchr(lp, " | ||
| - | if (is_void(pos)) pos = strlen(lp); | + | |
| - | + | ||
| line = left(lp, pos); | line = left(lp, pos); | ||
| - | lp = substr(lp, pos + 1); | + | |
| - | + | ||
| if (strlen(line) == 0) { | if (strlen(line) == 0) { | ||
| /* saw header separator */ | /* saw header separator */ | ||
| Line 71: | Line 105: | ||
| nb_syslog(" | nb_syslog(" | ||
| if (age > MAXAGE) { | if (age > MAXAGE) { | ||
| - | nb_syslog(" | + | |
| - | return | + | return |
| } | } | ||
| } else { | } else { | ||
| Line 90: | Line 124: | ||
| if (allowed == 0) { | if (allowed == 0) { | ||
| nb_syslog(" | nb_syslog(" | ||
| - | return | + | return |
| } else { | } else { | ||
| nb_syslog(" | nb_syslog(" | ||
| Line 103: | Line 137: | ||
| if (left(line, strlen(ADMPWD)) != ADMPWD) { | if (left(line, strlen(ADMPWD)) != ADMPWD) { | ||
| nb_syslog(" | nb_syslog(" | ||
| - | return | + | return |
| } else { | } else { | ||
| nb_syslog(" | nb_syslog(" | ||
| Line 109: | Line 143: | ||
| } else if ((AUTH && tlnr == 1) || (!AUTH && tlnr == 0)) { | } else if ((AUTH && tlnr == 1) || (!AUTH && tlnr == 0)) { | ||
| /* this line must contain the command */ | /* this line must contain the command */ | ||
| - | | + | return |
| - | return " | + | |
| - | } else if (left(line, 7) == " | + | |
| - | return " | + | |
| - | } else if (left(line, 10) == " | + | |
| - | return " | + | |
| - | } else if (left(line, 6) == " | + | |
| - | return " | + | |
| - | } else if (left(line, 6) == " | + | |
| - | | + | |
| - | } | + | |
| } else { | } else { | ||
| break; | break; | ||
| Line 129: | Line 153: | ||
| nb_syslog(" | nb_syslog(" | ||
| - | return | + | return |
| } | } | ||
| - | int setdio (string | + | int setdio (string |
| { | { | ||
| - | newstate = substr(cmd, 9, 3); | ||
| - | port = substr(cmd, 7, 1); | ||
| - | | ||
| if (port != " | if (port != " | ||
| nb_syslog(" | nb_syslog(" | ||
| Line 200: | Line 221: | ||
| /* track states */ | /* track states */ | ||
| reboot = 0; | reboot = 0; | ||
| - | connecting = 0; | ||
| - | disconnecting = 0; | ||
| - | |||
| /* only process latest messages */ | /* only process latest messages */ | ||
| Line 215: | Line 233: | ||
| i, nr_msgs, msgs[i]); | i, nr_msgs, msgs[i]); | ||
| - | | + | |
| - | if (cmd == "reboot") { | + | if ((is_array(args)) && (length(args) > 0)) { |
| - | nb_syslog(" | + | if (args[0] |
| - | | + | nb_syslog(" |
| - | | + | } else if ((args[0] |
| - | nb_syslog(" | + | nb_syslog(" |
| - | if (connecting) { | + | |
| - | nb_syslog(" | + | } else if ((args[0] |
| - | } else { | + | nb_syslog(" |
| - | | + | |
| - | nb_config_set(" | + | nb_syslog(" |
| - | connecting | + | |
| - | | + | |
| - | | + | |
| - | nb_syslog(" | + | |
| - | if (disconnecting) { | + | |
| - | nb_syslog(" | + | |
| - | } else { | + | |
| - | | + | |
| - | nb_config_set(" | + | |
| - | disconnecting = 1; | + | |
| - | } | + | |
| - | } else if (cmd == "status") { | + | |
| - | nb_syslog(" | + | |
| - | rcpt = nb_sms_header(msgs[i], | + | |
| - | if (rcpt) { | + | |
| - | id = nb_sms_send(rcpt, | + | |
| - | if (!id) { | + | |
| - | nb_syslog(" | + | |
| } else { | } else { | ||
| - | | + | |
| + | nb_config_set("wanlink.0.mode=1"); | ||
| } | } | ||
| + | } else if ((args[0] == " | ||
| + | nb_syslog(" | ||
| + | if (nb_config_get(" | ||
| + | nb_syslog(" | ||
| + | } else { | ||
| + | /* disable first wanlink */ | ||
| + | nb_config_set(" | ||
| + | } | ||
| + | } else if ((args[0] == " | ||
| + | nb_syslog(" | ||
| + | rcpt = nb_sms_header(msgs[i], | ||
| + | if (rcpt) { | ||
| + | id = nb_sms_send(rcpt, | ||
| + | if (!id) { | ||
| + | nb_syslog(" | ||
| + | } else { | ||
| + | nb_syslog(" | ||
| + | } | ||
| + | } | ||
| + | } else if ((args[0] == " | ||
| + | nb_syslog(" | ||
| + | setdio(args[1], | ||
| + | } else { | ||
| + | nb_syslog(" | ||
| } | } | ||
| - | } else if (left(cmd, | ||
| - | nb_syslog(" | ||
| - | setdio(cmd); | ||
| } else { | } else { | ||
| nb_syslog(" | nb_syslog(" | ||
| } | } | ||
| - | /* delete message | + | /* delete message */ |
| ret = nb_sms_delete(msgs[i]); | ret = nb_sms_delete(msgs[i]); | ||
| if (ret == 0) nb_syslog(" | if (ret == 0) nb_syslog(" | ||
| Line 261: | Line 283: | ||
| if (reboot == 1) { | if (reboot == 1) { | ||
| - | /* trigger reboot | + | /* trigger reboot */ |
| nb_syslog(" | nb_syslog(" | ||
| nb_reboot(); | nb_reboot(); | ||
| Line 267: | Line 289: | ||
| exit(0); | exit(0); | ||
| - | |||
| </ | </ | ||