Skip to content

Commit

Permalink
Add Ban china browser, fix some language errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ellermister committed Nov 17, 2023
1 parent 34b82f1 commit 50b67a8
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 46 deletions.
42 changes: 24 additions & 18 deletions lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
'Firewall' => '拦截器',
'Endpoint' => '跳转方式',

'normal' => '原始',
'no referer' => '无Referer',
'encrypt redirect' => '加密跳转',
'Normal' => '原始',
'No referer' => '无Referer',
'Encrypt redirect' => '加密跳转',
'Fake page' => '伪装页面',
'redirect once' => '阅后即焚',
'password access' => '密码访问',
'whisper text' => '附加图文',
'Redirect once' => '阅后即焚',
'Password access' => '密码访问',
'Whisper text' => '附加图文',
'PC access only' => '仅限PC访问',
'Mobile access only' => '仅限手机访问',
'Ban China Browser' => '屏蔽中国大陆浏览器',

'Jump directly to the website' => '直接跳转到目标网站',
'No Referer parameter' => '无 Referer 参数,目标网站无法获取来源站地址',
Expand All @@ -39,8 +40,10 @@
'Append rich text information' => '附加富文本信息,您可以在此留言并分享给您的其他社交媒体用户',
'Only PC users can access this page' => '仅限PC用户访问该地址',
'Only Mobile users can access this page' => '仅限手机用户访问该地址',
'mainland China access only' => '仅限中国大陆访问',
'Mainland China access only' => '仅限中国大陆访问',
'Non-mainland China access only' => '仅限非中国大陆访问',
'Please use a non-China browser' => '请使用安全浏览器访问: 如 Chrome, Edge, Firefox',
'Please copy this link to open in other browsers' => '请复制这个链接到其他浏览器打开',

'Access only to users in mainland China' => '仅限中国大陆用户访问',
'Only access users who are not in mainland China' => '仅限非中国大陆用户访问',
Expand Down Expand Up @@ -68,17 +71,20 @@
'Firewall' => 'ファイアウォール',
'Endpoint' => '終点',

'normal' => 'デフォルト',
'no referer' => '「Referer」パラメータなし',
'encrypt redirect' => '暗号化されたアクセス',
'Fake Page' => '偽のウェブページ',
'redirect once' => '1回限りの訪問',
'password access' => 'パスワードの検証',
'whisper text' => '追加テキスト',
'PC access only' => 'PCアクセスのみ',
'Mobile access only' => 'モバイルアクセスのみ',
'mainland China access only' => '中国本土のユーザーのみがアクセス可能',
'Non-mainland China access only' => '中国本土以外のユーザーに限定',
'Normal' => 'デフォルト',
'No referer' => '「Referer」パラメータなし',
'Encrypt redirect' => '暗号化されたアクセス',
'Fake Page' => '偽のウェブページ',
'Redirect once' => '1回限りの訪問',
'Password access' => 'パスワードの検証',
'Whisper text' => '追加テキスト',
'PC access only' => 'PCアクセスのみ',
'Mobile access only' => 'モバイルアクセスのみ',
'Mainland China access only' => '中国本土のユーザーのみがアクセス可能',
'Non-mainland China access only' => '中国本土以外のユーザーに限定',
'Ban China Browser' => '中国のブラウザを禁止する',
'Please use a non-China browser' => '中国以外のブラウザを使用してください',
'Please copy this link to open in other browsers' => '他のブラウザで開くには、このリンクをコピーしてください',

'Jump directly to the website' => 'ターゲットのWebサイトに直接ジャンプします',
'No Referer parameter' => '「Referer」パラメータがないと、ターゲットWebサイトは送信元ステーションのアドレスを取得できません',
Expand Down
35 changes: 21 additions & 14 deletions libs/EncryptTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,74 @@ class EncryptTool
{

/**
* 兼容UTF8字符并与JS加密解密通用的方法
* Compatibility method for handling UTF-8 characters and common encryption/decryption in JavaScript.
*
* key 不支持utf8字符
* Note: The key does not support UTF-8 characters.
*
* @param $key
* @param $plaintext
* @param string $key
* @param string $plaintext
* @return string
*/
public static function encrypt($key, $plaintext): string
{
$cypherText = [];
// 转换为十六进制以正确处理UTF8
// Convert to hexadecimal to correctly handle UTF-8
$plaintext = implode('', array_map(function ($c) {
if (ord($c) < 128) {
return dechex(ord($c));
} else {
return bin2hex($c);
// return strtolower(rawurlencode($c));
// return strtolower(rawurlencode($c));
}
}, preg_split('//u', $plaintext, -1, PREG_SPLIT_NO_EMPTY)));


// 将每个十六进制转换为十进制
// Convert each hexadecimal to decimal
$plaintext = array_map('hexdec', str_split($plaintext, 2));

// 执行异或运算
// Perform XOR operation
for ($i = 0; $i < count($plaintext); $i++) {
$cypherText[] = $plaintext[$i] ^ ord($key[($i % strlen($key))]);
}

// 转换为十六进制, pad 2
// Convert to hexadecimal, pad 2
$cypherText = array_map(function ($x) {
return sprintf("%02X", $x);
// return dechex($x);
}, $cypherText);
return implode('', $cypherText);
}

/**
* Decrypts the given ciphertext using the specified key.
*
* @param string $key
* @param string $cypherText
* @return string|bool The decrypted plaintext or false on failure.
*/
static function decrypt($key, $cypherText)
{
try {
// 将十六进制字符串转换为整数数组
// Convert hexadecimal string to an array of integers
$cypherText = array_map('hexdec', str_split($cypherText, 2));

$plaintext = [];

for ($i = 0; $i < count($cypherText); $i++) {
// 进行异或运算,并转换为十六进制字符串
// Perform XOR operation and convert to hexadecimal string
$plaintext[] = dechex($cypherText[$i] ^ ord($key[($i % strlen($key))]));
}

// 将十六进制字符串转换为URL编码的字符串
// Convert hexadecimal string to URL-encoded string
$decodedPlaintext = '%' . implode('%', $plaintext);
// 将URL编码的字符串解码为原始字符串
// Decode URL-encoded string to the original plaintext
return rawurldecode($decodedPlaintext);
} catch (\Exception $e) {
return false;
}
}



const ENCRYPT_METHOD = 'AES-128-CBC';


Expand Down
87 changes: 87 additions & 0 deletions libs/Redirects/BanChinaBrowser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* Created by PhpStorm.
* User: ellermister
* Date: 2023/11/17
* Time: 23:40
*/

namespace Libs\Redirects;


class BanChinaBrowser extends Handler
{

const KEYWORD_IN_USERAGENT = [
'bidubrowser',
'metasr',
'tencenttraveler',
'MicroMessenger',
'MiuiBrowser',
'YodaoBot',
'IqiyiApp',
'Weibo',
'qq',
'QQBrowser',
'Quark',
'MetaSr',
'SNEBUY-APP',
'AlipayClient',
'AliApp',
'115Browser',
'2345Explorer',
'Mb2345Browser',
'2345chrome',
'QihooBrowser',
'QHBrowser',
'360Spider',
'HaosouSpider',
'BIDUBrowser',
'baidubrowser',
'baiduboxapp',
'BaiduD',
'DingTalk',
'douban.frodo',
'aweme',
'HuaweiBrowser',
'HUAWEI',
'HONOR',
'HBPC',
'LBBROWSER',
'LieBaoFast',
'MZBrowser',
'HeyTapBrowser',
'OPPO',
'Opera',
'VivoBrowser',
];

function getHandlerName(): string
{
return "ban_china_browser";
}

function requireAuthorize(): bool
{
return true;
}

function isAuthorize(): bool
{
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
$userAgent = strtolower($userAgent);
foreach (self::KEYWORD_IN_USERAGENT as $value) {
if (strpos($userAgent, strtolower($value)) !== false) {
view('ban_china_browser', ['url' => $this->data['url']]);
return false;
}
}
return true;
}

function showPage(): bool
{
return false;
}

}
1 change: 1 addition & 0 deletions libs/Redirects/RedirectRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function __construct(string $url, array $encryptTypes, string $hash, arra

// 优先级
$this->handlers = [
$this->makeHandler(BanChinaBrowser::class),
$this->makeHandler(WhisperHandler::class),
$this->makeHandler(EncryptHandler::class),
$this->makeHandler(PasswordHandler::class),
Expand Down
53 changes: 53 additions & 0 deletions view/ban_china_browser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="<?php echo get_lang() ?>">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WARNING</title>
<meta name="referrer" content="no-referrer" />
<style>
.main-tips{
text-align: center;
padding: 20px;
flex-direction: column;
align-items: center;
display: flex;
}
.main-tips h2{
user-select: none;
}
.main-tips pre{
padding: 12px;
background: #ccc;
}
</style>
</head>

<body>
<div class="main-tips">
<h2><?php echo __('Please use a non-China browser');?></h2>
<pre onclick="allSelectContent()" id="url"></pre>
<label><?php echo __('Please copy this link to open in other browsers');?></label>
</div>
<script>
let safeURL = new URL(location.href)
safeURL.search = ""

let url = document.getElementById('url')
url.innerText = safeURL.href

function allSelectContent(){
let url = document.getElementById('url')
var selection = document.getSelection()

var range = document.createRange()
range.selectNode(url)

selection.removeAllRanges()
selection.addRange(range)
}
</script>
</body>
</html>
31 changes: 18 additions & 13 deletions view/welcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
</div>
<div class="mb-3" id="extent-element">
<h5><?php echo __('Firewall')?></h5>
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" id="radio-fake-page" name="encrypt_type" class="custom-control-input"
value="ban_china_browser" checked="">
<label class="custom-control-label" for="radio-fake-page"><?php echo __('Ban China Browser') ?></label>
</div>
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" id="radio-fake-page" name="encrypt_type" class="custom-control-input"
value="fake_page" checked="">
Expand All @@ -65,12 +70,12 @@
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" id="radio-once" name="encrypt_type" class="custom-control-input"
value="once">
<label class="custom-control-label" for="radio-once"><?php echo __('redirect once') ?></label>
<label class="custom-control-label" for="radio-once"><?php echo __('Redirect once') ?></label>
</div>
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" id="radio-password" name="encrypt_type" class="custom-control-input"
value="password">
<label class="custom-control-label" for="radio-password"><?php echo __('password access') ?></label>
<label class="custom-control-label" for="radio-password"><?php echo __('Password access') ?></label>
</div>
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" id="radio-pc-only" name="encrypt_type" class="custom-control-input"
Expand All @@ -87,7 +92,7 @@
<input type="checkbox" id="radio-china-only" name="encrypt_type" class="custom-control-input"
value="china_only">
<label class="custom-control-label"
for="radio-china-only"><?php echo __('mainland China access only') ?></label>
for="radio-china-only"><?php echo __('Mainland China access only') ?></label>
</div>
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" id="radio-non-china-only" name="encrypt_type" class="custom-control-input"
Expand All @@ -99,37 +104,37 @@
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" id="radio-normal" name="encrypt_type" class="custom-control-input"
value="normal">
<label class="custom-control-label" for="radio-normal"><?php echo __('normal') ?></label>
<label class="custom-control-label" for="radio-normal"><?php echo __('Normal') ?></label>
</div>
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" id="radio-dynamic" name="encrypt_type" class="custom-control-input"
value="dynamic">
<label class="custom-control-label" for="radio-dynamic"><?php echo __('no referer') ?></label>
<label class="custom-control-label" for="radio-dynamic"><?php echo __('No referer') ?></label>
</div>
<div class="custom-control custom-checkbox custom-control-inline">
<input type="checkbox" id="radio-encrypt" name="encrypt_type" class="custom-control-input"
value="encrypt" checked="">
<label class="custom-control-label" for="radio-encrypt"><?php echo __('encrypt redirect') ?></label>
<label class="custom-control-label" for="radio-encrypt"><?php echo __('Encrypt redirect') ?></label>
</div>
<div class="custom-control custom-checkbox custom-control-inline" style="display: inline-block;">
<input type="checkbox" id="radio-whisper" name="encrypt_type" class="custom-control-input"
value="whisper">
<label class="custom-control-label" for="radio-whisper"><?php echo __('whisper text') ?></label>
<label class="custom-control-label" for="radio-whisper"><?php echo __('Whisper text') ?></label>
</div>
</div>

<div class="card">
<div class="card-body text-left">
<p><b> 🏄🏼‍♀️ <?php echo __('normal') ?>: </b><?php echo __('Jump directly to the website') ?><br>
<b>🐸<?php echo __('no referer') ?>: </b><?php echo __('No Referer parameter') ?><br>
<b>🕷 <?php echo __('encrypt redirect') ?>
<p><b> 🏄🏼‍♀️ <?php echo __('Normal') ?>: </b><?php echo __('Jump directly to the website') ?><br>
<b>🐸<?php echo __('No referer') ?>: </b><?php echo __('No Referer parameter') ?><br>
<b>🕷 <?php echo __('Encrypt redirect') ?>
: </b><?php echo __('Encrypted access, anti-crawler') ?><br>
<b>👺 <?php echo __('Fake page') ?>
: </b><?php echo __('Use random news, forums, product website information to fool robots') ?>
<br>
<b>🔥 <?php echo __('redirect once') ?>: </b><?php echo __('Jump only once') ?><br>
<b>🔑 <?php echo __('password access') ?>: </b><?php echo __('Password required') ?><br>
<b>📝 <?php echo __('whisper text') ?>: </b><?php echo __('Append rich text information') ?><br>
<b>🔥 <?php echo __('Redirect once') ?>: </b><?php echo __('Jump only once') ?><br>
<b>🔑 <?php echo __('Password access') ?>: </b><?php echo __('Password required') ?><br>
<b>📝 <?php echo __('Whisper text') ?>: </b><?php echo __('Append rich text information') ?><br>
<b>💻 <?php echo __('PC access only') ?>
: </b><?php echo __('Only PC users can access this page') ?><br>
<b>📱 <?php echo __('Mobile access only') ?>
Expand Down
Loading

0 comments on commit 50b67a8

Please sign in to comment.