vestacp2 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 92cd396e93a1c6f3a0089b3fb5c58b2cda3270b4
4
+ data.tar.gz: 7a997be78bb56354a90c5dc8b6047506eb9ffce6
5
+ SHA512:
6
+ metadata.gz: e6a4923ee4569a09fc316d4fb640ba3f82636a4eb0a56c48eaf0d80e7af3abfc7a06eb0f39e8a681466d96b9c4b05dbc4027d98175393e6f70fbf7b97c145318
7
+ data.tar.gz: ff3e4816308f51674e6c133b005671a2587378058d8072ffdd43a52204c404aa2b6e202cf0c2fb9a6028fb09ac19769ef69c22db26ce270404babe0e15296286
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .history/
16
+ Untitled-1.http
17
+ test.rb
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vestacp.gemspec
4
+ gemspec
5
+
6
+ gem 'faraday'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Dmitry K.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # Vestacp
2
+
3
+ VestaCP API bindings on ruby. For now, only with user accounts, but that's simple — to make it work with another api functions.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'vestacp2'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install vestacp2
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ Vestacp::Account.information({username: 'admin'})
25
+ ```
26
+
27
+ will return
28
+ ```ruby
29
+ {:error=>false,
30
+ :response=>
31
+ {"admin"=>
32
+ {"FNAME"=>"System",
33
+ "LNAME"=>"Administrator",
34
+ "PACKAGE"=>"default",
35
+ "WEB_TEMPLATE"=>"default",
36
+ "BACKEND_TEMPLATE"=>"",
37
+ "PROXY_TEMPLATE"=>"default",
38
+ "DNS_TEMPLATE"=>"default",
39
+ "WEB_DOMAINS"=>"100",
40
+ "WEB_ALIASES"=>"100",
41
+ "DNS_DOMAINS"=>"100",
42
+ "DNS_RECORDS"=>"100",
43
+ "MAIL_DOMAINS"=>"100",
44
+ "MAIL_ACCOUNTS"=>"100",
45
+ "DATABASES"=>"100",
46
+ "CRON_JOBS"=>"100",
47
+ "DISK_QUOTA"=>"10000",
48
+ "BANDWIDTH"=>"100000",
49
+ "NS"=>"ns1.localhost.ltd, ns2.localhost.ltd",
50
+ "SHELL"=>"bash",
51
+ "BACKUPS"=>"3",
52
+ "CONTACT"=>"a@kdas.me",
53
+ "CRON_REPORTS"=>"yes",
54
+ "RKEY"=>"YTTyCNpySz",
55
+ "SUSPENDED"=>"no",
56
+ "SUSPENDED_USERS"=>"0",
57
+ "SUSPENDED_WEB"=>"0",
58
+ "SUSPENDED_DNS"=>"0",
59
+ "SUSPENDED_MAIL"=>"0",
60
+ "SUSPENDED_DB"=>"0",
61
+ "SUSPENDED_CRON"=>"0",
62
+ "IP_AVAIL"=>"1",
63
+ "IP_OWNED"=>"1",
64
+ "U_USERS"=>"1",
65
+ "U_DISK"=>"0",
66
+ "U_DISK_DIRS"=>"0",
67
+ "U_DISK_WEB"=>"0",
68
+ "U_DISK_MAIL"=>"0",
69
+ "U_DISK_DB"=>"0",
70
+ "U_BANDWIDTH"=>"0",
71
+ "U_WEB_DOMAINS"=>"1",
72
+ "U_WEB_SSL"=>"0",
73
+ "U_WEB_ALIASES"=>"1",
74
+ "U_DNS_DOMAINS"=>"1",
75
+ "U_DNS_RECORDS"=>"11",
76
+ "U_MAIL_DOMAINS"=>"1",
77
+ "U_MAIL_DKIM"=>"0",
78
+ "U_MAIL_ACCOUNTS"=>"0",
79
+ "U_DATABASES"=>"1",
80
+ "U_CRON_JOBS"=>"7",
81
+ "U_BACKUPS"=>"0",
82
+ "LANGUAGE"=>"en",
83
+ "HOME"=>"/home/admin",
84
+ "TIME"=>"06:03:09",
85
+ "DATE"=>"2015-07-18"}}}
86
+ ```
87
+
88
+ etc..
89
+
90
+ ## Contributing
91
+
92
+ 1. Fork it ( https://github.com/okdas/vestacp/fork )
93
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
94
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
95
+ 4. Push to the branch (`git push origin my-new-feature`)
96
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/vestacp.rb ADDED
@@ -0,0 +1,30 @@
1
+ require "vestacp/version"
2
+
3
+ module Vestacp
4
+ autoload :Config, "vestacp/config"
5
+ autoload :Base, "vestacp/base"
6
+ autoload :Database, "vestacp/database"
7
+ autoload :Account, "vestacp/account"
8
+ autoload :Domain, "vestacp/domain"
9
+
10
+ class << self
11
+ attr_accessor :config
12
+ end
13
+
14
+ self.config ||= Config.new
15
+
16
+ # Pass a block to configure the Vestacp API
17
+ #
18
+ # Vestacp.configure do |config|
19
+ # config.api_username = 'admin'
20
+ # config.api_password = 'n0passw0rd'
21
+ # config.api_url = 'https://example.com:8083/api/'
22
+ # end
23
+
24
+ def self.configure
25
+ yield config
26
+ config
27
+ end
28
+ end
29
+
30
+
@@ -0,0 +1,116 @@
1
+ module Vestacp
2
+ # Vestacp::Account is the class for managing clients
3
+ class Account < Base
4
+
5
+ # Create User Account
6
+ #
7
+ # Parameters:
8
+ #
9
+ # * <tt>:username</tt>
10
+ # * <tt>:password</tt>
11
+ # * <tt>:email</tt>
12
+ # * <tt>:package</tt>
13
+ # * <tt>:first_name</tt>
14
+ # * <tt>:last_name</tt>
15
+ #
16
+ # See:
17
+ #
18
+ # http://vestacp.com/docs/api/#add_user
19
+ def self.add(raw = {})
20
+ args = {
21
+ username: 'arg1',
22
+ password: 'arg2',
23
+ email: 'arg3',
24
+ package: 'arg4',
25
+ first_name: 'arg5',
26
+ last_name: 'arg6'
27
+ }
28
+ params = {}
29
+ raw.each {|key, value| params[args[key].to_sym] = value }
30
+ params.merge!(cmd: 'v-add-user')
31
+ send_request(params, raw)
32
+ end
33
+
34
+ # Delete User Account
35
+ #
36
+ # Parameters:
37
+ #
38
+ # * <tt>:username</tt>
39
+ def self.delete(raw = {})
40
+ args = {
41
+ username: 'arg1'
42
+ }
43
+ params = {}
44
+ raw.each {|key, value| params[args[key].to_sym] = value }
45
+ params.merge!(cmd: 'v-delete-user')
46
+ send_request(params, raw)
47
+ end
48
+
49
+
50
+ # Suspend User Account
51
+ #
52
+ # Parameters:
53
+ #
54
+ # * <tt>:username</tt>
55
+ def self.suspend(raw = {})
56
+ args = {
57
+ username: 'arg1'
58
+ }
59
+ params = {}
60
+ raw.each {|key, value| params[args[key].to_sym] = value }
61
+ params.merge!(cmd: 'v-suspend-user')
62
+ send_request(params, raw)
63
+ end
64
+
65
+
66
+ # Suspend User Account
67
+ #
68
+ # Parameters:
69
+ #
70
+ # * <tt>:username</tt>
71
+ def self.unsuspend(raw = {})
72
+ args = {
73
+ username: 'arg1'
74
+ }
75
+ params = {}
76
+ raw.each {|key, value| params[args[key].to_sym] = value }
77
+ params.merge!(cmd: 'v-unsuspend-user')
78
+ send_request(params, raw)
79
+ end
80
+
81
+
82
+ # List User Account Information
83
+ #
84
+ # Returns JSON.
85
+ #
86
+ # Parameters:
87
+ #
88
+ # * <tt>:username</tt>
89
+ def self.information(raw = {})
90
+ args = {
91
+ username: 'arg1'
92
+ }
93
+ params = {}
94
+ raw.each {|key, value| params[args[key].to_sym] = value }
95
+ params.merge!(cmd: 'v-list-user', arg2: 'json')
96
+ send_request(params, raw, true)
97
+ end
98
+
99
+ # Check User Account Credentials
100
+ #
101
+ # Parameters:
102
+ #
103
+ # * <tt>:username</tt>
104
+ # * <tt>:password</tt>
105
+ def self.check_credentials(raw = {})
106
+ args = {
107
+ username: 'arg1',
108
+ password: 'arg2'
109
+ }
110
+ params = {}
111
+ raw.each {|key, value| params[args[key].to_sym] = value }
112
+ params.merge!(cmd: 'v-list-user')
113
+ send_request(params, raw)
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,95 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Vestacp
5
+ # Vestacp::Base is the main class used to subclass Vestacp API resources
6
+ class Base
7
+
8
+ # Sends an API request to the Vestacp API
9
+ #
10
+ # Parameters:
11
+ # * <tt>:cmd</tt> - The API action to perform
12
+ #
13
+ # All other paramters are passed along as HTTP POST variables
14
+ def self.send_request(params = {}, raw = {}, json_response = false)
15
+ if params[:cmd].nil? || params[:cmd].empty?
16
+ raise "No API command set"
17
+ end
18
+
19
+ if !raw[:server]
20
+ raise "No server as argument and server configuration!" unless Vestacp.config
21
+ raw[:server] = {
22
+ api_username: Vestacp.config.api_username,
23
+ api_password: Vestacp.config.api_password,
24
+ api_url: Vestacp.config.api_url
25
+ }
26
+ end
27
+
28
+ params.merge!(
29
+ user: raw[:server][:api_username],
30
+ password: raw[:server][:api_password]
31
+ )
32
+
33
+ # params.merge!(returncode: 'yes') unless params[:returncode]
34
+
35
+ url = URI.parse(raw[:server][:api_url])
36
+
37
+ # SSL without is really bad design. In order to support even self-signed
38
+ # certificates I should do that.
39
+ conn = Faraday.new(:url => url, ssl: { verify: false }) do |faraday|
40
+ faraday.request :url_encoded # form-encode POST params
41
+ faraday.response :logger # log requests to STDOUT
42
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
43
+ end
44
+
45
+ response = conn.post do |req|
46
+ req.body = params
47
+ end
48
+
49
+ parse_response(json_response ? JSON.parse(response.body) : response.body)
50
+ end
51
+
52
+ # Parse VestaCP responses.
53
+ # TODO: add more responses.
54
+ #
55
+ # See: http://vestacp.com/docs/api/#return_codes
56
+ def self.parse_response(raw, json_response = false)
57
+ case raw
58
+ when 'OK'
59
+ {error: false, response: raw}
60
+ when /^Error/
61
+ {error: true, response: raw}
62
+ else
63
+ {error: false, response: raw}
64
+ end
65
+
66
+ # case raw
67
+ # when '0'
68
+ # {
69
+ # error: false, value: raw, name: 'OK',
70
+ # comment: 'Command has been successfuly performed.'
71
+ # }
72
+ # when '1'
73
+ # {
74
+ # error: true, value: raw, name: 'E_ARGS',
75
+ # comment: 'Not enough arguments provided.'
76
+ # }
77
+ # when '2'
78
+ # {
79
+ # error: true, value: raw, name: 'E_INVALID',
80
+ # comment: 'Object or argument is not valid.'
81
+ # }
82
+ # when '3'
83
+ # {
84
+ # error: true, value: raw, name: 'E_NOTEXIST',
85
+ # comment: "Object doesn't exist."
86
+ # }
87
+ # else
88
+ # {
89
+ # error: true, value: '-1', name: 'E_UNKNOWN',
90
+ # comment: "Unknown response: #{raw}"
91
+ # }
92
+ # end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,20 @@
1
+ module Vestacp
2
+ # Vestacp::Config stores configuration data for connecting to the Vestacp API
3
+ class Config
4
+ # The Vestacp API username
5
+ attr_accessor :api_username
6
+
7
+ # The Vestacp API password
8
+ attr_accessor :api_password
9
+
10
+ # The Vestacp API URL
11
+ attr_accessor :api_url
12
+
13
+ # Create a new config object
14
+ def initialize
15
+ @api_username = 'example_user'
16
+ @api_password = 'example_pass'
17
+ @api_url = 'https://example.com:8083/api/'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,38 @@
1
+ module Vestacp
2
+ # Vestacp::Database is the class for clients domain
3
+ class Database < Base
4
+ def self.add(raw = {})
5
+ args = {
6
+ username: 'arg1',
7
+ db_name: 'arg2',
8
+ db_user: 'arg3',
9
+ db_pass: 'arg4'
10
+ }
11
+ params = {}
12
+ raw.each {|key, value| params[args[key].to_sym] = value }
13
+ params.merge!(cmd: 'v-add-database')
14
+ send_request(params, raw)
15
+ end
16
+
17
+ # Delete User Databaase
18
+ #
19
+ # Parameters:
20
+ #
21
+ # * <tt>:username</tt>
22
+ # * <tt>:db_name</tt>
23
+ # * <tt>:db_name</tt>
24
+ # * <tt>:db_pass</tt>
25
+ def self.delete(raw = {})
26
+ args = {
27
+ username: 'arg1',
28
+ db_name: 'arg2',
29
+ db_user: 'arg3',
30
+ db_pass: 'arg4'
31
+ }
32
+ params = {}
33
+ raw.each {|key, value| params[args[key].to_sym] = value }
34
+ params.merge!(cmd: 'v-delete-database')
35
+ send_request(params, raw)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,46 @@
1
+ module Vestacp
2
+ # Vestacp::Domain is the class for clients domain
3
+ class Domain < Base
4
+
5
+ # Create User Account
6
+ #
7
+ # Parameters:
8
+ #
9
+ # * <tt>:username</tt>
10
+ # * <tt>:password</tt>
11
+ # * <tt>:email</tt>
12
+ # * <tt>:package</tt>
13
+ # * <tt>:first_name</tt>
14
+ # * <tt>:last_name</tt>
15
+ #
16
+ # See:
17
+ #
18
+ # http://vestacp.com/docs/api/#add_user
19
+ def self.add(raw = {})
20
+ args = {
21
+ username: 'arg1',
22
+ domain: 'arg2'
23
+ }
24
+ params = {}
25
+ raw.each {|key, value| params[args[key].to_sym] = value }
26
+ params.merge!(cmd: 'v-add-domain')
27
+ send_request(params, raw)
28
+ end
29
+
30
+ # Delete User Domain
31
+ #
32
+ # Parameters:
33
+ #
34
+ # * <tt>:username</tt>
35
+ def self.delete(raw = {})
36
+ args = {
37
+ username: 'arg1',
38
+ domain: 'arg2'
39
+ }
40
+ params = {}
41
+ raw.each {|key, value| params[args[key].to_sym] = value }
42
+ params.merge!(cmd: 'v-delete-domain')
43
+ send_request(params, raw)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Vestacp
2
+ VERSION = "0.1.3"
3
+ end
data/vestacp.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vestacp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vestacp2"
8
+ spec.version = Vestacp::VERSION
9
+ spec.authors = ["Umut ADALI","Dmitry Knyazev"]
10
+ spec.email = ["kobeumut@gmail.com"]
11
+ spec.summary = %q{VestaCP API bindings}
12
+ spec.description = %q{Developed and tested on version 0.9.8-14. Only to do simple things with user accounts. That's not a problem to make them more complicated :)}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ # if spec.respond_to?(:metadata)
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
+ # else
19
+ # raise "RubyGems 2.0 or newer is required to protect against " \
20
+ # "public gem pushes."
21
+ # end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+
31
+ spec.add_runtime_dependency "faraday", "~> 0.13.1"
32
+
33
+ spec.add_development_dependency 'bundler', '~> 1.15', '>= 1.15.4'
34
+ spec.add_development_dependency 'rake', '~> 12.2', '>= 12.2.1'
35
+ end
Binary file
Binary file
data/vestacp2-0.1.gem ADDED
Binary file
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vestacp2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Umut ADALI
8
+ - Dmitry Knyazev
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-10-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.13.1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.13.1
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.15'
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: 1.15.4
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - "~>"
43
+ - !ruby/object:Gem::Version
44
+ version: '1.15'
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.15.4
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.2'
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 12.2.1
58
+ type: :development
59
+ prerelease: false
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - "~>"
63
+ - !ruby/object:Gem::Version
64
+ version: '12.2'
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 12.2.1
68
+ description: Developed and tested on version 0.9.8-14. Only to do simple things with
69
+ user accounts. That's not a problem to make them more complicated :)
70
+ email:
71
+ - kobeumut@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/vestacp.rb
82
+ - lib/vestacp/account.rb
83
+ - lib/vestacp/base.rb
84
+ - lib/vestacp/config.rb
85
+ - lib/vestacp/database.rb
86
+ - lib/vestacp/domain.rb
87
+ - lib/vestacp/version.rb
88
+ - vestacp.gemspec
89
+ - vestacp2-0.1.1.gem
90
+ - vestacp2-0.1.2.gem
91
+ - vestacp2-0.1.gem
92
+ homepage: ''
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.5.1
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: VestaCP API bindings
116
+ test_files: []