#!%PERL% -w 
# Copyright (c) vhffs project and its contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without 
# modification, are permitted provided that the following conditions 
# are met:
#
# 1. Redistributions of source code must retain the above copyright 
#   notice, this list of conditions and the following disclaimer.
#2. Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in 
#   the documentation and/or other materials provided with the 
#   distribution.
#3. Neither the name of vhffs nor the names of its contributors 
#   may be used to endorse or promote products derived from this 
#   software without specific prior written permission.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
# POSSIBILITY OF SUCH DAMAGE.


use utf8;
use POSIX qw(locale_h);
use strict;

use lib '%VHFFS_LIB_DIR%';
use Vhffs::User;
use Vhffs::Group;
use Vhffs::Main;
use Vhffs::Panel::Main;
use Vhffs::Panel::Menu;
use Vhffs::Stats;
use Vhffs::Constants;

my $vhffs = init Vhffs::Main;
exit 1 unless defined $vhffs;

my $stats = new Vhffs::Stats( $vhffs );
exit 1 unless defined $stats;

my $output = '';

$output .= '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$output .= '<stats>'."\n";

$output .= '<users>'."\n";
$output .= '  <total>'.$stats->get_user_total.'</total>'."\n";
$output .= '</users>'."\n";

$output .= '<groups>'."\n";
$output .= '  <total>'.$stats->get_groups_total.'</total>'."\n";
$output .= '  <activated>'.$stats->get_groups_activated.'</activated>'."\n";
$output .= '</groups>'."\n";

$output .= '<service name="web">'."\n";
$output .= '  <awaitingmoderation>'.$stats->get_web_in_moderation.'</awaitingmoderation>'."\n";
$output .= '  <activated>'.$stats->get_web_activated.'</activated>'."\n";
$output .= '</service>'."\n";

$output .= '<service name="mysql">'."\n";
$output .= '  <awaitingmoderation>'.$stats->get_mysql_in_moderation.'</awaitingmoderation>'."\n";
$output .= '  <activated>'.$stats->get_mysql_activated.'</activated>'."\n";
$output .= '</service>'."\n";

$output .= '<service name="pgsql">'."\n";
$output .= '  <awaitingmoderation>'.$stats->get_pgsql_in_moderation.'</awaitingmoderation>'."\n";
$output .= '  <activated>'.$stats->get_pgsql_activated.'</activated>'."\n";
$output .= '</service>'."\n";

$output .= '<service name="cvs">'."\n";
$output .= '  <awaitingmoderation>'.$stats->get_cvs_in_moderation.'</awaitingmoderation>'."\n";
$output .= '  <activated>'.$stats->get_cvs_activated.'</activated>'."\n";
$output .= '</service>'."\n";

$output .= '<service name="svn">'."\n";
$output .= '  <awaitingmoderation>'.$stats->get_svn_in_moderation.'</awaitingmoderation>'."\n";
$output .= '  <activated>'.$stats->get_svn_activated.'</activated>'."\n";
$output .= '</service>'."\n";

$output .= '<service name="git">'."\n";
$output .= '  <awaitingmoderation>'.$stats->get_git_in_moderation.'</awaitingmoderation>'."\n";
$output .= '  <activated>'.$stats->get_git_activated.'</activated>'."\n";
$output .= '</service>'."\n";

$output .= '<service name="mercurial">'."\n";
$output .= '  <awaitingmoderation>'.$stats->get_mercurial_in_moderation.'</awaitingmoderation>'."\n";
$output .= '  <activated>'.$stats->get_mercurial_activated.'</activated>'."\n";
$output .= '</service>'."\n";

$output .= '<service name="bazaar">'."\n";
$output .= '  <awaitingmoderation>'.$stats->get_bazaar_in_moderation.'</awaitingmoderation>'."\n";
$output .= '  <activated>'.$stats->get_bazaar_activated.'</activated>'."\n";
$output .= '</service>'."\n";

$output .= '<service name="mail">'."\n";
$output .= '  <awaitingmoderation>'.$stats->get_mail_in_moderation.'</awaitingmoderation>'."\n";
$output .= '  <activated>'.$stats->get_mail_activated.'</activated>'."\n";
$output .= '  <boxes>'.$stats->get_mail_total_boxes.'</boxes>'."\n";
$output .= '  <forwards>'.$stats->get_mail_total_forwards.'</forwards>'."\n";
$output .= '</service>'."\n";

$output .= '<service name="mailinglist">'."\n";
$output .= '  <total>'.$stats->get_lists_total.'</total>'."\n";
$output .= '  <activated>'.$stats->get_lists_activated.'</activated>'."\n";
$output .= '  <subscriptions>'.$stats->get_lists_totalsubs.'</subscriptions>'."\n";
$output .= '</service>'."\n";

$output .= '<service name="dns">'."\n";
$output .= '  <awaitingmoderation>'.$stats->get_dns_in_moderation.'</awaitingmoderation>'."\n";
$output .= '  <activated>'.$stats->get_dns_activated.'</activated>'."\n";
$output .= '</service>'."\n";

$output .= '</stats>'."\n";

binmode STDOUT , ':utf8';
print "Content-Type: text/xml; charset=utf-8\n\n" . $output;
