10

I'm trying to display my PIs temperatures in a website that I can access anywhere at any time.

So far I've been able to get the CPU and GPU temps working. However my HDD temp won't show in the browser. It works fine in terminal.

Here is a pic:

Image

As you'll notice I didn't have the GPU temp showing either, however this was fixed by using the following command:

sudo usermod -G video www-data

I haven't been successful in getting this to work for smartmoxntools, though.

Does anyone know how to make it work?

Also, is it safe to have these in an external website? Can hackers inject php code to run shell commands using it?

Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90
Rapid
  • 1,442
  • 1
  • 13
  • 25
  • Improved grammar and clarity – Peter DeWeese Jan 27 '16 at 13:04
  • Does your Raspberry Pi *have* a hard drive that supports SMART? Many USB drives don't, and the onboard SD card isn't a hard drive. –  Jan 27 '16 at 19:53
  • Yes. As you can see, when I run it in terminal it picks up the value for SMART attribute 194. I believe this issue is simply to do with permissions. – Rapid Jan 27 '16 at 23:10
  • Please do not rely on third-party websites to share your code (if the external website goes down, your question becomes meaningless). Instead, paste a relevant excerpt *inside* your question. – RandomSeed Feb 01 '16 at 12:06

2 Answers2

5

in order to run some root privileged command in website, you need to put www-data in your /etc/sudoers to allow the www-data to run as root for the command, here is the line you need in /etc/sudoers:

www-data ALL=(root) NOPASSWD: /usr/sbin/smartctl
Allen
  • 6,505
  • 16
  • 19
2

When executing under your web server, your script will probably have a different PATH configured, so it will run differently from how it runs in the Terminal.

Try putting the full path to smartctl in your script, e.g.

sudo /usr/local/bin/smartctl -A -d sat /dev/sda | awk '/^194/ {print $10}'
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Hi, thanks for this idea. It was certainly worth trying. Unfortunately it hasn't changed the outcome. Oh, also, I had to use the following path "/usr/sbin/smartctl". It still works in my SSH terminal, but not via the web. – Rapid Jan 27 '16 at 23:11