dancyPi-audio-reactive-led icon indicating copy to clipboard operation
dancyPi-audio-reactive-led copied to clipboard

PHP URL commands not activating visualizations.

Open Codename-11 opened this issue 5 years ago • 8 comments

I was able to successfully implement Scotts original and everything works fine. I stumbled across your fork which solved the issue of controlling the on/off state of the LED strip and visualizations. Thank you kindly for that! Very handy feature. I'm having a problem however with getting the visualization('s) to execute via the URL. Everything works as intended using the command line arguments to change the visualization. I do have Apache2 and PHP installed. I did test a couple simple "hello world" and print date PHP index files to insure that Apache could run PHP scripts, which were successful. The http://ip-address/control.php?on=spectrum returns nothing on the page (expected) but does not start the visualization (unexpected). http://ip-address/control.php?off=1 reutrns sudo: no tty present and no askpass program specifiednada, not sure why... Any suggestions? Thanks!

Codename-11 avatar Oct 02 '19 14:10 Codename-11

That looks like a permissions issue. What's in your /etc/sudoers file? Do you see anything that says tty there? If you do, try disabling it and try again.

naztronaut avatar Oct 03 '19 05:10 naztronaut

I was able to get it to work! I checked the sudoers file and there's nothing listed pertaining to TTY. I made sure all the files in /var/www/html are owned by the www-data user/group.

I did some googling on the error and it pertaining to Apache and found that I needed to give the user www-data permissions to use python in the sudoers file. For the sake of testing, I used ww-data ALL = NOPASSWD: /usr/bin/python, however I do think it's probably a security flaw to have NOPASSWD, so ether I have to see how to restrict the user's privilege to only execute visualization.py and or add a password for said command to be executed.

Thanks for the help! Prehaps we should add something about this to the README?

Codename-11 avatar Oct 03 '19 14:10 Codename-11

It's very strange that you ran into this. You shouldn't have to do that. Did you make sure that www-data owned all the files in /var/www/html (listed in Browser Setup)? If you did and you still got the error, my mind is stuck.

naztronaut avatar Oct 03 '19 15:10 naztronaut

I also added a new troubleshooting section and referenced this issue and the workaround you posted: https://github.com/naztronaut/dancyPi-audio-reactive-led#troubleshooting

Thanks for doing that!

And I'm really glad you got it to work :) congrats!!

naztronaut avatar Oct 03 '19 15:10 naztronaut

The user www-data does own all the files inside of /var/www/html. Screenshot_20191003_122133 The only file that isn't owned by www-data is the index.php I created which just shows a line of text on the page describing what it's for. I did try removing that and attempting to run the visuals as stated in Browser Setup, but to no avail. I will do a freash install again when I get the chance and work it backwards and see if I can find out a cause since you're saying that I shouldn't need to give www-data Python permissions in the sudoers file. I'll let you know what I come up with.

Unrelated to this issue, but if you're interested I also came up with a solution for controlling the strips visualization and on/off using your repository via Home Assistant. It doesn't use the web server, it uses SSH to remotely run the commands and an automation to run sudo killall python and run off.py in sequence so no conflicts happen. I couldn't have done this without your expansion on Scott's repo, so I really appreciate the work man. I'd love to contribute where I can! Let me know.

Codename-11 avatar Oct 03 '19 16:10 Codename-11

It might work if you have www-data own index.php. Since it's owned by root, www-data doesn't have access unless you allow it through the sudoers list. Good luck with your fresh install! Let me know how that goes.

I'm interested in learning about your home assistant setup! That's actually been on my list todo for a while but I haven't had any time to work on it. Would love to see what you have :) Thanks!

naztronaut avatar Oct 03 '19 18:10 naztronaut

I’m not sure the workaround you added with the sudoers file covers the sudo killall python command in control.php when passing the off=1 URL variable?

NickSutton avatar Nov 14 '19 18:11 NickSutton

For info, changing your trouble shooting to: www-data ALL=(ALL) NOPASSWD: ALL Will allow your php pages to run the sudo killall python command and correctly stop the LEDs

NickSutton avatar Nov 15 '19 17:11 NickSutton