From 14cc0ec57acf60c0253f7e20a2d11c8ca505f25d Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Mon, 16 Jun 2025 00:38:47 +0300 Subject: [PATCH] debugging... --- README.txt | 10 ++++++++++ configs/php.ini | 4 ++++ main/index.php | 24 ++++++++++++++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 configs/php.ini diff --git a/README.txt b/README.txt index 491af1f..fd9f4f6 100644 --- a/README.txt +++ b/README.txt @@ -13,6 +13,9 @@ Installation: CentOS: yum install httpd php php-mysqlnd mariadb-server cp configs/apache.conf.centos /etc/httpd/conf.d/text0nly.conf + cp configs/php.ini /etc/php.ini + chown -R apache:apache /var/www/html/main + chmod -R 755 /var/www/html/main systemctl start mariadb systemctl enable mariadb systemctl start httpd @@ -21,6 +24,9 @@ CentOS: Alpine: apk add apache2 php php-mysql mariadb cp configs/apache.conf.debian /etc/apache2/sites-available/text0nly.conf + cp configs/php.ini /etc/php/php.ini + chown -R www-data:www-data /var/www/html/main + chmod -R 755 /var/www/html/main ln -s /etc/apache2/sites-available/text0nly.conf /etc/apache2/sites-enabled/ rc-update add mariadb default rc-update add apache2 default @@ -30,6 +36,9 @@ Alpine: Debian: apt install apache2 php mariadb-server cp configs/apache.conf.debian /etc/apache2/sites-available/text0nly.conf + cp configs/php.ini /etc/php/php.ini + chown -R www-data:www-data /var/www/html/main + chmod -R 755 /var/www/html/main a2ensite text0nly.conf systemctl start mariadb systemctl enable mariadb @@ -41,6 +50,7 @@ Files: configs/ - Server configs configs/apache.conf.centos - Apache config for CentOS configs/apache.conf.debian - Apache config for Debian/Alpine + configs/php.ini - PHP configuration main/db.sql - Database structure main/index.php - Main page main/register.php - Registration diff --git a/configs/php.ini b/configs/php.ini new file mode 100644 index 0000000..4103d64 --- /dev/null +++ b/configs/php.ini @@ -0,0 +1,4 @@ +display_errors = On +error_reporting = E_ALL +log_errors = On +error_log = /var/log/php_errors.log \ No newline at end of file diff --git a/main/index.php b/main/index.php index 667d547..cad5fc9 100644 --- a/main/index.php +++ b/main/index.php @@ -4,8 +4,12 @@ header('X-Frame-Options: DENY'); header('X-XSS-Protection: 1; mode=block'); header('Content-Security-Policy: default-src \'self\''); -$db = new PDO('mysql:host=localhost;dbname=messenger', 'root', ''); -$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +try { + $db = new PDO('mysql:host=localhost;dbname=messenger', 'root', ''); + $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + die('Connection failed: ' . $e->getMessage()); +} if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING); @@ -14,15 +18,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $is_encrypted = isset($_POST['encrypted']); if ($username && $message) { - $stmt = $db->prepare('INSERT INTO messages (username, message, signature, is_encrypted) VALUES (?, ?, ?, ?)'); - $stmt->execute([$username, $message, $signature, $is_encrypted]); + try { + $stmt = $db->prepare('INSERT INTO messages (username, message, signature, is_encrypted) VALUES (?, ?, ?, ?)'); + $stmt->execute([$username, $message, $signature, $is_encrypted]); + } catch (PDOException $e) { + die('Database error: ' . $e->getMessage()); + } } header('Location: ' . $_SERVER['PHP_SELF']); exit; } -$stmt = $db->query('SELECT * FROM messages ORDER BY created_at DESC LIMIT 50'); -$messages = $stmt->fetchAll(PDO::FETCH_ASSOC); +try { + $stmt = $db->query('SELECT * FROM messages ORDER BY created_at DESC LIMIT 50'); + $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch (PDOException $e) { + die('Database error: ' . $e->getMessage()); +} ?>