Skip to content

Commit

Permalink
feat: add user agent list
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed Mar 29, 2020
1 parent f52a663 commit d929b0c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<div align="center">

[![actions status](https://github.com/yanglbme/gitee-pages-action/workflows/Lint/badge.svg)](https://github.com/yanglbme/gitee-pages-action/actions) [![release](https://img.shields.io/github/v/release/yanglbme/gitee-pages-action.svg)](../../releases) [![license](https://badgen.net/github/license/yanglbme/gitee-pages-action)](./LICENSE)
[![actions status](https://github.com/yanglbme/gitee-pages-action/workflows/Lint/badge.svg)](https://github.com/yanglbme/gitee-pages-action/actions) [![release](https://img.shields.io/github/v/release/yanglbme/gitee-pages-action.svg)](../../releases) [![license](https://badgen.net/github/license/yanglbme/gitee-pages-action)](./LICENSE) [![PRs Welcome](https://badgen.net/badge/PRs/welcome/green)](../../pulls)

</div>

Expand Down Expand Up @@ -65,7 +65,6 @@ jobs:
gitee-password: ${{ secrets.GITEE_PASSWORD }}
# 注意替换为你的 Gitee 仓库
gitee-repo: doocs/advanced-java
branch: master
```
先使用 [`wearerequired/git-mirror-action`](https://github.com/wearerequired/git-mirror-action) 将 GitHub 仓库同步到 Gitee 仓库,再使用 [`yanglbme/gitee-pages-action`](https://github.com/yanglbme/gitee-pages-action) 实现 Gitee Pages 的自动部署。
Expand All @@ -77,7 +76,7 @@ jobs:

![](/images/add_secrets.png)

如果一切配置正常,并成功触发 [Gitee Pages Action](https://github.com/marketplace/actions/gitee-pages-action) ,我们可能会收到一封来自 Gitee 的告警邮件/站内信。放心,这是 GitHub Action 程序帮我们登录到 Gitee 官网,并为我们点击了项目的部署钮
如果一切配置正常,并成功触发 [Gitee Pages Action](https://github.com/marketplace/actions/gitee-pages-action) ,我们可能会收到一封来自 Gitee 的告警邮件/站内信。放心,这是 GitHub Action 程序帮我们登录到 Gitee 官网,并为我们点击了项目的部署按钮

![](/images/gitee_warn.png)

Expand Down
58 changes: 48 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import os
import random
import re
import sys

Expand All @@ -20,6 +21,45 @@
YkfslRZzCq5Fl3ooowIDAQAB
-----END PUBLIC KEY-----"""

USER_AGENTS = [
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; "
"SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; "
"SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)",
"Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; "
"Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
"Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; "
"Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; "
".NET CLR 2.0.50727; Media Center PC 6.0)",
"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; "
"Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; "
".NET CLR 3.5.30729; .NET CLR 3.0.30729; "
".NET CLR 1.0.3705; .NET CLR 1.1.4322)",
"Mozilla/4.0 (compatible; MSIE 7.0b; "
"Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; "
"InfoPath.2; .NET CLR 3.0.04506.30)",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) "
"AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) "
"Arora/0.3 (Change: 287 c9dfb30)",
"Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ "
"(KHTML, like Gecko, Safari/419.3) Arora/0.6",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; "
"rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) "
"Gecko/20080705 Firefox/3.0 Kapiko/3.0",
"Mozilla/5.0 (X11; Linux i686; U;) "
"Gecko/20070322 Kazehakase/0.4.5",
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) "
"Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 "
"(KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) "
"AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20",
"Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) "
"Presto/2.9.168 Version/11.52",
]


def get_csrf_token(html):
return re.search(
Expand Down Expand Up @@ -49,9 +89,7 @@ def login(self):
'q=0.9,image/webp,image/apng,*/*;'
'q=0.8,application/signed-exchange;v=b3;q=0.9',
'Host': 'gitee.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/80.0.3987.149 Safari/537.36'
'User-Agent': random.choice(USER_AGENTS)
}
try:
resp = self.session.get(login_index_url, headers=index_headers)
Expand All @@ -60,9 +98,7 @@ def login(self):
'Referer': 'https://gitee.com/login',
'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-Token': csrf_token,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/80.0.3987.149 Safari/537.36'
'User-Agent': random.choice(USER_AGENTS)
}
self.session.post(check_login_url, headers=headers, data=form_data)
data = f'{csrf_token}$gitee${self.password}'
Expand All @@ -79,9 +115,10 @@ def login(self):
'encrypt_data[user[password]]': encrypt_data,
'user[remember_me]': 1
}
self.session.post(login_index_url,
headers=index_headers,
data=form_data)
resp = self.session.post(login_index_url,
headers=index_headers,
data=form_data)
print(resp.text)
except Exception as e:
print(f'::set-output name=result::{e}')
sys.exit(1)
Expand All @@ -98,7 +135,8 @@ def build_pages(self):
'application/x-www-form-urlencoded; charset=UTF-8',
'Referer': pages_url,
'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-Token': csrf_token
'X-CSRF-Token': csrf_token,
'User-Agent': random.choice(USER_AGENTS)
}
form_data = {
'branch': self.branch,
Expand Down

0 comments on commit d929b0c

Please sign in to comment.