Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('__ROOT__', dirname((__FILE__)));
- session_start();
- session_regenerate_id(true);
- /**********************************************************************/
- // Configuraion //
- /**********************************************************************/
- // SQL Database Connection
- $dbuser = 'root';
- $dbpass = '';
- // Date settings
- date_default_timezone_set('Asia/Bishkek');
- /**********************************************************************/
- // End configuration //
- /**********************************************************************/
- try {
- //open the database
- $db = new PDO('mysql:host=localhost;dbname=test;charset=utf8', $dbuser, $dbpass);
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch(PDOException $e) {
- error_log('Database exception: '.$e->getMessage(), 1, $supportEmail);
- echo('Exception: '.$e->getMessage());
- }
- function WifiAddUser($guest) {
- // Add a user to the database
- global $db;
- try {
- // Insert a new user database
- $sql = "INSERT INTO guests (username, password, expires, notes, download, upload) VALUES (:username, :password, :expires, :notes, :download, :upload)";
- $sth = $db->prepare($sql);
- $sth->bindParam(':username', $guest['username'], PDO::PARAM_STR);
- $sth->bindParam(':password', $guest['password'], PDO::PARAM_STR);
- $sth->bindParam(':expires', $guest['expires'], PDO::PARAM_INT);
- $sth->bindParam(':notes', $guest['notes'], PDO::PARAM_STR);
- $sth->bindParam(':download', $guest['download'], PDO::PARAM_INT);
- $sth->bindParam(':upload', $guest['upload'], PDO::PARAM_INT);
- $sth->execute();
- } catch(PDOException $e) {
- error_log('addUser exception: '.$guest['username'].' Message: '.$e->getMessage(), 0);
- return false;
- }
- // Everything went okay
- return true;
- }
- function WifiRemoveUser($id) {
- global $db;
- try {
- $sql = 'DELETE FROM guests WHERE id=:id';
- $sth = $db->prepare($sql);
- $sth->bindParam(':id', $id, PDO::PARAM_STR);
- $sth->execute();
- } catch(PDOException $e) {
- error_log('removeUser exception: '.$id.' Message: '.$e->getMessage(), 0);
- return false;
- }
- // Everything went okay
- return true;
- }
- function WifiGetGuests() {
- global $db;
- try {
- // Select all the users from the database
- $sql = 'SELECT * FROM guests';
- $result = $db->query($sql);
- $db = NULL; // Close the connection
- } catch(PDOException $e) {
- error_log('GetGuests exception: '.$e->getMessage(), 0);
- $db = NULL; // Close the connection
- }
- return $result;
- }
- function authorizeCMS($username, $password) {
- global $db;
- try {
- // See if user is in the database
- $sth = $db->prepare('SELECT id, password FROM accounts WHERE username = :username');
- $sth->bindParam(':username', $username, PDO::PARAM_STR);
- $sth->execute();
- $result = $sth->fetch();
- $db = NULL; // Close the connection
- } catch(PDOException $e) {
- error_log('authorizeCMS exception: '.$e->getMessage(), 0);
- return false;
- }
- $id = $result['id'];
- // See if the user has a valid password and remaining time
- if (password_verify($password, $result['password']))
- {
- return $id;
- }
- // Always return false if something goes wrong
- return false;
- }
- function GetName($id) {
- global $db;
- try {
- // See if user is in the database
- $sth = $db->prepare('SELECT name FROM accounts WHERE id = :id');
- $sth->bindParam(':id', $id, PDO::PARAM_INT);
- $sth->execute();
- $result = $sth->fetch();
- $db = NULL; // Close the connection
- } catch(PDOException $e) {
- error_log('GetName exception: '.$e->getMessage(), 0);
- return false;
- }
- $name = $result['name'];
- return $name;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement