MOD: Nutzer bei Überschreiten der Webquota warnen

mare

Member
Hallo,

Folgendes Script schickt eine Warnmail an den Nutzer eines Webs wenn mehr als 95% des erlaubten Speichers belegt sind.
Ich möchte das nur ab und zu machen deshalb als einzelnes Script aber man kann es auch einfach in die cron_daily.php packen.


/usr/local/ispconfig/server/websitequotacheck.php
Code:
<?php

/*
Copyright (c) 2007-2012, Till Brehm, projektfarm Gmbh
All rights reserved.

Contributed by Rene Marticke COSIMO GmbH (rm@cosimo.de)

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * 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.
    * Neither the name of ISPConfig 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.
*/

define('SCRIPT_PATH', dirname($_SERVER["SCRIPT_FILENAME"]));
require(SCRIPT_PATH."/lib/config.inc.php");
require(SCRIPT_PATH."/lib/app.inc.php");

set_time_limit(0);

// Load required base-classes
$app->uses('ini_parser,file,services,getconf,system');

#######################################################################################################
// Read Quotainfos from monitor_data and inform webuser if watermark is reached
#######################################################################################################
$global_config = $app->getconf->get_global_config('mail');

if ($app->dbmaster == $app->db) {
$sql = "SELECT data FROM monitor_data where type='harddisk_quota'" ;
$records = $app->db->queryAllRecords($sql);
foreach($records as $rec) {
        $data = unserialize($rec['data']) ;

        if (@is_array($data["user"]))
        foreach ($data["user"] as $datau => $dataw)
            {
            if ($dataw["used"]>0&&$dataw["soft"]>0)
                {
                if (round($dataw["used"]*100/$dataw["soft"]) > 94)
                {
                $sql = "SELECT domain,system_group FROM web_domain where system_user='".$datau."'" ;
                $domdat = $app->db->queryOneRecord($sql) ;
                $clientid = str_replace("client","",$domdat["system_group"]) ;
                $sql = "SELECT email from client where client_id=$clientid" ;
                $client = $app->db->queryOneRecord($sql) ;
                $subject = "Achtung Ihr Speicherplatz auf ".$domdat["domain"]." wird knapp !" ;
                $mailtext = "Sehr geehrter Kunde, " ;
                $mailtext .= "\n\nDer maximale Speicherplatz Ihrer Domain ".$domdat["domain"]." beträgt ".round($dataw["soft"]/1024)." MB. ";
                $mailtext .= "\nDavon sind aktuell ".round($dataw["used"]/1024,2)."MB (".round($dataw["used"]*100/$dataw["soft"])."%) belegt!" ;
                $mailtext .= "\n\nBitte entfernen Sie nicht mehr benötigte Daten oder setzten Sie sich mit unserem Vertrieb in Verbindung.";
                $mailtext .= "\n\nMit freundlichen Grüßen\n\nIhr Webserviceteam";
                $mailHeaders      = "MIME-Version: 1.0" . "\n";
                $mailHeaders     .= "Content-type: text/plain; charset=utf-8" . "\n";
                $mailHeaders     .= "Content-Transfer-Encoding: 8bit" . "\n";
                $mailHeaders     .= "From: ". $global_config['admin_mail'] . "\n";
                $mailHeaders     .= "Reply-To: ". $global_config['admin_mail'] . "\n";
                $app->log('Sending quotanotify for $datau to $client["email"] because of $datab% usage on $domdat["domain"]') ;

                mail($client["email"], $subject, $mailtext, $mailHeaders);
                }
        }
        }
}
}
die("finished.\n");
?>
 

Werbung

Top