<?php
/*
Simple "SRCDS Demos archive" databaseless script
Copyright (C) 2011 CL0NE
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 3 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, see <http://www.gnu.org/licenses/>.
*/
/*
Configure server archives
[subfolder name without trailing '/']
title = [server title]
prefix = [demo file prefixes without trailing '-']
*/
$servers = array (
'/home/kid/servers/new-serv/css/cstrike/demos1' => array(
"title" => "CYBERVOLGA.Com Public Server #3",
"prefix" => "auto"
),
'/home/kid/servers/new-serv/css/cstrike/demos2' => array(
"title" => "CYBERVOLGA.Com Public Server #2",
"prefix" => "auto"
)
);
$filesPerPage = 20;
# Size in bytes
function format_size($size, $round = 0)
{
$sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
for ($i=0; $size > 1024 && isset($sizes[$i+1]); $i++)
$size /= 1024;
return round($size, $round)." ".$sizes[$i];
}
function browse($path)
{
global $servers;
global $filesPerPage;
$data = array();
$page = $_GET['page'];
$page = !isset($page) || $page < 1 ? 0 : $page - 1;
$prefix = $servers[$path]['prefix'];
$prefix_sz = strlen($prefix) + 1;
$offsets = array(
year => $prefix_sz,
month => $prefix_sz + 2,
day => $prefix_sz + 4,
hour => $prefix_sz + 9,
minute => $prefix_sz + 11,
map => $prefix_sz + 14
);
if(is_dir($path))
{
$files = glob($path."/*.dem.gz");
$count = count($files);
$pages = ceil( $count / $filesPerPage );
$page = $page >= $pages ? $pages - 1 : $page;
$begin = $count - ($page + 1) * $filesPerPage;
$end = $count - $page * $filesPerPage;
for($i = $begin < 0 ? 0 : $begin; $i < $end; ++$i)
{
$file = end( explode('/', $files[$i]) );
$name_end = strrpos($file, ".dem");
$name_end = $name_end === FALSE ? strrpos($file, ".gz") : $name_end;
$tmpfilesize = @filesize($files[$i]);
if($name_end === FALSE)
continue;
$tmp = array();
$tmp[year] = substr($file, $offsets[year], 4);
$tmp[month] = substr($file, $offsets[month], 2);
$tmp[day] = substr($file, $offsets[day], 2);
$tmp[hour] = substr($file, $offsets[hour], 2);
$tmp[minute] = substr($file, $offsets[minute], 2);
$tmp[map] = substr($file, $offsets[map], $name_end - $offsets[map]);
$tmp[file] = $file;
$tmp[size] = format_size($tmpfilesize);
$tmp[path] = $files[$i];
$data[] = $tmp;
}
$files = array();
}
echo '<table class="list" border="1" cellspacing="0" cellpadding="2">
<tr>
<th style="width: 25%; text-align: center;"> Карта</th>
<th style="width: 15%; text-align: center;"> Дата</th>
<th style="width: 9%; text-align: center;"> Время</th>
<th style="width: 10%; text-align: center;"> Размер</th>
<th style="text-align: center;"> Скачать</th>
</tr>';
if($count > 0)
{
$ll = 0;
foreach($data as $field)
{
echo '<tr'.($ll?' class="ll"':'').'>
<td style="text-align: center;">'.$field[map].'</td>
<td style="text-align: center;">'.$field[day].'.'.$field[month].'.'.$field[year].'</td>
<td style="text-align: center;">'.$field[hour].':'.$field[minute].'</td>
<td style="text-align: center;">'.$field[size].'</td>
<td style="text-align: center;"><a href="'.$field[path].'">'.$field[file].'</a></td>
</tr>';
$ll = !$ll;
}
}
else
{
echo '<tr><td class="ll" colspan="5" align="center">- Нет демо -</td></tr>';
}
echo '</table>';
if($pages > 1)
{
echo '<div class="pagination">';
for($i = 0; $i < $pages; ++$i)
{
if($pages > 10)
{
if($i > 2 && $i < $page - 1)
{
echo '...';
$i = $page - 1;
}
else
if($i > $page + 1 && $i > 2 && $i < $pages - 3)
{
echo '...';
$i = $pages - 3;
}
}
if($i != $page)
echo '<a href="?page='.($i + 1).'&server='.$path.'">'.($i + 1).'</a>';
else
echo '<span>'.($page + 1).'</span>';
}
echo '</div>';
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Cybervolga Demos</title>
<style type="text/css">
body
{
padding: 0px;
margin: 0px;
text-align: center;
background-color: #1F1F1F;
color: #6BA9BF;
font-size: 9pt;
font-family: sans-serif;
}
#wrapper
{
margin: 0 auto;
padding: 0em 0.5em;
max-width: 960px;
min-width: 760px;
width: auto !important;
}
#header
{
padding-bottom: 1em;
}
ul.menu
{
list-style-type: none;
margin: 0em;
margin-left: 1em;
border-left: solid 3px #3f6fEF;
padding: 0em;
font-size: 11pt;
float: left;
}
ul.menu li
{
padding-bottom: 1px;
border-right: solid 1px #313A3F;
border-bottom: solid 1px #313A3F;
float: left;
}
ul.menu li:hover
{
border-bottom: solid 1px #6BA9BF;
padding-bottom: 0px;
}
ul.menu li a
{
display: block;
padding: 3px 1em;
}
ul.menu a:hover
{
padding: 3px 1em 4px 1em;
background-color: #313A3F;
}
a
{
color: #6BA9BF !important;
text-decoration:none;
}
h1.title
{
clear: left;
text-shadow: 1px 1px 1px #666, -1px -1px 1px #000;
}
#content
{
min-height: 450px;
}
.list
{
width: 99%;
text-align: left;
border: #313A3F solid 1px;
}
.list th
{
border-bottom: solid 1px #313A3F;
color: #4F6F7F;
background: url('bgth.gif') repeat-x scroll center bottom #000;
color: #EFEFEF;
text-shadow: 1px 1px 1px #555, -1px -1px 1px #000;
}
.list tr:hover
{
background-color: #272F2F;
}
.list .ll
{
background-color: #313A3F;
}
.pagination
{
padding: 0.5em;
font-size: 1.5em;
}
.pagination a
{
text-decoration: underline;
margin: 0 0.2em;
}
.pagination span
{
margin: 0 0.1em;
padding: 0 0.1em;
background-color: #272F2F;
}
#footer
{
background-color: #272F2F;
border: 1px solid #3f3f3f;
padding: 1em;
margin: 1em 0em 0.25em 0em;
}
</style>
</head>
<body>
<div id="wrapper" align="center">
<div id="header">
<ul class="menu">
<li><a href="http://cybervolga.com/">Сайт</a></li>
<li><a href="http://cybervolga.com/forum/">Форум</a></li>
<li><a href="http://88.147.148.229/sb/">Банлист</a></li>
<li><a href="http://google.com./">В гугл?</a></li>
</ul>
<h1 class="title">SRCDS Demos</h1>
</div>
<div id="content">
<?php
if(is_array($servers))
{
$count = count($servers);
if($count > 1)
{
?>
<form action="" method="get">
<span style="font-weight: bold; font-size: 1.1em;">Server: </span>
<select name="server">
<?php
foreach ($servers as $key => $value)
{
echo '<option'.( $key == $_GET['server'] ? ' selected' : '').' value="'.$key.'">'.$value['title'].'</option>';
}
?>
</select>
<button type="submit">Go</button>
</form>
<?php
}
if($count == 1)
{
end($servers);
browse( key($servers) );
}
else if($count == 0)
{
echo "- Список серверов пуст -";
}
elseif( isset( $servers[$_GET['server']] ) )
browse($_GET['server']);
}
else
{
echo "- Скрипт не сконфигурирован -";
}
?>
</div>
<div id="footer">SRCDS demos archive. CYBERVOLGA.COM</div>
</div>
</body>
</html>