@@ -88,7 +88,7 @@ public function manageEditRow($module_row, array &$vars)
8888 */
8989 public function addModuleRow (array &$ vars )
9090 {
91- $ meta_fields = ['account_name ' , 'api_token ' ];
91+ $ meta_fields = ['account_name ' , 'api_token ' , ' api_base_url ' ];
9292 $ encrypted_fields = ['api_token ' ];
9393 $ this ->Input ->setRules ($ this ->getRowRules ($ vars ));
9494 if ($ this ->Input ->validates ($ vars )) {
@@ -117,7 +117,7 @@ public function addModuleRow(array &$vars)
117117 */
118118 public function editModuleRow ($ module_row , array &$ vars )
119119 {
120- $ meta_fields = ['account_name ' , 'api_token ' ];
120+ $ meta_fields = ['account_name ' , 'api_token ' , ' api_base_url ' ];
121121 $ encrypted_fields = ['api_token ' ];
122122 if (empty ($ vars ['use_ssl ' ])) {
123123 $ vars ['use_ssl ' ] = 'false ' ;
@@ -165,7 +165,7 @@ private function getRowRules(&$vars)
165165 'valid_connection ' => [
166166 'rule ' => [
167167 [$ this , 'validateConnection ' ],
168- $ vars ['api_token ' ],
168+ $ vars ['api_base_url ' ],
169169 ],
170170 'message ' => Language::_ ('Upcloudvps.!error.api_token_valid_connection ' , true )
171171 ]
@@ -179,12 +179,13 @@ private function getRowRules(&$vars)
179179 * Validates the connection to the UpCloud API using provided credentials.
180180 *
181181 * @param string $api_token The UpCloud API token
182+ * @param string $api_base_url The UpCloud API base URL
182183 * @return bool True if the connection is successful, false otherwise
183184 */
184- public function validateConnection ($ api_token )
185+ public function validateConnection ($ api_token, $ api_base_url )
185186 {
186187 try {
187- $ api = $ this ->getApi ($ api_token );
188+ $ api = $ this ->getApi ($ api_token, $ api_base_url );
188189 $ result = $ api ->GetAccountInfo ();
189190 $ this ->log ('upcloud|accountRequest ' , serialize ($ result ), 'input ' , true );
190191 if ($ result ['response_code ' ] == '200 ' ) {
@@ -199,9 +200,10 @@ public function validateConnection($api_token)
199200 * Initializes and returns an instance of the UpcloudvpsApi.
200201 *
201202 * @param string $api_token The UpCloud API token
203+ * @param string $api_base_url The UpCloud API base URL (optional)
202204 * @return UpcloudvpsApi An instance of the UpCloud API wrapper
203205 */
204- private function getApi ($ api_token )
206+ private function getApi ($ api_token, $ api_base_url = null )
205207 {
206208 Loader::load (dirname (__FILE__ ) . DS . 'apis ' . DS . 'upcloudvps_api.php ' );
207209 Loader::loadComponents ($ this , ['Record ' ]);
@@ -217,6 +219,7 @@ private function getApi($api_token)
217219 }
218220 $ blestaVer = $ setting ->value ;
219221 $ params = [
222+ 'baseUrl ' => empty ($ api_base_url ) ? 'https://api.upcloud.com/1.3/ ' : $ api_base_url ,
220223 'apiToken ' => $ api_token ,
221224 'blestaVer ' => $ blestaVer ,
222225 'moduleVer ' => $ this ->config ->version ,
@@ -233,7 +236,7 @@ private function getApi($api_token)
233236 */
234237 private function getServerPlans ($ module_row )
235238 {
236- $ api = $ this ->getApi ($ module_row ->meta ->api_token );
239+ $ api = $ this ->getApi ($ module_row ->meta ->api_token , $ module_row -> meta -> api_base_url );
237240 $ result = $ api ->Getplans ()['response ' ]['plans ' ]['plan ' ];
238241 //$this->log('upcloud|Getplans', serialize($result), 'input', true);
239242 $ Vmplans = [];
@@ -255,7 +258,7 @@ private function getServerPlans($module_row)
255258 */
256259 private function getTemplates ($ module_row , $ package = null )
257260 {
258- $ api = $ this ->getApi ($ module_row ->meta ->api_token );
261+ $ api = $ this ->getApi ($ module_row ->meta ->api_token , $ module_row -> meta -> api_base_url );
259262 $ result_os = $ api ->GetTemplate ()['response ' ]['storages ' ]['storage ' ];
260263 //$this->log('upcloud|GetTemplates', serialize($result_os), 'input', true);
261264 $ templates = [];
@@ -283,7 +286,7 @@ private function getTemplates($module_row, $package = null)
283286 */
284287 private function getLocations ($ module_row )
285288 {
286- $ api = $ this ->getApi ($ module_row ->meta ->api_token );
289+ $ api = $ this ->getApi ($ module_row ->meta ->api_token , $ module_row -> meta -> api_base_url );
287290 $ zones = $ api ->GetZones ()['response ' ]['zones ' ]['zone ' ];
288291 // $this->log('upcloud|getLocations', serialize($zones), 'input', true);
289292 $ zoneLocation = [];
@@ -556,7 +559,7 @@ private function performServiceAction($service, $actionName, $logTag, $expectedR
556559 {
557560 $ module_row = $ this ->getModuleRow ();
558561 if ($ module_row ) {
559- $ api = $ this ->getApi ($ module_row ->meta ->api_token );
562+ $ api = $ this ->getApi ($ module_row ->meta ->api_token , $ module_row -> meta -> api_base_url );
560563 $ service_fields = $ this ->serviceFieldsToObject ($ service ->fields );
561564 $ vmId = $ service_fields ->upcloudvps_vmid ;
562565 //$this->log($logTag, serialize(['vm_id' => $vmId]), 'input', true);
@@ -749,7 +752,7 @@ public function addService($package, array $vars = null, $parent_package = null,
749752 $ this ->log ('upcloud|create ' , serialize ($ params ), 'input ' , true );
750753
751754 try {
752- $ api = $ this ->getApi ($ row ->meta ->api_token );
755+ $ api = $ this ->getApi ($ row ->meta ->api_token , $ row -> meta -> api_base_url );
753756 if (empty ($ vars ['upcloudvps_vmid ' ])) {
754757 $ server = $ api ->CreateServer ($ params );
755758 $ this ->log ('upcloud ' , serialize ($ server ), 'output ' , true );
@@ -869,7 +872,7 @@ public function editService($package, $service, array $vars = null, $parent_pack
869872 }
870873 }
871874 if ($ vars ['use_module ' ] == 'true ' && !isset ($ delta ['upcloudvps_vmid ' ])) {
872- $ api = $ this ->getApi ($ row ->meta ->api_token );
875+ $ api = $ this ->getApi ($ row ->meta ->api_token , $ row -> meta -> api_base_url );
873876 if ($ this ->Input ->errors ()) {
874877 return ;
875878 }
@@ -1071,7 +1074,7 @@ private function getServiceInfo($service, $package, $client = false)
10711074 {
10721075 $ row = $ this ->getModuleRow ();
10731076 $ service_fields = $ this ->serviceFieldsToObject ($ service ->fields );
1074- $ api = $ this ->getApi ($ row ->meta ->api_token );
1077+ $ api = $ this ->getApi ($ row ->meta ->api_token , $ row -> meta -> api_base_url );
10751078 $ response = $ api ->GetServer ($ service_fields ->upcloudvps_vmid )['response ' ]['server ' ];
10761079 $ server_details = $ response ?? (object ) [];
10771080 $ this ->view = new View ($ client ? 'client_service_info ' : 'admin_service_info ' , 'default ' );
@@ -1216,7 +1219,7 @@ private function getTabActions($package, $service, array $post = null, $client =
12161219 Loader::loadModels ($ this , ['Services ' ]);
12171220 $ service_fields = $ this ->serviceFieldsToObject ($ service ->fields );
12181221 $ templates = $ this ->getTemplates ($ row , $ package );
1219- $ api = $ this ->getApi ($ row ->meta ->api_token );
1222+ $ api = $ this ->getApi ($ row ->meta ->api_token , $ row -> meta -> api_base_url );
12201223 // $this->log('upcloud|GetVMInformation', serialize($service_fields), 'input', true);
12211224 $ vmId = $ service_fields ->upcloudvps_vmid ;
12221225 $ server_details = $ api ->GetServer ($ vmId )['response ' ]['server ' ];
@@ -1379,7 +1382,7 @@ private function generatePassword()
13791382 public function changeServicePackage ($ package_from , $ package_to , $ service , $ parent_package = null , $ parent_service = null )
13801383 {
13811384 if (($ row = $ this ->getModuleRow ())) {
1382- $ api = $ this ->getApi ($ row ->meta ->api_token );
1385+ $ api = $ this ->getApi ($ row ->meta ->api_token , $ row -> meta -> api_base_url );
13831386 if ($ package_from ->meta ->server_plan != $ package_to ->meta ->server_plan ) {
13841387 $ service_fields = $ this ->serviceFieldsToObject ($ service ->fields );
13851388 $ action = $ api ->ModifyServer ($ service_fields ->upcloudvps_vmid , $ package_to ->meta ->server_plan );
0 commit comments