travlrmap 0.0.17 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,11 @@
18
18
  :cluster_image_extension: png
19
19
  :cluster_image_sizes: [25, 27, 31, 37, 43]
20
20
  :show_geocode_link: true
21
+ :authenticate: false
22
+ #:admin_user: admin
23
+ #:admin_salt: d34fda332c9a0f8997d33db8172b67b1a319fd79d108568aa4fbdb2b
24
+ #:admin_hash: 267d09bb203ec5c9a20eb7dbc1a
25
+ #:google_analytics_id: UA-99999999-9
21
26
 
22
27
  :views:
23
28
  :default:
@@ -4,6 +4,7 @@ module Travlrmap
4
4
  @config = config
5
5
  @map = @config[:map]
6
6
  @types = @config[:types]
7
+ @js_map_update = false
7
8
 
8
9
  raise "The constant APPROOT should be set in config.ru to the directory your webserver is serving from" unless defined?(APPROOT)
9
10
  raise "The directory %s set in APPROOT does not exist" % APPROOT unless File.directory?(APPROOT)
@@ -22,6 +23,31 @@ module Travlrmap
22
23
 
23
24
  alias_method :h, :escape_html
24
25
 
26
+ def protected!
27
+ return if authorized?
28
+ headers['WWW-Authenticate'] = 'Basic realm="Restricted Area"'
29
+ halt(401, "Not authorized\n")
30
+ end
31
+
32
+ def authorized?
33
+ return true if !@map[:authenticate]
34
+
35
+ halt(500, ":admin_salt: is not set in the config") unless @map[:admin_salt]
36
+ halt(500, ":admin_salt: should be at least 16 characters") unless @map[:admin_salt].length >= 16
37
+ halt(500, ":admin_user: is not set in the config") unless @map[:admin_user]
38
+ halt(500, ":admin_hash: is not set in the config") unless @map[:admin_hash]
39
+
40
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
41
+
42
+ if @auth.provided? && @auth.basic? && @auth.credentials
43
+ provided_hash = Digest::MD5.hexdigest("%s%s" % [@map[:admin_salt], @auth.credentials[1]])
44
+
45
+ return (@auth.credentials[0] == @map[:admin_user] && provided_hash == @map[:admin_hash])
46
+ end
47
+
48
+ false
49
+ end
50
+
25
51
  def base_url
26
52
  @base_url ||= "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}"
27
53
  end
@@ -49,6 +75,7 @@ module Travlrmap
49
75
  @street_view_control = @map[:street_view_control].nil? ? false : @map[:street_view_control]
50
76
  @overview_control = @map[:overview_control].nil? ? false : @map[:overview_control]
51
77
  @pan_control = @map[:pan_control].nil? ? true : @map[:pan_control]
78
+ @js_map_update = true
52
79
  end
53
80
 
54
81
  def to_json
@@ -107,7 +134,13 @@ module Travlrmap
107
134
  erb :index
108
135
  end
109
136
 
137
+ get '/about' do
138
+ erb :about
139
+ end
140
+
110
141
  get '/geocode' do
142
+ protected!
143
+
111
144
  erb :geolocate
112
145
  end
113
146
 
@@ -122,6 +155,8 @@ module Travlrmap
122
155
  end
123
156
 
124
157
  post '/points/validate' do
158
+ protected!
159
+
125
160
  content_type :"application/json"
126
161
 
127
162
  data = JSON.parse(request.body.read)
@@ -1,3 +1,3 @@
1
- module Travlmap
2
- VERSION = "0.0.17"
1
+ module Travlrmap
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/travlrmap.rb CHANGED
@@ -3,6 +3,7 @@ require 'bundler/setup'
3
3
  require 'yaml'
4
4
  require 'sinatra'
5
5
  require 'json'
6
+ require "digest/md5"
6
7
 
7
8
  Bundler.require(:default)
8
9
 
@@ -0,0 +1,11 @@
1
+ <% if @map[:google_analytics_id] %>
2
+ <script>
3
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
4
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
5
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
6
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
7
+
8
+ ga('create', '<%= @map[:google_analytics_id] %>', 'auto');
9
+ ga('send', 'pageview');
10
+ </script>
11
+ <% end %>
data/views/_map_js.erb CHANGED
@@ -20,6 +20,11 @@
20
20
  map.addMarkers(markers_data);
21
21
  }
22
22
 
23
+ function setMapCoordinates(lat, lng, zoom) {
24
+ map.setCenter(lat, lng);
25
+ map.setZoom(zoom);
26
+ }
27
+
23
28
  $(document).ready(function(){
24
29
  infoWindow = new google.maps.InfoWindow({});
25
30
  map = new GMaps({
data/views/about.erb ADDED
@@ -0,0 +1,7 @@
1
+ <div class="jumbotron">
2
+ <h1>Travlrmap</h1>
3
+ <p>This site is creating using Travlrmap version <%= Travlrmap::VERSION %>. It's a simple tool designed to be self-hosted or on a PaaS like Heroku. All the configuration and points are maintained in static YAML files.</p>
4
+ <p>It's a standalone system, has no social features and is more aimed a city level tracker for places you have been rather than a coffee shop level check-in system, though a mobile app is planned to assist in logging visits while on the move.</p>
5
+ <p>It's written by <a href="https://www.devco.net/">R.I.Pienaar</a>, released under the terms of the Apache 2 licence and can be found at <a href="http://github.com/ripienaar/travlrmap">GitHub</a>.
6
+ <p><a class="btn btn-primary btn-lg" href="https://ripienaar.github.io/travlrmap/" role="button">Learn more</a></p>
7
+ </div>
data/views/geolocate.erb CHANGED
@@ -118,7 +118,9 @@
118
118
  $(document).ready(function() {
119
119
  $('#point_date').datepicker({
120
120
  format: 'yyyy-mm-dd',
121
- todayHighlight: true
121
+ todayHighlight: false,
122
+ autoclose: true,
123
+ clearBtn: true,
122
124
  });
123
125
 
124
126
  map = new GMaps({
data/views/layout.erb CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8">
5
5
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1">
7
- <meta name="description" content="Travlrmap version <%= Travlmap::VERSION %>">
7
+ <meta name="description" content="Travlrmap version <%= Travlrmap::VERSION %>">
8
8
  <meta name="author" content="R.I.Pienaar <rip@devco.net>">
9
9
  <link rel="icon" href="/favicon.ico">
10
10
 
@@ -24,6 +24,7 @@
24
24
  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
25
25
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
26
26
  <![endif]-->
27
+ <%= erb :"_google_analytics", :layout => false, :locals => {:map => @map} %>
27
28
  </head>
28
29
 
29
30
  <body>
@@ -45,16 +46,21 @@
45
46
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Views <span class="caret"></span></a>
46
47
  <ul class="dropdown-menu" role="menu">
47
48
  <% @config[:views].sort_by{|k, v| v[:description]}.each do |k, v| %>
48
- <li><a href="/view/<%= k %>"><%= v[:description] %></a></li>
49
+ <% if @js_map_update %>
50
+ <li><a onclick="javascript:setMapCoordinates(<%= v[:lat] %>, <%= v[:lon] %>, <%= v[:zoom] %>); window.history.replaceState('x', 'Title', '/view/<%= k %>');"><%= v[:description] %></a></li>
51
+ <% else %>
52
+ <li><a href="/view/<%= k %>"><%= v[:description] %></a></li>
53
+ <% end %>
49
54
  <% end %>
50
55
  </ul>
51
56
  </li>
52
57
  </ul>
53
- <% if @map[:show_geocode_link] %>
54
58
  <ul class="nav navbar-nav navbar-right">
59
+ <% if @map[:show_geocode_link] %>
55
60
  <li><a href="/geocode">Geocode</a></li>
56
- </ul>
57
61
  <% end %>
62
+ <li><a href="/about">About</a></li>
63
+ </ul>
58
64
  </div>
59
65
  </div>
60
66
  </nav>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travlrmap
3
3
  version: !ruby/object:Gem::Version
4
- hash: 61
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 17
10
- version: 0.0.17
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - R.I.Pienaar
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2015-01-07 00:00:00 +00:00
18
+ date: 2015-01-09 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -151,6 +151,8 @@ files:
151
151
  - views/layout.erb
152
152
  - views/index.erb
153
153
  - views/_point_comment.erb
154
+ - views/_google_analytics.erb
155
+ - views/about.erb
154
156
  - views/_map_js.erb
155
157
  - views/geolocate.erb
156
158
  - public/travlrmap.css