Commit 51f1e253 authored by Cool Fire's avatar Cool Fire

Warpped the whole thing in a try-catch as an extra failsafe

parent 105689f1
...@@ -41,59 +41,65 @@ end ...@@ -41,59 +41,65 @@ end
# Main server loop # Main server loop
loop do loop do
# New client connected begin
client = server.accept # New client connected
client = server.accept
# Read request from socket
input = client.gets # Read request from socket
input.strip! input = client.gets
input.strip!
sane = true
p1 = 0 puts "Request: #{input}"
p2 = 0
sane = true
# Check if it's something that looks like an ident response p1 = 0
if( input =~ /^(\d+)(|\s),(|\s)(\d+)$/ ) p2 = 0
p1 = $1.to_i
p2 = $3.to_i # Check if it's something that looks like an ident response
else if( input =~ /^(\d+)(|\s),(|\s)(\d+)$/ )
sane = false p1 = $1.to_i
end p2 = $4.to_i
else
# Sanity check on port number sane = false
if( p1 < 1 || p1 > 65535 || p2 < 1 || p2 > 65535 ) end
sane = false
end # Sanity check on port number
if( p1 < 1 || p1 > 65535 || p2 < 1 || p2 > 65535 )
# Send generic error for stuff that does not look like ident requests sane = false
if(!sane) end
client.puts "#{input}:ERROR:NO-USER"
client.close # Send generic error for stuff that does not look like ident requests
next if(!sane)
end client.puts "#{input}:ERROR:NO-USER"
client.close
# Do NAT table lookup next
n = natlookup( p1, p2 ) end
# Do NAT table lookup
n = natlookup( p1, p2 )
# Check if there was a NAT table entry # Check if there was a NAT table entry
if( n.nil? ) if( n.nil? )
client.puts "#{input}:ERROR:NO-USER" client.puts "#{input}:ERROR:NO-USER"
client.close
next
end
# Forward request to NAT'ed server
result = forwardrequest( n[0], n[1], n[2] )
# Show result to client
if( result.nil? )
client.puts "#{input}:ERROR:NO-USER"
client.close
next
end
puts "Response: #{result}"
client.puts result
# Close connection and wait for the next request
client.close client.close
next rescue Exception => e
end
# Forward request to NAT'ed server
result = forwardrequest( n[0], n[1], n[2] )
# Show result to client
if( result.nil? )
client.puts "#{input}:ERROR:NO-USER"
client.close
next
end end
client.puts result
# Close connection and wait for the next request
client.close
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment