Skip to content

Commit

Permalink
Store newsoftware in database
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdtrekkie committed Jun 22, 2024
1 parent 9da80eb commit 6228a25
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
20 changes: 12 additions & 8 deletions .sandstorm/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,19 @@ HOME=/etc/mysql /usr/sbin/mysqld --skip-grant-tables &
# Wait until mysql and php have bound their sockets, indicating readiness
wait_for mysql /var/run/mysqld/mysqld.sock

if [ ! -e /var/.db-2406.1 ]; then
if [ ! -e /var/.db-created ]; then
mysql --user root -e 'CREATE DATABASE app'
mysql --user root --database app < /opt/app/install_into_db.sql
mysql --user root --database app < /opt/app/install_into_db_sync.sql
touch /var/.db-created
if [ ! -e /var/.db-2406.2 ]; then
if [ ! -e /var/.db-2406.1 ]; then
if [ ! -e /var/.db-created ]; then
mysql --user root -e 'CREATE DATABASE app'
mysql --user root --database app < /opt/app/install_into_db.sql
mysql --user root --database app < /opt/app/install_into_db_sync.sql
touch /var/.db-created
fi
mysql --user root --database app < /opt/app/install_into_db_sync_2406.1.sql
touch /var/.db-2406.1
fi
mysql --user root --database app < /opt/app/install_into_db_sync_2406.1.sql
touch /var/.db-2406.1
mysql --user root --database app < /opt/app/install_into_db_sync_2406.2.sql
touch /var/.db-2406.2
fi

wait_for php-fpm8.2 /var/run/php/php8.2-fpm.sock
Expand Down
12 changes: 11 additions & 1 deletion api/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,17 @@
if ($message_type == "nodedata" && $destination == "server" && $message = "newsoftware") {
// This is a node updating it's installed software list
$requestBody = file_get_contents('php://input');
error_log($requestBody);
$softwareData = json_decode($requestBody);
foreach ($softwareData->newsoftware as $software) {
$appname = $software->Name;
$appver = $software->Version;
$apppub = $software->Publisher;
$appdate = $software->InstallDate;
$storeapps = mysqli_prepare($xrf_db, "INSERT INTO y_nodesoftware (descr, name, ver, pub, date) VALUES (?, ?, ?, ?. ?)");
mysqli_stmt_bind_param($storeapps, "sssss", $descr, $appname, $appver, $apppub, $appdate);
mysqli_stmt_execute($storeapps) or die (mysqli_error($xrf_db));
http_response_code(200); echo "[]";
}
$handled = true;
}

Expand Down
9 changes: 9 additions & 0 deletions install_into_db_sync_2406.2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS `y_nodesoftware` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`descr` varchar(32) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Node software is installed on',
`appname` varchar(128) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Name of software',
`appver` varchar(32) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Version of software',
`apppub` varchar(128) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Publisher of software',
`appdate` varchar(16) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Install date of software',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Software installed on nodes';

0 comments on commit 6228a25

Please sign in to comment.