March 2010

Vim – Syntax highlighting

Turn on color syntax highlighting

Now press ESC key, type : syntax on

:syntax on

You can edit ~/.vimrc file and add command syntax on to it so that next you will start vim with color syntax highlighting option

$ vim ~/.vimrc

Append the following line:

syntax on

GRUB – Init Shell

Sometime in case of root password lost or file system corruption, you need to boot system with simple shell, skipping the init sequence.

1. At Grub prompt press ‘e’ to edit command before booting.

2. Select ‘kernel’ line

3. Press ‘e’ again to edit selected command

4. Type follow at end of the line: init=/bin/bash (or sh)

5. Press ‘b’ to boot system

6. Now you are at shell prompt. Enjoy

Linux – dmidecode

dmidecode is a tool for dumping a computer’s DMI (some say SMBIOS) table contents in a human-readable format. This table contains a description of the system’s hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision.
If you like to see which memory banks is in use and what the ram module sizes, you simply call dmidecode with memory parameter.

# dmidecode -t memory

dmidecode also gives you information about your system’s cache, bios and cpu.
Here is a sample output for processor:

# dmidecode -t processor

information about your system cache

# dmidecode -t cache

bios information includes vendor of your bios and it’s version. Also, which devices are supported and which ones can be use for booting up your system.

# dmidecode -t bios

PHP & FlickrAPI – Photo wall

I wrote a simple code/class for automatic get photos from flickr photostream (by service API)  to compose randomly a nice miniature photowall (you can see an example on my homepage).

First of all you can need API code (only key, we don’t need secret authentication).

Now the code, my class file was called lib/fget.php in here we define variable, class and function construct:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
class Flickr {
//API Key you can get them on http://www.flickr.com/services/apps/create/apply/
private $apiKey = 'xxxx';
//We define our numeric username http://www.flickr.com/services/api/explore/?method=flickr.people.getInfo
private $NSID = '29479498@N05';
//File per page (max file 200 for free account)
private $ppage = '200';public function __construct() {
}public function retrive() {
//For get data we use REST method and serialize option
$getdata = 'http://flickr.com/services/rest/?method=flickr.photos.search&api_key=' . $this->apiKey . '&user_id=' . $this->NSID . '&per_page=' . $this->ppage . '&format=php_serial';
//Get the data
$result = file_get_contents($getdata);
//De serialize for array use
$result = unserialize($result);
return $result;
}
}
?>

Now include the class into a sample page:

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
<?php
//Include the class
require_once('lib/fget.php');
//Recall the class
$Flickr = new Flickr;
//Retrive data array
$data = $Flickr->retrive();
//Randomize data
shuffle($data['photos']['photo']);
//Define 0 to the counter (we need this some line down here)
$count = 0;
?>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
<title>deepreflect.net</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.css" rel="stylesheet" type="text/css">
</head>
<body>
<p>
<a href="home.php">
<?php
 
        foreach($data['photos']['photo'] as $photo) { 
        //URL base format for all photo, if you wanna miniature you can modify .jpg into _s.jpg
        // http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg
 
        //print photo sequence:
	echo '<img alt="click to Enjoy..." src="http://farm' . $photo["farm"] . '.static.flickr.com/' . $photo["server"] . '/' . $photo["id"] . '_' . $photo["secret"] . '_s.jpg">'; 
	//Start the counter
	$count++;
	//Every 13 create a new line
	if ($count == 13) echo '<br>';
	if ($count == 26) echo '<br>';
	if ($count == 39) echo '<br>';
	if ($count == 52) echo '<br>';
	if ($count == 65) echo '<br>';
	if ($count == 78) echo '<br>';
	//Limit print results to 91 photo
	if ($count == 91) break;
}
?>
</a>
</p>
</body>
</html>

Squid – Radius auth

In this example a squid installation will use RADIUS “squid_radius_auth” Squid RADIUS authentication helper to authenticate users.

Get last version of squid radius auth helper at:
http://www.squid-cache.org/contrib/squid_radius_auth/

Download:

[leo@srv01 leo]# wget http://www.squid-cache.org/contrib/squid_radius_auth/squid_radius_auth-1.10.tar.gz

Extract:

[leo@srv01 leo]# tar -xvf squid_radius_auth-1.10.tar.gz

Go to directory:

[leo@srv01 leo]# cd squid_radius_auth-1.10

Compile:

[leo@srv01 squid_radius_auth-1.10]# make
gcc -O2 -Wall -g -c -o squid_rad_auth.o squid_rad_auth.c
gcc -O2 -Wall -g -c md5.c
gcc -O2 -Wall -g -c util.c
gcc -g -o squid_radius_auth squid_rad_auth.o md5.o util.o

Now the installation, for my needs, I wanna keep binary into /usr/lib/squid/ and configuration file into /etc/squid/ and I don’t wanna take man files then edit Make.inc like this:

BINDIR = /usr/lib/squid
CONFDIR = /etc/squid

install: squid_radius_auth
mkdir -p $(BINDIR)
install -m 755 -s squid_radius_auth $(BINDIR)/squid_radius_auth
# mkdir -p $(DESTDIR)$(MANDIR)
# install -m 755 squid_radius_auth.8 $(DESTDIR)$(MANDIR)/squid_radius_auth$(MANEXT)
mkdir -p $(CONFDIR)
install -m 644 etc/squid_radius_auth.conf $(CONFDIR)/squid_radius_auth.conf.default
if ! test -f $(CONFDIR)/squid_radius_auth.conf; then \
cp -p $(CONFDIR)/squid_radius_auth.conf.default $(CONFDIR)/squid_radius_auth.conf; \
fi

Edit config file /etc/squid/squid_radius_auth.conf here my example:

server 10.255.X.X
secret XXXXXXXX
port 1645

Now you can test the helper, execute and then type your radius username/password on the same line separated with space, on successful authentication it will give “OK” otherwise “ERR login failure”

[leo@srv01 leo]# /usr/lib/squid/squid_radius_auth -f /etc/squid/squid_radius_auth.conf
leo xxxx
OK

Now you can made change to “squid.conf”

# TAG: auth_param
auth_param basic program /usr/lib/squid/squid_radius_auth -f /etc/squid/squid_radius_auth.conf
auth_param basic children 5
auth_param basic realm Wide-NET-Proxy
auth_param basic credentialsttl 5 minute
auth_param basic casesensitive on

# TAG: acl
acl radius-auth proxy_auth REQUIRED

# TAG: http_access
http_access allow localhost
http_access allow radius-auth
http_access deny all

OpenVMS – Set Time

The command to reset the system time to 18-APR-2010 09:47 is:

$ SET TIME=18-APR-2010:09:47

Note the colon between the date and the time specification. (This
extra colon is a requirement resulting from the DCL parsing rules.
Normally, there is a space between the date and time.)

On OpenVMS VAX, once a year between January 1st and circa April 11th,
or whenever a different SYS.EXE system image is bootstrapped, issue the
command:

$ SET TIME

to resynchronize the VAX time-of-year (TOY) clock and the contents of
the OpenVMS VAX system image. (This SET TIME command is automatically
performed during a normal system shutdown.) The TOY clock stores (only)
the time since January 1 00:00:00.00 of the current year, and has a
maximum resolution of roughly 466 days. The system image is used as the
storage location for the current year. Between these two values, the
current time and date is “constructed” during the OpenVMS VAX system
bootstrap. (And this is the reason the saved time value in the system
image must be reset every year between January and April.)

The SYSGEN parameter SETTIME can be used to enable prompting for the
system time during the system bootstrap.