Log in
06
October

Overlay boxes are poping up all over the place now, the most common use ive seen is to display a bigger version of an image when you click on a thumbnail.

They arent hard to create, all you need is 2 or 3 divs and a few lines of javascript, for a basic one. There are obviously much more complicated ones that resize themselves etc… when they open. This one just appears when you click a link and disappears when you click on close.

So first off lets create the div tags.

At the top of your page (just after the <body> tags)



You also need to add a couple of styles to your css:

.overlay{
	position:absolute;
	left:0px;
	top:0px;
	width:100%;
	height:100%;
	text-align:center;
	z-index:1000;
	opacity:0.6;
	filter:alpha(opacity=60);
	background-color:#000000;
}
.overlay-box{
	position:absolute;
	margin-top:50px;
	margin-left:23%;
	z-index:1001;
	width:50%;
	background-color:#FFFFFF;
	border:8px solid #000000;
	padding:15px;
	max-width:50%;
	overflow:auto;
	text-align:center;
}

There are few things in that css id like to explain before we go on.

Setting the z-index attribute to 1000 means that the overlay appears infront of all the other divs etc… on the page. Setting it to 1001 for the box means that the box appears infront of the overlay. The overlay is basically and big black rectangle that covers the entire page, and because we have set the opacity and the alpha filter it has some transparrency, so you can still see the site behind it.

So you now need some javascript to make it appear and disappear. Instead of writing “show()” and “hide()” Ive written one function that swaps the state of the overlay.

function overlay(id){
	var div = document.getElementById("overlay");
	var box = document.getElementById("overlay-box");
	var cont = document.getElementById(id);
	if(div.style.display == "block"){
		div.style.display="none";
		box.style.display="none";
	}else{
		div.style.display="block";
		box.style.display="block";
		box.innerHTML = cont.innerHTML;
	}
}

This is where this box becomes re-usable. instead of writing your content into the “overlay-id” div you write into any div you want and hide that div, you then pass its id into the function.

Simply create a link to “javascript:overlay(‘myid’);” and it will bring up the overlay. You can close the overlay by clicking anywhere in the black. You could also put the same link into the content, this would close the box.

11
September

Progress on Train

Written by Arcath. No comments Posted in: Programming, Train
Tagged with , ,

In a previous post I mentioned that Arcath.net was now using Train, my new RoR CMS.

Well I think now is a good time for a progress report.

I am picking up RoR quite quickly (it helps that i already knew ruby). Im not getting stuck when making new controllers etc… so development is speeding up :D . Feature wise Train currently has:

I am currently working on the forums and hope to have something resembeling forums working in the not to distant future.

02
September

Last Nights Downtime

Written by Arcath. No comments Posted in: Server
Tagged with ,

We had a power cut here last night that lasted too long for the UPS powering whitefall to keep it on, so it turned off. Now normally i would just turn it back on and all would be fine. But not today :( . I knew that Arch would probabbly want to perform a HDD scan because of the 150 days scince its last boot, so braced my self for an age of scanning whilst all 2.5TB was scanned. So i pulled the plug fitted a graphics card an brought it into work to fix.

I was right it wanted to scan all the disks, normally this is okay and it scans fine but again not today. my backup drive (for the main company server) was corrupt apparently. After a while manually scanning all the partitions to find the problem i narrowed it down to /dev/sdb1. After a while i gave up trying to repair the corrupted HDD, the data existed on the company server so formatting it wouldnt be a problem. So i set the scan flag to 0 in /etc/fstab and it then proceeded to boot no problem at all.

Once the server was on and working i decided to have a look at the drive, mounted it no problems to its mount point and so far havent discovered any problems with it.

I also took this oppoutunity to do some upgrades to the cooling system. This bascially meant spreading the hard drives out a bit and mounting one with arms in a 5.25″ bay. I then attached a fan to blanking plates and made a hole for air flow, that HDD now has dedicated cooling. Because it lives in a loft space i was concered about the fan siezing up (like the old HDD one) so i fashioned a fan grill from the facia of an old pc. I have also replaced the old HDD fan with one that spins. So whitefall now looks a bit different

Whitefall (On its Side)

Whitefall (On its Side)

31
August

Arcath.net Now using Train

Written by Arcath. No comments Posted in: Programming, Train
Tagged with , , , ,

My main website Arcath.net has now swapped to using Train. It is on the “cutting edge” of Train, in so much as it is Train. What you see there is Train up to the last time i touched restart.txt to have passenger re-load the app.

For more information please head over to the site, thats where im posting all the little train annoucements for now.

13
August

Recent Downtime

Written by Arcath. 1 comment Posted in: Server
Tagged with , ,

This was one of those annoying downtimes where it wasnt because the internet was down or there was a power cut. There was actually something wrong with Whitefall!

The downtime started some time wednesday after a mysql update, i didnt notice untill friday because on thursday i went down to i37, and checking my server wasnt on my agenda. i got back on monday and began to look at the problem, after countless fixes failed i started to think dark thoughts about formatting it. And then when checking the system uptime on phpsysinfo i noticed that / had 0.0Kb left on it :S after i cleared the 3.5GB Pacman Cache and re ran mysqld_safe and mysqld_upgrade it all worked fine, proven by this blog working.

I await your messages of Fail

21
July

Train

Written by Arcath. No comments Posted in: Train
Tagged with , , , ,

Ive begun my next big project! Id like to say its my summer project, but im going to be working over summer and when im not im either going to be in a tent in the lake district or at i37 so writing ruby code will be a litle hard (although i do have an inverter for my car so i could charge my netbook whilst camping :p). I also intend to this be an ongoing project that i never finish (aka never reach a final version, just multiple stable ones).

So Step 1 The Name (Dilbert referance there)

Train

The reasoning behind this name becomes rather obvious when Ruby on Rails is mentioned (*ducks* from the obvious slaps)

My main aim with Train is to make a CMS that is is simple enough for any end user to pick up and make a website with, but yet be simple on a code front so anyone with ruby/rails knowledge can make changes and tweak it to thier own liking. This would mainly take the form of custom pages (I got rather annoyed at Drupal for not letting me create my own php code for a page).

The Ruby on Rails part is for 3 reasons:

Ive started work on it, but i dont know how long it will be before i decide to setup mod_rails and let you all see its progress. I will commit its source to GitHub at the same time so anyone can pull it down.

06
July

I have looked at Ruby on Rails in the pas, but hit brck walls when it came to running it with apache.

I recenelty came across something called Phusion Passenger (mod_rails). This lets you run rails inside apache! so its bound by all you apache rules. simply create a rails site in your usual place and create a vhost (has to have its own vhost)

I Suppose the best plase to start is with install ruby + rails.

sudo pacman -S ruby rubygams
sudo gem install rails

There you go! you now have rails installed, and can now develop rails apps and hpst them. the problem is that it usesits own webserver app and defaults to port 3000. So if like i do you have apache running with a few websites hosted on the server (this blog for example), you want your rails apps to run within apache. This is where mod_rails comes in. Install Passenger via ruby gems:

sudo gem install passenger

Then setup the apache module

sudo passenger-install-apache2-module

and it will give you 3 lines to add to your httpd.conf, just place them after all the “LoadModule” lines. You then have to create a VirtualHost for your rails app. In this example i have an app in /a/rails/app and i want www.example.com to use it.

<VirtualHost *>
ServerName www.example.com
DocumentRoot /a/rails/app/public
</
VirtualHost>

And thats it! You now have a rails app running at www.example.com!

Something you will notice is that your app wont update itself (wierd i know) if you change the source an old version seems to still exist somewhere and thats whats used. If you:

touch tmp/restart.txt

In the root of your rails app it will allways use the latest source

Well this is a special post:

This is a printer script i wrote to replace a script some else had written for one of the schools i work in, his script was a big, HOOOOGE case statement that ran of host name, e.g.

pc1 -> printer 1
pc2 -> printer 1 & 2
pc3 -> printer 1 & 2

This to the end user works exactly the same as the new script, but from my point of view the new script is allot better.

When the user logs in the script looks at the host name and then asks Active Directory where that computer is in its orginsational Structure. This means that if i move a PC in active directory the printers it gets change. You can tell how much better that is already, instead of having to rewite its case the new script just changes it for me.

So then its time to post the script:

'Printer Script based on AD Group
'Written by Adam Laycock (Arcath)
'July 2009

'Variables

Set WshNetwork = WScript.CreateObject("WScript.Network")

Set oPrinters = WshNetwork.EnumPrinterConnections

printServer = "SERVERNAME" 'Set this to the machine that is your Print Server

DefaultColourPrinter = "\PRINTERNAME" 'The Main Colour Printer

DefaultBWPrinter = "\PRINTERNAME" 'The Main Black and White Printer

'Functions

'Get First Match
'Returns the First REGEX Match for the pattern you supply
'from http://www.somacon.com/p138.php
Function GetFirstMatch(PatternToMatch, StringToSearch)
	Dim regEx, CurrentMatch, CurrentMatches

	Set regEx = New RegExp
	regEx.Pattern = PatternToMatch
	regEx.IgnoreCase = True
	regEx.Global = True
	regEx.MultiLine = True
	Set CurrentMatches = regEx.Execute(StringToSearch)

	GetFirstMatch = ""
	If CurrentMatches.Count >= 1 Then
		Set CurrentMatch = CurrentMatches(0)
		If CurrentMatch.SubMatches.Count >= 1 Then
			GetFirstMatch = CurrentMatch.SubMatches(0)
		End If
	End If
	Set regEx = Nothing
End Function

'Remove all the Network Printers from the Machine
For i = 0 to oPrinters.Count - 1 Step 2

            On Error Resume Next

	    if Left(oPrinters.Item(i), 3) <> "lpt" And Left(oPrinters.Item(i), 3) <> "usb" then

             	WshNetwork.RemovePrinterConnection oPrinters.Item(i+1), true, true

            else WScript.Echo "No network printers found"

            end if

Next

'Connect to AD
Set objSysInfo = CreateObject("ADSystemInfo")

'Get LDAP entry to current computer object.
strComputerDN = objSysInfo.ComputerName
Set objComputer = GetObject("LDAP://" & strComputerDN)

strOU = GetFirstMatch("OU=(.*?),OU=", strComputerDN)

Select Case (LCase(strOU))
	'For Each OU make a Case
	'note that the OU Name is made to be all lower case
	case "room1"
		WshNetwork.AddWindowsPrinterConnection "\\" & printServer & DefaultColourPrinter
 		WshNetwork.SetDefaultPrinter "\\" & printServer & DefaultColourPrinter
	case "room2"
		WshNetwork.AddWindowsPrinterConnection "\\" & printServer & DefaultBWPrinter
		WshNetwork.AddWindowsPrinterConnection "\\" & printServer & DefaultColourPrinter
 		WshNetwork.SetDefaultPrinter "\\" & printServer & DefaultBWPrinter
End Select

and now an explination

First off it declares all its variables and creates some objects, can you tell i wrote this to be used in more than 1 place?

It then declares 1 function. This comes from http://www.somacon.com/p138.php and is basically a find the first hit to a regex string funtion. I had never done any regex in VBS and thier function does exactly what i need.

Then comes some actual printer management. It starts by removing all the connections to network printers that the machine has. This way the machine only gets the printers that you want it to (other than any connected by a cable to it).

This is followed by making a connection to active directory to get the AD String for the machine. An example of this is “CN=pc1,OU=Room1,OU=Site,DC=Arcath,DC=NET” This is then passed into the function i mentioned earlier and the first OU is returned, in this case “Room1″.

It then has a case statement where you place a case for each OU, in each case simply place the code for a simple printer script.

15
June

HsDB Class for Ruby

Written by Arcath. 1 comment Posted in: Programming
Tagged with

In a previous post i mentioned that i was going to write a database interface that the new bot would use, and here it is:

require 'mysql'

class HsDB
	def initialize(dbhost,dbuser,dbpass,dbname)
		@dbc=Mysql::new(dbhost,dbuser,dbpass,dbname)
	end
	def query(q)
		out=[]
		out[0]=0
		qa=q.split(" ")
		query=""
		qa.each do |a|
			if query != "" then
				query+="AND "
			end
			query+="`record` LIKE '%#{a}%' "
		end
		res=@dbc.query("SELECT * FROM `records` WHERE #{query}")
		res.each do |row|
			out[0]+=1
			out.push(row[1])
		end
		return out
	end
	def add(record)
		@dbc.query("INSERT INTO `records` (`record`) VALUES ('#{record}')")
	end
	def remove(q)
		qa=self.query(q)
		if qa[0] == 1 then
			@dbc.query("DELETE FROM `records` WHERE `record` = '#{qa[1]}'")
			out=0
		else
			out=qa[0]
		end
		return out
	end
end

There are 4 methods to this class.

Initialize

This is the standard creation method in ruby, it is used in the this case to create the database connection “@dbc” using the ruby-mysql class, i will dig up the link and post it in a comment later.

Query

Of the 4 this is by far the most important. It searches the the database for “q”. To make the database searcher come up with more results, and more importantly similar results it searches for records that contain each word that the user searches for. This is even more precise than the database searcher i described before. It works using WORD1 and WORD2 etc… this means that the user can refine the search by adding more words.

The output is an array, the array contains the results aswell as a count of the results (held in array[0]) This means that any program using the class can easily tell how many results there are.

Add

This adds to the database, rather simple, it just inserts “record” into the database

Remove

This removes from the database, it uses the same query syntax as “query”, ive limited it to only deleting records when the query returns 1 result, didnt want some one using the bot to delete all records with an “a” in for example.

Thats about it simply require the class and the ruby mysql

13
June

Anyone who has poped into our IRC Channel (#whitefall on freenode) will have noticed that theres a new name thats allways there, “Beylix”. This is yet another bot, i know this is yet another bot, but i hope unlike the others ive made it wont just dis appear from use.

The underlying IRC Class is the same one i wrote for “Verbend”, and was used in “Silverhold”. Ive chosen not to re-write it for a few simple reasons:

  1. It works
  2. it covers all the bases (join, leave, whois) aswell as some little extras that where added for some of “Silverholds” advanced functions.
  3. The main focus of this bot was to completely re-write its parsing functions.

So its parsing, I decided that for it to be noticeably better it would have to read human input, instead of using strict syntax, for example the old bot used “!time” as the command to return the time. This new bot reads what the user has typed to see if it contained the question “what is the time?”, and if it detects this it then returns the time.

It still uses command like syntax for maths. “~ 1+1″ will return “> 2″, but this was the only way to really “secure” the maths command. Because the maths is evaled it needs to be secured in some way to stop accidentally harmful code being evaled. I do heavily restrict the code, it is run in a new process thread so it cant effect the root program, and that thread is restricted to ruby safe level 4. I also restrict the words that can go in e.g. “sleep = no”. Its also limited to on 1 second execution time.

But the big thing (the title piece of this article) is the database searching, “Silverhold” was the first bot to use a mysql database to store its data. My problem was that when someone asked it about a topic its ability to find similar topics was serverly limited. I understand now how hard it is to make search algorithms for mysql databases. Id rather not create a keyword table so that it can find them, the main problem with that is that the user(s) have to supply the keywords. I personally would rather have it simply search the article and work out the results. SO ive been thinking about how to make it so that it can work like that.

“Silverhold” stored data by holding the Item in one table and then inf facts for an item in another. This meant that the user searches for an item and then it recounts all the facts it has for that item. I want “Constance” to seach more by fact, no item. So if it had 5 facts of:

  1. The Sky is blue
  2. The Sea looks blue
  3. Blue is a colour
  4. Red is a colour
  5. Colour is made of light

Then i want the query “blue” should return 1,2,3 and the query “colour” 3,4. This could be done by using LIKE and then i need to come up with a big rule for the inputs. so “What is blue” or “Who is blue” but then it does need to ignore all requests for data that obviosuly arent for it e.g. “What is that?”.

This has turned into a really waffely post, so im gonna go write the program to do this and post the results later.