end
def authorize(realm='Web Password', errormessage="Couldn't authenticate you")
- username, passwd = get_auth_data # parse from headers
- # authenticate per-scheme
- if username.nil?
- @user = nil # no authentication provided - perhaps first connect (client should retry after 401)
- elsif username == 'token'
- @user = User.authenticate_token(passwd) # preferred - random token for user from db, passed in basic auth
- else
- @user = User.authenticate(username, passwd) # basic auth
+ unless request.get?
+ username, passwd = get_auth_data # parse from headers
+ # authenticate per-scheme
+ if username.nil?
+ @user = nil # no authentication provided - perhaps first connect (client should retry after 401)
+ elsif username == 'token'
+ @user = User.authenticate_token(passwd) # preferred - random token for user from db, passed in basic auth
+ else
+ @user = User.authenticate(username, passwd) # basic auth
+ end
+
+ # handle authenticate pass/fail
+ if @user
+ # user exists and password is correct ... horray!
+ if @user.methods.include? 'lastlogin' # note last login
+ @session['lastlogin'] = user.lastlogin
+ @user.last.login = Time.now
+ @user.save()
+ @session["User.id"] = @user.id
+ end
+ else
+ # no auth, the user does not exist or the password was wrong
+ response.headers["Status"] = "Unauthorized"
+ response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\""
+ render_text(errormessage, 401) # :unauthorized
+ end
end
-
- # handle authenticate pass/fail
- if @user
- # user exists and password is correct ... horray!
- if @user.methods.include? 'lastlogin' # note last login
- @session['lastlogin'] = user.lastlogin
- @user.last.login = Time.now
- @user.save()
- @session["User.id"] = @user.id
- end
- else
- # no auth, the user does not exist or the password was wrong
- response.headers["Status"] = "Unauthorized"
- response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\""
- render_text(errormessage, 401) # :unauthorized
- end
end
# Report and error to the user
begin
logger.info("GPX Import importing #{trace.name} (#{trace.id}) from #{trace.user.email}")
- \r
+
# TODO *nix specific, could do to work on windows... would be functionally inferior though - check for '.gz'
- gzipped = `file -b /home/osm/gpx/#{trace.id}.gpx`.chomp =~/^gzip/\r
+ filetype = `file -b /home/osm/gpx/#{trace.id}.gpx`.chomp
+ gzipped = filetype =~ /^gzip/
+ zipped = filetype =~ /^Zip/
if gzipped
logger.info("gzipped")
+ filename = "/tmp/#{rand}"
+ system("gunzip -c /home/osm/gpx/#{trace.id}.gpx > #{filename}")
+ elsif zipped
+ logger.info("zipped")
+ filename = "/tmp/#{rand}"
+ system("unzip -p /home/osm/gpx/#{trace.id}.gpx > #{filename}")
else
logger.info("not gzipped")
+ filename = "/home/osm/gpx/#{trace.id}.gpx"
end
- gpx = OSM::GPXImporter.new("/home/osm/gpx/#{trace.id}.gpx")
+ gpx = OSM::GPXImporter.new(filename)
f_lat = 0
f_lon = 0
trace.inserted = true
trace.save
+ if gzipped || zipped
+ FileUtils.rm_f(filename)
+ end
+
logger.info "done trace #{trace.id}"
Notifier::deliver_gpx_success(trace, gpx.possible_points)
else
- `rm /home/osm/gpx/#{trace.id}.gpx`
+ FileUtils.rm_f("/home/osm/gpx/#{trace.id}.gpx", filename)
trace.destroy
Notifier::deliver_gpx_failure(trace, '0 points parsed ok. Do they all have lat,lng,alt,timestamp?')
end
rescue Exception => ex
logger.info ex
ex.backtrace.each {|l| logger.info l }
- `rm /home/osm/gpx/#{trace.id}.gpx`
+ FileUtils.rm_f("/home/osm/gpx/#{trace.id}.gpx", filename)
trace.destroy
Notifier::deliver_gpx_failure(trace, ex.to_s + ex.backtrace.join("\n") )
end
end
Trace.find(:all, :conditions => ['inserted = ?', false]).each do |trace|
- `rm /home/osm/gpx/#{trace.id}.gpx`
+ FileUtils.rm_f("/home/osm/gpx/#{trace.id}.gpx")
trace.destroy
end
exit