Compile and run shellinabox - Open SSH in a browser

I bought one beaglebone black, It has a nice IDE called Cloud9. One great feature of this IDE that runs entirely in a browser is allow access to shell.  I was amused by access shell on a browser. I was thinking if there's no any open source system to do the same in GConnect, then I found Shell In a Box.


bash-148836_640.png
Take a look in the project at: https://code.google.com/p/shellinabox/



The project keeps a lot of pre compiled versions. One compiled to ARM compatible with Raspberry pi - ARMv6. Our hardware is ARMv5, so it's necessary compile from the sources.

1- Installing the pre requirements:
# ipkg install gcc
# ipkg install gawk
# ipkg install libtool
# ipkg install coreutils
# ipkg install make

2- Download and expand the source:
# mkdir /opt/shellinabox
# cd /opt/shellinabox
# wget https://shellinabox.googlecode.com/files/shellinabox-2.14.tar.gz
# tar zxpvf shellinabox-2.14.tar.gz
# cd shellinabox-2.14

3- Starting the pre compilation process - ./configure :
To compile a source, basically it's necessary run:
# ./configure
# make

I didn't face any problem running ./configure, just run and wait.

# ./configure
checking for a BSD-compatible install... /usr/bin/install -c                       
checking whether build environment is sane... yes                                           
checking for a thread-safe mkdir -p... /bin/mkdir -p                                    
checking for gawk... gawk                                                   
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes                                                      
checking for C compiler default output file name... a.out                             
checking for suffix of executables...                                                      
checking whether we are cross compiling... no                                               
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes                                
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3                                                         
checking build system type... armv5tel-unknown-linux-gnueabi                      
checking host system type... armv5tel-unknown-linux-gnueabi                        
checking for a sed that does not truncate output... /bin/sed                     
checking for grep that handles long lines and -e... /bin/grep                    
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F                                                        
checking for ld used by gcc... /mnt/eSata/root/opt/arm-none-linux-gnueabi/bin/ld
checking if the linker (/mnt/eSata/root/opt/arm-none-linux-gnueabi/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm                 
checking whether ln -s works... yes
checking the maximum length of command line arguments... 98304                   
checking whether the shell understands some XSI constructs... yes            
checking whether the shell understands "+="... yes                                 
checking for /mnt/eSata/root/opt/arm-none-linux-gnueabi/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for ar... ar                                                 
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok   
checking how to run the C preprocessor... gcc -E                                
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes                                 
checking for string.h... yes                                 
checking for memory.h... yes                                  
checking for strings.h... yes                                  
checking for inttypes.h... yes                                 
checking for stdint.h... yes                                 
checking for unistd.h... yes                                 
checking for dlfcn.h... yes                                 
checking for objdir... .libs                                  
checking if gcc supports -fno-rtti -fno-exceptions... no                               
checking for gcc option to produce PIC... -fPIC -DPIC                                   
checking if gcc PIC flag -fPIC -DPIC works... yes                                      
checking if gcc static flag -static works... no                                             
checking if gcc supports -c -o file.o... yes                                                  
checking if gcc supports -c -o file.o... (cached) yes                                    
checking whether the gcc linker (/mnt/eSata/root/opt/arm-none-linux-gnueabi/bin/ld) supports shared libraries... yes                           
checking whether -lc should be explicitly linked in... no                          
checking dynamic linker characteristics... GNU/Linux ld.so                       
checking how to hardcode library paths into programs... immediate           
checking whether stripping libraries is possible... yes                              
checking if libtool supports shared libraries... yes                                    
checking whether to build shared libraries... yes                                        
checking whether to build static libraries... yes                                        
checking for an ANSI C-conforming const... yes                                             
checking whether gcc needs -traditional... no                                               
checking libutil.h usability... no
checking libutil.h presence... no
checking for libutil.h... no
checking pthread.h usability... yes
checking pthread.h presence... yes
checking for pthread.h... yes                                    
checking pty.h usability... yes
checking pty.h presence... yes
checking for pty.h... yes
checking for strings.h... (cached) yes
checking sys/prctl.h usability... yes
checking sys/prctl.h presence... yes
checking for sys/prctl.h... yes
checking sys/uio.h usability... yes
checking sys/uio.h presence... yes
checking for sys/uio.h... yes                                
checking util.h usability... no
checking util.h presence... no                                   
checking for util.h... no                               
checking utmp.h usability... yes
checking utmp.h presence... yes                                  
checking for utmp.h... yes
checking utmpx.h usability... yes                                       
checking utmpx.h presence... yes
checking for utmpx.h... yes                                  
checking for login_tty... no
checking for login_tty in -lutil... yes
checking for strlcat... no
checking for getgrgid_r... yes                                  
checking for getgrnam_r... yes
checking for gethostbyname_r... yes
checking for getpwnam_r... yes                                 
checking for getpwuid_r... yes
checking for openpty... yes                                 
checking for strcasestr... yes
checking for getresuid... yes                                 
checking for getresgid... yes                                 
checking for setresuid... yes                                 
checking for setresgid... yes                                 
checking openssl/bio.h usability... no
checking openssl/bio.h presence... no                                        
checking for openssl/bio.h... no
checking openssl/err.h usability... no
checking openssl/err.h presence... no                                         
checking for openssl/err.h... no                                     
checking openssl/ssl.h usability... no
checking openssl/ssl.h presence... no                                         
checking for openssl/ssl.h... no
checking security/pam_appl.h usability... no                                                     
checking security/pam_appl.h presence... no
checking for security/pam_appl.h... no                                            
checking security/pam_client.h usability... no                                                  
checking security/pam_client.h presence... no                                                   
checking for security/pam_client.h... no
checking security/pam_misc.h usability... no                                                    
checking security/pam_misc.h presence... no
checking for security/pam_misc.h... no
checking for dlopen... no
checking for dlopen in -ldl... yes
checking for deflate in -lz... yes
checking zlib.h usability... yes
checking zlib.h presence... yes
checking for zlib.h... yes
configure: creating ./config.status
config.status: creating Makefile                                      
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands

3- Starting the compilation process - make :
Probably when you run the make, you'll face a error about libtool. It's a path problem.

bash-3.2# make
od shellinabox/beep.wav >shellinabox/beep.h
od shellinabox/cgi_root.html >shellinabox/cgi_root.h
od shellinabox/enabled.gif >shellinabox/enabled.h
od shellinabox/favicon.ico >shellinabox/favicon.h
od shellinabox/keyboard.png >shellinabox/keyboard.h
od shellinabox/keyboard-layout.html >shellinabox/keyboard-layout.h
od shellinabox/print-styles.css >shellinabox/print-styles.h
od shellinabox/root_page.html >shellinabox/root_page.h
od shellinabox/shell_in_a_box.js >shellinabox/shell_in_a_box.h
od shellinabox/styles.css >shellinabox/styles.h
od shellinabox/vt100.js >shellinabox/vt100.h
make  all-am
make[1]: Entering directory `/mnt/eSata/root/opt/shellinabox/shellinabox-2.14'
/bin/sh ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.    -g -std=gnu99 -Wall -Os -MT hashmap.lo -MD -MP -MF .deps/hashmap.Tpo -c -o hashmap.lo `test -f 'libhttp/hashmap.c' || echo './'`libhttp/hashmap.c
./libtool: ./libtool: cannot execute binary file
make[1]: *** [hashmap.lo] Error 126
make[1]: Leaving directory `/mnt/eSata/root/opt/shellinabox/shellinabox-2.14'
make: *** [all] Error 2

3.1- Change Makefile to the right libtool:
The libtool that comes with the source does not work well, but we already installed the right one using ipkg in the beginning of this tutorial. Now let's set this in Makefile.

Comment this line and create the follow one:
# vi Makefile

Comment the line below:
# LIBTOOL = $(SHELL) $(top_builddir)/libtool

And create a entry to the right libtool:
LIBTOOL = /opt/bin/libtool

Save and re run make.

bash-3.2# make
make  all-am
make[1]: Entering directory `/mnt/eSata/root/opt/shellinabox/shellinabox-2.10'
/opt/bin/libtool --tag=CC   --mode=link gcc -g -std=gnu99 -Wall -Os -export-symbols  ./libhttp/libhttp.sym -version 1:0:0  -o libhttp.la  hashmap.lo trie.lo httpconnection.lo server.lo ssl.lo url.lo   -lz -ldl -lutil
/home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/arm-none-linux-gnueabi-ar cru .libs/libhttp.a .libs/hashmap.o .libs/trie.o .libs/httpconnection.o .libs/server.o .libs/ssl.o .libs/url.o
/opt/bin/libtool: line 5999: /home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/arm-none-linux-gnueabi-ar: No such file or directory
make[1]: *** [libhttp.la] Error 127
make[1]: Leaving directory `/mnt/eSata/root/opt/shellinabox/shellinabox-2.10'
make: *** [all] Error 2

Now you'll probably face another path problem. this time: arm-none-linux-gnueabi-ar

3.2 - Solve the arm-none-linux-gnueabi-ar path problem:
The easiest way is create this directory structure and create a symbolic link to a ar binary.

# mkdir -p /home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/
# which ar
# ln -s /usr/bin/ar /home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/arm-none-linux-gnueabi-ar

Then re run make.

bash-3.2# make
make  all-am
make[1]: Entering directory `/mnt/eSata/root/opt/shellinabox/shellinabox-2.10'
/opt/bin/libtool --tag=CC   --mode=link gcc -g -std=gnu99 -Wall -Os -export-symbols  ./libhttp/libhttp.sym -version 1:0:0  -o libhttp.la  hashmap.lo trie.lo httpconnection.lo server.lo ssl.lo url.lo   -lz -ldl -lutil
/home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/arm-none-linux-gnueabi-ar cru .libs/libhttp.a .libs/hashmap.o .libs/trie.o .libs/httpconnection.o .libs/server.o .libs/ssl.o .libs/url.o
/home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/arm-none-linux-gnueabi-ranlib .libs/libhttp.a
/opt/bin/libtool: line 5999: /home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/arm-none-linux-gnueabi-ranlib: No such file or directory
make[1]: *** [libhttp.la] Error 127
make[1]: Leaving directory `/mnt/eSata/root/opt/shellinabox/shellinabox-2.10'
make: *** [all] Error 2
bash-3.2# ranlib

Now you'll probably face another path problem. this time: arm-none-linux-gnueabi-ranlib

3.3 - Solve the arm-none-linux-gnueabi-ranlib path problem:

Same solution:

# which ranlib
# ln -s /usr/bin/ranlib /home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/arm-none-linux-gnueabi-ranlib

Then re run make and the code will compile flawlessly.

OBS: As the flash of GConnect is pretty small, I didn't run make install script. I prefer keep the binaries and the source together in the hard drive and call the binaries using the full path.

4 - Testing the shellinabox
# ./shellinaboxd -s/:LOGIN -t --no-beep

Open a browser and open http://gconnect.local:4200 (or substitute gconnect.local by your GConnect IP)

Optional - Put the shellinabox to start automatically
I include this line in my /root/rc.local
# Start shell in a box http://gconnect.local:4200                                                                                              
/opt/shellinabox/shellinabox-2.14/shellinaboxd -s/:LOGIN -t --no-beep --css=/opt/shellinabox/shellinabox-2.14/shellinabox/white-on-black.css -b
=/opt/shellinabox/shellinabox-2.14/shellinaboxd.pid   

I include some preferences in this start as: Black on White profile (letters in white, back in black) and creation of PID file inside the source directory.

OBS: All command is in the same line.