Sign in to follow this  
Followers 0
gcriaco

XGUI

1 post in this topic

#1 ·  Posted (edited)

Logic/Purpose

Based on Cygwin X packages, provides a GUI for easely starting X Client sessions on Unix servers.

Hou to install/configure it

Download and install Cygwin X packages

Configure XGUI.ini as follows:

Section Settings

XWinPath = path of Xwin.exe

Cygwin1Path = path of cygwin1.dll

LocalIP=Client IP Address (optional: use it if your client have more than one IP Address)

Section Servers

Hostname of server1=IP Address1

...

Hostname of servern=IP Addressn

How to use it

Start the code

Select the hostname you want to connect to and press <Start> or double-click on it.

XGui.au3

#Region Compiler directives section
;** This is a list of compiler directives used by CompileAU3.exe.
;** comment the lines you don't need or else it will override the default settings
;#Compiler_Prompt=y                             ;y=show compile menu
;** AUT2EXE settings
;#Compiler_AUT2EXE=
#Compiler_Icon=XWin1.ico                        ;Filename of the Ico file to use
;#Compiler_OutFile=                             ;Target exe filename.
#Compiler_Compression=4                         ;Compression parameter 0-4  0=Low 2=normal 4=High
#Compiler_Allow_Decompile=y                     ;y= allow decompile
;#Compiler_PassPhrase=                          ;Password to use for compilation
;** Target program Resource info
#Compiler_Res_Comment=Unix Shell Management
#Compiler_Res_Description=Unix Shell Management
#Compiler_Res_Fileversion=1.1
#Compiler_Res_LegalCopyright=Giuseppe Criaco
; free form resource fields ... max 15
#Compiler_Res_Field=Email|gcriaco@sogei.it      ;Free format fieldname|fieldvalue
#Compiler_Res_Field=Release Date|23/1/2006      ;Free format fieldname|fieldvalue
;#Compiler_Res_Field=Name|Value                 ;Free format fieldname|fieldvalue
;#Compiler_Res_Field=Name|Value                 ;Free format fieldname|fieldvalue
#Compiler_Run_AU3Check=y                        ;Run au3check before compilation
; The following directives can contain:
;   %in% , %out%, %icon% which will be replaced by the fullpath\filename.
;   %scriptdir% same as @ScriptDir and %scriptfile% = filename without extension.
#Compiler_Run_Before=                           ;process to run before compilation - you can have multiple records that will be processed in sequence
#Compiler_Run_After=move "%out%" "%scriptdir%"  ;process to run After compilation - you can have multiple records that will be processed in sequence
#EndRegion
;===================================================================================================================================================
;
; Program Name:     XGUI()
; Description:      Unix Shell Management
; Parameter(s):     None
; Requirement(s):   XGUI.ini
; Return Value(s):  None
; Author(s):        Giuseppe Criaco <gcriaco@quipo.it>
;
;===================================================================================================================================================
;

#Region - Include and Declarations

AutoItSetOption("TrayIconDebug", 1) ;Debug: 0=no info, 1=debug line info

#include <XGuiConstants.au3>
;~ #include <GuiConstants.au3>

Global Const $WM_COMMAND    = 0x0111
Global Const $LBN_SELCHANGE    = 1
Global Const $LBN_DBLCLK    = 2

Dim $asCmd[50], $iCmd = 0, $IP, $sHostName, $sEncryptPwd, $sPwd, $sUser, $iSleep = 1000, $sPutty, $iSendKeyDelay = 50

#EndRegion - Include and Declarations

#Region - GUI objects creation

GuiCreate("XGUI v. 1.1", 235, 375,(@DesktopWidth-325)/2, (@DesktopHeight-285)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

GUICtrlCreateLabel("Server List:", 10, 10, 135, 30)
$lstServer = GuiCtrlCreateList("", 10, 30, 215, 310)
$btnOk = GuiCtrlCreateButton("&Start", 75, 340, 70, 25, $BS_DEFPUSHBUTTON )
$btnExit = GuiCtrlCreateButton("&Exit", 155, 340, 70, 25)

HotKeySet("{ESC}", "_Terminate")

#EndRegion - GUI objects creation

#Region Management

If (Not FileExists(@ScriptDir & "\XGUI.ini")) Then
    #Region --- CodeWizard generated code Start ---
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Warning
    MsgBox(48, "File Not Found", "Required file not found (" & @ScriptDir & "\XGUI.ini" & ")" & @CRLF & "" & @CRLF & "XGUI will now exit!!!")
    #EndRegion --- CodeWizard generated code End ---
    Exit
EndIf

;Settings
$sSection = IniReadSection(@ScriptDir & "\XGUI.ini", "Settings")
If @error Then 
    #Region --- CodeWizard generated code Start ---
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
    MsgBox(16,"XGUI","Unable to read the section Settings")
    #EndRegion --- CodeWizard generated code End ---
    Exit
Else
    For $iSection = 1 To $sSection[0][0]
        If $sSection[$iSection][0] = "XWinPath" Then $XWinPath = $sSection[$iSection][1]
        If $sSection[$iSection][0] = "Cygwin1Path" Then $Cygwin1Path = $sSection[$iSection][1]
        If $sSection[$iSection][0] = "LocalIP" Then $IP = $sSection[$iSection][1]
    Next
    
    If  $IP = "" Then $IP = @IPAddress1
EndIf

;Servers
$sSection = IniReadSection(@ScriptDir & "\XGUI.ini", "Servers")
If @error Then 
    #Region --- CodeWizard generated code Start ---
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
    MsgBox(16,"XGUI","Unable to read the section Server")
    #EndRegion --- CodeWizard generated code End ---
    Exit
Else
    ;Load ListBox
    For $iSection = 1 To $sSection[0][0]
        GUICtrlSetData($lstServer,$sSection[$iSection][0])
    Next
EndIf

;Register a user defined function for the Windows Message ID WM_COMMAND.
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $btnExit
            _Terminate()

        Case $msg = $btnOk
            _Start()
    EndSelect
WEnd

;==============================================================================================================

Func _Start()
    $sKey = GUICtrlRead($lstServer)
    $sValue = IniRead(@ScriptDir & "\XGUI.ini", "Servers", $sKey, "NotFound")
    If @error Then 
        #Region --- CodeWizard generated code Start ---
        ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
        MsgBox(16,"UnixCmd","Unable to read the Key " & $sKey)
        #EndRegion --- CodeWizard generated code End ---
        Exit
    Else
        ;msgbox(0,$XWinPath,$Cygwin1Path)
        EnvSet("PATH", "%PATH%;" & $XWinPath &";" & $Cygwin1Path)
        Run("xwin.exe -clipboard -keyhook -logfile " & @ScriptDir & "\XGUI.log" & " -from " & $IP & " -query " & $sValue, "", @SW_HIDE)
        ;Run("xwin.exe -clipboard -keyhook -query " & $sValue, "", @SW_HIDE)
    EndIf
EndFunc

;----------------------------------------------------------------------------------------------------------------

Func _Terminate()
    Exit 0
EndFunc

;----------------------------------------------------------------------------------------------------------------

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode    = BitShift($wParam, 16)
    $nID            = BitAnd($wParam, 0x0000FFFF)
    $hCtrl          = $lParam
    
    If $nID = $lstServer Then
        Switch $nNotifyCode                    
            Case $LBN_DBLCLK
                _Start()
                Return 0
        EndSwitch
    EndIf
EndFunc
oÝ÷ ٵƺ ¨ËZÛ»Ûjëh×6
Global Const $GUI_EVENT_CLOSE           = -3
Global Const $WS_OVERLAPPED         = 0
Global Const $WS_OVERLAPPEDWINDOW   = 0x00CF0000
Global Const $WS_CLIPSIBLINGS       = 0x04000000
Global Const $WS_VISIBLE            = 0x10000000
Global Const $BS_DEFPUSHBUTTON  = 0x0001

XGui.ini Example

[settings]

XWinPath=C:\cygwin\usr\X11R6\bin

Cygwin1Path=C:\cygwin\bin

LocalIP=

[servers]

Hostname1=IP Address1

Hostname2=IP Address2

...

Hostnamen=IP Addressn

Edited by gcriaco

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0