Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SIP_GET command /co issue
#1
Hi has anyone seen the following issue with SIP_GET command to change options

http://xx.xx.xx.xx:9580/co?pw=xxxxxxx&loc=12345
returns "method not allowed" message on the web page us to send the command to server
same seems to be true for /co options as well
I have ! in my password but /si, /cv functions seem to work.
I was looking at using o23 option to change the water level in the system.
I guess the monthly adj plugin may be the only work around

Thanks,
Reply
#2
(2022 Oct 26, 09:25 PM)tutqiunnh Wrote: Hi has anyone seen the following issue with SIP_GET command to change options

http://xx.xx.xx.xx:9580/co?pw=xxxxxxx&loc=12345
returns "method not allowed" message on the web page us to send the command to server
same seems to be true for /co options as well
I have ! in my password but /si, /cv functions seem to work.
I was looking at using o23 option to change the water level in the system.
I guess the monthly adj plugin may be the only work around

Thanks,
Yeah, it looks like the /co GET commands are broken.
There are a couple of reasons for that.
First, the oXX numbers were replaced with variable names quite a while ago. Instead of o23 it would need to be owl for water level (lower case letter o) plus wl for water level.

The other reason, which can be fixed if you don't mind a small edit to the Python code, was a change to improve security a little.
In webpages.py on line 169 there is code that reads "def POST(self): #  was GET", If you change POST to GET the /co commands will work. and if you use /co?owl=xx the setting will be updated.

As I recall the GET to POST change was only needed in an edge case involving password access. I will look into changing just that part of the code and restoring the rest of the /co options.

Dan
<p><br></p>
Reply
#3
Thanks for the quick response. When I was parsing the code I noticed that and POST seemed like it should be GET. I can make that change. Looks like the option definitions are in gv.reference.txt

The POST to GET changed fixed the WL issue.

Thanks so much.
Reply
#4
(2022 Oct 26, 11:28 PM)dan Wrote:
(2022 Oct 26, 09:25 PM)tutqiunnh Wrote: Hi has anyone seen the following issue with SIP_GET command to change options

http://xx.xx.xx.xx:9580/co?pw=xxxxxxx&loc=12345
returns "method not allowed" message on the web page us to send the command to server
same seems to be true for /co options as well
I have ! in my password but /si, /cv functions seem to work.
I was looking at using o23 option to change the water level in the system.
I guess the monthly adj plugin may be the only work around

Thanks,
Yeah, it looks like the /co GET commands are broken.
There are a couple of reasons for that.
First, the oXX numbers were replaced with variable names quite a while ago. Instead of o23 it would need to be owl for water level (lower case letter o) plus wl for water level.

The other reason, which can be fixed if you don't mind a small edit to the Python code, was a change to improve security a little.
In webpages.py on line 169 there is code that reads "def POST(self): #  was GET", If you change POST to GET the /co commands will work. and if you use /co?owl=xx the setting will be updated.

As I recall the GET to POST change was only needed in an edge case involving password access. I will look into changing just that part of the code and restoring the rest of the /co options.

Dan

Dan.

Seems like this is long term problematic as once POST is changed to GET a lot of normal web function stop working. Web page options page becomes non-functional for changes. So I'm headed in a different direction using the run-once functionality which defeats the value of things like setting programs, waterlevel options, etc. Does it make sense to break off the use password and new password options into a separate type of http command group to allow options to be changed without the security risks to the password compromise? 

Thanks,
Reply
#5
I think I found a solution.
I just pushed an update to GitHub.
As of version: 4.1.51 the GET commands for options should be working


Also the GET commands PDF has been updated to show the correct commands:
https://raw.githubusercontent.com/wiki/D...mmands.pdf

For example, to set the water level you would use <SIP URL>/co?owl=50
assuming password access is not on.

Let me know if you encounter any problems.

Dan
<p><br></p>
Reply
#6
(2022 Nov 17, 04:22 PM)dan Wrote: I think I found a solution.
I just pushed an update to GitHub.
As of version: 4.1.51 the GET commands for options should be working


Also the GET commands PDF has been updated to show the correct commands:
https://raw.githubusercontent.com/wiki/D...mmands.pdf

For example, to set the water level you would use <SIP URL>/co?owl=50
assuming password access is not on.

Let me know if you encounter any problems.

Dan

Dan,

Got the update installed using the system update on the website. Ran into the following issues:
1) I had to move the webages.py file that I modified earlier to get the update to install.
2) I'm using it on an Dell Wyse z90d7 mini pc running Ubuntu that does not have GPIO pins. So the restart fails due to the GPIO.cleanup()
Exception in thread Thread-14:
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]: Traceback (most recent call last):
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]:  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]:    self.run()
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]:  File "/usr/lib/python3.8/threading.py", line 870, in run
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]:    self._target(*self._args, **self._kwargs)
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]:  File "/home/bitman1/SIP/helpers.py", line 176, in restart
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]:    GPIO.cleanup()
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]: NameError: name 'GPIO' is not defined
workaround was to do a restart using systemctl

Web Home page shows the correct version of SIP and syslog showed that just webpages.py was updated for this update.

I will let you know after some testing how this update works. I will be using it in password mode.

On a separate note. I have a couple of hacks that I added to gv.py and helpers.py to attempt fix cpu temperature display issue on my Ubuntu install. I assume that I will have to do the same move the gv.py and helpers.py files for future updates that include these files.
Here are my hacks
gv.py
#determine platform for use with temperature and other system specific items
oscmd = "cat /etc/os-release | grep ^ID= | sed -e 's/^ID=//'"
osval = subprocess.check_output(oscmd, shell=True).strip()  #returns output of cmd with byte value
platform = osval.decode("utf-8")

helpers.py
def get_cpu_temp():
    """
    Reads and returns the Celsius temperature of the CPU if available.
#    If unit is F, temperature is returned as Fahrenheit otherwise Celsius.
    """
    try:
        print(gv.platform)
        if gv.platform == u"bo":
            res = os.popen(u"cat /sys/class/hwmon/hwmon0/device/temp1_input").readline()
            temp = u"" + str(int(res / 1000.0))
>>>>        elif gv.platform == "raspbian" or gv.platform == "debian" or gv.platform == "ubuntu":  <<<<
            command = u"cat /sys/class/thermal/thermal_zone0/temp"
            output = int(subprocess.check_output(command.split()))
            temp = int(output / 1000.0)
        else:
            return u""
        return temp
    except Exception:
        return u""

These 2 hacks work for raspberry pi using rasbian or debian or ubuntu and other hardware running debian or ubuntu.

Best,

Bryan
Reply
#7
(2022 Nov 23, 05:24 PM)tutqiunnh Wrote:
(2022 Nov 17, 04:22 PM)dan Wrote: I think I found a solution.
I just pushed an update to GitHub.
As of version: 4.1.51 the GET commands for options should be working


Also the GET commands PDF has been updated to show the correct commands:
https://raw.githubusercontent.com/wiki/D...mmands.pdf

For example, to set the water level you would use <SIP URL>/co?owl=50
assuming password access is not on.

Let me know if you encounter any problems.

Dan

Dan,

Got the update installed using the system update on the website. Ran into the following issues:
1) I had to move the webages.py file that I modified earlier to get the update to install.
2) I'm using it on an Dell Wyse z90d7 mini pc running Ubuntu that does not have GPIO pins. So the restart fails due to the GPIO.cleanup()
Exception in thread Thread-14:
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]: Traceback (most recent call last):
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]:  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]:    self.run()
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]:  File "/usr/lib/python3.8/threading.py", line 870, in run
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]:    self._target(*self._args, **self._kwargs)
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]:  File "/home/bitman1/SIP/helpers.py", line 176, in restart
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]:    GPIO.cleanup()
Nov 23 11:58:29 bdp-cam-serv1 sip[69234]: NameError: name 'GPIO' is not defined
workaround was to do a restart using systemctl

Web Home page shows the correct version of SIP and syslog showed that just webpages.py was updated for this update.

I will let you know after some testing how this update works. I will be using it in password mode.

On a separate note. I have a couple of hacks that I added to gv.py and helpers.py to attempt fix cpu temperature display issue on my Ubuntu install. I assume that I will have to do the same move the gv.py and helpers.py files for future updates that include these files.
Here are my hacks
gv.py
#determine platform for use with temperature and other system specific items
oscmd = "cat /etc/os-release | grep ^ID= | sed -e 's/^ID=//'"
osval = subprocess.check_output(oscmd, shell=True).strip()  #returns output of cmd with byte value
platform = osval.decode("utf-8")

helpers.py
def get_cpu_temp():
    """
    Reads and returns the Celsius temperature of the CPU if available.
#    If unit is F, temperature is returned as Fahrenheit otherwise Celsius.
    """
    try:
        print(gv.platform)
        if gv.platform == u"bo":
            res = os.popen(u"cat /sys/class/hwmon/hwmon0/device/temp1_input").readline()
            temp = u"" + str(int(res / 1000.0))
>>>>        elif gv.platform == "raspbian" or gv.platform == "debian" or gv.platform == "ubuntu":  <<<<
            command = u"cat /sys/class/thermal/thermal_zone0/temp"
            output = int(subprocess.check_output(command.split()))
            temp = int(output / 1000.0)
        else:
            return u""
        return temp
    except Exception:
        return u""

These 2 hacks work for raspberry pi using rasbian or debian or ubuntu and other hardware running debian or ubuntu.

Best,

Bryan
Thanks for the feedback Bryan,

You are definitely running SIP under unusual conditions but I think others have tried something similar.
I'll take a look at the "name 'GPIO' is not defined" error. There is an internal option to disable the use of GPIO pins (gv.use_gpio_pins = 0) so it may be possible to skip the error in future updates.

I'll also check out your temperature code and probably include it in a future update.

SIP's system updater uses git pull to do the update and raises an error of you have made any uncommitted changes to the code. One way around that is to do a git stash before the update to save your changes, then do the update and then
git stash apply to restore your changes.

Dan
<p><br></p>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)