Configuring tftp in Ubuntu
I am trying to upgrade an old FNS1000 NAS to be a LAMP server, which I will describe here if I am successful. One thing I needed was to be able to communicate with the NAS via tftp and I had a real hard time setting up the tftp server on my Ubuntu system. I have finally got it working and so I will explain how I did it here.
First you need to download and install tftp tftpd and xinetd using Synaptic or with
sudo apt-get install tftp tftpd xinetd
Using your favourite editor write the following text file and save it as /etc/xinetd.d/tftp
service tftp
{
protocol = udp
port = 69
socket_type = dgram
wait = yes
user = nobody
server = /usr/sbin/in.tftpd
server_args = -s var/lib/tftpboot
disable = no
}
I found that the directory /var/lib/tftpboot was already in my /var/lib folder. I’m not sure where it came from but if you have it use it and if not make it with
sudo mkdir /var/lib/tftpboot
Then change it’s permissions and ownership with
sudo chmod -R 777 /var/lib/tftpboot
sudo chown -R nobody /var/lib/tftpboot
Then start tftpd through xinetd. You have to use re-start and not start
sudo /etc/init.d/xinetd restart
That’s the configuration. Now to test the server.
Place a test file test.txt in the /var/lib/tftpboot and then give it 777 permissions with
chmod 777 /var/lib/tftpboot/test.txt
cd into the /var/lib/tftpboot directory and start tftp with the ip address of your PC. On the tftp> type “put test.txt” and if everything works you will get the Sent message like below.
cd /var/lib/tftpboot
tftp 192.168.0.10
tftp> put test.txt
Sent 722 bytes in 0.0 seconds
tftp> quit
Good luck
Microwave Link Engineering Tool proving popular in Poland
This is a special welcome to all of the new MLET users from Poland, I hope that you are happy with the tool. You can leave any comments or suggestions for improvement below.
There has been a big increase of MLET users from Poland over the last few weeks and I was wondering what the reason for this increase is. Was there an article written about the tool or was it word of mouth? I would appreciate any feedback on this.
One more thing, please click on any interesting Google Ads links on the page. This is the only way I get anything for my efforts.
Do widzenia
Deleting root’s trash
Time again I manage to delete the root trash but next time I’ve forgotten how to do it. So this time I’ll write it down.
open a root nautilus window with
gksu nautilus /root/.Trash/
now highlight the files you want to delete and then press Shift-delete.
Do not “move to trash” as they will just pop up again
Nautilus “Open as root” script and “gksudo nautilus” not working.
I recently tried my “open as root” script and it didn’t work so I tried “gksudo nautilus” from the terminal and got the following error:
steve@x-desktop:~$ sudo nautilus [sudo] password for steve: seahorse nautilus module initialized Initializing nautilus-share extension (nautilus:6653): GLib-GIO-CRITICAL **: g_simple_async_result_set_from_error: assertion `error != NULL' failed (nautilus:6653): GLib-CRITICAL **: g_error_free: assertion `error != NULL' failed (nautilus:6653): GLib-GIO-CRITICAL **: g_simple_async_result_set_from_error: assertion `error != NULL' failed (nautilus:6653): GLib-GIO-WARNING **: (/build/buildd/glib2.0-2.16.6/gio/gfile.c:5249):IA__g_file_load_partial_contents_finish: runtime check failed: (g_simple_async_result_get_source_tag (simple) == g_file_load_contents_async) Segmentation fault
The problem was that I had a blank CD in the drive. After I removed the CD everything was back to normal.
I have made a currency convertor which uses the daily updated European Central Banks exchange rates. You can convert between 35 different currencies.
The converter can be found here.
The previous post shows how I download and upload the ECB XML file.
Using the ECB Currency XML with Javascript
The European Central Bank make available daily an XML file with the exchange rate of the Euro to 34 currencies. This can be found at http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml
To use this in javascript I faced two problems:
1) How to get around the inter-domain problem. The easiest way to do this is with PHP/Curl but my ISP does not support php! I solved this by downloading the file and uploading it to my webserver. First I GET the file from the CEB website.
<?php
function get_file1($file, $local_path, $newfilename) {
$out = fopen($newfilename, 'wb');
if ($out == FALSE){
print "File not opened<br>";
exit;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $out);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $file);
curl_exec($ch);
curl_close($ch);
}
and the I PUT the file onto my server.
$url = "ftp://my.server.at/ECBRates.xml";
$localfile = "/var/www/ECBRates";
$fp = fopen ($localfile, "r");
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'user:password');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
$http_result = curl_exec($ch);
$error = curl_error($ch);
$http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE);
curl_close($ch);
fclose($fp);
print $http_code;
print "<br /><br />$http_result";
if ($error) {
print "<br /><br />$error";
}
?>
Copy these into a single document and name it xmlgetandput.php and run it using curl:
curl localhost/xmlgetandput.php
If for whatever reason you are unable to do this yourself I can upload the file (or any other file) to your webserver daily for fee of €5 per month. Just make a comment with the title “upload” and I will contact you via email with details.
2) Loading and parsing an XML file is different for DOM compliant browsers and for Internet Explorer. I found this simple for the DOM complient browsers but it took me over a week of googling to get the IE working. The problem was further compounded by the fact that the ECB Currency XML has a strange hierarchy. But I got it working with the following javascript code.
var doc
function load() {
if (document.implementation &&document.implementation.createDocument){
doc = document.implementation.createDocument("", "", null);
doc.load('CEBrates.xml');
doc.onload = createTableMoz;
}
else if (window.ActiveXObject){
var doc1 = new ActiveXObject('Msxml2.DOMDocument.3.0');
function loadXML(xmlFile){
doc1.async=false;
doc1.load(xmlFile);
doc1.setProperty("SelectionLanguage", "XPath");
var nsMappings = "xmlns:gesmes='http://www.gesmes.org/xml/2002-08-01' " + "xmlns:default='http://www.ecb.int/vocabulary/2002-08-01/eurofxref'";
doc1.setProperty("SelectionNamespaces", nsMappings);
var xpath = "/gesmes:Envelope/default:Cube/default:Cube";
var cubeMain = doc1.selectNodes(xpath)
var dateRate = cubeMain[0].getAttribute('time');
var dateRateSplit = dateRate.split('-');
xpath = "/gesmes:Envelope/default:Cube/default:Cube/default:Cube";
var cubes = doc1.selectNodes(xpath);
for (var i = 2; i < cubes.length; i++){
var currency = cubes[i].getAttribute('currency');
var rate = cubes[i].getAttribute('rate');
rateObject[currency] = rate;
}
document.getElementById('boldStuff').innerHTML = dateRateSplit[2] + "." + dateRateSplit[1] + "." + dateRateSplit[0];
document.getElementById("currency").value = "GBP";
getRates();
}
loadXML('CEBrates.xml');
}
else {
alert('ActiveX must be enabled for this feature');
return;
}
}
function createTableMoz() {
var cubes = doc.getElementsByTagNameNS('http://www.ecb.int/vocabulary/2002-08-01/eurofxref','Cube');
var dateRate = cubes[1].getAttribute('time');
var dateRateSplit = dateRate.split('-');
for (var i = 2; i < cubes.length; i++){
var currency = cubes[i].getAttribute('currency');
var rate = cubes[i].getAttribute('rate');
rateObject[currency] = rate;
}
document.getElementById('boldStuff').innerHTML = dateRateSplit[2] + "." + dateRateSplit[1] + "." + dateRateSplit[0];
document.getElementById("currency").value = "GBP";
getRates();
};
var rateObject = {};
function getRates() {
var curr= document.getElementById("currency").value;
var currRate = rateObject[curr];
var currStatement= "1 EUR = " + currRate + " " + curr ;
document.getElementById("rate").value=currStatement;
var currRev=1/currRate;
currRevFix=currRev.toFixed(5);
var currRevStatement= "1 " + curr +"= " + currRevFix + " EUR";
document.getElementById("rateRev").value=currRevStatement;
};
Here is a link to the finished product http://members.chello.at/stephen.joung/indexCC.html . You might find the currency converter useful.
The Monty Hall Problem Simulation
The Monty Hall problem takes it’s name from a game show where the contestant has to choose from one of three doors.
Behind one door is a car, the main prize, and behind each of the other two doors is a goat.
After the contestant has chosen a door the host, Monty Hall, opens one of the other doors to reveal a goat.
The contestant is then invited to either swap his chosen door for the other unopened door or to stick with his chosen door.
The contestant actually improves his chances by swapping but this fact caused a lot of controversy
and disagreement, even among some famous mathematicians. You can read more about the problem here.
I have written a JavaScript script that simulates this game. You click on a door to select it then a goat will be revealed behind another door. You should then click on Swap or No Swap. The result is then counted according to whether you swapped or not. You can save yourself a lot of clicking by playing 1000 games at a go by selecting “1000 Plays Swap” or “1000 Plays No-Swap”. There is also a cheat function that enables you to check that the script is not cheating!
You can try it out here.