remove.cgi

私はPerlについてはまるで素人なので、稚拙なのでしょうが、playing.cgiから引数id=で渡された番号の行を削除します。


#!/usr/bin/perl -w

# ==[ remove.cgi ]===================================================== #
# #
# a part of the icecast shout_tools package by nathan strom #
# #
# contact e-mail: nstrom@andrew.cmu.edu #
# url: http://www.andrew.cmu.edu/~nstrom/ #
# #
# ====================================================================== #
# #
# 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. #
# #
# ====================================================================== #
# last updated: 07-01-2001 #
# ====================================================================== #

use CGI;

# modify the next three lines to fit your system configuration

$SHOUTPLAYLIST = "/var/shout/shout.playlist";

# modify the next line to point to your "success" url

$SUCCESS_URL = "http://localhost/cgi-bin/playing.cgi";

$query = new CGI;

$id = $query->param('id');
die("error: id must be non-negative") if $id <= 0;

$i = 0;

open(SHOUTPLAYLIST, $SHOUTPLAYLIST) or die("error: cannot open $SHOUTPLAYLIST");
open(TMP, ">/tmp/shout.playlist");
while(<SHOUTPLAYLIST>) {
$i++;
if($i != $id) {
print TMP $_;
}
}
close(TMP);
close(SHOUTPLAYLIST);
system("mv \/tmp\/shout\.playlist -f $SHOUTPLAYLIST");

print "Location: $SUCCESS_URL\n\n";


returnReturn