$user = "1c_user";
$pass = "1c_pass";
$path = "upload/";
if (!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER["PHP_AUTH_PW"]) && !isset($_REQUEST["type"])) {
header('WWW-Authenticate: Basic realm="1C-Exchange"');
header('HTTP/1.0 401 Unauthorized');
$_SESSION["login"] = false;
die("failure");
}
if (($_SERVER["PHP_AUTH_USER"] == $user && $_SERVER["PHP_AUTH_PW"] == $pass) || $_SESSION["login"]) {
$_SESSION["login"] = true;
if ($_REQUEST["type"] == "catalog") {
switch ($_REQUEST["mode"]):
case "checkauth":
die("success");
break;
case "init":
die("zip=no" . "\r\n" . "file_limit=0");
break;
case "file":
$filename = (strpos($_REQUEST["filename"], ".") == 0) ? substr($_REQUEST["filename"], 1) : $_REQUEST["filename"];
$dirname = dirname($path . $filename);
if (!is_dir($dirname))
mkdir($dirname, 0755, true);
$file = fopen($path . $filename, 'ab') or die("failure");
fwrite($file, file_get_contents('php://input'));
fclose($file);
die("success");
break;
endswitch;
}
if ($_REQUEST["type"] == "sale") {
}
} else {
header('WWW-Authenticate: Basic realm="1C-Exchange"');
header('HTTP/1.0 401 Unauthorized');
$_SESSION["login"] = false;
die("failure");
}