direct_admin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +57 -0
- data/lib/direct_admin.rb +5 -0
- data/lib/direct_admin/client.rb +38 -0
- data/lib/direct_admin/commands.rb +51 -0
- data/lib/direct_admin/request.rb +50 -0
- data/lib/direct_admin/version.rb +4 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 56f4b3c401671eee31fef798b7148c8b27bc5f50
|
4
|
+
data.tar.gz: f0da1e4026fd7b53e9bcc2847ed958289e0005fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7fbd723f9ee51975c0a73a5a8471897093b62a493d223fe84d1806a12a5e41e2a665c4e9dec646f06a0bd7dc24d666f438aa65e4d50ddd72f636f71398fd782d
|
7
|
+
data.tar.gz: c7cffe79128d54c819362fffac3658344fad17d0cc05062a5dcd08ee8cc619730b12129f2a139efbadd101dbad8d5cba709c3ddcf46d10ffd9aac03207920a20
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# DirectAdmin API Client
|
2
|
+
|
3
|
+
An unofficial (and very incomplete) API client for the DirectAdmin webhosting
|
4
|
+
control panel.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem "direct_admin"
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install direct_admin
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
First you will need to create an instance of the client:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require "direct_admin"
|
26
|
+
|
27
|
+
client = DirectAdmin::Client.new(url: "https://localhost:2222", username: "admin", password: "secret")
|
28
|
+
```
|
29
|
+
|
30
|
+
And then you can call any of the Command methods on the client:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
client.create_login_key("CLI Tool", "abcd1234")
|
34
|
+
```
|
35
|
+
|
36
|
+
## Limitations
|
37
|
+
|
38
|
+
This library is purposely not feature complete. The DirectAdmin API is very large,
|
39
|
+
and spread out over a large knowledgebase.
|
40
|
+
|
41
|
+
I'm implementing what I need when it's needed, but will welcome contributions,
|
42
|
+
provided they are accompanied with tests.
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/adam12/direct_admin.
|
47
|
+
|
48
|
+
I love pull requests! If you fork this project and modify it, please ping me to see
|
49
|
+
if your changes can be incorporated back into this project.
|
50
|
+
|
51
|
+
That said, if your feature idea is nontrivial, you should probably open an issue to
|
52
|
+
[discuss it](http://www.igvita.com/2011/12/19/dont-push-your-pull-requests/)
|
53
|
+
before attempting a pull request.
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/direct_admin.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative "commands"
|
3
|
+
require_relative "request"
|
4
|
+
|
5
|
+
module DirectAdmin
|
6
|
+
class Client
|
7
|
+
include DirectAdmin::Commands
|
8
|
+
|
9
|
+
# URL of the DirectAdmin server
|
10
|
+
attr_accessor :url
|
11
|
+
alias server_url url
|
12
|
+
|
13
|
+
# Username to authenticate with
|
14
|
+
attr_accessor :username
|
15
|
+
alias server_username username
|
16
|
+
|
17
|
+
# Password to authenticate with
|
18
|
+
attr_accessor :password
|
19
|
+
alias server_password password
|
20
|
+
|
21
|
+
# Create a new instance of the Client
|
22
|
+
#
|
23
|
+
# == Required Arguments
|
24
|
+
#
|
25
|
+
# :url :: The url of the DirectAdmin server.
|
26
|
+
# :username :: A username to login as.
|
27
|
+
# :password :: The password which correspondes to the username.
|
28
|
+
def initialize(url:, username:, password:)
|
29
|
+
@url = url
|
30
|
+
@username = username
|
31
|
+
@password = password
|
32
|
+
end
|
33
|
+
|
34
|
+
def _request(method, endpoint, params) # :nodoc:
|
35
|
+
Request.new(self, method, endpoint, params)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module DirectAdmin
|
3
|
+
module Commands
|
4
|
+
# Create a login key
|
5
|
+
#
|
6
|
+
# client.create_login_key("CLI Tool", "abcd1234")
|
7
|
+
#
|
8
|
+
# == Required Arguments
|
9
|
+
#
|
10
|
+
# :name :: The name of the login key
|
11
|
+
# :value :: The value of the login key
|
12
|
+
def create_login_key(name, value, options = {})
|
13
|
+
never_expires = options.fetch(:never_expires, false)
|
14
|
+
expiration = options[:expiration]
|
15
|
+
allow_htm = options.fetch(:allow_htm, true)
|
16
|
+
allowed_commands = options.fetch(:allowed_commands, [])
|
17
|
+
allowed_ips = options.fetch(:allowed_ips, []).join("\r\n")
|
18
|
+
max_uses = options.fetch(:max_uses, 1)
|
19
|
+
clear_key = options.fetch(:clear_key, false)
|
20
|
+
|
21
|
+
params = {
|
22
|
+
"keyname" => name,
|
23
|
+
"key" => value,
|
24
|
+
"key2" => value,
|
25
|
+
"never_expires" => never_expires,
|
26
|
+
"max_uses" => max_uses,
|
27
|
+
"ips" => allowed_ips,
|
28
|
+
"passwd" => server_password,
|
29
|
+
"create" => "Create"
|
30
|
+
}
|
31
|
+
|
32
|
+
params["never_expires"] = "yes" if never_expires
|
33
|
+
params["clear_key"] = "yes" if clear_key
|
34
|
+
params["allow_htm"] = "yes" if allow_htm
|
35
|
+
|
36
|
+
if !never_expires && expiration
|
37
|
+
params["hour"] = expiration.hour
|
38
|
+
params["minute"] = expiration.minute
|
39
|
+
params["month"] = expiration.month
|
40
|
+
params["day"] = expiration.day
|
41
|
+
params["year"] = expiration.year
|
42
|
+
end
|
43
|
+
|
44
|
+
allowed_commands.each_with_index do |command, i|
|
45
|
+
params["select_allow#{i}"] = command
|
46
|
+
end
|
47
|
+
|
48
|
+
request(:post, "/CMD_API_LOGIN_KEYS", params)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "uri"
|
3
|
+
require "cgi"
|
4
|
+
require "http"
|
5
|
+
|
6
|
+
module DirectAdmin
|
7
|
+
class Request
|
8
|
+
attr_reader :method, :endpont, :params, :url
|
9
|
+
|
10
|
+
def initialize(client, method, endpoint, params)
|
11
|
+
@method = method
|
12
|
+
@endpoint = endpoint
|
13
|
+
@params = params
|
14
|
+
@url = URI.join(client.server_url, endpoint).to_s if client
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
response = _make_request
|
19
|
+
|
20
|
+
if response.status == 404
|
21
|
+
raise DirectAdmin::Error, "Invalid URL: #{url}"
|
22
|
+
end
|
23
|
+
|
24
|
+
parsed_body = _parse_response(response.to_s)
|
25
|
+
|
26
|
+
unless response.code == 200
|
27
|
+
raise DirectAdmin::Error, parsed_body["reason"]
|
28
|
+
end
|
29
|
+
|
30
|
+
parsed_body
|
31
|
+
end
|
32
|
+
|
33
|
+
def _make_request
|
34
|
+
HTTP.basic_auth(user: client.server_username, pass: client.server_password)
|
35
|
+
.public_send(method, url, form: params)
|
36
|
+
end
|
37
|
+
|
38
|
+
def _parse_response(response)
|
39
|
+
CGI.parse(response).reduce({}) do |memo, (key, value)|
|
40
|
+
if value.is_a?(Array) && value.length == 1
|
41
|
+
memo[key] = value.first
|
42
|
+
else
|
43
|
+
memo[key] = value
|
44
|
+
end
|
45
|
+
|
46
|
+
memo
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: direct_admin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Daniels
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubygems-tasks
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.2'
|
69
|
+
description: |
|
70
|
+
An unofficial (and very incomplete) API client for the DirectAdmin webhosting
|
71
|
+
control panel.
|
72
|
+
email: adam@mediadrive.ca
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- README.md
|
78
|
+
- lib/direct_admin.rb
|
79
|
+
- lib/direct_admin/client.rb
|
80
|
+
- lib/direct_admin/commands.rb
|
81
|
+
- lib/direct_admin/request.rb
|
82
|
+
- lib/direct_admin/version.rb
|
83
|
+
homepage: https://github.com/adam12/direct_admin
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.6.8
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Unofficial API for DirectAdmin
|
107
|
+
test_files: []
|