Sha256: 2f46430c3421450ac8eb45cbe250fc61f7e5c4106da316b81cfcf6457bb0946d
Contents?: true
Size: 1.75 KB
Versions: 12
Compression:
Stored size: 1.75 KB
Contents
require 'sinatra/base' require 'json' require 'securerandom' require 'base64' require 'openssl' # require 'digest' module Adminix class ServerSetup < Sinatra::Base get '/' do %{ <html> <head> <title>Adminix start</title> </head> <body> <script type="text/javascript"> var host = window.location.protocol + '//' + window.location.host; var newPath = "https://beta.adminix.io/setup-server/init?host=" + host; window.location.href = newPath; </script> </body> </html> } end get '/ping' do 'pong' end post '/data' do config = Adminix::Config.instance config.password = SecureRandom.hex content_type :json { password: config.password, image: config.image_sname }.to_json end post '/connect' do content_type :json data = {} config = Adminix::Config.instance begin decoded = Base64.decode64 request.body.read.encode('ascii-8bit') decipher = OpenSSL::Cipher::AES256.new :CBC decipher.decrypt decipher.key = config.password decipher.iv = config.iv decrypted_data = decipher.update(decoded) + decipher.final data = JSON.parse(decrypted_data)['server_setup'] rescue { success: false }.to_json end config.password = '' config.service_id = data['service_id'] config.secret_key = data['secret_key'] config.export_credentials Thread.start do sleep(2) Adminix::Service.instance.restart! end { success: true }.to_json end set :bind, '0.0.0.0' set :port, Adminix::Config::DEFAULT_SETUP_SERVER_PORT run! end end
Version data entries
12 entries across 12 versions & 1 rubygems