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,11 +289,51 @@ EOF
</thead> </thead>
<tbody> <tbody>
<?php <?php
$use_dotnet = true;
if ($use_dotnet)
{
// using .NET OMS
$curl = curl_init("http://localhost:4436/tenants");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if ($curl == false)
{
}
else
{
$result = curl_exec($curl);
$json = json_decode($result, true);
if ($json["result"] == "success")
{
foreach ($json["tenants"] as $tenant)
{
?>
<tr>
<td><?php echo($tenant); ?></td>
<td>Active</td>
<td>Development</td>
<td>Local</td>
<td>No Charge</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<?php
}
}
}
}
else
{
global $pdo; global $pdo;
global $basepath; global $basepath;
$query = "SELECT * FROM mocha_tenants"; $query = "SELECT * FROM mocha_tenants";
$stmt = $pdo->prepare($query); $stmt = $pdo->prepare($query);
try
{
$result = $stmt->execute(); $result = $stmt->execute();
$rows = $stmt->fetchAll(); $rows = $stmt->fetchAll();
foreach ($rows as $values) foreach ($rows as $values)
@ -317,6 +357,12 @@ EOF
</tr> </tr>
<?php <?php
} }
}
catch (\Exception $ex)
{
echo ("<tr><td colspan=\"10\">" . $ex . "</td></tr>");
}
}
?> ?>
</tbody> </tbody>
</table> </table>
@ -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();
} }