Wednesday, January 25, 2006

MySQL FULLTEXT searching

I want users to be able to search the website for content but the way I've done this in the past sucked as it was using the user's input then checking:

where field1 like '%input%' or field2 like '%input'

This isn't efficient as a user may enter, for example 'abba money money' and the returning MySQL relults will be empty as neither field1 or field2 would contain both the artist and title of an item, I need a way the user's data can be well and truly searched.... I need FULLTEXT searching.

ALTER TABLE TABLENAME ADD FULLTEXT(cell,cell);

Once I'd queried that to all the tables so they were setup to run a fulltext search on both the cells I needed to run the full the full MySQL to get the results:

SELECT cell,celcell,MATCH (cell,cell) AGAINST ('SEARCHTERM') AS score
FROM TABLENAME WHERE MATCH (cell,cell) AGAINST ('SEARHTERM')
ORDER by score DESC

It works, spanking :)

Tuesday, January 24, 2006

URL Rewriting with .htaccess

.htaccess rocks. it enables the true voodoo magick of the internet in my opinion.

Here's a couple of good reference guides for anyone wanting to spice up their site by making file.php?var1=foo&var2=bar look like foo-bar.html their browser:

http://corz.org/serv/tricks/htaccess.php
http://corz.org/serv/tricks/htaccess2.php

First things first, I don't want people hotlinking to the images on the website. We put an end to that by adding this to our .htaccess file

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mobtex\.net/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule \.(jpg|jpeg|gif|bmp|png)$ gif_icons/mobtex-site-logo.gif [L]

If you want to check this works then there is a hotlink prevention checky thing here and an ok tutorial about hotlink prevention here though watch out if you cut and paste there are ] characters missing on the end of some statements.

Someone on a forum I found while doing a Google wrote this great post on .htaccess rewriting.

RewriteRule ^(.*)/(.*)/(.*)-([0-9][0-9][0-9][0-9][0-9][0-9]*).* display-content.php?code=$4

The line above is a direct cut and paste from my .htaccess so any requests in the format of /artist/title/track/library-id/ will now direct through to display-content.php?code=id

However, this means that you could change the ID value in the URL and end up with conflicting data on the page, example, the URL says http://www.mobtex.net/john-lennon/imagine/full-track-download-100123/ but if we changed 100123 to 101010 the page would say Beverly Knight.............

So I knocked up a little PHP to sort it out (get_hyperlink is a function to make a full URL from a product's ID code)

$uri = getenv('REQUEST_URI');
if(get_hyperlink($code)!="http://www.mobtex.net$uri"){
$link = get_hyperlink($code);
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: '.$link);
exit;
}

Nice, now the URL's can't be screwed and shouldn't confuse the robots and spiders.
Not just that, it looks better too.

Sunday, January 22, 2006

Alexa Screenshots

I want to link to the sites of the artists who's tracks we have on the website but I want to do something more funky looking than a standard text link, I still want the text links as the anchor text and related URL can be a powerful friend to us in persuading Google our site's cool.

I want screenshots, just like those you see over on Alexa and DNS Report (who get them from Alexa) when you run a check on a site. Yet, when I checked the database for realtones there's over 800 distinct artists I'd have to go through manually, then check the link, then check Alexa for a screenshot, right click, save as and then upload. Screw that, too much work. Let's script it instead with PHP. I know I could link direct to the images on Alexa but then if they didn't have a screenshot of the site in question it would show the default image which would make the site look sloppy.

First, we select each distinct artist from the database, then foreach result we do the following:

Remove any spaces and make the string lowercase

strtolower(ereg_replace(" ","","$artist"))

add .com to the end of the variable that gets returned

Now I want to check the screenshot exists

$screenshot = file_get_contents("$screenshoturl");

That will return the data of the file in a string

We now compare this against a screenshot we saved earlier that says 'coming soon'
If there is not a match we simply write the image to a file.

That's it in a nutshell really. The directory you want to store the image in must be writable otherwise it will not work.

I've run the script on polyphonic ringtones, realtone ringtones, full track downloads and the mobile phone karaoke so that each artist stands a chance of getting a screenshot if we can find a matching URL image from Alexa.

I now have a collection of 1,277 screenshots and have thought about running the script that does this on a cron job but really the updates aren't going to be that big so I might as well just run it manually whenever I think it needs it.

Friday, January 20, 2006

IP to Country

I want to be able to work out the country the visitor is in so that I can pre-propagate some hidden form fields and maybe show a flag on the website, it's also handy for internal stats tracking and a plethora of other goodies.

It appears that the original IP 2 Country website www.webhosting.info is down at least for me today it is so I've had to use a different site> www.32tech.com I've downlaod the free zip, extracted it, changed the name of the table from ip2country to IP2COUNTRY as I want all my MySQL table names in upper case (yes I know it's anal) to conform to the new in-house style.

Once that had finished the find and replace I uploaded it through phpMyAdmin and a couple of minutes later the tables were setup and propagated with data.

I also want the flags to go with this as mentioned. Best place for these that I've found is flags.blogpotato.de so I've downloaded the flags, loaded them onto the server and unpackaged them. You can download the zip I used here.

Now to start really playing with the data as I want much more than just the ISO value country code..................

So I've added an extra field to the table now called 'dial' this will be for the international dialing code of that country.

Now to get the data and import it somehow.

I've just spent half an hour scouring around the net to find a decent list of numbers from countries, I wanted something with the ISO country codes too but from what I feel now there's not one.

I had to make my own..... Painful. Based on a distinct country value from the MySQL then hand filled with the data.......

AFGHANISTAN#93
ALBANIA#355
ALGERIA#213
ANDORRA#376
ANGOLA#244
ANTIGUA AND BARBUDA#1268
ARGENTINA#54
ARMENIA#374
AUSTRALIA#61
AUSTRIA#43
AZERBAIJAN#994
BAHAMAS#1242
BAHRAIN#973
BANGLADESH#880
BARBADOS#1246
BELARUS#375
BELGIUM#32
BELIZE#501
BENIN#229
BERMUDA#1441
BHUTAN#975
BOLIVIA#591
BOSNIA AND HERZEGOVINA#387
BOTSWANA#267
BRAZIL#55
BRUNEI DARUSSALAM#673
BULGARIA#359
BURKINA FASO#226
BURUNDI#257
CAMBODIA#855
CAMEROON#237
CANADA#1
CAPE VERDE#238
CAYMAN ISLANDS#1345
CENTRAL AFRICAN REPUBLIC#236
CHAD#235
CHILE#56
CHINA#86
COLOMBIA#57
COMOROS#269
CONGO#242
CONGO, Democratic Republic of#243
COOK ISLANDS#682
COSTA RICA#506
COTE D-IVOIRE#225
CROATIA#385
CUBA#53
CYPRUS#357
CZECH REPUBLIC#420
DENMARK#45
DJIBOUTI#253
DOMINICAN REPUBLIC#1809
EAST TIMOR#670
ECUADOR#593
EGYPT#20
EL SALVADOR#503
EQUATORIAL GUINEA#240
ERITREA#291
ESTONIA#372
ETHIOPIA#251
FALKLAND ISLANDS (MALVINAS)#500
FAROE ISLANDS#298
FIJI#679
FINLAND#358
FRANCE#33
FRENCH POLYNESIA#689
GABON#241
GAMBIA#220
GEORGIA#995
GERMANY#49
GHANA#233
GIBRALTAR#350
GREECE#30
GREENLAND#299
GRENADA#1473
GUADELOUPE#590
GUAM#1671
GUATEMALA#502
GUINEA#224
GUINEA-BISSAU#245
HAITI#509
HOLY SEE (VATICAN CITY STATE)#379
HONDURAS#504
HONG KONG#852
HUNGARY#36
ICELAND#354
INDIA#91
INDONESIA#62
IRAQ#964
IRELAND#353
ISLAMIC REPUBLIC OF IRAN#98
ISRAEL#972
ITALY#39
JAMAICA#1876
JAPAN#81
JORDAN#962
KAZAKHSTAN#7
KENYA#254
KIRIBATI#86
KOREA#850
KUWAIT#965
KYRGYZSTAN#996
LAO#856
LATVIA#371
LEBANON#961
LESOTHO#266
LIBERIA#231
LIBYAN ARAB JAMAHIRIYA#218
LIECHTENSTEIN#423
LITHUANIA#370
LUXEMBOURG#352
MACAO, CHINA#853
MACEDONIA#389
MADAGASCAR#261
MALAWI#265
MALAYSIA#60
MALDIVES#690
MALI#223
MALTA#356
MARTINIQUE#596
MAURITANIA#222
MAURITIUS#230
MEXICO#52
MONACO#377
MONGOLIA#976
MOROCCO#212
MOZAMBIQUE#258
MYANMAR#95
NAMIBIA#264
NAURU#674
NEPAL#977
NETHERLANDS#31
NETHERLANDS ANTILLES#599
NEW CALEDONIA#687
NEW ZEALAND#64
NICARAGUA#505
NIGER#227
NIGERIA#234
NORTHERN MARIANA ISLANDS#1670
NORWAY#47
OMAN#968
PAKISTAN#92
PALAU#680
PALESTINIAN#970
PANAMA#507
PAPUA NEW GUINEA#675
PARAGUAY#595
PERU#51
PHILIPPINES#63
POLAND#48
PORTUGAL#351
PUERTO RICO#1787
QATAR#974
REPUBLIC OF KOREA#82
REPUBLIC OF MOLDOVA#373
REUNION#262
ROMANIA#40
RUSSIAN FEDERATION#7
RWANDA#250
SAMOA#685
SAN MARINO#378
SAO TOME AND PRINCIPE#239
SAUDI ARABIA#966
SENEGAL#221
SERBIA AND MONTENEGRO#381
SEYCHELLES#248
SIERRA LEONE#232
SINGAPORE#65
SLOVAKIA#421
SLOVENIA#386
SOLOMON ISLANDS#677
SOMALIA#252
SOUTH AFRICA#27
SPAIN#34
SRI LANKA#94
SUDAN#249
SURINAME#597
SWAZILAND#268
SWEDEN#46
SWITZERLAND#41
SYRIAN ARAB REPUBLIC#963
TAIWAN#886
TAJIKISTAN#992
THAILAND#66
TOGO#228
TONGA#676
TRINIDAD AND TOBAGO#1868
TUNISIA#216
TURKEY#90
TURKMENISTAN#993
TUVALU#688
UGANDA#256
UKRAINE#380
UNITED ARAB EMIRATES#971
UNITED KINGDOM#44
UNITED REPUBLIC OF TANZANIA#255
UNITED STATES#1
URUGUAY#598
UZBEKISTAN#598
VANUATU#678
VENEZUELA#58
VIET NAM#84
VIRGIN ISLANDS BRITISH#1284
YEMEN#697
ZAMBIA#260
ZIMBABWE#263


Now I'll bang this in a text file, read it with PHP then explode via the hash and update the tables with the variables we have. Sorted, and it is! ;)

Thursday, January 19, 2006

GD Library Manipulation

The blog has simmered down a little since last week, not because I've been sitting on my arse doing nothing, far from it, I've now got quite a library of mobile content to work with. I've been busy and I want to be able to keep track on the size of the library.

Rather then writing the results here it's better if I make a quick PHP script to render the number of items in each library, realtones, polyphonics and so on, inside a graphic I can call on the site, on the blog or even view it on my mobile phone.

The render an image in PHP the main requirement is GD Library which is Open Source software that does all sors of wonderful things with images through PHP.

GD Library is written by Boutelle and really is the nads and thankfully WHM has an easy install option which I took full advantage of so I didn't have to arse around with tars and recompiling etc.....

What's involved:
  1. Setup MySQL connection
  2. Create array on table names
  3. Foreach value query count
  4. Setup image headers
  5. Echo results
This is what we're after:



This is how we get it:

Start with the headers we need to echo out so the browser knows to understand what we're giving it, I want a gif that the browser can't cache and must revisit with each request so it's always fresh:

header( "Content-type: image/gif");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

Next we set the image dimensions foreground and background colours:

$image = imagecreate(150,74);
$foreground = ImageColorAllocate($image,0x00,0x00,0x00);
$transparent = ImageColorAllocate($image,0xFA,0xFA,0xFA);
ImageColorTransparent($image,$transparent);
ImageFilledRectangle($image,0,0,150,744,$transparent);

We need a height variable as the loop we're about to run needs to tell the image where within it's dimensions the line it is about to make should go:

$height = "02";

// setup an array of table names to query
$tables = array("BLAH","BLAH");

// loop begin
foreach($tables as $table){

Assuming that all tables have the same cell formatting:

// query and retuen
$total = mysql_query("SELECT count(code) FROM $table");
$total = mysql_result($total,0);

// add that to the data string
ImageString($image,2,2,$height, "$table: $total",$foreground);

// increment the height variable so the next line is okay and written on top of the last one....
$height = $height + 12;

// loop end
}

// do it baby
imagepng($image);

There. That's one sorted, another funky thing I want from GD is the ability to verify anyone submitting a form is a human and not a robot. It's just sessions, GD and a form which reads and compares the session, it's name is Turing Symbol Verification. This is a hack from Planet Source Code's repository.

A nice quick hack to the original script and I had it doing what I wanted it to do and in the colours I wanted too. Thanks to the guy who wrote it who's website is now going through to seeq.com

As a quick afterthought I also wanted to know how many items we had in stock in total, right now on the first day of counting there's over 16,000 which isn't too bad a starting point for a mobile media company who's so new we've not built the website for customers to buy from yet!

Content Storage Structure


This is the content storage structure we're using.
content_files is outside the public_html directory so all content is stored away from the world wide web.

Each product library has it's own directory and within each content library folder is a folder for each relevant file type, inside the sub-directories are the files, all with a numbered value filename which would then tie up with the MySQL database tables we've put together.

FULLTRACK

full - mp3 format
preview -mp3 format

KARAOKE

full - 3gp video clip
preview - 3gp format preview

MOANTONES

amr - amw narrow band
awb - amr wide band
mp3 - mp3 format
wav - wave format

POLYPHONIC

mid - sp-midi scalable polyphony midi format
mmf - smaf mmf format
mp3 - mp3 format

REALTONES

amr - amw narrow band
awb - amr wide band
mmf - smaf mmf format
mp3 - mp3 format
wav - wave format

VIDEOTONES

3gp - 3gp wap preview
avi -avi web preview
cab - cab pocket pc format
sis - symbian installer

Wednesday, January 18, 2006

Mozilla Extensions


Thunderbird and Firefox extensions. I'd quite like to create my own one day but till then here's a list of all the Mozilla Extensions I'm running. Some of these are way cool.

Thunderbird

Mail User Agent Extension 1.2

Firefox

PDF Download
IE View
Google Toolbar
Skype Toolbar
Add N Edit Cookies
Firefox Showcase 0.5.5
CustomizeGoogle 0.40
DNS Stuff Toolbar
Foxy Tunes

Monday, January 16, 2006

Configuring MIME types

I need to tell the server to add MIME types for the following files: .amr .awb .mmf .mid .3gp .sis .cab and .wav - normally I would just VI into the .htaccess in the public_html directory of the site I want to deploy these from but I might want to save myself a job in the future if I ever decide to rent server space to mobile media producers or if I want to deploy them from another website so this time I'm going to add them to the main HTTP conf file.

Some time back I wrote a post on Dev Shed's WAP Forum (where I'm one of the moderators) with a list of the most common WAP based mime types. Now the actual generation of the WAP sites will be done through WURFL and WALL so I don't need to configure anything other than the file types:

## polyphonic and realtone mmf
AddType application/vnd.smaf .mmf

## realtone amr and awb
AddType audio/amr .amr
AddType audio/amr-wb awb

## varients of midi for polyphonic
AddType audio/midi .mid
AddType audio/midi .midi
AddType audio/sp-midi .mid

## mp3 and wav for realtones
AddType audio/mpeg .mp3
AddType audio/x-mpeg .mp3
AddType audio/x-wav .wav

## video ringtones for symbian and pocket pc
AddType application/vnd.symbian.install sis
AddType application/octet-stream cab

## video and audio clips in 3gp
AddType video/3gpp 3gp
AddType audio/3gpp 3gp

## process .m3u files as php so they can be dynamic
AddType application/x-httpd-php .m3u

Once I had cut and pasted that into into my httpd.conf I restarted HTTPD on the server and bingo. All sorted.

More info on /htaccess etc can be found here.

Friday, January 13, 2006

MCPS and PRS Licences


Right I've finally gone and done it, I have now completed the application process for a MCPS and PRS Ringtone Licence and I've paid the bill before they sent it. £587.88 inc VAT to MCPS as a setup, then £267.88 inc VAT to PRS as the first quarters payment.

As it stands today, I have no content that I could deploy, no payment mechanisms so bearing in mind it will take me time to get things sorted out, content contracts in place, content loaded by FTP the imported onto the new platform, plus I need to get my Bango and Text Anywhere integrations rolling I have requested the licence commence on April 1st 2006.

Now all I need to do is get some content and start selling it to make some money.

Wednesday, January 11, 2006

Immobilise Phone Crime


Having just got a new mobile phone today I want to make sure it's registered with the Police in the same way as you could get your push bike stamped with your postcode by a copper when you were a kid. www.immobilise.com

I met someone from Immobilise some time back at an event in London and I thought the idea was worth something, you register your handset's IMEI number with the Police and if your phone ever goes missing then turns up in a theiving chav bastard's posession you can get it back.

The site sucks in Fire Fox though. Why don't more of the authorities put more effort into their websites and make them better on more browsers.

You need to enter the handsets IMEI number and can get this by tapping *#06# on your phone. That's the hard bit reading something from such a small screen, now I am registered and the website has given me the most wank username and password combination. Still my new phone is listed so job done.

I've gone i-Mode


It's big in Japan and it's been here a few weeks now, I was keen to find out what it's like, what it does and what I can do with it. Plus the phone I was using was owned by the old company I was with so I needed to get my own.

O2 have the NEC 343i available on PAYG for £49.99 - you can get one on Amazon for a tenner less but then you can't go and swear at the people in the store if it goes Pete Tong, nor can you go and pick it up today, neiher can you smile and ask what range of numbers are available so you can pick.

Cutting a long story short, I went into Loughborough and got one today. It's charging up right now and I'll not do anything with it till it's fully done but it'll be interesting to see what i-Mode is really like. CHTML on my platform will be output from WALL via the WURFL and at last I have a cellphone to demo it with!

Is i-Mode great or pooh? I dunno yet but will update once I can make a decision on it.

Now, a day later and I've just added a forward on all Mobtex emails to come through to my i-mode email account, this rocks, I like it so far, I don't need to configure any email stuff like I would if I wanted my pop3 account to talk to a Blackberry as it just pushes them to me, for free, well at least till the end of March when the free i-mode offer expires.

The only bug I've found in the i-mode email system so far is that my address is 07999778405@o2imail.co.uk which to Spam Assasin is a black point as it's numbers and no mane, so it's possible that many emails from i-mode devices are labelled wrongly as spam. To counteract this I have added my mobile email address to the Spam Assasin whitelist so it now comes through unflagged.

Tuesday, January 10, 2006

Tiny MCE Text Editor

This is a sweet little thing based on java script and thankfully it's standards compliant so the website will be able to validate as XHTML 1.1 and use this too as a tool to enhance user experience. Plus I need a nice simple well documented interface to the content management platform I'm about to put togeher.

It's really similar to the post screen here at blogger.com and is used on the Mambo / Joomla Open Source project which is where I first came across it.

What is Tiny MCE?

TinyMCE is a platform independent web based Javascript HTML WYSIWYG editor control released as Open Source under LGPL by Moxiecode Systems AB. It has the ability to convert HTML TEXTAREA fields or other HTML elements to editor instances. TinyMCE is very easy to integrate into other CMS systems.

The Moxicode documentation says the install is easy. I've heard it a million times before and this time it's true!

http://kent.dl.sourceforge.net/sourceforge/tinymce/tinymce_2_0_1.tgz

Then into SSH:

cd public_html
wget http://kent.dl.sourceforge.net/sourceforge/tinymce/tinymce_2_0_1.tgz

gzip -d tinymce_2_0_1.tgz
tar xvf tinymce_2_0_1.tar

Then call in the browser and it works, wonderful stuff!

http://www.mobtex.net/tinymce/examples/


So simple, thanks Moxicode!

Clicky

Backup MX Records


I've used No-IP's desktop client in the past so I could remote desktop into my PC from another PC as long as both were connected to the net and opened up to allow it. It's a free download and at the time I did wonder how they made any money. Today I delved into DNS even deeper and started looking into Backup MX Records, so if my mailserver was to go down the DNS would know to reroute my email to another server to hold for seven days. Then once my mailserver is back online the backup mailserver will post all the emails through to me.

Sounds okay in principle but what's involved?

http://www.no-ip.info/

$29.95 per domain per year.

Signup was simple, payment was painless and an email confirmed the order within seconds, now to get this thing working...

Here we go, back into WHM and under DNS Functions, Edit DNS Zone, mobtex.net

We add this to the zone:

mobtex.net. 14400 in MX mail1.no-ip.info.
mobtex.net. 14400 in MX mail2.no-ip.info.

Then restart Bind. Yesterday's perfect DNS Report came up with a warning today about only having one MX Record, now if I've set this up right we should have three MX Records and I should never miss an email.

Monday, January 09, 2006

E-Commerce Law

I needed contracts and found Compact Law who offer legal documents for download and customise for £81.00 - the E-Commerce Pack they offer covers affiliate linking agreements, developer terms, a privacy policy that complies with the Data Protection Act, hosting agreements and a terms of sale which covers Distance Selling Regulations and more.

SmartPhone Emulator

This bit of software rocks, it's the nearest thing you'll get to testing your online mobile applications without having a huge collection of cellphones.

After having just installed WALL4PHP which uses the WURFL to empower an abscraction library called WALL I wanted to know it worked.

Yospace have a great SmartPhone Emulator - it costs around 2-300 for the full key but the five minute trial is enough for me to find out if everything is sorted.


It works, I'm chuffed, gotta blank canvas and the tools to really do some stuff funky now!

WURFL and WALL

WURFL = Wireless Universal Resource File

I discovered the WURFL a long time back, it was some XML thing that ran on Java and I knew by that point I was lost. It knew a lot of information about mobile phones, screen size, colours used, support for Digital Rights Management and much much more but I didn't have a clue about XML or Java back then so I never took it any further.

A few weeks back I found WURLF again and having moved on a lot as a developer was more game for the challenge of XML and Java, then I learnt about WALL4PHP - not only had I moved on but so had this WURFLthing.

WALL4PHP uses the WURFL to generate WALL templates with PHP, my language of choice. :)

By using the WALL abstraction library I can generate the right output markup language for the mobile device accessing the script. In other words, naff old phones will get WML, better phones will get XHTML - Mobile Profile and i-Mode phones will get CHTML, plus there's tonnes more funky stuff you can do with it to enhance the end user experience.

Let's load this thing!

http://laacz.lv/dev/Wall/Wall4PHP-1.0beta2.tar.gz

Plus we'll need the most up to date version of the WURFL

http://www.nusho.it/wurfl/dl.php?t=d&f=wurfl.zip

Now I've got copies of both the newest WURFL and WALL4PHP I need to backup the original XML file with all the phone data and replace it with the new one I just downloaded.

Quote from the install guide to WALL4PHP:

Unpack downloaded archive. Copy file Wall.php and directory Wall to somewhere in PHP include path. Open file wall_prepend.php in Your favorite code editor. Make appropriate changes. Allow webserver's user to write into DATADIR. See WALL reference Guide, sample files, which are provided with this archive, and You are on!

Since I'd added the latest WURFL to WALL4PHP I needed to repackage it us as a zip and load it on the server. Once there I SSH'd to the right directory I could unzip it:

mobtex@mobtex.net [~/public_html]# unzip wall4php.zip

Wow, I love the unzip utility, you need your box compiling with it though but WHM users can do this easily enough.

mobtex@mobtex.net [~/public_html]# cd wall4php
mobtex@mobtex.net [~/public_html/wall4php]# ls
./ ../ changelog.txt examples/ Wall/ Wall.php wall_prepend.php wurfl/
mobtex@mobtex.net [~/public_html/wall4php]# cd wurfl
mobtex@mobtex.net [~/public_html/wall4php/wurfl]# ls
./ check_wurfl.php readme.txt wurfl_class.php wurfl_parser.php
../ data/ update_cache.php wurfl_config.php

I to apply a CHMOD of 777 to /data and all the files within and we should be on our way?

http://www.mobtex.net/wall4php/examples/

Oh yes! But how would that render on a load of different devices? I need an emulator.

Secondary Nameservers

In order to get a clean bill of DNS health I needed secondary nameservers, after a quick Google an AdWord stood out and I found nettica.com who can provide secondary nameservers for me for $10.00 a year.

I needed to log into my Go Daddy account and add two new nameservers to mobtex.net

dns2.nettica.com (64.237.45.34)
dns4.nettica.com (69.41.170.223)

Once those were added I needed to tell our server that dns2 and dns4.nettica.com were acting as remote nameservers for us, this was done in WHM under Zone editing, once they were updated I restarted Bind then added the following to /etc/named.conf under the options ()

// allow transfers to Nettica's DNS servers
allow-transfer { 64.237.45.34; 69.41.170.223; };

All the info I needed to do this was on the Nettica FAQ's. It was nice to do business with them, all automated, only $10.00 a year most importantly, if works. Next year I'll do the $40.00 option and get a 'for life' deal through them. Stunning. If only everything else on the net was as efficient and cost effective.....

Once named.conf had been saved I restarted Bind again then went for a cuppa and returned to run a DNS Report again, this time there were slight differences in TTL and DNS versions but a quick edit, restart and wait.

Finally everything came together and resulted in the thing that I wanted to get out of all of this.

A perfect DNS Report.

ICSTIS Compliance

The aim is to setup and maintain a series of services for mobile phones, such as:

Video Ringtones
Polyphonic Ringtones

Realtone Ringtones
Full Audio Tracks
Karaoke 3gp Videos

Mainly music based content so I will require both PRS and MCPS licenses before I can trade, right now though while things are still in the planning stage I want to make sure that the services I am about to launch are all going to comply with the regulations set out by ICSTIS.

I tried to call and get through to Applications but no joy so I've emailed a quick outline to Nazia Khan there who deals with the setting up of new services, her email does nothing but bounce after 24 hours.........

I know I have to comply with the Code of Practice and Guideline 12 to cover Pay-For-Product Services but asked if there's anything else I need to be aware of before I launch.

After no reply to emails which ultimately bounced on me I took it into my own hands and rang to speak to someone else, I will not legally be classed as a Service Provider as it isn't me who has the connections into networks, nor is it me who runs the billing platform. I'm just an information provider in the eyes of ICSTIS.

I can send over links to the website and any offline advertising I run to the ICSTIS copy clearence department but as it stands right now I have no need to apply for a licence through them to trade.

Saturday, January 07, 2006

FTP Configuration

I was inspired by the goings on with SSH earlier on and thought I should setup the FTP the way I need it as there are a few things I want to change. How many people can FTP into the server, how many from one IP and the number of files we'll list in a directory.

root@server [/]# vi /etc/pure-ftpd.conf

To change the number of simultanious users and users from the same ip on the box find the lines:

MaxClientsNumber 50
MaxClientsPerIP 8

Change 50 and 8 to whatever you see fit.

Now it bugs me when I'm doing a command line FTP session and need to piss, make a coffee or go for a smoke and by the time I've come back the session has ended and I need to log back in again. Chore, no not if you set find this line:

MaxIdelTime 15

And change 15 to 45. Now you have long enough to make a coffee, run to the toilet and have a smoke without being booted. Bonus.

Another thing with FTP that gets to me, it's basic limit is to show 2000 files in a directory then just hide the rest, this is a pain if you're dealing with thousands and thousands of items as you just can't manage them through FTP, to overcome this just find this line:

LimitRecursion 2000 8

2000 is the limit to the number of files it will list, you might only see 1998 though as . and .. are not shown. 8 is the limit as to how deep down the folder tree it will recurse.

These are the little twaeks that cPanel can't help you with so you need to muck in and get you hands dirty to sort it.

SSH Security

I just got the first email from our server telling me that there had been loads and loads and loads of username and password attemps to get access through SSH.

Best thing to do here is change the port it runs on. SSH normally runs on Port 22 so all requests for access would automatically fail if SSH were only to be deployed via another port. Example: 1234

Here's how I did it on our Red Hat Enterprise Linux box:

root@server [/]# cd /etc/ssh/
root@server [/etc/ssh]# vi sshd_config

Scroll down till you find the line that reads:
#Port 22

Then remove the # and change 22 to the port you want to run SSH on.

I also want to make sure that anyone who does log onto our server by SSH gets a standard Welcome message from us, something to say we're watching you kinda thing so while I'm inside sshd_config I might as well kill two birds with one stone......

Scroll down till you find this section:

# no default banner path

Then upload the text file you want to use to show your welcome message, then create a line in your sshd_conf that looks like this but references the location of the file on your server.

Banner /home/mobtex/etc/ssh-welcome.txt

Then save that and restart SSH:

root@server [/etc/ssh]# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
root@server [/etc/ssh]#

Log out and try to log in again on port 22, you should not be able to. It should come up as "Network error, connection refused."

Change the port you are accessing to the correct port, first of all Putty is likely to mention keys but accept that, the server will then promt you for your login once you enter that you should get the welcome message from the text file!

Mine now reads:

login as: root
Mobtex Limited - SSH
We know you are here

root@67.15.221.30's password:

Next thing, I want an email each time someone logs in as Root, it should only ever be me so I'll most likely get pissed with an email each time I do login but If I can get it to work it's another little tweak I'll be happy with.

root@server [~]# cd /root
root@server [~]# vi .bashrc

Then I added this line:

echo 'ALERT - Root Shell Access (server.mobtex.net) on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" info@mobtex.net

Now, each time root logs into the server I will get an email letting me know about it.

While we're on the subject of SSH here's a nice little tool to SSH into your kit. Putty.

Friday, January 06, 2006

DNS Issues

The newly setup server was having a few DNS issues. The server had been configured with one IP, I'd requested two more for nameservers and one for HTTP requests.

First was a look at WHM to see if there was anything that stood out, I looked under Basic cPanel WHM Setup and checked the nameservers and the hostname were okay
.

I was checking DNS records when I saw a duff nameserver, once that had been removed all the records looked right so I restarted Named and after two minutes all worked.

ns1.mobtex.net
ns2.mobtex.net
server.mobtex.net
ftp.mobtex.net
mail.mobtex.net

www.mobtex.net
and
https://www.mobtex.net

Next thing it's falling over again. www.dnsreport.com told me that the only Warn was on the nameservers not being on seperate class C's, understandable but the only thing that came up with a warning was the SPF records which I added to the zone file for the domain.

www. on 80 and 443 go down so does mail but ns1, ns2 and server are all fine. When it's down www.dnsreport.com comes back with a failure on the mail server, it really does seem to be an intermittant fault . It's setup okay so why?

I submitted a ticket and 14 minutes later the issue had been sorted so it seemed, it was a case of having individual zonefiles for the nameservers when they should have been setup on the mobtex.net zone file. Also, the resolve.conf was updated to use the DNS resolvers of EV1.

Still up and down though.

According to EV1 the .150 and .151 IP addresses aren't mine to take and there's been a conflict. Seems like it's bugger all to do with zonefiles but an IP conflict instead.

Problem fully diagnosed and at last a solution.

Now I'm not playing victim but this was a glitch at EV1 which assigned me IP's that were already in use. EV1's problem and not mine yet it's kick on effect is the loss of time which could have been better spent getting the architecture and development of the company underway.

This is the new total range of IP's we're using:

67.15.221.30 (server.mobtex.net)
67.15.221.149 (ns1.mobtex.net)
67.15.221.188 (www.mobtex.net)
67.15.221.189 (ns2.mobtex.net)
67.15.221.190/1 (not-used)

Go Daddy's Domain Host Summary record has been updated for ns2. and now things are working a lot slicker. I still want to get things tighter as a ship but things are resolving.

; Modified by Web Host Manager
; Zone File for mobtex.net
$TTL 14400
@ 86400 IN SOA ns1.mobtex.net. info.mobtex.net. (
2006010804
7200
7200
1209600
86400
)

mobtex.net. 86400 IN NS ns1.mobtex.net.
mobtex.net. 86400 IN NS ns2.mobtex.net.

mobtex.net. 14400 IN A 67.15.221.188

localhost.mobtex.net. 14400 IN A 127.0.0.1

mobtex.net. 14400 IN MX 0 mobtex.net.

mail 14400 IN CNAME mobtex.net.
www 14400 IN CNAME mobtex.net.
ftp 14400 IN CNAME mobtex.net.
server 14400 IN A 67.15.221.30
ns1 14400 IN A 67.15.221.149
ns2 14400 IN A 67.15.221.189

mobtex.net. 14400 IN TXT "v=spf1 ip4: 67.15.221.188 a mx"
localhost 14400 IN A 127.0.0.1
*.mobtex.net. 14400 IN A 67.15.221.188

I just want to get server aliasing sorted now so any browser calls to ns1. ns2. server. localhost. *. all use the /home/mobtex directory to call the page from. No more of those nonky looking cPanel 'no website' pages and instead just a unified Mobtex brand.

Thursday, January 05, 2006

Skype Rocks

My Skype is mobtex if you want to get in touch. If you don't use Skype you can call me on

UK 0208 123 5543

which is actually a Skype In number so will come through to me on my PC.

I love Skype it's great stuff and I've even got Skype Out for cheaper calls than what normal telecoms companies charge. At long last a 100 year old business model is shattered beyond repair, based on call duration and distance between callers the old phone giants must be reworking business models to compensate for VOIP. Free global telephony. That's spanking.



The image above is is based on Jyve Inc's Skype Web Plugin which integrates with my Skype and shows the results as an image online.

I've developed a modification to this to allow PHP developers to return their Skype status as a standard variable. I wrote this in a little spell of free time last year and in reality it's nothing more than a file_get_contents call to read the image from the Jyve website then run a comparison against a local copy of the image till there is a match.

Anyway, here's the code made nice in function and switch form:

function skype_status($skypename)
{

// first of all make reference to the image on skypepresence.com
$statusfile = "http://www.skypepresence.com/callbutton/$skypename.gif";


// now make reference to the images you have stored locally
$onlinefile = "http://www.mobtex.net/gif_icons/skype_icons/skype-online.gif";

$offlinefile = "http://www.mobtex.net/gif_icons/skype_icons/skype-offline.gif";
$awayfile = "http://www.mobtex.net/gif_icons/skype_icons/skype-away.gif";
$skypemefile = "http://www.mobtex.net/gif_icons/skype_icons/skype-me.gif";
$nafile = "http://www.mobtex.net/gif_icons/skype_icons/skype-na.gif";
$dndfile = "http://www.mobtex.net/gif_icons/skype_icons/skype-dnd.gif";
$oncallfile = "http://www.mobtex.net/gif_icons/skype_icons/skype-call.gif";

// we no initiate the switch to do the match checking
switch (file_get_contents($statusfile)) {


case file_get_contents($onlinefile):

$status = "Online";
break;

case file_get_contents($offlinefile):

$status = "Offline";
break;

case file_get_contents($awayfile):

$status = "Away";
break;

case file_get_contents($skypemefile):

$status = "Skype Me";
break;

case file_get_contents($nafile):

$status = "Unavailable";
break;

case file_get_contents($dndfile):

$status = "Don't Disturb";
break;

case file_get_contents($oncallfile):

$status = "On a call";
break;

}


// and return the status
return "$status";

}

Simple, yet fab. You do need to use the Jyve plugin as mentioned earlier plus you also need to make sure the copies of the images you store to do the checking are from the same Jyve image set, small, large etc so they do tie up.

Other than that enjoy.

SSL Certificate

Things be a moving now in the right direction and I need to make sure the website is secure for any forms or pages that I don't want to be parsed via standard Port 80 but rather through Port 443 for SSL Secure HTTPS.

I decided to use Go Daddy again to get the certificate from, I had one from there when I was with the other company a few months ago and the setup went really well. Yet again it was simple enough, setting up an SSL Certificate just requires a little patience and the ability to follow instructions and cut and paste. I'm gobsmacked that the first SSL certificate I ever got cost me £300, I sold it to a client for £500 and it took a week to setup and get running. Today I've setup a dedicated server with custom nameservers and secure certificate for less than that.

Thankfully times change and prices get better so I can't grumble at paying $29.95 a year for a SSL Certificate and having it setup within 20 minutes.

Dedicated Server


Now I have the domain names I need somewhere for them to live, there are two options in the US that I could use and one in the UK which seemed viable till I learnt they're control panel sucks so bad it blows. It at least narowed the choice down to The Planet and EV1 Servers I've had servers from both in the past and both seem good. I've admin'd a P2800S at The Planet and a cheap as chips $119 a month box from EV1 Servers.

For this purpose I needed a small yet scalable box with two x 80 gb hard drives, 1 gb RAM, 100 mbps pipe to connect it to the internet and a shed load of data thrown in.

The best box for budget that I could find ended up being a Celeron 2.00 from EV1 Servers running cPanel on Linux Red Hat Enterprise. I know the OS having had three boxes with it in the past. I like what I know and did the business online today. I'm blown away by EV1 Servers the box was sitting in a rack just waiting for me to order so it could go live that moment, the box was running within two minutes of my order going through, ID was requested as I'm in the UK and they needed a scan of my passport to make sure I'm who I say I am, one phone call later (they rang me) and my order had been fully confirmed and sorted.

For anyone in the position of setting up a new RHE box for the first time with custom nameservers here's what I did to get it working.

First time login as root to myip:2086 presented me with a first run form, just go through it and don't set anything really at first as the chances are you'll need to add IP addresses to your box before you can continue to set your nameservers up.

Once the first run had been completed and the server knew the email addresses etc to use I logged into Server Control, the Control Panel software for EV1 Servers' dedicated server clients and requested three IP addresses, I need two for the custom nameservers plus another so that I can run a SSL certificate on the main site and also call it via IP for API purposes in the browser.

Within ten minutes, the order had been confirmed and the IP addresses were provisioned for me to use. I then logged back into Web Host Manager and hit the IP Addresses tab from the X themed front page. Then Add a new IP Address whereby I entered the IP numbers that had been assigned.

Once the box had accepted them I went to the Server Configuration tab and then into Basic cPanel / WHM setup. Once there I entered ns1.mobtex.net and ns2.mobtex.net into the Primary and Secondary nameserver form fields, I then clicked Assign IP address which took the first available IP from the pool and assigned it to each nameserver. Then it was just a case of asking WHM to add the A entry for the NS then save that screen and let BIND do it's restart and the machine was setup to work as a nameserver in the background.

Now the hardware was ready I needed to get the actual DNS side of things sorted through Go Daddy which was done by logging in and selecting the domain name I wanted to first Unlock so I could then set the nameservers up Once the domain was unlocked I went under the Domain Host Summary tab and entered ns1.mobtex.net and ns2.mobtex.net with the IP addresses I wanted and saved the data. Once that was done I locked the domain again to make sure it's safe and can't be tampered with.

While waiting for the DNS to propagate I logged back into WHM and created the hosting account for mobtex.net within a cuppa and a smoke it had done it's stuff and I got the default Apache directory listing page for that account. Now I could get to grips with stuff like the creation of email accounts, MySQL and much funkier stuff that is to come.