bfabiszewski / ulogger-server

μlogger • web viewer for tracks uploaded with μlogger mobile client
GNU General Public License v3.0
538 stars 85 forks source link

Error uploading tracks with the app on Android #110

Closed momentum24111 closed 4 years ago

momentum24111 commented 4 years ago

I installed ulogger on my webserver and everything works great (create tracks, edit tracks, etc.). Now I installed the app (Android) and when I try to upload the track I get this error message: https://i.imgur.com/rbRkArP.jpg

Does someone know why?

bfabiszewski commented 4 years ago

Do you see any errors in system or web server logs? What happens if you open client API page in web browser. Android client URL is your web server URL plus client subfolder, eg. http://your_server.tld/client/index.php

momentum24111 commented 4 years ago

I see the following error message on the page http://your_server.tld/client/index.php: {"error":true,"message":"Unknown command"} In response headers:

Cache-Control | no-store, no-cache, must-revalidate
-- | --
Connection | Upgrade, Keep-Alive
Content-Type | application/json
Date | Wed, 22 Jan 2020 14:53:49 GMT
Expires | Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive | timeout=5, max=100
Pragma | no-cache
Server | Apache/2.4.41
Transfer-Encoding | chunked
Upgrade | h2c
X-Powered-By | PHP/7.3.6

I guess it doesn't help, because it says nothing, right?

bfabiszewski commented 4 years ago

This is not expected result. See demo server message.

Which version of µlogger server and client do you use?

momentum24111 commented 4 years ago

I get the same message on the demo server: grafik

On the webserver I use version μlogger 1.0-beta On my Android device version 2.8

bfabiszewski commented 4 years ago

That's a bit different. On your server you get "Unknown command". But that may be because you had logged in on your own server before the check. Which hosting provider do you use? I am asking because some providers block non-browser access by injecting javascript into each request.

momentum24111 commented 4 years ago

My provider is: https://www.df.eu/ I guess you will not know it.

Maybe I should try again installing the docker container on my Synology NAS, which I had other issues too.

bfabiszewski commented 4 years ago

I can't find any info about anti-bot features on this hosting. Try to query your client page with curl, eg. curl -v http://ulogger-demo.herokuapp.com/client/index.php. If you don't have curl on command line, use some online service like https://reqbin.com/curl. You should get same response as from browser. Some hostings return a script which redirects to the real page. Such script works only in browser.

momentum24111 commented 4 years ago

By running a curl I get the following message: { "error": true, "message": "Unauthorized" }

It's pretty strange. Now I get this message in every browser, even if I just call the URL. but I still get the error message in the app, even if I put the right login credentials and the url including index.php at the end. Do you have more advices for me?

momentum24111 commented 4 years ago

Screenshot_20200123_001453_net fabiszewski ulogger-01

bfabiszewski commented 4 years ago

Curl result means that your hosting is ok. Now you get unauthorized, because previously you were logged in in your browser. That's ok.

But now your server URL in settings is wrong (screenshot). You should give main URL of your µlogger server without client part, eg. http://your-domain.tld.

If you correct that and it still does not work it means there is problem with your server setup. You should look into server logs for any warnings or errors.

momentum24111 commented 4 years ago

I now have installed a new uLogger instance (Docker container) on different Hardware, a Synology NAS. Even with that I can connect via Browser and can edit/view the tracks. But on the Android App I again get the same error, as shown in my first comment.

In the log files I can see this line:

172.17.0.1 - - [23/Jan/2020:23:06:22 +0000] "POST /client/index.php HTTP/1.1" 200 50 "-" "ulogger/2.8; Dalvik/2.1.0 (Linux; U; And
roid 10; LYA-L29 Build/HUAWEILYA-L29)" "-"  

The curl answer ist still:

{ "error": true, "message": "Unauthorized" }

Do you have any idea?

bfabiszewski commented 4 years ago

It seems that adding new track from client fails. You may try to add track from command line to make sure this is the problem and to see server answer. Following two commands will add new track. Substitute $USER, $PASS and $URL with real values. It must be run from command line as it creates cookies file in current directory, which may be deleted after tests.

curl -c ./cookies -d "action=auth&user=$USER&pass=$PASS" -X POST http://$URL/client/index.php

curl -b ./cookies -d "action=addtrack&track=test_track" -X POST http://$URL/client/index.php

Correct answer is {"error":false} and {"error":false,"trackid":123} where 123 is new track id.

In case of server errors log messages are written to system defined logger. The exact log destination depends on your setup. Look for any errors in /var/log/syslog, /var/log/messages and PHP and web server logs.

Which database backend do you use?

momentum24111 commented 4 years ago

After running this command (replacing the variables): curl -c ./cookies -d "action=auth&user=$USER&pass=$PASS" -X POST http://$URL/client/index.php I get this anwer: {"error":false}

Request: curl -b ./cookies -d "action=addtrack&track=test_track" -X POST http://$URL/client/index.php Answer: {"error":true,"message":"Unauthorized"}

I'm currently running your docker container, but I don't know how to access the /var/log folders... I guess that my technical know how isn't enough to run such a service. You would probably just need 5 minutes to get it run. :D Sorry for taking so much of your time. I think I will stick to the web service, without using the app...

bfabiszewski commented 4 years ago

The result you get is strange. First command should authorize you and store session id in cookie. The response you get from first command is correct. No error. But you are still unauthorized in second step. Something is going wrong here. Really difficult to solve it. Unfortunately the application lacks proper error reporting.

In docker container logs are redirected to stdout and stderr. You should get it with docker logs -f ulogger.

momentum24111 commented 4 years ago

In the logs (stdout) I get these two entries, when I try to upload a track with the app:

`

2020-01-26 19:01:08 stdout 172.17.0.1 - - [26/Jan/2020:19:01:08 +0000] "POST /client/index.php HTTP/1.1" 200 50 "-" "ulogger/2.8; Dalvik/2.1.0 (Linux; U; Android 10; LYA-L29 Build/HUAWEILYA-L29)" "-"
2020-01-26 19:01:08 stdout 172.17.0.1 - - [26/Jan/2020:19:01:08 +0000] "POST /client/index.php HTTP/1.1" 200 25 "-" "ulogger/2.8; Dalvik/2.1.0 (Linux; U; Android 10; LYA-L29 Build/HUAWEILYA-L29)" "-"

`

bfabiszewski commented 4 years ago

Nothing wrong here. I have no idea. Maybe you experience some bug in Android 10? I tested the app on Android 10 in emulator though without any issues.

momentum24111 commented 4 years ago

I can't believe it! I found the problem. At the beginning I created a new track, in the app. Just for testing. Afterwards I installed uLogger on both my Webservers and typed in the login credentials into the app. The problem: I didn't created a new track, after typing the login credentials. I guess the app makes a request to the server, asking if the track is existing and the server answers with "no". So, instead of creating the new track, the app emits an error. I hope you understand my explanation.

Thank you very much for your great support and your time!! I will be very happy to use your great application.

bfabiszewski commented 4 years ago

Good to hear you solved it! The scenario was probably more complicated than you describe it, because application would create new track if it didn't exist on server. Problem might be that you started the track on one server and later switch to another one where the track didn't exist, but application already received track id from server. Never mind!

Ammiszaddaj commented 3 years ago

Hello, I had exactly the same error message in android app after reinstalling (updating) server. Problem was that i used the app before and there was old track. It was synced and tracking turned off before changing server. Solution was to click "new track" in app. Sincerely

Evidlo commented 3 years ago

Problem might be that you started the track on one server and later switch to another one where the track didn't exist, but application already received track id from server.

I have this situation now. Is there any simple fix for this or do I have to fiddle with the SQL database?

bfabiszewski commented 3 years ago

No simple solution. When new track is synchronized with the client, the ID is created on server and saved on client. If you change the server and try to upload recorded track to new server, the ID will probably not exist there or it may belong to another track. You may try to manually create track on the new server. You will have to copy the ID from the old one. Or just export the track to GPX file and import it from the file on the server.