Module: DirectAdmin::Commands
- Included in:
- Client
- Defined in:
- lib/direct_admin/commands.rb
Instance Method Summary collapse
-
#create_login_key(name, value, options = {}) ⇒ Object
Create a login key.
-
#domain_owner(domain) ⇒ Object
Owner of domain.
-
#email_auth(email, password) ⇒ Object
Authenticate email account.
-
#verify_password(username, password) ⇒ Object
Verify the username and password of a user.
Instance Method Details
#create_login_key(name, value, options = {}) ⇒ Object
Create a login key
client.create_login_key("CLI Tool", "abcd1234")
Required Arguments
- :name
-
The name of the login key
- :value
-
The value of the login key
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/direct_admin/commands.rb', line 12 def create_login_key(name, value, = {}) never_expires = .fetch(:never_expires, false) expiration = [:expiration] allow_htm = .fetch(:allow_htm, true) allowed_commands = .fetch(:allowed_commands, []) allowed_ips = .fetch(:allowed_ips, []).join("\r\n") max_uses = .fetch(:max_uses, 1) clear_key = .fetch(:clear_key, false) params = { "keyname" => name, "key" => value, "key2" => value, "never_expires" => never_expires, "max_uses" => max_uses, "ips" => allowed_ips, "passwd" => server_password, "create" => "Create" } params["never_expires"] = "yes" if never_expires params["clear_key"] = "yes" if clear_key params["allow_htm"] = "yes" if allow_htm if !never_expires && expiration params["hour"] = expiration.hour params["minute"] = expiration.minute params["month"] = expiration.month params["day"] = expiration.day params["year"] = expiration.year end allowed_commands.each_with_index do |command, i| params["select_allow#{i}"] = command end request(:post, "/CMD_API_LOGIN_KEYS", params) end |
#domain_owner(domain) ⇒ Object
Owner of domain
client.domain_owner("domain.com")
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/direct_admin/commands.rb', line 87 def domain_owner(domain) params = { "domain" => domain } response = request(:post, "/CMD_API_DOMAIN_OWNERS", params) if response.has_key?(domain) response[domain] end end |
#email_auth(email, password) ⇒ Object
Authenticate email account. Must be logged in as domain owner for command to be successful.
client.email_auth("[email protected]", "secret")
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/direct_admin/commands.rb', line 71 def email_auth(email, password) params = { "email" => email, "passwd" => password } response = request(:post, "/CMD_API_EMAIL_AUTH", params) if response.has_key?("error") Integer(response["error"]) == 0 end end |
#verify_password(username, password) ⇒ Object
Verify the username and password of a user
client.verify_password("admin", "secret")
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/direct_admin/commands.rb', line 54 def verify_password(username, password) params = { "user" => username, "passwd" => password } response = request(:post, "/CMD_API_VERIFY_PASSWORD", params) if response.has_key?("valid") Integer(response["valid"]) == 1 end end |