diff --git a/cp/app/Controllers/ApplicationsController.php b/cp/app/Controllers/ApplicationsController.php index e0cbaa6..6e928e2 100644 --- a/cp/app/Controllers/ApplicationsController.php +++ b/cp/app/Controllers/ApplicationsController.php @@ -465,9 +465,17 @@ class ApplicationsController extends Controller $db->insert( 'error_log', [ - 'registrar_id' => $clid, - 'log' => "Application : $domainName ; hostName : $nameserver - is duplicated", - 'date' => $logdate + 'channel' => 'control_panel', + 'level' => 3, + 'level_name' => 'warning', + 'message' => "Application: $domainName; hostName: $nameserver - is duplicated", + 'context' => json_encode([ + 'registrar_id' => $clid, + 'domain' => $domainName, + 'host' => $nameserver + ]), + 'extra' => json_encode([]), + 'created_at' => $logdate ] ); } diff --git a/cp/app/Controllers/DomainsController.php b/cp/app/Controllers/DomainsController.php index eea7e46..0460854 100644 --- a/cp/app/Controllers/DomainsController.php +++ b/cp/app/Controllers/DomainsController.php @@ -748,9 +748,17 @@ class DomainsController extends Controller $db->insert( 'error_log', [ - 'registrar_id' => $clid, - 'log' => "Domain : $domainName ; hostName : $nameserver - is duplicated", - 'date' => $logdate + 'channel' => 'control_panel', + 'level' => 3, + 'level_name' => 'warning', + 'message' => "Domain: $domainName; hostName: $nameserver - is duplicated", + 'context' => json_encode([ + 'registrar_id' => $clid, + 'domain' => $domainName, + 'host' => $nameserver + ]), + 'extra' => json_encode([]), + 'created_at' => $logdate ] ); } diff --git a/cp/resources/views/partials/js-log.twig b/cp/resources/views/partials/js-log.twig index a673665..69cfe56 100644 --- a/cp/resources/views/partials/js-log.twig +++ b/cp/resources/views/partials/js-log.twig @@ -8,7 +8,7 @@ document.addEventListener("DOMContentLoaded", function(){ table = new Tabulator("#logsTable", { - ajaxURL:"/api/records/error_log?join=registrar", // Set the URL for your JSON data + ajaxURL:"/api/records/error_log", // Set the URL for your JSON data ajaxConfig:"GET", pagination:"local", paginationSize:10, @@ -20,14 +20,15 @@ responsiveLayoutCollapseStartOpen:false, resizableColumns:false, initialSort:[ - {column:"date", dir:"desc"}, // sorting by the "cldate" field in descending order + {column:"created_at", dir:"desc"}, // sorting by the "created_at" field in descending order ], placeholder: "{{ __('No Data') }}", columns:[ {formatter:"responsiveCollapse", width:30, minWidth:30, hozAlign:"center", resizable:false, headerSort:false, responsive:0}, - {title:"{{ __('Registrar') }}", field:"registrar_id.name", minWidth:200, resizable:false, headerSort:true, responsive:0}, - {title:"{{ __('Date') }}", field:"date", resizable:false, minWidth:300, headerSort:true, responsive:0}, - {title:"{{ __('Log') }}", field:"log", resizable:false, minWidth:600, headerSort:true, responsive:2}, + {title:"{{ __('Channel') }}", field:"channel", minWidth:200, resizable:false, headerSort:true, responsive:0}, + {title:"{{ __('Level') }}", field:"level_name", resizable:false, minWidth:200, headerSort:true, responsive:0}, + {title:"{{ __('Log') }}", field:"message", resizable:false, minWidth:550, headerSort:true, responsive:2}, + {title:"{{ __('Date') }}", field:"created_at", resizable:false, minWidth:250, headerSort:true, responsive:2}, ] }); var searchInput = document.getElementById("search-input"); @@ -38,9 +39,10 @@ table.setFilter(function (data) { // Check if any of the fields contain the search term return ( - String(data.registrar_id.name).toLowerCase().includes(term) || - String(data.date).toLowerCase().includes(term) || - String(data.log).toLowerCase().includes(term) + String(data.channel).toLowerCase().includes(term) || + String(data.level_name).toLowerCase().includes(term) || + String(data.message).toLowerCase().includes(term) || + String(data.created_at).toLowerCase().includes(term) ); }); } else { diff --git a/database/registry.mariadb.sql b/database/registry.mariadb.sql index 204a719..ba84ff1 100644 --- a/database/registry.mariadb.sql +++ b/database/registry.mariadb.sql @@ -81,12 +81,14 @@ CREATE TABLE IF NOT EXISTS `registry`.`allocation_tokens` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='allocation tokens'; CREATE TABLE IF NOT EXISTS `registry`.`error_log` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `registrar_id` INT(10) unsigned NOT NULL, - `log` TEXT NOT NULL, - `date` TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - CONSTRAINT `error_log_ibfk_1` FOREIGN KEY (`registrar_id`) REFERENCES `registrar` (`id`) + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `channel` VARCHAR(255), + `level` INT(3), + `level_name` VARCHAR(10), + `message` TEXT, + `context` JSON, + `extra` JSON, + `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP() ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='registry error log'; CREATE TABLE IF NOT EXISTS `registry`.`reserved_domain_names` ( diff --git a/database/registry.postgres.sql b/database/registry.postgres.sql index d60f456..510a339 100644 --- a/database/registry.postgres.sql +++ b/database/registry.postgres.sql @@ -79,10 +79,14 @@ CREATE TABLE allocation_tokens ( ); CREATE TABLE error_log ( - "id" SERIAL PRIMARY KEY, - "registrar_id" int CHECK ("registrar_id" >= 0) NOT NULL, - "log" TEXT NOT NULL, - "date" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP + "id" SERIAL PRIMARY KEY, + "channel" VARCHAR(255), + "level" INT, + "level_name" VARCHAR(10), + "message" TEXT, + "context" JSONB, + "extra" JSONB, + "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); CREATE TABLE reserved_domain_names ( @@ -846,8 +850,8 @@ INSERT INTO settings (name, value) VALUES ('address2', '48000'), ('cc', 'Ukraine'), ('vat_number', '12345678'), -('verifyEmail', NULL), -('verifyPhone', NULL), +('verifyEmail', NULL), +('verifyPhone', NULL), ('verifyPostal', NULL), ('phone', '+123456789'), ('handle', 'RXX'), diff --git a/docs/update1016.sh b/docs/update1016.sh new file mode 100644 index 0000000..db9f4bc --- /dev/null +++ b/docs/update1016.sh @@ -0,0 +1,175 @@ +#!/bin/bash + +# Ensure the script is run as root +if [[ $EUID -ne 0 ]]; then + echo "Error: This update script must be run as root or with sudo." >&2 + exit 1 +fi + +# Prompt the user for confirmation +echo "This will update Namingo Registry from v1.0.15 to v1.0.16." +echo "Make sure you have a backup of the database, /var/www/cp, and /opt/registry." +read -p "Are you sure you want to proceed? (y/n): " confirm + +# Check user input +if [[ "$confirm" != "y" ]]; then + echo "Upgrade aborted." + exit 0 +fi + +# Create backup directory +backup_dir="/opt/backup" +mkdir -p "$backup_dir" + +# Backup directories +echo "Creating backups..." +tar -czf "$backup_dir/cp_backup_$(date +%F).tar.gz" -C / var/www/cp +tar -czf "$backup_dir/whois_backup_$(date +%F).tar.gz" -C / var/www/whois +tar -czf "$backup_dir/registry_backup_$(date +%F).tar.gz" -C / opt/registry + +# Database credentials +config_file="/opt/registry/whois/port43/config.php" +db_user=$(grep "'db_username'" "$config_file" | awk -F "=> '" '{print $2}' | sed "s/',//") +db_pass=$(grep "'db_password'" "$config_file" | awk -F "=> '" '{print $2}' | sed "s/',//") +db_host=$(grep "'db_host'" "$config_file" | awk -F "=> '" '{print $2}' | sed "s/',//") + +# List of databases to back up +databases=("registry" "registryAudit" "registryTransaction") + +# Backup specific databases +for db_name in "${databases[@]}"; do + echo "Backing up database $db_name..." + sql_backup_file="$backup_dir/db_${db_name}_backup_$(date +%F).sql" + mysqldump -u"$db_user" -p"$db_pass" -h"$db_host" "$db_name" > "$sql_backup_file" + + # Compress the SQL backup file + echo "Compressing database backup $db_name..." + tar -czf "${sql_backup_file}.tar.gz" -C "$backup_dir" "$(basename "$sql_backup_file")" + + # Remove the uncompressed SQL file + rm "$sql_backup_file" +done + +# Stop services +echo "Stopping services..." +systemctl stop caddy +systemctl stop epp +systemctl stop whois +systemctl stop rdap +systemctl stop das +systemctl stop msg_producer +systemctl stop msg_worker + +# Clear cache +echo "Clearing cache..." +php /var/www/cp/bin/clear_cache.php + +# Clone the new version of the repository +echo "Cloning v1.0.16 from the repository..." +git clone --branch v1.0.16 --single-branch https://github.com/getnamingo/registry /opt/registry1016 + +# Copy files from the new version to the appropriate directories +echo "Copying files..." + +# Function to copy files and maintain directory structure +copy_files() { + src_dir=$1 + dest_dir=$2 + + if [[ -d "$src_dir" ]]; then + echo "Copying from $src_dir to $dest_dir..." + cp -R "$src_dir/." "$dest_dir/" + else + echo "Source directory $src_dir does not exist. Skipping..." + fi +} + +# Copy specific directories +copy_files "/opt/registry1016/automation" "/opt/registry/automation" +copy_files "/opt/registry1016/cp" "/var/www/cp" +copy_files "/opt/registry1016/whois/web" "/var/www/whois" +copy_files "/opt/registry1016/das" "/opt/registry/das" +copy_files "/opt/registry1016/whois/port43" "/opt/registry/whois/port43" +copy_files "/opt/registry1016/rdap" "/opt/registry/rdap" +copy_files "/opt/registry1016/epp" "/opt/registry/epp" +copy_files "/opt/registry1016/docs" "/opt/registry/docs" + +# Run composer update in copied directories (excluding docs) +echo "Running composer update..." + +composer_update() { + dir=$1 + if [[ -d "$dir" ]]; then + echo "Updating composer in $dir..." + cd "$dir" || exit + COMPOSER_ALLOW_SUPERUSER=1 composer update --no-interaction --quiet + else + echo "Directory $dir does not exist. Skipping composer update..." + fi +} + +# Update composer in relevant directories +composer_update "/opt/registry/automation" +composer_update "/var/www/cp" +composer_update "/opt/registry/das" +composer_update "/opt/registry/whois/port43" +composer_update "/opt/registry/rdap" +composer_update "/opt/registry/epp" + +CONFIG_FILE="/opt/registry/rdap/config.php" + +# Extract database credentials from the config file +DB_NAME=$(grep "'db_database'" "$CONFIG_FILE" | awk -F "=> " '{print $2}' | tr -d "',") +DB_USER=$(grep "'db_username'" "$CONFIG_FILE" | awk -F "=> " '{print $2}' | tr -d "',") +DB_PASS=$(grep "'db_password'" "$CONFIG_FILE" | awk -F "=> " '{print $2}' | tr -d "',") + +echo "Starting error_log table upgrade..." + +# Drop old table (if it exists) +echo "Dropping old error_log table..." +mysql -u$DB_USER -p$DB_PASS $DB_NAME -e "DROP TABLE IF EXISTS error_log;" 2>/dev/null + +if [ $? -ne 0 ]; then + echo "Warning: Failed to drop old error_log table. Continuing..." +fi + +# Create new table +echo "Creating new error_log table..." +mysql -u$DB_USER -p$DB_PASS $DB_NAME <prepare("INSERT INTO domain_host_map (domain_id,host_id) VALUES(:domain_id,:host_id)"); $insertDomainHostMapStmt->execute([':domain_id' => $domain_id, ':host_id' => $hostObj_already_exist]); } else { - $errorLogStmt = $db->prepare("INSERT INTO error_log (registrar_id,log,date) VALUES(:registrar_id,:log,CURRENT_TIMESTAMP(3))"); - $errorLogStmt->execute([':registrar_id' => $clid, ':log' => "Domain : $domainName ; hostObj : $hostObj - is duplicated"]); + $errorLogStmt = $db->prepare("INSERT INTO error_log + (channel, level, level_name, message, context, extra, created_at) + VALUES ('epp', 3, 'warning', :log, :context, '{}', CURRENT_TIMESTAMP)"); + $errorLogStmt->execute([ + ':log' => "Domain: $domainName; hostObj: $hostObj - is duplicated", + ':context' => json_encode(['registrar_id' => $clid, 'domain' => $domainName, 'host' => $hostObj]) + ]); } } else { $internal_host = false; @@ -1532,8 +1537,13 @@ function processDomainCreate($conn, $db, $xml, $clid, $database_type, $trans, $m $stmt->execute([$domain_id, $hostName_already_exist]); } else { // Log duplicate mapping error - $stmt = $db->prepare("INSERT INTO error_log (registrar_id, log, date) VALUES (?, ?, CURRENT_TIMESTAMP(3))"); - $stmt->execute([$clid, "Domain: $domainName ; hostName: $hostName - duplicate mapping"]); + $stmt = $db->prepare("INSERT INTO error_log + (channel, level, level_name, message, context, extra, created_at) + VALUES ('epp', 3, 'warning', ?, ?, '{}', CURRENT_TIMESTAMP)"); + $stmt->execute([ + "Domain: $domainName; hostName: $hostName - duplicate mapping", + json_encode(['registrar_id' => $clid, 'domain' => $domainName, 'host' => $hostName]) + ]); } } else { // Insert a new host diff --git a/epp/src/epp-update.php b/epp/src/epp-update.php index 5b7e19e..5f23c76 100644 --- a/epp/src/epp-update.php +++ b/epp/src/epp-update.php @@ -1529,11 +1529,16 @@ function processDomainUpdate($conn, $db, $xml, $clid, $database_type, $trans) { return; } } else { - $stmt = $db->prepare("INSERT INTO error_log (registrar_id,log,date) VALUES(:registrar_id, :log, CURRENT_TIMESTAMP(3))"); - $log = "Domain : $domainName ; hostObj : $hostObj - is duplicated"; - $stmt->bindParam(':registrar_id', $clid, PDO::PARAM_INT); - $stmt->bindParam(':log', $log, PDO::PARAM_STR); - $stmt->execute(); + $logMessage = "Domain: $domainName; hostObj: $hostObj - is duplicated"; + $contextData = json_encode([ + 'registrar_id' => $clid, + 'domain' => $domainName, + 'host' => $hostObj + ]); + $stmt = $db->prepare("INSERT INTO error_log + (channel, level, level_name, message, context, extra, created_at) + VALUES ('epp', 3, 'warning', ?, ?, '{}', CURRENT_TIMESTAMP)"); + $stmt->execute([$logMessage, $contextData]); } } else { $host_from_this_registry = 0; @@ -1625,9 +1630,16 @@ function processDomainUpdate($conn, $db, $xml, $clid, $database_type, $trans) { return; } } else { - $logMessage = "Domain : $domainName ; hostName : $hostName - is duplicated"; - $sth = $db->prepare("INSERT INTO error_log (registrar_id,log,date) VALUES(?, ?, CURRENT_TIMESTAMP(3))"); - if (!$sth->execute([$clid, $logMessage])) { + $logMessage = "Domain: $domainName; hostName: $hostName - is duplicated"; + $contextData = json_encode([ + 'registrar_id' => $clid, + 'domain' => $domainName, + 'host' => $hostName + ]); + $sth = $db->prepare("INSERT INTO error_log + (channel, level, level_name, message, context, extra, created_at) + VALUES ('epp', 3, 'warning', ?, ?, '{}', CURRENT_TIMESTAMP)"); + if (!$sth->execute([$logMessage, $contextData])) { sendEppError($conn, $db, 2400, 'Database error', $clTRID, $trans); return; }