#!/usr/bin/perl -w ############################################################################### # HCCBandwidth.pm - A custom API module for CPanel # Version 0.1.1 beta - 11/MAY/2005 # (c) 2002-2005 Juan R. Pozo # http://html.conclase.net/cp/scripts/ # mailto:jrpozo@conclase.net # Mailing-list: http://www.conclase.net/mailman/listinfo/cpanel_conclase.net ############################################################################### # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################### # For INSTALLATION and DOCUMENTATION please see: # http://html.conclase.net/cp/scripts/HCCBandwidth.txt (plain text), or # http://html.conclase.net/cp/scripts/HCCBandwidth.pdf (Acrobat) ############################################################################### # Please consider making a donation today. Visit my amazon.com wishlist at: # http://html.conclase.net/link/wishlist # Thank you :) ############################################################################### # Changelog: # May 11, 2005 - v0.1.1: Fixed lang function # Sep 22, 2003 - v0.1: First public release ############################################################################### package Cpanel::HCCBandwidth; use strict; use vars qw(@ISA @EXPORT $VERSION $prefix); require Exporter; @ISA = qw(Exporter); @EXPORT = qw( HCCBandwidth_init HCCBandwidth_Max HCCBandwidth_Used HCCBandwidth_Available ); $VERSION = '0.1.1'; $prefix = "HCCBandwidth"; Cpanel::Lang::loadlang($Cpanel::CPDATA{LANG}); require 5.004; sub HCCBandwidth_init { return(1); } sub HCCBandwidth_Max { # Check parameters my ($param, $div, $dec) = (shift, 1024*1024*1024, 3); if ($param =~ /^\s*["']?([^"']+)["']?\s*$/) { if ($1 =~ /^bytes$/i) { ($div, $dec) = (1, 0); } elsif ($1 =~ /^kb$/i) { ($div, $dec) = (1024, 1); } elsif ($1 =~ /^mb$/i) { ($div, $dec) = (1024*1024, 2); } elsif ($1 !~ /^gb$/i) { return; } } if ($Cpanel::CPDATA{'BWLIMIT'} <= 0) { print lang("Unlimited"); } else { printf("%.${dec}f", $Cpanel::CPDATA{'BWLIMIT'}/$div); } } sub HCCBandwidth_Used { my ($param, $mult, $dec) = (shift, 1 / 1024, 3); if ($param =~ /^\s*["']?([^"']+)["']?\s*$/) { if ($1 =~ /^bytes$/i) { ($mult, $dec) = (1024*1024, 0); } elsif ($1 =~ /^kb$/i) { ($mult, $dec) = (1024, 1); } elsif ($1 =~ /^mb$/i) { ($mult, $dec) = (1, 2); } elsif ($1 !~ /^gb$/i) { return; } } my $cbw = Cpanel::Stats::countbandwidth(); printf("%.${dec}f", $cbw*$mult); } sub HCCBandwidth_Available { my ($param, $div, $dec) = (shift, 1024 * 1024 * 1024, 3); my $cbw = Cpanel::Stats::countbandwidth() * 1024 * 1024; if ($param =~ /^\s*["']?([^"']+)["']?\s*$/) { if ($1 =~ /^bytes$/i) { ($div, $dec) = (1, 0); } elsif ($1 =~ /^kb$/i) { ($div, $dec) = (1024, 1); } elsif ($1 =~ /^mb$/i) { ($div, $dec) = (1024*1024, 2); } elsif ($1 !~ /^gb$/i) { return; } } if ($Cpanel::CPDATA{'BWLIMIT'} <= 0) { print lang("Unlimited"); } else { printf("%.${dec}f", ($Cpanel::CPDATA{'BWLIMIT'}-$cbw)/$div); } } sub lang { my ($key) = @_; return $Cpanel::Lang::LANG{$Cpanel::CPDATA{LANG}}{"${prefix}_${key}"}; } 1;