Code Monkey home page Code Monkey logo

proxmox's Introduction

Api Proxmox

Using Php , easy.

Code ,

// Exmaple by using form.
<?php
Here for your admin panel.
session_start();
$id = $_SESSION['email'];
if(!preg_match($id)){
    header('Location : index.php');
    // Plus en ban la personne par ip et par MAC
    // Ou on fait pop la flash alert + redirection + ban.

}


?>
<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<form action="app_container.php" method="post">
  <select name="os" size="1">
<option>local:templates/debian-8.0-standard_6.0-4_amd64.tar.gz
<option>local:templates/debian-8.6-standard_6.0-4_amd64.tar.gz
<option>local:templates/centos-7.0-standard_6.0-4_amd64.tar.gz

</select>
  <input type="number" name="vmid">
  <input type="number" name="cpus">
  <input type="description" name="description">
  <input type="number" name="disk">
  <input type="text" name="hostname">
  <input type="number" name="memory" placeholder="ram">
  <input type="text" name="nameserver">
    <input type="submit" name="submit">



</body>
</html>

Génération of CT by the form

<?php
/*
 * @autor Ermal Ahmedi
 * @created for , creat CT in Proxmox via form
 * @Php 5.4 , 7
 */

require("pve2_api.class.php");

if(isset($_POST['submit'])) {
    // On récupère les valeurs envoie sur le formulaire.

    // Choix du serveur
    $hostname = $_POST['hostname'];
    $realm = $_POST['realm'];
    $password = $_POST['password'];
    $templates = $_POST['templates'];
    $mail = $_POST['mail'];

# You can try/catch exception handle the constructor here if you want.
    $pve2 = new PVE2_API($hostname, "root", $realm, $password);
# realm above can be pve, pam or any other realm available.

    /* Optional - enable debugging. It print()'s any results currently */
// $pve2->set_debug(true);

    if ($pve2->login()) {

        # Get first node name.
        $nodes = $pve2->get_node_list();
        $first_node = $nodes[0];
        unset($nodes);

        # Create a VZ container on the first node in the cluster.
        $new_container_settings = array();
        $new_container_settings['ostemplate'] = "local:vztmpl/debian-6.0-standard_6.0-4_amd64.tar.gz";
        $new_container_settings['vmid'] = $_POST['vmid'];
        $new_container_settings['cpus'] = $_POST['cpus'];;
        $new_container_settings['description'] = $_POST['description'];;
        $new_container_settings['disk'] = $_POST['disk'];;
        $new_container_settings['hostname'] = $_POST['hostname'];;
        $new_container_settings['memory'] = $_POST['memory'];;
        $new_container_settings['nameserver'] = $_POST['nameserver'];;

        // print_r($new_container_settings);
        print("---------------------------\n");

        print_r($pve2->post("/nodes/" . $first_node . "/openvz", $new_container_settings));
        print("\n\n");
        $valide = 1;
        $bdd = new PDO('mysql:host=localhost;dbname=vps', 'root', 'password');
        while ($valide == 1) {

            $bdd->query("INSERT INTO `vpsok` (`ostemplate`, `vmid`, `cpus`,`disk`,`hostname`,`memory`,`nameserver`,`date`)) VALUES ('" . $new_container_settings['vmid'] . "','" . $new_container_settings['cpus'] . "',NOW())");

        }

        //Ici on va envoyer un email , à nous meme est à la personne pour lui dire que son vps est en cours de réalisation


    } else {
        print("Login to Proxmox Host failed.\n");
        exit;
    }
}

#Require The Proxmox Api PHP LIB Is on the github repesotory

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.