Added page authorisation and cug processing
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
use Sock\{SocketClient,SocketException};
|
||||
|
||||
use App\User;
|
||||
use App\Classes\Frame as FrameClass;
|
||||
use App\Models\Frame as FrameModel;
|
||||
use App\Models\Mode;
|
||||
@@ -20,6 +21,50 @@ abstract class Server {
|
||||
{
|
||||
$this->mo = $o;
|
||||
|
||||
define('MODE_BL',1); // Typing a * command on the baseline
|
||||
define('MODE_FIELD',2); // typing into an imput field
|
||||
define('MODE_WARPTO',3); // awaiting selection of a timewarp
|
||||
define('MODE_COMPLETE',4); // Entry of data is complete ..
|
||||
define('MODE_SUBMITRF',5); // asking if should send or not.
|
||||
define('MODE_RFSENT',6);
|
||||
define('MODE_RFERROR',7);
|
||||
define('MODE_RFNOTSENT',8);
|
||||
|
||||
define('ACTION_RELOAD',1);
|
||||
define('ACTION_GOTO',2);
|
||||
define('ACTION_BACKUP',3);
|
||||
define('ACTION_NEXT',4);
|
||||
define('ACTION_INFO',5);
|
||||
define('ACTION_TERMINATE',6);
|
||||
define('ACTION_SUBMITRF',7); // Offer to submit a response frame
|
||||
define('ACTION_STAR',8);
|
||||
|
||||
define('FRAMETYPE_INFO','i');
|
||||
define('FRAMETYPE_ACTION','a');
|
||||
define('FRAMETYPE_LOGIN','l');
|
||||
|
||||
// Keyboard presses
|
||||
define('KEY_LEFT',chr(136));
|
||||
define('KEY_RIGHT',chr(137));
|
||||
define('KEY_DOWN',chr(138));
|
||||
define('KEY_UP',chr(139));
|
||||
|
||||
define('TCP_IAC',chr(255));
|
||||
define('TCP_DONT',chr(254));
|
||||
define('TCP_DO',chr(253));
|
||||
define('TCP_WONT',chr(252));
|
||||
define('TCP_WILL',chr(251));
|
||||
define('TCP_SB',chr(250));
|
||||
define('TCP_AYT',chr(246));
|
||||
define('TCP_SE',chr(240));
|
||||
|
||||
define('TCP_BINARY',chr(0));
|
||||
define('TCP_OPT_ECHO',chr(1));
|
||||
define('TCP_OPT_SUP_GOAHEAD',chr(3));
|
||||
define('TCP_OPT_TERMTYPE',chr(24));
|
||||
define('TCP_OPT_WINDOWSIZE',chr(31));
|
||||
define('TCP_OPT_LINEMODE',chr(34));
|
||||
|
||||
define('MSG_SENDORNOT', GREEN.'KEY 1 TO SEND, 2 NOT TO SEND');
|
||||
define('MSG_SENT', GREEN.'MESSAGE SENT - KEY _ TO CONTINUE');
|
||||
define('MSG_NOTSENT', GREEN.'MESSAGE NOT SENT - KEY _ TO CONTINUE');
|
||||
@@ -29,6 +74,7 @@ abstract class Server {
|
||||
define('ERR_PRIVATE', WHITE.'PRIVATE PAGE'.GREEN.'- FOR EXPLANATION *37_..');
|
||||
define('ERR_ROUTE', WHITE.'MISTAKE?'.GREEN.'TRY AGAIN OR TELL US ON *08');
|
||||
define('ERR_PAGE',ERR_ROUTE);
|
||||
define('ERR_USER_ALREADYMEMBER', RED.'ALREADY MEMBER OF CUG');
|
||||
|
||||
define('MSG_TIMEWARP_ON', WHITE.'TIMEWARP ON'.GREEN.'VIEW INFO WITH *02');
|
||||
define('MSG_TIMEWARP_OFF', WHITE.'TIMEWARP OFF'.GREEN.'VIEWING DATE IS FIXED');
|
||||
@@ -82,6 +128,7 @@ abstract class Server {
|
||||
$action = ACTION_GOTO; // Initial action.
|
||||
$cmd = ''; // Current *command being typed in
|
||||
$mode = FALSE; // Current mode.
|
||||
$user = User::find(1); // The logged in user
|
||||
|
||||
$current = []; // Attributes about the current page
|
||||
// field/fieldnum indexes are for fields on the active page
|
||||
@@ -199,6 +246,8 @@ abstract class Server {
|
||||
$action = FALSE;
|
||||
|
||||
switch ($fo->type()) {
|
||||
// Login frame.
|
||||
case 'l':
|
||||
// Response frame.
|
||||
case 'a':
|
||||
switch ($read) {
|
||||
@@ -213,13 +262,11 @@ abstract class Server {
|
||||
|
||||
if ($current['fieldnum'] !== FALSE) {
|
||||
$current['field'] = $fo->getField($current['fieldnum']);
|
||||
$fielddata[$current['fieldnum']] = '';
|
||||
|
||||
$client->send($this->outputPosition($current['field']->x,$current['field']->y).CON);
|
||||
$mode = MODE_FIELD;
|
||||
$fielddate[$current['fieldnum']] = '';
|
||||
|
||||
// There were no (more) editable fields.
|
||||
// There were no (more) editable fields.
|
||||
} else {
|
||||
$action = ACTION_SUBMITRF;
|
||||
}
|
||||
@@ -286,6 +333,9 @@ abstract class Server {
|
||||
// Record Data Entry
|
||||
default:
|
||||
if (ord($read) > 31 && $current['fieldpos'] < $current['field']->length) {
|
||||
if (! array_get($fielddata,$current['fieldnum']))
|
||||
$fielddata[$current['fieldnum']] = '';
|
||||
|
||||
$fielddata[$current['fieldnum']]{$current['fieldpos']} = $read;
|
||||
$current['fieldpos']++;
|
||||
$client->send($read);
|
||||
@@ -309,7 +359,7 @@ abstract class Server {
|
||||
switch ($read) {
|
||||
// @todo Input received, process it.
|
||||
case '1':
|
||||
// dump(['line'=>__LINE__,'s' => $service, 'f' => $fielddata]);
|
||||
// dump(['line'=>__LINE__,'f' => $fielddata]);
|
||||
// @todo if send successful or not
|
||||
if (TRUE) {
|
||||
$this->sendBaseline($client,MSG_SENT);
|
||||
@@ -621,32 +671,53 @@ abstract class Server {
|
||||
break;
|
||||
}
|
||||
|
||||
// validate if we have access top it
|
||||
/* if (isset($m['access']) && $m['access'] == 'n') {
|
||||
$this->sendBaseline($client,ERR_PAGE);
|
||||
$mode = $action = false;
|
||||
break;
|
||||
}
|
||||
if (isset($m['cug']) && is_numeric($m['cug']) && $m['cug'] && !in_array($m['cug'],$usercugs)) {
|
||||
$this->sendBaseline($client,ERR_PRIVATE);
|
||||
$mode = $action = false;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
// Is there a user logged in
|
||||
if ($user)
|
||||
{
|
||||
if ($fo->isFramePublic() AND $fo->isAccessible())
|
||||
{
|
||||
if ($fo->type() == FRAMETYPE_LOGIN AND $user->isMemberCUG($fo->getCUG()))
|
||||
{
|
||||
$this->sendBaseline($client,ERR_USER_ALREADYMEMBER);
|
||||
$mode = $action = FALSE;
|
||||
|
||||
// we have access...
|
||||
//if ($r['varient_id'] != $varient['varient_id']) {
|
||||
/* if ($timewarpalt) {
|
||||
if (empty($v['varient_date'])) {
|
||||
$this->sendBaseline($client,sprintf(MSG_TIMEWARP_TO, 'unknown date'));
|
||||
} else {
|
||||
$this->sendBaseline($client,sprintf(MSG_TIMEWARP_TO, date('j f Y', strtotime($v['varient_date']))));
|
||||
break;
|
||||
}
|
||||
|
||||
// If this is a login frame and the user is already a member.
|
||||
} else {
|
||||
|
||||
if (! $fo->isOwner($user))
|
||||
{
|
||||
if (! $fo->isAccessible())
|
||||
{
|
||||
$this->sendBaseline($client,ERR_PAGE);
|
||||
$mode = $action = FALSE;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (! $user->isMemberCUG($fo->getCUG()))
|
||||
{
|
||||
$this->sendBaseline($client, ERR_PRIVATE);
|
||||
$mode = $action = FALSE;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
//$varient = array_merge($varient, array_intersect_key($r, $varient));
|
||||
$msg = "TIMEWARP";
|
||||
dump(['line'=>__LINE__,'write'=>'TIMEWARP MESSAGE']);
|
||||
}
|
||||
*/
|
||||
|
||||
} else {
|
||||
// Is this a public frame in CUG 0?
|
||||
if (! $fo->isCUG(0) OR ! $fo->isFramePublic())
|
||||
{
|
||||
$this->sendBaseline($client,ERR_PAGE);
|
||||
$mode = $action = FALSE;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$current['page'] = $fo->page(TRUE);
|
||||
$current['fieldpos'] = 0;
|
||||
|
||||
@@ -678,13 +749,15 @@ abstract class Server {
|
||||
|
||||
switch ($fo->type()) {
|
||||
default:
|
||||
// Standard Frame
|
||||
// Standard Frame
|
||||
case 'i':
|
||||
$client->send($output);
|
||||
$mode = $action = false;
|
||||
|
||||
break;
|
||||
|
||||
// Login Frame.
|
||||
case 'l':
|
||||
// Active Frame. Prestel uses this for a Response Frame.
|
||||
case 'a':
|
||||
$client->send($output);
|
||||
|
Reference in New Issue
Block a user