Tim Groeneveld

Random musings from the world of an Open Source geek

Making external applications add money to accounts in MyBanco

/ | Leave a Comment

I got an email earlier this morning, asking me how hard it would be to “make something that can activate a transaction when an action happens in another code”. I thought about it for thirty seconds, and realised that it would not be too hard. Infact, it was super easy to do.

There are two ways that it can be done, the MyInfo way, which is complicated, and the MySQL way, which will be the easiest (for the moment). A simple transaction taking place will take about 12 lines of code.

In Psuedocode:

mysql_connect("database.server.com", "root", "password");
mysql_selectdb("myinfo");
if (mysql_error) die "Can't connect to DB";
$SQL = 'INSERT INTO `transactions` (
          `transactionTime`, `from_aid`,
          `to_aid`, `amount`, `description`
        ) VALUES (
          UNIX_TIME(), "$from", "$to",
          "$amount", "Transaction from app"
        )'
mysql_query($SQL);
if (mysql_error) die "fail.";

And that is pretty much it. Not only does it add money to an account (the $to variable)… but it takes it out of an existing account in MyBanco. The only bad thing with using this is that there are no checks done to ensure that the central bank account (the $from) does actually have the right amount of money in there.

Adding this is done with a simple peice of code (in PHP):

if (!$aid) return array('error' => 982);

$SQL = 'SELECT SUM(`amount`) as `positive`
	FROM `transactions`
	WHERE (`to_aid`="' . $aid . '")';

$mr1 = mysql_fetch_array(mysql_query($SQL));
$money_pos = 0;
if($mr1) {
        $money_pos = (is_numeric($mr1["positive"])) ?
                $mr1["positive"]:0;
}

$SQL = 'SELECT SUM(`amount`) as `negative`
        FROM `transactions`
        WHERE `from_aid`="' . $aid . '"
                AND `from_aid`<>`to_aid`';

$mr2 = mysql_fetch_array(mysql_query($SQL));
$money_neg=0;
if($mr2) {
	$money_neg=(is_numeric($mr2["negative"])) ?
                $mr2["negative"]:0;
}

return number_format($money_pos - $money_neg, 2);

Pretty easy, huh? Now all you have to do is before you insert the row into the transactions table, make sure that __bank_amountForAccount($from) is >$amount … and then you will never have “magic” money being circulated around the MyBanco bank system that ultimately should not exist.

Making ShareSource ‘Google Friendly’

| Leave a Comment

In the past few days, I have been working on making ShareSource a little more search engine (and in some cases user friendly).

The changes all round are pretty minor, but they were necessary things that had to be done, as Google Webmaster Tools said that ShareSource had around 3,000 pages with the same title!

Well, most of the changes have been pushed to the live server, and include changes such as:

  • The commits log showing what page you are on if the page is not page one.
  • The ShareSource project Search showing the query that you have made.
  • Project file releases have a nicer title … which is based on the project’s info.
  • Screenshots is similar, all screenshots now have a (pretty) unique title
  • The ShareSource Wiki knows that it sometimes needs to ditch useless parts of it’s URL, so it redirect to a better, nicer and shorter URL
  • Fixed a few spelling mistakes again (like facilies => facilities on the home page!)
  • Fixed a few broken URL’s on the project link bar.

Did I mention that is only the top seven? Plenty more changes were made as well as those.

The fact of the matter is now ShareSource will be a nicer place for search engines to crawl. The aim is also that the site will now get a bit of a bigger Google Rank, because there is no more duplicated content on the ShareSource site.

New MyBanco bug fix release (v0.04)

/ | Leave a Comment
# diffstat mybanco-0.03-to-0.04.patch
CHANGELOG               |  4 ++++
Skins/Simple/Simple.php | 38 +++++++++++++++++++++++++++++++++++++-
backend/index.php       | 28 ++++++++--------------------
backend/test.php        |  7 +++++++
libs/MyInfo-Client.php  |  7 +++----
5 files changed, 59 insertions(+), 25 deletions(-)

Mainly a bugfix release. Fixes the following issues:

  • Data sent to MyInfo is now always unescaped.
  • Nice pretty runtime errors for MyBanco.
  • The right MyInfo server is now always selected.

Most of these are changes I have made because of errors that were seen on dr-spangle’s local install of MyBanco. You can download either the update package (14KB) or the entire package (200KB) at the MyBanco website.

A .firm Top Level Domain?

/ | Leave a Comment

Hi,

Prior to writing a charter I hope to determine how well received .firm
will be as a top level domain.

The domain will be for users who want to establish any kind of presence
in the OpenNIC name space, commercial or non commercial.

This would be the alternate ‘.com’ , more or less but open to any kind
of use with very little restriction. While the name space is likely to
turn into the twilight zone quickly, it would make it easy for companies
to register their trademark vanity on OpenNIC.

Cheers,
Tim [Post]

I personally think this is a good idea, however there have been top level domains such as .pro, .tel and even .travel created, but how often do you see them used? Maybe it’s just that we need to beat into peoples head that “just” because a domain does not end in dot com does not mean it’s rubbish.

But even I see my self crawling through Google, and when I see a .info domain I sort of skip over it.

It probably has more to do with content, I know that I can get Panasonic’s website when I type in panasonic.com (which I think alot of people do … brandname dot com), but I can’t get it when I goto www.panasonic.pro.

Why does dot com seem to be the de facto location for registering domains?

The modern BBS

/ | Leave a Comment

Ahhh, the modern BBS. Let’s examine it. The modern BBS (which has yet to be given a name) is a mini hackathon project that I am doing to give some life to the rotting away OpenNIC “.bbs” top level domain. I am going to operate a bulitin board system, but update it a little at the same time.

My plans are to use SSH, Perl and Curses (Curses::UI to be exact) to do funky ASCII interfaces without spending *too* much time working on the fine lines.

Will share more when I awaken from my slumber.

How to run your own Top Level Domain

/ | 5 Comments on How to run your own Top Level Domain

What does it take to run a Top Level Domain Registry? And what’s more easy to run: a ccTLD or gTLD?

Opinions so far have ranged from “it’s easy” to “it’s a serious business” – both of which are obviously far too vague to being to measure what is an intriguing question. Some suggestions fall down in favour of the easy option: “only 5 ccTLDs show 24 x 7 support”, “registries are not difficult to run”. Others say, “it requires great technical skills, and business approach”. They maintain that the while technically and even theoretically it is easy to run a top-level domain, the realities mean providing and/or selling domains, advanced review systems, legal considerations and so on.

( the above was quoted from http://blog.icann.org/?p=21 )

It’s with some what of a geeky pride that I stand up and say: “I run my own top level domain (and you don’t)“, and I thought I might write a little article on how you can put your own geek hat on and say for yourself, that you run your own top level domain.

(Please don’t hurt my geek pride by saying dotING is not part of ICANN’s official root)

I will be looking at everything from technical requirements, through to staffing requirements and costs [which I did in my last post]. I will look at what software is needed to successfully operate a top level domain, the hardware and the management skills.

By reading this guide, I will assume that you know how to change the network settings for your operating system (i.e., change your DNS server(s)) and that you know how to install (but not configure) BIND. I will also assume that you run a decent operating system that is not based on the Windows architecture.

Required software
For this, I will presume you already have BIND (I recommend version 9) of some sort installed on your machine. I will be using Ubuntu 7.10 ( yes, I know I need to upgrade 🙂 ), with the BIND that ships with Ubuntu. Other installations of BIND may or may not be similar. If not, I would suggest reading up on a basic BIND tutorial.

sudo apt-get install bind9 dnsutils

The first config change
The first thing I do when I set up an Ubuntu machine to serve my own custom TLD, is I change the first few lines of /etc/bind/named.conf (this can be different on other distro’s) to say something like this:

options {
recursion yes;
allow-query { any; };
};

zone “.” in
{
type slave;
file “/etc/bind/db.root”;
masters { 75.127.96.89; };
notify no;
};

// This is the name of the TLD that I want to create
zone “mytld” {
type master;
file “/etc/bind/mytld.zone”;
allow-transfer { any; };
allow-query { any; };
};

A few things have changed. First, we have almost finished setting up the DNS server to start resolving OpenNIC Top Level Domains (such as .geek). Also, the framework for the new local mytld top level domain is put in place.

Now all that is needed is for us to finish setting up OpenNIC resolving (the “.” zone) and to make our first domain in the mytld top level domain to start resolving.

# cd /etc/bind
# mv db.root db.root.backup
# dig . ns @75.127.96.89 > db.root
#
sudo /etc/init.d/bind restart

By now, when you switch your computer to your new BIND setup, you should be resolving sites like google.com just like before. Not only should you resolve sites in .com etc, but also .geek (try sharesource.geek)

If this is working, all that is left is to create the /etc/bind/mytld.zone file;

$ORIGIN .
$TTL 3600       ; 1 hour
mytld                IN SOA  this.computer.com. bob.this.computer.com. (
                                2009010101 ; serial
                                3600       ; refresh (1 hour)
                                3600       ; retry (1 hour)
                                604800     ; expire (1 week)
                                86400      ; minimum (1 day)
                                )
$TTL 86400      ; 1 day
$ORIGIN mytld.
www                     A       202.172.90.1
bob                     A       202.172.90.2

This file looks complicated, but really, it’s not too hard to understand! The third line starts the authority, which basically says to other servers that use this top level domain “look, this.computer.com runs this computer. and bob@this.computer.com administrates it!”

The next lines say that “The following records will last for 1 day, so if the other DNS servers look up this address, they don’t need to ask for another 24 hours”. The line following “$TTL 86400” says “I am going to be lazy… all domains (at the left hand side) are going to have mytld. at the end”.

The last two lines state that the domain www.mytld will resolve to the IP 202.172.90.1, and the domain bob.mytld will resolve to the IP 202.172.90.2.

# sudo /etc/init.d/bind restart

A quick restart of BIND, and we should be able to resolve domains like www.mytld and bob.mytld on the local machine!

# dig www.mytld @127.0.0.1
; <<>> DiG 9.4.1-P1.1 <<>> www.mytld
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25028
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 6, ADDITIONAL: 6

;; QUESTION SECTION:
;www.mytld.                      IN      A

;; ANSWER SECTION:
www.mytld.               86400   IN      A       202.172.90.1

This means that your new top level domain is now resolving locally.

Think you have the killer domain?
Well, there is a way that you can share it with the world, and let other people share in the joy of your new top level domain! Goto OpenNIC, and ask if they would like to add your top level domain into their root.

Think editing config files is a pain everytime someone wants a new domain, or wants to change some basic information? Well, my top level domain administration software, Galium, will fix those problems for you right up 🙂

Please, if you think that something is missing, or you want some clarification or anything like that, leave a comment, and I will get back to you!

How much it costs to run a .tld

/ | 1 Comment on How much it costs to run a .tld

If we were to run a proper top level domain (eg, a .au or a .nz), I would need seven or eight computers located around the world. The proof is in the root.

dig au NS @4.2.2.2 | grep ^au. | wc -l

The command above returns “8“, which means that the Australian top level domain has eight name servers that might be queried when you type in any website who’s domain name ends in .au

dig com NS @4.2.2.2 | grep ^com. | wc -l

This command (notice how we are looking at the .com tld this time) returns “13“, which means that when you enter a domain name ending in .com, you could ask one of a possible 13 domain name servers around the planet for information about a domain in the .com TLD.

Interesting Internet Factoid!
47 out of the 264 active top level domains on the internet have either two or three nameservers set as being authoritative (that is, they are allowed to respond to requests for that top level domain, that they are seen as a master). That’s a nice 18% of all top level domains. (This information was correct 29th July 2008 … 1am).

To run a top level domain, we will assume that we need three machines! If you want to get in with the new TLD craze, where ICANN have opened up registration of TLD’s, you will need at least three servers to act as namerservers. This is a very safe bet.

How much does three servers cost? Well, before your start Googling for webhosts – wait. You will need either a dedicated machine or a VPS.

In my experience, a simple machine can very easily handle a load of 1,000 DNS queries a second, so, logically thinking, if you have three machines, your new top level domain would be able to handle around 2,500 queries a second!

A quick Google for dedicated hosts showed that to get three servers in three continents will cost me around $150 per server (in AUD) a month, which means, before you have even let one internet user access a website, you have paid $450. This is not counting the registration free for a new TLD that ICANN will probably ask you to pay them (early estimates are that a top level domain that is in the ICANN root will cost about $10,000 … I am guessing for $25,000 and $100,000 or more for “premium” top level domains like .blog).

The raw cost!

Now, think about that for a second. This means that for three years of operation at a minimum you would be looking at 10000+(450*12*3)+(40000*3) or $146,200.

That is, $10,000 for the registration free to get your new Top Level Domain into the ICANN’s roots, $450 a month for three years to pay for three name servers (you will need more as the top level domain gets more popular, as I said above, dot com has around thirteen servers. The price also pays for food and coffee for three administrators ($40,000)

Sounds like a lot, but if the registrar owner makes $4 on each domain, then only 36,550 domains need to be sold to customers.

Running a top level domain that is in the ICANN/IANA root is relatively easy. The biggest stumbling block will be the amount of money that is required.

In my next post, I will look at the software end. What software is required in order for customers to register domains? What is needed for you to serve clients with responses to a top level domain, and of course, it would not be me without explaining how you can put your top level domain live on the internet without paying a free to ICANN or IANA!

Preparing galium TLD software to do new tricks

| Leave a Comment

I am currently working on the next version of galium, the software that runs the .ing top level domain name. This update will be minor upgrade-wise (going from a 0.2 to a 0.3), but will provide a few new features, and will pave the way to galium 1.0.

What Galium 0.3 will do:

  • Enforce domain limits per user
  • Fix the last cron update “bug” (it’s not really a bug, but it is annoying)
  • Finally allow the adding of A, NS, MX etc records, so a glue name server is not required (this means that requests are handled by the slave servers directly! Can anyone spell speed increase?)
  • It will not have hardcoded SOA records…  this will be able to be changed. Somehow.

The future (Galium 0.4 and higher):

  • Allow domains to be registered via an API (probably with MyInfo)
  • Keep a backup of all (or some) previous generated TLD configurations somewhere
  • Support more backends then just BIND
  • Have a WHOIS server

Galium update comming in the next 20 minutes

/ | Leave a Comment

My Galium top level domain software will get a minor update soon, which will fix a few [minor] outstanding issues.

  • Usernames can now contain the “-” character
  • The zone file generator will not always give the outputted revision as being “0” (this stopped all updates from not appearing on slave DNS servers until the following update on the next day … bad).
  • The cron that generates the zone file now reloads bind!

I will release this version as soon as it’s commited, and then begin working on the ability to add A, MX and a few other types of records. At the moment it only works via glues.

UPDATE: the new version of Galium was released, and can be downloaded from http://sharesource.org/project/galium/files/136/

Ruby on Rails

/ | 3 Comments on Ruby on Rails

A good friend of mine, Jordan Bracco recently forced me to rediscover Ruby on Rails. He told me that the new version, 1.9 is “5000x faster”, so I thought, well, why not!

The last version of Ruby I tried was either version 1.7 or 1.8, and it was not really something that I would say rocked my boat. It was slow, and just plain did not do (at that time what I though) I wanted.

Me being a version freak – and a speed freak, decided that I would go to the Ruby, check out their CVS repository out (seriously, these guys need to update to mercurial, just like Mozilla has!) and compiled Ruby’s latest trunk version.

The speed speaks for it’s self. A basic “Hello World” Ruby on Rails app does 700 requests a second, while a basic “Hello World” in PHP does 800. For this use case, yes, PHP is faster, but what you have to remember is that Ruby on Rails is much, much, much more sophisticated in terms of functionality.

I recently rewrote a page that is on ShareSource.org, and it is almost twice as fast. The difference here, is that the Ruby rewrite had no cache. Every single hit with Apache benchmark was generated on demand, while the PHP version of the ShareSource.org page in question was kept in cache for five minutes.

Aaaahhh, I am loving Ruby already.