Inheritance: extends Request
Exemplo n.º 1
0
 /**
  * Returns the result of the given route's callable.
  *
  * @param string|null $method = new ServerRequest()->getMethod()
  * @param string|null $route = new ServerRequest()->getUri()->getPath()
  * @return mixed the result of the given route's callable.
  * @throws ServerResponseException
  */
 public function resolve($method = null, $route = null)
 {
     $serverRequest = new ServerRequest();
     if ($method === null) {
         $method = $serverRequest->getMethod();
     }
     if ($route === null) {
         $route = $serverRequest->getUri()->getPath();
     }
     if ($this->basePath !== '' && strpos($route, $this->basePath, 0) === 0) {
         $route = substr($route, strlen($this->basePath));
     }
     return $this->callCallable($this->getCallable($method, $route));
 }
Exemplo n.º 2
0
    public function testExecute()
    {
        // test func
        $this->setToken();
        $this->object->allow('min');
        $this->assertEquals(min($this->args), $this->object->execute());

        // test static method
        $sr = new ServerRequest(array('NonConstructorTest', 'staticTic'));
        $sr->allow('NonConstructorTest::staticTic');
        $this->assertEquals('toc', $sr->execute());

        $num = mt_rand();
        $add = mt_rand();
        $sr = new ServerRequest(array('ConstructorTest', 'getNum'), array($num, $add));
        $sr->allow('ConstructorTest::getNum');
        $this->assertEquals($num + $add, $sr->execute());
    }
/**
 * Credits to StackOverflow user: user2247350
 */
function getBrowserOS()
{
    $server = array('HTTP_USER_AGENT' => Request::REQUIRED);
    $request = new ServerRequest();
    $server = $request->extract($server);
    $server = arrayToJSONObject($server);
    $userAgent = $server->HTTP_USER_AGENT;
    $browser = "Unknown Browser";
    $OS = "Unknown OS Platform";
    // Get the Operating System Platform
    if (preg_match('/windows|win32/i', $userAgent)) {
        $OS = 'Windows';
        if (preg_match('/windows nt 6.2/i', $userAgent)) {
            $OS .= " 8";
        } else {
            if (preg_match('/windows nt 6.1/i', $userAgent)) {
                $OS .= " 7";
            } else {
                if (preg_match('/windows nt 6.0/i', $userAgent)) {
                    $OS .= " Vista";
                } else {
                    if (preg_match('/windows nt 5.2/i', $userAgent)) {
                        $OS .= " Server 2003/XP x64";
                    } else {
                        if (preg_match('/windows nt 5.1/i', $userAgent) || preg_match('/windows xp/i', $userAgent)) {
                            $OS .= " XP";
                        } else {
                            if (preg_match('/windows nt 5.0/i', $userAgent)) {
                                $OS .= " 2000";
                            } else {
                                if (preg_match('/windows me/i', $userAgent)) {
                                    $OS .= " ME";
                                } else {
                                    if (preg_match('/win98/i', $userAgent)) {
                                        $OS .= " 98";
                                    } else {
                                        if (preg_match('/win95/i', $userAgent)) {
                                            $OS .= " 95";
                                        } else {
                                            if (preg_match('/win16/i', $userAgent)) {
                                                $OS .= " 3.11";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        if (preg_match('/macintosh|mac os x/i', $userAgent)) {
            $OS = 'Mac';
            if (preg_match('/macintosh/i', $userAgent)) {
                $OS .= " OS X";
            } else {
                if (preg_match('/mac_powerpc/i', $userAgent)) {
                    $OS .= " OS 9";
                }
            }
        } else {
            if (preg_match('/linux/i', $userAgent)) {
                $OS = "Linux";
            }
        }
    }
    // Override if matched
    if (preg_match('/iphone/i', $userAgent)) {
        $OS = "iPhone";
    } else {
        if (preg_match('/android/i', $userAgent)) {
            $OS = "Android";
        } else {
            if (preg_match('/blackberry/i', $userAgent)) {
                $OS = "BlackBerry";
            } else {
                if (preg_match('/webos/i', $userAgent)) {
                    $OS = "Mobile";
                } else {
                    if (preg_match('/ipod/i', $userAgent)) {
                        $OS = "iPod";
                    } else {
                        if (preg_match('/ipad/i', $userAgent)) {
                            $OS = "iPad";
                        }
                    }
                }
            }
        }
    }
    // Get the Browser
    if (preg_match('/msie/i', $userAgent) && !preg_match('/opera/i', $userAgent)) {
        $browser = "Internet Explorer";
    } else {
        if (preg_match('/firefox/i', $userAgent)) {
            $browser = "Firefox";
        } else {
            if (preg_match('/chrome/i', $userAgent)) {
                $browser = "Chrome";
            } else {
                if (preg_match('/safari/i', $userAgent)) {
                    $browser = "Safari";
                } else {
                    if (preg_match('/opera/i', $userAgent)) {
                        $browser = "Opera";
                    } else {
                        if (preg_match('/netscape/i', $userAgent)) {
                            $browser = "Netscape";
                        }
                    }
                }
            }
        }
    }
    // Override if matched
    if ($OS == "iPhone" || $OS == "Android" || $OS == "BlackBerry" || $OS == "Mobile" || $OS == "iPod" || $OS == "iPad") {
        if (preg_match('/mobile/i', $userAgent)) {
            $browser = "Handheld Browser";
        }
    }
    // Create a Data Array
    $returnData = ['browser' => $browser, 'OS' => $OS];
    return arrayToJSONObject($returnData);
}
Exemplo n.º 4
0
 function __construct($contentfield = NULL, $namefield = NULL, $mailfield = NULL, $urifield = NULL)
 {
     if ($contentfield && isset($_POST[$contentfield])) {
         $contentfield = $_POST[$contentfield];
     }
     if ($namefield && isset($_POST[$namefield])) {
         $namefield = $_POST[$namefield];
     }
     if ($mailfield && isset($_POST[$mailfield])) {
         $mailfield = $_POST[$mailfield];
     }
     if ($urifield && isset($_POST[$urifield])) {
         $urifield = $_POST[$urifield];
     }
     parent::__construct($contentfield, $namefield, $mailfield, $urifield, ServerRequest::getRequestIPs());
 }
Exemplo n.º 5
0
require_once WWW_DIR . '/classes/ServerRequest.php';

// include valid callbacks files
// TODO replace with Zend_Loader
require_once WWW_DIR . '/classes/Extension/WidgetManager.php';
require_once LIBS_DIR . '/ArticleList/ArticleList.php';
require_once LIBS_DIR . '/MediaList/MediaList.php';
require_once LIBS_DIR . '/ImageList/ImageList.php';
require_once WWW_DIR . '/classes/GeoNames.php';
require_once WWW_DIR . '/classes/GeoMap.php';
require_once WWW_DIR . '/classes/Article.php';
require_once WWW_DIR . '/classes/ArticleData.php';

try {
    // init request
    $serverRequest = new ServerRequest($_POST['callback'],
        (array) $_POST['args']);

    // set permissions
    $serverRequest->allow('ping');
    $serverRequest->allow('ArticleList::doAction'); // checked in handler
    $serverRequest->allow('ArticleList::doData');
    $serverRequest->allow('ArticleList::getFilterIssues');
    $serverRequest->allow('ArticleList::getFilterSections');
    $serverRequest->allow('ArticleList::doOrder', 'Publish');
    $serverRequest->allow('WidgetManager::AddWidget');
    $serverRequest->allow('WidgetManagerDecorator::delete');
    $serverRequest->allow('WidgetRendererDecorator::render');
    $serverRequest->allow('WidgetManagerDecorator::getSetting');
    $serverRequest->allow('WidgetContext::setWidgets');
    $serverRequest->allow('WidgetManagerDecorator::update');
    $serverRequest->allow('Topic::UpdateOrder');
Exemplo n.º 6
0
 protected function postFromRow(array $r)
 {
     d($r, 'creating new post from row');
     assert('!empty($r["id"])');
     assert('!empty($r["headers"])');
     assert('!empty($r["path"])');
     assert('!empty($r["timestamp"])');
     assert('array_key_exists("name",$r)');
     assert('isset($r["content"])');
     assert('isset($r["ip"])');
     $heads = array();
     foreach (explode("\n", $r['headers']) as $h) {
         if (preg_match("!(.*?):\\s*(.*)!", $h, $o)) {
             $heads[$o[1]] = $o[2];
         }
     }
     if (!isset($heads['HTTP_HOST'])) {
         $heads['HTTP_HOST'] = $r['host'];
     }
     if ($r['ip']) {
         $heads['REMOTE_ADDR'] = long2ip($r['ip']);
     }
     $post = new SblamBasePost($r['content'], $r['name'], $r['email'], $r['url'], ServerRequest::getRequestIPs($heads, true));
     $post->setSpamReason($r['spamreason']);
     $post->setSpamScore(array($r['spamscore'] / 100, $r['spamcert'] / 100));
     $post->setPostId($r['id']);
     $post->setHeaders($heads);
     $post->setTime($r['timestamp']);
     $post->setPath($r['path']);
     $post->setInstallId($r['serverid']);
     $post->bayesadded = $r['added'];
     $post->manualspam = $r['manualspam'];
     $post->worktime = $r['worktime'];
     $post->account = $r['account'];
     $post->profiling = $r['profiling'];
     $postarr = array();
     if ($r['post']) {
         foreach (explode("\n", $r['post']) as $pline) {
             if (preg_match("!^([^:]+): ?(.*)\$!", $pline, $out)) {
                 $postarr[$out[1]] = $out[2];
             }
         }
         $post->setPost($postarr);
     }
     return $post;
 }
Exemplo n.º 7
0
 public function testWithoutAttribute()
 {
     $request = new ServerRequest();
     $new = $request->withAttribute("attr", "val");
     $this->assertNotSame($request, $new);
     $this->assertEquals(["attr" => "val"], $new->getAttributes());
     $changed = $new->withoutAttribute("attr");
     $this->assertNotSame($new, $changed);
     $this->assertEmpty($changed->getAttributes());
 }
Exemplo n.º 8
0
 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]) : '');
 }