Commit 95f3cb50 authored by root's avatar root

Module upgrade to 3.1

parent c4b1fa1b
......@@ -7,6 +7,7 @@
- ISPConfig 3.1
- Mysql database (same as ISPconfig)
- Proxmox Virtual Environement
- Firewall permission
## Features
- Manage your VPS :
......@@ -28,7 +29,7 @@
- Admin display :
- Per client assignation
## TODO
## ToDo
- Admin function :
- Snapshot (add / remove)
- Networks : Enable / Disable, Vlan, rate limit
......@@ -37,6 +38,19 @@
- Event log
- Vps consol integration
## How To implement this module
- Create Proxmox user for ISPConfig communication with PVEVMUser right
- Assign VMs to this user
- Deploy the module into your ISPConfig setup -> /usr/local/ispconfig/interface/web
- Configure the module with your Proxmox user -> /usr/local/ispconfig/interface/lib/config.inc.local.php
- $conf["pve_username"] = 'username';
- $conf["pve_password"] = 'password';
- $conf["pve_link"] = 'hostname / ip of your cluster head';
- $conf["pve_realm"] = 'realm';
- Create MySQL table for this module -> misc/vm_proxmox.sql
# License
Copyright (c) 2016, Oricom Internet
All rights reserved.
<?php
require_once '../../lib/config.inc.php';
require_once '../../lib/app.inc.php';
include './lib/pve2_api.class.php';
//* Check permissions for module
$app->auth->check_module_permissions('proxmox');
$prox_id = $app->functions->intval($_REQUEST['vm']);
$condition = $_REQUEST['periode'];
$vm_pvesvr = $_REQUEST['vm_pvesvr'];
if($_POST)
{
// Vrification Apartenance VM (user vs admin)
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid']))
{
$vm = $app->db->queryOneRecord("SELECT vm_containers, vm_id FROM proxmox_vm WHERE id = $prox_id AND sys_groupid = $client_group_id");
}
else
{
$vm = $app->db->queryOneRecord("SELECT vm_containers, vm_id FROM proxmox_vm WHERE id = $prox_id");
}
$vm_containers = $vm['vm_containers'];
$vm_id = $app->functions->intval($vm['vm_id']);
if(isset($vm_pvesvr) && isset($vm_id) && isset($vm_containers))
{
$pve2 = new PVE2_API($conf["pve_link"], $conf["pve_username"], $conf["pve_realm"], $conf["pve_password"]);
if ($pve2) {
if ($pve2->login()) {
switch ($condition)
{
case 'ah' :
$params = "&timeframe=hour&cf=AVERAGE";
break;
case 'mh' :
$params = "&timeframe=hour&cf=MAX";
break;
case 'ad' :
$params = "&timeframe=day&cf=AVERAGE";
break;
case 'md' :
$params = "&timeframe=day&cf=MAX";
break;
case 'aw' :
$params = "&timeframe=week&cf=AVERAGE";
break;
case 'mw' :
$params = "&timeframe=week&cf=MAX";
break;
case 'am' :
$params = "&timeframe=month&cf=AVERAGE";
break;
case 'mm' :
$params = "&timeframe=month&cf=MAX";
break;
case 'ay' :
$params = "&timeframe=year&cf=AVERAGE";
break;
case 'my' :
$params = "&timeframe=year&cf=MAX";
break;
}
if( isset($params) )
{
$graphs['cpu'] = $pve2->get("/nodes/{$vm_pvesvr}/{$vm_containers}/{$vm_id}/rrd?ds=cpu{$params}");
$graphs['memory'] = $pve2->get("/nodes/{$vm_pvesvr}/{$vm_containers}/{$vm_id}/rrd?ds=mem,maxmem{$params}");
$graphs['network'] = $pve2->get("/nodes/{$vm_pvesvr}/{$vm_containers}/{$vm_id}/rrd?ds=netin,netout{$params}");
$graphs['disk'] = $pve2->get("/nodes/{$vm_pvesvr}/{$vm_containers}/{$vm_id}/rrd?ds=diskread,diskwrite{$params}");
$retour['CPU'] = base64_encode(utf8_decode($graphs['cpu']['image']));
$retour['MEM'] = base64_encode(utf8_decode($graphs['memory']['image']));
$retour['NET'] = base64_encode(utf8_decode($graphs['network']['image']));
$retour['HDD'] = base64_encode(utf8_decode($graphs['disk']['image']));
}
echo json_encode($retour);
} else {
echo "Login to Proxmox Host failed.\n";
exit;
}
} else {
echo "Could not create PVE2_API object.\n";
exit;
}
}
}
?>
<?php
/*
Form Definition
Tabledefinition
Datatypes:
- INTEGER (Forces the input to Int)
- DOUBLE
- CURRENCY (Formats the values to currency notation)
- VARCHAR (no format check, maxlength: 255)
- TEXT (no format check)
- DATE (Dateformat, automatic conversion to timestamps)
Formtype:
- TEXT (Textfield)
- TEXTAREA (Textarea)
- PASSWORD (Password textfield, input is not shown when edited)
- SELECT (Select option field)
- RADIO
- CHECKBOX
- CHECKBOXARRAY
- FILE
VALUE:
- Wert oder Array
Hint:
The ID field of the database table is not part of the datafield definition.
The ID field must be always auto incement (int or bigint).
Search:
- searchable = 1 or searchable = 2 include the field in the search
- searchable = 1: this field will be the title of the search result
- searchable = 2: this field will be included in the description of the search result
*/
$form["title"] = "Assignation";
$form["description"] = "";
$form["name"] = "proxmox_vm";
$form["action"] = "proxmox_vm_edit.php";
$form["db_table"] = "proxmox_vm";
$form["db_table_idx"] = "id";
$form["db_history"] = "yes";
$form["tab_default"] = "proxmox_vm";
$form["list_default"] = "proxmox_vm_list.php";
$form["auth"] = 'yes'; // yes / no
$form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user
$form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user
$form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete
$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete
$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete
$form["tabs"]['proxmox_vm'] = array (
'title' => "Assignation",
'width' => 100,
'template' => "templates/proxmox_vm_edit.htm",
'fields' => array (
//#################################
// Begin Datatable fields
//#################################
'server_id' => array (
'datatype' => 'INTEGER',
'default' => 1,
'value' => 1,
),
'vm_id' => array (
'datatype' => 'INTEGER',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'separator' => '',
'width' => '30',
'maxlength' => '255',
'rows' => '',
'cols' => '',
'searchable' => 2
),
'vm_containers' => array (
'datatype' => 'VARCHAR',
'formtype' => 'SELECT',
'default' => '',
'value' => array('qemu' => 'qemu', 'lxc' => 'lxc'),
'separator' => '',
'width' => '30',
'maxlength' => '255',
'rows' => '',
'cols' => '',
'searchable' => 2
),
'vm_name' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'separator' => '',
'width' => '30',
'maxlength' => '255',
'rows' => '',
'cols' => '',
'searchable' => 2
),
'vm_description' => array (
'datatype' => 'TEXT',
'formtype' => 'TEXTAREA',
'default' => '',
'value' => '',
'separator' => '',
'width' => '',
'maxlength' => '',
'rows' => '10',
'cols' => '30'
),
//#################################
// ENDE Datatable fields
//#################################
)
);
?>
<?php
/*
Form Definition
Tabledefinition
Datatypes:
- INTEGER (Forces the input to Int)
- DOUBLE
- CURRENCY (Formats the values to currency notation)
- VARCHAR (no format check, maxlength: 255)
- TEXT (no format check)
- DATE (Dateformat, automatic conversion to timestamps)
Formtype:
- TEXT (Textfield)
- TEXTAREA (Textarea)
- PASSWORD (Password textfield, input is not shown when edited)
- SELECT (Select option field)
- RADIO
- CHECKBOX
- CHECKBOXARRAY
- FILE
VALUE:
- Wert oder Array
Hint:
The ID field of the database table is not part of the datafield definition.
The ID field must be always auto incement (int or bigint).
Search:
- searchable = 1 or searchable = 2 include the field in the search
- searchable = 1: this field will be the title of the search result
- searchable = 2: this field will be included in the description of the search result
*/
$form["title"] = "Informations";
$form["description"] = "";
$form["name"] = "proxmox_vm";
$form["action"] = "proxmox_vm_informations.php";
$form["db_table"] = "proxmox_vm";
$form["db_table_idx"] = "id";
$form["db_history"] = "yes";
$form["tab_default"] = "informations";
$form["list_default"] = "proxmox_vm_list.php";
$form["auth"] = 'yes'; // yes / no
$form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user
$form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user
$form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete
$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete
$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete
$form["tabs"]['informations'] = array (
'title' => "Informations", // Need to translate with variable
'width' => 100,
'template' => "templates/proxmox_vm_informations.htm",
'fields' => array (
//#################################
// Begin Datatable fields
//#################################
'id' => array (
'datatype' => 'INTEGER',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'separator' => '',
'width' => '30',
'maxlength' => '255',
'rows' => '',
'cols' => '',
'searchable' => 2
),
//#################################
// ENDE Datatable fields
//#################################
)
);
$form["tabs"]['graphics'] = array (
'title' => "Graphics", // Need to translate with variable
'width' => 100,
'template' => "templates/proxmox_vm_graphiques.htm",
'readonly' => false,
/*
'fields' => array (
//#################################
// Begin Datatable fields
//#################################
'id' => array (
'datatype' => 'INTEGER',
'formtype' => 'TEXT',
'default' => '',
'value' => '',
'separator' => '',
'width' => '30',
'maxlength' => '255',
'rows' => '',
'cols' => '',
'searchable' => 2
),
//#################################
// ENDE Datatable fields
//#################################
)*/
);
?>
<?php
$wb['Virtuals servers'] = 'Serveurs virtuels';
$wb['Assignation'] = 'Assigner un serveur virtuel';
$wb['Graphiques'] = 'Graphiques';
$wb['VPS'] = 'Serveurs virtuels';
?>
<?php
$wb["_csrf_id_txt"] = '_csrf_id';
$wb["_csrf_key_txt"] = '_csrf_key';
$wb["proxy_directives_txt"] = 'proxy_directives';
$wb["edit_txt"] = 'Edition';
$wb["vm_id_txt"] = 'ID serveur virtuel';
$wb["vm_pvesvr_txt"] = 'Serveur Hôte';
$wb["vm_containers_txt"] = 'Conteneurs';
$wb["vm_nom_txt"] = 'Nom serveur virtuel';
$wb["vm_description_txt"] = 'Description';
$wb["vm_client_txt"] = 'Client';
$wb["vm_memoire_txt"] = 'Mémoire';
$wb["vm_maxhdd_txt"] = 'Quota Disque dur';
$wb["vm_status_txt"] = 'Status';
$wb["vm_cpu_txt"] = 'Processeurs';
$wb["vm_load_txt"] = 'Charge';
$wb["vm_uptime_txt"] = 'Uptime';
$wb["vm_err_assignation"] = 'Assignation invalide';
$wb["vm_err_login"] = 'Impossible de se connecter au serveur hôte';
$wb["vm_err_api_obj"] = 'Impossible de créer l\'objet de l\'API';
$wb["vm_time_txt"] = 'Minutes';
$wb["vm_start_txt"] = 'Démarrer';
$wb["vm_shutdown_txt"] = 'Arrêter';
$wb["vm_reset_txt"] = 'Réinitialiser';
$wb["vm_kill_txt"] = 'Terminer';
$wb["vm_cancel_txt"] = 'Retour';
$wb["vm_timeframe"] = 'Période';
$wb["vm_avg_hour"] = 'Heure (moy.)';
$wb["vm_avg_day"] = 'Jour (moy.)';
$wb["vm_avg_week"] = 'Semaine (moy.)';
$wb["vm_avg_month"] = 'Mois (moy.)';
$wb["vm_avg_year"] = 'Années (moy.)';
$wb["vm_max_hour"] = 'Heure (max.)';
$wb["vm_max_day"] = 'Jour (max.)';
$wb["vm_max_week"] = 'Semaine (max.)';
$wb["vm_max_month"] = 'Mois (max.)';
$wb["vm_max_year"] = 'Années (max.)';
$wb["vm_confirm_reset"] = 'Réinitialiser de la machine virtuelle ?';
$wb["vm_confirm_kill"] = 'Stopper la machine virtuelle ?';
$wb["vm_confirm_shutdown"] = 'Arreter la machine virtuelle ?';
$wb["vm_select_timeframe_txt"] = 'Merci de choisir une période' ;
?>
<?php
$wb["list_head_txt"] = 'Liste serveurs virtuels';
$wb["list_desc_txt"] = 'Liste des machines virtuelles que vous contrôlez';
$wb["client_id_txt"] = 'Client';
$wb["vm_name_txt"] = 'Nom serveur virtuel';
$wb["vm_description_txt"] = 'Déscription';
$wb["vm_pvesvr_txt"] = 'Serveur Hôte';
$wb["vm_id_txt"] = 'VM id';
$wb["add_new_assignation_txt"] = 'Assigner une VM';
$wb["edit_txt"] = 'Éditer' ;
?>
<?php
$wb['Virtuals servers'] = 'Virtuals servers';
$wb['Assignation'] = 'Assign a virtual server';
$wb['Graphiques'] = 'Graphics';
$wb['VPS'] = 'Virtuals servers';
?>
<?php
$wb["_csrf_id_txt"] = '_csrf_id';
$wb["_csrf_key_txt"] = '_csrf_key';
$wb["proxy_directives_txt"] = 'proxy_directives';
$wb["edit_txt"] = 'Edit';
$wb["vm_id_txt"] = 'Virtual server ID';
$wb["vm_pvesvr_txt"] = 'Host server';
$wb["vm_containers_txt"] = 'Containers';
$wb["vm_nom_txt"] = 'Virtual server name';
$wb["vm_description_txt"] = 'Description';
$wb["vm_client_txt"] = 'Client';
$wb["vm_memoire_txt"] = 'Memory';
$wb["vm_maxhdd_txt"] = 'Quota Hard disk';
$wb["vm_status_txt"] = 'Status';
$wb["vm_cpu_txt"] = 'Processors';
$wb["vm_load_txt"] = 'Load';
$wb["vm_uptime_txt"] = 'Uptime';
$wb["vm_err_assignation"] = 'Invalid assignation';
$wb["vm_err_login"] = 'Login to host failed.';
$wb["vm_err_api_obj"] = 'Could not create api object.';
$wb["vm_time_txt"] = 'Minutes';
$wb["vm_start_txt"] = 'Start';
$wb["vm_shutdown_txt"] = 'Stop';
$wb["vm_reset_txt"] = 'Reset';
$wb["vm_kill_txt"] = 'Kill';
$wb["vm_cancel_txt"] = 'Back';
$wb["vm_timeframe"] = 'Timeframe';
$wb["vm_avg_hour"] = 'Hour (avg)';
$wb["vm_avg_day"] = 'Day (avg)';
$wb["vm_avg_week"] = 'Week (avg)';
$wb["vm_avg_month"] = 'Month (avg)';
$wb["vm_avg_year"] = 'Year (avg)';
$wb["vm_max_hour"] = 'Hour (max)';
$wb["vm_max_day"] = 'Day (max)';
$wb["vm_max_week"] = 'Week (max)';
$wb["vm_max_month"] = 'Month (max)';
$wb["vm_max_year"] = 'Year (max)';
$wb["vm_confirm_reset"] = 'Reset the virtual machine ?';
$wb["vm_confirm_kill"] = 'Kill the virtual machine ?';
$wb["vm_confirm_shutdown"] = 'Shutdown the virtual machine ?';
$wb["vm_select_timeframe_txt"] = 'Choose a timeframe please' ;
?>
<?php
$wb["list_head_txt"] = 'Virtuals servers list';
$wb["list_desc_txt"] = 'List of virtual machines you control';
$wb["client_id_txt"] = 'Client';
$wb["vm_name_txt"] = 'Virtual server name';
$wb["vm_description_txt"] = 'Description';
$wb["vm_pvesvr_txt"] = 'Host server';
$wb["vm_id_txt"] = 'VM id';
$wb["add_new_assignation_txt"] = 'VM assignation';
$wb["edit_txt"] = 'Edit' ;
?>
<?php
$wb['Virtuals servers'] = 'Serveurs virtuels';
$wb['Assignation'] = 'Assigner un serveur virtuel';
$wb['Graphiques'] = 'Graphiques';
$wb['VPS'] = 'Serveurs virtuels';
?>
<?php
$wb["_csrf_id_txt"] = '_csrf_id';
$wb["_csrf_key_txt"] = '_csrf_key';
$wb["proxy_directives_txt"] = 'proxy_directives';
$wb["edit_txt"] = 'Edition';
$wb["vm_nom_txt"] = 'Nom serveur virtuel';
$wb["vm_id_txt"] = 'ID serveur virtuel';
$wb["vm_description_txt"] = 'Description';
$wb["vm_client_txt"] = 'Client';
$wb["vm_pvesvr_txt"] = 'Serveur Hôte';
$wb["vm_containers_txt"] = 'Conteneurs';
$wb["vm_memoire_txt"] = 'Mémoire';
$wb["vm_maxhdd_txt"] = 'Quota Disque dur';
$wb["vm_status_txt"] = 'Status';
$wb["vm_cpu_txt"] = 'Processeurs';
$wb["vm_load_txt"] = 'Charge';
$wb["vm_uptime_txt"] = 'Uptime';
$wb["vm_err_assignation"] = 'Assignation invalide';
$wb["vm_err_login"] = 'Impossible de se connecter au serveur hôte';
$wb["vm_err_api_obj"] = 'Impossible de créer l\'objet de l\'API';
$wb["vm_time_txt"] = 'Minutes';
$wb["vm_start_txt"] = 'Démarrer';
$wb["vm_shutdown_txt"] = 'Arrêter';
$wb["vm_reset_txt"] = 'Réinitialiser';
$wb["vm_kill_txt"] = 'Terminer';
$wb["vm_cancel_txt"] = 'Retour';
$wb["vm_timeframe"] = 'Période';
$wb["vm_avg_hour"] = 'Heure (moy.)';
$wb["vm_avg_day"] = 'Jour (moy.)';
$wb["vm_avg_week"] = 'Semaine (moy.)';
$wb["vm_avg_month"] = 'Mois (moy.)';
$wb["vm_avg_year"] = 'Années (moy.)';
$wb["vm_max_hour"] = 'Heure (max.)';
$wb["vm_max_day"] = 'Jour (max.)';
$wb["vm_max_week"] = 'Semaine (max.)';
$wb["vm_max_month"] = 'Mois (max.)';
$wb["vm_max_year"] = 'Années (max.)';
$wb["vm_confirm_reset"] = 'Réinitialiser de la machine virtuelle ?';
$wb["vm_confirm_kill"] = 'Stopper la machine virtuelle ?';
$wb["vm_confirm_shutdown"] = 'Arreter la machine virtuelle ?';
$wb["vm_select_timeframe_txt"] = 'Merci de choisir une période' ;
?>
<?php
$wb["list_head_txt"] = 'Liste serveurs virtuels';
$wb["list_desc_txt"] = 'Liste des machines virtuelles que vous contrôlez';
$wb["client_id_txt"] = 'Client';
$wb["vm_name_txt"] = 'Nom serveur virtuel';
$wb["vm_description_txt"] = 'Déscription';
$wb["vm_pvesvr_txt"] = 'Serveur Hôte';
$wb["vm_id_txt"] = 'VM id';
$wb["add_new_assignation_txt"] = 'Assigner une VM';
$wb["edit_txt"] = 'Éditer' ;
?>
<?php
$userid=$app->auth->get_user_id();
$module['name'] = 'proxmox';
$module['title'] = 'top_menu_vm';
$module['template'] = 'module.tpl.htm';
$module['startpage'] = 'proxmox/proxmox_vm_list.php';
$module['tab_width'] = '60';
$module['order'] = '90';
//**** Templates menu
$items = array();
if($_SESSION["s"]["user"]["typ"] == 'admin') {
$items[] = array( 'title' => 'Assignation',
'target' => 'content',
'link' => 'proxmox/proxmox_vm_edit.php',
'html_id' => 'proxmox_vm_list');
}
if($_SESSION["s"]["user"]["typ"] == 'admin') {
$items[] = array( 'title' => 'Virtuals servers',
'target' => 'content',
'link' => 'proxmox/proxmox_vm_list.php',
'html_id' => 'proxmox_vm_list');
}
if(count($items))
{
$module['nav'][] = array( 'title' => 'VPS',
'open' => 1,
'items' => $items);
}
?>
This diff is collapsed.
<?php
/*
Datatypes:
- INTEGER
- DOUBLE
- CURRENCY
- VARCHAR
- TEXT
- DATE
*/
// Name of the list
$liste["name"] = "proxmox_vm";
$liste["name"] = "proxmox_vm";
// Database table
$liste["table"] = "proxmox_vm";
// Index index field of the database table
$liste["table_idx"] = "id";
// Search Field Prefix
$liste["search_prefix"] = "search_";
// Records per page
$liste["records_per_page"] = 15;
// Script File of the list
$liste["file"] = "proxmox_vm_list.php";
// Script file of the edit form
$liste["edit_file"] = "proxmox_vm_edit.php";
// Script File of the delete script
$liste["delete_file"] = "proxmox_vm_del.php";
// Paging Template
$liste["paging_tpl"] = "templates/paging.tpl.htm";
// Enable authe
$liste["auth"] = "yes";
$liste["item"][] = array( 'field' => "id",
'datatype' => "INTEGER",
'formtype' => "TEXT",
'op' => "=",
'prefix' => "",
'suffix' => "",
'width' => "",
'value' => "");