function admin_settings() { if (!sr_is_signed_in()) { sr_redirect('/d/main/signin/'); } if (!sr_is_admin()) { sr_redirect('/d/'); } global $sr_root; global $sr_db_type; global $sr_db_host; global $sr_db_port; global $sr_db_name; global $sr_db_user; global $sr_db_password; global $sr_db_charset; global $sr_email_addr; global $sr_email_smtp; global $sr_default_authority; global $sr_join_anonymous; global $sr_join_non_authorized; global $sr_main_content; $sr_email_addr = htmlentities($sr_email_addr); $context = array('db_type' => $sr_db_type, 'db_host' => $sr_db_host, 'db_port' => $sr_db_port, 'db_database' => $sr_db_name, 'db_username' => $sr_db_user, 'db_password' => $sr_db_password, 'db_char_set' => $sr_db_charset, 'default_authority' => $sr_default_authority ? 'Yes' : 'No', 'join_anonymous' => $sr_join_anonymous ? 'Yes' : 'No', 'join_non_authorized' => $sr_join_non_authorized ? 'Yes' : 'No', 'smtp_email_addr' => $sr_email_addr, 'smtp_server' => $sr_email_smtp['host'], 'smtp_port' => $sr_email_smtp['port'], 'smtp_username' => $sr_email_smtp['username'], 'installation_path' => $sr_root, 'maximum_users' => 'TODO', 'stun_server' => 'TODO', 'xmpp_server_use' => 'TODO', 'xmpp_server' => 'TODO', 'main_content' => $sr_main_content); sr_response('views/admin/settings.php', $context); }
function room() { global $sr_root; global $sr_channel_server_uri; global $sr_room_ui_title; global $sr_join_anonymous; global $sr_join_non_authorized; global $sr_default_chat_name; $db = sr_pdo(); $browser = room_get_browser(); if ($browser['name'] != 'Mozilla Firefox' && $browser['name'] != 'Google Chrome') { sr_redirect('/d/room/message/browser/'); } if (isset($_GET['name']) && strlen($_GET['name']) > 0) { try { $context = array(); // check if the room with the specified name exists $stmt = $db->prepare('SELECT * FROM room WHERE name = :name'); $stmt->bindParam(':name', $_GET['name']); $stmt->setFetchMode(PDO::FETCH_CLASS, 'Room'); $stmt->execute(); $room = $stmt->fetch(); if ($room === False) { // Room doesn't exist. Create a room using the requested name $room = new Room(); $room->name = $_GET['name']; $room->title = ''; $room->description = ''; $room->password = ''; $room->is_open = 1; $room->open($db); } else { $room->title = stripslashes($room->title); $room->description = stripslashes($room->description); } } catch (PDOException $e) { sr_response_error(500); } $context['sunrise_main'] = $sr_root; $context['channel_server'] = $sr_channel_server_uri; $context['room'] = $room; $context['room_link'] = sr_current_url(); $context['room_api'] = $sr_root; $context['room_ui_title'] = $sr_room_ui_title; //IF he is registered user if (sr_is_signed_in()) { //IF server allow non-authorized user to join if ($sr_join_non_authorized) { $context['user_id'] = $_SESSION['user_id']; $context['is_registered_user'] = '******'; //IF server allow only authorized user to join } else { //IF he is authorized user if (sr_is_authorized()) { $context['user_id'] = $_SESSION['user_id']; $context['is_registered_user'] = '******'; //IF he is non-authorized user } else { sr_redirect('/d/room/message/auth/'); } } //IF he is anonymous user } else { //IF server allow anonymous user to join if ($sr_join_anonymous) { $context['user_id'] = 0; $context['is_registered_user'] = '******'; //IF server not allow anonymous user to join } else { $_SESSION['next_page'] = 1; $_SESSION['room_name'] = $_GET['name']; $context['info'] = 'Only registered users can join the room.'; sr_response('views/main/signin.php', $context); } } $context['user_name'] = $_SESSION['user_name']; $context['chat_name'] = $_SESSION['chat_name']; if ($_SESSION['chat_name']) { $context['chat_name'] = $_SESSION['chat_name']; } else { if ($_SESSION['user_name']) { $context['chat_name'] = $_SESSION['user_name']; $_SESSION['chat_name'] = $_SESSION['user_name']; } else { $context['chat_name'] = $sr_default_chat_name; $_SESSION['chat_name'] = $sr_default_chat_name; } } if ($room->is_open == 1) { sr_response('views/room/room.php', $context); //IF locked room } else { if (isset($_SESSION['is_checked_password']) && $_SESSION['is_checked_password'] == $_SESSION['room_name']) { unset($_SESSION['is_checked_password']); unset($_SESSION['room_name']); sr_response('views/room/room.php', $context); } else { $_SESSION['room_name'] = $_GET['name']; sr_redirect('/d/room/message/pswd/'); } } } else { sr_response_error(400); } }
function main_signup() { if (sr_is_signed_in()) { sr_redirect('/d/'); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { global $sr_regex_name; global $sr_regex_email; global $sr_regex_password; global $sr_default_authority; $user = new User(); $context = array(); if (!preg_match($sr_regex_email, $_POST['signup_email'])) { $context['result'] = 3; $context['msg'] = 'Please enter a valid email address'; } else { if (!preg_match($sr_regex_password, $_POST['signup_password'])) { $context['result'] = 4; $context['msg'] = 'Please enter a valid password. Password should be alphanumeric.'; } else { if (!preg_match($sr_regex_name, $_POST['first_name'])) { $context['result'] = 5; $context['msg'] = 'Name should consist of only alphabets (uppercase or lowercase).'; } else { if (!preg_match($sr_regex_name, $_POST['last_name'])) { $context['result'] = 6; $context['msg'] = 'Name should consist of only alphabets (uppercase or lowercase).'; } else { if ($_POST['signup_password'] != $_POST['repeat_password']) { $context['result'] = 7; $context['msg'] = 'Please repeat your password.'; } else { $user->first_name = ucfirst($_POST['first_name']); $user->last_name = ucfirst($_POST['last_name']); $user->email = strtolower($_POST['signup_email']); $user->password = md5($_POST['signup_password']); $user->is_authorized = $sr_default_authority; $user->is_admin = 0; $user->join_date = Model::getCurrentTime(); $user->last_active_date = Model::getCurrentTime(); try { $db = sr_pdo(); $id = $user->add($db); $context['result'] = 0; $context['msg'] = 'Successfully registered'; } catch (PDOException $e) { switch ($e->errorInfo[1]) { case 1062: // Duplicated entry $context['result'] = 1; $context['msg'] = 'The email address is already registered.'; break; default: // Other exceptions $context['result'] = 2; $context['msg'] = 'Failed to signup. Please try it again.'; } } } } } } } if ($context['result'] === 0) { sr_signin($user); if (isset($_SESSION['next_page']) && isset($_SESSION['room_name'])) { $room_name = $_SESSION['room_name']; unset($_SESSION['next_page']); unset($_SESSION['room_name']); sr_redirect('/d/room/?name=' . $room_name); } else { sr_redirect('/d/'); } } else { sr_response('views/main/signup.php', $context); } } else { // Show signup view sr_response('views/main/signup.php', null); } }