Saturday, February 18, 2017

How to forward X11 from a CentOS/RedHat Linux server to a Windows PC

In some cases it might be useful to run GUI based apps on backend servers (usually VPSs or dedicated servers) that lack the means to display them, i.e. have no graphics capability or monitor attached to them.

On Linux servers this is usually done via VNC but that requires firewall mods to open the VNC port(s) on the server side which may not always be possible or desirable.

That leaves us with two options:
  • TeamViewer which is fine for the occasional non-commercial use but requires licensing otherwise
  • Good old X forwarding from the server to a listening port on a computer with graphics display capability. In this scenario the backend server (or the GUI app running on it) becomes the X client and the app, running on the graphics capable PC, that displays their GUIs becomes the X server.

I will shortly cover here how the second scenario can be set up using a CentOS/RedHat server and Xming + Putty on a Windows PC. There are basically two ways to do it:

  1. Simply forward X on your remote server to your local X Server. This requires that you open/forward a port on your local PC to receive the X data in your X server.To set this up:
    • Install PuTTY on your PC
    • Install Xming on your PC
    • Open port 6000 on your PC and open/forward it from your router to your PC.
    • Add your remote server's IP into a file named "X0.hosts" under the Xming installation directory (typically "C:\Program Files (x86)\Xming") and start or restart Xming
    • Connect to your remote server via ssh using PuTTY and install the full X Window System on your backend server: yum groupinstall "X Window System"
    • Then issue this command to redirect the X display to your PC: export DISPLAY=x.x.x.x:0.0 where x.x.x.x is your PC's IP address.
    • From this point any command issued on your remote server that invokes a program with a GUI should bring up the app's windows on your PC via Xming, e.g. xclock & or firefox &
  2. Forward X to your PC via ssh (in this case PuTTY). This has two benefits and one possible down side compared to the option right above. The benefits are a)Secured X data (i.e. it cannot be intercepted while travelling between the server and your PC), b)You do not need to open/forward any port on your PC or allow your server's IP address in Xming's hosts list. The down side is that X forwarding may be slower this way, unless ssh compression is used which I am not sure how much it would change things. To do this follow these steps:
    • Install PuTTY on your PC
    • Install Xming on your PC and have it running
    • In PuTTY, under the SSH settings, find the X11 tab and
      • enable X11 forwarding
      • set the X display location to localhost:0
    • On your server edit your ssh daemon's config file, typically at "/etc/ssh/sshd_config" and set the following options:
      • X11Forwarding yes
      • X11DisplayOffset 10
    • Connect to your remote server via ssh using your PuTTY with the X11 options set as shown above.
    • From this point on any command issued on your remote server that invokes a program with a GUI should bring up the app's windows on your PC via Xming, e.g. xclock & or firefox &





Monday, January 30, 2017

Open/save password protected PowerPoint Presentations using VSTO

Although VSTO offers easy ways to save or open password protected Word documents or Excel Workbooks e.g. in pseudocode, Open(docpath, ..., password) or Save(docpath,..., password), it does not offer such options for PowerPoint presentations. However, there is still a way to do it programmatically fairly easily:

To save a presentation with a password:

PowerPoint.Presentation p = Globals.ThisAddIn.Application.Presentations.Add();
p.Password = "whatever";
p.Save();

To open a password protected presentation simply pass the password at the end of the presentation path, when opening it, in this "hackish" way:

PowerPoint.Presentation d = Globals.ThisAddIn.Application.Presentations.Open(FullFilePath + "::whatever::");