2020-06-03 04:14:39 +00:00
|
|
|
class ArsesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
respond_to :json
|
|
|
|
|
|
2026-02-16 04:04:17 +00:00
|
|
|
def index
|
|
|
|
|
if params[:code] != Rails.application.config.data_dump_code
|
|
|
|
|
render :json => {error: "Unauthorized"}, :status => 401
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@arses = Ars.all
|
|
|
|
|
render :json => @arses
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
if params[:code] != Rails.application.config.data_dump_code
|
|
|
|
|
render :json => {error: "Unauthorized"}, :status => 401
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@ars = Ars.find_by_id(params[:id])
|
|
|
|
|
if @ars.nil?
|
|
|
|
|
render :json => {error: "Not Found"}, :status => 404
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
allowed = [:password, :username, :active, :beta, :name, :provider, :id_int, :ip, :port, :continent, :country, :city, :subdivision, :latitude, :longitude]
|
|
|
|
|
|
|
|
|
|
update_hash = {}
|
|
|
|
|
allowed.each do |attr|
|
|
|
|
|
update_hash[attr] = params[attr] if params.has_key?(attr)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if @ars.update_attributes(update_hash, as: :admin)
|
|
|
|
|
render :json => @ars, :status => :ok
|
|
|
|
|
else
|
|
|
|
|
render :json => @ars.errors, :status => :unprocessable_entity
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-06-03 04:14:39 +00:00
|
|
|
# create or update a client_artifact row
|
|
|
|
|
def get_or_create
|
|
|
|
|
name = params[:name]
|
|
|
|
|
provider = params[:provider]
|
|
|
|
|
active = params[:active]
|
2020-06-05 22:56:17 +00:00
|
|
|
ip = params[:ip]
|
|
|
|
|
username = params[:username]
|
|
|
|
|
password = params[:password]
|
2020-10-18 18:57:32 +00:00
|
|
|
topology = params[:topology]
|
|
|
|
|
ars_id = params[:ars_id]
|
|
|
|
|
puts "TOPOLOGY #{topology}"
|
2020-06-03 04:14:39 +00:00
|
|
|
|
2020-10-18 18:57:32 +00:00
|
|
|
if ars_id
|
|
|
|
|
ars = Ars.find_by_id_int(ars_id)
|
|
|
|
|
end
|
2020-06-03 04:14:39 +00:00
|
|
|
if ars.nil?
|
|
|
|
|
ars = Ars.new
|
|
|
|
|
ars.name = name
|
2021-04-27 20:07:56 +00:00
|
|
|
ars.id_int = ars_id if !ars_id.nil?
|
2020-06-03 04:14:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
ars.provider = provider
|
|
|
|
|
ars.active = active
|
2020-06-05 22:56:17 +00:00
|
|
|
ars.ip = ip
|
|
|
|
|
ars.password = password
|
|
|
|
|
ars.username = username
|
2020-10-18 18:57:32 +00:00
|
|
|
if topology
|
|
|
|
|
ars.city = topology['city']
|
|
|
|
|
ars.country = topology['country']
|
|
|
|
|
ars.continent = topology['continent']
|
|
|
|
|
ars.latitude = topology['latitude']
|
|
|
|
|
ars.longitude = topology['longitude']
|
|
|
|
|
ars.subdivision = topology['subdivision']
|
|
|
|
|
end
|
2020-06-03 04:14:39 +00:00
|
|
|
ars.save
|
|
|
|
|
|
|
|
|
|
@ars = ars
|
|
|
|
|
unless @ars.errors.any?
|
2021-04-29 19:13:32 +00:00
|
|
|
if ars_id.nil?
|
|
|
|
|
ars.reload
|
|
|
|
|
ars_id = ars.id_int
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@ars = Ars.find_by_id_int(ars_id)
|
2020-06-05 22:56:17 +00:00
|
|
|
render :json => {id_int: @ars.id_int, id: @ars.id, name: @ars.name, provider: @ars.provider, active: @ars.active, ip: @ars.ip}, :status => :ok
|
2020-06-03 04:14:39 +00:00
|
|
|
else
|
|
|
|
|
response.status = :unprocessable_entity
|
|
|
|
|
respond_with @ars
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|