Skip to content

Commit

Permalink
Merge pull request #4 from xx10n31y/only_proxy
Browse files Browse the repository at this point in the history
Add option `only_proxies` and `random_name`.
  • Loading branch information
vvbbnn00 authored Nov 23, 2023
2 parents 5fff42a + 53b0de6 commit ee34140
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 6 deletions.
2 changes: 2 additions & 0 deletions logs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
17 changes: 14 additions & 3 deletions services/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
CLASH = json.load(open("./config/clash.json", "r", encoding="utf8"))


def generate_Clash_subFile(account: Account = None, logger=logging.getLogger(__name__), best=False):
def generate_Clash_subFile(account: Account = None,
logger=logging.getLogger(__name__),
best=False,
only_proxies=False,
random_name=False):
"""
Generate Clash subscription file
:param random_name: Whether to use random name
:param only_proxies: If this is True, only generate proxies
:param account:
:param logger:
:param best: Whether to use the best entrypoints
Expand All @@ -32,9 +38,10 @@ def generate_Clash_subFile(account: Account = None, logger=logging.getLogger(__n
# Use len() instead of RANDOM_COUNT because the entrypoints may be less than RANDOM_COUNT
for i in range(len(random_points)):
point = random_points[i]
name = f"{fake.emoji()} CF-{fake.color_name()}" if random_name else f"CF-WARP-{i + 1}"
user_config.append(
{
"name": f"{fake.emoji()} CF-{fake.color_name()}",
"name": name,
"type": "wireguard",
"server": point.ip,
"port": point.port,
Expand All @@ -50,7 +57,11 @@ def generate_Clash_subFile(account: Account = None, logger=logging.getLogger(__n
proxyGroup["proxies"] += [proxy["name"] for proxy in user_config]

# Generate YAML file
clashYAML = yaml.dump(clashJSON, allow_unicode=True)
if only_proxies:
clashYAML = yaml.dump({'proxies': clashJSON['proxies'], 'proxy-groups': clashJSON['proxy-groups']},
allow_unicode=True)
else:
clashYAML = yaml.dump(clashJSON, allow_unicode=True)
return clashYAML


Expand Down
26 changes: 25 additions & 1 deletion services/web_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def http_account():
def http_clash():
account = getCurrentAccount(logger)
best = request.args.get('best') or False
fileData = generate_Clash_subFile(account, logger, best=best)
random_name = request.args.get('randomName').lower() == "true" or False

fileData = generate_Clash_subFile(account, logger, best=best, random_name=random_name)

headers = {
'Content-Type': 'application/x-yaml; charset=utf-8',
Expand All @@ -115,6 +117,7 @@ def http_clash():
def http_wireguard():
account = getCurrentAccount(logger)
best = request.args.get('best') or False

fileData = generate_Wireguard_subFile(account, logger, best=best)

headers = {
Expand All @@ -127,6 +130,27 @@ def http_wireguard():

return response

@app.route('/api/only_proxies', methods=['GET'])
@rate_limit()
@authorized()
def only_proxies():
account = getCurrentAccount(logger)
best = request.args.get('best') or False
random_name = request.args.get('randomName').lower() == "true" or False

fileData = generate_Clash_subFile(account, logger, best=best, only_proxies=True, random_name=random_name)

response = make_response(fileData)
headers = {
'Content-Type': 'application/x-yaml; charset=utf-8',
'Content-Disposition': f'attachment; filename=Clash-{fake.color_name()}.yaml',
"Subscription-Userinfo": f"upload=0; download={account.usage}; total={account.quota}; expire=253388144714"
}

response.headers = headers

return response


def create_app(app_name: str = "web", logger: logging.Logger = None) -> Flask:
if logger is None:
Expand Down
35 changes: 33 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
left: 50%;
transform: translateX(-50%);
padding: 10px 20px;
background-color: rgba(110, 255, 114, 0.8);
background-color: rgba(110, 255, 114);
color: #4caf50;
border-radius: 4px;
font-size: 16px;
Expand All @@ -85,6 +85,12 @@
.show {
opacity: 1;
}

.tip {
color: #666;
font-size: 14px;
margin-bottom: 10px;
}
</style>
</head>
<body>
Expand All @@ -104,6 +110,9 @@ <h1>WARP Clash 订阅地址生成器</h1>
<label>
<input type="checkbox" id="alwaysBest" onchange="generateLink()"> 始终选择最优节点
</label>
<label>
<input type="checkbox" id="randomName" onchange="generateLink()" checked> 随机节点名称
</label>
</div>
</form>
<center>
Expand All @@ -112,6 +121,13 @@ <h2>Clash</h2>
<div id="qrcode"></div>
<h2>Wireguard</h2>
<textarea id="WireguardLink" rows="1" readonly onclick="copyText('WireguardLink')"></textarea>
<h2>Only Proxies & Proxies Group</h2>
<div class="tip">
该链接仅包含节点信息,不包含规则信息,适用于自定义规则的用户。
</div>
<textarea id="onlyProxyLink" rows="1" readonly onclick="copyText('onlyProxyLink')"></textarea>
<a onclick="getOnlyProxy()" href="javascript:">点击复制节点信息</a>
<textarea id="onlyProxyInfo" rows="0" style="height: 0; width: 0;"></textarea>
<h2>账户信息</h2>
<a href="#" title="账户信息" target="_blank" id="AccountLink">点击查看</a>
</center>
Expand All @@ -128,9 +144,11 @@ <h2>账户信息</h2>
function generateLink() {
const password = document.getElementById('passwordInput').value;
const best = document.getElementById('alwaysBest').checked;
const randomName = document.getElementById('randomName').checked;
const baseUrl = location.protocol + '//' + location.host + '/api/';
const queryParams = new URLSearchParams({
best
best,
randomName
});

if (password.length) {
Expand All @@ -140,6 +158,7 @@ <h2>账户信息</h2>
document.getElementById('subscriptionLink').textContent = baseUrl + "clash?" + queryParams.toString();
document.getElementById('WireguardLink').textContent = baseUrl + "wireguard?" + queryParams.toString();
document.getElementById('AccountLink').href = baseUrl + "account?" + queryParams.toString();
document.getElementById('onlyProxyLink').textContent = baseUrl + "only_proxies?" + queryParams.toString();

const qrcodeContainer = document.getElementById('qrcode');
qrcodeContainer.innerHTML = '';
Expand Down Expand Up @@ -167,6 +186,18 @@ <h2>账户信息</h2>
}, 1000);
}

function getOnlyProxy() {
const url = document.getElementById('onlyProxyLink').textContent;
fetch(url, {
method: 'GET',
}).then(res => res.text()).then(res => {
document.getElementById('onlyProxyInfo').textContent = res;
copyText('onlyProxyInfo');
}).catch(err => {
showToast(`Error ${err.status}: ${err.statusText}`)
});
}

generateLink()
</script>

Expand Down

0 comments on commit ee34140

Please sign in to comment.