10/24/2008

Moving from Win XP to Ubuntu - 2

8. Shortcuts on Ubuntu

Desktop Environment
Ctrl + Alt + F1(F2)(F3)(F4)(F5)(F6) = Select the different virtual terminals, if you are in one of these term, no Ctrl is needed to do the switch.
Ctrl + Alt + F7 = Switch to current terminal session with X.
Ctrl + Alt + F8(f9)(...) = If there are more than one X terninal session, these key combines can switch to them.

Ctrl + Alt + +/- = Switch to next/previous X resolution (Depends of your X configuration)
Ctrl + Alt + <-/-> = Switch to next/previous workspace(virtual desktop)
Ctrl + Alt + Shift + <-/-> = Bring current applicatioin to next/previous workspace(virtual desktop)

Ctrl + Alt + Backspace = Kill & Restart X server
Alt+Tab = Switch between open programs
Alt + F1 = Bring up the start menu
Alt + F2 = Bring up the "run command" dialogue
Ctrl + Alt + D = Display desktop/Resotre application
Ctrl + Alt + L = Lock the computer
Ctrl + Alt + Del = Log out
Ctrl + L = Open location
Ctrl + F = File browser/Search

Window Management
Alt + F4 = Close current window
Alt + F5 = Restore current window
Alt + F7 = Move current window
Alt + F8 = Resize current window
Alt + F9 = Maxmize current window
Alt + F10 = Minmize current window
Alt + Space = Open control menu of current window

Screen Shot
Prtsrn = Print screen
Alt_+ PtrSrn = Print current window
Shell command : "gnome-screenshot --delay 3" = Print screen after 3 seconds

Command line/Terminal shortcuts
Ctrl+C = Kill process (Kill the current process in terminal, also used to copy elsewhere)
Ctrl+Z = Send process to background
Ctrl+D = Log out from the current terminal. In X, this may log you out after a shuting down the emulator.

Ctrl+A/Home = Move cursor to beginning of line
Ctrl+E/End = Move cursor to end of line
Tab = List available commands from typed letters (Ex: type iw and click tab, output = iwconfig iwevent iwgetid iwlist iwpriv iwspy)

Ctrl+U = Delete current line
Ctrl+K = Delete current line from cursor
Ctrl+W = Delete word before cursor in terminal (Terminal only, also used to close the current document elsewhere)

Arrows up and down = Browse command history
Ctrl+R = History search (Finds the last command matching the letters you type)

Shift+PageUp / PageDown = Scroll terminal output
Ctrl+L = Clears terminal output
Shift+insert = Paste

Mouse
Middle Click Window Title = The window will lose focus
Shift + Drag Window = Window border will be sticky to desktop border
Drag file into ternimal = Show full path of that file/dir
Middle Click Scroll Bar = Move scroll bar to that place
Middle Drag a Picture to Desktop = Make that picture to be the wallpaper
Middle Click in Web Browser = Cop selected text


Customize keyboard shortcut
1. install xbindkeys/xbindkeys-config. It works for each desktop (KDE, GNOME, XFCE, ...)

2. using metacity (the default GNOME window manager). Run gconf-editor, go to: Apps -> MetaCity -> KeyBinding_commands ...

3. using System>Preferences>Keyboard Shortcuts ...

10/23/2008

Moving from Win XP to Ubuntu - 1

  Due to recent policies from Win XP provider, I decided to move my home computer's OS from Win XP to Ubuntu.

  When you decided to replace the OS, you must replaces those daily used applications. Here I collected some of those substitutes:

  1. Web Browser
  FireFox is build into Ubuntu natively, but the firefox version and Ubuntu version mapping is fixed. So fx's version maybe not be as latest as the one from Mazillia's website. If you want to use your own version of FireFox, you can Automatic Install, or you can Manual Install 1 and Manual Install 2 it into Ubuntu.
  Opera is also available on Ubuntu.

  2. Office suite
  OOo(OpenOffice org) is definitely the good candidate. Here is a simple components mapping:
  Microsoft Office V.S. OpenOffice.org
  Word V.S. Write
  Excel V.S. Calc
  Access V.S. Base
  Powerpoint V.S. Impress

  3. Multimedia
  DVD player - MPlayer, the coolest thing is that all control can be accomplished by key strokes. In order to get chinese subtitles show up, you should do some manual settings to /etc/mplayer/mplayer.conf, especially to the sub-fuzziness variable. use "man mplayer" to get explaination on it.

  Music player - RhythmBox
  
  4. BBS tool
  Fterm -> Qterm

  5. P2P tool
  eMule -> aMule.

  For chinese internet user, recommended server list: for ed2k network, use http://www.emule.org.cn/server.met, for kad network, use ttp://www.emule-inside.net/nodes.dat.

  In order to log into popular servers, you'd better change your client name to [CHN][VeryCD]** style. For those wireless router users, in order to get HighID when you log into a server, you should configurate the TCP/UDP port mapping on your wireless router. If outter client can connect to your client directly, you will get HighID in eMule system.

  To better integrate amule with Firefox, you should add some web protocol handler to Firefox and some other aMule plugins. First, use "sudo apt-get install amule-utils" to install amule-utils package. In about:config page of Firefox, create a new boolean var, named "network.protocol-handler.external.ed2k", and set it to be true; create another string var, named "network.protocol-handler.app.ed2k", set its value to "/usr/bin/ed2k". From now on, when you searched out some useful resources on VeryCD's website, you can just click the ed2k://*** link, and that resouce will then automatically added to your amule client if it is already running.

  6. IM tool
  Google Talk ,Windows Live Messenger and Tecent QQ -> Pidgin. It will organize all your buddies from these 3 protocols into one uniformed UI.

  7. Fonts from Microsoft
  To beautify your system fonts, run "$ sudo apt-get install msttcorefonts ". It will download some popular fonts from Microsoft, extract and install the font files. You now have more options in font choosing dialogues.

  So life seems much the same as on Win XP paltform, the only exception is that I still haven't get my TV card run on Ubuntu yet ...

10/19/2008

The great PsExec and How it works

  Recently, one of my project tasks is to remotely manage serveral tens of computers - format the disks, deploy some softwares, run some executables, copy some data files into a center place ...

  Due to the lack of cluster managment tool, I turn to a simple but very powerful tool PsExec, one of the PsTool commands from systeminternals.

  You can use this tool to execute any commands on remote nodes and bring the console output back to the node where PsExec runs. You can also copy some local file to remote node and execute that file. And also, you can specify in what user account, those commands will run. You can try that command to get more info about it.

  One thing needs to mention is that if you want to use some commands, that are inner command (for example, dir c:\*) of windows console shell(cmd.exe), you'd better tell PsExec to run "cmd /c dir c:\*" on remote server. This is because there is no executable called "dir.exe", but "cmd.exe" does.

  The most magic character of PsExec is that, there is nearly NO ANY need for the server side, no need to manually copy something into remote server, no need to open the telnet service ... So, as a developer, I think many people would ask how did PsExec do all the magic stuff? Of cause, I am one of them.

  After some discussion with colleagues and searching on the web, here is the secret:
"  First of all I've found that psexec.exe contains embedded binary resource PSEXESVC, that is actually a PE-executable, more exact it's a Win32 service. Some initial reversing of PSEXESVC discovered that this is a server part of utility responsible for starting processes and redirecting I/O to/from client system. However, lets start from very beginning and describe what psexec.exe do in sequence.

  As it expected first things utility do is checking host operating system and parameters validity, an example if the application to copy and execute exists on the host system. I think here is no need to describe this part in details, any programmer working over console application do the same things (again and again in endless loop...).

  After parameters validated psexec obtains pointer and size of PSEXESVC resource:

HRSRC hSvc = FindResource (NULL, "PSEXESVC", "BINRES" );
if ( !hSvc ) return 0;
HGLOBAL hGbDesc = LoadResource (NULL, hSvc);
DWORD dwSvcSize = SizeofResource (NULL, hSvc);
PBYTE pPsExeSvc = LockResource (hGbDesc);

  Then creates file in "\\RemoteSystemName\ADMIN$\System32" named PSEXESVC.EXE and saves resource into it. If there is no existing session with permissions to access RemoteAdmin(ADMIN$) share it tries to establish new session using username and password specified in command line via call to WNetAddConnection2 as following:

DWORD PsExecRemoteLogon (
LPCSTR lpComputerName,
LPCSTR lpUserName,
LPCSTR lpPassword
)
{
char szFullPath [_MAX_PATH];
NETRESOURCE NetResource;
sprintf (szFullPath, "\\\\%s\\IPC$");
// Initialize NetResource structure, omitted here
...
return (NO_ERROR ==
WNetAddConnection2 (
&NetResource,
lpPassword,
lpUserName,
0)
);
}
  If no error happen we have PSEXESVC.EXE in \\SystemRoot\System32 folder on remote system. Note, if the executable to start remotely must be copied to the remote system, it will be also placed into that folder. After this psexec.exe install and start PSEXESVC service using SCM API (OpenSCManager, CreateService, StartService). Full description of these calls in source would take pretty much place, and I don't see much need to do this.

  After start PSEXESVC creates named pipe "psexecsvc", and start reading messages from it. For this moment we have server part installed and started on remote system, ready to accept command messages. All other work is typical for client/server applications (for better understanding of writing server applications I strongly recommend Jeffrey Richter, Jason D.Clark "Programming Server-Side Applications for MS Windows 2000"). So psexec.exe copies executable to start to remote system if necessary, opens psexecsvc pipe on remote host (CreateFile), fill in message structure with necessary parameters (command line arguments, username&password if specified and etc...) and sends it into \\RemoteSytem\pipe\psexecsvc (TransactNamedPipe API call).

  On receiving this message PSEXESVC creates three named pipes instances "psexecsvc-app_name-app_instance-stdin", "psexecsvc-app_name-app_instance-stdout", "psexecsvc-app_name-app_instance-stderr". As you may suspect psexec.exe connects to each of these pipes and creates separate threads to work with each one. Using console functions (GetStdHandle, ReadConsole, WriteConsole and etc..) standard I/O streams (input, output, error) redirected to/from remote system through previously mentioned named pipes.

  On exiting application psexec.exe stops and uninstall PSEXESVC service, removes it's binary from remote host and removes console executable if it was copied.

  As a result you have telnet like application with extensive use of Windows NT/2000 features, it can be effectively used by system administrators for common administration tasks. The only hole (mentioned on utility homepage) is security: "If you omit a username the remote process runs in the same account from which you execute PsExec, but because the remote process is impersonating it will not have access to network resources on the remote system. When you specify a username the remote process executes in the account specified, and will have access to any network resources the account has access to. Note that the password is transmitted in clear text to the remote system". As you can see this tool is dangerous to use for remote administration via Internet or sometimes even in corporate network (as dangerous as telnet an example). One of the possible extension for this tool would be securing communication of psexec and psexesvc with encryption. However, in combination with IPSEC (if IP used as transport for CIFS) it can be successfully used even today. "


  So from the upper description we can find that the corner stones that make PsExec magic happen are two mechanisms: one is the convinient way to access "\\RemoteNode\ADMIN$" folder, withou this, PsExec can't upload the extracted PSEXESVC onto the remote server; the other one is the Remote Service Management facilities proviced by windows OS, by which PsExec can start and manage its server part. In a word, some existing inner "remote copy, remote execute" facility, provided by windows OS, make PsExec behaves like a magic tool.

  As to my task mentioned at the beginning of this article, I write some batch script and store it as *.bat file, and tell PsExec to execute it remotely. For each inner command of windows console shell, I prefix it with "cmd /c". For the powerful commands come from windows console shell and other useful executables, please refer to my previous articles. And also, use windows PowerShell and PowerShell script is another good alternative to batch script.

  One suggestion to make this tool even better is to make it have some "persistent copying" features.

  There are many situations that I need to copy some data files onto remote servers, but the user accounts in local and remote machine can't access eath other's resources, so share folder can't resolve this problem.

  Yes, PsExec now has one "-c" parameter, by which you can upload it to remote machine. But this file can only be executable files and it is the command that PSEXESVC will execute. What's more, this file will be deleted when the PsExec ends, so you can't cheat current PsExec to do what I mentioned here.

  So, in order to do "persistent copy", PsExec should either provide a switch to tell it NOT delete remote copied files on exiting, or It should provide a new parameter that is only used to copy files persistently.

10/09/2008

Books on Scalable Web Application Architecture

"Building Scalable Web Sites"
- by Cal Henderson, 2006.
[It focuses on back-end architecture, design considerations, technologies tips and practices, but not only system scaling technologies, also some application level techniques ]

"High Performance Web Sites"
- by Steve Souders, 2007.
[It focuses on front-end technologies and some web server tuning tips that can improve web application performance]

"Information Architecture for the World Wide Web"
- by Louis Rosenfeld and Peter Morville, 2006.
[It focus on overall design of web based information system and involves both technical and non-technical aspects]

"Scalable Internet Architectures"
- by Theo Schlossnagle, 2006.
[This book is all about core scaling problems and technologies that a large scale web site have to face]

"Squid: The Definitive Guide"
- by Duane Wessels, 2004.
[Squid is a caching software for web server, this book focuses on various aspects on this great software]