plesk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/Guardfile +14 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +3 -0
- data/VERSION +1 -0
- data/bin/template +13 -0
- data/lib/plesk.rb +132 -0
- data/lib/plesk/version.rb +4 -0
- data/plesk.gemspec +18 -0
- data/spec/config.yml.example +4 -0
- data/spec/plesk_spec.rb +58 -0
- data/spec/spec_helper.rb +2 -0
- metadata +80 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'bundler' do
|
5
|
+
watch('Gemfile')
|
6
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
7
|
+
# watch(/^.+\.gemspec/)
|
8
|
+
end
|
9
|
+
|
10
|
+
guard 'rspec', :version => 2 do
|
11
|
+
watch(%r{^spec/.+_spec\.rb$})
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
13
|
+
watch('spec/spec_helper.rb') { "spec/" }
|
14
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Martin Schneider
|
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,29 @@
|
|
1
|
+
# Plesk.rb - Control Plesk with Ruby
|
2
|
+
|
3
|
+
This Project is an attempt at getting a usable Plesk interface for use in Ruby and/or Rails.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'plesk.rb'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install plesk.rb
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/template
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# for 1.8.7 compat
|
3
|
+
unless File.respond_to? :realpath
|
4
|
+
class File #:nodoc:
|
5
|
+
def self.realpath path
|
6
|
+
return realpath(File.readlink(path)) if symlink?(path)
|
7
|
+
path
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
|
12
|
+
|
13
|
+
# require 'module' here
|
data/lib/plesk.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require "net/https"
|
2
|
+
require "nokogiri"
|
3
|
+
module Plesk
|
4
|
+
class Client
|
5
|
+
attr_accessor :response, :uri,:http
|
6
|
+
def initialize path, user, password
|
7
|
+
@response = 0
|
8
|
+
@uri = URI(path)
|
9
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
10
|
+
http.use_ssl = true
|
11
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
12
|
+
@headers = {
|
13
|
+
'HTTP_AUTH_LOGIN' => user,
|
14
|
+
'HTTP_AUTH_PASSWD' => password,
|
15
|
+
'Accept' => '*/*',
|
16
|
+
'Content-Type' => 'text/xml',
|
17
|
+
}
|
18
|
+
@http = http
|
19
|
+
end
|
20
|
+
def get_domain_info
|
21
|
+
packet = PleskPacket.new
|
22
|
+
packet.domain_info
|
23
|
+
start_request packet.to_xml
|
24
|
+
end
|
25
|
+
def get_domain_id_for domain
|
26
|
+
packet = PleskPacket.new
|
27
|
+
packet.domain_info_for_domain domain
|
28
|
+
answer = start_request packet.to_xml
|
29
|
+
Nokogiri::XML(answer.body).at('id').text
|
30
|
+
end
|
31
|
+
def get_mailgroup_info_for mail
|
32
|
+
name,domain = mail.split("@")
|
33
|
+
domain_id = get_domain_id_for domain
|
34
|
+
packet = PleskPacket.new
|
35
|
+
packet.mailgroup_info name,domain_id
|
36
|
+
answer = start_request packet.to_xml
|
37
|
+
|
38
|
+
Nokogiri::XML(answer.body).search('address').map(&:text)
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_mailgroup_for mail,mails
|
42
|
+
name,domain = mail.split("@")
|
43
|
+
domain_id = get_domain_id_for domain
|
44
|
+
packet = PleskPacket.new
|
45
|
+
packet.mailgroup_set name,domain_id,mails
|
46
|
+
answer = start_request packet.to_xml
|
47
|
+
end
|
48
|
+
|
49
|
+
def start_request(body)
|
50
|
+
response = http.request_post(@uri.path,body,@headers)
|
51
|
+
@response = response
|
52
|
+
end
|
53
|
+
end
|
54
|
+
class PleskPacket
|
55
|
+
attr_accessor :content
|
56
|
+
def initialize version="1.4.1.2"
|
57
|
+
@content = Nokogiri::XML::Builder.new do |xml|
|
58
|
+
xml.packet(version: version)
|
59
|
+
end.doc
|
60
|
+
end
|
61
|
+
def domain_info
|
62
|
+
doc = @content
|
63
|
+
Nokogiri::XML::Builder.with(doc.at('packet')) do |xml|
|
64
|
+
xml.domain {
|
65
|
+
xml.get {
|
66
|
+
xml.filter
|
67
|
+
xml.dataset {
|
68
|
+
xml.limits
|
69
|
+
xml.prefs
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
end
|
74
|
+
end
|
75
|
+
def domain_info_for_domain domain
|
76
|
+
doc = @content
|
77
|
+
@content=Nokogiri::XML::Builder.with(doc.at('packet')) do |xml|
|
78
|
+
xml.domain {
|
79
|
+
xml.get {
|
80
|
+
xml.filter {
|
81
|
+
xml.domain_name domain
|
82
|
+
}
|
83
|
+
xml.dataset {
|
84
|
+
xml.limits
|
85
|
+
xml.prefs
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
def mailgroup_info name,id
|
92
|
+
doc = @content
|
93
|
+
@content =Nokogiri::XML::Builder.with(doc.at('packet')) do |xml|
|
94
|
+
xml.mail {
|
95
|
+
xml.get_info {
|
96
|
+
xml.filter {
|
97
|
+
xml.name name
|
98
|
+
xml.domain_id id
|
99
|
+
}
|
100
|
+
xml.group
|
101
|
+
}
|
102
|
+
}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
def mailgroup_set name,id,mails
|
106
|
+
doc = @content
|
107
|
+
@content =Nokogiri::XML::Builder.with(doc.at('packet')) do |xml|
|
108
|
+
xml.mail {
|
109
|
+
xml.update {
|
110
|
+
xml.set {
|
111
|
+
xml.filter {
|
112
|
+
xml.domain_id id
|
113
|
+
xml.mailname {
|
114
|
+
xml.name name
|
115
|
+
xml.mailgroup {
|
116
|
+
xml.enabled :true
|
117
|
+
mails.each do |mail|
|
118
|
+
xml.address mail
|
119
|
+
end
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
def to_xml
|
129
|
+
@content.to_xml
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
data/plesk.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/plesk/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Martin Schneider"]
|
6
|
+
gem.email = ["info@outsmartin.de"]
|
7
|
+
gem.description = %q{Plesk RPC API wrapper written in Ruby }
|
8
|
+
gem.summary = %q{You can communicate with your Plesk System through the RPC API. Sends XML and recieves XML for your pleasure.}
|
9
|
+
gem.homepage = "http://github.com/outsmartin/plesk"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "plesk"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.add_dependency 'nokogiri'
|
17
|
+
gem.version = Plesk::VERSION
|
18
|
+
end
|
data/spec/plesk_spec.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "yaml"
|
3
|
+
include Plesk
|
4
|
+
describe "Plesk" do
|
5
|
+
let(:api) {
|
6
|
+
config = YAML.load( File.open "spec/config.yml")
|
7
|
+
path = config["path"]
|
8
|
+
user = config["user"]
|
9
|
+
pass = config["password"]
|
10
|
+
Client.new(path,user,pass)
|
11
|
+
}
|
12
|
+
|
13
|
+
it "should connect to the Plesk RPC" do
|
14
|
+
api.start_request("bla")
|
15
|
+
api.response.code.should == "200"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be able to get basic domain list" do
|
19
|
+
api.get_domain_info
|
20
|
+
api.response.code.should == "200"
|
21
|
+
end
|
22
|
+
it "should be able to find domain id by name" do
|
23
|
+
id = api.get_domain_id_for "itsax.de"
|
24
|
+
id.should be_kind_of String
|
25
|
+
|
26
|
+
end
|
27
|
+
it "should get a mailgroup list for a mail" do
|
28
|
+
mails = api.get_mailgroup_info_for "developer@pludoni.de"
|
29
|
+
mails.should be_kind_of Array
|
30
|
+
end
|
31
|
+
it "should set mailgroup for a mail" do
|
32
|
+
mails_to_set = ["stefan.wienert@pludoni.de","akos.toth@pludoni.de","martin.schneider@pludoni.de"]
|
33
|
+
answer = api.set_mailgroup_for "developer@pludoni.de", mails_to_set
|
34
|
+
Nokogiri::XML(answer.response.body).at('status').text.should == "ok"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe PleskPacket do
|
39
|
+
it "should generate xml" do
|
40
|
+
p = PleskPacket.new
|
41
|
+
Nokogiri::XML(p.to_xml).errors.should be_empty
|
42
|
+
end
|
43
|
+
it "should have a packet version matching the param" do
|
44
|
+
ver = "1.0.0.0"
|
45
|
+
p = PleskPacket.new(ver)
|
46
|
+
Nokogiri::XML(p.to_xml).at('packet').attr('version').should == ver
|
47
|
+
end
|
48
|
+
it "should create a packet to get a domain list" do
|
49
|
+
p = PleskPacket.new("1.4.1.2")
|
50
|
+
p.domain_info
|
51
|
+
Nokogiri::XML(p.to_xml).at('get').children.count.should > 0
|
52
|
+
end
|
53
|
+
it "should create a packet to get the mailgroup of a mail adress" do
|
54
|
+
p = PleskPacket.new("1.6.0.2")
|
55
|
+
p.mailgroup_info "developer","1"
|
56
|
+
Nokogiri::XML(p.to_xml).at('get_info').children.count.should > 0
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: plesk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Martin Schneider
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: ! 'Plesk RPC API wrapper written in Ruby '
|
31
|
+
email:
|
32
|
+
- info@outsmartin.de
|
33
|
+
executables:
|
34
|
+
- template
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- Guardfile
|
41
|
+
- LICENSE
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- VERSION
|
45
|
+
- bin/template
|
46
|
+
- lib/plesk.rb
|
47
|
+
- lib/plesk/version.rb
|
48
|
+
- plesk.gemspec
|
49
|
+
- spec/config.yml.example
|
50
|
+
- spec/plesk_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
homepage: http://github.com/outsmartin/plesk
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.24
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: You can communicate with your Plesk System through the RPC API. Sends XML
|
76
|
+
and recieves XML for your pleasure.
|
77
|
+
test_files:
|
78
|
+
- spec/config.yml.example
|
79
|
+
- spec/plesk_spec.rb
|
80
|
+
- spec/spec_helper.rb
|