<?php

include_once '/pineapple/includes/api/tile_functions.php';
global $directory, $rel_dir;
require_once '/pineapple/components/infusions/torgateway/functions.php';
if (!is_tor_installed()) {
    echo "<h3>Before continuing, you need to install Tor.</h3>";
    echo "<button onclick='torgateway_take_action(\"install_tor\",\"tor_result\")'>Install Tor</button>";
} else {
    if (tor_proc_status() == 3) {
        echo "<h3 style=color:red;>Tor is not currently running.</h3>";
        echo "<button onclick='torgateway_take_action(\"toggle_tor\",\"tor_result\")'>Start Tor</button>";
    } else {
        if (tor_proc_status() == 2) {
            echo "<h3 style=color:blue;>Tor is coming online. Watch the logs below for bootstrap status</h3>";
        } else {
            echo "<h3 style=color:green;>Tor is running.</h3>";
            echo "<button onclick='torgateway_take_action(\"toggle_tor\",\"tor_result\")'>Stop Tor</button>";
        }
    }
}
function tor_new_identity()
{
    # Check to see if tor is even running
    if (tor_proc_status() == FALSE) {
        die('Tor is not running');
    }
    $value = tor_control('SIGNAL NEWNYM');
    if (substr($value, 0, 6) == "250 OK") {
        echo $value;
    } else {
        echo $value;
    }
}
<?php

include_once '/pineapple/includes/api/tile_functions.php';
global $directory, $rel_dir;
require_once '/pineapple/components/infusions/torgateway/functions.php';
$status = tor_proc_status();
if ($status == 1) {
    $msg = '<span style=color:green;>Running</span>';
    $cStatus = tor_circuit_status();
} else {
    if ($status == 3) {
        $msg = '<span style=color:red;>Stopped</span>';
    } else {
        if ($status == 2) {
            $msg = '<span style=color:blue;>Tor Coming Up</span>';
            $cStatus = tor_circuit_status();
        }
    }
}
echo "<div>Tor status: " . $msg . "</div>";
if ($status == 3) {
    echo "<button onclick=torgateway_take_action('toggle_tor','mini_tor_result')>Start Tor</button>";
} else {
    echo "<div>Circuit status: " . ($cStatus ? '<span style=color:green;>Connected</span>' : '<span style=color:blue;>Connecting</span>') . "</div>";
    echo "<a href=javascript:torgateway_take_action('tor_new_identity','mini_tor_result')>New identity</a>";
}