php-doorlib

Author: William Eggers <william at eggers.id.au>

About php-doorlib

PHP-Doorlib is a PHP 5.x extension written by William Eggers that provides access to the MBSE Door Library for Unix BBS Systems.

This extension can be used to develop BBS doors for MBSE and compatible Unix BBS platforms and will simplify their implementation when using PHP.

If you find a bug, please let me know. You can email me at william at eggers.id.au.

Installation instructions

Please note: Doorlib 0.9.5 is bundled with php-doorlib, so downloading and compiling the doorlib package is not necessary.

    (please make sure libtool and php-devel packages are installed)
    
    # tar -xzvf php-doorlib-0.1.tar.gz
    # cd php-doorlib
    # phpize
    # ./configure
    (wait)
    # make clean
    # make
    # cp modules/doorlib.so /usr/lib/php/modules
  
Remember to add the following entries into php.ini
    extension=doorlib.so
    ; Default timeout for door_getch() calls
    doorlib.default_alarm_timeout=600
  

API

string door_getch(void)

Get a character from the remote user. ANSI escaped keycodes are processed and translated to codes like KEY_DOWN etc. The following table contains the defined key constants in PHP:

DOORLIB_KEY_BACKSPACE DOORLIB_KEY_LINEFEED DOORLIB_KEY_ENTER
DOORLIB_KEY_ESCAPE DOORLIB_KEY_RUBOUT DOORLIB_KEY_UP
DOORLIB_KEY_DOWN DOORLIB_KEY_LEFT DOORLIB_KEY_RIGHT
DOORLIB_KEY_HOME DOORLIB_KEY_END DOORLIB_KEY_INS
DOORLIB_KEY_DEL DOORLIB_KEY_PGUP DOORLIB_KEY_PGDN

Sample code

     /** Attempt to load the doorsys file **/
     if ( ($result = door_load_doorsys()) === false) {
        die("Failed loading door sys");
     }
     
     while (1) {
        $input = door_getch();
     
        switch(ord($input)) {
     	   case DOORLIB_KEY_ENTER:
     	   case DOORLIB_KEY_ESCAPE:
     	      // Do something
     	      break 2;
	   default:
	      // Something else, etc.
	      break;     
        }
     }
  

All other keys return the normal values. While waiting for a key, there are two timers running, a inactivity timer with a 10 minutes timeout, and a timer that forces logoff when the users maximum login time is reached. These timers are also running during the next string input functions.

string door_getstr(int $maxLength)

Get a string from the user. The first parameter is the maximum string length to fetch.

string door_getname(int $maxLength)

Get a username from the user. The first parameter is the maximum string length. Each first letter of a name part is forced to uppercase, the rest to lowercase. When the user types JhOn SmITH this function will return John Smith.

string door_getnum(int $maxLength)

Get a number from the user. The first parameter is the maximum input length. As you can see the number is returned in a string, use the intval() function to convert the string to a integer.

void door_waitenter([ string $message ])

Displays a message to the user and waits for the user to press the enter key. The string to pass should be something like "Press ENTER to continue: " If the string is omitted, then the English string "Press (Enter) to continue: " is used. The string is displayed in White on Black and after the user has pressed the enter key, the string is erased from the screen.

void door_cout(int $fg, int $bg, string $message)

Colored output, the first two parameters are the foreground and background colors, the third is the string to send. The color is send to the user using standard ANSI sequences. Foreground colors are in the range 0..15, background colors in the range 0..7. The following colors are defined by php-doorlib:

ConstantValue
DOORLIB_BLACK0
DOORLIB_BLUE1
DOORLIB_GREEN2
DOORLIB_CYAN3
DOORLIB_RED4
DOORLIB_MAGENTA5
DOORLIB_BROWN6
DOORLIB_LIGHTGRAY7
DOORLIB_DARKGRAY8
DOORLIB_LIGHTBLUE9
DOORLIB_LIGHTGREEN10
DOORLIB_LIGHTCYAN11
DOORLIB_LIGHTRED12
DOORLIB_LIGHTMAGENTA13
DOORLIB_YELLOW14
DOORLIB_WHITE15

void door_color(int $fg, int $bg)

Set new colors. This is a smart function, only changed colors are send to the users terminal. See color constant table above for values.

void door_center(string $message)

Write a centered string to the users terminal.

void door_clear(void)

Clear screen, or on a dumb tty, do a linefeed.

void door_locate(int $y, int $x)

Move cursor to position Y, X. Works only if the remote terminal is ANSI capable.

void door_line(int $linefeeds)

Draw a line. Advance a given number of linefeeds.

void door_alarm_set(int $seconds)

Set the inactivity timer to the given number of seconds.

void door_alarm_on(void)

Set the inactivity timer to the default 600 seconds. The default value can be overriden by the PHP ini setting doorlib.default_alarm_timeout.

void door_alarm_off(void)

Turn off the inactivity timer.

mixed door_load_doorsys(void)

This function should be called before any other door_* function.

Load door.sys file from current directory. This is the standard 52 lines door.sys dropfile format. The filename may be DOOR.SYS or door.sys, but not mixed case. If the file is not found, this function will return FALSE. If the load is successful, this function will return the contents of the dropfile as an associative array:

	Array
	(
	    [comport] => COM0:	 		/* DOS style COM port           */
	    [ebaud] => 0			/* Effective baudrate           */
	    [databits] => 8			/* Databits                     */
	    [nodenumber] => 1			/* Multiline nodenumber         */
	    [lbaud] => 0			/* Locked baudrate              */
	    [screen_display] => Y		/* Screen display Y/N           */
	    [printer_on] => N			/* Printer on Y/N               */
	    [page_bell] => Y			/* Paging bell Y/N              */
	    [caller_alarm] => Y			/* Caller alarm Y/N             */
	    [username] => Test User		/* User name                    */
	    [location] => Test Location		/* User's location              */
	    [voice_phone] =>			/* User's voice phone           */
	    [data_phone] => 61395555555		/* User's data phone            */
	    [password] => 			/* User's password              */
	    [seclevel] => 20			/* User's security level        */
	    [totalcalls] => 21			/* User's total calls           */
	    [last_login] => 03-27-09		/* last login date MM-DD-YYYY   */
	    [sec_timeleft] => 3540		/* Seconds time left            */
	    [min_timeleft] => 59		/* Minutes time left            */
	    [graphics] => GR			/* Graphics GR or NG            */
	    [screenlen] => 24			/* User's screen length         */
	    [usermode] => N			/* Always Y ??                  */
	    [extra1] =>				
	    [extra2] =>
	    [expiry_date] => 00-00-00		/* User's expiry date           */
	    [grecno] => 0			/* User's record number         */
	    [protocol] => Zmodem		/* Transfer protocol            */
	    [uploads] => 0			/* Total uploads                */
	    [downloads] => 3			/* Total downloads              */
	    [lim_downk] => 40960		/* Download limit in Kb.        */
	    [lim_downk2] => 40960		/* Download limit in Kb.        */
	    [date_of_birth] =>			/* Date of birth                */
	    [userbase] =>			/* Path to userbase             */
	    [msgbase] =>			/* Path to msgbase              */
	    [sysopname] => William Eggers	/* Sysop name                   */
	    [handle] => test			/* User's alias                 */
	    [nextevent] => none			/* Next event time or none      */
	    [errorfree] => Y			/* Error free connection        */
	    [allwaysN] => N
	    [allwaysY] => Y
	    [defcolor] => 7			/* Default textcolor            */
	    [allways0] => 0			
	    [last_login2] => 03-27-09		/* Last login date              */
	    [time_login] => 21:35		/* Login time                   */
	    [last_login_time] => 12:01:12	/* Last login time              */
	    [maxinteger] => 32768		/* DOS maxint value             */
	    [downs_today] => 25			/* Downloads today              */
	    [uploadK] => 0			/* Uploads in Kb                */
	    [downloadK] => 10792		/* Downloads in Kb              */
	    [comment] =>			/* User's comment               */
	    [allways0_2] => 0			
	    [posted] => 20			/* Messages posted              */
	)
  

int door_dispfile(string $filename)

Display a textfile to the user. The paramater is the full path and filename of the file to display, but without the extension. The prefered file to display has a .ans extension, if this is not present or the user doesn't support ANSI a file with .asc extension will be displayed. Control codes are processed and translated. The following codes are processed:

	^A	Wait for a character from the user.
	^F	Intro to control-F codes.
	^F!	Print protocol name.
	^FA	Print number of uploads.
	^FB	Print number of downloads.
	^FC	Print downloads in Kilobytes.
	^FD	Print uploads in Kilobytes.
	^FE	Print uploads + downloads in Kilobytes.
	^FF	Print download limit in Kilobytes.
	^FG	Print number of downloads of today.
	^K	Intro to control-K codes.
	^KA	Print current date.
	^KB	Print current time.
	^KC	Print COM port.
	^KD	Print locked baudrate.
	^KE	Print effective baudrate.
	^KF	Print node (line) number.
	^KG	Print errorfree connection.
	^L	Clear screen
	^P	Wait one second.
	^U	Intro to control-U codes.
	^UA	Print users full name.
	^UB	Print users location.
	^UC	Print users voice phone.
	^UD	Print users data phone.
	^UE	Print users last login date.
	^UF	Print users comment line.
	^UG	Print users last login time.
	^UH	Print users security level.
	^UI	Print users total calls.
	^UJ	Print users expiry date.
	^UK	Print users time left in seconds.
	^UL	Print users time left in minutes.
	^UM	Print users screenlength.
	^UN	Print users first name.
	^UO	Print users last name.
	^UP	Print Yes for ANSI, No for dumb terminal.
	^UQ	Print default color number.
	^UT	Print users date of birth.
	^UU	Print users number of posted messages.
	^UY	Print users handle.
  

Sample code

     /** Attempt to load the doorsys file **/
     if ( ($result = door_load_doorsys()) === false) {
        die("Failed loading door sys");
     }

     door_clear();

     // Load the php-doorlib.ans file from the current directory
     door_dispfile(dirname(__FILE__) . "/php-doorlib");
  

ANSI sequence constants

The following ANSI sequences have been defined within php-doorlib and can be used within your php-doorlib application:

ConstantValue
DOORLIB_ANSI_RED\x1B[31;1m
DOORLIB_ANSI_YELLOW\x1B[33;1m
DOORLIB_ANSI_BLUE\x1B[34;1m
DOORLIB_ANSI_GREEN\x1B[32;1m
DOORLIB_ANSI_WHITE\x1B[37;1m
DOORLIB_ANSI_CYAN\x1B[36;1m
DOORLIB_ANSI_MAGENTA\x1B[35m
DOORLIB_ANSI_HOME\x1B[H
DOORLIB_ANSI_UP\x1B[A
DOORLIB_ANSI_DOWN\x1B[B
DOORLIB_ANSI_RIGHT\x1B[C
DOORLIB_ANSI_LEFT\x1B[D
DOORLIB_ANSI_BOLD\x1B[1m
DOORLIB_ANSI_NORMAL\x1B[0m
DOORLIB_ANSI_CLEAR\x1B[2J
DOORLIB_ANSI_CLREOL\x1B[K