Blue Coat CPL Syntax Highlighting vim

October 24th, 2008

For those of you who need syntax highlighting in vim/gvim for Blue Coat CPL I have written one covering most of the keywords and methods used by CPL. These can be found at http://www.phpandmore.org/cpl.vim

This will be constantly updated read release notes below

Note: This is the first syntax highlighting file I have done and I found a starting base for this vim file on the Blue Coat forums.

If you have any features/problems leave a comment and I will see what I can do.

Install:

Download & Install vim for you favorite OS.

Save the cpl.vim file in the <VIM runtime directory>/syntax/ or save it to the default syntax directory on Linux using precompiled it would be <installprefix>/share/vim/vim72/syntax/ once the file is in there edit <installprefix>share/vim/vim72/filetype.vim where vim72 is the vim version you are running and add:

” CPL
au BufNewFile,BufRead *.cpl setf cpl

Underneath

” Perl POD
au BufNewFile,BufRead *.pod setf pod

If you are on Windows the above steps are the same except the file path is different default install DIR for vim on Windows is %ProgramFiles%\Vim\

Now that is done once you open up a CPL file with the extension .cpl you should now have colors provided :syntax on is set. This can be done in either the vimrc file in your runtime or in the global vimrc file.

If you still have issues leave a comment and I will see what I can do

Releases

24th October 2008 - First Release fixed minor highlighting bugs

Written By: Michael Baker (michael.baker [at] diversit.com.au)

Web: http://www.diversit.com.au/

AXFR DNS Query

August 9th, 2008

I have recently been looking at the use of AXFR across my own domain names as I was migrating DNS. I have since thought ‘oh this used to work on everything lets see if it still does’. First shot I done was the new .me TLD (host -l me.). This was now showing me a list of every .me domain registered along with there name servers. Next attempt .org once again it works. AXFR can be used in alot of cases to map a company’s DNS eg. Where all the services are ect..  You should always disable zone transfers on ANY DNS Server this could lead to potential security risks. Take for example we have a domain name test.com and we have routers ect.. behind this no one knows the IP’s of them you create router.test.com AXFR is enabled people then see your router’s ip which could lead to potential security risks. And can consume alot of bandwidth :)

See below for an example of stopping this with BIND

options {
   allow-transfer {"none";};
};

Australian Post Code Geo Database

June 24th, 2008

Here is some code and the SQL required to do searching based on Post Code it will give you distances between post codes, Suburbs close by, All suburbs with that post code, Distance between 2 post codes / long & lat, Give you the post code for the specified suburb. The PHP code can be found: here The SQL for MySQL can be found: here This code requires PHP 5 with PDO Support.

Update :)

I have now made 2 versions 1 for PHP4 and another for PHP5 neither require PDO they use the native MySQL library for PHP See link below

PHP5 : Native MySQL version

PHP4 : Native MySQL version

Note the above 2 have not been tested if you have any issues let me know.

Update:

Do not use tools what are browser based as this is a massive SQL Dump it will most likely time out uploading. Use a MySQL console by mysql -u USERNAME -p DATABASE < import.sql or a 3rd party app such as SqlYog

Half done YoutubeAPI

April 29th, 2008

Youtube PHP

If anyone is up for finishing it off just a few checks need to be made to see if an array has a SimpleXML Object and if it does convert it to an array.

This has all the REST API calls already implemented all you need to test each one is a Youtube API key.

This will only work under PHP 5 :)

Also finish the documenting. Any questions leave a comment

Namespacing much similar to Perl’s in PHP

April 23rd, 2008

Namepsacing in PHP is very handy at times why use require/include :) When you can have simply.

<?php

use foo::bar;

$blah = new bar();

?>

See below for an example any questions leave a comment

?Download template.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
Example:
index.php
<?php
$template = new Template("test.php");
$template->ParseTemplate();
?>
test.php should be in modules/ and contain the following
<?php
use some::blah;
$blah = new blah();
?>
 
now create some/blah.php containing the following
<?php
class blah {
public function __construct() {
echo "namespacing in the works!";
}
}
?>
Namepspacing in pure php..
@author Michael Baker
*/
class Template {
 
public $_incpath = "/home";
public $tempdir = "/tmp";
 
/**
* Initate the Templating class ready for our name spacing
* @param $template string The module name eg. module.php
* @throws IO Errors
* @access public
*/
public function __construct($template) {
$this->contents = "";
if(file_exists("modules/$template")) {
$this->contents = file("modules/$template");
}
else {
throw new Exception('Fatal Error: <b>Template not found</b>');
exit;
}
}
/**
* ParseTemplate - Parse the template and do perl style namespacing on the script
* This will do a require_once once complete with the new code :)
* @throws IO Errors
* @access public
*/
public function ParseTemplate() {
foreach($this->contents as $line) {
if(preg_match("/use (?<dir>\w+)::(?<module>\w+)/", $line, $matches)) {
if(isset($matches['dir']) && isset($matches['module'])) {
if(file_exists($this->_incpath.'/'.$matches['dir'].'/'.$matches['module'].".php")) {
$line = "require_once('".$this->_incpath.'/'.$matches['dir'].'/'.$matches['module'].".php);";
}
else {
throw new Exception("Fatal Error: <b>Module {$matches['dir']}/{$matches['module']}.php not found</b>");
exit;
 
}
}
}
$this->_output .= $line;
}
$file = md5(time());
$handle = @fopen("/tmp/".$file.".php", "a");
if(!$handle) {
throw new Exception("Fatal Error: <b>Unable to write temp file</b>");
exit;
}
fwrite($handle, $this->_output);
fclose($handle);
require_once("/tmp/".$file);
unlink("/tmp/".$file);
}
}
?>

Templated HTML to PDF using DOMPdf

April 7th, 2008

The code posted below will convert the specified HTML file to PDF using DOMPdf (http://www.digitaljunkies.ca/dompdf/) code is documented with examples below.


<?php
/**
* HTMLPDF This will use the DOMPdf class to convert a HTML to PDF with templating
* @author Michael Baker
*/
class HTMLPDF extends DOMPdf {

proctected $input = null;
protected
$pdf = null;

public function __construct() {
$this->pdf = new DOMPDF();
}

/**
* inputFile - The input file name for the html file to be parsed
*
* @param string $filename The filename to parse for the template
* @return bool False if we hit an error but an exception will be thrown
* @throws I/O Errors
*/
public function inputFile($filename) {
if(!
file_exists($filename)) {
throw new
Exception(“Input file not found!”);
return
false;
}

if(!is_readable($filename)) {
throw new
Exception(“Input file found but not readable!”);
return
false;
}

$file = fopen($filename, “r”);
while(!
feof($file)) {
$this->input .= fread($file,8192);
}
fclose($file);
return
true;
}

/**
* parseTemplate - This will parse a set of key => value array pairs into the PDF
*
* @param array $template
* @return boll False on I/O error
* @throws I/O exception is output is not writable
*/
public function parseTemplate($template) {
if(!
is_array($template)) {
throw new
Exception(“Variable passed is not an array k => v array required”);
return
false;
}
foreach (
$template as $k => $v) {
$this->input = str_replace(“[$k]“, $v, $this->input);
}
$this->pdf->load_html($this->input);
return
true;
}

/**
* documentSize - This will set the document size for the output of the PDF see the PDF lib config for sizes
*
* @param string $paper Paper size
* @param string $orientation Paper orientation
* @return bool If the paper size or orientation is null it will return false
* @throws Null exception errors
*/
public function documentSize($paper,$orientation) {
if(
is_null($paper) || is_null($orientation)) {
throw new
Exception(“Paper and orientation cannot be null!”);
return
false;
}
$this->pdf->set_paper($paper, $orientation);
}

/**
* renderPDF - This will render the PDF to a specifed outfile
*
* @param string $output Outpu file name
* @return bool False on I/O error
* @throws I/O Exceptions
*/
public function renderPDF($output) {
if(!
is_writeable($output)) {
throw new
Exception(“Output file is not writeable exiting”);
return
false;
}
$this->pdf->render();
$this->pdf>stream($output);
return
true;
}

public function __destruct() {
unset(
$this->input);
}
}
$pdf = new HTMLPDF();
$pdf->inputFile(“Test.html”);
$template['NAME'] = “Michael”;
$pdf->parseTemplate($template);
$pdf->documentSize(“a4″, “portrait”);
$pdf->renderPDF(“Test.pdf”);
$pdf->renderPDF(“/tmp/out.pdf”);
?>

HackerSafe what a waste of money…

April 7th, 2008

oday I was browsing a site.. It has a HackerSafe logo and yet within 5 seconds of being on the page I seen SQL Injection?

So how does HackerSafe work you pay them all this money and they just say its secure?

Early Jan there was a post on a News website about Hackersafe and XSS I really think they should give up!

I would like any comments as to how you think hackersafe actually works?

Let me know your thoughts…

MySQL.com

April 2nd, 2008

http://www.mysql.com The best Commercial Open Source SQL engine :)

PHPro.org

April 2nd, 2008

http://www.phpro.org/ One of the best PHP sites Tutorials, Examples,Opensource Projects,Classes

PHP.net

April 2nd, 2008

http://www.php.net/ PHP the one thing I will never lose love for :)