From 359656bdd609b1d7d60b205b50d6872105dc174d Mon Sep 17 00:00:00 2001 From: spengreb Date: Tue, 8 Oct 2019 21:57:37 +0200 Subject: [PATCH] Change how ruby executes commands --- app/controllers/vouchers_controller.rb | 6 +++--- log/development.log | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/vouchers_controller.rb b/app/controllers/vouchers_controller.rb index a810685..76297ee 100644 --- a/app/controllers/vouchers_controller.rb +++ b/app/controllers/vouchers_controller.rb @@ -5,7 +5,7 @@ class VouchersController < ApplicationController # GET /vouchers def index @vouchers = Voucher.all - whitelist = `mcrcon -c -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} 'whitelist list' | sed 's/There are*.*whitelisted players: //g'`.gsub("\n", "").split(", ") + whitelist = %x(mcrcon -c -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} 'whitelist list' | sed 's/There are*.*whitelisted players: //g').gsub("\n", "").split(", ") render json: { :vouchers => @vouchers, :whitelist => whitelist }.to_json end @@ -19,13 +19,13 @@ class VouchersController < ApplicationController def create # Logic for creating a voucher output = "" - whitelist = `mcrcon -c -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} "whitelist list" | sed 's/There are*.*whitelisted players: //g'`.gsub("\n", "").split(", ") + whitelist = %x(mcrcon -c -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} "whitelist list" | sed 's/There are*.*whitelisted players: //g').gsub("\n", "").split(", ") if Voucher.exists?(vouchee: params[:voucher]) && params[:voucher].in?(whitelist) @voucher = Voucher.new(voucher_params) if @voucher.save - output = `mcrcon -c -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} "whitelist add #{params[:vouchee]}"` + output = %x(mcrcon -c -H mine.vereto.net -p #{ENV["MC_RCON_PASS"]} "whitelist add #{params[:vouchee]}") render json: { :message => output }.to_json, status: :created, location: @voucher else render json: @voucher.errors, status: :unprocessable_entity diff --git a/log/development.log b/log/development.log index e4dbcab..f74e93d 100644 --- a/log/development.log +++ b/log/development.log @@ -2329,3 +2329,12 @@ Processing by VouchersController#index as */* Completed 200 OK in 102ms (Views: 0.1ms | ActiveRecord: 1.1ms | Allocations: 5483) +Started GET "/vouchers" for ::1 at 2019-10-08 21:57:13 +0200 +  (0.2ms) SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483 +  (0.2ms) SELECT `schema_migrations`.`version` FROM `schema_migrations` ORDER BY `schema_migrations`.`version` ASC +Processing by VouchersController#index as */* + Voucher Load (0.3ms) SELECT `vouchers`.* FROM `vouchers` + ↳ app/controllers/vouchers_controller.rb:10:in `index' +Completed 200 OK in 111ms (Views: 0.1ms | ActiveRecord: 1.1ms | Allocations: 6058) + +