@@ -45,11 +45,6 @@ public function manageAddRow(array &$vars)
4545 $ this ->view ->base_uri = $ this ->base_uri ;
4646 $ this ->view ->setDefaultView ('components ' . DS . 'modules ' . DS . 'upcloud ' . DS );
4747 Loader::loadHelpers ($ this , ['Form ' , 'Html ' , 'Widget ' ]);
48- if (!empty ($ vars )) {
49- if (empty ($ vars ['use_ssl ' ])) {
50- $ vars ['use_ssl ' ] = 'false ' ;
51- }
52- }
5348 $ this ->view ->set ('vars ' , (object ) $ vars );
5449 return $ this ->view ->fetch ();
5550 }
@@ -69,10 +64,6 @@ public function manageEditRow($module_row, array &$vars)
6964 Loader::loadHelpers ($ this , ['Form ' , 'Html ' , 'Widget ' ]);
7065 if (empty ($ vars )) {
7166 $ vars = $ module_row ->meta ;
72- } else {
73- if (empty ($ vars ['use_ssl ' ])) {
74- $ vars ['use_ssl ' ] = 'false ' ;
75- }
7667 }
7768 $ this ->view ->set ('vars ' , (object ) $ vars );
7869 return $ this ->view ->fetch ();
@@ -88,7 +79,7 @@ public function manageEditRow($module_row, array &$vars)
8879 */
8980 public function addModuleRow (array &$ vars )
9081 {
91- $ meta_fields = ['account_name ' , 'api_token ' ];
82+ $ meta_fields = ['account_name ' , 'api_token ' , ' api_base_url ' ];
9283 $ encrypted_fields = ['api_token ' ];
9384 $ this ->Input ->setRules ($ this ->getRowRules ($ vars ));
9485 if ($ this ->Input ->validates ($ vars )) {
@@ -117,11 +108,8 @@ public function addModuleRow(array &$vars)
117108 */
118109 public function editModuleRow ($ module_row , array &$ vars )
119110 {
120- $ meta_fields = ['account_name ' , 'api_token ' ];
111+ $ meta_fields = ['account_name ' , 'api_token ' , ' api_base_url ' ];
121112 $ encrypted_fields = ['api_token ' ];
122- if (empty ($ vars ['use_ssl ' ])) {
123- $ vars ['use_ssl ' ] = 'false ' ;
124- }
125113 $ this ->Input ->setRules ($ this ->getRowRules ($ vars ));
126114 if ($ this ->Input ->validates ($ vars )) {
127115 $ meta = [];
@@ -165,7 +153,7 @@ private function getRowRules(&$vars)
165153 'valid_connection ' => [
166154 'rule ' => [
167155 [$ this , 'validateConnection ' ],
168- $ vars ['api_token ' ],
156+ $ vars ['api_base_url ' ],
169157 ],
170158 'message ' => Language::_ ('Upcloudvps.!error.api_token_valid_connection ' , true )
171159 ]
@@ -179,12 +167,13 @@ private function getRowRules(&$vars)
179167 * Validates the connection to the UpCloud API using provided credentials.
180168 *
181169 * @param string $api_token The UpCloud API token
170+ * @param string $api_base_url The UpCloud API base URL
182171 * @return bool True if the connection is successful, false otherwise
183172 */
184- public function validateConnection ($ api_token )
173+ public function validateConnection ($ api_token, $ api_base_url )
185174 {
186175 try {
187- $ api = $ this ->getApi ($ api_token );
176+ $ api = $ this ->getApi ($ api_token, $ api_base_url );
188177 $ result = $ api ->GetAccountInfo ();
189178 $ this ->log ('upcloud|accountRequest ' , serialize ($ result ), 'input ' , true );
190179 if ($ result ['response_code ' ] == '200 ' ) {
@@ -199,9 +188,10 @@ public function validateConnection($api_token)
199188 * Initializes and returns an instance of the UpcloudvpsApi.
200189 *
201190 * @param string $api_token The UpCloud API token
191+ * @param string $api_base_url The UpCloud API base URL (optional)
202192 * @return UpcloudvpsApi An instance of the UpCloud API wrapper
203193 */
204- private function getApi ($ api_token )
194+ private function getApi ($ api_token, $ api_base_url = null )
205195 {
206196 Loader::load (dirname (__FILE__ ) . DS . 'apis ' . DS . 'upcloudvps_api.php ' );
207197 Loader::loadComponents ($ this , ['Record ' ]);
@@ -217,6 +207,7 @@ private function getApi($api_token)
217207 }
218208 $ blestaVer = $ setting ->value ;
219209 $ params = [
210+ 'baseUrl ' => empty ($ api_base_url ) ? 'https://api.upcloud.com/1.3/ ' : $ api_base_url ,
220211 'apiToken ' => $ api_token ,
221212 'blestaVer ' => $ blestaVer ,
222213 'moduleVer ' => $ this ->config ->version ,
@@ -233,7 +224,7 @@ private function getApi($api_token)
233224 */
234225 private function getServerPlans ($ module_row )
235226 {
236- $ api = $ this ->getApi ($ module_row ->meta ->api_token );
227+ $ api = $ this ->getApi ($ module_row ->meta ->api_token , $ module_row -> meta -> api_base_url );
237228 $ result = $ api ->Getplans ()['response ' ]['plans ' ]['plan ' ];
238229 //$this->log('upcloud|Getplans', serialize($result), 'input', true);
239230 $ Vmplans = [];
@@ -255,7 +246,7 @@ private function getServerPlans($module_row)
255246 */
256247 private function getTemplates ($ module_row , $ package = null )
257248 {
258- $ api = $ this ->getApi ($ module_row ->meta ->api_token );
249+ $ api = $ this ->getApi ($ module_row ->meta ->api_token , $ module_row -> meta -> api_base_url );
259250 $ result_os = $ api ->GetTemplate ()['response ' ]['storages ' ]['storage ' ];
260251 //$this->log('upcloud|GetTemplates', serialize($result_os), 'input', true);
261252 $ templates = [];
@@ -283,7 +274,7 @@ private function getTemplates($module_row, $package = null)
283274 */
284275 private function getLocations ($ module_row )
285276 {
286- $ api = $ this ->getApi ($ module_row ->meta ->api_token );
277+ $ api = $ this ->getApi ($ module_row ->meta ->api_token , $ module_row -> meta -> api_base_url );
287278 $ zones = $ api ->GetZones ()['response ' ]['zones ' ]['zone ' ];
288279 // $this->log('upcloud|getLocations', serialize($zones), 'input', true);
289280 $ zoneLocation = [];
@@ -556,7 +547,7 @@ private function performServiceAction($service, $actionName, $logTag, $expectedR
556547 {
557548 $ module_row = $ this ->getModuleRow ();
558549 if ($ module_row ) {
559- $ api = $ this ->getApi ($ module_row ->meta ->api_token );
550+ $ api = $ this ->getApi ($ module_row ->meta ->api_token , $ module_row -> meta -> api_base_url );
560551 $ service_fields = $ this ->serviceFieldsToObject ($ service ->fields );
561552 $ vmId = $ service_fields ->upcloudvps_vmid ;
562553 //$this->log($logTag, serialize(['vm_id' => $vmId]), 'input', true);
@@ -749,7 +740,7 @@ public function addService($package, array $vars = null, $parent_package = null,
749740 $ this ->log ('upcloud|create ' , serialize ($ params ), 'input ' , true );
750741
751742 try {
752- $ api = $ this ->getApi ($ row ->meta ->api_token );
743+ $ api = $ this ->getApi ($ row ->meta ->api_token , $ row -> meta -> api_base_url );
753744 if (empty ($ vars ['upcloudvps_vmid ' ])) {
754745 $ server = $ api ->CreateServer ($ params );
755746 $ this ->log ('upcloud ' , serialize ($ server ), 'output ' , true );
@@ -869,7 +860,7 @@ public function editService($package, $service, array $vars = null, $parent_pack
869860 }
870861 }
871862 if ($ vars ['use_module ' ] == 'true ' && !isset ($ delta ['upcloudvps_vmid ' ])) {
872- $ api = $ this ->getApi ($ row ->meta ->api_token );
863+ $ api = $ this ->getApi ($ row ->meta ->api_token , $ row -> meta -> api_base_url );
873864 if ($ this ->Input ->errors ()) {
874865 return ;
875866 }
@@ -1071,7 +1062,7 @@ private function getServiceInfo($service, $package, $client = false)
10711062 {
10721063 $ row = $ this ->getModuleRow ();
10731064 $ service_fields = $ this ->serviceFieldsToObject ($ service ->fields );
1074- $ api = $ this ->getApi ($ row ->meta ->api_token );
1065+ $ api = $ this ->getApi ($ row ->meta ->api_token , $ row -> meta -> api_base_url );
10751066 $ response = $ api ->GetServer ($ service_fields ->upcloudvps_vmid )['response ' ]['server ' ];
10761067 $ server_details = $ response ?? (object ) [];
10771068 $ this ->view = new View ($ client ? 'client_service_info ' : 'admin_service_info ' , 'default ' );
@@ -1216,7 +1207,7 @@ private function getTabActions($package, $service, array $post = null, $client =
12161207 Loader::loadModels ($ this , ['Services ' ]);
12171208 $ service_fields = $ this ->serviceFieldsToObject ($ service ->fields );
12181209 $ templates = $ this ->getTemplates ($ row , $ package );
1219- $ api = $ this ->getApi ($ row ->meta ->api_token );
1210+ $ api = $ this ->getApi ($ row ->meta ->api_token , $ row -> meta -> api_base_url );
12201211 // $this->log('upcloud|GetVMInformation', serialize($service_fields), 'input', true);
12211212 $ vmId = $ service_fields ->upcloudvps_vmid ;
12221213 $ server_details = $ api ->GetServer ($ vmId )['response ' ]['server ' ];
@@ -1379,7 +1370,7 @@ private function generatePassword()
13791370 public function changeServicePackage ($ package_from , $ package_to , $ service , $ parent_package = null , $ parent_service = null )
13801371 {
13811372 if (($ row = $ this ->getModuleRow ())) {
1382- $ api = $ this ->getApi ($ row ->meta ->api_token );
1373+ $ api = $ this ->getApi ($ row ->meta ->api_token , $ row -> meta -> api_base_url );
13831374 if ($ package_from ->meta ->server_plan != $ package_to ->meta ->server_plan ) {
13841375 $ service_fields = $ this ->serviceFieldsToObject ($ service ->fields );
13851376 $ action = $ api ->ModifyServer ($ service_fields ->upcloudvps_vmid , $ package_to ->meta ->server_plan );
0 commit comments