fix some stuff to use .NET OMS, and allow viewing of certain credentials

This commit is contained in:
Michael Becker 2024-12-21 00:25:05 -05:00
parent 2a964d1b5c
commit b289d26c89

View File

@ -289,33 +289,79 @@ EOF
</thead> </thead>
<tbody> <tbody>
<?php <?php
global $pdo; $use_dotnet = true;
global $basepath;
$query = "SELECT * FROM mocha_tenants"; if ($use_dotnet)
$stmt = $pdo->prepare($query);
$result = $stmt->execute();
$rows = $stmt->fetchAll();
foreach ($rows as $values)
{ {
if ($values["is_library"] != 0) // using .NET OMS
$curl = curl_init("http://localhost:4436/tenants");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if ($curl == false)
{ {
continue;
} }
?> else
<tr> {
<td><a class="uwt-external-link" target="_blank" href="<?php echo("https://" . $basepath . "/" . $values["tenant_name"]); ?>"><?php echo ($values["tenant_name"]); ?></a></td> $result = curl_exec($curl);
<td>Active</td> $json = json_decode($result, true);
<td>Development</td> if ($json["result"] == "success")
<td>Local</td> {
<td>No Charge</td> foreach ($json["tenants"] as $tenant)
<td></td> {
<td></td> ?>
<td></td> <tr>
<td></td> <td><?php echo($tenant); ?></td>
<td><?php echo($values["tenant_purpose"]); ?></td> <td>Active</td>
</tr> <td>Development</td>
<?php <td>Local</td>
<td>No Charge</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<?php
}
}
}
}
else
{
global $pdo;
global $basepath;
$query = "SELECT * FROM mocha_tenants";
$stmt = $pdo->prepare($query);
try
{
$result = $stmt->execute();
$rows = $stmt->fetchAll();
foreach ($rows as $values)
{
if ($values["is_library"] != 0)
{
continue;
}
?>
<tr>
<td><a class="uwt-external-link" target="_blank" href="<?php echo("https://" . $basepath . "/" . $values["tenant_name"]); ?>"><?php echo ($values["tenant_name"]); ?></a></td>
<td>Active</td>
<td>Development</td>
<td>Local</td>
<td>No Charge</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><?php echo($values["tenant_purpose"]); ?></td>
</tr>
<?php
}
}
catch (\Exception $ex)
{
echo ("<tr><td colspan=\"10\">" . $ex . "</td></tr>");
}
} }
?> ?>
</tbody> </tbody>
@ -363,6 +409,48 @@ EOF
}; };
$tabContainer->TabPages[] = $page; $tabContainer->TabPages[] = $page;
global $passwd_file;
$passwd_file = "/etc/mocha/passwd";
if (file_exists($passwd_file))
{
$page = new TabPage();
$page->Title = "Access";
$page->Content = function()
{
global $passwd_file;
?>
<h1>SFTP Accounts</h1>
<p>Use these details to log into your SUV for SFTP transfers.</p>
<p>
<strong>These credentials are stored as plain text and should not be used in production environments.</strong>
To push changes from your SUV to a production server, run <em>mocha suv migrate</em> from a shell.
</p>
<table class="uwt-listview">
<thead>
<tr>
<th>User name</th>
<th>Password</th>
</tr>
</thead>
<tbody>
<?php
$contents = file_get_contents($passwd_file);
$lines = explode("\n", $contents);
foreach ($lines as $line)
{
if (trim($line) == "") continue;
$lineSplit = explode(":", $line);
if (count($lineSplit) != 2) continue;
echo ("<tr><td>" . trim($lineSplit[0]) . "</td><td>" . trim($lineSplit[1]) . "</td></tr>");
}
?>
</tbody>
</table>
<?php
};
$tabContainer->TabPages[] = $page;
}
$tabContainer->Render(); $tabContainer->Render();
} }