generating xml using XmlWrite class

<?php


class XmlWriter {
var $xml;
var $indent;
var $stack = array();
function XmlWriter($indent = ' ') {
$this->indent = $indent;
$this->xml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
}
function _indent() {
for ($i = 0, $j = count($this->stack); $i < $j; $i++) {
$this->xml .= $this->indent;
}
}
function push($element, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= ">\n";
$this->stack[] = $element;
}
function element($element, $content, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= '>'.htmlentities($content).'</'.$element.'>'."\n";
}
function emptyelement($element, $attributes = array()) {
$this->_indent();
$this->xml .= '<'.$element;
foreach ($attributes as $key => $value) {
$this->xml .= ' '.$key.'="'.htmlentities($value).'"';
}
$this->xml .= " />\n";
}
function pop() {
$element = array_pop($this->stack);
$this->_indent();
$this->xml .= "</$element>\n";
}
function getXml() {
return $this->xml;
}
}

/* Test

$xml = new XmlWriter();
$array = array(
array('monkey', 'banana', 'Jim'),
array('hamster', 'apples', 'Kola'),
array('turtle', 'beans', 'Berty'),
);

$xml->push('zoo');
foreach ($array as $animal) {
$xml->push('animal', array('species' => $animal[0]));
$xml->element('name', $animal[2]);
$xml->element('food', $animal[1]);
$xml->pop();
}
$xml->pop();

print $xml->getXml();

*/
?>

Perlmod is a program that will help you manage Perl Modules.

http://sourceforge.net/projects/perlmod/files/latest/download

A Perl module is a discrete component of software for the Perl
programming language. Technically, it is a particular set of
conventions for using Perl's package mechanism that has become
universally adopted.[discuss] A module defines its source code to be
in a package (much like a Java package), the Perl mechanism for
defining namespaces, e.g. CGI or Net::FTP or XML::Parser; the file
structure mirrors the namespace structure (e.g. the source code for
Net::FTP is in Net/FTP.pm). Furthermore, a module is the Perl
equivalent of the class when object-oriented programming is employed

Now we'll see an easy way to manage them, install, list, delete
(uninstall) from the command line.


Perlmod is a program that will help you manage Perl Modules.

script to delete dovecot users

#!/bin/bash
#
# deldovecotuser - for deleting virtual dovecot users
#
if [ ! $# = 1 ]
then
echo -e "Usage: $0 username@domain"
exit 1
else
user=`echo "$1" | cut -f1 -d "@"`
domain=`echo "$1" | cut -s -f2 -d "@"`
if [ -x $domain ]
then
echo -e "No domain given\nUsage: $0 username@domain: "
exit 2
fi
fi
read -n 1 -p "Delete user $user@$domain from dovecot? [Y/N]? " REPLY
echo
case $REPLY in
y | Y)
new_users=`grep -v $user@$domain /etc/dovecot-users`
new_passwd=`grep -v $user@$domain /etc/dovecot-passwd`
new_vmaps=`grep -v $user@$domain /etc/postfix/vmaps`
new_vhosts=`grep -v $domain /etc/postfix/vhosts`
echo "Deleting $user@$domain from /etc/dovecot/users"
echo "$new_users" > /etc/dovecot-users
echo "Deleting $user@$domain from /etc/dovecot-passwd"
echo "$new_passwd" > /etc/dovecot-passwd
echo "Deleting $user@$domain from /etc/postfix/vmaps"
echo "$new_vmaps" > /etc/postfix/vmaps
echo "Deleting $domain from /etc/postfix/vhosts"
echo "$new_vhosts" > /etc/postfix/vhosts
postmap /etc/postfix/vmaps
postfix reload
read -n1 -p "Delete all files in /home/vmail/$domain/$user? [Y/N]? " DELETE
echo
case $DELETE in
y | Y)
echo "Deleting files in /home/vmail/$domain/$user"
rm -fr /home/vmail/$domain/$user
rm -fr /home/vmail/$domain
;;
* )
echo "Not deleting files in /home/vmail/$domain/$user"
;;
esac
;;
* )
echo "Aborting..."
;;
esac

script to add dovecot user

#!/bin/sh
if [ ! $# = 1 ]
then
echo "Usage: $0 username@domain"
exit 1
else
user=`echo "$1" | cut -f1 -d "@"`
domain=`echo "$1" | cut -s -f2 -d "@"`
if [ -x $domain ]
then
echo "No domain given\nUsage: $0 username@domain"
exit 2
fi
echo "Adding user $user@$domain to /etc/dovecot-users"
echo "$user@$domain::5000:5000::/home/vmail/$domain/$user/:/bin/false::"
>> /etc/dovecot-users

# Create the needed Maildir directories
echo "Creating user directory /home/vmail/$domain/$user"
# maildirmake.dovecot does only chown on user directory, we'll
create domain directory instead
if [ ! -x /home/vmail/$domain ]
then
mkdir /home/vmail/$domain
chown 5000:5000 /home/vmail/$domain
chmod 700 /home/vmail/$domain
fi
/usr/bin/maildirmake.dovecot /home/vmail/$domain/$user
chown 5000:5000 /home/vmail/$domain
chmod -R vmail:vmail /home/vmail/$domain


# To add user to Postfix virtual map file and relode Postfix
echo "Adding user to /etc/postfix/vmaps"
echo $1 $domain/$user/ >> /etc/postfix/vmaps
echo $domain >> /etc/postfix/vhosts
postmap /etc/postfix/vmaps
postfix reload
fi
echo "\nCreate a password for the new email user"
passwd=`dovecotpw`
echo "Adding password for $user@$domain to /etc/dovecot-passwd"
if [ ! -x /etc/dovecot-passwd ]
then
touch /etc/dovecot-passwd
chmod 640 /etc/dovecot-passwd
fi
echo "$user@$domain:$passwd" >> /etc/dovecot-passwd
/etc/init.d/dovecot restart
exit 0

Other Articles

Enter your email address: