2015-04-06 20:26:05 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Sakura Sock Chat authentication script
|
|
|
|
* By Flashwave
|
|
|
|
*/
|
|
|
|
|
2015-12-03 19:40:01 +00:00
|
|
|
// Filesystem path to the sakura root directory WITHOUT an ending /
|
2015-04-25 20:08:44 +00:00
|
|
|
// This can also be set before an include of this file in case
|
|
|
|
// you're using git to keep in sync and don't want conflicts
|
2015-09-07 20:53:47 +00:00
|
|
|
// You can also create a PHP file including this SockChat.php
|
|
|
|
// file so it's always up-to-date! Don't forget to include the
|
|
|
|
// variable below in the file __BEFORE__ the include!
|
2015-09-14 20:51:23 +00:00
|
|
|
if (!isset($sockSakuraPath)) {
|
2015-09-05 16:11:04 +00:00
|
|
|
$sockSakuraPath = '';
|
|
|
|
}
|
2015-04-06 20:26:05 +00:00
|
|
|
|
|
|
|
/* * * DON'T EDIT ANYTHING BELOW THIS LINE * * */
|
|
|
|
|
|
|
|
// Include Sakura
|
2015-09-14 20:51:23 +00:00
|
|
|
require_once $sockSakuraPath . '/sakura.php';
|
2015-04-06 20:26:05 +00:00
|
|
|
|
2015-09-05 16:11:04 +00:00
|
|
|
use Sakura\Permissions;
|
|
|
|
use Sakura\User;
|
2015-09-14 20:51:23 +00:00
|
|
|
use Sakura\Users;
|
|
|
|
use sockchat\Auth;
|
2015-04-06 20:26:05 +00:00
|
|
|
|
2015-09-14 20:51:23 +00:00
|
|
|
if (Auth::getPageType() == AUTH_FETCH) {
|
2015-04-06 20:26:05 +00:00
|
|
|
// Check if user is logged into the Sakura backend if not deny
|
2015-12-01 13:34:16 +00:00
|
|
|
if ($data = Users::checkLogin()) {
|
2015-04-06 20:26:05 +00:00
|
|
|
// If so append the required arguments and accept
|
2015-12-01 13:34:16 +00:00
|
|
|
Auth::AppendArguments([$data[0], $data[1]]);
|
2015-04-06 20:26:05 +00:00
|
|
|
Auth::Accept();
|
2015-09-05 16:11:04 +00:00
|
|
|
} else {
|
2015-04-06 20:26:05 +00:00
|
|
|
Auth::Deny();
|
2015-09-05 16:11:04 +00:00
|
|
|
}
|
2015-04-06 20:26:05 +00:00
|
|
|
} else {
|
2015-04-18 11:35:16 +00:00
|
|
|
// Get arguments
|
2015-04-25 20:08:44 +00:00
|
|
|
$uid = $_REQUEST['arg1'];
|
|
|
|
$sid = $_REQUEST['arg2'];
|
2015-04-18 11:35:16 +00:00
|
|
|
|
2015-04-06 20:26:05 +00:00
|
|
|
// Check if session is active else deny
|
2015-12-01 13:34:16 +00:00
|
|
|
if ($data = Users::checkLogin($uid, $sid)) {
|
2015-09-05 16:11:04 +00:00
|
|
|
// Check if they can access the chat
|
2015-12-29 01:27:49 +00:00
|
|
|
if (Perms::check('SITE', 'DEACTIVATED', $uid, 1) || Perms::check('SITE', 'RESTRICTED', $uid, 1)) {
|
2015-04-18 11:35:16 +00:00
|
|
|
Auth::Deny();
|
|
|
|
Auth::Serve();
|
|
|
|
exit;
|
|
|
|
}
|
2015-04-06 20:26:05 +00:00
|
|
|
|
2015-09-05 16:11:04 +00:00
|
|
|
// Create a user object
|
2015-12-29 01:27:49 +00:00
|
|
|
$user = User::construct($uid);
|
2015-09-05 16:11:04 +00:00
|
|
|
|
2015-04-28 15:53:53 +00:00
|
|
|
// Set the user's data
|
2015-04-06 20:26:05 +00:00
|
|
|
Auth::SetUserData(
|
2015-12-01 13:34:16 +00:00
|
|
|
$user->id(),
|
|
|
|
$user->username(),
|
2015-09-05 16:11:04 +00:00
|
|
|
$user->colour()
|
2015-04-06 20:26:05 +00:00
|
|
|
);
|
|
|
|
|
2015-04-28 15:53:53 +00:00
|
|
|
// Set the common permissions
|
|
|
|
Auth::SetCommonPermissions(
|
2015-12-01 13:34:16 +00:00
|
|
|
$user->mainRank()['hierarchy'],
|
2015-12-29 01:27:49 +00:00
|
|
|
Perms::check('MANAGE', 'USE_MANAGE', $uid, 1) ? 1 : 0,
|
|
|
|
Perms::check('SITE', 'CREATE_BACKGROUND', $uid, 1) ? 1 : 0,
|
|
|
|
Perms::check('SITE', 'CHANGE_USERNAME', $uid, 1) ? 1 : 0,
|
|
|
|
Perms::check('SITE', 'MULTIPLE_GROUPS', $uid, 1) ? 2 : (
|
|
|
|
Perms::check('SITE', 'CREATE_GROUP', $uid, 1) ? 1 : 0
|
2015-09-05 16:11:04 +00:00
|
|
|
)
|
2015-04-28 15:53:53 +00:00
|
|
|
);
|
|
|
|
|
2015-04-18 11:35:16 +00:00
|
|
|
Auth::Accept();
|
2015-09-05 16:11:04 +00:00
|
|
|
} else {
|
2015-04-06 20:26:05 +00:00
|
|
|
Auth::Deny();
|
2015-09-05 16:11:04 +00:00
|
|
|
}
|
2015-04-06 20:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Serve the authentication data
|
|
|
|
Auth::Serve();
|