// IfsTelnetShow.bcpl -- Show Directory-Parameters command
// Copyright Xerox Corporation 1979, 1980, 1981

// Last modified April 23, 1982  1:59 PM by Taft

get "IfsRs.decl"
get "IfsTelnet.decl"
get "IfsFiles.decl"
get "CmdScan.decl"

external
[
// outgoing procedures
ExecShow

// incoming procedures
ExecShowGroup; ExecShowPress; ExecShowSysParams
SelectKeyword; GetString; DefaultPhrase
GetDIF; ListProtection; ListOneProt
Wss; Ws; Puts; Errors; PutTemplate; SysFree; WritePackedDT

// incoming statics
dsp; CtxRunning; enableGrapevineAuth; enableGrapevineGroup
]

//---------------------------------------------------------------------------
let ExecShow(cs) be
//---------------------------------------------------------------------------
[
switchon SelectKeyword(cs, "Directory-parameters", "Group-membership",
 "Printing-requests", "System-parameters") into
   [
   case 1: ExecShowDirectory(cs); endcase
   case 2: ExecShowGroup(cs); endcase
   case 3: ExecShowPress(cs, true); endcase
   case 4: ExecShowSysParams(cs); endcase
   ]
]

//---------------------------------------------------------------------------
and ExecShowDirectory(cs) be
//---------------------------------------------------------------------------
[
Wss(cs, " (of directory) ")
DefaultPhrase(cs, CtxRunning>>RSCtx.userInfo>>UserInfo.connName)
let name = GetString(cs, 0, Wss, "directory name")

let dif = GetDIF(name, true)  // get real DIF from file system if one exists
if dif eq 0 then dif = GetDIF(name)  // if none, try for just the cached one
SysFree(name)
if dif eq 0 then Errors(cs, 0)

test dif>>DIF.nonexistentDIF
   ifso Ws("*nNo local directory; cached Grapevine info only")
   ifnot
      [
      if dif>>DIF.filesOnly then
         PutTemplate(dsp, "*nFiles-only, owner is $S", lv dif>>DIF.owner)
      if dif>>DIF.capabilities.wheel then Ws("*nWheel")
      if dif>>DIF.capabilities.mail then Ws("*nMail")
      PutTemplate(dsp, "*nUsed $ED out of $ED disk pages",
       lv dif>>DIF.diskPageUsage, lv dif>>DIF.diskPageLimit)
      Ws("*nDefault file protection: ")
      ListProtection(lv dif>>DIF.fileProt)
      Ws("*nCreate permission: ")
      ListOneProt(lv dif>>DIF.createProt)
      Ws("*nConnect permission: ")
      ListOneProt(lv dif>>DIF.connectProt)
      ]

unless dif>>DIF.filesOnly do
   [
   Ws("*nGroup membership: ")
   ListOneProt(lv dif>>DIF.userGroups)
   if enableGrapevineGroup then
      [
      Ws("*nGroup non-membership hint: ")
      ListOneProt(lv dif>>DIF.hintNotUserGroups)
      ]
   unless dif>>DIF.nonexistentDIF do
      [
      Ws("*nGroup ownership: ")
      ListOneProt(lv dif>>DIF.ownedGroups)
      if dif>>DIF.defaultPrinter.length ne 0 then
         [ Ws("*nDefault printing server: "); Ws(lv dif>>DIF.defaultPrinter) ]
      ]
   ]

if enableGrapevineAuth then
   test dif>>DIF.timeLastValid.h eq 0
      ifnot PutTemplate(dsp, "*nLast successful authentication at $P",
          WritePackedDT, lv dif>>DIF.timeLastValid)
      ifso Ws("*nNever authenticated")

SysFree(dif)
]