This repository has been archived by the owner on Jun 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wads.php
153 lines (142 loc) · 4.17 KB
/
wads.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
include dirname(dirname(__FILE__)) . '/common/pages.php';
include dirname(dirname(__FILE__)) . '/common/wads.php';
include dirname(dirname(__FILE__)) . '/config/config.php';
function human_filesize($bytes, $decimals = 2)
{
$sz = ' KMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f %sB", $bytes / pow(1024, $factor), @$sz[$factor]);
}
?>
<?php sn_page_header('WADs'); ?>
<?php sn_page_start_container(); ?>
<script src='/assets/wadshared.js'></script>
<script>
function err(e) {
$('#ss-err-box').hide();
$('#ss-err-box').html('');
$('#js-err-box').hide();
$('#js-err-box').show();
$('#js-err-box').html(e);
}
function derr() {
$('#ss-err-box').hide();
$('#ss-err-box').html('');
$('#js-err-box').hide();
$('#js-err-box').html('');
}
function wadupload() {
$('#clickme').click();
$('#clickme').change(function() {
derr();
$('#clickmetoo').click();
$('#upload-button').text('Uploading, please wait...');
$('#upload-button').prop('disabled', true);
// update_progress();
});
}
function update_progress() {
$.post('/api/wads.php',
{
'fn': 'upload_progress',
'formname': $('#__form_name').val()
})
.done(function(d) {
var split = d.split(' ');
if (split.length == 1) {
$('#upload-button').text('Uploading — ' + d + '%');
setTimeout(function() {
update_progress();
}, 100);
} else {
var code = split.shift();
var l = split.join(' ');
$('#upload-button').text(code + ' ' + l);
}
})
.fail(function(d) {
if (d.status == 400) {
var msg = d.responseText.split(' ');
var code = msg.shift();
msg = msg.join(' ');
err('<strong>API Error ' + code + '</strong><br/>' + msg);
} else {
err('Failed import.<br />' + d.status + ' ' + d.statusText);
}
});
}
</script>
<h1>WADs</h1>
<?php
if (is_authed())
{
$type = (isset($_GET['ok']) ? 'ok' : 'err');
$c = '';
if (isset($_GET['ok']))
{
$c = "Uploaded file <code>" . $_GET['ok'] . "</code> successfully.";
}
elseif (isset($_GET['exists']))
{
$c = "File <code>" . $_GET['exists'] . "</code> already exists on the server.";
}
elseif (isset($_GET['iwad']))
{
$c = "You are not allowed to upload commerical IWADs.";
}
elseif (isset($_GET['unknownerror']))
{
$c = "An unknown error occured while uploading <code>" . $_GET['exists'] . "</code>.";
}
elseif (isset($_GET['badext']))
{
$c = "The file type <code>" . $_GET['badext'] . "</code> is not supported..";
}
else
{
$c = null;
}
$h = '';
if ($c == null)
{
$h = "<div class='submit-$type-box' id='ss-err-box' style='display:none'>";
}
else
{
$h = "<div class='submit-$type-box' id='ss-err-box'>";
}
echo $h;
echo $c;
echo "</div>";
?>
<div class='submit-err-box' id='js-err-box' style='display:none'></div>
<form action='/api/wads.php' method='POST' id='upform' enctype='multipart/form-data'>
<input type='hidden' name='doup' value='true' />
<input type='hidden' name='fn' value='upload' />
<div style='width:100%;display:table'>
<div id='upload-button' onclick='wadupload()'>Upload</div>
</div>
<div style='width:100%;text-align:center;margin-top:4px;font-size:10pt'>
Maximum size file 250MB.
<br />
Supported formats are <code>wad</code>, <code>pk3</code>, and <code>pk7</code>.
</div>
<input type='hidden' id='__form_name' value='form<?=mt_rand() + time();?>' name='<?php echo ini_get('session.upload_progress.name'); ?>'>
<input type='file' name='file' style='display: none' id='clickme' />
<input type='submit' name='sb' style='display: none' value='Upload' id='clickmetoo' />
</form>
<br /><hr /><br />
<?php
}
?>
<div id='serverboxhead'>
<h3>Most Recent WADs</h3>
<div id='right'>
<input type='button' value='View All' onclick='document.location="/wads/all"'/>
</div>
</div>
<?php display_wad_table(20); ?>
<?php sn_page_cfooter(); ?>
<?php sn_page_end_container(); ?>
<?php sn_page_footer(); ?>