plesk_kit 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDJiNDZmZTE5NzI1MTQ3NTlhZTU2MTgxZGM2ZDA0OTg5NzdkMmRkZg==
4
+ ZDdkYzJhMjBhNGYxMmZiMWViYjM2Y2FjNTY4YWM1ODU2ZWQ5Y2YwOQ==
5
5
  data.tar.gz: !binary |-
6
- OWJkYTY2MzM1M2EwNWMxNjViZWFjZDZhOTYwMjA4MmQyY2U3N2YwMg==
6
+ ZTQzMTU3ZGJhZjUyZjRiYTAzOWJiZDNhNWEyNzY3MTc3MDczOTcxYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZWUxNTRkYjZlNTkxZTVkZjdhN2Y4MjJkOGU2YzI0NzI4M2ExOGFmMzk2MTRm
10
- NmQ0YTJlODU2ODJlM2MwMGM4ZmI4MWQ2ZThlZDY4MjE3NDEyM2UxMTQ1MjY2
11
- OWJhMGNjNDQ0ZGRiZTJkYWJmN2MxMzMwNTJkMGIxYmMyODY2ODQ=
9
+ YmY0MDM1ZjRiOWM1OTQ2MzAyYWRkMGRkMjc4OWE5MDM1ZGNjODMxOThiNGVl
10
+ ZTZmNTlhNWQwMTRmNGQ5MTM5NWI1ODZjMmUyZWUzMzNlNzRiYzIyM2JmN2Rl
11
+ ZTNhYTc0NWRjM2Q5NzY5ZGNkZWVhN2I0OGExN2FjZDk4NDVkMjQ=
12
12
  data.tar.gz: !binary |-
13
- MjNjNzMyZmFmYzQxODlhZWIzNjdjOGY5YmVlZGRjYTcwM2Y0Y2FhOGU3MmYy
14
- NGU5NjUyZTRiMjUwNjNkZDViNzExZDY2ZDgxOGI1ODE0NjkzYmIyYTkxZWFj
15
- MjgyNDI1MTBlYjRjZjI5Mzg3YjJlOGRiZmZlODc3OGI4OWM0ZjM=
13
+ ODJkNmMyMDAyYWQ0Y2U5MDg3ZjZjZTIzZGViODYyYTNjZjNiY2VhNThmOGFj
14
+ YmFjZDUzZGJkY2FhNGMwZWIzNTIwYmI3YWNhM2NlMzA1NDFkMTZiYzBhODQ4
15
+ OWU1OTA5NWUxZjJlYzhmNjhkMTgyZDE1NzZkM2E5Yzc1YjIwYWQ=
@@ -24,6 +24,13 @@ module PleskKit
24
24
  subscription.analyse response[0],customer_account
25
25
  end
26
26
 
27
+ def self.pack_and_switch_subscription subscription, new_plan_guid, plesk_sub_id
28
+ server = subscription.customer_account.server
29
+ packet = subscription.switch_pack shell, new_plan_guid, plesk_sub_id
30
+ response = transportation_for packet,server
31
+ sub.analyse response[0]
32
+ end
33
+
27
34
  def self.sync_subscription sub, sub_guid, customer_account
28
35
  server = customer_account.server
29
36
  packet = sub.sync_pack shell,sub_guid
@@ -31,6 +38,20 @@ module PleskKit
31
38
  sub.analyse response[0]
32
39
  end
33
40
 
41
+ def self.get_subscription_guid subscription
42
+ packet = subscription.id_pack shell, subscription.name
43
+ server = subscription.customer_account.server
44
+ response = transportation_for(packet,server)
45
+ subscription.analyse response[0]
46
+ end
47
+
48
+ def self.get_subscription_id subscription
49
+ packet = subscription.id_pack shell, subscription.name
50
+ server = subscription.customer_account.server
51
+ response = transportation_for(packet,server)
52
+ subscription.analyse_for_id response[0]
53
+ end
54
+
34
55
  def self.get_service_plan service_plan, server
35
56
  packet = service_plan.build_xml_for_get shell
36
57
  response = transportation_for packet, server
@@ -32,6 +32,21 @@ module PleskKit
32
32
  end
33
33
  end
34
34
 
35
+ # update the plan name attr here before switching
36
+ def switch_in_plesk
37
+ account = (customer_account_id.present? ? customer_account : (reseller_account_id.present? ? reseller_account : raise(msg="no accounts?")))
38
+ plan = PleskKit::ServicePlan.find_by_name self.plan_name
39
+ plesk_subscription_identifier = PleskKit::Communicator.get_subscription_id(self)
40
+ if plan.find_or_push(account.server) == true
41
+ #guid = PleskKit::Communicator.pack_and_play_with_subscription self, account
42
+ guid = PleskKit::Communicator.get_service_plan plan, account.server
43
+ PleskKit::Communicator.pack_and_switch_subscription(self, guid, plesk_subscription_identifier)
44
+ sub_guid = PleskKit::Communicator.get_subscription_guid(self)
45
+ PleskKit::Communicator.sync_subscription self, sub_guid, self.customer_account
46
+ true
47
+ end
48
+ end
49
+
35
50
  def pack_this shell, customer
36
51
  xml = shell
37
52
  xml.instruct!
@@ -47,7 +62,7 @@ module PleskKit
47
62
  xml.vrt_hst{
48
63
  xml.property{
49
64
  xml.name('ftp_login')
50
- xml.value("#{customer.login}#{rand(99).to_s}#{(0...2).map { (65 + rand(26)).chr }.join}") #rand(36**8).to_s(36)
65
+ xml.value("#{customer.login}#{(0...2).map { (65 + rand(26)).chr }.join}") #rand(36**8).to_s(36)
51
66
  }
52
67
  xml.property{
53
68
  xml.name('ftp_password')
@@ -64,6 +79,38 @@ module PleskKit
64
79
  return xml.target!
65
80
  end
66
81
 
82
+ def switch_pack shell, sub_guid, plesk_sub_id
83
+ xml = shell
84
+ xml.instruct!
85
+ xml.packet(:version => '1.6.3.5') {
86
+ xml.webspace{
87
+ xml.send(:"sync-subscription") {
88
+ xml.filter{
89
+ xml.id(plesk_sub_id) # TODO!!!
90
+ }
91
+ xml.tag! 'plan-guid', sub_guid
92
+ }
93
+ }
94
+ }
95
+ end
96
+
97
+ def id_pack shell, domain_name
98
+ xml = shell
99
+ xml.instruct!
100
+ xml.packet(:version => '1.6.3.5') {
101
+ xml.webspace{
102
+ xml.get{
103
+ xml.filter{
104
+ xml.name(domain_name)
105
+ }
106
+ xml.dataset{
107
+ xml.gen_info
108
+ }
109
+ }
110
+ }
111
+ }
112
+ end
113
+
67
114
  def sync_pack shell, sub_guid
68
115
  xml = shell
69
116
  xml.instruct!
@@ -91,5 +138,18 @@ module PleskKit
91
138
  return sub_guid || true # TODO save plesk_id? Probably not necessary as we have the customer login
92
139
  end
93
140
 
141
+ def analyse_for_id response_string, customer = nil
142
+ xml = REXML::Document.new(response_string)
143
+ status = xml.root.elements['//status'].text if xml.root.elements['//status'].present?
144
+ if status == "error"
145
+ code = xml.root.elements['//errcode'].text
146
+ message = xml.root.elements['//errtext'].text
147
+ raise "#{code}: #{message}"
148
+ else
149
+ sub_guid = xml.root.elements['//id'].text if xml.root.elements['//id'].present?
150
+ end
151
+ return id || true
152
+ end
153
+
94
154
  end
95
155
  end
@@ -1,3 +1,3 @@
1
1
  module PleskKit
2
- VERSION = "2.0.5"
2
+ VERSION = "2.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plesk_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dionne Saunders
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-01 00:00:00.000000000 Z
11
+ date: 2013-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails