mirror of
https://github.com/YunoHost/dynette.git
synced 2024-09-03 20:06:17 +02:00
Init
This commit is contained in:
commit
b9a98a54ab
5 changed files with 155 additions and 0 deletions
BIN
.dynette.rb.swp
Normal file
BIN
.dynette.rb.swp
Normal file
Binary file not shown.
8
Gemfile
Normal file
8
Gemfile
Normal file
|
@ -0,0 +1,8 @@
|
|||
source :rubygems
|
||||
|
||||
gem 'sinatra'
|
||||
gem 'thin'
|
||||
gem 'json'
|
||||
gem 'data_mapper'
|
||||
gem 'dm-postgres-adapter'
|
||||
gem 'pg'
|
83
Gemfile.lock
Normal file
83
Gemfile.lock
Normal file
|
@ -0,0 +1,83 @@
|
|||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
addressable (2.3.4)
|
||||
bcrypt-ruby (3.0.1)
|
||||
daemons (1.1.9)
|
||||
data_mapper (1.2.0)
|
||||
dm-aggregates (~> 1.2.0)
|
||||
dm-constraints (~> 1.2.0)
|
||||
dm-core (~> 1.2.0)
|
||||
dm-migrations (~> 1.2.0)
|
||||
dm-serializer (~> 1.2.0)
|
||||
dm-timestamps (~> 1.2.0)
|
||||
dm-transactions (~> 1.2.0)
|
||||
dm-types (~> 1.2.0)
|
||||
dm-validations (~> 1.2.0)
|
||||
data_objects (0.10.13)
|
||||
addressable (~> 2.1)
|
||||
dm-aggregates (1.2.0)
|
||||
dm-core (~> 1.2.0)
|
||||
dm-constraints (1.2.0)
|
||||
dm-core (~> 1.2.0)
|
||||
dm-core (1.2.1)
|
||||
addressable (~> 2.3)
|
||||
dm-do-adapter (1.2.0)
|
||||
data_objects (~> 0.10.6)
|
||||
dm-core (~> 1.2.0)
|
||||
dm-migrations (1.2.0)
|
||||
dm-core (~> 1.2.0)
|
||||
dm-mysql-adapter (1.2.0)
|
||||
dm-do-adapter (~> 1.2.0)
|
||||
do_mysql (~> 0.10.6)
|
||||
dm-serializer (1.2.2)
|
||||
dm-core (~> 1.2.0)
|
||||
fastercsv (~> 1.5)
|
||||
json (~> 1.6)
|
||||
json_pure (~> 1.6)
|
||||
multi_json (~> 1.0)
|
||||
dm-timestamps (1.2.0)
|
||||
dm-core (~> 1.2.0)
|
||||
dm-transactions (1.2.0)
|
||||
dm-core (~> 1.2.0)
|
||||
dm-types (1.2.2)
|
||||
bcrypt-ruby (~> 3.0)
|
||||
dm-core (~> 1.2.0)
|
||||
fastercsv (~> 1.5)
|
||||
json (~> 1.6)
|
||||
multi_json (~> 1.0)
|
||||
stringex (~> 1.4)
|
||||
uuidtools (~> 2.1)
|
||||
dm-validations (1.2.0)
|
||||
dm-core (~> 1.2.0)
|
||||
do_mysql (0.10.13)
|
||||
data_objects (= 0.10.13)
|
||||
eventmachine (1.0.3)
|
||||
fastercsv (1.5.5)
|
||||
json (1.8.0)
|
||||
json_pure (1.8.0)
|
||||
multi_json (1.7.7)
|
||||
rack (1.5.2)
|
||||
rack-protection (1.5.0)
|
||||
rack
|
||||
sinatra (1.4.3)
|
||||
rack (~> 1.4)
|
||||
rack-protection (~> 1.4)
|
||||
tilt (~> 1.3, >= 1.3.4)
|
||||
stringex (1.5.1)
|
||||
thin (1.5.1)
|
||||
daemons (>= 1.0.9)
|
||||
eventmachine (>= 0.12.6)
|
||||
rack (>= 1.0.0)
|
||||
tilt (1.4.1)
|
||||
uuidtools (2.1.4)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
data_mapper
|
||||
dm-mysql-adapter
|
||||
json
|
||||
sinatra
|
||||
thin
|
1
Procfile
Normal file
1
Procfile
Normal file
|
@ -0,0 +1 @@
|
|||
web: bundle exec ruby dynette.rb -p $PORT
|
63
dynette.rb
Executable file
63
dynette.rb
Executable file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require 'rubygems'
|
||||
require 'sinatra'
|
||||
require 'data_mapper'
|
||||
require 'json'
|
||||
|
||||
DataMapper.setup(:default, ENV['DATABASE_URL'] || "pgsql://root:yayaya@localhost/dynette")
|
||||
DOMAIN = "yoyoyo.fr"
|
||||
|
||||
class Entry
|
||||
include DataMapper::Resource
|
||||
|
||||
property :id, Serial
|
||||
property :public_key, String
|
||||
property :subdomain, String
|
||||
property :current_ip, String
|
||||
|
||||
has n, :ips
|
||||
end
|
||||
|
||||
class Ip
|
||||
include DataMapper::Resource
|
||||
|
||||
property :id, Serial
|
||||
property :ip_addr, String
|
||||
|
||||
belongs_to :entry
|
||||
end
|
||||
|
||||
#get '/' do
|
||||
#`whoami`
|
||||
#end
|
||||
|
||||
post '/' do
|
||||
content_type :json
|
||||
# TODO: check params
|
||||
if entry = Entry.first(:public_key => params[:public_key])
|
||||
status 409
|
||||
return { :error => "Key already exists for domain #{entry.subdomain}.#{DOMAIN}" }
|
||||
end
|
||||
entry = Entry.new(:public_key => params[:public_key], :subdomain => params[:subdomain], :current_ip => request.ip)
|
||||
if entry.save
|
||||
status 201
|
||||
return { :public_key => params[:public_key], :subdomain => params[:subdomain], :current_ip => request.ip }.to_json
|
||||
else
|
||||
status 412
|
||||
return { :error => "A problem occured during DNS registration" }
|
||||
end
|
||||
end
|
||||
|
||||
get '/all' do
|
||||
unless request.ip == "82.242.206.127"
|
||||
status 403
|
||||
return "Access denied"
|
||||
end
|
||||
content_type :json
|
||||
Entry.all.to_json
|
||||
end
|
||||
|
||||
|
||||
|
||||
DataMapper.auto_upgrade!
|
Loading…
Reference in a new issue