init
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
class ApplicationController < Sinatra::Base
|
||||
register Sinatra::ActiveRecordExtension
|
||||
register Sinatra::Contrib
|
||||
|
||||
configure do
|
||||
set :views, File.expand_path('../../views', __FILE__)
|
||||
set :public_folder, File.expand_path('../../../public', __FILE__)
|
||||
set :root, File.expand_path('../../..', __FILE__)
|
||||
set :trust_proxy, true
|
||||
set :bind, '0.0.0.0'
|
||||
set :port, 4567
|
||||
end
|
||||
|
||||
get '/' do
|
||||
client_ip = request.ip.to_s
|
||||
puts client_ip
|
||||
|
||||
if client_ip.start_with?('100.')
|
||||
@url_type = 'tailscale'
|
||||
elsif params[:local_ip].present? && params[:local_ip] == 'true'
|
||||
@url_type = 'local_ip'
|
||||
else
|
||||
@url_type = 'local_domain'
|
||||
end
|
||||
@media = ServiceType.media
|
||||
@media.services.map { |serv| serv.set_current_url(@url_type) }
|
||||
@support = ServiceType.support
|
||||
@support.services.map { |serv| serv.set_current_url(@url_type) }
|
||||
@admin = ServiceType.admin
|
||||
@admin.services.map { |serv| serv.set_current_url(@url_type) }
|
||||
erb :'index'
|
||||
end
|
||||
|
||||
get '/admin' do
|
||||
erb :'admin/index'
|
||||
end
|
||||
|
||||
get '/admin/local_network' do
|
||||
@local_network = LocalNetwork.first || LocalNetwork.new
|
||||
@is_readonly = true
|
||||
erb :'admin/local_network/index'
|
||||
end
|
||||
|
||||
get '/admin/local_network/edit' do
|
||||
@local_network = LocalNetwork.first || LocalNetwork.create
|
||||
@is_readonly = false
|
||||
erb :'admin/local_network/index'
|
||||
end
|
||||
|
||||
post '/admin/local_network' do
|
||||
@local_network = LocalNetwork.find(params[:local_network][:id])
|
||||
if @local_network.update(params[:local_network])
|
||||
redirect 'admin/local_network'
|
||||
else
|
||||
erb :'admin/local_network/index'
|
||||
end
|
||||
end
|
||||
|
||||
get '/admin/machines' do
|
||||
@machines = Machine.all
|
||||
@is_readonly = true
|
||||
erb :'admin/machines/index'
|
||||
end
|
||||
|
||||
get '/admin/machines/edit' do
|
||||
@machines = Machine.all
|
||||
@is_readonly = false
|
||||
erb :'admin/machines/index'
|
||||
end
|
||||
|
||||
post '/admin/machines' do
|
||||
params[:machines].each do |machine_data|
|
||||
machine_data["local_network_id"] = 1
|
||||
if machine_data[:id].empty? && machine_data[:name].present?
|
||||
Machine.create(machine_data)
|
||||
elsif machine_data[:id].present?
|
||||
@machine = Machine.find(machine_data[:id])
|
||||
@machine.update(machine_data)
|
||||
end
|
||||
end
|
||||
redirect 'admin/machines'
|
||||
end
|
||||
|
||||
get '/admin/service_types' do
|
||||
@service_types = ServiceType.all
|
||||
@is_readonly = true
|
||||
erb :'admin/service_types/index'
|
||||
end
|
||||
|
||||
get '/admin/service_types/edit' do
|
||||
@service_types = ServiceType.all
|
||||
@is_readonly = false
|
||||
erb :'admin/service_types/index'
|
||||
end
|
||||
|
||||
get '/admin/service_types/media' do
|
||||
@service_type = ServiceType.media
|
||||
erb :'admin/service_types/position'
|
||||
end
|
||||
|
||||
get '/admin/service_types/admin' do
|
||||
@service_type = ServiceType.admin
|
||||
erb :'admin/service_types/position'
|
||||
end
|
||||
|
||||
get '/admin/service_types/support' do
|
||||
@service_type = ServiceType.support
|
||||
erb :'admin/service_types/position'
|
||||
end
|
||||
|
||||
post '/admin/service_types' do
|
||||
puts params
|
||||
params[:service_types].each do |service_type_data|
|
||||
if service_type_data[:id].empty? && service_type_data[:name].present?
|
||||
ServiceType.create(service_type_data)
|
||||
elsif service_type_data[:id].present?
|
||||
@service_type = ServiceType.find(service_type_data[:id])
|
||||
@service_type.update(service_type_data)
|
||||
end
|
||||
end
|
||||
redirect 'admin/service_types'
|
||||
end
|
||||
|
||||
get '/admin/services' do
|
||||
@services = Service.all
|
||||
@service_types = ServiceType.all
|
||||
@machines = Machine.all
|
||||
@is_readonly = true
|
||||
erb :'admin/services/index'
|
||||
end
|
||||
|
||||
get '/admin/services/edit' do
|
||||
@services = Service.all
|
||||
@service_types = ServiceType.all
|
||||
@machines = Machine.all
|
||||
@is_readonly = false
|
||||
erb :'admin/services/index'
|
||||
end
|
||||
|
||||
post '/admin/services' do
|
||||
params[:services].each do |service_data|
|
||||
if service_data[:id].empty? && service_data[:name].present?
|
||||
Service.create(service_data)
|
||||
elsif service_data[:id].present?
|
||||
@service = Service.find(service_data[:id])
|
||||
@service.update(service_data)
|
||||
end
|
||||
end
|
||||
redirect 'admin/services'
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user