OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • Archive »
  • 19.1 Legacy Series »
  • [solved]API via Ruby
« previous next »
  • Print
Pages: [1]

Author Topic: [solved]API via Ruby  (Read 3202 times)

BrianW

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
    • View Profile
[solved]API via Ruby
« on: February 06, 2019, 06:29:07 pm »
I am running OPNsense 19.1.1 and attempting to access the API via Ruby

This code snippet:

Code: [Select]
require 'net/http'
require 'openssl'
require 'json'

uri = URI('https://10.15.1.227/api/captiveportal/service/searchtemplates')

request = Net::HTTP::Get.new(uri)

request.basic_auth '123', 'abc'

result = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.request(request)
end

puts result.body

produces the error:

Code: [Select]
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
I have confirmed that the key and secret are correct.

Am I doing it right?

Thanks
« Last Edit: February 07, 2019, 04:35:50 pm by BrianW »
Logged

abraxxa

  • Jr. Member
  • **
  • Posts: 67
  • Karma: 7
    • View Profile
Re: API via Ruby
« Reply #1 on: February 06, 2019, 09:53:57 pm »
verify_mode NONE doesn‘t seem to do what you expect.
Logged

BrianW

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
    • View Profile
Re: API via Ruby
« Reply #2 on: February 06, 2019, 10:08:06 pm »
I've tried with and without http.verify_mode = OpenSSL::SSL::VERIFY_NONE with the same result.

Thanks
Logged

fabian

  • Hero Member
  • *****
  • Posts: 2769
  • Karma: 200
  • OPNsense Contributor (Language, VPN, Proxy, etc.)
    • View Profile
    • Personal Homepage
Re: API via Ruby
« Reply #3 on: February 06, 2019, 11:14:15 pm »
This one is for working with legacy pages but I am sure you can adjust it for API as it is simplier:
https://github.com/fabianfrz/scripts/blob/master/OPNsense/backup_over_http.rb#L13-L40
Logged

BrianW

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
    • View Profile
Re: API via Ruby
« Reply #4 on: February 07, 2019, 04:35:18 pm »
Awesome! That did it. Here's the code that works for any interested...

Code: [Select]
require 'net/http'
require 'openssl'
require 'json'

uri = URI('https://10.15.1.227/api/captiveportal/service/searchtemplates')

request = Net::HTTP::Get.new(uri)

request.basic_auth '123', 'abc'

result = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
http.request(request)
end

puts result.body
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • Archive »
  • 19.1 Legacy Series »
  • [solved]API via Ruby
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2024 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2