diff --git a/app/Classes/TTY.php b/app/Classes/TTY.php deleted file mode 100644 index 66a6264..0000000 --- a/app/Classes/TTY.php +++ /dev/null @@ -1,918 +0,0 @@ -sendf = new FileSend; // @todo these should be delcared private if they are staying here - $this->recvf = new FileReceive; - $this->rnode = new rnode; - } - - protected function check_cps(): void - { - Log::debug('- Start',['m'=>__METHOD__]); - - $cpsdelay=10; // $cpsdelay=cfgi(CFG_MINCPSDELAY); - $ncps = 38400/1000; $this->speed/1000; - $r=1; //$r=cfgi(CFG_REALMINCPS); - - if(!($this->sendf->cps=time()-$this->sendf->start)) { - $this->sendf->cps=1; - } else { - $this->sendf->cps=($this->sendf->foff-$this->sendf->soff)/$this->sendf->cps; - } - - if(!($this->recvf->cps=time()-$this->recvf->start)) { - $this->recvf->cps=1; - } else { - $this->recvf->cps=($this->recvf->foff-$this->recvf->soff)/$this->recvf->cps; - } - - if($this->sendf->start&&(true ? 0 : cfgi(CFG_MINCPSOUT))>0&&(time()-$this->sendf->start)>$cpsdelay&&$this->sendf->cps<($r?$cci:$cci*$ncps)) { - //write_log("mincpsout=%d reached, aborting session",r?cci:cci*ncps); - $tty_gothup = self::HUP_CPS; - } - - if($this->recvf->start&&(true ? 0 : cfgi(CFG_MINCPSIN))>0&&(time()-$this->recvf->start)>$cpsdelay&&$this->recvf->cps<($r?$cci:$cci*$ncps)) { - //write_log("mincpsin=%d reached, aborting session",r?cci:cci*ncps); - $tty_gothup = self::HUP_CPS; - } - - $this->getevt(); - - Log::debug('- End',['m'=>__METHOD__]); - } - - // @todo no longer used? - protected function getevt(): void - { - Log::debug('+ Start', ['m' => __METHOD__]); - $qsndbuflen = 0; - - while($this->qrecvpkt($qrcv_buf)) { - Log::debug(' - qrecvpkt Returned', ['m' => __METHOD__,'qrcv_buf'=>$qrcv_buf]); - - switch($qrcv_buf[2]) { // @todo this doesnt seem right? - case self::QR_SKIP: - //$this->rxstatus=self::RX_SKIP; - break; - - case self::QR_REFUSE: - //$this->rxstatus=self::RX_SUSPEND; - break; - - case self::QR_HANGUP: - $tty_gothup = self::HUP_OPERATOR; - break; - - case self::QR_CHAT: - /* - if($qrcv_buf[3]) { - xstrcpy((qsnd_buf+qsndbuflen),(qrcv_buf+3),self::CHAT_BUF-$qsndbuflen); - $qsndbuflen+=strlen((qrcv_buf+3)); - if($qsndbuflen>self::CHAT_BUF-128) { - $qsndbuflen=self::CHAT_BUF-128; - } - } else { - $i=$chatprot; - $chatprot=-1; - chatsend(qsnd_buf); - if($chatlg) { - chatlog_done(); - } - $chatlg=0; - $chatprot=i; - xstrcat($qsnd_buf,"\n * Chat closed\n",CHAT_BUF); - chatsend($qsnd_buf); - if($chattimer>1) { - qlcerase(); - } - $qsndbuflen=0; - $chattimer=1; - } - */ - break; - } - $qsnd_buf[$qsndbuflen]=0; - } - - if ($qsndbuflen>0) - if(! $this->chatsend($qsnd_buf)) { - $qsndbuflen=0; - } - - Log::debug('- End', ['m' => __METHOD__]); - } - - protected function qrecvpkt(&$str): int - { - Log::debug('+ Start',['m'=>__METHOD__,'str'=>$str]); - - /* - if (! $this->xsend_cb) { - return 0; - } - */ - - $rc = $this->xrecv($this->client->connection,$str,self::MSG_BUFFER-1,0); - Log::debug(sprintf(' - qrecvpkt Got [%x] (%d)',$rc,$rc),['m'=>__METHOD__]); - if ( $rc < 0 && $this->errno != 11 /*MSG_EAGAIN*/ ) { - if ($this->errno == self::ECONNREFUSED) { - $xsend_cb = NULL; - } - //DEBUG(('I',1,"can't recv (fd=%d): %s",ssock,strerror(errno))); - } - Log::debug(sprintf(' - qrecvpkt Got [%x] (%d)',$rc,$rc),['m'=>__METHOD__,'str'=>$str,'len'=>strlen($str)]); - if ($rc < 3 || ! substr($str,0,2)) { - Log::debug('+ End',['m'=>__METHOD__,'rc'=>0]); - return 0; - } - - //str[rc] = '\0'; - if (! $rc) - $str = ''; - - Log::debug('+ End',['m'=>__METHOD__,'rc'=>$rc]); - return $rc; - } - - protected function rxclose(&$f, int $what): int - { - Log::debug('+ Start',['m'=>__METHOD__,'what'=>$what,'f'=>$f]); - - $cps=time()-$this->recvf->start; - $ss = ''; - - if(!$f || !$f) { - Log::debug('= End',['m'=>__METHOD__,'rc'=>self::FOP_ERROR]); - return self::FOP_ERROR; - } - - $this->recvf->toff+=$this->recvf->foff; - $this->recvf->stot+=$this->recvf->soff; - $p2=0; - if(! $cps) { - $cps=1; - } - - $cps=($this->recvf->foff-$this->recvf->soff)/$cps; - /* - IFPerl(if((ss=perl_end_recv(what))) { - if(!$ss) { - $what=self::FOP_SKIP; - } else { - $p2 = $ss; //xstrcpy(p2,ss,MAX_PATH); - } - }); - */ - switch($what) { - case self::FOP_SUSPEND: - $ss="suspended"; - break; - case self::FOP_SKIP: - $ss="skipped"; - break; - case self::FOP_ERROR: - $ss="error"; - break; - case self::FOP_OK: - $ss="ok"; - break; - default: - $ss=""; - } - - Log::debug(' -',['m'=>__METHOD__,'soff'=>$this->recvf->soff,'ss'=>$ss]); - if($this->recvf->soff) { - //write_log("rcvd: %s, %lu bytes (from %lu), %ld cps [%s]", - // recvf.fname, (long) recvf.foff, (long) recvf.soff, cps, ss); - } else { - //write_log("rcvd: %s, %lu bytes, %ld cps [%s]", - // recvf.fname, (long) recvf.foff, cps, ss); - } - - fclose($f); - $f=''; - - /* - snprintf(p, MAX_PATH, "%s/tmp/%s", cfgs(CFG_INBOUND), recvf.fname); - if($p2) { - if($p2!='/'&&*$p2=='.') { - $ss=xstrdup($p2); - snprintf($p2,MAX_PATH,"%s/%s",cfgs(CFG_INBOUND),$ss); - xfree($ss); - } - } else { - snprintf(p2, MAX_PATH, "%s/%s", cfgs(CFG_INBOUND), recvf.fname); - } - */ - - //$ut->actime=$ut->modtime=$this->recvf->mtime; - $this->recvf->foff=0; - switch($what) { - case self::FOP_SKIP: - unlink($p); - break; - case self::FOP_SUSPEND: - case self::FOP_ERROR: - /* - if($this->whattype($p)==self::IS_PKT&&cfgi(self::CFG_KILLBADPKT)) { - unlink($p); - } else { - //utime(p,&ut); - touch ($this->recvf->name,octdec($this->recvf->mtime)); - } - */ - break; - case self::FOP_OK: - $rc=isset($receive_callback)?receive_callback($p):0; - - if($rc) { - //lunlink(p); - } else { - $ss=$p2+strlen($p2)-1; - $overwrite=0; - /* - for(i=cfgsl(CFG_ALWAYSOVERWRITE); i; i=i->next) - if(!xfnmatch(i->str,recvf.fname,FNM_PATHNAME)) { - $overwrite=1; - } - while(!$overwrite&&!stat(p2, &sb)&&p2[0]) { - if(sifname(ss)) { - ss--; - while('.' == *ss && ss >= p2) { - ss--; - } - if(ss < p2) { - write_log("can't find suitable name for %s: leaving in temporary directory",p); - p2[0] = '\x00'; - } - } - } - if(p2[0]) { - if(overwrite) { - lunlink(p2); - } - if(rename(p, p2)) { - write_log("can't rename %s to %s: %s",p,p2,strerror(errno)); - } else { - utime(p2,&ut); - chmod(p2,cfgi(CFG_DEFPERM)); - } - } - */ - Log::debug(sprintf('Recevied [%s] with mtime [%s]',$this->f->name,$this->recvf->mtime),['m'=>__METHOD__]); - touch('/tmp/tmp/'.$this->f->name,$this->recvf->mtime); - } - break; - } - - if($what==self::FOP_SKIP||$what==self::FOP_SUSPEND) { - $skipiftic=$what; - } - $this->recvf->start=0; - $this->recvf->ftot=0; - //$this->rxstatus=0; - Log::debug('= End',['m'=>__METHOD__,'rc'=>$what]); - return $what; - } - - protected function rxopen(string $name,int $rtime,int $rsize,string &$f): int - { - Log::debug('+ Start',['m'=>__METHOD__,'name'=>$name,'rtime'=>$rtime,'rsize'=>$rsize,'f'=>$f]); - - $ccs = '/tmp'; // @todo Base path needs to be a config item - $this->speed = 38400; - - $prevcps = ($this->recvf->start&&(time()-$this->recvf->start>2))?$this->recvf->cps:$this->speed/10; - - if(! $name) { - return self::FOP_ERROR; - } - - $bn = basename($name);//xstrcpy($bn, qbasename($name), self::MAX_PATH); - Log::debug(sprintf(' - bn[%s]',$bn),['m'=>__METHOD__]); - //mapname((char*)bn, cfgs(CFG_MAPIN), MAX_PATH); - - //$this->recvf->start=(int)decoct(time()); - $this->recvf->start=time(); - //xfree(recvf.fname); - $this->recvf->fname=$bn; //xstrdup($bn); - //dd(['rtime'=>$rtime,'start'=>$this->recvf->start]); - $this->recvf->mtime=$rtime; //-gmtoff($this->recvf->start); - $this->recvf->ftot=$rsize; - if($this->recvf->toff+$rsize > $this->recvf->ttot) { - $this->recvf->ttot+=$rsize; - } - - $this->recvf->nf++; - if($this->recvf->nf > $this->recvf->allf) { - $this->recvf->allf++; - } - //IFPerl(if((rc=perl_on_recv())!=FOP_OK)return rc); - /* - if($this->whattype($name)==self::IS_PKT&&($rsize==60||!$rsize)&&cfgi(self::CFG_KILLBADPKT)) { - return self::FOP_SKIP; - } - */ - $rc=$skipiftic = 0; // @todo - $skipiftic=0; - if($rc&&istic($bn)&&cfgi(self::CFG_AUTOTICSKIP)) { - //write_log($rc==self::FOP_SKIP?$weskipstr:$wesusstr,$this->recvf->fname,"auto"); - return $rc; - } - // @todo - /* - for($i=cfgsl(self::CFG_AUTOSKIP); $i; $i=$i->next) - if(!$this->xfnmatch($i->str,$bn, self::FNM_PATHNAME)) { - //write_log(weskipstr,$this->recvf.fname,""); - $skipiftic=self::FOP_SKIP; - return self::FOP_SKIP; - } - for($i=cfgsl(self::CFG_AUTOSUSPEND); $i; $i=$i->next) - if(!$this->xfnmatch($i->str, $bn, self::FNM_PATHNAME)) { - //write_log(wesusstr,$this->recvf->fname,""); - $skipiftic=self::FOP_SUSPEND; - return self::FOP_SUSPEND; - } - */ - - $p = '/tmp/tmp/'; //@todo snprintf(p, MAX_PATH, "%s/tmp/", cfgs(CFG_INBOUND)); - - //if ($sb = stat($p)) // if(stat($p, &sb)) - if(! is_dir($p) AND ! mkdir($p)) { // && $errno!=EEXIST - Log::debug(sprintf(' - dir doesnt exist and cannot make it? [%s]',$p),['m'=>__METHOD__,'rc'=>self::FOP_SUSPEND]); - //write_log("can't make directory %s: %s", p, strerror(errno)); - //write_log(wesusstr,$this->recvf.fname,""); - $skipiftic=self::FOP_SUSPEND; - return self::FOP_SUSPEND; - } - - $p = sprintf('%s/%s',$ccs,$bn);// snprintf($p, self::MAX_PATH, "%s/%s", $ccs, $bn); - - if(file_exists($p) AND ($sb=stat($p)) && $sb['size']==$rsize) {//if(!stat(p, &sb) && sb.st_size==rsize) { - Log::debug(sprintf(' - file exists and size is same? [%s]',$p),['m'=>__METHOD__,'sb'=>$sb,'rsize'=>$rsize,'rc'=>self::FOP_SKIP]); - //write_log(weskipstr,$this->recvf.fname,""); - $skipiftic=self::FOP_SKIP; - return self::FOP_SKIP; - } - - //dd(['maxpath'=>self::MAX_PATH,'bn'=>$bn]); - //snprintf($p, self::MAX_PATH, "%s/tmp/%s", $ccs, $bn); - $p = sprintf('%s/tmp/%s',$ccs,$bn); - - // If the file exists - if (file_exists($p) AND $sb=stat($p)) {//if(!stat(p, &sb)) { - Log::debug(sprintf(' - file exists... [%s]',$p),['m'=>__METHOD__,'sb'=>$sb,'rsize'=>$rsize, - 'mtime'=>$this->recvf->mtime, - //'mtime-decopt'=>(int)decoct($this->recvf->mtime), - //'mtime-octdec'=>(int)octdec($this->recvf->mtime), - 'sbmtime'=>$sb['mtime'], - 'sbmtime-decopt'=>(int)decoct($sb['mtime']), - //'sbmtime-octdec'=>(int)octdec($sb['mtime']), - ]); - // @todo binkp doesnt use octal. - if($sb['size']<$rsize && $sb['mtime']==(int)$this->recvf->mtime) { - Log::debug(sprintf(' - attempt open for append [%s]',$p),['m'=>__METHOD__]); - - $f=fopen($p, "ab"); - if(!$f) { - Log::debug(sprintf(' - attempt open for append FAILED [%s]',$p),['m'=>__METHOD__,'rc'=>self::FOP_SUSPEND]); - //write_log("can't open file %s for writing: %s", p,strerror(errno)); - //write_log(wesusstr,$this->recvf.fname,""); - $skipiftic=self::FOP_SUSPEND; - return self::FOP_SUSPEND; - } - Log::debug(sprintf(' - FTELL REPORTS [%s]',serialize(ftell($f))),['m'=>__METHOD__]); - // ftell() gives undefined results for append-only streams (opened with "a" flag). - $this->recvf->foff = $this->recvf->soff = $sb['size']; //ftell($f); - Log::debug(sprintf(' - open for append [%s] at [%d]',$p,$this->recvf->soff),['m'=>__METHOD__,'rc'=>self::FOP_CONT]); - //if(cfgi(self::CFG_ESTIMATEDTIME)) { - //write_log("start recv: %s, %lu bytes (from %lu), estimated time %s", - // $this->recvf.fname, (long) rsize, (long) $this->recvf.soff, estimatedtime(rsize-$this->recvf.soff,prevcps,effbaud)); - //} - return self::FOP_CONT; - } - } - - $f=fopen($p, "wb"); - if(!$f) { - //write_log("can't open file %s for writing: %s", p,strerror(errno)); - //write_log(wesusstr,$this->recvf.fname,""); - $skipiftic=self::FOP_SUSPEND; - return self::FOP_SUSPEND; - } - - //dd(['sb'=>$sb,'recvf'=>$this->recvf]); - Log::debug(sprintf(' - new file created [%s]',$p),['m'=>__METHOD__,'rc'=>self::FOP_OK]); - $this->recvf->foff = $this->recvf->soff = 0; - //if(cfgi(self::CFG_ESTIMATEDTIME)) { - //write_log("start recv: %s, %lu bytes, estimated time %s", - // $this->recvf.fname, (long) rsize, estimatedtime(rsize,prevcps,effbaud)); - //} - return self::FOP_OK; - } - - public function setClient(SocketClient $client): void - { - $this->client = $client; - } - - public function timer_expired(int $timer): int - { - return (time()>=$timer); - } - - public function timer_rest(int $timer): int - { - return (($timer)-time()); - } - - public function timer_set(int $expire): int - { - return (time()+$expire); - } - - protected function txclose(&$f, int $what):int - { - $cps=time()-$this->sendf->start; - - if(!$f) { - return self::FOP_ERROR; - } - $this->sendf->toff+=$this->sendf->foff; - $this->sendf->stot+=$this->sendf->soff; - - if(!$cps) { - $cps=1; - } - $cps=($this->sendf->foff-$this->sendf->soff)/$cps; - //IFPerl(perl_end_send(what)); - switch($what) { - case self::FOP_SUSPEND: - $ss="suspended"; - break; - case self::FOP_SKIP: - $ss="skipped"; - break; - case self::FOP_ERROR: - $ss="error"; - break; - case self::FOP_OK: - $ss="ok"; - break; - default: - $ss=""; - } - if($this->sendf->soff) {} - //write_log("sent: %s, %lu bytes (from %lu), %ld cps [%s]", sendf.fname, (long) sendf.foff, (long) sendf.soff, cps, ss); - else {} - //write_log("sent: %s, %lu bytes, %ld cps [%s]",sendf.fname, (long) sendf.foff, cps, ss); - $this->sendf->foff=0; - $this->sendf->ftot=0; - $this->sendf->start=0; - fclose($f); - $f=NULL; - return $what; - } - - protected function xrecv($sock,&$buf,int $len,int $wait):int - { - Log::debug('+ Start',['m'=> __METHOD__]); - - $l = 0; - - if (! $sock) { - $this->errno = self::EBADF; - return -1; - } - - if (! $wait) { - Log::debug(' - Not wait',['m'=> __METHOD__]); - $tv_tv_sec = 0; - $tv_tv_usec = 0; - $rfd = 0; //FD_ZERO(&rfd); - //FD_SET(sock, &rfd); - $read = [$sock]; - $write = []; - $except = []; - $rc = socket_select($read,$write,$except,0,0); - //$foo = ''; - //$rc = socket_recv($this->client->connection,$foo,1,MSG_PEEK | MSG_DONTWAIT); - Log::debug(' - socket_select',['m'=> __METHOD__,'rc'=>$rc,'read'=>$read,'write'=>$write,'except'=>$except]); - //$rc = $this->client->hasData(0); - if ($rc < 1) { - if (! $rc) { - $this->errno = 11; //MSG_EAGAIN; - } - - return -1; - } - } - - Log::debug(sprintf(' - doing a read now for [%d].',$len)); - $rc = socket_recv($read[0],$l,$len,MSG_PEEK | MSG_DONTWAIT); - Log::debug(' - socket_recv PEEK', ['m' => __METHOD__,'l'=>$l,'rc'=>$rc]); - - if ($rc <= 0) { - return $rc; - } - - if ($rc == 2) { - return 2; - //l = I2H16(l); -// $l = unpack('s',$l); - $l = ((ord($l[0])&0x7f)<<8)+ord($l[1]); - -// dd(['l'=>$l,'0'=>ord($l[0])&0xf,'00'=>((ord($l[0])&0x7f)<<8)+ord($l[1]),'1'=>ord($l[1]),'hex'=>sprintf('%x',unpack('v',$l)),'len'=>$len]); - if (! $l) { - return 0; - } - - if ($l > $len) { - $l = $len; - } - - Log::debug(' - L is ',['m' => __METHOD__,'l'=>min($l+$rc,$len)]); - $rc = socket_recv($sock,$buf,min($l+$rc,$len),MSG_WAITALL); - Log::debug(' - socket_recv GOT', ['m' => __METHOD__,'buf'=>$buf,'len'=>strlen($buf),'rc'=>$rc]); - if ($rc <= 0) { - return $rc; - } - $rc = min($rc - 2, strlen($buf)); - if ($rc < 1) { - return 0; - } - if ($rc >= $len) { - $rc = $len - 2; - } - $buf = substr($buf,2,$rc); //memcpy(buf, buf + 2, rc); - return $rc; - } - - return 0; - } - - private function tty_bufc(int $ch): int - { - return $this->tty_bufblock( chr($ch), 1 ); - } - - // SocketClient::buffer_add() - public function tty_bufblock(string $data, int $nbytes): int - { - Log::debug(sprintf('%s: + Start [%s] (%d)',__METHOD__,$data,$nbytes)); - $rc = self::OK; - $txptr = self::TX_BUF_SIZE - $this->tty_tx_free; - $nptr = 0; - - $this->tty_status = self::TTY_SUCCESS; - - while ( $nbytes ) { - Log::debug(sprintf(' - Num Bytes [%d]: TX Free [%d]',$nbytes,$this->tty_tx_free)); - - if ( $nbytes > $this->tty_tx_free ) { - do { - $this->tty_bufflush( 5 ); - if ( $this->tty_status == self::TTY_SUCCESS ) { - $n = min($this->tty_tx_free,$nbytes); - $this->tty_tx_buf = substr($data,$nptr,$n); - $this->tty_tx_free -= $n; - $nbytes -= $n; - $nptr += $n; - } - } while ( $this->tty_status != self::TTY_SUCCESS ); - - } else { - Log::debug(sprintf(' -'),['data'=>$data,'nptr'=>$nptr,'txptr'=>$txptr,'tx_buff'=>substr($data,$nptr+$txptr,$nbytes)]); - - $this->tty_tx_buf .= $data;// memcpy( (void *) (tty_tx_buf + txptr), nptr, nbytes ); - $this->tty_tx_free -= $nbytes; - $nbytes = 0; - } - } - - Log::debug('= End',['m'=>__METHOD__,'rc'=>$rc]); - return $rc; - } - - private function tty_bufclear(): void - { - $this->tty_tx_ptr = 0; - $this->tty_tx_free = self::TX_BUF_SIZE; - $this->tty_tx_buf = ''; - } - - protected function tty_bufflush(int $tsec): int - { - Log::debug('+ Start',['m'=>__METHOD__,'tsec'=>$tsec,'txfree'=>$this->tty_tx_free,'txptr'=>$this->tty_tx_ptr,'txbuff'=>$this->tty_tx_buf]); - - $rc = self::OK; - $restsize = self::TX_BUF_SIZE - $this->tty_tx_free - $this->tty_tx_ptr; - - $tm = $this->timer_set( $tsec ); - while (self::TX_BUF_SIZE != $this->tty_tx_free ) { - $wd = true; - $tv = $this->timer_rest( $tm ); - - if (( $rc = $this->client->canSend($tv) > 0 && $wd )) { - - Log::debug(sprintf(' - Sending [%d]: Buffer [%s] Size [%d]',substr($this->tty_tx_buf,$this->tty_tx_ptr,$restsize),$this->tty_tx_buf,$restsize)); - $rc = $this->client->send(substr($this->tty_tx_buf,$this->tty_tx_ptr,$restsize),0,$restsize); - Log::debug(sprintf(' - Sent [%d]: Buffer [%s] Size [%d]',$rc,$this->tty_tx_buf,$restsize)); - - if ($rc == $restsize ) { - $this->tty_bufclear(); - } else if ( $rc > 0 ) { - $this->tty_tx_ptr += $rc; - $restsize -= $rc; - } else if ( $rc < 0 && $this->tty_status != self::TTY_TIMEOUT ) { - return self::ERROR; - } - - } else { - return $rc; - } - - if ($this->timer_expired( $tm )) { - return self::ERROR; - } - } - - Log::debug('= End',['m'=>__METHOD__,'rc'=>$rc]); - return $rc; - } - - public function tty_getc(int $timeout): int - { - Log::debug(sprintf('%s: + Start [%d]',__METHOD__,$timeout),['rx_left'=>$this->tty_rx_left]); - - if ($this->tty_rx_left == 0 ) { - if ($this->client->hasData($timeout) > 0) { - if (! ($this->tty_rx_buf = $this->client->read(0,self::RX_BUF_SIZE))) { - Log::debug(sprintf('%s: - Nothing read',__METHOD__)); - - return ($this->EWBOEA()) ? self::TTY_TIMEOUT : self::ERROR; - } - - Log::info(sprintf('%s: - Read [%d]',__METHOD__,strlen($this->tty_rx_buf))); - $this->tty_rx_ptr = 0; - $this->tty_rx_left = strlen($this->tty_rx_buf); - - } else { - return ( $this->tty_gothup ? self::TTY_HANGUP : self::TTY_TIMEOUT ); - } - } - - $rc = ord(substr($this->tty_rx_buf,$this->tty_rx_ptr,1)); //tty_rx_buf[tty_rx_ptr++]; - - $this->tty_rx_left--; - $this->tty_rx_ptr++; - - Log::debug(sprintf('%s: = Return [%x] (%c)',__METHOD__,$rc,$rc)); - return $rc; - } - - private function tty_getc_timed(int $timeout): int - { - $t = time(); - - $rc = $this->tty_getc($timeout); - $timeout -= (time() - $t); - return $rc; - } - - protected function tty_purge(): void - { - //DEBUG(('M',3,"tty_purge")); - - $this->tty_rx_ptr = $this->tty_rx_left = 0; - /* - if ( isatty( tty_fd )) { - tio_flush_queue( tty_fd, TIO_Q_IN ); - } - */ - } - - private function tty_purgeout(): void - { - //DEBUG(('M',3,"tty_purgeout")); - - $this->tty_bufclear(); - /* - if ( isatty( tty_fd )) { - tio_flush_queue( tty_fd, TIO_Q_OUT ); - } - */ - } - - private function tty_putc(string $ch):int - { - $this->tty_bufblock($ch,1); - return $this->tty_bufflush(5); - } - - protected function tty_select($rd,$wd,int $tval): int - { - //DEBUG(('T',2,"tty_select")); - $rfd = $this->client->connection; - $wfd = $this->client->connection; - //dump($rfd,$wfd); - - //FD_ZERO( &rfd ); - //FD_ZERO( &wfd ); - //if ($rd && $rd) { - //FD_SET($tty_fd,$rfd); - $rd = FALSE; - //} - - //if ($wd && $wd ) { - //FD_SET($tty_fd,$wfd); - $wd = FALSE; - //} - - $tty_error = 0; - $read = [$this->client->connection]; - $write = [$this->client->connection]; - $except = []; - dump('calling socket_select',['timeout'=>$tval,'read'=>$read,'write'=>$write]); - $rc = socket_select($read, $write, $except,($tval ?: NULL)); - dump('done socket_select',$tval); - - $tty_error = socket_last_error(); - $tty_status = self::TTY_SUCCESS; - - if ($rc < 0 ) { - if (EWBOEA()) { - $tty_status = self::TTY_TIMEOUT; - - } else if ($errno == self::EINTR) { - $tty_status = ($tty_online && $tty_gothup ) ? self::TTY_HANGUP : self::TTY_TIMEOUT; - } else if ($errno == self::EPIPE) { - $tty_gothup = self::HUP_LINE; - $tty_status = self::TTY_HANGUP; - } else { - $tty_status = self::TTY_ERROR; - } - - } else if ($rc == 0) { - $tty_status = self::TTY_TIMEOUT; - - /* - } else { - if ($rd /*&& FD_ISSET( tty_fd, &rfd )*) { - $rd = TRUE; - } - if ($wd /*&& FD_ISSET( tty_fd, &wfd )*) { - $wd = TRUE; - } - */ - } - - //DEBUG(('T',2,"tty_select: fd=%d rc=%i (rd=%s, wd=%s)", tty_fd, rc, FDS( rd ), FDS( wd ))); - - return $rc; - } - - protected function BUFCHAR(int $c) - { - $this->tty_bufc($c); - } - - protected function BUFFLUSH(int $tsec): int - { - return $this->tty_bufflush($tsec); - } - - // @todo this should go into SocketCLient? - protected function EWBOEA(): bool - { - $errno = socket_last_error($this->client->connection); - Log::debug('+ Start',['m'=> __METHOD__,'errno'=>$errno]); - return $errno === 11 /*MSG_EAGAIN*/; - } - - protected function GETCHAR(int $t): int - { - return $this->tty_getc($t); - } - - protected function GETCHART($t): int - { - return $this->tty_getc_timed($t); - } - - public function NOTTO(string $ch): int - { - return (($ch)==self::ERROR || ($ch)==self::RCDO || ($ch)==self::EOF); - } - - protected function PUTSTR(string $s):void - { - $this->tty_bufblock($s,strlen($s)); - $this->BUFFLUSH( 5); - } - - protected function PURGEALL(): void - { - $this->tty_purge(); - $this->tty_purgeout(); - } - - protected function PUTCHAR(string $c) - { - $this->tty_putc( $c ); - } - - protected function PUTSTRCR(string $str) - { - $this->tty_bufblock($str."\r",strlen($str)+1); - return $this->tty_bufflush(5); - } -} - -class rnode -{ - public $starttime = 0; - public $options = 0; - public $netmail = 0; - public $files = 0; - public $ewboea = 0; - public $phone = ''; -} diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index a6a31cf..d59e332 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -11,6 +11,8 @@ class HomeController extends Controller { public function network(Domain $o) { + $o->load(['zones.system','zones.domain']); + return view('domain.view') ->with('o',$o); } diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index ed8974b..a641690 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -121,7 +121,7 @@ class SystemController extends Controller $oo = new Address; $oo->zone_id = $request->post('zone_id'); - $oo->region_id = ($x=$request->post('region_id')) == 'no' ? 0 : $x; + $oo->region_id = $request->post('region_id'); $oo->host_id = $request->post('host_id_new'); $oo->node_id = $request->post('node_id_new'); $oo->point_id = 0; @@ -163,11 +163,11 @@ class SystemController extends Controller $oo = new Address; $oo->zone_id = $request->post('zone_id'); - $oo->region_id = ($x=$request->post('region_id')) == 'no' ? 0 : $x; + $oo->region_id = $request->post('region_id'); $oo->host_id = $request->post('host_id'); $oo->node_id = $request->post('node_id'); $oo->point_id = $request->post('point_id'); - $oo->hub_id = $request->post('hub_id'); + $oo->hub_id = $request->post('hub_id') > 0 ? $request->post('hub_id') : NULL; $oo->role = (! $oo->point_id) && $request->post('hub') ? DomainController::NODE_HC : NULL; $oo->active = TRUE; diff --git a/resources/views/domain/home.blade.php b/resources/views/domain/home.blade.php index e0292c8..9b3d641 100644 --- a/resources/views/domain/home.blade.php +++ b/resources/views/domain/home.blade.php @@ -41,7 +41,7 @@ Add New Domain @endcan - @foreach (\App\Models\Domain::orderBy('name')->cursor() as $oo) + @foreach (\App\Models\Domain::orderBy('name')->with(['zones'])->get() as $oo) {{ $oo->id }} {{ $oo->name }} diff --git a/resources/views/domain/view.blade.php b/resources/views/domain/view.blade.php index c65d9c7..f57602b 100644 --- a/resources/views/domain/view.blade.php +++ b/resources/views/domain/view.blade.php @@ -101,16 +101,18 @@ - @foreach ($oz->addresses()->active()->FTNorder()->where('hub_id',$ao->id)->with(['system','zone.domain'])->get() as $aoo) - - {{ $aoo->system->full_name($aoo) }} - {{ $aoo->system->sysop }} - {{ $ao->system->location }} - {{ $aoo->role }} - {{ $aoo->ftn }} - - - - @endforeach + @if ($ao->role == 'Hub') + @foreach ($oz->addresses()->active()->FTNorder()->where('hub_id',$ao->id)->with(['system','zone.domain'])->get() as $aoo) + + {{ $aoo->system->full_name($aoo) }} + {{ $aoo->system->sysop }} + {{ $ao->system->location }} + {{ $aoo->role }} + {{ $aoo->ftn }} + - + + @endforeach + @endif @endforeach @endforeach diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php index 64b24a7..569db8c 100644 --- a/resources/views/system/addedit.blade.php +++ b/resources/views/system/addedit.blade.php @@ -525,7 +525,7 @@ $.get('{{ url('api/regions') }}'+'/'+this.value,function(data) { $('#region_id').append(''); - $('#region_id').append(''); + $('#region_id').append(''); $('#region_id').append(''); data.forEach(function(item) { @@ -584,7 +584,7 @@ $('#action').val('region'); break; - case 'no': + case '0': default: // Find Hosts if ($('#host-select').hasClass('d-none')) @@ -610,10 +610,10 @@ $('#host_id').children().remove(); var that = this; - $.get('{{ url('api/hosts') }}'+'/'+$('#zone_id').val()+'/'+((this.value === 'no') ? 0 : this.value),function(data) { + $.get('{{ url('api/hosts') }}'+'/'+$('#zone_id').val()+'/'+this.value,function(data) { $('#host_id').append(''); - if (that.value !== 'no') - $('#host_id').append(''); + if (that.value !== '0') + $('#host_id').append(''); $('#host_id').append(''); data.forEach(function(item) { @@ -661,7 +661,7 @@ $('#action').val('host'); break; - case 'no': + case '0': default: if (! $('#host-address').hasClass('d-none')) $('#host-address').addClass('d-none'); @@ -679,8 +679,8 @@ $('#hub_id').prop('disabled',true); $('#hub_id').children().remove(); - $.get('{{ url('api/hubs') }}'+'/'+$('#zone_id').val()+'/'+((this.value === 'no') ? 0 : this.value),function(data) { - $('#hub_id').append(''); + $.get('{{ url('api/hubs') }}'+'/'+$('#zone_id').val()+'/'+this.value,function(data) { + $('#hub_id').append(''); data.forEach(function(item) { $('#hub_id').append(''); @@ -698,7 +698,7 @@ $('#hub_id').on('change',function() { switch(this.value) { - case 'no': + case '': if ($('#hub-checkbox').hasClass('d-none')) $('#hub-checkbox').removeClass('d-none'); break; diff --git a/resources/views/system/home.blade.php b/resources/views/system/home.blade.php index e68e561..4d18cd5 100644 --- a/resources/views/system/home.blade.php +++ b/resources/views/system/home.blade.php @@ -40,7 +40,7 @@ - @foreach (\App\Models\System::active()->orderBy('name')->cursor() as $oo) + @foreach (\App\Models\System::active()->orderBy('name')->with(['addresses.zone.domain'])->get() as $oo) {{ $oo->id }} {{ $oo->name }} diff --git a/resources/views/zone/home.blade.php b/resources/views/zone/home.blade.php index 9831e78..deba573 100644 --- a/resources/views/zone/home.blade.php +++ b/resources/views/zone/home.blade.php @@ -38,7 +38,7 @@ - @foreach (\App\Models\Zone::with(['domain'])->cursor() as $oo) + @foreach (\App\Models\Zone::with(['domain'])->get() as $oo) {{ $oo->domain->name }} {{ $oo->zone_id }}