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

Version Path
adminix-0.1.49 lib/adminix/server_setup.rb
adminix-0.1.48 lib/adminix/server_setup.rb
adminix-0.1.47 lib/adminix/server_setup.rb
adminix-0.1.46 lib/adminix/server_setup.rb
adminix-0.1.45 lib/adminix/server_setup.rb
adminix-0.1.44 lib/adminix/server_setup.rb
adminix-0.1.43 lib/adminix/server_setup.rb
adminix-0.1.41 lib/adminix/server_setup.rb
adminix-0.1.40 lib/adminix/server_setup.rb
adminix-0.1.39 lib/adminix/server_setup.rb
adminix-0.1.38 lib/adminix/server_setup.rb
adminix-0.1.37 lib/adminix/server_setup.rb