Class: PleskKit::Subscription
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PleskKit::Subscription
- Defined in:
- app/models/plesk_kit/subscription.rb
Instance Method Summary collapse
- #analyse(response_string, customer = nil) ⇒ Object
- #analyse_for_id(response_string, customer = nil) ⇒ Object
- #analyse_usage(response_string) ⇒ Object
- #downgradable?(new_plan) ⇒ Boolean
- #id_pack(shell, domain_name) ⇒ Object
- #pack_this(shell, customer) ⇒ Object
-
#provision_in_plesk ⇒ Object
request should look like this: <packet version=“1.6.3.0”> <webspace> <get> <filter> <id>subscription_id.to_i</id> </filter> <gen_info> <stat/> </get> </webspace> </packet>.
-
#switch_in_plesk ⇒ Object
update the plan name attr here before switching.
- #switch_pack(shell, sub_guid, plesk_sub_id) ⇒ Object
- #sync_pack(shell, sub_guid) ⇒ Object
- #usage_pack(shell, plesk_sub_id) ⇒ Object
Instance Method Details
#analyse(response_string, customer = nil) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'app/models/plesk_kit/subscription.rb', line 193 def analyse response_string, customer = nil xml = REXML::Document.new(response_string) status = xml.root.elements['//status'].text if xml.root.elements['//status'].present? if status == "error" code = xml.root.elements['//errcode'].text = xml.root.elements['//errtext'].text raise "#{code}: #{}" else sub_guid = xml.root.elements['//guid'].text if xml.root.elements['//guid'].present? end return sub_guid || true # TODO save plesk_id? Probably not necessary as we have the customer login end |
#analyse_for_id(response_string, customer = nil) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'app/models/plesk_kit/subscription.rb', line 206 def analyse_for_id response_string, customer = nil xml = REXML::Document.new(response_string) status = xml.root.elements['//status'].text if xml.root.elements['//status'].present? sub_guid ='' if status == "error" code = xml.root.elements['//errcode'].text = xml.root.elements['//errtext'].text raise "#{code}: #{}" else sub_guid = xml.root.elements['//id'].text if xml.root.elements['//id'].present? end return sub_guid || true end |
#analyse_usage(response_string) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'app/models/plesk_kit/subscription.rb', line 220 def analyse_usage response_string xml = REXML::Document.new(response_string) status = xml.root.elements['//status'].text if xml.root.elements['//status'].present? space = '' mbox = '' if status == "error" code = xml.root.elements['//errcode'].text = xml.root.elements['//errtext'].text raise "#{code}: #{}" else space = xml.root.elements['//real_size'].text if xml.root.elements['//real_size'].present? mbox = xml.root.elements['//box'].text if xml.root.elements['//box'].present? end return [space,mbox] end |
#downgradable?(new_plan) ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/plesk_kit/subscription.rb', line 49 def downgradable?(new_plan) account = (customer_account_id.present? ? customer_account : (reseller_account_id.present? ? reseller_account : raise(msg="no accounts?"))) mbox_limit = new_plan.mailboxes space_limit = new_plan.storage #this value is already bytes space_limit = 10000000000000000000000000 if space_limit == '-1' mbox_limit = 10000000000000000000000000 if mbox_limit == '-1' plesk_subscription_identifier = PleskKit::Communicator.get_subscription_id(self) usage = PleskKit::Communicator.get_subscription_usage(self,plesk_subscription_identifier, account.server) puts usage[0],usage[1] usage[0] = 10000000000000000000000000 if usage[0] == '-1' usage[1] = 10000000000000000000000000 if usage[1] == '-1' if usage[0].to_i < space_limit.to_i && usage[1].to_i < mbox_limit.to_i true else false end end |
#id_pack(shell, domain_name) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/models/plesk_kit/subscription.rb', line 162 def id_pack shell, domain_name xml = shell xml.instruct! xml.packet(:version => '1.6.3.5') { xml.webspace{ xml.get{ xml.filter{ xml.name(domain_name) } xml.dataset{ xml.gen_info } } } } end |
#pack_this(shell, customer) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/models/plesk_kit/subscription.rb', line 112 def pack_this shell, customer digits = customer.login.to_s.split('') xx = '' digits.each {|d|xx << (d.to_i + 65).chr} xml = shell xml.instruct! xml.packet(:version => '1.6.3.5') { xml.webspace { xml.add{ xml.gen_setup{ xml.name(self.name) xml.tag! 'owner-login', self.owner_login xml.ip_address(self.ip_address) } xml.hosting{ xml.vrt_hst{ xml.property{ xml.name('ftp_login') xml.value(xx.downcase) #rand(36**8).to_s(36) } xml.property{ xml.name('ftp_password') xml.value(customer.passwd) } xml.ip_address(self.ip_address) } } xml.tag! 'plan-name', self.plan_name } } } puts xml.target! return xml.target! end |
#provision_in_plesk ⇒ Object
request should look like this: <packet version=“1.6.3.0”>
<webspace>
<get>
<filter>
<id>subscription_id.to_i</id>
</filter>
<gen_info>
<stat/>
</get>
</webspace>
</packet>
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/plesk_kit/subscription.rb', line 27 def provision_in_plesk account = (customer_account_id.present? ? customer_account : (reseller_account_id.present? ? reseller_account : raise(msg="no accounts?"))) plan = PleskKit::ServicePlan.find_by_name self.plan_name self.service_plan_id = plan.id if plan.find_or_push(account.server).present? self.plan_name = self.plan_name self.ip_address = account.server.ip_address self.owner_login = account.login self.name = self.name if account.class.to_s == 'PleskKit::ResellerAccount' self.reseller_account_id = account.id elsif account.class.to_s == 'PleskKit::CustomerAccount' self.customer_account_id = account.id end guid = PleskKit::Communicator.pack_and_play_with_subscription self, account PleskKit::Communicator.sync_subscription self, guid, account self.id else return false end end |
#switch_in_plesk ⇒ Object
update the plan name attr here before switching
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/models/plesk_kit/subscription.rb', line 87 def switch_in_plesk account = (customer_account_id.present? ? customer_account : (reseller_account_id.present? ? reseller_account : raise(msg="no accounts?"))) plan = PleskKit::ServicePlan.find_by_name self.plan_name puts "|=|plan = PleskKit::ServicePlan.find_by_name self.plan_name ||| #{plan.inspect}" puts plan puts plan_name puts '_-_-_' plesk_subscription_identifier = PleskKit::Communicator.get_subscription_id(self) puts "plesk_subscription_identifier #{plesk_subscription_identifier}" if plan.find_or_push(account.server).present? #guid = PleskKit::Communicator.pack_and_play_with_subscription self, account guid = PleskKit::Communicator.get_service_plan plan, account.server puts "|=| THE GUID IS #{guid}" puts "|=| about to start the switch cmd" PleskKit::Communicator.pack_and_switch_subscription(self, guid, plesk_subscription_identifier) puts "|=| about to start the get_subscription_guid cmd" sub_guid = PleskKit::Communicator.get_subscription_guid(self) puts "|=| about to sync up" PleskKit::Communicator.sync_subscription self, sub_guid, self.customer_account true else puts "could not find or push?" end end |
#switch_pack(shell, sub_guid, plesk_sub_id) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/models/plesk_kit/subscription.rb', line 147 def switch_pack shell, sub_guid, plesk_sub_id xml = shell xml.instruct! xml.packet(:version => '1.6.3.5') { xml.webspace{ xml.tag!("switch-subscription") { xml.filter{ xml.id(plesk_sub_id) # TODO!!! } xml.tag! 'plan-guid', sub_guid } } } end |
#sync_pack(shell, sub_guid) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'app/models/plesk_kit/subscription.rb', line 179 def sync_pack shell, sub_guid xml = shell xml.instruct! xml.packet(:version => '1.6.3.5') { xml.webspace{ xml.tag!("sync-subscription") { xml.filter{ xml.guid(sub_guid) } } } } end |
#usage_pack(shell, plesk_sub_id) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/plesk_kit/subscription.rb', line 68 def usage_pack shell, plesk_sub_id xml = shell xml.instruct! xml.packet(:version => '1.6.3.0') { xml.webspace{ xml.get { xml.filter{ xml.id(plesk_sub_id) # TODO!!! } xml.dataset { xml.gen_info xml.stat } } } } end |