load(); // Check if the user's IP matches the allowed IP $allowed_ip = $_ENV['ALLOWED_IP']; $user_ip = $_SERVER['REMOTE_ADDR']; if ($user_ip !== $allowed_ip) { // If IP address doesn't match, show an error message and exit header('HTTP/1.0 403 Forbidden'); echo "Access denied."; exit; } include 'db.php'; // Handle deletion of an entry if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['delete'])) { $id = intval($_POST['delete']); // Prepare and bind $stmt = $conn->prepare("DELETE FROM phonebook WHERE id = ?"); $stmt->bind_param("i", $id); // Execute the statement if ($stmt->execute()) { $success_message = "Entry deleted successfully!"; } else { $error_message = "Error: " . $stmt->error; } // Close the statement $stmt->close(); } // Handle adding a new phonebook entry if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['tilde_name']) && isset($_POST['extension']) && isset($_POST['username'])) { $tilde_name = htmlspecialchars($_POST['tilde_name']); $extension = htmlspecialchars($_POST['extension']); $username = htmlspecialchars($_POST['username']); // Prepare and bind $stmt = $conn->prepare("INSERT INTO phonebook (tilde_name, extension, username) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $tilde_name, $extension, $username); // Execute the statement if ($stmt->execute()) { $success_message = "New entry added successfully!"; } else { $error_message = "Error: " . $stmt->error; } // Close the statement $stmt->close(); } // Handle sending the confirmation email if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['send_email'])) { $extension = htmlspecialchars($_POST['extension']); $pbxPassword = htmlspecialchars($_POST['pbx_password']); $ucpPassword = htmlspecialchars($_POST['ucp_password']); $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); // Prepare the email content $subject = "Your tilde.tel Account Details"; $message = "Here are your account details:\n\n" . "For VOIP Application:\n\n" . "Extension: $extension\n" . "Password: $pbxPassword\n" . "Server name: connect.tilde.tel\n" . "Port: 5060 (UDP)\n" . "Voicemail Password: Your extension number is your temporary password. Please dial the voicemail to change this.\n\n" . "For User Control Panel:\n\n" . "Username: $extension\n" . "Password: $ucpPassword\n" . "Access control panel at:\n\n" . "https://connect.tilde.tel/ucp\n\n" . "Thanks,\n\n~deepend"; $headers = "From: no-reply@tilde.tel\r\n"; $headers .= "Cc: signup@tilde.tel\r\n"; // Send the email if (mail($email, $subject, $message, $headers)) { $success_message = "Email sent successfully to $email!"; } else { $error_message = "Error sending email to $email."; } } // Fetch all entries with a username $sql = "SELECT id, tilde_name, extension, username FROM phonebook WHERE username IS NOT NULL AND username != '' ORDER BY tilde_name, extension"; $users_result = $conn->query($sql); // Fetch all pending entries (without a username) $sql = "SELECT id, tilde_name, extension FROM phonebook WHERE username IS NULL OR username = '' ORDER BY tilde_name, extension"; $pending_result = $conn->query($sql); // Determine which section to show based on the query parameter $section = isset($_GET['section']) ? $_GET['section'] : 'users'; ?> Admin - Phonebook Management

Phonebook Management

$success_message

"; } if (isset($error_message)) { echo "

$error_message

"; } ?>

Existing Users

num_rows > 0) { $currentTilde = ''; while($row = $users_result->fetch_assoc()) { if ($currentTilde != $row['tilde_name']) { if ($currentTilde != '') { echo "
"; // Close previous content div and table } $currentTilde = $row['tilde_name']; echo ""; echo "
"; echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Extension Username Action
{$row['extension']}{$row['username']}
"; // Close the last table and content div } else { echo "

No users found.

"; } ?>

Pending Entries (No Username)

num_rows > 0) { while($row = $pending_result->fetch_assoc()) { echo ""; echo ""; echo ""; echo ""; echo ""; } } else { echo ""; } ?>
Tilde Name Extension Action
{$row['tilde_name']}{$row['extension']}
No pending entries.

Add a New Phonebook Entry

Send Signup Confirmation Email

close(); ?>