Home | History | Annotate | Download | only in misc
      1 #!/usr/dt/bin/dtksh
      2 #
      3 # accept dialog script for x11vnc
      4 # 2004-07-13 stefan.radman (at] ctbto.org
      5 # should work in any CDE environment (Sun,HP,IBM,...)
      6 # 
      7 # when called without parameters shows a CDE question dialog:
      8 #   Do you want to accept a VNC connection
      9 #   from IP address $RFB_CLIENT_IP to your desktop?
     10 #   Note:
     11 #   After 30 seconds the screen will
     12 #   be locked and the connection will be
     13 #   accepted automatically."
     14 #       [Yes} {__No__] [View/Only]
     15 # and counts down a timer in the dialog title bar
     16 # when the timer is down to 0, it locks the display and returns 0
     17 # (if the screenlock was successful or if the login prompt was active)
     18 #
     19 # buttons=retcode:
     20 #    Yes = 0
     21 #    No = 1 (same as closing the dialog windows)
     22 #    View/Only = 3
     23 #
     24 # usage: x11vnc -forever -shared -accept "yes:0,no:*,view:3 dtVncPopup" -gone "dtVncPopup lock"
     25 #
     26 # security considerations: when you return to your console and unlock the display 
     27 #                  you can never know if enyone else is connected to your display
     28 #
     29 
     30 # timeout until accept
     31 timeout=30
     32 
     33 # dialog message
     34 test -z "${RFB_CLIENT_IP}" && unknown="an unknown " || ip="$RFB_CLIENT_IP "
     35 message="\
     36 Do you want to accept a VNC connection
     37 from ${unknown}IP address ${ip}to your desktop?
     38 Note:
     39 After $timeout seconds the screen will
     40 be locked and the connection will be
     41 accepted automatically."
     42 
     43 # action functions
     44 accept () {
     45 	exit 0
     46 }
     47 reject () {
     48 	exit 1
     49 }
     50 view () {
     51 	exit 3
     52 }
     53 lock () {
     54         # lock only if dtsession active
     55         xrdb -query | grep -c '^dtsession*' || accept
     56 	# accept only if lock succeeds
     57 	/usr/dt/bin/dtaction LockDisplay && accept || reject
     58 }
     59 
     60 # main
     61 
     62 # actions can be called directly
     63 test $# -gt 0 && $@
     64 
     65 # initialize the display
     66 XtInitialize TOPLEVEL vncPopup VncPopup "$0" "$@"
     67 
     68 # create a message dialog containing the contents of the specified file
     69 XmCreateQuestionDialog DIALOG $TOPLEVEL dialog \
     70 	dialogTitle:"$DTKSH_APPNAME" \
     71         messageString:"$message" \
     72 	unmapCallback:reject \
     73 #        symbolPixmap:/usr/dt/appconfig/icons/C/DtFlag.m.pm
     74 
     75 # change the OK button to "Yes"
     76 XmMessageBoxGetChild OK_BUTTON $DIALOG DIALOG_OK_BUTTON
     77 XtSetValues $OK_BUTTON \
     78 	labelString:"Yes" \
     79 	activateCallback:accept
     80 
     81 # change the Cancel Button to "No"
     82 XmMessageBoxGetChild CANCEL_BUTTON $DIALOG DIALOG_CANCEL_BUTTON
     83 XtSetValues $CANCEL_BUTTON \
     84 	labelString:"No" \
     85 	activateCallback:reject
     86 
     87 # change Help button to View-Only, set focus and make it the default
     88 XmMessageBoxGetChild HELP_BUTTON $DIALOG DIALOG_HELP_BUTTON
     89 XtSetValues $HELP_BUTTON \
     90 	labelString:"View\nOnly" \
     91 	activateCallback:view
     92 
     93 # make "No" the default (for unmap as well)
     94 XtSetValues $DIALOG \
     95 	defaultButton:$CANCEL_BUTTON initialFocus:$CANCEL_BUTTON \
     96 
     97 # create the ticker
     98 ticker () {
     99         test $timeout -eq 0 && lock
    100 	XtSetValues $DIALOG dialogTitle:"accepting in $timeout seconds"
    101 	XtAddTimeOut TICKER 1000 ticker
    102         timeout=`expr $timeout - 1`
    103 }
    104 
    105 # display dialog and activate ticker
    106 XtAddTimeOut TICKER 1000 ticker
    107 XtManageChild $DIALOG
    108 XtMainLoop
    109 
    110