Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cp -r /app/src/ /var/www/tmp/
chmod +x /app/dockcheck.sh
chmod +x /app/watcher.sh
cp /var/www/tmp/src/index.php /var/www/html/index.php
cp /var/www/tmp/src/api.php /var/www/html/api.php
cp /var/www/tmp/src/style.css /var/www/html/style.css
touch /var/www/html/update.txt
chown www-data:www-data /var/www/html/*
Expand Down
37 changes: 37 additions & 0 deletions app/src/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
ini_set('max_execution_time', '300');
set_time_limit(300);

header("Content-Type: application/json; charset=UTF-8");

$filename = '/app/containers';
$f = fopen($filename, 'r');

if ($f) {
$contents = fread($f, filesize($filename));
fclose($f);
preg_match("/(?<=Containers with errors, wont get updated:\n)(?s).*?(?=\n\n)/", $contents, $conerror_match);
$string_output_error = implode('', $conerror_match);
$conerror_match = preg_split('`\n`', $string_output_error);

preg_match("/(?<=Containers on latest version:\n)(?s).*?(?=\n\n)/", $contents, $conlatest_match);
$string_output_latest = implode('', $conlatest_match);
$conlatest_match = preg_split('`\n`', $string_output_latest);

preg_match("/(?<=Containers with updates available:\n)(?s).*?(?=\n\n)/", $contents, $conupdate_match);
$string_output_update = implode('', $conupdate_match);
$conupdate_match = preg_split('`\n`', $string_output_update);
}

sort($conlatest_match);
sort($conupdate_match);
sort($conerror_match);

$latest = array_values($conlatest_match);
$updates = array_values($conupdate_match);
$errors = array_values($conerror_match);

$api_response = array( 'latest' => $latest, 'updates' => $updates, 'errors' => $errors );

echo json_encode($api_response);
?>
4 changes: 4 additions & 0 deletions app/src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,9 @@ function bg()
</div>
</div>

<div class="row">
<a href=api.php>JSON API</a>
</div>

</body>
</html>