Postgre quickguide

postgres@dev:~$ psql projektstyring
Welcome to psql 8.1.9, the PostgreSQL interactive terminal.

postgres@dev:~$ createdb projektstyring
CREATE DATABASE

projektstyring=# create user projektstyring with password ‘kode’;
CREATE ROLE

projektstyring=# GRANT ALL ON DATABASE projektstyring TO projektstyring;
GRANT

should be all that you need to continue from phppgadmin..

projektstyring=# create schema authorization projektstyring;
CREATE SCHEMA

projektstyring=# grant all on schema public to projektstyring;
GRANT

Udgivet i Knowledge Base, Old Base, Programmering | Skriv en kommentar

Xini file parser v1.0

<?
  
  # Xini parser v1.0 by MC Solutions 2007, all righs reserved
  
  /*
    Samlpe file:
    
    menu.xini:
    
    !Structure=Text,Url

    [Menu]
    Item="Om firmaet","about.php"
    Item="Kontakt firmaet","contact.php"

    [Menu2]
    Item="Bestil","order.php"
    Item="Log ind","login.php","nisse","fisk"


    [forside]
    Titel="Bla bla bla"
    BestilLink="Bla bla bla"
    
    
    EOF
    
    !Structure describes the name of the coma separated variables, used for generation an associative array.
    
    Lines starting with ; or # are ignores ie. comments
    
    The result of parsing the file ahead will be:
    
    Array
    (
        [Menu] => Array
    	    (
    	        [0] => Array
                (
                    [Text] => Om firmaet
                    [Url] => about.php
                )

    	        [1] => Array
                (
                    [Text] => Kontakt firmaet
                    [Url] => contact.php
                )

        	)

    		[Menu2] => Array
        	(
            	[0] => Array
                (
                    [Text] => Bestil
                    [Url] => order.php
                )

            	[1] => Array
                (
                    [Text] => Log ind
                    [Url] => login.php
                    [0] => nisse
                    [1] => fisk
                )

        	)

    		[forside] => Array
        	(
        	    [Titel] => Bla bla bla
          	    [BestilLink] => Bla bla bla
        	)

  )

  
  */
  

  
  class XiniParser
  {
    public function parse($file)
    {
      $data=preg_split("/\n/",file_get_contents($file));
      foreach ($data as $number=>$line)
      {
        $tokkens=preg_split("/=|\ /",$line,-1,PREG_SPLIT_NO_EMPTY);	
        if (($tokkens[0]=="") or ($tokkens[0][0]=="#") or ($tokkens[0][0]==";"))
        {
          // Tom Linie eller kommentar
        }
        else if ($tokkens[0]=="!Structure")
        {
          //print "NEW STRUC:$line\n";
          $struct=preg_split('/,/',$tokkens[1],-1,PREG_SPLIT_NO_EMPTY);
      
          
          $keys=$struct;
      
        } else if ($tokkens[0][0]=='[')
        {
          $block=preg_split('/\[|\]/',$line);
          $block=$block[1];		
        } else {
      
          $tokkens=preg_split("/=/",$line);
      
          $values=preg_split('/","/',$tokkens[1]);
      
          if (count($values)==1)
          {
            $value=substr($values[0],1,-1);	// Remove tailing and heading "
          } else {
            $values[0]=substr($values[0],1);
            $values[count($values)-1]=substr($values[count($values)-1],0,-1);
            unset($value);
            foreach ($values as $k=>$v)
            {
              if ($keys[$k]!="")
              {
                $value[$keys[$k]]=$v;
              } else {
                $value[]=$v;
              }
            }
        
          }	
            
          if ($tokkens[0]=="Item")
          {
            $ret[$block][]=$value;					
          } else {
            if (strpos($line,"="))
            {
              $ret[$block][$tokkens[0]]=$value;
            
              // Value Assignments	
            } else 
            {
              print "syntax error at line $number:`<i>$line</i>`<br>";
            }	
          }
        }		
      }
      return $ret;
    }
  }
  
  $xini=new XiniParser();
  
  print_r($xini->parse('menu.xini'));
  
?>

 

Udgivet i Knowledge Base, Old Base, Programmering | Skriv en kommentar

Installing mailserver on Debian

### Install packages needed:
apt-get install apache2 mysql-server libapache2-mod-php5 php5-mysql postfix postfix-mysql courier-authlib-mysql courier-imap courier-pop

### Answers:
Create Web Based Configuration: NO
General type of configuration: Internet Site
Mail name: mail02.ar.mcn.dk

### Run this to edit /etc/postfix/main.cf:

postconf -e myhostname=mail02.ar.mcn.dk
postconf -e mydomain=mcn.dk
postconf -e mynetworks=127.0.0.0/8
postconf -e alias_maps=mysql:/etc/postfix/mysql-aliases.cf
postconf -e relocated_maps=mysql:/etc/postfix/mysql-relocated.cf
postconf -e local_transport=local
postconf -e ‘local_recipient_maps=$alias_maps $virtual_mailbox_maps unix:passwd.byname’
postconf -e virtual_transport=virtual
postconf -e virtual_mailbox_domains=mysql:/etc/postfix/mysql-transport.cf
postconf -e virtual_minimum_uid=1000
postconf -e virtual_gid_maps=mysql:/etc/postfix/mysql-virtual-gid.cf
postconf -e virtual_mailbox_maps=mysql:/etc/postfix/mysql-virtual-maps.cf
postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql-virtual.cf
postconf -e virtual_uid_maps=mysql:/etc/postfix/mysql-virtual-uid.cf
postconf -e virtual_mailbox_base=/

### file mysql-aliases.cf:
# mysql-aliases.cf

user = mailsql
password = mypassword
dbname = mailsql
table = alias
select_field = destination
where_field = alias
hosts = 127.0.0.1

### file mysql-relocated.cf:
# mysql-relocated.cf

user = mailsql
password = mypassword
dbname = mailsql
table = relocated
select_field = destination
where_field = email
hosts = 127.0.0.1

### file mysql-transport.cf:
# mysql-transport.cf

user = mailsql
password = mypassword
dbname = mailsql
table = transport
select_field = destination
where_field = domain
hosts = 127.0.0.1

### file mysql-virtual-gid.cf:
#myql-virtual-gid.cf

user = mailsql
password = mypassword
dbname = mailsql
table = users
select_field = gid
where_field = email
additional_conditions = and postfix = ‘y’
hosts = 127.0.0.1

### file mysql-virtual-maps.cf:
#myql-virtual-maps.cf

user = mailsql
password = mypassword
dbname = mailsql
table = users
select_field = maildir
where_field = email
additional_conditions = and postfix = ‘y’
hosts = 127.0.0.1

### file mysql-virtual-uid.cf:
# mysql-virtual-uid.cf

user = mailsql
password = mypassword
dbname = mailsql
table = users
select_field = uid
where_field = email
additional_conditions = and postfix = ‘y’
hosts = 127.0.0.1

### file mysql-virtual.cf:
# mysql-virtual.cf

user = mailsql
password = mypassword
dbname = mailsql
table = virtual
select_field = destination
where_field = email
hosts = 127.0.0.1

### file mailsql.sql:
— phpMyAdmin SQL Dump
— version 2.11.1.2
— http://www.phpmyadmin.net

— Vært: localhost
— Genereringstid: 26. 11 2007 kl. 21:44:15
— Serverversion: 5.0.44
— PHP-version: 5.2.4_p20070914-pl2-gentoo

SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;


— Database: `mailsql`

— ——————————————————–


— Struktur-dump for tabellen `alias`

CREATE TABLE IF NOT EXISTS `alias` (
`id` int(11) NOT NULL auto_increment,
`alias` varchar(42) NOT NULL default ”,
`destination` varchar(42) NOT NULL default ”,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

— ——————————————————–


— Struktur-dump for tabellen `relocated`

CREATE TABLE IF NOT EXISTS `relocated` (
`id` int(11) NOT NULL auto_increment,
`email` varchar(42) NOT NULL default ”,
`destination` varchar(42) NOT NULL default ”,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

— ——————————————————–


— Struktur-dump for tabellen `transport`

CREATE TABLE IF NOT EXISTS `transport` (
`id` int(11) NOT NULL auto_increment,
`domain` varchar(42) NOT NULL default ”,
`destination` varchar(42) NOT NULL default ”,
PRIMARY KEY (`id`),
UNIQUE KEY `domain` (`domain`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

— ——————————————————–


— Struktur-dump for tabellen `users`

CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL auto_increment,
`email` varchar(42) NOT NULL default ”,
`clear` varchar(42) NOT NULL default ”,
`name` tinytext NOT NULL,
`uid` int(11) NOT NULL default ‘1101’,
`gid` int(11) NOT NULL default ‘1101’,
`homedir` tinytext NOT NULL,
`maildir` tinytext NOT NULL,
`quota` tinytext NOT NULL,
`postfix` enum(‘n’,’y’) NOT NULL default ‘y’,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

— ——————————————————–


— Struktur-dump for tabellen `virtual`

CREATE TABLE IF NOT EXISTS `virtual` (
`id` int(11) NOT NULL auto_increment,
`email` varchar(42) NOT NULL default ”,
`destination` varchar(42) NOT NULL default ”,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

### edit /etc/courier/authdaemonrc:

authmodulelist=”authmysql”

### file /etc/courier/authmysqlrc:
MYSQL_SERVER 127.0.0.1
MYSQL_USERNAME mailsql
MYSQL_PASSWORD mypassword
MYSQL_DATABASE mailsql
#MYSQL_CRYPT_PWFIELD crypt
MYSQL_USER_TABLE users
MYSQL_CLEAR_PWFIELD clear
MYSQL_LOGIN_FIELD email
MYSQL_HOME_FIELD homedir

### After creating the files run:
groupadd -g 1101 vmail
useradd -u 1101 -g 1101 -d /var/vmail -m vmail
mysqladmin create mailsql
mysql mailsql < mailsql.sql
echo “grant all privileges on mailsql.* to mailsql@localhost identified by ‘pass1234’;” | mysql
sed -i -e ‘s/mypassword/pass1234/’ /etc/postfix/mysql-* /etc/courier/authmysqlrc
/etc/init.d/postfix reload
/etc/init.d/courier-authdaemon restart
/etc/init.d/courier-imap restart
/etc/init.d/courier-pop restart

Udgivet i Knowledge Base, Linux, Networking, Old Base | Skriv en kommentar

Creating PDF Files from PHP on debian

apt-get install php-fpdf

look for tutorials and documentation at: http://www.fpdf.org/

add fpdf to the include path, and save yourself the hazzle to edit it every time:

include_path = “.:/usr/share/php:/usr/share/php/fpdf”

(in php.ini (DUH!))

Udgivet i Knowledge Base, Old Base, Programmering | Skriv en kommentar

Generating java code from JavaDoc HTML

Cut’n’paste the method summary to the created class.

Use this search and replace in VS.NET:

Search:
^{[^\)]*}\) \n:b*{[^\n]*}$
Replace:
\n/**\n * \2\n */\npublic \1) { }

For interfaces use this replace:
\n/**\n * \2\n */\n\1);

Strip blank comment blocks with:

Search:
^:b*/\*\*:b*\n:b*\*:b*\n:b*\*/:b*\n
Replace:
\n

Udgivet i Knowledge Base, Old Base, Programmering | Skriv en kommentar

Get enums fra mysql in php

PRIVATE function GetEnums($table,$field)
{
$dat=mysql_fetch_array(mysql_query(“show columns from `$table` like ‘$field’;”,$this->MysqlResource));
return(preg_split(“/’|,|enum|\(|\)/”,$dat[‘Type’],null,PREG_SPLIT_NO_EMPTY));
}

Udgivet i Knowledge Base, Old Base, Programmering | Skriv en kommentar

SSH Mount in Ubuntu

I did the following, you might not need to do it all:

Create mount dir and chown it to the user who needs to access it.

Add the following line to fstab:
sshfs#USERNAME@SERVER:/PATH /mnt/MOUNTPOINT fuse defaults,noauto,user,uid=mike,gid=mike,allow_other,reconnect,transform_symlinks 0 0

For automated mounts add ssh keys.

Udgivet i Knowledge Base, Linux, Old Base | Skriv en kommentar

Installing webserver on Debian

apt-get install apache2 mysql-server php5-mysql

Udgivet i Knowledge Base, Linux, Old Base | Skriv en kommentar

How to fix broken MMConfig on ASUS K8N4-E Deluxe

Remove support for mmconfig config space access in the kernel configuration, it’s broken on Asus boards with recent kernels apparently (I have this board, and nothing that’s connected on PCI works with mmconfig enabled). It’s here in the kernel configuration:

Bus options (PCI etc.) —>
[ ] Support mmconfig PCI config space access

You can also boot with “pci=nommconf” added to the kernel parameters, it should disable mmconfig too.

Udgivet i Knowledge Base, Old Base | Skriv en kommentar

SOURCE: Generic PHP Autoloader

<?
// COPYRIGHT (c) 2007 MC Solutions
/**
* Class to handle autoloading of Php class files
*/
Class AutoLoader
{

private $files;
private $error;

private $use_session_cache = “true”;

/**
* Tells the AutoLoader what to do when duplicate class files are found, I_ALL Include all, I_FIRST Include first, I_LAST Include last, I_FAIL Fail with error message
*
* @var [I_ALL,I_FIRST,I_LAST,I_FAIL]
*/
public $on_duplicate = I_ALL;

/**
* Tells the Autoloader how to cache the directory structure, C_SESSION for each session, C_PAGEVIEW for each pageview, C_NEVER dont cache
*
* @var [C_SESSION,C_PAGEVIEW,C_NEVER]
*/
public $on_cache = C_SESSION;

/**
* Tells AutoLoader which dir to look for class files in
*
* @var string
*/

public $on_classes_dir = ‘./’;

/**
* Used to recurse the directory structure containing the
*
* @param string $dir
* @return array of files in the directory
*/
private function RecurseDir($dir)
{
$dh=opendir($dir);
while ($file=readdir($dh))
{
if (($file != “.”) and ($file != “..”))
{
if (filetype($dir.$file) == ‘dir’)
{
$return[$dir.$file]= $this->RecurseDir($dir.$file.’/’);
}
else
{
$return[]=$file;
if ($this->files[$file])
{
//print “Duplicate detected $dir$file and $this->files[$file]<br>”;

if (!is_array($this->files[$file]))
{
$tmp=$this->files[$file];
$this->files[$file]=array();
$this->files[$file][]=$tmp;
}

$this->files[$file][]=$dir.$file;

} else {
$this->files[$file]=”$dir$file”;
}
}
}
}

closedir($dh);

return $this->files;
}

/**
* Checks if sessions are needed, and tries to initiate them if they are not allready
*
*/
public function __construct()
{
if ($this->on_cache == “C_SESSION”)
{
if (!headers_sent())
{
session_start();
} else {
// Output er sent, se om sessions er startet
if (isset($_SESSION))
{
// Sessions er startet, vi koerer videre
} else {
// Sessions er ikke startet, session-cache deaktiveres
$this->use_session_cache=”false”;
}
}
}
}

/**
* Tries to include a PHP File
*
* @param string $file
* @return boolean true if inclusions succeded
*/
private function try_include($file)
{
if (@include($file))
{
return true;
} else {
return false;
}
}

/**
* This function contains the semantics required to determine what file to load
*
* @param string $classname Name of wanted class
* @return true when file found
*/
private function performloadclass($classname)
{
if ($this->try_include($classname.”.php”)) { return true;}
if ($this->try_include($classname.”.class.php”)) { return true;}

if (($this->use_session_cache==”false”) and ($this->on_cache==”C_SESSION”))
{
print “Defaulting”;
$this->on_cache=C_PAGEVIEW;
}

switch ($this->on_cache)
{
case C_SESSION:

if (!$_SESSION[‘_CLASS_CACHE’])
{
$this->files=”;
$_SESSION[‘_CLASS_CACHE’]=$this->RecurseDir($this->on_classes_dir);
}
$this->files=$_SESSION[‘_CLASS_CACHE’];
break;

case C_PAGEVIEW:
if (!is_array($this->files))
{
$this->files=”;
$this->files=$this->RecurseDir($this->on_classes_dir);
}
break;

case C_NEVER:
$this->files=”;
$this->files=$this->RecurseDir($this->on_classes_dir);
break;
}

if ($this->files[$classname.”.php”])
{
$filename=$classname.”.php”;
}
else if ($this->files[$classname.”.class.php”])
{
$filename=$classname.”.class.php”;
} else {
$this->error=”Not found”;
return false;
}
if (is_array($this->files[$filename]))
{
switch ($this->on_duplicate)
{
case “I_ALL”:
foreach ($this->files[$filename] as $k)
{
print “Include $k<br>”;
include($k);
}
return true;
break;

case “I_FIRST”:
$this->try_include($this->files[$filename][0]);
return true;
break;

case “I_LAST”:
$this->try_include($this->files[$filename][count($this->files[$filename])-1]);
return true;
break;

case “I_FAIL”:
$this->error=”Duplicate files found”;
return false;
break;

default:
$this->error=”Wrong on_duplicate settings”;
return false;
break;
}
}
else
{
$this->try_include($this->files[$filename]);
return true;
}
}

/**
* This method are invoked by __autoload
*
* @param string $classname Name of wanted class
*/
public function loadclass($classname)
{
if (!$this->performloadclass($classname))
{
print “<strong>Klassefejl: $classname</strong><br><br>Kunne ikke findes i:<br>”;
print “<ul>”;
print “<li>$classname.php i php include_path samt i $this->on_classes_dir og dennes undermapper</li>”;
print “<li>$classname.class.php i php include_path samt i $this->on_classes_dir og dennes undermapper</li>”;
print “</ul>”;
if ($this->error)
{
print $this->error;
}
}
}

}

$_AutoLoader = new AutoLoader();
$_AutoLoader->on_classes_dir=’./classes/’;
$_AutoLoader->on_duplicate=I_ALL;

function __autoload($classname)
{
global $_AutoLoader;
$_AutoLoader->loadclass($classname);
}

?>

Udgivet i Knowledge Base, Old Base, Programmering | Skriv en kommentar