infeeeee / kimai2-cmd

Command line client for Kimai2, the open source, self-hosted time tracker
MIT License
26 stars 6 forks source link

SyntaxError: Unexpected token < in JSON at position 0 #10

Closed rg-ch closed 5 years ago

rg-ch commented 5 years ago

Hello, I've cloned the most recent version node kimai2-cmd.js -V 0.2.5 node v11.15.0 npm v6.11.2 Linux 4.19.66-1-MANJARO

[serversettings] kimaiurl=https://server.ch/kimai2/public username=myuser password=mypassword

if I'm understanding correctly my access logs, the settings.ini is correct because i've got redirected (Code 302) and logged in (code 200), isn't it ?

server.ch XX.XX.XXX.XXXX - - [04/Sep/2019:13:39:57 +0200] "GET /kimai2/public/en/login HTTP/1.1" 200 3865 "https://server.ch/kimai2/public/api/projects" "-"

server.ch XX.XX.XXX.XXXX - - [04/Sep/2019:13:39:56 +0200] "GET /kimai2/public/api/projects HTTP/1.1" 302 420 "-" "-"

I can launch the menu image

But any selected function but Exit creates following error messages image

Hosting (https://www.infomaniak.com/) Kimai 2 1.2 stable (Ayumi) Debian 4.9.168-1+deb9u3~deb8u1 (2019-06-17) x86_64 GNU/Linux PHP 7.3.8 mysql Ver 14.14 Distrib 5.5.62, for debian-linux-gnu (x86_64) using readline 6.3

Thank you for any possible help

infeeeee commented 5 years ago

I think your kimaiurl is wrong. If you write it correctly you should get a json response from the api, but you get <!DOCTYPE html> which is the beginning of a html page. Your server logs show the access because you actually access your server but not the api but a regular page.

The program constructs the api address this way: kimaiurl + /api

You have to find your correct url, I think it will be https://server.ch/kimai2 without the public dir.

You can check your url this way: every installation contains the api documentation at the url /api/doc. You can find the docs of the demo install here: https://demo.kimai.org/api/doc (user: anna_admin pass: kitten). Find this page on your installation, remove the /api/doc from the end of its address, and use this address in settings.ini.

rg-ch commented 5 years ago

Thank you for your fast answer. I tested my local client with the demo settings. It's working.

Having no access to my vhost definitions I can't configure it as recommended in the docs (see below).

ServerName kimai.local ServerAlias www.kimai.local DocumentRoot /var/www/kimai2/public <Directory /var/www/kimai2/public> source: Docs Kimai -> Create VirtualHost

That means I have to point directly to public/ see below, do I ?

ch/kimai2/public/api/doc

image

Perhaps that's the problem ? Can I define something equivalent to DocumentRoot in my kimai2/.htaccess For the moment it contains only

SetEnv PHP_VERSION 7.3

I've tried some hacks but my htaccess rewritings didn't work.

Do you have a hint or an idea ? Thanks a lot ... I'm conscious that's more a problem of a server configuration than an api problem.

infeeeee commented 5 years ago

Yes, it's definitely a problem with your installation. I don't really know apache and htacces files (I use nginx), so I can't help you setting that up. But here are some tips troubleshooting:

You can test your api access with the demo application from the docs: https://www.kimai.org/documentation/rest-api.html Just copy the demo on the bottom of the page to a new file, save as api.html, open with your browser and login with your server credentials. You should use the same url as serverurl as here.

Also what is the output of this wget request:

wget -O- --header="X-AUTH-USER: anna_admin" --header="X-AUTH-TOKEN: api_kitten" https://demo.kimai.org/api/projects

Replace anna_admin with your username, api_kitten with your apipassword, and the url with your server's url. You should get a json list of projects, but you will get some html, maybe it will help figure out where you are redirected to instead of the api.

rg-ch commented 5 years ago

Thank you very much for your help. I will try and coming back

kevinpapst commented 5 years ago

@rg-ch Using Kimai like this is dangerous.! Can you see your .env file in your browser your-server.ch/kimai2/.env ? If so, thats obviously a critical problem. Every hoster should be able to change the document root. Use a subdomain if you can't configure path mappings! Or get a new hoster...

rg-ch commented 5 years ago

ouf ... yes i can see .env , thank you for your warning ... I will try a subdomain. That's realy dangerous

rg-ch commented 5 years ago

Dear helpers, thank you very much for your Input. I moved the kimai2 folder and created a subdomain and activated the https part in public/.htaccess. After adjusting the settings.ini everything works like a charm.
image Merci