source: subversion/utils/ns1togpx/web_wrapper.rbx @ 2026

Last change on this file since 2026 was 1455, checked in by ben, 14 years ago

more debugging tweaks

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#!/usr/bin/env ruby
2
3=begin Copyright (C) 2006 Ben Gimpert (ben@somethingmodern.com)
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18MA  02111-1307, USA.
19
20=end
21
22require 'cgi'
23require 'cgi/session'
24require 'stringio'
25
26require 'ns1togpx'
27
28THIS_URL = "http://ns1togpx.somethingmodern.com/"
29THIS_DIR = File.expand_path(File.dirname(__FILE__))
30
31$cgi = CGI.new("html3")
32
33style = <<'EOF'
34<style>
35a { text-decoration: none; }
36a:hover { color: blue; }
37</style>
38EOF
39
40params = {}
41$cgi.params.each do |param|
42        key = param.first
43        value = $cgi[key]
44        if value.respond_to?(:read)
45                params[key] = $cgi[key].read
46        else
47                params[key] = value.to_s.strip
48        end
49        params[key].untaint
50end
51
52errors = ''
53gpx = nil
54if (! params["ns1_file"].nil?) && (! params["ns1_file"].empty?)
55        begin
56                rd = StringIO.new(params["ns1_file"])
57                wr = StringIO.new
58                Ns1togpx::Converter.new.convert(rd, wr)
59                gpx = wr.string
60        rescue =>ex
61                errors =
62                        "<p><font face=\"Courier New,Courier,Monospace\" color=\"red\">" +
63                        "ERROR(" + CGI::escapeHTML(ex.message) + ")" + $cgi.br +
64                        ex.backtrace.map { |line| ("&nbsp;" * 4) + CGI::escapeHTML(line) }.join($cgi.br) +
65                        "</font></p>"
66        end
67end
68
69if gpx.nil?
70        $cgi.out { $cgi.html {
71                $cgi.head { $cgi.title { "ns1togpx" } + style } +
72                $cgi.body("bgcolor" => "#A0A0C0", "link" => "white", "vlink" => "white") { $cgi.multipart_form(THIS_URL) {
73                        "<font face='Arial,Helvetica,Verdana,Sans-serif'>" +
74                        $cgi.h2 { $cgi.a(THIS_URL) { "ns1togpx" } } +
75                        $cgi.h5 { <<EOF
76Online conversion of a NetStumbler (.NS1) log file into the GPS Exchange Format
77(.GPX) for use in mapping software.  This converter effectively strips the
78wireless access point information from the NetStumbler file, leaving just a
79track of GPS &ldquo;breadcrumbs&rdquo; for community mapping projects like
80<a href="http://www.openstreetmap.org/">OpenStreetMap</a>.
81EOF
82                        } +
83                        $cgi.hr +
84                        errors +
85                        $cgi.p {
86                                $cgi.file_field("ns1_file", 80) + $cgi.br + $cgi.br +
87                                $cgi.submit("Upload & Convert Your .NS1 File")
88                        } +
89                        $cgi.p("align" => "right") {
90                                "<font size='-2'>" +
91                                $cgi.a("http://svn.openstreetmap.org/utils/ns1togpx/") { "GPL'ed source code" } +
92                                " by " +
93                                $cgi.a("mailto:ben@somethingmodern.com") { "Ben Gimpert" } +
94                                ", 2006" +
95                                "</font>"
96                        } +
97                        "</font>"
98                } }
99        } }
100else
101        $cgi.out("type" => "text/xml") { gpx }
102end
103
Note: See TracBrowser for help on using the repository browser.