<?
////////////////////////////////////////////////////////////////////////
/*SMI - SHOUTcast Management Interface
A web based shoutcast server management program
Founding Author: Scott D. Harvanek <scotth@sourcemirrors.org>

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.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.*/
////////////////////////////////////////////////////////////////////////

$id = $_REQUEST['id'];
$port = $_REQUEST['port'];
$srvname = $_REQUEST['srvname'];

$db = dbConnect();
$config = settings();
//////////////////////////////////////////
//
//Stop the server before deleting it.
//
//////////////////////////////////////////

stopstream($id);

// Delete  server's configuration and process id
deletefile($config['smi_path']."/servers/".$port.$srvname.".conf");
deletefile($config['smi_path']."/servers/".$port.$srvname.".pid");

// Delete server's MRTG related files
deletefile($config['smi_path']."/mrtg/".$port.$id.".log");
deletefile($config['smi_path']."/mrtg/".$port.$id.".old");
deletefile($config['smi_path']."/mrtg/".$port.$id.".html");
deletefile($config['smi_path']."/mrtg/".$port.$id."-day.png");
deletefile($config['smi_path']."/mrtg/".$port.$id."-week.png");
deletefile($config['smi_path']."/mrtg/".$port.$id."-month.png");
deletefile($config['smi_path']."/mrtg/".$port.$id."-year.png");

// Delete server's log files
deletefile($config['smi_path']."/logs/".$port.$srvname.".log");
deletefile($config['smi_path']."/logs/".$port.$srvname.".w3c.log");

// Delete server's AutoDJ related files
deletefile($config['smi_path']."/ices/".$id.".".$port.".conf");
deletefile($config['smi_path']."/ices/".$id.".pls.php");
deletefile($config['smi_path']."/ices/".$id.".".$port.".pid");

// Delete server from database
$db->delete('servers', array('PortBase' => $port, 'id' => $id));

// Add to event log
$event = " Deleted server on port $port";
addevent($_SESSION['username'],$event);
echo "<b>Server with port base ".$port." is deleted.</b>";
echo "<br><br>Click <a href=\"home.php\">here</a> to return to the front page.";

// Remove server's port and regenerate MRTG
cleanmrtg($port);
generatemrtg();
?>
