102 lines
3.9 KiB
PHP
102 lines
3.9 KiB
PHP
<?php
|
|
$config_file = 'google-config.php';
|
|
$error_message = '';
|
|
$success_message = '';
|
|
|
|
// Check if the form has been submitted
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// Get the submitted values
|
|
$client_id = $_POST['client_id'] ?? '';
|
|
$client_secret = $_POST['client_secret'] ?? '';
|
|
|
|
if (!empty($client_id) && !empty($client_secret)) {
|
|
// Read the existing config file
|
|
$config_content = file_get_contents($config_file);
|
|
|
|
if ($config_content !== false) {
|
|
// Replace the placeholder values
|
|
$config_content = preg_replace("/define\('GOOGLE_CLIENT_ID', '.*'\);/", "define('GOOGLE_CLIENT_ID', '$client_id');", $config_content);
|
|
$config_content = preg_replace("/define\('GOOGLE_CLIENT_SECRET', '.*'\);/", "define('GOOGLE_CLIENT_SECRET', '$client_secret');", $config_content);
|
|
|
|
// Write the updated content back to the file
|
|
if (file_put_contents($config_file, $config_content) !== false) {
|
|
$success_message = 'Your Google API credentials have been saved successfully!';
|
|
} else {
|
|
$error_message = 'Error: Unable to write to the configuration file. Please check file permissions.';
|
|
}
|
|
} else {
|
|
$error_message = 'Error: Unable to read the configuration file.';
|
|
}
|
|
} else {
|
|
$error_message = 'Please provide both Client ID and Client Secret.';
|
|
}
|
|
}
|
|
|
|
// Read the current values to display them (or placeholders)
|
|
$current_client_id = '';
|
|
$current_client_secret = '';
|
|
if (file_exists($config_file)) {
|
|
$config_content = file_get_contents($config_file);
|
|
if (preg_match("/define\('GOOGLE_CLIENT_ID', '(.*)'\);/", $config_content, $matches)) {
|
|
$current_client_id = $matches[1];
|
|
}
|
|
if (preg_match("/define\('GOOGLE_CLIENT_SECRET', '(.*)'\);/", $config_content, $matches)) {
|
|
$current_client_secret = $matches[1];
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Google API Setup</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
background-color: #f8f9fa;
|
|
}
|
|
.setup-container {
|
|
max-width: 600px;
|
|
margin: 50px auto;
|
|
padding: 30px;
|
|
background-color: #fff;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="setup-container">
|
|
<h2 class="text-center mb-4">Google API Setup</h2>
|
|
|
|
<?php if ($error_message): ?>
|
|
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($success_message): ?>
|
|
<div class="alert alert-success"><?php echo $success_message; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="POST" action="setup.php">
|
|
<div class="mb-3">
|
|
<label for="client_id" class="form-label">Google Client ID</label>
|
|
<input type="text" class="form-control" id="client_id" name="client_id" value="<?php echo htmlspecialchars($current_client_id); ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="client_secret" class="form-label">Google Client Secret</label>
|
|
<input type="password" class="form-control" id="client_secret" name="client_secret" value="<?php echo htmlspecialchars($current_client_secret); ?>" required>
|
|
</div>
|
|
<div class="d-grid">
|
|
<button type="submit" class="btn btn-primary">Save Credentials</button>
|
|
</div>
|
|
</form>
|
|
<div class="text-center mt-3">
|
|
<a href="index.php">Back to Home</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|