base64 dns key

This commit is contained in:
Kload 2013-07-07 10:38:58 +00:00
parent 340ecea987
commit 1cf19fd581

View file

@ -109,6 +109,7 @@ end
post '/key/:public_key' do post '/key/:public_key' do
params[:public_key] = Base64.decode64(params[:public_key])
# Check params # Check params
halt 400, { :error => "Please indicate a subdomain" }.to_json unless params.has_key?("subdomain") halt 400, { :error => "Please indicate a subdomain" }.to_json unless params.has_key?("subdomain")
@ -131,6 +132,7 @@ post '/key/:public_key' do
end end
put '/key/:public_key' do put '/key/:public_key' do
params[:public_key] = Base64.decode64(params[:public_key])
entry = Entry.first(:public_key => params[:public_key]) entry = Entry.first(:public_key => params[:public_key])
unless request.ip == entry.current_ip unless request.ip == entry.current_ip
entry.ips << Ip.create(:ip_addr => request.ip) entry.ips << Ip.create(:ip_addr => request.ip)
@ -144,6 +146,7 @@ put '/key/:public_key' do
end end
delete '/key/:public_key' do delete '/key/:public_key' do
params[:public_key] = Base64.decode64(params[:public_key])
if entry = Entry.first(:public_key => params[:public_key]) if entry = Entry.first(:public_key => params[:public_key])
if entry.destroy if entry.destroy
halt 200, "OK".to_json halt 200, "OK".to_json
@ -174,6 +177,7 @@ get '/all/:domain' do
end end
get '/ips/:public_key' do get '/ips/:public_key' do
params[:public_key] = Base64.decode64(params[:public_key])
unless ALLOWED_IP.include? request.ip unless ALLOWED_IP.include? request.ip
status 403 status 403
return "Access denied" return "Access denied"