Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nsmle committed Apr 12, 2022
0 parents commit c24cdd5
Show file tree
Hide file tree
Showing 9 changed files with 381 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
vendor/
tests/
composer.lock
php-cs-fixer.php
.php-cs-fixer.cache
.phpunit.result.cache
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Fiki Pratama

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Ouo.io Bypass


A PHP library to bypass short links [ouo.io](https://ouo.io) or [ouo.press](https://ouo.press).

If you like or use this package, please share your love by starring this repository, or follow [@nsmle](https://github.com/nsmle).

## Installation
```bash
composer require nsmle/ouo-bypass
```

## Usage
```php
require 'vendor/autoload.php';

use Nsmle\OuoBypass\Api;

$ouo = new Api();
$ouo->setOriginUrl("https://ouo.press/ZGawzS");
$ouo->bypass();
$link = $ouo->getDestinationUrl();

echo $link;
```

Or if you want something simpler you can try some code like below:

```php
$ouo = new Api("https://ouo.press/ZGawzS");
$ouo->bypass();
$link = $ouo->getDestinationUrl();
```
or
```php
$ouo = new Api("https://ouo.press/ZGawzS");
$link = $ouo->bypass()['destination-url'];
```

## License

Licensed under the terms of the [MIT License](https://github.com/nsmle/ouo-bypass/blob/main/LICENSE).
45 changes: 45 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "nsmle/ouo-bypass",
"description": "A PHP library to bypass ouo.io/press short links",
"type": "library",
"keywords": [
"shortlink",
"ouo.io",
"ouo.press",
"php",
"ouo-bypass",
"shorlink-bypass"
],
"homepage": "https://github.com/nsmle/ouo-bypass",
"license": "MIT",
"autoload": {
"psr-4": {
"Nsmle\\OuoBypass\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Nsmle\\OuoBypass\\Test\\": "tests/"
}
},
"authors": [
{
"name": "nsmle",
"email": "fikiproductionofficial@gmail.com"
}
],
"require": {
"guzzlehttp/guzzle": "^6.0|^7.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "dev-master",
"phpunit/phpunit": "10.0.x-dev",
"friendsofphp/php-cs-fixer": "dev-master"
},
"scripts": {
"fix": "php ./vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix src/ --allow-risky=yes --config=php-cs-fixer.php",
"check": "php ./vendor/bin/phpcs src/ --standard=PSR12",
"test": "php ./vendor/bin/phpunit --no-coverage",
"coverage": "php ./vendor/bin/phpunit"
}
}
93 changes: 93 additions & 0 deletions src/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

/**
* ouo-bypass
*
* @see https://github.com/nsmle/ouo-bypass/ The ouo-bypass GitHub project
* @author Fiki Pratama (nsmle) <fikiproductionofficial@gmail.com>
*/

declare(strict_types=1);

namespace Nsmle\OuoBypass;

use Nsmle\OuoBypass\Exception\OuoException;
use Nsmle\OuoBypass\Utils\HtmlParse;
use Nsmle\OuoBypass\Utils\Request;
use Nsmle\OuoBypass\Utils\UrlHelper;

class Api extends Request
{
/**
* @var originUrl
*/
private $originUrl;

/**
* @var destinationUrl
*/
private $destinationUrl;

/**
* @param string $originUrl|null
*/
public function __construct(string $originUrl = null)
{
parent::__construct();
$this->originUrl = $originUrl;
}

/**
* @throws OuoException
*/
public function bypass(): array
{
if (empty($this->originUrl)) {
throw new OuoException('Empty originUrl or unset originUrl.
see https://github.com/nsmle/ouo-bypass/#usage');
}

$tempUrl = UrlHelper::getTempUrl($this->originUrl);
$nextUrl = UrlHelper::getNextUrl('go', $tempUrl);

$res = $this->fetchData($tempUrl);
$htmlContent = (string) $res;

$data = HtmlParse::parseInputDataForm($htmlContent);

for ($i = 0; $i <= 2; ++$i) {
$res = $this->postData($nextUrl, $data, array('allow_redirects' => false));

if (!empty($res->getHeaderLine('Location'))) {
break;
}

$nextUrl = UrlHelper::getNextUrl('xreallcygo', $tempUrl);
}

$this->destinationUrl = $res->getHeaderLine('Location');

return array(
'origin-url' => $this->originUrl,
'destination-url' => $this->destinationUrl,
);
}

/**
* @param string originUrl
*/
public function setOriginUrl(string $originUrl): void
{
$this->originUrl = $originUrl;
}

public function getOriginUrl(): string
{
return $this->originUrl;
}

public function getDestinationUrl(): string
{
return $this->destinationUrl;
}
}
16 changes: 16 additions & 0 deletions src/Exception/OuoException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* ouo-bypass
*
* @see https://github.com/nsmle/ouo-bypass/ The ouo-bypass GitHub project
* @author Fiki Pratama (nsmle) <fikiproductionofficial@gmail.com>
*/

declare(strict_types=1);

namespace Nsmle\OuoBypass\Exception;

final class OuoException extends \Exception
{
}
43 changes: 43 additions & 0 deletions src/Utils/HtmlParse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* ouo-bypass
*
* @see https://github.com/nsmle/ouo-bypass/ The ouo-bypass GitHub project
* @author Fiki Pratama (nsmle) <fikiproductionofficial@gmail.com>
*/

declare(strict_types=1);

namespace Nsmle\OuoBypass\Utils;

use Nsmle\OuoBypass\Exception\OuoException;

class HtmlParse
{
/**
* @param string htmlContent
*/
public static function parseInputDataForm(string $htmlContent): array
{
if (preg_match('/LINK NOT FOUND/i', $htmlContent)) {
throw new OuoException('Link Not found,
please double check and enter valid link from domain host ouo.io or ouo.press.');
}

preg_match_all('/<input (.*?)>/i', $htmlContent, $inputs);
$data = array();
foreach ($inputs[0] as $input) {
$input = preg_replace('/"/', '', $input);

preg_match('/name=(.*?)\s/', $input, $inputName);
preg_match('/value=(.*?)>/', $input, $inputValue);

$data = array_merge($data, array(
$inputName[1] => $inputValue[1],
));
}

return $data;
}
}
71 changes: 71 additions & 0 deletions src/Utils/Request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/**
* ouo-bypass
*
* @see https://github.com/nsmle/ouo-bypass/ The ouo-bypass GitHub project
* @author Fiki Pratama (nsmle) <fikiproductionofficial@gmail.com>
*/

declare(strict_types=1);

namespace Nsmle\OuoBypass\Utils;

use GuzzleHttp\Client;
use GuzzleHttp\Cookie\SessionCookieJar;

class Request
{
/**
* @var client
*/
public $client;

public function __construct()
{
$jar = new SessionCookieJar('PHPSESSID', true);
$this->client = new Client(array('cookies' => $jar));
}

/**
* @param string endpoint
*/
public function fetchData(string $endpoint): object
{
$headers = array(
'headers' => array(
'content-type' => 'application/x-www-form-urlencoded',
),
);

$res = $this->client->request('GET', $endpoint, $headers);

return $res->getBody();
}

/**
* @param string endpoint
* @param array formParameters
* @param array opt
*/
public function postData(string $endpoint, array $formParameters = array(), array $opt = array()): object
{
$options = array(
'headers' => array(
'content-type' => 'application/x-www-form-urlencoded',
),
);

if (count($formParameters) > 0) {
$options = array_merge($options, array(
'form_params' => $formParameters,
));
}

if (count($opt) > 0) {
$options = array_merge($options, $opt);
}

return $this->client->request('POST', $endpoint, $options);
}
}
44 changes: 44 additions & 0 deletions src/Utils/UrlHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* ouo-bypass
*
* @see https://github.com/nsmle/ouo-bypass/ The ouo-bypass GitHub project
* @author Fiki Pratama (nsmle) <fikiproductionofficial@gmail.com>
*/

declare(strict_types=1);

namespace Nsmle\OuoBypass\Utils;

use Nsmle\OuoBypass\Exception\OuoException;

class UrlHelper
{
/**
* @throws OuoException
*/
public static function getTempUrl(string $url): string
{
if (!preg_match('/(ouo.press|ouo.io)/', $url)) {
throw new OuoException('This short link is not from ouo.press nor ouo.io, please check and try again.');
}

return str_replace('ouo.press', 'ouo.io', $url);
}

/**
* @throws OuoException
*/
public static function getNextUrl(string $path, string $url): string
{
if (!preg_match('/(ouo.press|ouo.io)/', $url)) {
throw new OuoException('This short link is not from ouo.press nor ouo.io, please check and try again.');
}

$uriParse = parse_url($url);
$id = str_replace('/', '', $uriParse['path']);

return "{$uriParse['scheme']}://{$uriParse['host']}/{$path}/{$id}";
}
}

0 comments on commit c24cdd5

Please sign in to comment.