From abbc2ce780dfb6b6c3d6fefd047c852ad79799b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Schl=C3=A4pfer?= Date: Fri, 29 Sep 2023 12:07:46 +0200 Subject: [PATCH] - Replaced pve2-api-php with fork that uses symfony & httpclient. - Reworked some of the server preparation functionality - Added "Debug mode" to proxmox Settings --- Api/Admin.php | 34 +- ProxmoxAuthentication.php | 174 ++-- ProxmoxServer.php | 73 +- ProxmoxVM.php | 13 +- Service.php | 3 +- composer.json | 24 + html_admin/mod_serviceproxmox_index.html.twig | 68 +- .../mod_serviceproxmox_settings.html.twig | 16 + pve2_api.class.php | 848 ++++++------------ 9 files changed, 590 insertions(+), 663 deletions(-) create mode 100644 composer.json diff --git a/Api/Admin.php b/Api/Admin.php index 2622305..27ef88f 100644 --- a/Api/Admin.php +++ b/Api/Admin.php @@ -402,12 +402,17 @@ public function server_create($data) 'ipv4' => 'Server ipv4 is missing', 'hostname' => 'Server hostname is missing', 'port' => 'Server port is missing', - 'root_user' => 'Root user is missing', - 'root_password' => 'Root password is missing', + 'auth_type' => 'Authentication type is missing', 'realm' => 'Proxmox user realm is missing', ); $this->di['validator']->checkRequiredParamsForArray($required, $data); + // check if server already exists based on name, ipv4 or hostname + $server = $this->di['db']->findOne('service_proxmox_server', 'name=:name OR ipv4=:ipv4 OR hostname=:hostname', array(':name' => $data['name'], ':ipv4' => $data['ipv4'], ':hostname' => $data['hostname'])); + if ($server) { + throw new \Box_Exception('Server already exists'); + } + $server = $this->di['db']->dispense('service_proxmox_server'); $server->name = $data['name']; $server->group = $data['group']; @@ -416,17 +421,34 @@ public function server_create($data) $server->hostname = $data['hostname']; $server->port = $data['port']; $server->realm = $data['realm']; - $server->root_user = $data['root_user']; - $server->root_password = $data['root_password']; $server->active = $data['active']; $server->created_at = date('Y-m-d H:i:s'); $server->updated_at = date('Y-m-d H:i:s'); $this->di['db']->store($server); - $this->di['logger']->info('Created Proxmox server %s', $server->id); + + // check if auth_type is username or token + if ($data['auth_type'] == 'username') { + $server->root_user = $data['root_user']; + $server->root_password = $data['root_password']; + $server->tokenname = ''; + $server->tokenvalue = ''; + $this->di['db']->store($server); + $this->getService()->test_connection($server); + } else { + $server->root_user = ''; + $server->root_password = ''; + $server->tokenname = $data['tokenname']; + $server->tokenvalue = $data['tokenvalue']; + $this->di['db']->store($server); + + } + + // Validate server by testing connection - $this->getService()->test_connection; + + return true; } diff --git a/ProxmoxAuthentication.php b/ProxmoxAuthentication.php index 375d75c..44bae86 100644 --- a/ProxmoxAuthentication.php +++ b/ProxmoxAuthentication.php @@ -32,11 +32,12 @@ trait ProxmoxAuthentication */ public function prepare_pve_setup($server) { + $config = $this->di['mod_config']('Serviceproxmox'); // Retrieve the server access information $serveraccess = $this->find_access($server); // Create a new instance of the PVE2_API class with the server access details - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue, debug: $config['pmx_debug_logging']); // Attempt to log in to the server using the API if (!$proxmox->login()) { @@ -82,85 +83,101 @@ public function prepare_pve_setup($server) default: throw new \Box_Exception("More than one group found"); break; - } - } - + } - // Validate if there already is a user and token for fossbilling - $users = $proxmox->get("/access/users"); - $found = 0; - // Iterate through the users and check for a user beginning with 'fb' - foreach ($users as $user) { - if (strpos($user['userid'], 'fb') === 0) { - $found += 1; - $userid = $user['userid']; - } - // Handle the cases where there are no users, one user, or multiple users - switch ($found) { - case 0: - // Create a new user - $userid = 'fb_' . rand(1000, 9999) . '@pve'; // TODO: Make realm configurable in the module settings - $newuser = $proxmox->post("/access/users", array('userid' => $userid, 'password' => $this->di['tools'], 'enable' => 1, 'comment' => 'fossbilling user', 'groups' => $groupid)); - - // Create a token for the new user - $token = $proxmox->post("/access/users/" . $userid . "/token/fb_access", array()); - - // Check if the token was created successfully - if ($token) { - $server->tokenname = $token['full-tokenid']; - $server->tokenvalue = $token['value']; - } else { - throw new \Box_Exception("Failed to create token for fossbilling user"); + // Validate if there already is a user and token for fossbilling + $users = $proxmox->get("/access/users"); + $found = 0; + // Iterate through the users and check for a user beginning with 'fb' + foreach ($users as $user) { + if (strpos($user['userid'], 'fb') === 0) { + $found += 1; + $userid = $user['userid']; + } + // Handle the cases where there are no users, one user, or multiple users + switch ($found) { + case 0: + // Create a new user + $userid = 'fb_' . rand(1000, 9999) . '@pve'; // TODO: Make realm configurable in the module settings + $newuser = $proxmox->post("/access/users", array('userid' => $userid, 'password' => $this->di['tools'], 'enable' => 1, 'comment' => 'fossbilling user', 'groups' => $groupid)); + + // Create a token for the new user + $token = $proxmox->post("/access/users/" . $userid . "/token/fb_access", array()); + + // Check if the token was created successfully + if ($token) { + $server->tokenname = $token['full-tokenid']; + $server->tokenvalue = $token['value']; + } else { + throw new \Box_Exception("Failed to create token for fossbilling user"); + break; + } break; - } - break; - case 1: - // Create a token for the existing user - $token = $proxmox->post("/access/users/" . $userid . "/token/fb_access", array()); - if ($token) { - $server->tokenname = $token['full-tokenid']; - $server->tokenvalue = $token['value']; - } else { - throw new \Box_Exception("Failed to create token for fossbilling user"); + case 1: + // Create a token for the existing user + $token = $proxmox->post("/access/users/" . $userid . "/token/fb_access", array()); + if ($token) { + $server->tokenname = $token['full-tokenid']; + $server->tokenvalue = $token['value']; + } else { + throw new \Box_Exception("Failed to create token for fossbilling user"); + break; + } + break; + default: + throw new \Box_Exception("There are more than one fossbilling users on the server. Please delete all but one."); break; + } + // Create permissions for the newly created token + // Set up permissions for the token (Admin user) to manage users, groups, and other administrative tasks + $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEUserAdmin', 'propagate' => 1, 'users' => $userid)); + $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEAuditor', 'propagate' => 1, 'users' => $userid)); + $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVESysAdmin', 'propagate' => 1, 'users' => $userid)); + $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEPoolAdmin', 'propagate' => 1, 'users' => $userid)); + $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEDatastoreAdmin', 'propagate' => 1, 'users' => $userid)); + $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEUserAdmin', 'propagate' => 1, 'tokens' => $server->tokenname)); + $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEAuditor', 'propagate' => 1, 'tokens' => $server->tokenname)); + $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVESysAdmin', 'propagate' => 1, 'tokens' => $server->tokenname)); + $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEPoolAdmin', 'propagate' => 1, 'tokens' => $server->tokenname)); + $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEDatastoreAdmin', 'propagate' => 1, 'tokens' => $server->tokenname)); + + // Sleep for 5 seconds + sleep(5); + + // Check if the permissions were created correctly by logging in and creating another user + /* + echo ""; + echo ""; + echo ""; + echo ""; + echo "

"; + */ + + // Delete the root password and unset the PVE2_API instance + $server->root_password = null; + unset($proxmox); + + // Return the test_access result for the server + return $this->test_access($server); + } + } else { + // Validate Permissions for the token + $permissions = $proxmox->get("/access/acl/"); + // Check for 'PVEUserAdmin', 'PVEAuditor', 'PVESysAdmin', 'PVEPoolAdmin', and 'PVEDatastoreAdmin' permissions, and if they don't exist, try to create them. + $required_permissions = array('PVEUserAdmin', 'PVEAuditor', 'PVESysAdmin', 'PVEPoolAdmin', 'PVEDatastoreAdmin'); + foreach ($required_permissions as $permission) { + $found_permission = 0; + foreach ($permissions as $acl) { + if ($acl['roleid'] == $permission) { + $found_permission += 1; } - break; - default: - throw new \Box_Exception("There are more than one fossbilling users on the server. Please delete all but one."); - break; + } + if (!$found_permission) { + $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => $permission, 'propagate' => 1, 'tokens' => $server->tokenname)); + } } - // Create permissions for the newly created token - // Set up permissions for the token (Admin user) to manage users, groups, and other administrative tasks - $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEUserAdmin', 'propagate' => 1, 'users' => $userid)); - $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEAuditor', 'propagate' => 1, 'users' => $userid)); - $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVESysAdmin', 'propagate' => 1, 'users' => $userid)); - $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEPoolAdmin', 'propagate' => 1, 'users' => $userid)); - $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEDatastoreAdmin', 'propagate' => 1, 'users' => $userid)); - $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEUserAdmin', 'propagate' => 1, 'tokens' => $server->tokenname)); - $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEAuditor', 'propagate' => 1, 'tokens' => $server->tokenname)); - $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVESysAdmin', 'propagate' => 1, 'tokens' => $server->tokenname)); - $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEPoolAdmin', 'propagate' => 1, 'tokens' => $server->tokenname)); - $permissions = $proxmox->put("/access/acl/", array('path' => '/', 'roles' => 'PVEDatastoreAdmin', 'propagate' => 1, 'tokens' => $server->tokenname)); - - // Sleep for 5 seconds - sleep(5); - - // Check if the permissions were created correctly by logging in and creating another user - /* - echo ""; - echo ""; - echo ""; - echo ""; - echo "

"; - */ - - // Delete the root password and unset the PVE2_API instance - $server->root_password = null; - unset($proxmox); - - // Return the test_access result for the server - return $this->test_access($server); + } } @@ -176,9 +193,9 @@ public function test_access($server) { // Retrieve the server access information $serveraccess = $this->find_access($server); - + $config = $this->di['mod_config']('Serviceproxmox'); // Create a new instance of the PVE2_API class with the server access details - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue, debug: $config['pmx_debug_logging']); // Attempt to log in to the server using the API if (!$proxmox->login()) { @@ -189,7 +206,7 @@ public function test_access($server) $userid = 'tfb_' . rand(1000, 9999) . '@pve'; // TODO: Make realm configurable in the module settings // Create a new user for testing purposes - $newuser = $proxmox->post("/access/users", array('userid' => $userid, 'password' => $this->di['tools']->generatePassword(16, 4), 'enable' => '1', 'comment' => 'fossbilling user 2')); + $proxmox->post("/access/users", array('userid' => $userid, 'password' => $this->di['tools']->generatePassword(16, 4), 'enable' => '1', 'comment' => 'FOSSBilling test user ' . $userid)); // Retrieve the newly created user $newuser = $proxmox->get("/access/users/" . $userid); @@ -227,7 +244,8 @@ public function create_client_user($server, $client) $clientuser->client_id = $client->id; $this->di['db']->store($clientuser); $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue); + $config = $this->di['mod_config']('Serviceproxmox'); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue, debug: $config['pmx_debug_logging']); if (!$proxmox->login()) { throw new \Box_Exception("Failed to connect to the server. create_client_user"); } diff --git a/ProxmoxServer.php b/ProxmoxServer.php index 7dd5ca3..840fb72 100644 --- a/ProxmoxServer.php +++ b/ProxmoxServer.php @@ -35,12 +35,14 @@ public function test_connection($server) { // Test if login $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue); + $config = $this->di['mod_config']('Serviceproxmox'); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); // check if tokenname and tokenvalue contain values by checking their content if (empty($server->tokenname) || empty($server->tokenvalue)) { if (!empty($server->root_user) && !empty($server->root_password)) { if ($proxmox->login()) { + error_log("Serviceproxmox: Login with username and password successful"); return true; } else { throw new \Box_Exception("Login to Proxmox Host failed"); @@ -48,7 +50,60 @@ public function test_connection($server) } else { throw new \Box_Exception("No login information provided"); } + } else if ($proxmox->getVersion()) { + error_log("Serviceproxmox: Login with token successful!"); + return true; + } else { + throw new \Box_Exception("Failed to connect to the server."); + } + } + + /* + Validate token access and setup + */ + public function test_token_connection($server) + { + // Test if login + $serveraccess = $this->find_access($server); + $config = $this->di['mod_config']('Serviceproxmox'); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); + // check if tokenname and tokenvalue contain values by checking their content + if (empty($server->tokenname) || empty($server->tokenvalue)) { + throw new \Box_Exception("Token Access Failed: No tokenname or tokenvalue provided"); } else if ($proxmox->get_version()) { + error_log("Serviceproxmox: Login with token successful!"); + $permissions = $proxmox->get("/access/permissions"); + $found_permission = 0; + // Iterate through the permissions and check for 'Realm.AllocateUser' permission + foreach ($permissions as $permission) { + if ($permission['Realm.AllocateUser'] == 1) { + $found_permission += 1; + } + } + // Throw an exception if the 'Realm.AllocateUser' permission is not found + if (!$found_permission) { + throw new \Box_Exception("Token does not have 'Realm.AllocateUser' permission"); + } + + // Validate if there already is a group for fossbilling + $groups = $proxmox->get("/access/groups"); + $foundgroups = 0; + // Iterate through the groups and check for a group beginning with 'fossbilling' + foreach ($groups as $group) { + if (strpos($group['groupid'], 'fossbilling') === 0) { + $foundgroups += 1; + $groupid = $group['groupid']; + } + // check if groupid is the same as the id of the token (fb_1234@pve!fb_access) + $fb_token_instanceid = explode('@', $server->tokenname)[1]; + + + if ($group['groupid'] == $server->tokenname) { + $foundgroups += 1; + $groupid = $group['groupid']; + } + + } return true; } else { throw new \Box_Exception("Failed to connect to the server."); @@ -56,6 +111,7 @@ public function test_connection($server) } + /* Find best Server */ public function find_empty($product) @@ -131,7 +187,8 @@ public function getHardwareData($server) { // Retrieve associated server $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue); + $config = $this->di['mod_config']('Serviceproxmox'); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { error_log("ProxmoxServer.php: getHardwareData: Login successful"); @@ -146,7 +203,8 @@ public function getStorageData($server) { // Retrieve associated server $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue); + $config = $this->di['mod_config']('Serviceproxmox'); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $storage = $proxmox->get("/nodes/" . $server->name . "/storage"); return $storage; @@ -160,7 +218,8 @@ public function getAssignedResources($server) { // Retrieve associated server $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue); + $config = $this->di['mod_config']('Serviceproxmox'); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $assigned_resources = $proxmox->get("/nodes/" . $server->name . "/qemu"); return $assigned_resources; @@ -175,7 +234,8 @@ public function getAvailableAppliances() $server = $this->di['db']->getExistingModelById('service_proxmox_server', 1, 'Server not found'); $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue); + $config = $this->di['mod_config']('Serviceproxmox'); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $appliances = $proxmox->get("/nodes/" . $server->name . "/aplinfo"); return $appliances; @@ -188,7 +248,8 @@ public function getAvailableAppliances() public function getQemuTemplates($server) { $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue); + $config = $this->di['mod_config']('Serviceproxmox'); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $templates = $proxmox->get("/nodes/" . $server->name . "/qemu"); return $templates; diff --git a/ProxmoxVM.php b/ProxmoxVM.php index 898bb30..8b416e8 100644 --- a/ProxmoxVM.php +++ b/ProxmoxVM.php @@ -95,7 +95,8 @@ public function delete($order, $model) // Connect to YNH API $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue); + $config = $this->di['mod_config']('Serviceproxmox'); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $server->tokenname, tokensecret: $server->tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $proxmox->post("/nodes/" . $model->node . "/" . $product_config['virt'] . "/" . $model->vmid . "/status/shutdown", array()); @@ -140,7 +141,7 @@ public function vm_info($order, $service) // Test if login $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->get_version()) { $status = $proxmox->get("/nodes/" . $server->name . "/" . $product_config['virt'] . "/" . $service->vmid . "/status/current"); // VM monitoring? @@ -169,7 +170,7 @@ public function vm_reboot($order, $service) // Test if login $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $proxmox->post("/nodes/" . $server->name . "/" . $product_config['virt'] . "/" . $service->vmid . "/status/shutdown", array()); $status = $proxmox->get("/nodes/" . $server->name . "/" . $product_config['virt'] . "/" . $service->vmid . "/status/current"); @@ -216,7 +217,7 @@ public function vm_start($order, $service) // Test if login $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $proxmox->post("/nodes/" . $server->name . "/" . $product_config['virt'] . "/" . $service->vmid . "/status/start", array()); return true; @@ -241,7 +242,7 @@ public function vm_shutdown($order, $service) $clientuser = $this->di['db']->findOne('service_proxmox_users', 'server_id = ? and client_id = ?', array($server->id, $client->id)); //echo "D: ".var_dump($order); $serveraccess = $this->find_access($server); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { $settings = array( 'forceStop' => true @@ -279,7 +280,7 @@ public function vm_cli($order, $service) //$password = 'test'; //$proxmox = new PVE2_API($serveraccess, $client->id, $server->name, $password); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->view_tokenname, tokensecret: $clientuser->view_tokenvalue); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->view_tokenname, tokensecret: $clientuser->view_tokenvalue,debug: $config['pmx_debug_logging']); if ($proxmox->login()) { // Get VNC Web proxy ticket by calling /nodes/{node}/{type}/{vmid}/vncproxy diff --git a/Service.php b/Service.php index b41417e..ac52ab8 100644 --- a/Service.php +++ b/Service.php @@ -688,7 +688,8 @@ public function activate($order, $model) $serveraccess = $this->find_access($server); // find client permissions for server $clientuser = $this->di['db']->findOne('service_proxmox_users', 'server_id = ? and client_id = ?', array($server->id, $client->id)); - $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue); + $config = $this->di['mod_config']('Serviceproxmox'); + $proxmox = new PVE2_API($serveraccess, $server->root_user, $server->realm, $server->root_password, port: $server->port, tokenid: $clientuser->admin_tokenname, tokensecret: $clientuser->admin_tokenvalue,debug: $config['pmx_debug_logging']); // Create Proxmox VM if ($proxmox->login()) { diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..ca87598 --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "vendor/pve2-api-client", + "description": "A Proxmox VE API v2 client for Symfony", + "type": "library", + "require": { + "php": "^8.1|^8.2", + "symfony/http-client": "^5.3", + "symfony/http-foundation": "^5.3", + "symfony/validator": "^5.3" + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\PVE2API\\": "src/" + } + }, + "license": "MIT", + "authors": [ + { + "name": "Christoph Schläpfer", + "email": "chris+github@cleverly.ch" + } + ] + } + \ No newline at end of file diff --git a/html_admin/mod_serviceproxmox_index.html.twig b/html_admin/mod_serviceproxmox_index.html.twig index 151f4a7..7f8d043 100644 --- a/html_admin/mod_serviceproxmox_index.html.twig +++ b/html_admin/mod_serviceproxmox_index.html.twig @@ -258,25 +258,62 @@ + +
+ +
+
+ + +
+
+ + +
+
+
+ + +
- +
-
+
- +
This password will only be used to create the access tokens on the pve server.
- +
+
+ +
+ +
+
+
+ +
+ +
+ This token will be used to authenticate with the pve server. +
+
+
+ + +
+
+ + +
+
+ + +
+
+