<?
// common.inc
//
// Copyright, Exolution GmbH / Michael Kerrisk, Sep 2000
// http://www.exolution.com/wapsh   mailto:wapsh@exolution.de
//
// This software is Open Source licensed under the terms of the Trolltech QPL
// version 1.0.  See http://www.exolution.de/wapsh for further information.
//
// ---------------------------------------------------------------------
//
// Shared definitions needed by all pages
//
//
    
    define("SYSTEM_NAME", "htsh");	// The name of this system (used
    					// in certain message 
    
    define("SERVICE_NAME", "htsh");	// Name in /etc/services defining
    					// port at which htshd can be found

    /*****************************/
    /***** Session variables *****/
    /*****************************/

    session_register("clientType");	// "wap" or "http"
    session_register("hostAddress");	// Address of login host

    session_register("authenticated");	// True if successfully logged in
    session_register("socketPort");	// Socket port number for child command
    					// server for this session
    session_register("authKey");	// Authorisation key for messages
    					// from HTTP Server to CCS
    session_register("shellTimeout");	// Time out for commands at CCS
    session_register("setOptions");	// Options set by "set [-+]o" in .htshrc
    session_register("numSc");		// Number of Shortcut commands
    					// defined in .htshrc
    session_register("scName");		// Array of names of shortcut commands
    					// defined in .htshrc
    session_register("cmdNum");		// Current command numer
    					// (Used for hsitory)
    // Command history
    
    session_register("histCmd");	// Array of previous commands (inputs)
    session_register("histSilent");	// Array indicating whether previous 
    					// inputs had "silent" flag set
    session_register("histAddNl");	// Array indicating if previous inputs
    					// had "add newline" flag set
    session_register("historyBlockSize");  // Number of items to display
    					// at one time from history list
    
    session_register("shortcutBlockSize");  // Number of items to display
    					// at one time from shortcut list
    session_register("outputBufferLimit");  // Maximum size for output buffer
    session_register("outputWindowSize");  // Maximum output window size
    session_register("csMaxTransferSize"); // Maximum bytes transferred at one
    					// time from CCS to HTTP server
    session_register("shellTimeout"); 	// Timeout for input to client shell
    session_register("csOutputTimeout"); // Timeout for output from 
    					// client shell
    session_register("allowedProtocols"); // Protocols allowed to login
    session_register("wapBrowserStyle"); // WAP browser Style (can override
    					// autodetected style)
    session_register("outputBuf");	// Buffer of all output so far 
    					// produced for this session
    session_register("outputBufLen");	// Size of outputBuf
    session_register("outputPos");	// Current location in output buffer
    session_register("lastOutputBlockSize");
    					// Number of characters in last 
					// output to browser
    session_register("lastSearchPos");	// Location we found on last 
    					// sucessful search
    session_register("lastSrchStr");	// Last used search string

    /**********************************************/
    /***** NAMEs from RCFILE 'set NAME VALUE' *****/
    /**********************************************/

    // These strings must match the names in the htshd.c source code
    
    define(SN_ALLOWEDPROTOCOLS, "allowedprotocols");
    define(SN_OUTPUTBUFFERLIMIT, "outputbufferlimit");
    define(SN_OUTPUTWINDOWSIZE, "outputwindowsize");
    define(SN_HISTORYBLOCKSIZE, "historyblocksize");
    define(SN_SHORTCUTBLOCKSIZE, "shortcutblocksize");
    define(SN_SHELLTIMEOUT, "shelltimeout");
    define(SN_CSOUTPUTTIMEOUT, "csoutputtimeout");
    define(SN_CSMAXTRANSFERSIZE, "csmaxtransfersize");
    define(SN_WAPBROWSERSTYLE, "wapbrowserstyle");
    define(SNA_WBS_UPBROWSER, "up");


    define(DEF_OUTPUT_BUFFER_LIMIT, 100000);
    
    /********************************************/
    /***** Options from RCFILE 'set +/- o'. *****/
    /********************************************/

    // These values must match the values in the htshd.c source code
    
    define("OPT_ALLOWSHELLCMD",	01);
    define("OPT_DISPLAYMENU", 	02);
    define("OPT_ALLOWSILENT", 	04);
    define("OPT_ALLOWCONTROLCHARS", 010);
    define("OPT_HISTORY", 	020);
    define("OPT_FILTERANSIESC", 040);
    define("OPT_ALLOWTRIGRAPHS", 0100);
    define("OPT_ALLOWUSERINIT", 010000);
    define("OPT_SESSIONLOGGING", 0100000);

    /**********************************************************/
    /***** Request/response mesages for CCS communication *****/
    /**********************************************************/

    // These values must match the values in the htshd.c source code
    //
    // Command types to be sent to CCS.  
    //
    define("CMD_SIGNAL", 	'x');
    define("CMD_CONTROL", 	'^');
    define("CMD_CLOSE", 	'z');
    define("CMD_NULL", 		'n');
    define("CMD_SHELLCMD", 	'c');
    define("CMD_SHORTCUT", 	's');

    // Response types from CCS
    
    define("RESP_NORMAL", 'n');
    define("RESP_ERROR", 'e');
    define("RESP_FATAL", 'f');

    
    /***********************************/
    /***** Miscellaneous constants *****/
    /***********************************/

    define("INVALID_POS", -999);// Assigned to lasteSearchPos, this 
				// indicates that the last form operation 
    				// was not a search, so that the next search 
				// should start from the current version of 
				// outputPos (rather than from the last found 
    				// string)

    define("SEARCH_PRIOR_DISP_WINDOW", 80);	
    					// Maximum number of characters to
    					// display prior to a matched string 
    					// after a search



    function loginPage() {
	global $clientType;

	return ($clientType == "wap") ? "login_wml.php" : "login_html.php";
    } // loginPage

    function logMsg($msg) {
	$fp = fopen("/tmp/htsh.log", "a");
	if (fp !== false) {
	    fputs($fp, date("ymd-H:i:s") . " " . $msg . "\n");
	    fclose($fp);
	} // if
    } // logMsg
?>
