pwnix-api-client 1.3 → 1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
1
  ---
2
2
  BUNDLE_PATH: .bundle
3
+ BUNDLE_WITHOUT: development
3
4
  BUNDLE_DISABLE_SHARED_GEMS: '1'
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
1
  source :rubygems
2
2
 
3
- group :development do
4
- gem 'pry'
5
- end
3
+ gem 'pry'
6
4
 
7
5
  gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pwnix-api-client (1.0)
4
+ pwnix-api-client (1.4)
5
5
  httparty
6
6
  json
7
7
 
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+
3
+ # Get current directory
4
+ DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5
+
6
+ # Execute console
7
+ bundle exec ruby $DIR/../util/console.rb
@@ -1,46 +1,137 @@
1
1
  require 'httparty'
2
+ require 'json'
3
+ require 'singleton'
4
+
5
+ require_relative 'config/config_file'
2
6
 
3
7
  module Pwnix
4
8
  module Api
5
9
  module Client
6
- if ENV['PWNIX_DEV']
7
- BASE_URI = "http://localhost:9292/v1"
8
- else
9
- BASE_URI = "https://localhost:7967/v1"
10
+ class Config < Pwnix::Api::Client::ConfigFile
11
+
12
+ include Singleton
13
+
14
+ def initialize
15
+ @config_file = "/opt/pwnix/pwnix-config/pwnix-ui/config.json"
16
+ read
17
+ end
18
+
19
+ def base_uri
20
+ @config_hash['api_uri']
21
+ end
22
+
23
+ def debug_mode
24
+ @config_hash['debug_mode']
25
+ end
26
+
27
+ def [](key)
28
+ @config_hash[key]
29
+ end
10
30
  end
11
31
  end
12
32
  end
13
33
  end
14
34
 
15
- require_relative 'system'
16
- require_relative 'shell'
17
- require_relative 'shell_receiver_config'
18
- require_relative 'mode'
19
- require_relative 'service'
35
+ module Pwnix
36
+ module Api
37
+ module Client
38
+ class ErrorQueue
39
+ include Singleton
40
+
41
+ attr_accessor :queue
42
+
43
+ def initialize
44
+ @queue =[]
45
+ end
46
+
47
+ def clear
48
+ @queue = []
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+ end
20
55
 
21
56
  module Pwnix
22
57
  module Api
23
58
  module Client
59
+ module HTTPartyTime
24
60
 
61
+ def self.included(base)
62
+ base.base_uri Pwnix::Api::Client::Config.instance['api_base_uri']
63
+ base.basic_auth Pwnix::Api::Client::Config.instance['api_username'],
64
+ Pwnix::Api::Client::Config.instance['api_password']
65
+ base.debug_output
66
+ base.format :json
25
67
 
26
- =begin
27
- module AuthdClient
28
- include Httparty
29
-
30
- def initialize(config={})
31
- username = config[:username]
32
- password = config[:password]
33
- server = config[:server] || "localhost"
68
+ @@errors = ErrorQueue.instance
69
+ end
70
+
71
+ def has_errors?
72
+ !@@errors.queue.empty?
73
+ end
74
+
75
+ def errors
76
+ @@errors.queue
77
+ end
78
+
79
+ def last_error
80
+ @@errors.queue.last
81
+ end
82
+
83
+ def clear_errors
84
+ @@errors.queue = []
85
+ end
86
+
87
+ def safe_api_call(endpoint,params={})
88
+ begin
89
+
90
+ response = self.class.post(endpoint,{:body => params})
91
+ case response.code
92
+
93
+ when 200
94
+
95
+ # TODO - everything should return a hash
96
+ parsed_response = response.parsed_response['result']
97
+
98
+ if parsed_response.is_a? Hash
99
+
100
+ if parsed_response['error']
101
+ @@errors.queue.push "Handled exception: #{parsed_response['error']}"
102
+ end
103
+
104
+ end
34
105
 
35
- # Configure with Basic auth for the API
36
- if username && password
37
- self.class.basic_auth username,password
106
+ return parsed_response
107
+
108
+ when 404
109
+ @@errors.queue.push "404 - not found! #{endpoint} #{parsed_response}"
110
+
111
+ when 500...600
112
+ @@errors.queue.push "500 - server exception! #{response}"
113
+ end
114
+ rescue Exception => e
115
+ @@errors.queue.push "Client error: #{e}"
116
+ return nil
38
117
  end
39
118
  end
40
119
 
41
120
  end
42
- =end
121
+ end
122
+ end
123
+ end
43
124
 
125
+ require_relative 'system'
126
+ require_relative 'shell'
127
+ require_relative 'shell_receiver_config'
128
+ require_relative 'mode'
129
+ require_relative 'node'
130
+ require_relative 'service'
131
+
132
+ module Pwnix
133
+ module Api
134
+ module Client
44
135
  class ApiClient
45
136
 
46
137
  attr_accessor :base_uri
@@ -49,10 +140,13 @@ module Pwnix
49
140
  attr_accessor :shell_receiver_config
50
141
  attr_accessor :services
51
142
  attr_accessor :modes
143
+ attr_accessor :node
144
+ attr_accessor :error_string
52
145
 
146
+ include HTTParty
147
+ include HTTPartyTime
53
148
 
54
149
  def initialize(config={})
55
-
56
150
  @shell_receiver_config = ShellReceiverConfig.new
57
151
 
58
152
  @shells = {
@@ -66,9 +160,11 @@ module Pwnix
66
160
  }
67
161
 
68
162
  @modes = {
69
- "normal_mode" => Mode.new("normal_mode"),
163
+ "normal_mode" => Mode.new("normal_mode")
70
164
  }
71
165
 
166
+ @node = Node.new
167
+
72
168
  @system = System.new
73
169
 
74
170
  @services = {
@@ -80,8 +176,12 @@ module Pwnix
80
176
  "stealth" => Service.new("stealth"),
81
177
  "text_to_bash" => Service.new("text_to_bash")
82
178
  }
179
+ end
83
180
 
181
+ def connected?
182
+ safe_api_call("/node/connected") == "ok"
84
183
  end
184
+
85
185
  end
86
186
  end
87
187
  end
@@ -0,0 +1,30 @@
1
+ module Pwnix
2
+ module Api
3
+ module Client
4
+ class ConfigFile
5
+
6
+ def initialize(config_file)
7
+ @config_file=config_file
8
+ @config_hash = JSON.parse(File.read(@config_file))
9
+ end
10
+
11
+ def [](key, value=nil)
12
+ if value
13
+ @config_hash[key] = value
14
+ else
15
+ @config_hash[key]
16
+ end
17
+ end
18
+
19
+ def read
20
+ @config_hash = JSON.parse(File.read(@config_file))
21
+ end
22
+
23
+ def write
24
+ File.open(@config_file,'w'){ |f| JSON.dump(@config_hash, f) }
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -3,36 +3,34 @@ module Pwnix
3
3
  module Client
4
4
  class Mode
5
5
  include HTTParty
6
- base_uri Pwnix::Api::Client::BASE_URI
7
- debug_output
8
- format :json
6
+ include HTTPartyTime
9
7
 
10
8
  def initialize(mode_name)
11
9
  @mode_name = mode_name
12
10
  end
13
11
 
14
12
  def start
15
- self.class.post("/mode/#{@mode_name}/start", :body => {}).parsed_response['result']
13
+ safe_api_call("/mode/#{@mode_name}/start")
16
14
  end
17
15
 
18
16
  def stop
19
- self.class.post("/mode/#{@mode_name}/stop", :body => {}).parsed_response['result']
17
+ safe_api_call("/mode/#{@mode_name}/stop")
20
18
  end
21
19
 
22
20
  def status
23
- self.class.post("/mode/#{@mode_name}/status", :body => {}).parsed_response['result']
21
+ safe_api_call("/mode/#{@mode_name}/status")
24
22
  end
25
23
 
26
24
  def status_string
27
- self.class.post("/mode/#{@mode_name}/status_string", :body => {}).parsed_response['result']
25
+ safe_api_call("/mode/#{@mode_name}/status_string")
28
26
  end
29
27
 
30
28
  def running?
31
- self.class.post("/mode/#{@mode_name}/running", :body => {}).parsed_response['result']
29
+ safe_api_call("/mode/#{@mode_name}/running")
32
30
  end
33
31
 
34
32
  def available?
35
- self.class.post("/mode/#{@mode_name}/available", :body => {}).parsed_response['result']
33
+ safe_api_call("/mode/#{@mode_name}/available")
36
34
  end
37
35
 
38
36
  end
@@ -0,0 +1,68 @@
1
+ require_relative 'node/api_config'
2
+ require_relative 'node/cookbook'
3
+ require_relative 'node/client/client_manager'
4
+ require_relative 'node/client/console_client'
5
+
6
+ module Pwnix
7
+ module Api
8
+ module Client
9
+ class Node
10
+ include HTTParty
11
+ include HTTPartyTime
12
+
13
+ attr_accessor :client_manager, :api_config
14
+
15
+ def initialize
16
+ @client_manager = Pwnix::Api::Client::ClientManager.new
17
+ @api_config = Pwnix::Api::Client::ApiConfig.new
18
+ end
19
+
20
+ def connected?
21
+ return true if safe_api_call("/node/check") == "ok"
22
+ end
23
+
24
+ def cookbooks
25
+ cookbook_list = safe_api_call("/node/cookbook/list")
26
+ cookbooks = []
27
+ cookbook_list.each do |cookbook_name|
28
+ cookbooks << Cookbook.new(cookbook_name)
29
+ end
30
+ cookbooks
31
+ end
32
+
33
+ def status
34
+ safe_api_call("/node/status")
35
+ end
36
+
37
+ def version
38
+ safe_api_call("/node/version")
39
+ end
40
+
41
+ def release
42
+ safe_api_call("/node/release")
43
+ end
44
+
45
+ def last_commit(product)
46
+ safe_api_call("/node/last_commit", { :product => product } )
47
+ end
48
+
49
+ def update
50
+ safe_api_call("/node/update", { :options => {:timeout => 600} } )
51
+ end
52
+
53
+ def updating?
54
+ safe_api_call("/node/updating")
55
+ end
56
+
57
+ def clear
58
+ safe_api_call("/node/clear")
59
+ end
60
+
61
+ def restart
62
+ safe_api_call("/node/restart")
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,19 @@
1
+ module Pwnix
2
+ module Api
3
+ module Client
4
+ class ApiConfig
5
+ include HTTParty
6
+ include HTTPartyTime
7
+
8
+ def dump
9
+ safe_api_call("/node/config/api/dump")
10
+ end
11
+
12
+ def set(config)
13
+ safe_api_call("/node/config/api/set", :config => config)
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,79 @@
1
+ module Pwnix
2
+ module Api
3
+ module Client
4
+ class ClientManager
5
+ include HTTParty
6
+ include HTTPartyTime
7
+
8
+ #attr_accessor :clients
9
+
10
+ def initialize
11
+ @clients = []
12
+ end
13
+
14
+ def status
15
+ safe_api_call("/node/clients/status")
16
+ end
17
+
18
+ # Public: Check if the client exists in the API
19
+ #
20
+ # API might be down, so lets make sure this returns a true or false
21
+ # othewise it could be an exception string
22
+ #
23
+ def client_exists?(id)
24
+ return true if safe_api_call("/node/clients/#{id}/exist") == true
25
+ false
26
+ end
27
+
28
+ def create(type)
29
+ # Go ahead and try to create the client
30
+ id = safe_api_call("/node/clients/create", :type => type )
31
+
32
+ # Check to make sure it was successfully created before adding it to our
33
+ # local list of clients
34
+ if client_exists?(id)
35
+ @clients << Pwnix::Api::Client::ConsoleClient.new(id)
36
+ return true
37
+ end
38
+
39
+ false
40
+ end
41
+
42
+ def get_client(id)
43
+ @clients.select{|c| c.id == id }.first
44
+ end
45
+
46
+ def destroy_client(id)
47
+ if client_exists?(id)
48
+ destroyable_client = @clients.select{|c| c.id == id }.first
49
+ destroyable_client.disconnect
50
+ destroyable_client.destroy # destroy it remotely
51
+ @clients.delete(destroyable_client)
52
+ return true
53
+ end
54
+ false
55
+ end
56
+
57
+ def list
58
+ @clients = []
59
+
60
+ # Since the API & UI are disconnected, we need to check to see if there are
61
+ # any other remote clients at this time - we might be out of sync.
62
+ remote_clients = safe_api_call("/node/clients/list")
63
+ if remote_clients
64
+ remote_clients.each do |remote_client_id|
65
+ # Now go through our clients and see if we have an id that matches
66
+ # TODO - these ids should probably be hard to spoof - needs more
67
+ # thought than i have time for right now.
68
+ unless (@clients.select{|c| c.id == remote_client_id }).count > 0
69
+ @clients << Pwnix::Api::Client::ConsoleClient.new(remote_client_id)
70
+ end
71
+ end
72
+ end
73
+ @clients
74
+ end
75
+
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,51 @@
1
+ module Pwnix
2
+ module Api
3
+ module Client
4
+ class ConsoleClient
5
+ include HTTParty
6
+ include HTTPartyTime
7
+
8
+ attr_reader :id
9
+ attr_reader :type
10
+
11
+ def initialize(id)
12
+ @id = id
13
+ @type = "console_client"
14
+ end
15
+
16
+ def status
17
+ safe_api_call("/node/clients/#{@id}/status")
18
+ end
19
+
20
+ def config
21
+ safe_api_call("/node/clients/#{@id}/config")
22
+ end
23
+
24
+ def get_config_value(key)
25
+ safe_api_call("/node/clients/#{@id}/config/#{key}")
26
+ end
27
+
28
+ def set_config_value(key,value)
29
+ safe_api_call("/node/clients/#{@id}/config/#{key}/set", :value => value)
30
+ end
31
+
32
+ def connected?
33
+ safe_api_call("/node/clients/#{@id}/connected") == true
34
+ end
35
+
36
+ def connect
37
+ safe_api_call("/node/clients/#{@id}/connect")
38
+ end
39
+
40
+ def disconnect
41
+ safe_api_call("/node/clients/#{@id}/disconnect")
42
+ end
43
+
44
+ def destroy
45
+ safe_api_call("/node/clients/#{@id}/destroy")
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ module Pwnix
2
+ module Api
3
+ module Client
4
+ class Cookbook
5
+ include HTTParty
6
+ include HTTPartyTime
7
+
8
+ def initialize(name)
9
+ @name = name
10
+ end
11
+
12
+ def metadata
13
+ safe_api_call("/node/cookbook/#{@name}/metadata")
14
+ end
15
+
16
+ def name
17
+ safe_api_call("/node/cookbook/#{@name}/name")
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -3,44 +3,42 @@ module Pwnix
3
3
  module Client
4
4
  class Service
5
5
  include HTTParty
6
- base_uri Pwnix::Api::Client::BASE_URI
7
- debug_output
8
- format :json
6
+ include HTTPartyTime
9
7
 
10
8
  def initialize(service_name)
11
9
  @service_name = service_name
12
10
  end
13
11
 
14
12
  def status
15
- self.class.post("/services/#{@service_name}/status", :body => {}).parsed_response['result']
13
+ safe_api_call("/services/#{@service_name}/status")
16
14
  end
17
15
 
18
16
  def status_string
19
- self.class.post("/services/#{@service_name}/status_string", :body => {}).parsed_response['result']
17
+ safe_api_call("/services/#{@service_name}/status_string")
20
18
  end
21
19
 
22
20
  def running?
23
- self.class.post("/services/#{@service_name}/running", :body => {}).parsed_response['result']
21
+ safe_api_call("/services/#{@service_name}/running")
24
22
  end
25
23
 
26
24
  def available?
27
- self.class.post("/services/#{@service_name}/available", :body => {}).parsed_response['result']
25
+ safe_api_call("/services/#{@service_name}/available")
28
26
  end
29
27
 
30
28
  def start(params)
31
- self.class.post("/services/#{@service_name}/start", :body => params).parsed_response['result']
29
+ safe_api_call("/services/#{@service_name}/start", params )
32
30
  end
33
31
 
34
32
  def stop
35
- self.class.post("/services/#{@service_name}/stop", :body => {}).parsed_response['result']
33
+ safe_api_call("/services/#{@service_name}/stop")
36
34
  end
37
35
 
38
36
  def enable(params={})
39
- self.class.post("/services/#{@service_name}/enable", :body => params).parsed_response['result']
37
+ safe_api_call("/services/#{@service_name}/enable", params )
40
38
  end
41
39
 
42
40
  def disable
43
- self.class.post("/services/#{@service_name}/disable", :body => {}).parsed_response['result']
41
+ safe_api_call("/services/#{@service_name}/disable")
44
42
  end
45
43
 
46
44
  end
@@ -3,32 +3,30 @@
3
3
  module Client
4
4
  class Shell
5
5
  include HTTParty
6
- base_uri Pwnix::Api::Client::BASE_URI
7
- debug_output
8
- format :json
6
+ include HTTPartyTime
9
7
 
10
8
  def initialize(shell_name)
11
9
  @shell_name = shell_name
12
10
  end
13
11
 
14
12
  def status
15
- self.class.post("/shells/#{@shell_name}/status", :body => {}).parsed_response['result']
13
+ safe_api_call("/shells/#{@shell_name}/status")
16
14
  end
17
15
 
18
16
  def running?
19
- self.class.post("/shells/#{@shell_name}/running", :body => {}).parsed_response['result']
17
+ safe_api_call("/shells/#{@shell_name}/running")
20
18
  end
21
19
 
22
20
  def configure(config={}) # Configuration options
23
- self.class.post("/shells/#{@shell_name}/configure", :body => config ).parsed_response['result']
21
+ safe_api_call("/shells/#{@shell_name}/configure", config )
24
22
  end
25
23
 
26
24
  def enable
27
- self.class.post("/shells/#{@shell_name}/enable", :body => {}).parsed_response['result']
25
+ safe_api_call("/shells/#{@shell_name}/enable")
28
26
  end
29
27
 
30
28
  def disable
31
- self.class.post("/shells/#{@shell_name}/disable", :body => {}).parsed_response['result']
29
+ safe_api_call("/shells/#{@shell_name}/disable")
32
30
  end
33
31
 
34
32
  end
@@ -3,16 +3,14 @@ module Pwnix
3
3
  module Client
4
4
  class ShellReceiverConfig
5
5
  include HTTParty
6
- base_uri Pwnix::Api::Client::BASE_URI
7
- debug_output
8
- format :json
6
+ include HTTPartyTime
9
7
 
10
8
  def backtrack_generate
11
- self.class.post("/shells/backtrack_receiver_config/generate", :body => {}).parsed_response['result']
9
+ safe_api_call("/shells/backtrack_receiver_config/generate")
12
10
  end
13
11
 
14
12
  def pwnix_generate
15
- self.class.post("/shells/pwnix_receiver_config/generate", :body => {}).parsed_response['result']
13
+ safe_api_call("/shells/pwnix_receiver_config/generate")
16
14
  end
17
15
 
18
16
  end
@@ -2,34 +2,32 @@ require_relative 'system/hardware'
2
2
  require_relative 'system/logs'
3
3
  require_relative 'system/network'
4
4
  require_relative 'system/os'
5
- require_relative 'system/server'
6
5
  require_relative 'system/sms'
7
6
  require_relative 'system/ssh'
7
+ require_relative 'system/utility'
8
8
 
9
9
  module Pwnix
10
10
  module Api
11
11
  module Client
12
12
  class System
13
13
  include HTTParty
14
- base_uri Pwnix::Api::Client::BASE_URI
15
- debug_output
16
- format :json
14
+ include HTTPartyTime
17
15
 
18
16
  attr_accessor :logs, :network, :hardware
19
- attr_accessor :os, :server, :sms, :ssh
17
+ attr_accessor :os, :sms, :ssh, :utility
20
18
 
21
19
  def initialize
22
20
  @hardware = Hardware.new
23
21
  @logs = Logs.new
24
22
  @network = Network.new
25
23
  @os = Os.new
26
- @server = Server.new
27
24
  @sms = Sms.new
28
25
  @ssh = Ssh.new
26
+ @utility = Utility.new
29
27
  end
30
28
 
31
29
  def status
32
- self.class.post("/system/status", :body => {}).parsed_response['result']
30
+ safe_api_call("/system/status")
33
31
  end
34
32
 
35
33
  end
@@ -3,12 +3,10 @@ module Pwnix
3
3
  module Client
4
4
  class Hardware
5
5
  include HTTParty
6
- base_uri Pwnix::Api::Client::BASE_URI
7
- debug_output
8
- format :json
6
+ include HTTPartyTime
9
7
 
10
8
  def status
11
- self.class.post("/system/hardware/status", :body => {}).parsed_response['result']
9
+ safe_api_call("/system/hardware/status")
12
10
  end
13
11
  end
14
12
  end
@@ -3,24 +3,22 @@ module Pwnix
3
3
  module Client
4
4
  class Logs
5
5
  include HTTParty
6
- base_uri Pwnix::Api::Client::BASE_URI
7
- debug_output
8
- format :json
6
+ include HTTPartyTime
9
7
 
10
8
  def list
11
- self.class.post("/system/logs/list", :body => {}).parsed_response['result']
9
+ safe_api_call("/system/logs/list")
12
10
  end
13
11
 
14
12
  def tail(name)
15
- self.class.post("/system/logs/tail", :body => { :log_name => name }).parsed_response['result']
13
+ safe_api_call("/system/logs/tail", { :log_name => name } )
16
14
  end
17
15
 
18
16
  def head(name)
19
- self.class.post("/system/logs/head", :body => { :log_name => name }).parsed_response['result']
17
+ safe_api_call("/system/logs/head", { :log_name => name } )
20
18
  end
21
19
 
22
20
  def contents(name)
23
- self.class.post("/system/logs/contents", :body => { :log_name => name }).parsed_response['result']
21
+ safe_api_call("/system/logs/contents", { :log_name => name } )
24
22
  end
25
23
 
26
24
  end
@@ -3,41 +3,49 @@ module Pwnix
3
3
  module Client
4
4
  class Network
5
5
  include HTTParty
6
- base_uri Pwnix::Api::Client::BASE_URI
7
- debug_output
8
- format :json
6
+ include HTTPartyTime
9
7
 
10
8
  def status
11
- self.class.post("/system/network/status", :body => {}).parsed_response['result']
9
+ safe_api_call("/system/network/status")
10
+ end
11
+
12
+
13
+ def primary_dns
14
+ safe_api_call("/system/network/primary_dns")
12
15
  end
13
16
 
14
17
  def list_interfaces
15
- details = self.class.post("/system/network/status", :body => {}).parsed_response['result']
18
+ details = safe_api_call("/system/network/status")
16
19
  # Read http://blog.jayfields.com/2008/03/ruby-inject.html if you're not super-familiar w/ inject
17
20
  details.inject([]){|interface_list, (interface,interface_details)| interface_list << interface; }
18
21
  end
19
22
 
20
23
  # Done
21
24
  def interface_status(interface)
22
- self.class.post("/system/network/#{interface}/status", :body => {}).parsed_response['result']
25
+ safe_api_call("/system/network/#{interface}/status")
26
+ end
27
+
28
+ # Done
29
+ def interface_mode(interface)
30
+ safe_api_call("/system/network/#{interface}/mode")
23
31
  end
24
32
 
25
33
  # Done
26
34
  def interface_reset(interface)
27
- self.class.post("/system/network/#{interface}/reset", :body => {}).parsed_response['result']
35
+ safe_api_call("/system/network/#{interface}/reset")
28
36
  end
29
37
 
30
38
  def interface_set_dhcp(interface)
31
- self.class.post("/system/network/#{interface}/dhcp/enable", :body => {}).parsed_response['result']
39
+ safe_api_call("/system/network/#{interface}/dhcp/enable")
32
40
  end
33
41
 
34
42
  def interface_set_static_ip(interface,options)
35
43
  # [ :ip, :netmask, :gateway, :dns]
36
- self.class.post("/system/network/#{interface}/static_ip/set", :body => options).parsed_response['result']
44
+ safe_api_call("/system/network/#{interface}/static_ip/set", options )
37
45
  end
38
46
 
39
47
  def interface_set_mac(interface, mac=nil)
40
- self.class.post("/system/network/#{interface}/mac/set", :body => { :mac => mac } ).parsed_response['result']
48
+ safe_api_call("/system/network/#{interface}/mac/set", { :mac => mac } )
41
49
  end
42
50
 
43
51
  end
@@ -3,36 +3,38 @@ module Pwnix
3
3
  module Client
4
4
  class Os
5
5
  include HTTParty
6
- base_uri Pwnix::Api::Client::BASE_URI
7
- debug_output
8
- format :json
6
+ include HTTPartyTime
9
7
 
10
8
  def status
11
- self.class.post("/system/os/status", :body => {}).parsed_response['result']
9
+ safe_api_call("/system/os/status")
12
10
  end
13
11
 
14
12
  def filesystem
15
- self.class.post("/system/os/filesystem", :body => {}).parsed_response['result']
13
+ safe_api_call("/system/os/filesystem")
16
14
  end
17
15
 
18
16
  def netstat
19
- self.class.post("/system/os/netstat", :body => {}).parsed_response['result']
17
+ safe_api_call("/system/os/netstat")
20
18
  end
21
19
 
22
20
  def cleanup
23
- self.class.post("/system/os/cleanup", :body => {}).parsed_response['result']
21
+ safe_api_call("/system/os/cleanup")
24
22
  end
25
23
 
26
24
  def restart
27
- self.class.post("/system/os/restart", :body => {}).parsed_response['result']
25
+ safe_api_call("/system/os/restart")
28
26
  end
29
27
 
30
28
  def hostname
31
- self.class.post("/system/os/hostname", :body => {}).parsed_response['result']
29
+ safe_api_call("/system/os/hostname")
32
30
  end
33
31
 
34
32
  def set_hostname(hostname)
35
- self.class.post("/system/os/hostname/set", :body => {:hostname => hostname}).parsed_response['result']
33
+ safe_api_call("/system/os/hostname/set", { :hostname => hostname } )
34
+ end
35
+
36
+ def set_password(username,password)
37
+ safe_api_call("/system/os/password/set", { :username => username, :password => password } )
36
38
  end
37
39
 
38
40
  end
@@ -3,30 +3,19 @@ module Pwnix
3
3
  module Client
4
4
  class Sms
5
5
  include HTTParty
6
- base_uri Pwnix::Api::Client::BASE_URI
7
- debug_output
8
- format :json
6
+ include HTTPartyTime
9
7
 
10
8
  def status
11
- self.class.post("/system/sms/status", :body => {}).parsed_response['result']
9
+ safe_api_call("/system/sms/status")
12
10
  end
13
11
 
14
12
  def set(options={})
15
- self.class.post(
16
- "/system/sms/set",
17
- :body => {
18
- :configuration => options
19
- }
20
- ).parsed_response['result']
13
+ safe_api_call("/system/sms/set", { :configuration => options })
21
14
  end
22
15
 
23
16
  def test(options={})
24
- self.class.post(
25
- "/system/sms/test",
26
- :body => {
27
- :configuration => options
28
- }
29
- ).parsed_response['result']
17
+ safe_api_call("/system/sms/test", { :configuration => options })
18
+
30
19
  end
31
20
 
32
21
  def hint
@@ -3,16 +3,14 @@ module Pwnix
3
3
  module Client
4
4
  class Ssh
5
5
  include HTTParty
6
- base_uri Pwnix::Api::Client::BASE_URI
7
- debug_output
8
- format :json
6
+ include HTTPartyTime
9
7
 
10
8
  def public_key
11
- self.class.post("/system/ssh/public_key", :body => {}).parsed_response['result']
9
+ safe_api_call("/system/ssh/public_key")
12
10
  end
13
11
 
14
12
  def reset
15
- self.class.post("/system/ssh/reset", :body => {}).parsed_response['result']
13
+ safe_api_call("/system/ssh/reset")
16
14
  end
17
15
 
18
16
  end
@@ -0,0 +1,30 @@
1
+ module Pwnix
2
+ module Api
3
+ module Client
4
+ class Utility
5
+ include HTTParty
6
+ include HTTPartyTime
7
+
8
+ def initialize
9
+ end
10
+
11
+ def ping(ip)
12
+ safe_api_call("/system/utility/ping", { :ip => ip } )
13
+ end
14
+
15
+ def nmap(ip)
16
+ safe_api_call("/system/utility/nmap", { :ip => ip } )
17
+ end
18
+
19
+ def traceroute(ip)
20
+ safe_api_call("/system/utility/traceroute", { :ip => ip } )
21
+ end
22
+
23
+ def run_command(command)
24
+ safe_api_call("/system/utility/run_command", { :command => command } )
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,7 +1,7 @@
1
1
  module Pwnix
2
2
  module Api
3
3
  module Client
4
- VERSION = "1.3"
4
+ VERSION = "1.4"
5
5
  end
6
6
  end
7
7
  end
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwnix-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.3'
4
+ version: '1.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-10 00:00:00.000000000 Z
12
+ date: 2012-11-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &9767620 !ruby/object:Gem::Requirement
16
+ requirement: &23148180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9767620
24
+ version_requirements: *23148180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &9767200 !ruby/object:Gem::Requirement
27
+ requirement: &23147380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,11 +32,12 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *9767200
35
+ version_requirements: *23147380
36
36
  description: ! ' Manage a Pwnix device. '
37
37
  email:
38
38
  - info@pwnieexpress.com
39
- executables: []
39
+ executables:
40
+ - console.sh
40
41
  extensions: []
41
42
  extra_rdoc_files: []
42
43
  files:
@@ -46,10 +47,17 @@ files:
46
47
  - Gemfile.lock
47
48
  - README.md
48
49
  - Rakefile
50
+ - bin/console.sh
49
51
  - examples/configure_shells.rb
50
52
  - lib/pwnix-api-client.rb
51
53
  - lib/pwnix-api-client/api_client.rb
54
+ - lib/pwnix-api-client/config/config_file.rb
52
55
  - lib/pwnix-api-client/mode.rb
56
+ - lib/pwnix-api-client/node.rb
57
+ - lib/pwnix-api-client/node/api_config.rb
58
+ - lib/pwnix-api-client/node/client/client_manager.rb
59
+ - lib/pwnix-api-client/node/client/console_client.rb
60
+ - lib/pwnix-api-client/node/cookbook.rb
53
61
  - lib/pwnix-api-client/service.rb
54
62
  - lib/pwnix-api-client/shell.rb
55
63
  - lib/pwnix-api-client/shell_receiver_config.rb
@@ -59,9 +67,9 @@ files:
59
67
  - lib/pwnix-api-client/system/logs.rb
60
68
  - lib/pwnix-api-client/system/network.rb
61
69
  - lib/pwnix-api-client/system/os.rb
62
- - lib/pwnix-api-client/system/server.rb
63
70
  - lib/pwnix-api-client/system/sms.rb
64
71
  - lib/pwnix-api-client/system/ssh.rb
72
+ - lib/pwnix-api-client/system/utility.rb
65
73
  - lib/pwnix-api-client/version.rb
66
74
  - pwnix-api-client.gemspec
67
75
  - util/console.rb
@@ -1,37 +0,0 @@
1
- module Pwnix
2
- module Api
3
- module Client
4
- class Server
5
- include HTTParty
6
- base_uri Pwnix::Api::Client::BASE_URI
7
- debug_output
8
- format :json
9
-
10
- def status
11
- self.class.post("/system/server/status", :body => {}).parsed_response['result']
12
- end
13
-
14
- def version
15
- self.class.post("/system/server/version", :body => {}).parsed_response['result']
16
- end
17
-
18
- def release
19
- self.class.post("/system/server/release", :body => {}).parsed_response['result']
20
- end
21
-
22
- def update
23
- self.class.post("/system/server/update", :options => {:timeout => 600}, :body => {}).parsed_response['result']
24
- end
25
-
26
- def clear
27
- self.class.post("/system/server/clear", :body => {}).parsed_response['result']
28
- end
29
-
30
- def restart
31
- self.class.post("/system/server/restart", :body => {}).parsed_response['result']
32
- end
33
-
34
- end
35
- end
36
- end
37
- end