panelbeater 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,72 @@
1
+ require "rubygems"
2
+ require "rake/gempackagetask"
3
+ require "rake/rdoctask"
4
+
5
+
6
+
7
+ task :default => :package do
8
+ puts "Don't forget to write some tests!"
9
+ end
10
+
11
+ # This builds the actual gem. For details of what all these options
12
+ # mean, and other ones you can add, check the documentation here:
13
+ #
14
+ # http://rubygems.org/read/chapter/20
15
+ #
16
+ spec = Gem::Specification.new do |s|
17
+
18
+ # Change these as appropriate
19
+ s.name = "panelbeater"
20
+ s.version = "0.1.0"
21
+ s.summary = "A gem for communicating with the cPanel and WHM API's"
22
+ s.author = "Jamie Dyer"
23
+ s.email = "jamie@kernowsoul.com"
24
+ s.homepage = "http://kernowsoul.com"
25
+
26
+ s.has_rdoc = false
27
+ # You should probably have a README of some kind. Change the filename
28
+ # as appropriate
29
+ # s.extra_rdoc_files = %w(README)
30
+ # s.rdoc_options = %w(--main README)
31
+
32
+ # Add any extra files to include in the gem (like your README)
33
+ s.files = %w() + Dir.glob("{**/*}")
34
+ s.test_files = Dir.glob('test/fixtures/*') + Dir.glob('test/*.rb') + Dir.glob('test/*.example')
35
+
36
+ s.require_paths = ["lib"]
37
+
38
+ # If you want to depend on other gems, add them here, along with any
39
+ # relevant versions
40
+ s.add_dependency("json")
41
+
42
+ # If your tests use any gems, include them here
43
+ s.add_development_dependency("shoulda")
44
+ s.add_development_dependency("fakeweb")
45
+
46
+ # If you want to publish automatically to rubyforge, you'll may need
47
+ # to tweak this, and the publishing task below too.
48
+ end
49
+
50
+ # This task actually builds the gem. We also regenerate a static
51
+ # .gemspec file, which is useful if something (i.e. GitHub) will
52
+ # be automatically building a gem for this project. If you're not
53
+ # using GitHub, edit as appropriate.
54
+ Rake::GemPackageTask.new(spec) do |pkg|
55
+ pkg.gem_spec = spec
56
+
57
+ # Generate the gemspec file for github.
58
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
59
+ File.open(file, "w") {|f| f << spec.to_ruby }
60
+ end
61
+
62
+ # Generate documentation
63
+ Rake::RDocTask.new do |rd|
64
+
65
+ rd.rdoc_files.include("lib/**/*.rb")
66
+ rd.rdoc_dir = "rdoc"
67
+ end
68
+
69
+ desc 'Clear out RDoc and generated packages'
70
+ task :clean => [:clobber_rdoc, :clobber_package] do
71
+ rm "#{spec.name}.gemspec"
72
+ end
data/Readme.markdown ADDED
@@ -0,0 +1 @@
1
+ #cPanel gem
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{cpanel-gem}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Jamie Dyer"]
9
+ s.date = %q{2010-01-29}
10
+ s.email = %q{jamie@kernowsoul.com}
11
+ s.files = ["cpanel-gem.gemspec", "lib", "lib/cpanel_api", "lib/cpanel_api/cpanel", "lib/cpanel_api/cpanel/commands.rb", "lib/cpanel_api/model.rb", "lib/cpanel_api/remote.rb", "lib/cpanel_api/response.rb", "lib/cpanel_api/whm", "lib/cpanel_api/whm/commands.rb", "lib/cpanel_api.rb", "Rakefile", "Readme.markdown", "test", "test/fixtures", "test/fixtures/applist.json", "test/fixtures/createacct_fail.json", "test/fixtures/createacct_success.json", "test/fixtures/passwd_fail.json", "test/fixtures/passwd_success.json", "test/test_helper.rb", "test/whm_test.rb", "~"]
12
+ s.homepage = %q{http://kernowsoul.com}
13
+ s.require_paths = ["lib"]
14
+ s.rubygems_version = %q{1.3.5}
15
+ s.summary = %q{A gem for communicating with cPanel}
16
+ s.test_files = ["test/fixtures/applist.json", "test/fixtures/createacct_fail.json", "test/fixtures/createacct_success.json", "test/fixtures/passwd_fail.json", "test/fixtures/passwd_success.json", "test/test_helper.rb", "test/whm_test.rb"]
17
+
18
+ if s.respond_to? :specification_version then
19
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
20
+ s.specification_version = 3
21
+
22
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
23
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
24
+ else
25
+ s.add_dependency(%q<shoulda>, [">= 0"])
26
+ end
27
+ else
28
+ s.add_dependency(%q<shoulda>, [">= 0"])
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ require 'net/https'
2
+ require 'json'
3
+ require 'uri'
4
+ require 'logger'
5
+
6
+ require 'panelbeater/remote'
7
+ require 'panelbeater/response'
8
+ require 'panelbeater/model'
9
+ require 'panelbeater/cpanel/commands'
10
+ require 'panelbeater/whm/commands'
@@ -0,0 +1,10 @@
1
+ module CpanelApi
2
+ module Cpanel
3
+ module Commands
4
+
5
+ def addsubdomain(user, subdomain, rootdomain, directory)
6
+ cpanel(user, {:xmlin => "<cpanelaction><module>SubDomain</module><func>addsubdomain</func><args><domain>#{subdomain}</domain><rootdomain>#{rootdomain}</rootdomain><dir>#{directory}</dir></args></cpanelaction>"})
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ module CpanelApi
2
+ module Model
3
+
4
+ def key_mappings(map, hash)
5
+ map.each_key do |k|
6
+ if hash.has_key? k
7
+ hash[map[k]] = hash[k]
8
+ hash.delete(k)
9
+ end
10
+ end
11
+ hash
12
+ end
13
+
14
+ def filter_options(hash)
15
+ hash.each do |k,v|
16
+ if v == true
17
+ hash[k] = 1
18
+ elsif v == false
19
+ hash[k] = 0
20
+ end
21
+ end
22
+ hash.delete_if {|k,v| v.nil? }
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ module CpanelApi
2
+ module Remote
3
+
4
+ @@default_port = 2087
5
+ @@default_user = 'root'
6
+
7
+ def set_server(options={})
8
+ self.base_url = options[:url]
9
+ self.user = options[:user] ||= @@default_user
10
+ self.api_key = options[:api_key].gsub(/\n|\r/, '')
11
+ self.port = options[:port] ||= @@default_port
12
+ end
13
+
14
+ def connect(server, port, command, username, api_key, options={})
15
+ http = Net::HTTP.new(server, port)
16
+ http.use_ssl = true
17
+ http.start do |http|
18
+ req = Net::HTTP::Get.new "/json-api/#{command}#{map_options_to_url(options)}"
19
+ req.add_field 'Authorization', "WHM #{username}:#{api_key}"
20
+ # req.each_header {|k,v| @log.info "#{k}: #{v}"}
21
+ http.request(req)
22
+ # puts response.to_yaml
23
+ # response.value
24
+ # response.body
25
+ end
26
+ end
27
+
28
+ def do_request(command, options={}, mappings=nil)
29
+ options = key_mappings(mappings, options) unless mappings.nil?
30
+ options = filter_options(options)
31
+ response = connect self.base_url, self.port, command, self.user, self.api_key, options
32
+ # if response.code == '200'
33
+ # response.json = JSON.parse(response.body)
34
+ # end
35
+ CpanelApi::Response.new(response)
36
+ end
37
+
38
+ def map_options_to_url(options={})
39
+ '?' + options.map { |k,v| "%s=%s" % [URI.encode(k.to_s), URI.encode(v.to_s)] }.join('&') unless options.nil?
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ module CpanelApi
2
+ class Response
3
+
4
+ def initialize(response)
5
+ @response = response
6
+ end
7
+
8
+ def json
9
+ JSON.parse @response.body
10
+ end
11
+
12
+ def method_missing(method, *args)
13
+ @response.send(method) if @response.respond_to?(method)
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,333 @@
1
+ module CpanelApi
2
+ module Whm
3
+ class Commands
4
+ include Model
5
+ include Remote
6
+ include Cpanel
7
+
8
+ attr_accessor :base_url
9
+ attr_accessor :user
10
+ attr_accessor :api_key
11
+ attr_accessor :port
12
+
13
+ def initialize(options={})
14
+ @log = Logger.new(STDOUT)
15
+ @log.level = Logger::INFO
16
+ set_server(options)
17
+ end
18
+
19
+ # Each WHM API command has its own method
20
+
21
+ # Get a users account summary
22
+ def accountsummary(user)
23
+ do_request 'accountsummary', {:user => user}
24
+ end
25
+
26
+
27
+ # Add a new package
28
+ #
29
+ # required params:
30
+ # name
31
+ # quota
32
+ # maxftp
33
+ # maxsql
34
+ # maxpop
35
+ # maxlists
36
+ # maxsub
37
+ # maxpark
38
+ # maxaddon
39
+ # bwlimit
40
+
41
+ def addpkg(options={}, mappings=nil)
42
+ default_options = { :featurelist => 'default',
43
+ :ip => 0,
44
+ :cgi => 1,
45
+ :frontpage => 0,
46
+ :cpmod => 'x3',
47
+ :hasshell => 0 }
48
+ all_options = default_options.merge!(options)
49
+ do_request 'addpkg', all_options, mappings
50
+ end
51
+
52
+ # Returns a list of available commands
53
+ def applist
54
+ do_request 'applist'
55
+ end
56
+
57
+ # Change a users package
58
+ def changepackage(user, package)
59
+ do_request 'changepackage', {:user => user, :pkg => package}
60
+ end
61
+
62
+ # Call cpanel API1 and API2 commands
63
+ #
64
+ # user (string)
65
+ # The name of the user that owns the cPanel account to be affected.
66
+ # xmlin (XML)
67
+ # XML container for the function. Format <cpanelaction><module><func><args></args></func></module></cpanelaction>
68
+ # module (string)
69
+ # Name of the module to access. (See http://www.cpanel.net/plugins/api2/index.html for module and function names)
70
+ # apiversion (integer)
71
+ # Version of the API to access. (1 = API1, no input defaults to API2)
72
+ # func (string)
73
+ # Name of the function to access. (See http://www.cpanel.net/plugins/api2/index.html for module and function names)
74
+ # args (XML or string)
75
+ # List of arguments or argument container. See examples for API1 and API2 passing arguments.
76
+
77
+ def cpanel(user, options={})
78
+ default_options = { :apiversion => 2 }
79
+ all_options = default_options.merge!(options).merge!(:user => user)
80
+ do_request 'cpanel', all_options
81
+ end
82
+
83
+ # Create a new account
84
+ #
85
+ # username (string)
86
+ # User name of the account. Ex: user
87
+ # domain (string)
88
+ # Domain name. Ex: domain.tld
89
+ # plan (string)
90
+ # Package to use for account creation. Ex: reseller_gold
91
+ # quota (integer)
92
+ # Disk space quota in MB. (0-999999, 0 is unlimited)
93
+ # password (string)
94
+ # Password to access cPanel. Ex: p@ss!w0rd$123
95
+ # ip (string)
96
+ # Whether or not the domain has a dedicated IP address. (y = Yes, n = No)
97
+ # cgi (string)
98
+ # Whether or not the domain has cgi access. (y = Yes, n = No)
99
+ # frontpage (string)
100
+ # Whether or not the domain has FrontPage extensions installed. (y = Yes, n = No)
101
+ # hasshell (string)
102
+ # Whether or not the domain has shell / ssh access. (y = Yes, n = No)
103
+ # contactemail (string)
104
+ # Contact email address for the account. Ex: user@otherdomain.tld
105
+ # cpmod (string)
106
+ # cPanel theme name. Ex: x3
107
+ # maxftp (string)
108
+ # Maximum number of FTP accounts the user can create. (0-999999 | unlimited, null | 0 is unlimited)
109
+ # maxsql (string)
110
+ # Maximum number of SQL databases the user can create. (0-999999 | unlimited, null | 0 is unlimited)
111
+ # maxpop (string)
112
+ # Maximum number of email accounts the user can create. (0-999999 | unlimited, null | 0 is unlimited)
113
+ # maxlst (string)
114
+ # Maximum number of mailing lists the user can create. (0-999999 | unlimited, null | 0 is unlimited)
115
+ # maxsub (string)
116
+ # Maximum number of subdomains the user can create. (0-999999 | unlimited, null | 0 is unlimited)
117
+ # maxpark (string)
118
+ # Maximum number of parked domains the user can create. (0-999999 | unlimited, null | 0 is unlimited)
119
+ # maxaddon (string)
120
+ # Maximum number of addon domains the user can create. (0-999999 | unlimited, null | 0 is unlimited)
121
+ # bwlimit (string)
122
+ # Bandiwdth limit in MB. (0-999999, 0 is unlimited)
123
+ # customip (string)
124
+ # Specific IP address for the site.
125
+ # useregns (boolean)
126
+ # Use the registered nameservers for the domain instead of the ones configured on the server. (1 = Yes, 0 = No)
127
+ # hasuseregns (boolean)
128
+ # Set to 1 if you are using the above option.
129
+ # reseller (boolean)
130
+ # Give reseller privileges to the account. (1 = Yes, 0 = No)
131
+
132
+ def createacct(options={}, mappings=nil)
133
+ default_options = { :featurelist => 'default',
134
+ :ip => 'n',
135
+ :cgi => 'y',
136
+ :frontpage => 'n',
137
+ :cpmod => 'x3',
138
+ :hasshell => 'n',
139
+ :maxlst => 0,
140
+ :reseller => 0 }
141
+ all_options = default_options.merge!(options)
142
+ do_request 'createacct', all_options, mappings
143
+ end
144
+
145
+ # Edits an existing package
146
+ #
147
+ # name (string)
148
+ # Name of the package.
149
+ # featurelist (string)
150
+ # Name of the feature list to be used for the package.
151
+ # quota (integer)
152
+ # Disk space quota for the package (in MB). (max is unlimited)
153
+ # ip (boolean)
154
+ # Whether or not the account has a dedicated IP. Yes=1, No=0.
155
+ # cgi (boolean)
156
+ # Whether or not the account has cgi access. Yes=1, No=0.
157
+ # frontpage (boolean)
158
+ # Whether or not the account can install FrontPage extensions. Yes=1, No=0.
159
+ # cpmod (string)
160
+ # What to change the default package them to. Format: cpmod=themename
161
+ # maxftp (integer)
162
+ # The maximum amount of FTP accounts a user assigned to the package can create. (max is 999)
163
+ # maxsql (integer)
164
+ # The maximum amount of SQL databases a user assigned to the package can create. (max is 999)
165
+ # maxpop (integer)
166
+ # The maximum amount of email accounts a user assigned to the package can create. (max is 999)
167
+ # maxlists (integer)
168
+ # The maximum amount of email lists a user assigned to the package can create. (max is 999)
169
+ # maxsub (integer)
170
+ # The maximum amount of subdomains a user assigned to the package can create. (max is 999)
171
+ # maxpark (integer)
172
+ # The maximum amount of parked domains a user assigned to the package can create. (max is 999)
173
+ # maxaddon (integer)
174
+ # The maximum amount of addon domains a user assigned to the package can create. (max is 999)
175
+ # hasshell (boolean)
176
+ # Whether or not the account has shell access. Yes=1, No=0.
177
+ # bwlimit (integer)
178
+
179
+ def editpkg(name, options={}, mappings=nil)
180
+ default_options = { :featurelist => 'default',
181
+ :ip => 'n',
182
+ :cgi => 'y',
183
+ :frontpage => 'n',
184
+ :cpmod => 'x3',
185
+ :hasshell => 'n',
186
+ :maxlists => '0' }
187
+ all_options = default_options.merge!(options).merge!(:name => name)
188
+ do_request 'editpkg', all_options, mappings
189
+ end
190
+
191
+ def fetchsslinfo
192
+
193
+ end
194
+
195
+ def generatessl
196
+
197
+ end
198
+
199
+ # Get the hostname of the server
200
+ def gethostname
201
+ do_request 'gethostname'
202
+ end
203
+
204
+ # List of available languages
205
+ def getlanglist
206
+ do_request 'getlanglist'
207
+ end
208
+
209
+ # Deletes a package from the server
210
+ def killpkg(package)
211
+ do_request 'killpkg', {:pkg => package}
212
+ end
213
+
214
+ # Searches for an account
215
+ #
216
+ # searchtype
217
+ # Type of account search. (domain | owner | user | ip | package )
218
+ # search
219
+ # Search criteria. (Perl Regular Expression)
220
+
221
+ def listaccts(term, options={})
222
+ default_options = {:searchtype => 'user'}
223
+ all_options = default_options.merge!(options).merge!(:search => term)
224
+ do_request 'listaccts', all_options
225
+ end
226
+
227
+ # Reseller functionality not needed yet
228
+ def listacls
229
+
230
+ end
231
+
232
+ def listcrts
233
+
234
+ end
235
+
236
+ # List packages on server
237
+ def listpkgs
238
+ do_request 'listpkgs'
239
+ end
240
+
241
+ # Reseller functionality not needed yet
242
+ def listresellers
243
+
244
+ end
245
+
246
+ # List suspended accounts
247
+ def listsuspended
248
+ do_request 'listsuspended'
249
+ end
250
+
251
+ # Get the server load average
252
+ def loadavg
253
+ do_request 'loadavg'
254
+ end
255
+
256
+ # Change and accounts password
257
+ def passwd(user, password)
258
+ do_request 'passwd', {:user => user, :pass => password}
259
+ end
260
+
261
+ # Reboot the server, don't know if this works or if it takes any arguments
262
+ def reboot
263
+ do_request 'reboot'
264
+ end
265
+
266
+ # Remore and account from the server
267
+ def removeacct(user, options={})
268
+ default_options = {:keepdns => false}
269
+ all_options = default_options.merge!(options).merge!(:user => user)
270
+ do_request 'removeacct', all_options
271
+ end
272
+
273
+ # Reseller functionality not needed yet
274
+ def resellerstats
275
+
276
+ end
277
+
278
+ # Restart a service on the server
279
+ #
280
+ # service
281
+ # Service to restart (bind | interchange | ftp | httpd | imap | cppop | exim | mysql | postgres | ssh | tomcat)
282
+
283
+ def restartservice(service)
284
+ do_request 'restartservice', :service => service
285
+ end
286
+
287
+ # Reseller functionality not needed yet
288
+ def saveacllist
289
+
290
+ end
291
+
292
+ # Reseller functionality not needed yet
293
+ def setacls
294
+
295
+ end
296
+
297
+ # Reseller functionality not needed yet
298
+ def setupreseller
299
+
300
+ end
301
+
302
+ # Get bandwidth usage for all users, don't know if this takes additional parameters
303
+ def showbw
304
+ do_request 'showbw'
305
+ end
306
+
307
+ # Suspend an account
308
+ def suspendacct(user, reason)
309
+ do_request 'suspendacct', {:user => user, :reason => reason}
310
+ end
311
+
312
+ # Reseller functionality not needed yet
313
+ def terminatereseller
314
+
315
+ end
316
+
317
+ # Reseller functionality not needed yet
318
+ def unsetupreseller
319
+
320
+ end
321
+
322
+ # Unsuspend an account
323
+ def unsuspendacct(user)
324
+ do_request 'unsuspendacct', :user => user
325
+ end
326
+
327
+ # Get the of WHM
328
+ def version
329
+ do_request 'version'
330
+ end
331
+ end
332
+ end
333
+ end
Binary file
@@ -0,0 +1 @@
1
+ {"app":["accountsummary","acctcounts","adddns","addip","addpkg","addzonerecord","applist","changepackage","configureservice","cpanel","createacct","delip","domainuserdata","dumpzone","editpkg","editquota","editzonerecord","fetchsslinfo","generatessl","gethostname","getlanglist","getresellerips","getzonerecord","installssl","killdns","killpkg","limitbw","listaccts","listacls","listcrts","listips","listpkgs","listresellers","listsuspended","listzones","loadavg","lookupnsip","modifyacct","myprivs","nvget","nvset","passwd","reboot","removeacct","removezonerecord","resellerstats","resetzone","restartservice","saveacllist","servicestatus","setacls","sethostname","setresellerips","setresellerlimits","setresellermainip","setresellernameservers","setresellerpackagelimit","setresolvers","setsiteip","setupreseller","showbw","suspendacct","suspendreseller","terminatereseller","unsetupreseller","unsuspendacct","unsuspendreseller","version"]}
@@ -0,0 +1 @@
1
+ {"result":[{"status":0,"statusmsg":"Sorry, that's an invalid domain\n","rawout":null,"options":null}]}
@@ -0,0 +1 @@
1
+ {"result":[{"status":1,"statusmsg":"Account Creation Ok","rawout":"<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Checking input data...System has 0 free ips.\n...Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>WWWAcct 12.5.0 (c) 1997-2009 cPanel, Inc....\n\nDns Zone check is enabled.\n+===================================+\n| New Account Info |\n+===================================+\n| Domain: bob.com\n| Ip: 77.72.7.154 (n)\n| HasCgi: y\n| UserName: bob\n| PassWord: FjW1tJ2dJlfRJU\n| CpanelMod: x3\n| HomeRoot: /home\n| Quota: 0 Meg\n| NameServer1: ns1.krystal.co.uk\n| NameServer2: ns2.krystal.co.uk\n| NameServer3: \n| NameServer4: \n| Contact Email: \n| Package: default\n| Feature List: default\n| Language: en\n+===================================+\n...Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Running pre creation script (/scripts/prewwwacct)......Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Adding User...Removing Shell Access (n)\n...Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Copying skel files from /root/cpanel3-skel/ to /home/bob/......Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Adding Entries to httpd.conf......Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Setting up Mail & Local Domains...localdomains...valiases ...vdomainaliases...vfilters......Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Configuring DNS......Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Restarting apache......Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\nChanging password for bob\nPassword for bob has been changed\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Updating Authentication Databases...Updating ftp passwords for bob\nFtp password files updated.\nFtp vhost passwords synced\n...Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Verifying MX Records and Setting up Databases...Reconfiguring Mail Routing:\n<ul><li>LOCAL MAIL EXCHANGER: This server will serve as a primary mail exchanger for bob.com's mail.:<br /> This configuration has been manually selected.<br /><br /></li></ul>...Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Setting up Proxy Subdomains......Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\nBind reload skipped on vps (nameserver disabled)\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Sending Account Information......Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\nSystem has 0 free ips.\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Running post creation scripts (/scripts/legacypostwwwacct, /scripts/postwwwacct, /scripts/postwwwacctuser)......Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\nwwwacct creation finished\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Setting up Domain Pointers......Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Setting Reseller Privs......Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n<table style=\"border-bottom: 1px #ccc dotted;\"><tr><td width=\"100%\"><pre>Account Creation Complete!!!...Account Creation Ok...Done</pre></td><td width=\"30\"><img align=absmiddle src=\"/cPanel_magic_revision_1264774563/cjt/images/icons/success.png\"></td></tr></table>\n","options":{"nameserver4":null,"nameserver":"ns1.krystal.co.uk","nameserverentry2":null,"nameserverentry3":null,"nameserverentry4":null,"nameserverentry":null,"ip":"77.72.7.154","nameservera2":null,"nameservera3":null,"package":"default","nameservera4":null,"nameserver2":"ns2.krystal.co.uk","nameservera":null,"nameserver3":null}}]}
@@ -0,0 +1 @@
1
+ {"passwd":[{"status":0,"services":null,"statusmsg":"Sorry, the user bob2 does not exist.","rawout":null}]}
@@ -0,0 +1 @@
1
+ {"passwd":[{"status":1,"services":[{"app":"system"},{"app":"ftp"},{"app":"mail"},{"app":"mySQL"}],"statusmsg":"Password changed for user bob","rawout":"Changing password for bob\nPassword for bob has been changed\nUpdating ftp passwords for bob\nFtp password files updated.\nFtp vhost passwords synced\n"}]}
@@ -0,0 +1,25 @@
1
+ $:.unshift File.join( File.dirname(File.dirname(__FILE__)), 'lib' )
2
+
3
+ require 'rubygems'
4
+
5
+ require 'panelbeater'
6
+
7
+ require 'test/unit'
8
+ require 'shoulda'
9
+ require 'fakeweb'
10
+
11
+ class Test::Unit::TestCase
12
+
13
+ # we don't want any connections to the outside world
14
+ FakeWeb.allow_net_connect = false
15
+
16
+ # include RR::Adapters::TestUnit
17
+
18
+ # def response(name)
19
+ # Pepper::Stanzas::Epp.parse File.read( File.join(File.dirname(__FILE__),"fixtures", "#{name}.xml") )
20
+ # end
21
+
22
+ def fixture(name)
23
+ File.read( File.join(File.dirname(__FILE__),"fixtures", "#{name}.json") )
24
+ end
25
+ end
data/test/whm_test.rb ADDED
@@ -0,0 +1,80 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require "test_helper"
3
+
4
+ class WhmTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ FakeWeb.clean_registry
8
+ @expected_url = 'https://cpanel.server.local:2087/json-api/'
9
+ @connection = CpanelApi::Whm::Commands.new({ :url => 'cpanel.server.local', :api_key => '1234' })
10
+ end
11
+
12
+
13
+ context "404 error handling" do
14
+ setup do
15
+ FakeWeb.register_uri(:get, "#{@expected_url}applist?", :body => '', :status => ["404", "Not Found"])
16
+ @response = @connection.applist
17
+ end
18
+
19
+ should "return an error status" do
20
+ assert_equal 'Not Found', @response.message
21
+ assert_equal '404', @response.code
22
+ end
23
+ end
24
+
25
+
26
+
27
+ context "getting a list of commands the server supports" do
28
+ setup do
29
+ FakeWeb.register_uri(:get, "#{@expected_url}applist?", :body => fixture('applist'))
30
+ @response = @connection.applist
31
+ end
32
+
33
+ should "return a list of commands" do
34
+ assert_equal JSON.parse(fixture('applist')), @response.json
35
+ end
36
+ end
37
+
38
+
39
+ context "creating a new account" do
40
+ setup do
41
+ FakeWeb.register_uri :get,
42
+ "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n",
43
+ :body => fixture('createacct_success')
44
+ @response = @connection.createacct :username => 'amos'
45
+ end
46
+
47
+ should "return a list of commands" do
48
+ assert_equal JSON.parse(fixture('createacct_success')), @response.json
49
+ end
50
+ end
51
+
52
+
53
+ context "creating a new account with key mappings" do
54
+ setup do
55
+ FakeWeb.register_uri :get,
56
+ "#{@expected_url}createacct?cpmod=x3&maxlst=0&hasshell=n&reseller=0&featurelist=default&ip=n&username=amos&cgi=y&frontpage=n",
57
+ :body => fixture('createacct_success')
58
+ @response = @connection.createacct({ :krazy => 'amos' }, { :krazy => :username })
59
+ end
60
+
61
+ should "return a list of commands" do
62
+ assert_equal JSON.parse(fixture('createacct_success')), @response.json
63
+ end
64
+ end
65
+
66
+
67
+ context "changing a users password" do
68
+ setup do
69
+ FakeWeb.register_uri :get,
70
+ "#{@expected_url}passwd?user=bob&pass=hello",
71
+ :body => fixture('passwd_success')
72
+ @response = @connection.passwd('bob', 'hello')
73
+ end
74
+
75
+ should "return a list of commands" do
76
+ assert_equal JSON.parse(fixture('passwd_success')), @response.json
77
+ end
78
+ end
79
+
80
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: panelbeater
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Dyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-29 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: shoulda
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: fakeweb
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description:
46
+ email: jamie@kernowsoul.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - cpanel-gem.gemspec
55
+ - lib/panelbeater/cpanel/commands.rb
56
+ - lib/panelbeater/model.rb
57
+ - lib/panelbeater/remote.rb
58
+ - lib/panelbeater/response.rb
59
+ - lib/panelbeater/whm/commands.rb
60
+ - lib/panelbeater.rb
61
+ - pkg/cpanel-gem-0.1.0.gem
62
+ - Rakefile
63
+ - Readme.markdown
64
+ - test/fixtures/applist.json
65
+ - test/fixtures/createacct_fail.json
66
+ - test/fixtures/createacct_success.json
67
+ - test/fixtures/passwd_fail.json
68
+ - test/fixtures/passwd_success.json
69
+ - test/test_helper.rb
70
+ - test/whm_test.rb
71
+ has_rdoc: true
72
+ homepage: http://kernowsoul.com
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options: []
77
+
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ version:
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.5
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: A gem for communicating with the cPanel and WHM API's
99
+ test_files:
100
+ - test/fixtures/applist.json
101
+ - test/fixtures/createacct_fail.json
102
+ - test/fixtures/createacct_success.json
103
+ - test/fixtures/passwd_fail.json
104
+ - test/fixtures/passwd_success.json
105
+ - test/test_helper.rb
106
+ - test/whm_test.rb