<?php

require_once __DIR__ . '/init.php';

use Illuminate\Database\Capsule\Manager as Capsule;

if (!function_exists('decrypt')) {
    require_once __DIR__ . '/includes/functions.php';
}

$servers = Capsule::table('tblservers')->get();

echo "<h2>WHMCS</h2>";
echo "<table border='1' cellpadding='6' cellspacing='0'>";
echo "<thead><tr>
    <th>ID</th>
    <th>Name</th>
    <th>IP</th>
    <th>Host</th>
    <th>Type</th>
    <th>Username</th>
    <th>Password</th>
    <td>Access Hash</td>
    <th>Port</th>
    <th>Active</th>
</tr></thead><tbody>";

foreach ($servers as $server) {
    $decryptedPassword = decrypt($server->password);

    echo "<tr>
        <td>{$server->id}</td>
        <td>{$server->name}</td>
        <td>{$server->ipaddress}</td>
        <td>{$server->hostname}</td>
        <td>{$server->type}</td>
        <td>{$server->username}</td>
        <td>{$decryptedPassword}</td>
        <td>{$server->accesshash}</td>
        <td>{$server->port}</td>
        <td>{$server->active}</td>
    </tr>";
}

echo "</tbody></table>";
