mastercontrol 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/lib/mastercontrol.rb +3 -2
- data/lib/mastercontrol/accounts.rb +110 -0
- data/lib/mastercontrol/server.rb +29 -29
- data/lib/mastercontrol/version.rb +1 -1
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9297109005398dc9e0cc35bd1b0d8d76d2c9ae11
|
4
|
+
data.tar.gz: ad650d02492371f1cedc5442e6da64c95eeb3b3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57ca7a0c275688cfbdad10d56b1dc927511e2e795ccbc53852a837953fea9858de91ae2df110016e890d73e5463f837e8af95646024622e31c00a79d7c1d79e4
|
7
|
+
data.tar.gz: d1f587ac1c23a4e722f0f5f264ff6caa6bc1f3db57624fb9d24e99901ca4699c089616278a585f7c99b1fffa9759d8f839d9e0165940bca450560dd58e24b6c1
|
data/lib/mastercontrol.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require "mastercontrol/version"
|
2
2
|
require "mastercontrol/server"
|
3
|
+
require "mastercontrol/accounts"
|
3
4
|
|
4
5
|
module Mastercontrol
|
5
6
|
class << self
|
6
|
-
attr_accessor :access_hash, :server_hostname
|
7
|
+
attr_accessor :access_hash, :access_hash_user, :server_hostname
|
7
8
|
end
|
8
9
|
|
9
10
|
def self.base_url
|
@@ -11,6 +12,6 @@ module Mastercontrol
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.auth_header
|
14
|
-
"WHM
|
15
|
+
"WHM #{@access_hash_user}:#{@access_hash}"
|
15
16
|
end
|
16
17
|
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Mastercontrol
|
5
|
+
module Accounts
|
6
|
+
class WhmAccount
|
7
|
+
attr_accessor :max_addons, :ip, :ipv6, :outgoing_mail_hold, :outgoing_mail_suspended, :min_defer_fail_to_trigger_protection,
|
8
|
+
:legacy_backup, :disk_used, :max_ftp, :start_date, :max_defer_fail_percentage, :disk_limit, :is_locked, :suspend_time,
|
9
|
+
:email, :domain, :unix_startdate, :user, :plan, :shell, :max_pop, :backup, :theme, :owner, :max_email_per_hour, :suspend_reason,
|
10
|
+
:max_list, :suspended, :max_sql, :max_parked, :partition, :max_sub
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.list
|
14
|
+
url = "#{Mastercontrol.base_url}/listaccts?api.version=1"
|
15
|
+
response = RestClient.get url, {authorization: Mastercontrol.auth_header}
|
16
|
+
|
17
|
+
# parse the json
|
18
|
+
json_response = JSON.parse(response)
|
19
|
+
return_array = []
|
20
|
+
# build and return the ServerLoad Object
|
21
|
+
json_response['data']['acct'].each do |account|
|
22
|
+
|
23
|
+
return_array << parse_account(account)
|
24
|
+
end
|
25
|
+
return_array
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.retrieve(username)
|
29
|
+
url = "#{Mastercontrol.base_url}/accountsummary?api.version=1&user=#{username}"
|
30
|
+
response = RestClient.get url, {authorization: Mastercontrol.auth_header}
|
31
|
+
|
32
|
+
# parse the json
|
33
|
+
json_response = JSON.parse(response)
|
34
|
+
|
35
|
+
if json_response["data"]["acct"].nil?
|
36
|
+
return nil
|
37
|
+
end
|
38
|
+
|
39
|
+
whm_account = json_response["data"]["acct"][0]
|
40
|
+
|
41
|
+
parse_account(whm_account)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.suspend(username, reason)
|
45
|
+
url = "#{Mastercontrol.base_url}/suspendacct?api.version=1&user=#{username}&reason=#{reason}"
|
46
|
+
response = RestClient.get url, {authorization: Mastercontrol.auth_header}
|
47
|
+
|
48
|
+
# parse the json
|
49
|
+
json_response = JSON.parse(response)
|
50
|
+
|
51
|
+
if json_response["metadata"]["result"].to_i == 1
|
52
|
+
return true
|
53
|
+
else
|
54
|
+
return false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.unsuspend(username)
|
59
|
+
url = "#{Mastercontrol.base_url}/unsuspendacct?api.version=1&user=#{username}"
|
60
|
+
response = RestClient.get url, {authorization: Mastercontrol.auth_header}
|
61
|
+
|
62
|
+
# parse the json
|
63
|
+
json_response = JSON.parse(response)
|
64
|
+
|
65
|
+
if json_response["metadata"]["result"].to_i == 1
|
66
|
+
return true
|
67
|
+
else
|
68
|
+
return false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.parse_account(whm_account)
|
73
|
+
account = WhmAccount.new
|
74
|
+
account.max_addons = whm_account["maxaddons"]
|
75
|
+
account.ip = whm_account["ip"]
|
76
|
+
account.ipv6 = whm_account["ipv6"]
|
77
|
+
account.outgoing_mail_suspended = Integer(whm_account["outgoing_mail_suspended"])
|
78
|
+
account.outgoing_mail_hold = Integer(whm_account["outgoing_mail_hold"])
|
79
|
+
account.min_defer_fail_to_trigger_protection = Integer(whm_account["min_defer_fail_to_trigger_protection"])
|
80
|
+
account.legacy_backup = Integer(whm_account["legacy_backup"])
|
81
|
+
account.disk_used = whm_account["diskused"]
|
82
|
+
account.max_ftp = whm_account["maxftp"]
|
83
|
+
account.start_date = whm_account["startdate"]
|
84
|
+
account.max_defer_fail_percentage = Integer(whm_account["max_defer_fail_percentage"])
|
85
|
+
account.disk_limit = whm_account["disklimit"]
|
86
|
+
account.is_locked = Integer(whm_account["is_locked"])
|
87
|
+
account.suspend_time = whm_account["suspendtime"]
|
88
|
+
account.email = whm_account["email"]
|
89
|
+
account.domain = whm_account["domain"]
|
90
|
+
account.unix_startdate = whm_account["unix_startdate"]
|
91
|
+
account.user = whm_account["user"]
|
92
|
+
account.plan = whm_account["plan"]
|
93
|
+
account.shell = whm_account["shell"]
|
94
|
+
account.max_pop = whm_account["maxpop"]
|
95
|
+
account.backup = Integer(whm_account["backup"])
|
96
|
+
account.theme = whm_account["theme"]
|
97
|
+
account.owner = whm_account["owner"]
|
98
|
+
account.max_email_per_hour = whm_account["max_email_per_hour"]
|
99
|
+
account.suspend_reason = whm_account["suspendreason"]
|
100
|
+
account.max_list = whm_account["maxlst"]
|
101
|
+
account.suspended = Integer(whm_account["suspended"])
|
102
|
+
account.max_sql = whm_account["maxsql"]
|
103
|
+
account.max_parked = whm_account["maxparked"]
|
104
|
+
account.partition = whm_account["partition"]
|
105
|
+
account.max_sub = whm_account["maxsub"]
|
106
|
+
account
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
data/lib/mastercontrol/server.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
class ServerLoad
|
5
|
-
attr_accessor :one, :five, :fifteen
|
6
|
-
def initialize(res_one, res_five, res_fifteen)
|
7
|
-
@one = res_one.to_f
|
8
|
-
@five = res_five.to_f
|
9
|
-
@fifteen = res_fifteen.to_f
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class ServerHostname
|
14
|
-
attr_accessor :name
|
15
|
-
def initialize(res_hostname)
|
16
|
-
@name = res_hostname
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class DiskPartition
|
21
|
-
attr_accessor :disk, :filesystem, :mount, :used, :percentage, :total, :available
|
22
|
-
def initialize(res_disk, res_filesystem, res_mount, res_used, res_percentage, res_total, res_available)
|
23
|
-
@disk = res_disk
|
24
|
-
@filesystem = res_filesystem
|
25
|
-
@mount = res_mount
|
26
|
-
@used = res_used.to_i
|
27
|
-
@percentage = res_percentage.to_f
|
28
|
-
@total = res_total.to_i
|
29
|
-
@available = res_available.to_i
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
4
|
module Mastercontrol
|
34
5
|
module Server
|
35
6
|
|
7
|
+
class ServerLoad
|
8
|
+
attr_accessor :one, :five, :fifteen
|
9
|
+
def initialize(res_one, res_five, res_fifteen)
|
10
|
+
@one = res_one.to_f
|
11
|
+
@five = res_five.to_f
|
12
|
+
@fifteen = res_fifteen.to_f
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class ServerHostname
|
17
|
+
attr_accessor :name
|
18
|
+
def initialize(res_hostname)
|
19
|
+
@name = res_hostname
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class DiskPartition
|
24
|
+
attr_accessor :disk, :filesystem, :mount, :used, :percentage, :total, :available
|
25
|
+
def initialize(res_disk, res_filesystem, res_mount, res_used, res_percentage, res_total, res_available)
|
26
|
+
@disk = res_disk
|
27
|
+
@filesystem = res_filesystem
|
28
|
+
@mount = res_mount
|
29
|
+
@used = res_used.to_i
|
30
|
+
@percentage = res_percentage.to_f
|
31
|
+
@total = res_total.to_i
|
32
|
+
@available = res_available.to_i
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
36
|
def self.system_load_avg
|
37
37
|
url = "#{Mastercontrol.base_url}/systemloadavg?api.version=1"
|
38
38
|
response = RestClient.get url, {authorization: Mastercontrol.auth_header}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mastercontrol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -94,20 +94,6 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '2.1'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: codeclimate-test-reporter
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0.6'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0.6'
|
111
97
|
description: MasterControl is a Ruby library for the cPanel/WHM APIs
|
112
98
|
email:
|
113
99
|
- matt@rackfleet.com
|
@@ -116,6 +102,7 @@ extensions: []
|
|
116
102
|
extra_rdoc_files: []
|
117
103
|
files:
|
118
104
|
- lib/mastercontrol.rb
|
105
|
+
- lib/mastercontrol/accounts.rb
|
119
106
|
- lib/mastercontrol/server.rb
|
120
107
|
- lib/mastercontrol/version.rb
|
121
108
|
homepage: https://github.com/rackfleet/mastercontrol
|