~grubng-dev/grubng/servers-dispatch-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
<?php

$directory = '/home/bartek/grub/sitemaps';
@include("config.php");
require("login.php");

if ($_SERVER['REQUEST_METHOD'] == "PUT")
{ 
  if (!isset($_SERVER['PHP_AUTH_USER'])) 
    {
      header('WWW-Authenticate: Basic realm="GrubNG"');
      header('HTTP/1.0 401 Unauthorized');
      echo 'Authorization required';
      exit;
    }

  if ( ! check_login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) ) {
      header('HTTP/1.0 401 Unauthorized');
      echo 'Bad username or password.';
      exit;
  }


  $sitemapdir = $directory."/" . $_SERVER['PHP_AUTH_USER'] . "/";
  if (!file_exists($sitemapdir))
  {
    mkdir($sitemapdir);
  }
  $extensions = substr($_SERVER['REQUEST_URI'], -6);
  if ($extensions != "xml.gz")
    {
      header('HTTP/1.0 406 Not Acceptable');
      echo 'Invalid sitemap file.';
      exit;
    }
  $s = fopen("php://input", "r");
  $f = fopen($sitemapdir.basename($_SERVER['REQUEST_URI']), "w");
  while($data = fread($s, 1024))
    { 
      fwrite($f, $data); 
    }
  fclose($f);
  fclose($s);
  Header("HTTP/1.1 200 Created"); 
  echo "Uploaded.";
}