mirror of
https://github.com/YunoHost/dynette.git
synced 2024-09-03 20:06:17 +02:00
Add test route and python cron
This commit is contained in:
parent
0bd0c3f5b0
commit
6252ec6791
2 changed files with 70 additions and 0 deletions
50
dynette.cron.py
Executable file
50
dynette.cron.py
Executable file
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
from urllib import urlopen
|
||||
|
||||
domain = 'yoyoyo.fr'
|
||||
|
||||
result = str(urlopen('http://dynette-dev.herokuapp.com/all').read())
|
||||
result = json.loads(result)
|
||||
|
||||
lines = [
|
||||
'zone "'+ domain +'" {',
|
||||
' type master;',
|
||||
' file "/var/named/data/yoyoyo.fr.db"; ',
|
||||
' update-policy {',
|
||||
]
|
||||
|
||||
for entry in result:
|
||||
fqdn = entry['subdomain'] +'.'+ domain +'.'
|
||||
lines.extend([
|
||||
' grant '+ fqdn +' name '+ fqdn +' A TXT;',
|
||||
' grant '+ fqdn +' name pubsub.'+ fqdn +' A;',
|
||||
' grant '+ fqdn +' name muc.'+ fqdn +' A;',
|
||||
' grant '+ fqdn +' name vjud.'+ fqdn +' A;',
|
||||
' grant '+ fqdn +' name _xmpp-client._tcp.'+ fqdn +' SRV;',
|
||||
' grant '+ fqdn +' name _xmpp-server._tcp.'+ fqdn +' SRV;',
|
||||
])
|
||||
|
||||
lines.extend([
|
||||
' };',
|
||||
'};',
|
||||
])
|
||||
|
||||
for entry in result:
|
||||
fqdn = entry['subdomain'] +'.'+ domain +'.'
|
||||
lines.extend([
|
||||
'key '+ fqdn +' {',
|
||||
' algorithm hmac-md5;',
|
||||
' secret "'+ entry['public_key'] +'";',
|
||||
'};',
|
||||
])
|
||||
|
||||
|
||||
with open('/etc/bind/named.conf.local', 'w') as zone:
|
||||
for line in lines:
|
||||
zone.write(line + '\n')
|
||||
|
||||
os.system('rndc reload')
|
20
dynette.rb
20
dynette.rb
|
@ -8,6 +8,7 @@ require 'json'
|
|||
DataMapper.setup(:default, ENV['DATABASE_URL'] || "postgres://postgres:yayaya@localhost/dynette")
|
||||
DOMAIN = "yoyoyo.fr"
|
||||
ALLOWED_IP = "82.196.13.142"
|
||||
#ALLOWED_IP = "127.0.0.1"
|
||||
|
||||
class Entry
|
||||
include DataMapper::Resource
|
||||
|
@ -46,6 +47,7 @@ before do
|
|||
if Ipban.first(:ip_addr => request.ip)
|
||||
halt 410, "Your ip is banned from the service"
|
||||
end
|
||||
pass if %w[test all ban unban].include? request.path_info.split('/')[1]
|
||||
if iplog = Iplog.last(:ip_addr => request.ip)
|
||||
if iplog.visited_at.to_time > Time.now - 30
|
||||
halt 410, "Please wait 30sec\n"
|
||||
|
@ -61,6 +63,22 @@ get '/' do
|
|||
"Wanna play the dynette ?"
|
||||
end
|
||||
|
||||
get '/test/:subdomain' do
|
||||
content_type :json
|
||||
unless params[:subdomain].match /^[a-z0-9-]{3,16}$/
|
||||
status 400
|
||||
return { :error => "Subdomain is invalid: #{params[:subdomain]}.#{DOMAIN}" }.to_json
|
||||
end
|
||||
if entry = Entry.first(:subdomain => params[:subdomain])
|
||||
status 409
|
||||
return { :error => "Subdomain already taken: #{entry.subdomain}.#{DOMAIN}" }.to_json
|
||||
else
|
||||
status 200
|
||||
return "Domain #{params[:subdomain]}.#{DOMAIN} is available".to_json
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
post '/:public_key' do
|
||||
content_type :json
|
||||
# Check params
|
||||
|
@ -156,6 +174,7 @@ get '/ban/:ip_to_ban' do
|
|||
status 403
|
||||
return "Access denied"
|
||||
end
|
||||
content_type :json
|
||||
unless params[:ip_to_ban].match /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
||||
status 400
|
||||
return { :error => "IP is invalid: #{params[:ip_to_ban]}" }.to_json
|
||||
|
@ -170,6 +189,7 @@ get '/unban/:ip_to_ub' do
|
|||
status 403
|
||||
return "Access denied"
|
||||
end
|
||||
content_type :json
|
||||
unless params[:ip_to_ub].match /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
||||
status 400
|
||||
return { :error => "IP is invalid: #{params[:ip_to_ub]}" }.to_json
|
||||
|
|
Loading…
Add table
Reference in a new issue