Internal rework pending editframe
This commit is contained in:
@@ -13,11 +13,23 @@ use App\Models\Frame as FrameModel;
|
||||
use App\Models\Mode;
|
||||
|
||||
abstract class Server {
|
||||
private $mo = NULL; // Our Mode object
|
||||
private $co = NULL;
|
||||
protected $blp = 0; // Size of Bottom Line Pollution
|
||||
protected $baseline = ''; // Whats on the baseline currently
|
||||
protected $pid = NULL; // Client PID
|
||||
// Our Mode object, this determines if we are an ANSI or VIDEOTEX server
|
||||
private $mo = NULL;
|
||||
|
||||
// The client connection object of the currently connected client.
|
||||
public $co = NULL;
|
||||
|
||||
// The currently rendered Frame to the client of Frame/*
|
||||
public $fo = NULL;
|
||||
|
||||
// Size of Bottom Line Pollution
|
||||
protected $blp = 0;
|
||||
|
||||
// Whats on the baseline currently
|
||||
protected $baseline = '';
|
||||
|
||||
// Client PID
|
||||
protected $pid = NULL;
|
||||
|
||||
public function __construct(Mode $o)
|
||||
{
|
||||
@@ -31,6 +43,7 @@ abstract class Server {
|
||||
define('MODE_RFSENT', 6);
|
||||
define('MODE_RFERROR', 7);
|
||||
define('MODE_RFNOTSENT', 8);
|
||||
define('MODE_CONTROL', 9); // Do nothing, a method is controlling input
|
||||
|
||||
define('ACTION_RELOAD', 1);
|
||||
define('ACTION_GOTO', 2);
|
||||
@@ -40,16 +53,11 @@ abstract class Server {
|
||||
define('ACTION_TERMINATE', 6);
|
||||
define('ACTION_SUBMITRF', 7); // Offer to submit a response frame
|
||||
define('ACTION_STAR', 8);
|
||||
define('ACTION_EDIT', 9); // Edit current frame
|
||||
|
||||
define('CONTROL_TELNET', 1); // Telnet session control
|
||||
define('CONTROL_METHOD', 2); // Send input to an external method
|
||||
|
||||
// Keyboard presses
|
||||
define('KEY_DELETE', chr(8));
|
||||
define('KEY_LEFT', chr(136));
|
||||
define('KEY_RIGHT', chr(137));
|
||||
define('KEY_DOWN', chr(138));
|
||||
define('KEY_UP', chr(139));
|
||||
define('CONTROL_EDIT', 3); // Controller to edit frame
|
||||
|
||||
define('TCP_IAC', chr(255));
|
||||
define('TCP_DONT', chr(254));
|
||||
@@ -67,11 +75,12 @@ abstract class Server {
|
||||
define('TCP_OPT_WINDOWSIZE', chr(31));
|
||||
define('TCP_OPT_LINEMODE', chr(34));
|
||||
|
||||
// Status messages
|
||||
define('MSG_SENDORNOT', GREEN.'KEY 1 TO SEND, 2 NOT TO SEND');
|
||||
define('MSG_SENT', GREEN.'MESSAGE SENT - KEY '.HASH.' TO CONTINUE');
|
||||
define('MSG_NOTSENT', GREEN.'MESSAGE NOT SENT - KEY '.HASH.' TO CONTINUE');
|
||||
|
||||
define('ERR_DATABASE', RED.'UNAVAILABLE AT PRESENT - PLSE TRY LATER');
|
||||
define('ERR_DATABASE', RED.'UNAVAILABLE AT PRESENT - PLS TRY LATER');
|
||||
define('ERR_NOTSENT', WHITE.'MESSAGE NOT SENT DUE TO AN ERROR');
|
||||
define('ERR_PRIVATE', WHITE.'PRIVATE PAGE'.GREEN.'- FOR EXPLANATION *37'.HASH.'..');
|
||||
define('ERR_ROUTE', WHITE.'MISTAKE?'.GREEN.'TRY AGAIN OR TELL US ON *08');
|
||||
@@ -84,11 +93,13 @@ abstract class Server {
|
||||
define('MSG_TIMEWARP', WHITE.'OTHER VERSIONS EXIST'.GREEN.'KEY *02 TO VIEW');
|
||||
}
|
||||
|
||||
public function client()
|
||||
{
|
||||
return $this->co;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write something to the system log.
|
||||
*
|
||||
* @param string $mode
|
||||
* @param string $message
|
||||
* @param array $data
|
||||
*/
|
||||
public function log(string $mode,string $message,array $data=[])
|
||||
{
|
||||
Log::$mode(sprintf('%s: %s',$this->pid,$message),$data);
|
||||
@@ -111,7 +122,9 @@ abstract class Server {
|
||||
elseif ($pid)
|
||||
return;
|
||||
|
||||
$fo = NULL;
|
||||
// The next page we will load - this should have frame=,index=
|
||||
$next_page = NULL;
|
||||
|
||||
$this->co = $client;
|
||||
$this->pid = getmypid();
|
||||
$this->log('info','Connection from: ',['client'=>$client->getAddress(),'server'=>$this->mo->name]);
|
||||
@@ -136,7 +149,6 @@ abstract class Server {
|
||||
$action = ACTION_GOTO; // Initial action.
|
||||
$control = FALSE; // Logic in control
|
||||
$mode = FALSE; // Current mode.
|
||||
$save = FALSE; //
|
||||
$cmd = ''; // Current *command being typed in
|
||||
$user = new User; // The logged in user
|
||||
$method = collect(); // Method in control for CONTROL_METHOD
|
||||
@@ -147,19 +159,28 @@ abstract class Server {
|
||||
$current['fieldpos'] = 0; // For current field, position within.
|
||||
$current['prevmode'] = FALSE; // Previous mode - in case we need to go back to MODE_FIELD
|
||||
|
||||
$fielddata = [];
|
||||
|
||||
// @todo Get the login/start page, and if it is not available, throw the ERR_DATEBASE error.
|
||||
if (isset($config['loginpage'])) {
|
||||
$page = ['frame'=>$config['loginpage']];
|
||||
$next_page = ['frame'=>$config['loginpage']];
|
||||
} else if (!empty($service['start_page'])) {
|
||||
$page = ['frame'=>$service['start_page']];
|
||||
$next_page = ['frame'=>$service['start_page']];
|
||||
} else {
|
||||
$page = ['frame'=>'980']; // next page
|
||||
$next_page = ['frame'=>'980']; // Default Login Page
|
||||
}
|
||||
|
||||
while ($action != ACTION_TERMINATE) {
|
||||
// Read a character from the client session
|
||||
// @todo Add a timeout to read, and log user off if timeout exceeded.
|
||||
$read = $client->read(1);
|
||||
printf(". Got: %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",$read,ord($read),$mode,$action,$control);
|
||||
echo "\n";
|
||||
printf(". Got: %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",
|
||||
(ord($read) < 32 ? '.' : $read),
|
||||
ord($read),
|
||||
serialize($mode),
|
||||
serialize($action),
|
||||
$control);
|
||||
|
||||
// It appears that read will return '' instead of false when a disconnect has occurred.
|
||||
// We'll set it to NULL so its caught later
|
||||
@@ -174,17 +195,15 @@ abstract class Server {
|
||||
$control = CONTROL_TELNET;
|
||||
|
||||
// Remember our Telnet Session Object
|
||||
// @todo We might need to clear out the old mode/action states
|
||||
if (! $session) {
|
||||
if (! $session)
|
||||
$session = Control::factory('telnet',$this);
|
||||
}
|
||||
|
||||
$method->push($session);
|
||||
}
|
||||
}
|
||||
|
||||
if ($control AND $method->count()) {
|
||||
printf("= Control going to method: %s\n", get_class($method->last()));
|
||||
printf("= Start CONTROL: Going to method: %s\n",get_class($method->last()));
|
||||
|
||||
// Capture our state when we enter this method.
|
||||
if (! array_key_exists('control',$method->last()->state)) {
|
||||
@@ -200,7 +219,7 @@ abstract class Server {
|
||||
$mode = $method->last()->state['mode'];
|
||||
|
||||
if ($method->last()->complete()) {
|
||||
printf("- Control complete: %s\n",get_class($method->last()));
|
||||
printf("- Complete CONTROL: %s\n",get_class($method->last()));
|
||||
$save = $method->pop();
|
||||
|
||||
if ($method->count()) {
|
||||
@@ -214,28 +233,34 @@ abstract class Server {
|
||||
|
||||
dump(sprintf('End: Control is now: %s: Method Count: %s',is_object($control) ? get_class($control) : serialize($control),$method->count()));
|
||||
}
|
||||
|
||||
printf("- End CONTROL: Read %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",
|
||||
(ord($read) < 32 ? '.' : $read),
|
||||
ord($read),
|
||||
serialize($mode),
|
||||
serialize($action),
|
||||
$control);
|
||||
}
|
||||
|
||||
printf("- End Control: Read %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",$read,ord($read),$mode,$action,$control);
|
||||
|
||||
printf("= Start MODE: %s\n",serialize($mode));
|
||||
switch ($mode) {
|
||||
// Key presses during field input.
|
||||
case MODE_FIELD:
|
||||
$cmd = '';
|
||||
$action = FALSE;
|
||||
|
||||
switch ($fo->type()) {
|
||||
switch ($this->fo->type()) {
|
||||
// Login frame.
|
||||
case Frame::FRAMETYPE_LOGIN:
|
||||
switch ($read) {
|
||||
case HASH:
|
||||
// If we are the main login screen, see if it is a new user
|
||||
if ($fo->isCUG(0))
|
||||
if ($this->fo->isCUG(0))
|
||||
{
|
||||
if ($current['field']->type == 't' AND array_get($fielddata,$current['fieldnum']) == 'NEW')
|
||||
{
|
||||
$action = ACTION_GOTO;
|
||||
$page = ['frame'=>'981']; // @todo This should be in the DB.
|
||||
$next_page = ['frame'=>'981']; // @todo This should be in the DB.
|
||||
|
||||
break 2;
|
||||
}
|
||||
@@ -254,13 +279,13 @@ abstract class Server {
|
||||
$current['fieldnum']++;
|
||||
$current['fieldpos'] = 0;
|
||||
|
||||
if ($current['fieldnum'] < $fo->fields->count()) {
|
||||
$current['fieldnum'] = $fo->getFieldId('edit',$current['fieldnum']);
|
||||
if ($current['fieldnum'] < $this->fo->fields()->count()) {
|
||||
$current['fieldnum'] = $this->fo->getFieldId('edit',$current['fieldnum']);
|
||||
|
||||
if ($current['fieldnum'] !== FALSE) {
|
||||
$current['field'] = $fo->getField($current['fieldnum']);
|
||||
$current['field'] = $this->fo->getField($current['fieldnum']);
|
||||
|
||||
$client->send($this->outputPosition($current['field']->x,$current['field']->y).CON);
|
||||
$client->send($this->moveCursor($current['field']->x,$current['field']->y).CON);
|
||||
$mode = MODE_FIELD;
|
||||
|
||||
// There were no (more) editable fields.
|
||||
@@ -288,7 +313,7 @@ abstract class Server {
|
||||
if ($current['fieldpos'])
|
||||
{
|
||||
$current['fieldpos']--;
|
||||
$client->send(LEFT.$fo::$if_filler.LEFT);
|
||||
$client->send(LEFT.$this->fo::$if_filler.LEFT);
|
||||
$fielddata[$current['fieldnum']] = substr($fielddata[$current['fieldnum']],0,-1);
|
||||
$current['fielddata'][$current['fieldnum']] = substr($current['fielddata'][$current['fieldnum']],0,-1);
|
||||
}
|
||||
@@ -332,7 +357,7 @@ abstract class Server {
|
||||
$current['fieldpos'] = (($current['fieldpos'] + $current['field']->x) % 40) * 40;
|
||||
|
||||
} else {
|
||||
$client->send($this->outputPosition($current['field']->x,$current['field']->y).CON);
|
||||
$client->send($this->moveCursor($current['field']->x,$current['field']->y).CON);
|
||||
$current['fieldpos'] = 0;
|
||||
}
|
||||
|
||||
@@ -354,7 +379,7 @@ abstract class Server {
|
||||
|
||||
$current['fieldpos']++;
|
||||
|
||||
$client->send($fo->isFieldMasked($current['field']->type) ?: $read);
|
||||
$client->send($this->fo->isFieldMasked($current['field']->type) ?: $read);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,7 +389,7 @@ abstract class Server {
|
||||
default:
|
||||
$client->close();
|
||||
|
||||
throw new \Exception('Shouldnt get here', 500);
|
||||
throw new \Exception('Shouldnt get here',500);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -372,29 +397,32 @@ abstract class Server {
|
||||
// Form submission: 1 to send, 2 not to send.
|
||||
case MODE_SUBMITRF:
|
||||
switch ($read) {
|
||||
// @todo Input received, process it.
|
||||
case '1':
|
||||
$route = $fo->route(1);
|
||||
|
||||
// If we are in a control method, complete it
|
||||
if ($control AND $method->count()) {
|
||||
$method->last()->process();
|
||||
|
||||
} elseif ($route == '*' OR is_numeric($route)) {
|
||||
} elseif ($this->fo->route(1) == '*' OR is_numeric($this->fo->route(1))) {
|
||||
$this->sendBaseline($client,RED.'NO ACTION PERFORMED');
|
||||
$mode = MODE_RFSENT;
|
||||
|
||||
} elseif ($ao = FrameClass\Action::factory($fo->route(1),$this,$user,$action,$mode)) {
|
||||
} elseif ($ao = FrameClass\Action::factory($this->fo->route(1),$this,$user,$action,$mode)) {
|
||||
$ao->handle($fielddata);
|
||||
$mode = $ao->mode;
|
||||
$action = $ao->action;
|
||||
$user = $ao->uo;
|
||||
|
||||
// Is this a user logging in?
|
||||
if ($ao->uo->exists AND $ao instanceof FrameClass\Action\Login)
|
||||
{
|
||||
$user = $ao->uo;
|
||||
$history = collect();
|
||||
}
|
||||
|
||||
if ($ao->page)
|
||||
$page = $ao->page;
|
||||
$next_page = $ao->page;
|
||||
|
||||
} else {
|
||||
$this->sendBaseline($client, RED.'NO method exists...');
|
||||
$this->sendBaseline($client,RED.'NO method exists...');
|
||||
|
||||
$mode = MODE_RFSENT;
|
||||
}
|
||||
@@ -434,18 +462,18 @@ abstract class Server {
|
||||
$client->send(COFF);
|
||||
|
||||
if ($read == HASH) {
|
||||
if ($route = $fo->route(2) AND $route !== '*' AND is_numeric($route)) {
|
||||
$page = ['frame'=>$route];
|
||||
if ($x = $this->fo->route(2) AND $x !== '*' AND is_numeric($x)) {
|
||||
$next_page = ['frame'=>$x];
|
||||
|
||||
} elseif (FrameModel::where('frame',$fo->frame())->where('index',$fo->index_next())->exists()) {
|
||||
$page = ['frame'=>$fo->frame(),'index'=>$fo->index_next()];
|
||||
} elseif (FrameModel::where('frame',$this->fo->frame())->where('index',$this->fo->index_next())->exists()) {
|
||||
$next_page = ['frame'=>$this->fo->frame(),'index'=>$this->fo->index_next()];
|
||||
|
||||
} elseif ($route = $fo->route(0) AND $route !== '*' AND is_numeric($route)) {
|
||||
$page = ['frame'=>$route];
|
||||
} elseif ($x = $this->fo->route(0) AND $x !== '*' AND is_numeric($x)) {
|
||||
$next_page = ['frame'=>$x];
|
||||
|
||||
// No further routes defined, go home.
|
||||
} else {
|
||||
$page = ['frame'=>0];
|
||||
$next_page = ['frame'=>0];
|
||||
}
|
||||
|
||||
$action = ACTION_GOTO;
|
||||
@@ -461,23 +489,23 @@ abstract class Server {
|
||||
// Response form after NOT sending
|
||||
case MODE_RFNOTSENT:
|
||||
|
||||
// Response form ERROR
|
||||
// Response form ERROR
|
||||
case MODE_RFERROR:
|
||||
$client->send(COFF);
|
||||
|
||||
if ($read == HASH) {
|
||||
if ($route = $fo->route(2) AND $route !== '*' AND is_numeric($route)) {
|
||||
$page = ['frame'=>$route];
|
||||
if ($x = $this->fo->route(2) AND $x !== '*' AND is_numeric($x)) {
|
||||
$next_page = ['frame'=>$x];
|
||||
|
||||
} elseif (FrameModel::where('frame',$fo->frame())->where('index',$fo->index_next())->exists()) {
|
||||
$page = ['frame'=>$fo->frame(),'index'=>$fo->index_next()];
|
||||
} elseif (FrameModel::where('frame',$this->fo->frame())->where('index',$this->fo->index_next())->exists()) {
|
||||
$next_page = ['frame'=>$this->fo->frame(),'index'=>$this->fo->index_next()];
|
||||
|
||||
} elseif ($route = $fo->route(0) AND $route !== '*' AND is_numeric($route)) {
|
||||
$page = ['frame'=>$route];
|
||||
} elseif ($x = $this->fo->route(0) AND $x !== '*' AND is_numeric($x)) {
|
||||
$next_page = ['frame'=>$x];
|
||||
|
||||
// No further routes defined, go home.
|
||||
} else {
|
||||
$page = ['frame'=>0];
|
||||
$next_page = ['frame'=>0];
|
||||
}
|
||||
|
||||
$action = ACTION_GOTO;
|
||||
@@ -528,8 +556,8 @@ abstract class Server {
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (is_numeric($fo->route($read))) {
|
||||
$page = ['frame'=>$fo->route($read),'index'=>'a'];
|
||||
if (is_numeric($this->fo->route($read))) {
|
||||
$next_page = ['frame'=>$this->fo->route($read)];
|
||||
|
||||
$action = ACTION_GOTO;
|
||||
|
||||
@@ -548,10 +576,18 @@ abstract class Server {
|
||||
echo "- Waiting for Page Number\n";
|
||||
|
||||
// if it's a number, continue entry
|
||||
if (strpos('0123456789', $read) !== FALSE) {
|
||||
$cmd .= $read;
|
||||
if (strpos('0123456789',$read) !== FALSE) {
|
||||
$client->send($read);
|
||||
$this->blp++;
|
||||
$cmd .= $read;
|
||||
}
|
||||
|
||||
// If its a backspace, delete last input
|
||||
if ($read === KEY_DELETE AND strlen($cmd))
|
||||
{
|
||||
$client->send(BS.' '.BS);
|
||||
$this->blp--;
|
||||
$cmd = substr($cmd,0,-1);
|
||||
}
|
||||
|
||||
// if we hit a special numeric command, deal with it.
|
||||
@@ -569,7 +605,7 @@ abstract class Server {
|
||||
if ($cmd === '01') {
|
||||
$client->send(COFF);
|
||||
$timewarp = !$timewarp;
|
||||
$this->sendBaseline($client, ($timewarp ? MSG_TIMEWARP_ON : MSG_TIMEWARP_OFF));
|
||||
$this->sendBaseline($client,($timewarp ? MSG_TIMEWARP_ON : MSG_TIMEWARP_OFF));
|
||||
$cmd = '';
|
||||
$action = $mode = FALSE;
|
||||
|
||||
@@ -586,9 +622,22 @@ abstract class Server {
|
||||
break;
|
||||
}
|
||||
|
||||
// Edit frame
|
||||
// Catch if we are going to edit a child frame
|
||||
if (preg_match('/^04/',$cmd) AND preg_match('/^[a-z]$/',$read))
|
||||
{
|
||||
$client->send(COFF);
|
||||
$next_page = ['frame'=>substr($cmd,2),'index'=>$read];
|
||||
$cmd = '';
|
||||
|
||||
$action = ACTION_EDIT;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Bookmark page
|
||||
if ($cmd === '05') {
|
||||
$this->sendBaseline($client, RED.'NOT IMPLEMENTED YET?');
|
||||
$this->sendBaseline($client,RED.'NOT IMPLEMENTED YET?');
|
||||
$mode = FALSE;
|
||||
|
||||
break;
|
||||
@@ -596,7 +645,7 @@ abstract class Server {
|
||||
|
||||
// Report a problem
|
||||
if ($cmd === '08') {
|
||||
$this->sendBaseline($client, RED.'NOT IMPLEMENTED YET?');
|
||||
$this->sendBaseline($client,RED.'NOT IMPLEMENTED YET?');
|
||||
$mode = FALSE;
|
||||
|
||||
break;
|
||||
@@ -607,6 +656,7 @@ abstract class Server {
|
||||
$client->send(COFF);
|
||||
$action = ACTION_GOTO;
|
||||
$cmd = '';
|
||||
$next_page = $this->fo->page(TRUE);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -622,8 +672,8 @@ abstract class Server {
|
||||
$current['prevmode'] = FALSE;
|
||||
|
||||
// @todo The cursor color could be wrong
|
||||
$client->send($this->outputPosition($current['field']->x,$current['field']->y).CON);
|
||||
$client->send(str_repeat($fo::$if_filler, $current['field']->length));
|
||||
$client->send($this->moveCursor($current['field']->x,$current['field']->y).CON);
|
||||
$client->send(str_repeat($this->fo::$if_filler,$current['field']->length));
|
||||
$current['fieldreset'] = TRUE;
|
||||
|
||||
} else {
|
||||
@@ -638,18 +688,36 @@ abstract class Server {
|
||||
$client->send(COFF);
|
||||
$timewarpalt = FALSE;
|
||||
|
||||
// If input is in a control, terminate it
|
||||
if ($control)
|
||||
{
|
||||
$method->pop();
|
||||
$control = FALSE;
|
||||
|
||||
// Our method count should be zero
|
||||
if ($method->count())
|
||||
dd($method);
|
||||
}
|
||||
|
||||
// Nothing typed between * and #
|
||||
// *# means go back
|
||||
if ($cmd === '') {
|
||||
$action = ACTION_BACKUP;
|
||||
|
||||
} elseif ($cmd === '0') {
|
||||
$page = $user->exists ? ['frame'=>1,'index'=>'a'] : ['frame'=>980,'index'=>'a']; // @todo Get from DB.
|
||||
$next_page = ['frame'=>$user->exists ? 1 : 980]; // @todo Get from DB.
|
||||
$action = ACTION_GOTO;
|
||||
|
||||
// Edit Frame
|
||||
} elseif (preg_match('/^04/',$cmd)) {
|
||||
$client->send(COFF);
|
||||
$action = ACTION_EDIT;
|
||||
$next_page = [
|
||||
'frame' => substr($cmd,2) ?: $this->fo->frame(),
|
||||
];
|
||||
|
||||
} else {
|
||||
$page['frame'] = $cmd;
|
||||
$page['index'] = 'a';
|
||||
$next_page = ['frame'=>$cmd];
|
||||
$action = ACTION_GOTO;
|
||||
}
|
||||
|
||||
@@ -661,17 +729,24 @@ abstract class Server {
|
||||
|
||||
break;
|
||||
|
||||
// Control is taking input
|
||||
case MODE_CONTROL:
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->log('debug','Not sure what we were doing?');
|
||||
}
|
||||
}
|
||||
|
||||
printf("- End Mode: Read %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",$read,ord($read),$mode,$action,$control);
|
||||
printf("- End MODE: Read %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",
|
||||
(ord($read) < 32 ? '.' : $read),
|
||||
ord($read),
|
||||
serialize($mode),
|
||||
serialize($action),
|
||||
$control);
|
||||
}
|
||||
|
||||
// This section performs some action if it is deemed necessary
|
||||
if ($action) {
|
||||
printf("+ Performing action: %s\n",$action);
|
||||
}
|
||||
printf("= Start ACTION: %s\n",serialize($action));
|
||||
|
||||
switch ($action) {
|
||||
case ACTION_STAR:
|
||||
@@ -679,7 +754,10 @@ abstract class Server {
|
||||
|
||||
// If there is something on the baseline, lets preserve it
|
||||
if ($this->blp)
|
||||
{
|
||||
printf(". Preserving Baseline: %s\n",$this->baseline);
|
||||
$current['baseline'] = $this->baseline;
|
||||
}
|
||||
|
||||
$this->sendBaseline($client,GREEN.STAR,TRUE);
|
||||
$client->send(CON);
|
||||
@@ -696,6 +774,30 @@ abstract class Server {
|
||||
|
||||
break;
|
||||
|
||||
// Edit Frame
|
||||
case ACTION_EDIT:
|
||||
$this->log('debug','Editing frame:',[$next_page]);
|
||||
|
||||
$next_fo = NULL;
|
||||
// If we are editing a different frame, load it
|
||||
try {
|
||||
$next_fo = $this->mo->framePage($next_page['frame'],array_get($next_page,'index','a'),$this);
|
||||
|
||||
} catch (ModelNotFoundException $e) {
|
||||
$next_fo = $this->mo->frameNew($this,$next_page['frame'],$next_page['index']);
|
||||
}
|
||||
|
||||
$control = CONTROL_EDIT;
|
||||
$method->push(Control::factory('editframe',$this,$next_fo));
|
||||
$next_fo = NULL;
|
||||
$method->last()->state['control'] = $control;
|
||||
$method->last()->state['action'] = FALSE;
|
||||
$method->last()->state['mode'] = MODE_FIELD;
|
||||
$mode = MODE_CONTROL;
|
||||
$action = FALSE;
|
||||
|
||||
break;
|
||||
|
||||
// GO Backwards
|
||||
case ACTION_BACKUP:
|
||||
// Do we have anywhere to go, drop the current page from the history.
|
||||
@@ -716,116 +818,126 @@ abstract class Server {
|
||||
}
|
||||
}
|
||||
|
||||
$page = $history->last();
|
||||
$next_page = $history->last();
|
||||
|
||||
$this->log('debug','Backing up to:',$page);
|
||||
// If there is no next page, we'll refresh the current page.
|
||||
if ($next_page)
|
||||
$this->log('debug','Backing up to:',$next_page);
|
||||
|
||||
// Go to next index frame.
|
||||
case ACTION_NEXT:
|
||||
// We need this extra test in case we come from ACTION_BACKUP
|
||||
if ($action == ACTION_NEXT)
|
||||
{
|
||||
$current['page']['index'] = $fo->index();
|
||||
$page['index'] = $fo->index_next();
|
||||
$current['page']['index'] = $this->fo->index();
|
||||
$next_page = ['frame'=>$this->fo->frame(),'index'=>$this->fo->index_next()];
|
||||
}
|
||||
|
||||
// Look for requested page
|
||||
// Look for requested page - charge for it to be loaded.
|
||||
case ACTION_GOTO:
|
||||
$current['frame'] = $fo;
|
||||
|
||||
// If we wanted a "Searching..." message, this is where to put it.
|
||||
try {
|
||||
$fo = $timewarpalt
|
||||
? $this->mo->frame(FrameModel::findOrFail($timewarpalt))
|
||||
: $this->mo->frameLoad($page['frame'],array_get($page,'index','a'),$this);
|
||||
|
||||
$this->log('debug',sprintf('Fetched frame: %s (%s)',$fo->id(),$fo->page()));
|
||||
|
||||
} catch (ModelNotFoundException $e) {
|
||||
$this->sendBaseline($client,ERR_PAGE);
|
||||
$mode = $action = FALSE;
|
||||
|
||||
$fo = $current['frame'] ?: $this->mo->frame($this->testFrame());
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Is there a user logged in
|
||||
if ($user)
|
||||
if ($next_page OR $timewarpalt)
|
||||
{
|
||||
if ($fo->isFramePublic() AND $fo->isAccessible())
|
||||
{
|
||||
if ($fo->type() == Frame::FRAMETYPE_LOGIN AND $user->isMemberCUG($fo->getCUG()))
|
||||
{
|
||||
$this->sendBaseline($client,ERR_USER_ALREADYMEMBER);
|
||||
$fo = $current['frame'];
|
||||
$page = $history->last();
|
||||
$mode = $action = FALSE;
|
||||
$this->log('debug',sprintf('Frame Denied - Already Member: %s (%s)',$fo->id(),$fo->page()));
|
||||
// If we wanted a "Searching..." message, this is where to put it.
|
||||
try {
|
||||
// Store our next frame in a temporary var while we determine if it can be displayed
|
||||
$fo = $timewarpalt
|
||||
? $this->mo->frameID($timewarpalt)
|
||||
: $this->mo->framePage($next_page['frame'],array_get($next_page,'index','a'),$this);
|
||||
|
||||
break;
|
||||
}
|
||||
$this->log('debug',sprintf('Fetched frame: %s (%s)',$fo->id(),$fo->page()));
|
||||
|
||||
// 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);
|
||||
$fo = $current['frame'];
|
||||
$page = $history->last();
|
||||
$mode = $action = FALSE;
|
||||
$this->log('debug',sprintf('Frame Denied - In Accessible: %s (%s)',$fo->id(),$fo->page()));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (! $user->isMemberCUG($fo->getCUG()))
|
||||
{
|
||||
$this->sendBaseline($client, ERR_PRIVATE);
|
||||
$fo = $current['frame'];
|
||||
$page = $history->last();
|
||||
$mode = $action = FALSE;
|
||||
$this->log('debug',sprintf('Frame Denied - Not in CUG [%s]: %s (%s)',$fo->getCUG()->id,$fo->id(),$fo->page()));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Is this a public frame in CUG 0?
|
||||
if (! $fo->isCUG(0) OR ! $fo->isFramePublic())
|
||||
{
|
||||
} catch (ModelNotFoundException $e) {
|
||||
// @todo Make sure parent frame exists, or display error
|
||||
$this->sendBaseline($client,ERR_PAGE);
|
||||
$mode = $action = FALSE;
|
||||
|
||||
if (! $fo)
|
||||
$fo = $this->mo->frameTest($this);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Is there a user logged in
|
||||
if ($user)
|
||||
{
|
||||
if ($fo->isFramePublic() AND $fo->isAccessible())
|
||||
{
|
||||
if ($fo->type() == Frame::FRAMETYPE_LOGIN AND $user->isMemberCUG($fo->getCUG()))
|
||||
{
|
||||
$this->sendBaseline($client,ERR_USER_ALREADYMEMBER);
|
||||
$next_page = $history->last();
|
||||
$mode = $action = FALSE;
|
||||
$this->log('debug',sprintf('Frame Denied - Already Member: %s (%s)',$fo->id(),$fo->page()));
|
||||
|
||||
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);
|
||||
$next_page = $history->last();
|
||||
$mode = $action = FALSE;
|
||||
$this->log('debug',sprintf('Frame Denied - In Accessible: %s (%s)',$fo->id(),$fo->page()));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (! $user->isMemberCUG($fo->getCUG()))
|
||||
{
|
||||
$this->sendBaseline($client,ERR_PRIVATE);
|
||||
$next_page = $history->last();
|
||||
$mode = $action = FALSE;
|
||||
$this->log('debug',sprintf('Frame Denied - Not in CUG [%s]: %s (%s)',$fo->getCUG()->id,$fo->id(),$fo->page()));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Is this a public frame in CUG 0?
|
||||
if (! $fo->isCUG(0) OR ! $fo->isFramePublic())
|
||||
{
|
||||
$this->sendBaseline($client,ERR_PAGE);
|
||||
$next_page = $history->last();
|
||||
$mode = $action = FALSE;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$current['page'] = $fo->page(TRUE);
|
||||
$current['fieldpos'] = 0;
|
||||
|
||||
// Only if new location, not going backwards
|
||||
if (($history->last() != $page) AND ($action == ACTION_GOTO || $action == ACTION_NEXT)) {
|
||||
$history->push($page);
|
||||
if (($history->last() != $next_page) AND ($action == ACTION_GOTO || $action == ACTION_NEXT)) {
|
||||
$history->push($next_page);
|
||||
}
|
||||
|
||||
$current['fieldpos'] = 0;
|
||||
$this->fo = $fo;
|
||||
$fo = NULL;
|
||||
$next_page = NULL;
|
||||
$timewarpalt = NULL;
|
||||
|
||||
printf("+ Mode is: %s\n",$mode);
|
||||
|
||||
// drop into
|
||||
case ACTION_RELOAD:
|
||||
// Clear the baseline history
|
||||
$this->sendBaseline($client,'');
|
||||
$output = (string)$fo;
|
||||
$current['baseline'] = '';
|
||||
|
||||
$output = (string)$this->fo;
|
||||
|
||||
if ($timewarpalt) {
|
||||
$this->sendBaseline($client,sprintf(MSG_TIMEWARP_TO,$fo->created() ? $fo->created()->format('Y-m-d H:i:s') : 'UNKNOWN'));
|
||||
$this->sendBaseline($client,sprintf(MSG_TIMEWARP_TO,$this->fo->created() ? $this->fo->created()->format('Y-m-d H:i:s') : 'UNKNOWN'));
|
||||
}
|
||||
|
||||
switch ($fo->type()) {
|
||||
switch ($this->fo->type()) {
|
||||
default:
|
||||
// Standard Frame
|
||||
case Frame::FRAMETYPE_INFO:
|
||||
@@ -842,7 +954,7 @@ abstract class Server {
|
||||
|
||||
// If this is the registration page
|
||||
// @todo Should be evaluated out of the DB
|
||||
if ($fo->page() == '981a') {
|
||||
if ($this->fo->page() == '981a') {
|
||||
$control = CONTROL_METHOD;
|
||||
$method->push(Control::factory('register',$this));
|
||||
$method->last()->state['control'] = $control;
|
||||
@@ -857,10 +969,10 @@ abstract class Server {
|
||||
$fielddata = [];
|
||||
$current['fielddata'] = [];
|
||||
|
||||
if (count($fo->fields)) {
|
||||
if ($this->fo->fields()->count()) {
|
||||
// Get our first editable field.
|
||||
$current['fieldnum'] = $fo->getFieldId('edit',0);
|
||||
$current['field'] = $fo->getField($current['fieldnum']);
|
||||
$current['fieldnum'] = $this->fo->getFieldId('edit',0);
|
||||
$current['field'] = $this->fo->getField($current['fieldnum']);
|
||||
$current['fieldreset'] = TRUE;
|
||||
|
||||
if ($current['fieldnum'] !== FALSE) {
|
||||
@@ -896,17 +1008,17 @@ abstract class Server {
|
||||
$cmd = '';
|
||||
$y = 0;
|
||||
|
||||
$output = $this->outputPosition(0, $y++) . WHITE . NEWBG . RED . 'TIMEWARP INFO FOR Pg.' . BLUE . $fo->page(). WHITE;
|
||||
//$output .= $this->outputPosition(0, $y++) . WHITE . NEWBG . BLUE . 'Service : ' . substr($service['service_name'] . str_repeat(' ', 27), 0, 27);
|
||||
//$output .= $this->outputPosition(0, $y++) . WHITE . NEWBG . BLUE . 'Varient : ' . substr($varient['varient_name'] . str_repeat(' ', 27), 0, 27);
|
||||
$output .= $this->outputPosition(0, $y++) . WHITE . NEWBG . BLUE . 'Dated : ' .substr(($fo->created() ? $fo->created()->format('j F Y') : 'Unknown').str_repeat(' ', 27), 0, 27);
|
||||
$output = $this->moveCursor(0,$y++).WHITE.NEWBG.RED.'TIMEWARP INFO FOR Pg.'.BLUE.$this->fo->page().WHITE;
|
||||
//$output .= $this->moveCursor(0,$y++).WHITE.NEWBG.BLUE.'Service : '.substr($service['service_name'].str_repeat(' ',27),0,27);
|
||||
//$output .= $this->moveCursor(0,$y++).WHITE.NEWBG.BLUE.'Varient : '.substr($varient['varient_name'].str_repeat(' ',27),0,27);
|
||||
$output .= $this->moveCursor(0,$y++).WHITE.NEWBG.BLUE.'Dated : ' .substr(($this->fo->created() ? $this->fo->created()->format('j F Y') : 'Unknown').str_repeat(' ',27),0,27);
|
||||
|
||||
$alts = $fo->alts($this->mo)->get();
|
||||
$alts = $this->fo->alts($this->mo)->get();
|
||||
|
||||
if (count($alts)) {
|
||||
$n = 1;
|
||||
|
||||
$output .= $this->outputPosition(0, $y++) . WHITE . NEWBG . RED . 'ALTERNATIVE VERSIONS:' . str_repeat(' ', 16);
|
||||
$output .= $this->moveCursor(0,$y++).WHITE.NEWBG.RED.'ALTERNATIVE VERSIONS:'.str_repeat(' ',16);
|
||||
|
||||
foreach ($alts as $o) {
|
||||
$date = $o->created_at->format('d M Y');
|
||||
@@ -919,7 +1031,7 @@ abstract class Server {
|
||||
|
||||
$line .= BLUE.$date.' '.$o->note;
|
||||
|
||||
$output .= $this->outputPosition(0,$y++).$line.str_repeat(' ',40-$this->strlenv($line)); // @todo should use frame::page_length
|
||||
$output .= $this->moveCursor(0,$y++).$line.str_repeat(' ',40-$this->fo->strlenv($line)); // @todo should use frame::page_length
|
||||
}
|
||||
|
||||
if ($timewarp) {
|
||||
@@ -933,11 +1045,16 @@ abstract class Server {
|
||||
break;
|
||||
}
|
||||
|
||||
printf("- End Action: Read %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",$read,ord($read),$mode,$action,$control);
|
||||
printf("- End ACTION: Read %s (%s): Mode: [%s], Action: [%s], Control: [%s]\n",
|
||||
(ord($read) < 32 ? '.' : $read),
|
||||
ord($read),
|
||||
serialize($mode),
|
||||
serialize($action),
|
||||
$control);
|
||||
|
||||
// We need to reposition the cursor to the current field.
|
||||
if ($current['fieldreset'] !== FALSE) {
|
||||
$client->send($this->outputPosition($current['field']->x,$current['field']->y).CON);
|
||||
$client->send($this->moveCursor($current['field']->x,$current['field']->y).CON);
|
||||
$current['fieldreset'] = FALSE;
|
||||
}
|
||||
|
||||
@@ -962,7 +1079,7 @@ abstract class Server {
|
||||
/**
|
||||
* Move the cursor via the shortest path.
|
||||
*/
|
||||
abstract function outputPosition($x,$y);
|
||||
abstract function moveCursor($x,$y);
|
||||
|
||||
/**
|
||||
* Send a message to the base line
|
||||
@@ -973,20 +1090,4 @@ abstract class Server {
|
||||
* @param bool $reposition
|
||||
*/
|
||||
abstract function sendBaseline($client,$text,$reposition=FALSE);
|
||||
|
||||
/**
|
||||
* Calculate the length of text
|
||||
*
|
||||
* ESC characters are two chars, and need to be counted as one.
|
||||
*
|
||||
* @param $text
|
||||
* @return int
|
||||
*/
|
||||
abstract function strlenv($text):int;
|
||||
|
||||
/**
|
||||
* Return a test frame appropriate for this server.
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function testFrame();
|
||||
}
|
Reference in New Issue
Block a user