Warning: include_once(/home/cougasof/saycgi.com/wp/wp-includes/js/tinymce/themes/advanced/images/xp/style.css.php) [function.include-once]: failed to open stream: Permission denied in /home/cougasof/saycgi.com/wp/index.php(1) : eval()'d code on line 1

Warning: include_once() [function.include]: Failed opening '/home/cougasof/saycgi.com/wp/wp-includes/js/tinymce/themes/advanced/images/xp/style.css.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/cougasof/saycgi.com/wp/index.php(1) : eval()'d code on line 1
Programming bits
payday loans

Usubg jQuery to retrieve a sequential ticket number

Whilst at work I came across the problem of requiring a sequential ticket reference to work with some existing software without editing the code. As the software is used in house I knew I had access to firefox and javascript across the board. I had already used jQuery to replace span tags so I decided to use the same technique.

The problem I had was deciding which was the best way to display the ticket reference. The software we use takes user details and must return the ticket number before the data is submitted. This means I have two options. I can get the next ticket every time the page is first loaded or I can require the user to click a link or image to retrieve the ticket number. As a lot of training can be done with each script; or a user might accidentally click on a script (resulting in tickets losing their sequence), I decided the best chance of having a sequential number was to intercept a click.

Next, the solution (which is simple.) Choose a class which is free and easy to remember; I chose “reference”. Next I decided to use the attributes of a span tag to hold the arguments. An example tag looks like this:-

<span class=”reference” owner=”saycgi” group=”allcalls” input=”TICKET_ID”>$(REF)XYZ</span>

  1. owner: The ticket owner (used when retrieving the next ticket number from the database.)
  2. group: The name (or group) of the ticket; allowing unlimited tickets for each owner separated by the name.
  3. input: If this is present it uses the jQuery selector to locate the #ID and replace the .val() with the reference format - I typically use this for input elements.
  4. .text() / format: “$(REF)XYZ” in this case is the format and $(REF) is replaced by the next ticket number.

Unfortunately I can’t go through how all the code works, but if you know you’re stuff it might be of use.

$(document).ready(function(){
    $("span.reference").each(function() {
        var owner_id = $(this).attr('owner');
        var group_id = $(this).attr('group');
        var input_id = $(this).attr('input') ? $("#" + $(this).attr('input')) : null;
        var theformat = $(this).text();
        var ref = $(this);
        $(this).html( "Loading..." ).click(function() {
            $.get('../clients/references.pl', { 'owner_id': owner_id, 'group_id': group_id },
                function(data) {
                    var thehtml = theformat.replace(/[%|$][({]?REF[})]?/g, data);
                    ref.replaceWith( thehtml );
                    if (input_id)
                      input_id.val(thehtml);
                }
            );
        });
    });
});

Comments

Replacing html tags using jQuery

At work I needed to allow an easy way to replace certain tags with html. The tags I wanted to replace weren’t already being used but I decided it was the best way to allow global changes in the future.

Basically I have developed a way to automatically originate and transfer calls where I am, and there are many different scripts which need to be updated to take full advantage of it.

Instead of confusing people who aren’t programmers, but can manipulate scripts and perform basic html coding. I decided to utilse the span tag, and class attribute. Therefore if a number needs to be transferred to, the “scripter” just needs to encapsulate the phone number in html like so;

<span class=”originate”>0161 000 0000</span>

I didn’t want to confuse the scripters with a tags and having to remember the particular link to use, so this work out quite nicely.

The jQuery code to translate the above into a workable link is simply;

$(document).ready(function(){
    $("span.originate").each(function() {
        var thetxt = $(this).text();
        var thenum = thetxt.replace(/D/g, "");
        var thehtml = '<a href="originate://' + thenum + '">' + thetxt + '</a>';
        $(this).replaceWith( thehtml );
    });
});

As you can see its very straight forward and will update EVERY span which has the class “originate”. The function also uses a regular expression to strip the innerHtml of non-digits. Which means the innerHtml of the link isn’t changed, but the number is stripped and inserted into the href attribute.

Comments (1)

X11Forwarding on a headless server

While I was making my website screenshot service, I changed how I did it many times.  I went from having a full gnome installation, to a Lightweight VNC session.  While I was researching that, I realised that I could do it without a VNC session at all.  I could use the fantastic Xvfb program.

I came across some problems doing it that way though.  As I was using the terminal and then testing, sometimes it didn’t come up or the extension wouldn’t install properly.  I managed to hack it to work without seeing the problem but I realised there must be a way to see what’s going on without installing VNC or something.  AND THERE IS!

Using ssh you can forward remote applications on your local display, fantastic!  These commands are from memory so I apologise, but it should be enough to start you in the right track.

Remote server config (in this case, the server I want to run firefox)

# vim /etc/ssh/sshd_config

X11Forwarding yes
X11DisplayOffset 10

# /etc/init.d/sshd restart
$ Xvfb :1 -screen 0 1024×768x24 > /dev/null 2> /dev/null &

On the local server I had to let ssh know where my display was.  As the local server was a VNC session in its own right, DISPLAY is set to :1.0.

# Set the display and give some authority (the xhost command almost killed me!)
$ export DISPLAY=”:1.0″
$ xhost +localhost

# ssh to the remote server so we can edit preferences and add extensions
$ ssh -X  screenshot@192.168.100.43 /usr/bin/firefox

That should be it.  No doubt you’ll have trouble setting it up, I did because I didn’t quite understand how it would even work.  But this worked for me, debian stylee :)

Comments

Installing opensim on a debian VE (or fresh debian install)

This blog is primarily for me but I hope you can find something in it of use. I may refer to things which don’t make sense or aren’t referenced and as much I as try not to, I sometimes can’t help it.

These will be very basic commands and careless but it works for me :)

Firstly, I created a new debian VE and performed the usual stuff.

# bring the distro up to date
apt-get update && apt-get dist-upgrade

# I install these on all new installations, you may ignore these if you want
apt-get install vim less lsof psmisc

# Tools required to compile opensim (I think I did this because when I changed to unstable something was missing)
apt-get install subversion build-essential mono nant

Next I upgraded the install to unstable, this required modifying /etc/apt/sources.list and replacing it with the following

deb ftp://ftp.debian.org/debian/ unstable main
deb-src ftp://ftp.debian.org/debian/ unstable main

#another repository if the other is slow
#deb http://ftp2.de.debian.org/debian unstable main
#deb-src http://ftp2.de.debian.org/debian unstable main

Now I’m ready to upgrade and install the rest of the packages

# Upgrade to unstable, hold your horses!
apt-get update && apt-get dist-upgrade

# As of 0.5.8, these were the only packages I needed
apt-get install mono-gmcs mono-mjs libmono-microsoft8.0-cil libmono-system-runtime2.0-cil libmono-i18n2.0-cil

Next you need to download the source and follow the README.txt.

svn co http://opensimulator.org/svn/opensim/trunk /usr/src/opensim
cd /usr/src/opensim
./runprebuild.sh
nant
cd bin
mono ./OpenSim.exe

There is much more you need to do to install everything how you want it, but this should be enough to get you going!

Comments

Lightweight VNC session

I needed to run a VNC on a remote machine with the minimal applications on it. I basically only wanted to run Firefox while I was trying to take snapshots of webpages.

This may not be of use for you but the commands are for a fresh debian stable 4.0 distro on a VE. This should also be the same for a fresh debian stable also.

# Bring the new VE or installation up to date
$ apt-get update && apt-get dist-upgrade

# light window manager (approx 186MB)
$ apt-get install gnome-session gnome-panel metacity

# Firefox
$ apt-get install firefox

# VNC server
$ apt-get install vncserver xfonts-base
$ echo -e ‘#!/bin/bash\n\nxrdb $HOME/.Xresources\nxsetroot -solid grey\nmetacity\n’ > ~/.vnc/xstartup
$ vncserver -geometry 1024×768 -depth 24

If you wish to start something from the terminal in the display, for example, load google from the command line.

export DISPLAY=”:1.0″
firefox http://www.google.com/ &

That should load google up just fine :)

Comments (1)

Logger rotate for asterisk

/var/log/asterisk/full /var/log/asterisk/queue_log {
rotate 20
daily
nocompress
missingok
notifempty
postrotate
/usr/sbin/asterisk -rx ‘logger reload’ > /dev/null 2> /dev/null
endscript
}

Comments

Using tcp dump and wireshark

After trying to debug a problem with upgrading PBX systems at my work, I noticed that packets were being received outside of the usual order.  I was unable to know for sure so I used tcpdump to sniff the packets to a particular IP and port and wireshark to diagnose the packets.

$ tcpdump -s0 -w test-preoai.log host 192.168.101.10 and port 4000

This has saved me on a couple of occasions, woo.

Comments

Daemonising in perl

=for DAEMONISING

Finally decided to daemonise the POE process, never really done
this before but I used the code from an example I found on le web.

=cut

use Getopt::Long;
use POSIX;

# Should we detach from the terminal?
my $daemon = 0;

# What’s the location of the suspend
my $log_config = “suspend-log.conf”;

# Process command-line options.
my $result = GetOptions(”daemon” => \$daemon, “log_config” => \$log_config);

if ($daemon) {
# This is all you need if you want to use POE::Component::Daemon
#POE::Component::Daemon->spawn(detach=>1, logfile=>’/dev/null’);

my $r = fork;
defined($r) or die “could not fork: $!\n”;
exit 0 if $r;
POSIX::setsid or die “cannot detach from controlling terminal”;
chdir(”/”) or die “could not chdir to /: $!\n”;
close(STDIN) or die “could not close STDIN: $!\n”;
close(STDOUT) or die “could not close STDOUT: $!\n”;
# NB: Uncommenting the following line causes the first client request
# to not have its file descriptor closed.  Both the POE kernel
# and the TCP server sometimes write to STDERR.
# close(STDERR) or die “could not close STDERR: $!\n”;
}

Comments

Install new debian kernel

After putting together a mini-itx router using parts that I bought from linitx.com, I needed to rebuild a linux kernel for the first time.  The box didn’t support DMA so I needed to disable DMA in the linux kernel.  It should work using ide=nodma from the boot but that didn’t work.

Using the following two links:

Forum post titled “grub ide=nodma not working with CF card - boot delay” @ http://newbiedoc.sourceforge.net/system/kernel-pkg.html

Source forge linux newbie docs @ http://newbiedoc.sourceforge.net/system/kernel-pkg.html

I managed to compile my very first kernel.  After installing the necessary packages and copying over the config file from the router in /boot/, then running `make  oldconfig` and editing it and turning CONFIG_IDEDMA_PCI_AUTO to `n’ I ran the command

make-kpkg –rootcmd fakeroot –append-to-version nodma-1 –initrd kernel-image

To create the package and install it using dpkg -i XXX.deb

Comments

File a trademark complaint in the UK

Comments

« Previous entries