Monday, November 28, 2011

making a ThinClient OS with pxeboot support


When I needed a thin client for the company which I am working for, I firstly researched some existing products on the market. (wise, chipPc etc.) Actually, there were some good things but I needed a more customizable one. When the subject is about customization, I have got an unique address for solution: that's
linux. I wanted to create a simple, easy to setup and strong solution. I checked following criterias:
  1. I had to use a complete distrubution to start to work. Because, all distrubutions are ready for use. I didn't need to handle more to start.
  2. I had to create image file/files as OS. It should be open from image / images files every times. Therefore, It can keep ifself as strong.
  3. If I could supply the Boot On Lan feature on my pxeboot server, the clients would never get damaged in the future. Because all clients would run on only their RAM device. Altough they had been shutdown un-properly, they could stil read the original image file from the pxeboot server. I only needed keep the image file safe which is located on the pxeboot server.
I researched a few distros and than I selected the SLAX for my project. It's using squash FS (lzm files). It seemed the best choice for my requirements about the image.. SLAX distro is normally used on the usb devices. It's a kind of mobile version of Linux. You can use it in several hardwares.

However; I had to change something on standard SLAX. The history of my project begins.

In order to install Slax, download the USB image from site "http://www.slax.org/get_slax.php". After extracting it, it will generate two different directories: slax and boot. Firstly we need dir2lzm and lzm2dir scripts/commands to extract lzm files and to re-build the lzm file again. These are located in the directory /slax/tools/.


Slax has got a very nice structure. Making manipulations are very easy and controllable. For example, you can create a module file to create some changes from original slax and you can apply this changes by a single copy-paste operation. There is a director, with name modules, exists for this purpose. After starting to make changes in 001-core.lzm file located in base directory, I realized that this was not a good way.

Note: Your linux (also windows OS) has got a variable about default PATH to find predefined commands on your operating system. But your tools directory (located in Slax directory) is not included in the PATH variable. So if you try to execute lzm2dir command in somewhere, you will not be able to execute it. You can execute it with a full path or you can execute it with "./lzm2dir" command when you are located in tools directory or you can add your tools directory it to the PATH. Most useful way is adding the tools directory into the your PATH variable. Suppose that your Slax directory is located in the /home/User. We can get and set the PATH environment variable as shown below:

[user@hostn stdioe]#  /home/User/slax
[user@hostn stdioe]# /home/User/slax/tools <- related commands located in here
[user@hostn stdioe]# echo $PATH <- to check existing value of your PATH variable
/usr/lib/mpi/gcc/openmpi/bin:/home/User/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin
[user@hostn stdioe]# PATH=$PATH:/home/User/slax/tools <- to add slax-tools directory to in your PATH variable

Good, We can use that commands from everywhere by now. Let's extract the 001-core.lzm file to do some manipulations.

Note: Actually, that commands are just several simple shell scripts. The real commands are squash FS commands. If squash FS is not installed in your operaing system, you can not use the tools directory scripts. You have to have squashfs installed on your system. The squashfs is a read-only file system with efficient compression property. It's essential and base thing so, almost all distrubutions has got it in their package manager. You can install it using your package manager.

Let's extract the file 001-base.lzm and start to manipulation step; I created a stdioe directory and copied the file 001-core.lzm to the the directory stdioe. I created a directory called core_Dir to extract contents of the lzm to the directory core_Dir.

[user@hostn stdioe]# pwd
/root/stdioe
[user@hostn stdioe]# ls
001-core.lzm
[user@hostn stdioe]# mkdir core_Dir
[user@hostn stdioe]# lzm2dir 001-core.lzm core_Dir/
TIOCGWINZ ioctl failed, defaulting to 80 columns
[===========================================================-] 12069/12069 100%[root@ismldgn stdioe]#
[user@hostn stdioe]# ls
001-core.lzm core_Dir
[user@hostn stdioe]# cd core_Dir/
[user@hostn core_Dir]# ls
bin dev home media opt root srv tmp var
boot etc lib mnt proc sbin sys usr
[user@hostn core_Dir]#

core_Dir directory is a container for our thin client OS file structure. First of all, we have to focus on the file /etc/rc.d/rd.M. The file manager starts up the process.

We will create an image file which will then be used by our thinclients. So if we don't solve the problem of hostnames, all our thinclients will have got the exactly same hostnames. The main problem is, all of them connect to the same terminal server. The terminal server can not handle the connections properly. If you look from terminal server side, you can see a lot of clients are connected but all names are the same!

Normally rc.M assigns a hostname from contents of the file /etc/hosts. My offer is, we can create a new and different hostname for each client while booting progress. The mac address information already provides an unique information for this. We can use the mac to assign them different names! We can edit our commands after the line in which it is written "# Initialize the networking hardware.".



ls -aA1b /etc/dhcpc | egrep ".info\$" | while read INFOFILE; do
# the next line won't affect rc.M variables, because it's in >while read< loop
. /etc/dhcpc/$INFOFILE
echo "TPL`/sbin/ifconfig | /bin/grep "HWaddr" | /bin/gawk -F' ' '{print $5}' | gawk -F: '{print $1$2$3$4$5$6}'`."$DOMAIN >/etc/HOSTNAME
sed -i -r "s:127.0.0.1\tslax.*:127.0.0.1\tslax.$DOMAIN slax:" /etc/hosts
break
done

Well. Now, each client has got a different hostname. All hostnames start with a TPL prefix and continue the mac info without ":" and ".$DOMAIN" variable, respectively. If you don't need FQDN name, do not use the ".$DOMAIN" part.

This OS will be used as a thin client os. So the main goal is to "connect to the terminal server". We don't need advance graphical user interface. We need simple a simple solution. I selected fluxbox for this purpose. When the OS starts, the fluxbox should be opened automaticly. For this purpose, we have to add the content shown below with a ".xprofile" name in the "/root" directory. This configuration is to start the fluxbox GUI.

session=/usr/bin/startfluxbox
/usr/bin/setxkbmap tr
#/usr/bin/rdesktop terminalServerAddr -f -r printer:oki="Epson LX-80" -k language

The -k option is for defining the language. Please replace the proper language code for your language. The line marked with a '#' supplies a connection to the terminal server automaticly but I marked it to make it disabled, because user may want to do a different thing. So we have to create a menu file for fluxbox GUI. Let's create a lzm file again from the edited base package and create a new module file for other purposes.

[user@hostn stdioe]# 
[user@hostn stdioe]#
[user@hostn stdioe]# ls stdioeBase/
bin boot dev etc home lib media mnt opt proc root sbin srv sys tmp unsped usr var
[user@hostn stdioe]# dir2lzm stdioeBase/ 001-base-edited.lzm
[=============- ] 2337/10544 22%

Right now, our base lzm file is ready. But normally we have to create a module file for our changes. We don't have to handle the original base file. because when we a new release is published, we will need to handle it again. But if we create a module file, the copy paste operation will probably be enough for this. Also the module mechanism is very useful feature. Let's create a module file for other requirements,

[user@hostn stdioe]# mkdir nameOfModule
[user@hostn stdioe]# mkdir nameOfModule/root
[user@hostn stdioe]# mkdir nameOfModule/sbin
[user@hostn stdioe]# cd nameOfModule/root
[user@hostn stdioe]# mkdir .fluxbox
[user@hostn stdioe]# cd .fluxbox
[user@hostn stdioe]# vim menu

Content of the menu file is shown below:

[begin] ('The Project Name' - MENU)
[encoding] {UTF-8}
[submenu] (Tools)
[exec] (Command Window) {xterm}
[exec] (Internet Browser) {kfmclient openProfile webbrowsing}
[exec] (Text Editor) {kwrite}
[restart] (KDE GUI) {startkde}
[end]
[submenu] (Remote Desktop : termSrv.dom)
[exec] (800x600) {termsrvDOMr1}
[exec] (1024x768) {termsrvDOMr2}
[exec] (Tam Ekran) {termsrvDOMrf}
[end]
[exec] (Shutdown Computer) {pcShutdown}
[endencoding]
[end]

Of course, some used commands are not default ones. These are user defined. We have to write them and set execution permissions and locate them into a proper directory as value of $PATH variable. That files are listed below.

pcshutdown:

#!/bin/bash
init 0

Note: Our thin client os is already running on the RAM. So we can shutdown up-properly. "init 0" is the most rough way.

termsrvDOMr1:

#!/bin/bash
/usr/bin/rdesktop termsrv.DOM -g 800x600 -k tr -r printer:UGLpoki="Epson LX-80" -d DOMAINNAME -u ""

termsrvDOMr2:

#!/bin/bash
/usr/bin/rdesktop termsrv.DOM -g 1024x768 -k tr -r printer:UGLpoki="Epson LX-80" -d DOMAINNAME -u ""

termsrvDOMrf:

#!/bin/bash
/usr/bin/rdesktop termsrv.DOM -f -k tr -r printer:UGLpoki="Epson LX-80" -d DOMAINNAME -u ""

Finally set to execute permission and copy it to /sbin directory. After all, create lzm file of the module.

[user@hostn stdioe]# chmod +x pcshutdown termsrvDOMr1 termsrvDOMr2 termsrvDOMrf
[user@hostn stdioe]# cp pcshutdown termsrvDOMr1 termsrvDOMr2 termsrvDOMrf nameOfModule/sbin/
[user@hostn stdioe]# dir2lzm nameOfModule nameOfModule.lzm
[===================================================================|] 6/6 100% [user@hostn stdioe]#
[user@hostn stdioe]#

Right now, if we copy that lzm module file to modules directory, this module will be enabled when booting the OS automaticly. But we still don't create a module for printer driver and configuration. That file content is a little bit long so explaining how to create a printing module is not a good idea in this.. But you can use a usb version of Slax and open it with "Slax Graphics mode" option and install printer driver and configure it then shutdown properly. Then, if you check directory changes, you can find all changes about the printer installations and configurations. The problem is, existing files are not only about the print functionalty. You have to select printer related ones. I can create a download link in this page, but usually it is not a good idea to create a download link about any file. If some body want to download that file, I will send it.

Good. Our thinClient OS is ready. We prepare it from the usb version of Slax. And now, we will prepare a tftp server and http server to get the pxeboot server ready. TFTP server installation and web server intallation are not related to this article, so I don't explain it. But I have to say again, your http server should be a permitted directory and configured as indexing compatible with httpfs property. Because, when the boot process starts, our pxeboot server will send the boot parameters via tftp server and than starts to use the https service for loading big files. Because tftp is a UDP based service and http is a TCP based service. Nobody wants to use UDP based service to load big files. So UDP does not check the data whereas TCP uses a checking mechanism while data is transfering.

The boot directory should be located in the directory "tftproot" and Slax directory should be located in the http publishing root directory. (/var/www/html or /srv/www or something like that).

The last step is to configure the DHCP server for pxe booting. My project environment has got a Microsoft Windows 2003 Server for DHCP server. When you right click to scope option and select the configure option in this DHCP server, you can see a window. This window has got "066 Boot Server host Name" and "067 Boot File Name" options lines. You have to add the ip address of your pxeboot server to "066 Boot Server host Name" option and write "/boot/pxelinux.0" for "067 Boot File Name" option. Right now, if you set "boot on lan" option in a client computer bios, as a client computer starts, it will search a DHCP server, and it will learn pxe boot server address, file name info, the boot parameters from the tftp server and OS files from pxeboot server via httpfs service, respectively.


Content of the file /tftproot/boot/pxelinux.cfg/default is shown below:

PROMPT 0

LABEL linux
MENU LABEL Run linux over PXE
KERNEL /vmlinuz
IPAPPEND 1
APPEND vga=769 initrd=/initrd.gz ramdisk_size=6666 root=/dev/ram0 password=qwe123 rw autoexec=xconf;telinit~4

LABEL memtest86
MENU LABEL Run Memtest utility
KERNEL /mt86p

This project is suitable to be developed more.. I created more than one configuration files. When the boot process starts, it will be able to read mac address and get the configuration as its mac info. So we can make more than one groups. Each single member of the group can read different module files and configurations. For example, you can create two different groups and than you can include some mac addresses of that groups. Every group have got a single configuration file. Therefore, every client will use their own setting. By the way, I think the most powerfull feature of this OS is, It will never crash!. Because it will use the same lzm file for booting process. If you can create a usable OS, you will always be able to use it. Itwill never need "disk defragmentation" or something like this...

String ambiguity in Java



Java has two kind of data types. The first one includes the primitive data types. They are int, long, double
float, short, byte, boolean and char. Defining a single variable with one of the data types given above is similar
to variable declaration in C or C++. As in C brother, Java simply allocates a proper memory area for the given
type and maps the variable name for it when we type

int i;

in a program. It is simple to understand and clear. The mechanism underlying instantiating a class to create a new object
is similar to C++. For example, we create an object by instantiating a CCObject class using

CCObject *obj = new CCObject();


in C++, whereas, it is

CCObject obj = new CCObject();


in Java. In C++ example, a memory area is allocated for the CCObject and it is mapped to pointer obj which is shown as *obj.
We call its method "meth" using a code similar to

obj->meth();

whereas, it is

obj.meth();

in java. They are both created using a dynamic loading mechanism, that is, they does not exist in compile time and they
are created in runtime. In this use of "->" operator, object instantiating mechanisms are similar. However there is an
other method of creating objects in C++ which is like

CCObject obj;
obj.meth();


and it is totally different from the examples above. In this example, the object obj is created at the compile time
and it is faster. The dot operator is also different from the same operator in Java. Understanding the dynamic class
instantiating and compile time creating is important.

Lets have a look at the String class in Java, which is defined in the package java.lang in the Java core library. We can
create two Strings using a code

String s1 = "This is string 1";
String s2 = "And this is the second one!";

and we can do

String cat = s1 + s2;

which requires a "operator overloading" operation in C++. In Java, there is no operator overloading, that is, you can
not define a behavior for a given operator on a given class. But String class do that!

String class is an exception and it has got different properties when compared to others. Java compiler behaves different
when it compiles the codes with a String object. The another ambiguity is using literals with class methods. Look that:

String s = "Hello, this is a curse Java string";

This use seems like the Java Strings are built-in data types rather than objects! Ofcourse, Java compiler changes this line to

String s = new String("Hello, this is a curse Java string");

but what about this? :

int l = "Hello, this is a curse Java string".length;

If a Java student looks this line, the Java String seems to be an object again! This is because of the weird design of Java Strings.
Java compiles them in a consistent way but being Java Strings a exception obstructs the clean pattern of Java language.

What is the solution?

Firstly, for my personel opinion, operator overloading would be a good property for Java language. So, it would be a more elegant solution
to drop this

Matrix A = new Matrix (data1);
Matrix B = new Matrix (data2);
Matrix C = A.transpose().product(A).inverse().product(A.transpose().product(B.transpose));

and replace with

Matrix A = new Matrix (data1);
Matrix B = new Matrix (data2);
Matrix C = (A.transpose() * A).inverse() * A.transpose() * B.transpose();

This provides the consistency in the use of summation operator with String classes.

Dropping the ambiguity in the cases that "a string content".length and String s = "This is a string" is hard because millions of
Java code uses this syntax. Deprecating this use and dropping it in next revision is a solution. It would be still as it is. But
remember the Basic language and remember how difficult to parse it was. Writing code in an easy way is not the whole art. A consistent
language is like an deterministic toolbox.

My radical idea is to use the C++ syntax in Java virtual machine. Something must be an object, something must be a pointer to an object. Operators
would be overloaded as "Java does it to its Strings!". So, how it would be nice if we compile this code into the JVM:

String *s = new String("Hello there, it would be a Java String!");
int length = s->length;
System::out::println(*s->chars);

and of course

String s = String("Hello there... it is also a Java String");
int length = s.length;
System::out::println(&s.chars);

:)

Moreoever, there would be some strangers around who want their C++ syntaxed Java code compiled into the JVM!

Tuesday, November 15, 2011

Web 2.0 Tech and a Jquery Auto Search Complete Application!

Hi! Today I want to talk about web 2.0 technology. As you know, web 2.0 is being used by many of us. Especially frameworks developed with javascript and ajax, used by everyone. Well, we can say that huge companies which are google, yahoo, facebook and twitter etc. use web 2.0 too.

I would like to make an application on Jquery and share with you guys. So, in 2006, Jquery's started to be developed as an open source project. When you see "The write less, do more", you should understand that is Jquery! There is a powerful library of javascript, that's why we can do good jobs with the less code on Jquery.

If you want to see more information, you can visit the official web site of jquery. You can also find documentation and examples on it. That is here!

You must call as include jquery library on your web site, for the successful operation of your jquery code. You can find the library on Jquery Web Site easily.

The point I wanted to show you here is an ajax application on jquery. However, I am thinkin' that I should show you couple simple examples, before starting to applicaton.

$('#divID').slideUp(1000); //Sliding the div up
$('#divID').slideDown(1000); //Sliding the div down
$('#divID').slideToggle(1000); //Sliding the div up and down
$('#divID').FadeToggle(1000); //Displaying or hiding the div
$('#divID').html(“Hello World!”); //Printing something as HTML tags

$(‘a’).click(function() {
 $("#divID").animate({left:'+=100px'}, 2000); //when you click the mouse, do something
});

As you have seen, when you code jquery, you can control the web site all the way.
The application I'll show you, is an AUTO SEARCH COMPLETE!


This is the text field we'll use when searching.


This is the div layer will open during our php script works.
// JavaScript Document
$(document).ready(function() {
 $('#TextBox').keyup(function() {
  document.getElementById("result").style.display="block";
  var variable=$('#TextBox').val();
  $.ajax({
      url:"data.php",
      data:"TextBox="+variable,
      cache:false,
      async:false,
      method:'post',
      success:function(kitchen) {
          var message="Loading..";
          $('#result').html(message).load();
      }
  });
 });       
});

As you have seen, when keyup() function works, the system is getting data from data.php page. data.php page is shown below

 include("database.php");
 $data=$_REQUEST["TextBox"];
 if(!$data==0) { 
  $MyData=mysql_query("select * from names where name like '%$data%'");
  if(mysql_num_rows($MyData)<"1") {
   echo "There is nothing about it!"; 
  } else {
   echo "Languages!
"; while($MyList=mysql_fetch_array($MyData)) { echo $MyList["name"]."\n"; } } } else { echo "Please, start to write something.."; }


Today, we made a jquery search auto complete application. If you visit and see this application, just click demo page!

See you guys next article!

Monday, November 14, 2011

A Nokia application for system room temperature controlling.

One of the our previous article ( http://stdioe.blogspot.com/2011/10/checking-system-room-temperature-with.html ) was explaining how to get temperature information from some devices. We showed that related scripts saves the temperature value to a MySQL table. In this article, we are explaining publishing only the current temperature value on a public web page. The Nokia application will read that value to generate alarms when the value exceeds a critical value. The Nokia application is written by jbytecode to follow up via cell phones. If system room temperature reaches a predefined critical value, your mobile cell phone will create an alarm sound. Therefore you will be informed where ever you are.

The mobile phone application is an open source project and is being hosted on Google Code web site. You can access .jar and .jad files and source code on http://code.google.com/p/atlantis-networking-utilities web page address.Note that we call that "Nokia Application" because we only tested it with a Nokia E-72. Of course it is generally a Midlet application which can run in any supported device.

You can start the application by simply clicking the icon,

You have to define a temperature reader url on that program. If you need, you can change the checking period of system room temperature and define a critical temperature value,

After editing the configuration you can start the application,


The application needs internet connectivity. When it starts, it will show a confirmation alert and wait your response. Allow it.


Finally, it will start to read the current temperature value for the given time period. Received temperature values are logged in a text box.


This application is in its early stages. If you need extra features etc. let us know please. It's already an open-source project on code.google.com site. Every body can help to develop it or write to us ...


The current temperature publishing page is like following: You need to replace some parts on the code. MySQL server, user and password,DB_name, table_name and "temp" field names should be changed manually.

Also you may want to sort the historical values by date, so I am adding a date field on the sample db.


<?php
$link = mysql_connect("MySQL_Server","MySQL_User","MySQL_Password") or die("Error message");

mysql_select_db("DB_Name") or die("Error message");

$query = "SELECT * FROM `table_name ORDER by `date` DESC";
$result = mysql_query($query);
$line = mysql_fetch_array($result);
$temp = $line["temp"];
print $temp;
mysql_close($link);
?>

You will get only the curreny temperature value as a plain text whenever the page is accessed by the TempAlarmer. Please let us know your comments to develop it more.

Have Fun!


Monday, October 31, 2011

Handling Plots with RCallerPhp Edition

Now we have RCaller Php edition, named RCallerPhp, which is able to handle images generated by R. I hope it will bring an other easy solution for calling R from other platforms.

With this feature, web developers that use Php as their main language and need calculations done by R will easly use this library.

It is distributed as its big brother, RCaller Java Edition, with the LGPL (Lesser GNU Public License).
RCallerPhp is intended to be compatible as much as possible with the Java version. So, investigating the old examples may be helpful for understanding this new release.

In a time of less than a week, we released this version without the plotting support. By now, generating R plots and showing them in a browser is implemented. Generated plots are stored in the temp directory instead www directory. That is why we are encoding generated plots inside the img src tags with base64 encoding. You can have a look at the source code at RCaller source code at Google project hosting.

Handling plots with RCallerPhp is quite easy. Let's have a look at the code below:

<?php

require_once("../RCode.php");
require_once("../RCaller.php");
require_once("simpletest.php");

$caller = new RCaller();
$code = new RCode("");

$plot = $code->startPlot();
$code->addRCode("plot.ts(rnorm(10))");
$code->endPlot();

$caller->setRscriptExecutable("/usr/bin/Rscript");
$caller->setRCode($code);
$caller->runOnly();

print($caller->getPlot($plot));
?>

Here is the generated output, which is copied from the web browser:


Nothing is easier than this! Do not hasitate to ask anything about RCaller.
We hope you enjoy...
Have fun...