-
Notifications
You must be signed in to change notification settings - Fork 12
/
handler.php
executable file
·60 lines (53 loc) · 1.81 KB
/
handler.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
<?php
/**
* This file is part of GtkGrab.
*
* GtkGrab 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; version 3 of the License.
*
* GtkGrab 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 GtkGrab. If not, see <http://www.gnu.org/licenses/>.
*
* @category GtkGrab
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPL
* @copyright Copyright 2010 Evan Coury (http://www.Evan.pro/)
* @copyright Copyright 2010 Pieter Kokx (http://blog.kokx.nl/)
* @package Server
*/
// must be in the format 'user' => 'token'
$users = array('myuser' => 'mypass');
// read the input
$input = file_get_contents("php://input");
// verify the user
if (!isset($_SERVER['HTTP_X_USERNAME']) || !isset($users[$_SERVER['HTTP_X_USERNAME']])) {
exit('Error: No authorization');
}
$token = $users[$_SERVER['HTTP_X_USERNAME']];
if (!isset($_SERVER['HTTP_X_SIGNATURE']) || ($_SERVER['HTTP_X_SIGNATURE'] != sha1($input . $token))) {
exit('Error: No authorization');
}
// write the file
function generateFilename()
{
return substr(md5(microtime()),0,6);
}
do {
$filename = 'caps/'.generateFilename().'.png';
} while(file_exists($filename));
file_put_contents($filename, base64_decode($input));
if (isset($_SERVER['FCGI_ROLE'])) {
$path = $_SERVER['REQUEST_URI'];
} else {
$path = $_SERVER['PHP_SELF'];
}
$path = trim(dirname($path), '/');
if (strlen($path) > 0) {
$path .= '/';
}
echo 'http://' . $_SERVER['HTTP_HOST'] . '/' . $path . $filename;