#!/usr/bin/perl -w ############################################################################### # HCCInclude.pm - A custom API module for CPanel # Version 0.1.1 beta - 11/MAY/2005 # (c) 2003, 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/HCCInclude.txt (plain text), or # http://html.conclase.net/cp/scripts/HCCInclude.pdf (Acrobat) ############################################################################### # Please consider making a donation today. Visit my amazon.com wishlist at: # http://html.conclase.net/link/wishlist # Thank you :) ############################################################################### package Cpanel::HCCInclude; use strict; use vars qw(@ISA @EXPORT $VERSION $prefix); require Exporter; @ISA = qw(Exporter); @EXPORT = qw( HCCInclude_init HCCInclude_Include HCCInclude_IncludeBodyContents ); $VERSION = '0.1.1'; $prefix = "HCCInclude"; Cpanel::Lang::loadlang($Cpanel::CPDATA{LANG}); require 5.004; sub HCCInclude_init { return(1); } sub HCCInclude_Include { reset_error(); my $url = shift; $url =~ s/^\s*//; $url =~ s/\s*$//; if ($url =~ /^'([^']+)'$/ || $url =~ /^"([^"]+)"$/ || $url =~ /^(.+)$/) { $url = $1; } print get($url); } sub HCCInclude_IncludeBodyContents { reset_error(); my $url = shift; $url =~ s/^\s*//; $url =~ s/\s*$//; if ($url =~ /^'([^']+)'$/ || $url =~ /^"([^"]+)"$/ || $url =~ /^(.+)$/) { $url = $1; } my $output = get($url); $output =~ s/^(.|\s)*<\s*body[^>]*>//mig; $output =~ s/<\s*\/\s*body[^>]*>(.|\s)*$//mig; print $output; } sub get { my $url = shift; my $output = ""; my $result = open(WGET, "-|"); if (!defined($result)) { set_error("nopipe", 1); return; } if (!$result) { exec("/usr/bin/wget", "-O", "-", "$url") or do { set_error("nowget", 1); exit; }; } else { while () { $output .= $_; } close(WGET); } return $output; } sub reset_error { $Cpanel::CPERROR{${prefix}} = 0; my @errors = ("nopipe", "nowget", "errstr"); foreach my $key (@errors) { delete($Cpanel::CPERROR{"${prefix}_${key}"}); } } sub set_error { my ($key, $value) = @_; $Cpanel::CPERROR{${prefix}} = 1; $Cpanel::CPERROR{"${prefix}_${key}"} = $value; $Cpanel::CPERROR{"${prefix}_errstr"} = lang("errstr_${key}"); } sub lang { my ($key) = @_; return $Cpanel::Lang::LANG{$Cpanel::CPDATA{LANG}}{"${prefix}_${key}"}; } 1;