function process(ServerRequest $req) { $starttime = microtime(true); $data = $req->getData(); if ($data['ip'] == '127.0.0.1' && $req->isDefaultAccount()) { throw new ServerException('Brak klucza API', 403); } $fs = isset($data['fields']) ? explode("\n", strtolower($data['fields'])) : array(); $postdata = array(); foreach ($data as $key => $val) { if (substr($key, 0, 5) === 'POST_') { $postdata[strtolower(substr($key, 5))] = $val; } if (substr($key, 0, 6) === 'field_') { $fs[substr($key, 6)] = $val; } } list($content, $author, $email, $url) = $this->findFields($postdata, $fs); /* short-circuit filtering for testing */ if (preg_match('!^[^a-z]*to\\s+jest\\s+test\\s+(sblam|spam)[ua]?[^a-z]*$!i', $content)) { $req->returnResult(1); return; } $p = $this->postFromFields($data, $postdata, $content, $author, $email, $url, $req->getIPs()); if (!$req->storeData($p)) { dieerr(500, "Awaria bazy danych"); } $config = $req->customizeConfig($this->config); $sblam = new Sblam($config, $this->services); $rawresult = $sblam->testPost($p); list($score, $cert, $reason) = $rawresult; $endtime = microtime(true); if ($content == '' && $author == '') { $req->returnResult(1); } else { if ($cert < 0.45 || abs($score) < 0.38) { $req->returnResult($score > 0 ? 1 : -1); } else { $req->returnResult($score > 0 ? 2 : -2); } } set_time_limit(25); $rawresult = $sblam->reportResult($p, $rawresult); $req->storeResult($score, $cert, $reason, $endtime - $starttime, empty($p->bayesadded) ? 0 : 6, isset($rawresult[3]) ? Sblam::formatProfiling($rawresult[3]) : ''); }
$host_id = $res->fetch()["id"]; if (!isset($_POST["username"]) || !isset($_POST["apikey"])) { dieerr("Username and API key are needed!"); } $apikey = $_POST["apikey"]; $res = db_query("SELECT * FROM users WHERE username=?", [$_POST["username"]]); if ($res->rowCount() === 0) { dieerr("There is no user by that name!"); } $arr = $res->fetch(); if ($arr["apikey"] !== $apikey) { dieerr("API key provided is invalid for user!"); } $user_id = $arr["id"]; if (!isset($_FILES["image"])) { dieerr("No image file given!"); } $filename = $_FILES["image"]["name"]; $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); $hash = sha1_file($_FILES["image"]["tmp_name"]); $slug = null; $good = false; while (!$good) { $good = true; $slug = generateRandomString(7); $sres = db_query("SELECT * FROM images WHERE slug=?", [$slug]); if ($sres->rowCount() > 0) { $good = false; } } if (!in_array($ext, array("gif", "png", "jpg", "jpeg"))) {