Skip to content

Commit 1092bd9

Browse files
Building the Rocket :) - v 0.1
1 parent 10e5240 commit 1092bd9

File tree

10 files changed

+288
-0
lines changed

10 files changed

+288
-0
lines changed

.github/workflows/build-zip.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Package Repository as Zip
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
package:
12+
name: Create Zip File
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Repository
16+
uses: actions/checkout@v3
17+
18+
- name: Create Zip File
19+
run: zip -r chatgpt-installer.zip . -x "*.git*" -x "*.github*"
20+
21+
- name: Upload Repository as Artifact
22+
uses: actions/upload-artifact@v4
23+
with:
24+
name: chatgpt-installer
25+
path: chatgpt-installer.zip

core.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
// Check if the file is being accessed through a browser
4+
if (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) {
5+
// Redirect to /
6+
header("Location: /");
7+
exit;
8+
} else {
9+
// Redirect to /
10+
header("Location: /");
11+
exit;
12+
}
13+
14+
?>

error.css

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@import url('https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css');
2+
3+
/* Add your custom CSS code here */
4+
.errorcode {
5+
display: flex;
6+
justify-content: center;
7+
align-items: center;
8+
height: 100vh;
9+
text-align: center;
10+
}

error.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
// FILEPATH: /mayurjobanputra/ChatGPT-wrapper-in-PHP-MySQL/error.php
3+
// Get the error code from the query string
4+
$errorCode = $_GET['error'] ?? '9999';
5+
6+
// Define an array of error codes and their corresponding messages
7+
$errorMessages = [
8+
'1000' => 'Error Code 1000. Administrator has been notified.',
9+
'1001' => 'Error Code 1001. Administrator has been notified.',
10+
'1002' => 'Error Code 1002. Administrator has been notified.',
11+
'1003' => 'Error Code 1003. Administrator has been notified.',
12+
'9999' => 'Hello Bot :)',
13+
// Add more error codes and messages as needed
14+
];
15+
16+
// Check if the error code exists in the array
17+
if (array_key_exists($errorCode, $errorMessages)) {
18+
// Display the error message
19+
?>
20+
<!DOCTYPE html>
21+
<html>
22+
<head>
23+
<title>Error Page</title>
24+
</head>
25+
<body>
26+
<?php
27+
echo '<p class="errorcode">' . $errorMessages[$errorCode] . '</p>';
28+
?>
29+
</body>
30+
</html>
31+
<?php
32+
} else {
33+
// Display a generic error message
34+
echo 'Hello BadBot! :)';
35+
}
36+
37+
// Log errors to error.log file
38+
if (isset($_GET['error'])) {
39+
$errorLog = date('Y-m-d H:i:s') . ' - Error ' . $errorCode . PHP_EOL;
40+
file_put_contents('error.log', $errorLog, FILE_APPEND);
41+
}
42+
?>

footer.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
// Check if the request is coming from a browser
4+
if (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) {
5+
// Redirect to /
6+
header("Location: /");
7+
exit;
8+
} else {
9+
// Redirect to /
10+
header("Location: /");
11+
exit;
12+
}
13+
14+
?>

header.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
// Check if the request is coming from a browser
4+
if (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) {
5+
// Redirect to /
6+
header("Location: /");
7+
exit;
8+
} else {
9+
// Redirect to /
10+
header("Location: /");
11+
exit;
12+
}
13+
14+
?>

index.php

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* File: index.php
4+
* Version: 0.1
5+
* Description: Main entry point of the application.
6+
*/
7+
8+
9+
10+
11+
// Function to redirect to error.php with a unique error number
12+
function redirectToError($errorCode) {
13+
$errorNumber = $errorCode; // Generate a unique 4-digit error number
14+
header("Location: error.php?error=$errorNumber");
15+
exit;
16+
}
17+
18+
// Include the core.php file
19+
$errorCode = 1000;
20+
if (file_exists('core.php')) {
21+
require_once 'core.php';
22+
} else {
23+
redirectToError($errorCode++);
24+
}
25+
26+
// Include the header.php file
27+
if (file_exists('header.php')) {
28+
require_once 'header.php';
29+
} else {
30+
$errorCode = 1001;
31+
redirectToError($errorCode++);
32+
}
33+
34+
// Include the page.php file
35+
if (file_exists('page.php')) {
36+
require_once 'page.php';
37+
} else {
38+
$errorCode = 1002;
39+
redirectToError($errorCode++);
40+
}
41+
42+
// Include the footer.php file
43+
if (file_exists('footer.php')) {
44+
require_once 'footer.php';
45+
} else {
46+
$errorCode = 1003;
47+
redirectToError($errorCode++);
48+
}
49+
50+
// Rest of your code for header, page, and footer
51+
// ...
52+
?>

install/index.php

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
// Check if the form is submitted
4+
if ($_SERVER["REQUEST_METHOD"] == "POST") {
5+
// Retrieve the MySQL login information from the form
6+
$server = $_POST["server"];
7+
$username = $_POST["username"];
8+
$password = $_POST["password"];
9+
10+
// Attempt to connect to MySQL server
11+
$conn = mysqli_connect($server, $username, $password);
12+
13+
// Check if the connection was successful
14+
if ($conn) {
15+
// Create the database if it doesn't exist
16+
$randomNumber = rand(10000, 99999);
17+
$randomLetters = substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 5);
18+
$database = "ChatGPT_" . $randomNumber . "_" . $randomLetters;
19+
$createDatabaseQuery = "CREATE DATABASE IF NOT EXISTS $database";
20+
mysqli_query($conn, $createDatabaseQuery);
21+
22+
// Check if the database already exists
23+
$existingDatabaseQuery = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME LIKE 'ChatGPT_%'";
24+
$existingDatabaseResult = mysqli_query($conn, $existingDatabaseQuery);
25+
$existingDatabases = mysqli_fetch_all($existingDatabaseResult, MYSQLI_ASSOC);
26+
$existingDatabaseNames = array_column($existingDatabases, 'SCHEMA_NAME');
27+
if (in_array($database, $existingDatabaseNames)) {
28+
// Close the database connection
29+
mysqli_close($conn);
30+
31+
// Display an error message if the database already exists
32+
$error = "Installation failed. An existing database starting with 'ChatGPT_' already exists.";
33+
} else {
34+
// Select the database
35+
mysqli_select_db($conn, $database);
36+
37+
// Read the SQL queries from the install.sql file
38+
$sqlQueries = file_get_contents('install.sql');
39+
40+
// Execute the SQL queries
41+
mysqli_multi_query($conn, $sqlQueries);
42+
43+
// Close the database connection
44+
mysqli_close($conn);
45+
46+
// Redirect to the next step of the installation wizard
47+
header("Location: next_step.php");
48+
exit;
49+
}
50+
} else {
51+
// Display an error message if the connection failed
52+
$error = "Failed to connect to MySQL server. Please check your login information.";
53+
}
54+
}
55+
?>
56+
57+
<!DOCTYPE html>
58+
<html>
59+
<head>
60+
<title>Installation Wizard - Step 1</title>
61+
</head>
62+
<body>
63+
<h1>Installation Wizard - Step 1</h1>
64+
<?php if (isset($error)) { ?>
65+
<p style="color: red;"><?php echo $error; ?></p>
66+
<?php } ?>
67+
<form method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
68+
<label for="server">MySQL Server:</label>
69+
<input type="text" name="server" id="server" required><br><br>
70+
<label for="username">Username:</label>
71+
<input type="text" name="username" id="username" required><br><br>
72+
<label for="password">Password:</label>
73+
<input type="password" name="password" id="password" required><br><br>
74+
<input type="submit" value="Connect">
75+
</form>
76+
</body>
77+
</html>

install/install.sql

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
CREATE TABLE IF NOT EXISTS users (
2+
id INT AUTO_INCREMENT PRIMARY KEY,
3+
email VARCHAR(255) NOT NULL,
4+
register_date DATETIME NOT NULL,
5+
last_login DATETIME,
6+
username VARCHAR(255) NOT NULL,
7+
user_status VARCHAR(255),
8+
user_role VARCHAR(255)
9+
);
10+
11+
CREATE TABLE IF NOT EXISTS chats (
12+
id INT AUTO_INCREMENT PRIMARY KEY,
13+
chat_message TEXT NOT NULL,
14+
message_date DATETIME NOT NULL,
15+
message_owner INT NULL,
16+
FOREIGN KEY (message_owner) REFERENCES users(id)
17+
);
18+
19+
CREATE TABLE IF NOT EXISTS app_settings (
20+
id INT AUTO_INCREMENT PRIMARY KEY,
21+
setting_key VARCHAR(255) NOT NULL,
22+
setting_value VARCHAR(255),
23+
date_changed DATETIME,
24+
date_created DATETIME,
25+
version VARCHAR(255)
26+
);

page.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
// Check if the request is coming from a browser
4+
if (isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) {
5+
// Redirect to /
6+
header("Location: /");
7+
exit;
8+
} else {
9+
// Redirect to /
10+
header("Location: /");
11+
exit;
12+
}
13+
14+
?>

0 commit comments

Comments
 (0)