Cloudflare

mdtaylorlrim8 years ago

Anton,

I am setting up a server that will operate primarily when the internet is NOT available. I see that traccar uses libraries hosted at cloudflare.com

Is there a way to make traccar completely standalone or will I have to search for another solution?

Thanks
Mark

Anton Tananaev8 years ago

You can just copy those libraries locally and update links. That's not a problem.

The problem would be map tiles. If you want your server to operate offline, you need a local tile server.

mdtaylorlrim8 years ago

Cool. Now that I know it is possible I'll start researching how to do that. Thanks!

Anton Tananaev8 years ago

It's definitely possible, but it might require some effort. If you manage to implement it, please share some information with the community. Some other people might be interested as well.

mdtaylorlrim8 years ago

As it turns out it is really quite simple, although we still have some bugs to work out.

Create the following directories:
~/traccar/cloudflare
~/traccar/cloudflare/images
~/traccar/cloudflare/images/button
~/traccar/cloudflare/images/form
~/traccar/cloudflare/images/loadmask
~/traccar/cloudflare/images/tools
~/traccar/cloudflare/images/util
~/traccar/cloudflare/images/util/splitter

Download the following from cloudflare and put in the directories.
Cloudflare:
ext-all-debug.js
ext-all.js
font-awesome.min.css
ol.css
ol-debug.js
theme-neptune-all_1.css
theme-neptune-all_2.css
theme-neptune-all.css
theme-neptune.js

Images:
date-trigger.png
exclamation.png

Button:
default-toolbar-small-arrow.png

Form:
trigger.png

Loadmask:
loading.gif

Tools:
tool-sprites.png

Splitter:
mini-left.png
mini-top.png

In ~/traccar/web/debug.html chage the links to cloudflare files:
<link rel="stylesheet" href="cloudflare/theme-neptune-all.css">
<link rel="stylesheet" href="cloudflare/ol.css">
<link rel="stylesheet" href="cloudflare/font-awesome.min.css">

I then created the directory ~/traccar/web/osm
Then set up OpenStreetMap server including a ~/traccar/web/osm/tiles directory.
Download the tiles maintaining the directory structure and put in the tiles directory. I used TileDownloader from https://sourceforge.net/projects/tiledownloader/

In the traccar UI select Settings -> server
Select custom map
Enter path to your tiles: http://[your_server]:8082/osm/tiles/{z}/{x}/{y}.png
(This assumes your tiles are in .png format. Adjust as necessary.)

There is still some tweaks to be done. We find errors in Firefox Developer tools. The one we are having trouble resolving is a call to ext-all.js is failing even though it is there and is displayed in the browser. It reports "Unreachable code after return statement."

And also, I am getting a file not found for ~/traccar/web/api/session that I cannot resolve.

Nothing prevents Traccar from working. It is just causing a delay on login/logout. Other than that I can see no effects from it.

Cheers,
Mark

Anton Tananaev8 years ago

You can ignore the session not found warning. It's intended behavior.

Not sure about unreachable code. Does Chrome show same warning as well?

mdtaylorlrim8 years ago

I have not tried any other browser except Firefox. I'll try some others. I always forget to do that...

mdtaylorlrim8 years ago

Well that helped me find another needed change. Thanks Anton.

I missed a link change in a file. Add the following to the post above:

Change all relative links in release.html

<link rel="stylesheet" href="cloudflare/theme-neptune-all.css">
<link rel="stylesheet" href="cloudflare/ol.css">
<link rel="stylesheet" href="cloudflare/font-awesome.min.css">
<link rel="stylesheet" href="app.css">
</head>
<body>
<div id="spinner"></div>
<div id="attribution">Powered by Traccar GPS Tracking System</div>
<script src="cloudflare/ext-all.js"></script>
<script src="cloudflare/theme-neptune.js"></script>
<script src="cloudflare/ol-debug.js"></script>
<script src="arrowstyle.js"></script>
<script src="locale.js"></script>
<script type="text/javascript">
Ext.Loader.loadScript('app.min.js');
</script>

Mark

Christopher8 years ago

Hi Mark,

How did you download all the files from Cloudflare?
All separately or is there a download link for the files somewhere?

Thanks!

Chris

Jeff Moe8 years ago

It would be nice if by default external services were disabled for privacy, except those required to function. For instance, cloudflare/cdn and google address lookups could be disabled by default.

I'm going to look into setting up my own tile server too. Thanks for the tips & info above.

-Jeff

Jeff Moe8 years ago

I set up tilestache from Debian Jessie. I created a config in /etc/tilestache.cfg


{
  "cache":
  {
    "name": "Disk",
    "path": "/tmp/stache",
    "umask": "0000",
    "verbose": true,
    "dirs": "portable",
    "gzip": ["xml", "json"]
  },
  "layers": 
  {
    "osm":
    {
        "provider": {"name": "proxy", "provider": "OPENSTREETMAP"},
        "png options": {"palette": "http://tilestache.org/example-palette-openstreetmap-mapnik.act"}
    }
  }
}

I then run it thusly:

tilestache-server -c /etc/tilestache.cfg -i 127.0.0.1

I can pull a tile from it ok:

wget http://127.0.0.1:8080/osm/5/2/3.png

I set the configuration in the traccar web GUI:
Settings ---> Server ---> Custom Map:
http://127.0.0.1:8080/osm/{z}/{x}/{y}.png

Settings ---> Account ---> Map Layer: Custom Map

Log out and log back in.

But when I do that, I don't see traccar making any attempts to pull a tile. I just get a blank map with my devices overlaid on white. The URL isn't 404, it just never tries to hit it.

Any hints? Thanks again!

-Jeff

Anton Tananaev8 years ago

I don't agree with not using external services by default. Most people won't be able to set up their own tile and reverse geocoding server, so it's good to use external services to allow those people to use Traccar system with minimum technical knowledge to set it up.

Traccar supports option to use everything local, so those who want to avoid external services, will always have this option.

As for the tile problem, have you checked browser console? What URLs does it use for tiles?

Jeff Moe8 years ago

Ya, most can't set up a tile server, so that would have to be external. But the reverse geocoding could be disabled. I was just surprised to find that by default my addresses were sent to google.

As for the images, I thought it was traccar that made the requests and then served up the web page. But it just gives the URL, which in this case was 127.0.0.1. I haven't done it yet, but I'm guessing if I move it to a public IP, it will start working.

Thanks!!

-Jeff

Anton Tananaev8 years ago

Most people can't even set up reverse geocoding. It used to be disabled by default and I got a lot of complaints that address is empty. The only thing that is sent to Google is raw latitude and longitude. There is no identification, so data is completely anonymous. Again, there is always an option to disable it or use your own service. I can't satisfy everybody with default configuration, so I'm trying my best to find default configuration that would be suitable for most people.

Traccar won't proxy tile requests. I don't see any reason for it to do so.

Jeff Moe8 years ago

Ok, so I did a few changes to get it to work. In this case, instead of serving tilestache directly, I proxy it through apache2 so I can use https.

I added this to the apache config file (as described here https://www.traccar.org/secure-connection/ ):

        ProxyPass /osm http://localhost:8080/osm
        ProxyPassReverse /osm http://localhost:8080/osm

Then the Custom Map URL is: https://somedomain.comm/osm/{z}/{x}/{y}.png

It works, and everything gets served via the main domain in https. :)

Thanks!

-Jeff