Php code for textbox input for keygenerator

Hi
I am quite new with PHP, but trying to run a keygenerator script on my ubuntu/apache webserver.
image

I want it to look like this on a website, and when i enter serialnr it generate a password.

The keygenerator script it self i have tested in php with ssh2.
What i need is how to make the fill in textbox come to the “serial” in keygen example (0Z35000711) and write a readable output.

If i run this script belov the php shows me the password.
Anybody please help? :slight_smile:

<?php
      
    $host = '192.168.1.9';
    $port = 22;
    $username = 'user';
    $password = 'password';
  
    $connection = ssh2_connect($host, $port);
    ssh2_auth_password($connection, $username, $password);
  
    $stream = ssh2_exec($connection, '/home/plex/Desktop/pwgen/gkey.sh 0Z35000711');
    stream_set_blocking($stream, true);
    $output = stream_get_contents($stream);
    echo "<pre>";
    print_r($output);
    echo "<pre>";
?>

Create a simple HTML form and submit the serial number via a POST request to your PHP script. Then, you can use this serial number as an argument in your ssh2_exec function.

HTML Form (let’s call this form.html ):

<!DOCTYPE html>
<html>
<head>
    <title>Key Generator</title>
</head>
<body>
    <form action="keygen.php" method="post">
        <label for="serial">Serial Number:</label>
        <input type="text" id="serial" name="serial">
        <input type="submit" value="Generate Key">
    </form>
</body>
</html>

PHP Script (let’s call this keygen.php ):

<?php
if(isset($_POST['serial'])) {
    $serial = $_POST['serial'];

    $host = '192.168.1.9';
    $port = 22;
    $username = 'user';
    $password = 'password';

    $connection = ssh2_connect($host, $port);
    ssh2_auth_password($connection, $username, $password);

    $stream = ssh2_exec($connection, '/home/plex/Desktop/pwgen/gkey.sh ' . $serial);
    stream_set_blocking($stream, true);
    $output = stream_get_contents($stream);

    echo "<pre>";
    print_r($output);
    echo "<pre>";
} else {
    header("Location: form.html"); // Redirect to the form if there's no serial number in POST request
    exit;
}
?>

The sent POST request to keygen.php will then run the key generator with the submitted serial number. The key that the generator produces will then be displayed in the browser.

Good luck

Sponsor our Newsletter | Privacy Policy | Terms of Service