-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_installation.php
More file actions
executable file
·199 lines (170 loc) · 5.3 KB
/
check_installation.php
File metadata and controls
executable file
·199 lines (170 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env php
<?php
echo "AdminLogPanel - Installation Check\n";
echo "===================================\n\n";
$errors = [];
$warnings = [];
$success = [];
// Check PHP version
echo "Checking PHP version... ";
if (version_compare(PHP_VERSION, '7.4.0', '>=')) {
echo "✓ " . PHP_VERSION . "\n";
$success[] = "PHP version OK";
} else {
echo "✗ " . PHP_VERSION . " (requires 7.4+)\n";
$errors[] = "PHP version too old";
}
// Check required extensions
echo "Checking PHP extensions:\n";
$required_extensions = ['pdo', 'pdo_pgsql', 'json'];
foreach ($required_extensions as $ext) {
echo " - $ext: ";
if (extension_loaded($ext)) {
echo "✓\n";
$success[] = "$ext extension loaded";
} else {
echo "✗ (required)\n";
$errors[] = "$ext extension not loaded";
}
}
// Check directory structure
echo "\nChecking directory structure:\n";
$required_dirs = [
'public_www',
'public_www/config',
'public_www/controllers',
'public_www/models',
'public_www/middleware',
'public_www/views',
'worker',
'worker/test'
];
foreach ($required_dirs as $dir) {
echo " - $dir: ";
if (is_dir(__DIR__ . '/' . $dir)) {
echo "✓\n";
$success[] = "$dir exists";
} else {
echo "✗\n";
$errors[] = "$dir not found";
}
}
// Check required files
echo "\nChecking required files:\n";
$required_files = [
'database.sql',
'public_www/index.php',
'public_www/config/database.php',
'public_www/config/router.php',
'public_www/models/Account.php',
'public_www/models/DataLog.php',
'public_www/controllers/AuthController.php',
'public_www/controllers/AdminController.php',
'public_www/controllers/UserController.php',
'public_www/middleware/AuthMiddleware.php',
'public_www/views/index.html',
'public_www/views/app.js',
'worker/worker.php',
'worker/GeoIP.php'
];
foreach ($required_files as $file) {
echo " - $file: ";
if (file_exists(__DIR__ . '/' . $file)) {
echo "✓\n";
$success[] = "$file exists";
} else {
echo "✗\n";
$errors[] = "$file not found";
}
}
// Check test data
echo "\nChecking test data:\n";
$test_dirs = glob(__DIR__ . '/worker/test/*', GLOB_ONLYDIR);
echo " - Test folders: " . count($test_dirs) . " found\n";
if (count($test_dirs) > 0) {
$success[] = "Test data present";
foreach ($test_dirs as $test_dir) {
$info = $test_dir . '/info.txt';
$country = $test_dir . '/country.txt';
if (!file_exists($info) || !file_exists($country)) {
$warnings[] = basename($test_dir) . " missing required files";
}
}
} else {
$warnings[] = "No test data folders found";
}
// Try to connect to database
echo "\nChecking database connection:\n";
$db_host = getenv('DB_HOST') ?: 'localhost';
$db_port = getenv('DB_PORT') ?: '5432';
$db_name = getenv('DB_NAME') ?: 'adminlogpanel';
$db_user = getenv('DB_USER') ?: 'postgres';
echo " - Host: $db_host:$db_port\n";
echo " - Database: $db_name\n";
echo " - User: $db_user\n";
echo " - Connecting: ";
try {
require_once __DIR__ . '/public_www/config/database.php';
$db = Database::getInstance()->getConnection();
echo "✓\n";
$success[] = "Database connection successful";
// Check tables
echo "\nChecking database tables:\n";
$stmt = $db->query("SELECT tablename FROM pg_tables WHERE schemaname = 'public' ORDER BY tablename");
$tables = $stmt->fetchAll(PDO::FETCH_COLUMN);
$required_tables = ['accounts', 'data_logs'];
foreach ($required_tables as $table) {
echo " - $table: ";
if (in_array($table, $tables)) {
echo "✓\n";
$success[] = "$table table exists";
} else {
echo "✗\n";
$errors[] = "$table table not found";
}
}
// Check accounts
echo "\nChecking default accounts:\n";
$stmt = $db->query("SELECT login, is_admin FROM accounts ORDER BY id");
$accounts = $stmt->fetchAll();
if (count($accounts) >= 2) {
foreach ($accounts as $account) {
echo " - {$account['login']} (" . ($account['is_admin'] ? 'admin' : 'user') . "): ✓\n";
}
$success[] = "Default accounts present";
} else {
$warnings[] = "Less than 2 accounts found";
}
} catch (Exception $e) {
echo "✗\n";
echo " Error: " . $e->getMessage() . "\n";
$errors[] = "Database connection failed: " . $e->getMessage();
}
// Summary
echo "\n===================================\n";
echo "Summary:\n";
echo " ✓ Success: " . count($success) . "\n";
echo " ⚠ Warnings: " . count($warnings) . "\n";
echo " ✗ Errors: " . count($errors) . "\n";
if (count($warnings) > 0) {
echo "\nWarnings:\n";
foreach ($warnings as $warning) {
echo " ⚠ $warning\n";
}
}
if (count($errors) > 0) {
echo "\nErrors:\n";
foreach ($errors as $error) {
echo " ✗ $error\n";
}
echo "\nPlease fix the errors before running the application.\n";
exit(1);
} else {
echo "\n✓ Installation check passed!\n";
echo "\nNext steps:\n";
echo " 1. Run: ./start_server.sh\n";
echo " 2. Open: http://localhost:8000\n";
echo " 3. Login with: admin / password\n";
echo " 4. Generate test data: cd worker && php worker.php 50\n";
exit(0);
}