econpy / torque

A set of tools used with the Torque app for Android to store OBD2 data in MySQL, view GPS data from Torque on a map in real time using the Google Maps JavaScript API, plot OBD2 data in time series charts, and export the data to CSV or JSON.
MIT License
285 stars 120 forks source link

Assistance in webserver configuration? #13

Open surfrock66 opened 10 years ago

surfrock66 commented 10 years ago

Hello, I'd like to start using and contributing to this, but I'm having an issue with my webserver configuration. I'm getting a permission error in my apache logs, and I haven't been able to diagnose it yet. Error:

[Thu Jul 24 12:40:41.459292 2014] [core:error] pid 4248Permission denied: [client 198.217.64.23:47298] AH00035: access to /torque/static/js/jquery.flot.updater.js denied (filesystem path '/var/www/torque/static/js') because search permissions are missing on a component of the path, referer: http://hda.surfrock66.com/torque/session.php

My www-data user has recursive permissions to /var/www which includes /var/www/torque. Thoughts?

econpy commented 10 years ago

First check your current permissions a day post them:

ls -l /var/www
ls -l /var/www/torque

Just to be sure, try running this command:

sudo chown -R www-data:www-data /var/www

Finally see if anything changed:

ls -l /var/www
ls -l /var/www/torque

Start with this, but eventually you'll want to add your user to the www-data group and give owner/group permissions of these folders (so you can edit files and not have to use root and thus reset ownership afterwards).

surfrock66 commented 10 years ago

surfrock66@sr66-blade:/var/log/apache2$ ls -l /var/www total 40 drwxr-xr-x 3 www-data users 4096 Sep 16 2013 ajaxplorer drwxrwsr-x 2 surfrock66 www-data 4096 Oct 3 2013 ajaxterm drwxr-xr-x 4 www-data users 4096 Sep 9 2013 apps-proxy drwxr-xr-x 2 root root 4096 Apr 3 05:21 html -rw-r--r-- 1 root www-data 177 Nov 5 2013 index.html drwxrwsr-x 2 surfrock66 www-data 4096 Jan 2 2014 maps drwxr-xr-x 5 root root 4096 Sep 9 2013 proftpd -rw-r--r-- 1 root root 0 Sep 17 2013 server.key drwxr-xr-x 4 surfrock66 surfrock66 4096 Jul 23 21:32 torque drwxr-xr-x 21 www-data users 4096 Nov 19 2013 ttrss drwxrwsr-x 3 www-data www-data 4096 Sep 25 2013 webvnc surfrock66@sr66-blade:/var/log/apache2$ ls -l /var/www/torque total 64 -rw-r--r-- 1 surfrock66 surfrock66 214 Jul 23 21:32 creds.php drw-r--r-- 2 surfrock66 surfrock66 4096 Jul 23 21:31 data -rw-r--r-- 1 surfrock66 surfrock66 1629 Jul 23 21:31 export.php -rw-r--r-- 1 surfrock66 surfrock66 843 Jul 23 21:31 get_columns.php -rw-r--r-- 1 surfrock66 surfrock66 880 Jul 23 21:31 get_sessions.php -rw-r--r-- 1 surfrock66 surfrock66 1679 Jul 23 21:31 parse_functions.php -rw-r--r-- 1 surfrock66 surfrock66 2756 Jul 23 21:31 plot.php -rw-r--r-- 1 surfrock66 surfrock66 18334 Jul 23 21:31 session.php drw-r--r-- 4 surfrock66 surfrock66 4096 Jul 23 21:31 static -rw-r--r-- 1 surfrock66 surfrock66 69 Jul 23 21:31 timezone.php -rw-r--r-- 1 surfrock66 surfrock66 1526 Jul 23 21:31 upload_data.php -rw-r--r-- 1 surfrock66 surfrock66 1204 Jul 23 21:31 url.php surfrock66@sr66-blade:/var/log/apache2$ sudo chown -R www-data:www-data /var/www [sudo] password for surfrock66: surfrock66@sr66-blade:/var/log/apache2$ ls -l /var/www total 40 drwxr-xr-x 3 www-data www-data 4096 Sep 16 2013 ajaxplorer drwxrwsr-x 2 www-data www-data 4096 Oct 3 2013 ajaxterm drwxr-xr-x 4 www-data www-data 4096 Sep 9 2013 apps-proxy drwxr-xr-x 2 www-data www-data 4096 Apr 3 05:21 html -rw-r--r-- 1 www-data www-data 177 Nov 5 2013 index.html drwxrwsr-x 2 www-data www-data 4096 Jan 2 2014 maps drwxr-xr-x 5 www-data www-data 4096 Sep 9 2013 proftpd -rw-r--r-- 1 www-data www-data 0 Sep 17 2013 server.key drwxr-xr-x 4 www-data www-data 4096 Jul 23 21:32 torque drwxr-xr-x 21 www-data www-data 4096 Nov 19 2013 ttrss drwxrwsr-x 3 www-data www-data 4096 Sep 25 2013 webvnc surfrock66@sr66-blade:/var/log/apache2$ ls -l /var/www/torque total 64 -rw-r--r-- 1 www-data www-data 214 Jul 23 21:32 creds.php drw-r--r-- 2 www-data www-data 4096 Jul 23 21:31 data -rw-r--r-- 1 www-data www-data 1629 Jul 23 21:31 export.php -rw-r--r-- 1 www-data www-data 843 Jul 23 21:31 get_columns.php -rw-r--r-- 1 www-data www-data 880 Jul 23 21:31 get_sessions.php -rw-r--r-- 1 www-data www-data 1679 Jul 23 21:31 parse_functions.php -rw-r--r-- 1 www-data www-data 2756 Jul 23 21:31 plot.php -rw-r--r-- 1 www-data www-data 18334 Jul 23 21:31 session.php drw-r--r-- 4 www-data www-data 4096 Jul 23 21:31 static -rw-r--r-- 1 www-data www-data 69 Jul 23 21:31 timezone.php -rw-r--r-- 1 www-data www-data 1526 Jul 23 21:31 upload_data.php -rw-r--r-- 1 www-data www-data 1204 Jul 23 21:31 url.php surfrock66@sr66-blade:/var/log/apache2$

econpy commented 10 years ago

That looks like it should have done the trick. Your ownerships were definitely messed up. Does it work now?

surfrock66 commented 10 years ago

Now my error.log looks like this...thousands of entries of it:

[Thu Jul 24 13:28:54.070479 2014] [:error] [pid 1616] [client 198.217.64.22:55746] PHP Warning: feof() expects parameter 1 to be resource, boolean given in /var/www/torque/parse_functions.php on line 6, referer: http://hda.surfrock66.com/torque/session.php [Thu Jul 24 13:28:54.070505 2014] [:error] [pid 1616] [client 198.217.64.22:55746] PHP Warning: fgetcsv() expects parameter 1 to be resource, boolean given in /var/www/torque/parse_functions.php on line 7, referer: http://hda.surfrock66.com/torque/session.php [Thu Jul 24 13:28:54.070530 2014] [:error] [pid 1616] [client 198.217.64.22:55746] PHP Warning: feof() expects parameter 1 to be resource, boolean given in /var/www/torque/parse_functions.php on line 6, referer: http://hda.surfrock66.com/torque/session.php [Thu Jul 24 13:28:54.070558 2014] [:error] [pid 1616] [client 198.217.64.22:55746] PHP Warning: fgetcsv() expects parameter 1 to be resource, boolean given in /var/www/torque/parse_functions.php on line 7, referer: http://hda.surfrock66.com/torque/session.php

econpy commented 10 years ago

I dug into it a bit and think you're getting these errors in parse_functions.php because of the changes made to CSV file parsing in PHP 5.5 (which your server is running), so I modified the CSVtoJSON function in parse_functions.php to work with all PHP 5.x versions. Go ahead and replace your current file with the updated parse_functions.php file and let me know if that solves the issue you're having.

surfrock66 commented 10 years ago

Error when plotting:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '! FROM raw_logs WHERE sessio' at line 1

I don't see that SQL call in this file or plot...I'm looking through the source, but you may know it faster.

surfrock66 commented 10 years ago

By the way it's public for now, if you want to see: http://hda.surfrock66.com/torque/

econpy commented 10 years ago

Browsing to your session.php file and inspecting the requests, I see that tons (all) of your static resources are failing to load. This is because you don't have the static folder at torque/static/ with all the js/css files it is asking for! You also don't have the data folder at torque/data/, which also explains why the earlier command about parsing the CSV file was failing. That file is supposed to be at torque/data/torque_keys.csv.

So you need to copy the static folder and the data folder to your torque directory.

As for the error with SQL syntax, there is a call that looks like what you posted in plot.php: here is the line.

After you copy the static and data folders to your torque directory, make sure your permissions are set. Just run these commands to get everything squared away after copying in the files:

sudo chmod -R 644 /var/www/torque/*
sudo chmod 755 /var/www/torque/
sudo chown -R www-data:www-data /var/www/torque
surfrock66 commented 10 years ago

weird...I ran that yesterday and it didn't run recursively. I just chmod'd static and data to 755 and now it works fine.

surfrock66 commented 10 years ago

I still get some errors choosing specific sensors though. Choose "Speed ODB" and you'll see that. I dropped the new parse_functions.php in there.

econpy commented 10 years ago

Looks like it's working just fine. Remember you have to select a session first, then select your sensors. The default map that is shown when you go to session.php is a map of Area 51, not your GPS data. So selecting sensors from the default session page doesn't do any good.

surfrock66 commented 10 years ago

Try this: go to session.php. Choose the 2nd session (July 24, 2014 03:53pm) then select "Speed (OBD)" and hit plot. I see the map fine, but when I hit plot, I'm taken here: http://awesomescreenshot.com/05437oda6b URL is http://hda.surfrock66.com/torque/session.php?id=1406242396033&s1=kd&s2=Plot!

econpy commented 10 years ago

You need to select exactly 2 sensors (so Speed OBD + something else) and it will render properly. I was able to replicate the problem you described though when I only selected 1 sensor.

This points out a useful bug though -- if the user only selects 1 sensor to plot, then it should only plot that 1 or it should automatically select a 2nd for them to avoid this error. I'll try and find time to fix that this weekend.

surfrock66 commented 10 years ago

Makes sense, thanks! Thanks for helping me figure this out, and I really appreciate this as I prefer self-hosted solutions.

The only other feature I'd like to see (and I don't think you can necessarily do this) is transferring data from Ian's version into this one...he'd first have to enable an export for you to have an import, unless you can think of a way to upload old tracks from the app itself (which

chandra50 commented 8 years ago

Hi, Any resolution to mysql issues referred in 'As for the error with SQL syntax, there is a call that looks like what you posted in plot.php: here is the line.'

Thanks.