Compare commits
2 commits
1fe6d01978
...
c0d54b2916
Author | SHA1 | Date | |
---|---|---|---|
c0d54b2916 | |||
7429664f3b |
3 changed files with 103 additions and 9 deletions
68
.forgejo/workflows/ci.yml
Normal file
68
.forgejo/workflows/ci.yml
Normal file
|
@ -0,0 +1,68 @@
|
|||
name: Build and Push Docker Image
|
||||
|
||||
# Define when this workflow will run
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master # Trigger on pushes to master branch
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+' # Trigger on semantic version tags
|
||||
paths-ignore:
|
||||
- 'Cargo.lock'
|
||||
- 'LICENSE'
|
||||
- 'README.md'
|
||||
- 'docker-compose.yml'
|
||||
workflow_dispatch: # Allow manual triggering of the workflow
|
||||
|
||||
# Define environment variables used throughout the workflow
|
||||
env:
|
||||
REGISTRY: git.nadeko.net
|
||||
IMAGE_NAME: fijxu/inv_sig_helper
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: runner
|
||||
|
||||
steps:
|
||||
# Step 1: Check out the repository code
|
||||
- name: Checkout code
|
||||
uses: https://github.com/actions/checkout@v3
|
||||
|
||||
# Step 3: Set up Docker Buildx for enhanced build capabilities
|
||||
- name: Set up Docker Buildx
|
||||
uses: https://github.com/docker/setup-buildx-action@v3
|
||||
|
||||
# Step 4: Authenticate with Quay.io registry
|
||||
- name: Login to Docker Container Registry
|
||||
uses: https://github.com/docker/login-action@v3.1.0
|
||||
with:
|
||||
registry: git.nadeko.net
|
||||
username: ${{ secrets.USERNAME }}
|
||||
password: ${{ secrets.TOKEN }}
|
||||
|
||||
# Step 5: Extract metadata for Docker image tagging and labeling
|
||||
- name: Extract metadata for Docker
|
||||
id: meta
|
||||
uses: https://github.com/docker/metadata-action@v4
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
# Define tagging strategy
|
||||
tags: |
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
|
||||
type=sha,prefix={{branch}}-
|
||||
# Define labels
|
||||
labels: |
|
||||
quay.expires-after=12w
|
||||
|
||||
# Step 6: Build and push the Docker image
|
||||
- name: Build and push Docker image
|
||||
uses: https://github.com/docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
platforms: linux/amd64
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
|
@ -20,8 +20,20 @@ pub static NSIG_FUNCTION_ENDINGS: &[&str] = &[
|
|||
|
||||
pub static REGEX_SIGNATURE_TIMESTAMP: &Lazy<Regex> = regex!("signatureTimestamp[=:](\\d+)");
|
||||
|
||||
pub static REGEX_SIGNATURE_FUNCTION: &Lazy<Regex> =
|
||||
regex!("\\bc&&\\(c=([a-zA-Z0-9$]{2,})\\(decodeURIComponent\\(c\\)\\)");
|
||||
pub static REGEX_SIGNATURE_FUNCTION: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(concat!(
|
||||
r#"(?:"#,
|
||||
// Pattern 1
|
||||
r#"\b[a-zA-Z0-9$]+&&\([a-zA-Z0-9$]+=([a-zA-Z0-9$]{2,})\(decodeURIComponent\([a-zA-Z0-9$]+\)\)\)"#,
|
||||
r#"|"#,
|
||||
// Pattern 2
|
||||
r#"([a-zA-Z0-9$]+)\s*=\s*function\(\s*[a-zA-Z0-9$]+\s*\)\s*\{\s*[^}]+?\.split\(\s*""\s*\)[^}]+?\.join\(\s*""\s*\)"#,
|
||||
r#"|"#,
|
||||
// Pattern 3
|
||||
r#"(?:\b|[^a-zA-Z0-9$])([a-zA-Z0-9$]{2,})\s*=\s*function\(\s*a\s*\)\s*\{\s*a\s*=\s*a\.split\(\s*""\s*\)"#,
|
||||
r#")"#
|
||||
)).unwrap()
|
||||
});
|
||||
pub static REGEX_HELPER_OBJ_NAME: &Lazy<Regex> = regex!(";([A-Za-z0-9_\\$]{2,})\\...\\(");
|
||||
|
||||
pub static NSIG_FUNCTION_NAME: &str = "decrypt_nsig";
|
||||
|
|
|
@ -18,6 +18,12 @@ pub enum FetchUpdateStatus {
|
|||
CannotFetchPlayerJS,
|
||||
NsigRegexCompileFailed,
|
||||
PlayerAlreadyUpdated,
|
||||
CannotMatchSignature
|
||||
}
|
||||
|
||||
fn fixup_n_function_code(code: &str) -> String {
|
||||
let re = regex::Regex::new(r#";\s*if\s*\(\s*typeof\s+[a-zA-Z0-9_$]+\s*===?\s*["']undefined["']\s*\)\s*return\s+[a-zA-Z0-9_$]+;"#).unwrap();
|
||||
re.replace_all(code, ";").to_string()
|
||||
}
|
||||
|
||||
pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStatus> {
|
||||
|
@ -140,18 +146,26 @@ pub async fn fetch_update(state: Arc<GlobalState>) -> Result<(), FetchUpdateStat
|
|||
i.get(1).unwrap().as_str()
|
||||
}
|
||||
};
|
||||
nsig_function_code = fixup_n_function_code(&nsig_function_code);
|
||||
debug!("got nsig fn code: {}", nsig_function_code);
|
||||
break;
|
||||
}
|
||||
|
||||
// Extract signature function name
|
||||
let sig_function_name = REGEX_SIGNATURE_FUNCTION
|
||||
.captures(&player_javascript)
|
||||
.unwrap()
|
||||
.get(1)
|
||||
.unwrap()
|
||||
.as_str();
|
||||
|
||||
let sig_function_name = match REGEX_SIGNATURE_FUNCTION.captures(&player_javascript) {
|
||||
Some(captures) => {
|
||||
// Try groups 1, 2, and 3 which contain the signature function name
|
||||
[1, 2, 3].iter()
|
||||
.find_map(|&i| captures.get(i))
|
||||
.map(|m| m.as_str())
|
||||
.ok_or(FetchUpdateStatus::CannotMatchSignature)?
|
||||
}
|
||||
None => {
|
||||
error!("Could not match signature function pattern");
|
||||
return Err(FetchUpdateStatus::CannotMatchSignature);
|
||||
}
|
||||
};
|
||||
debug!("sig function name: {}", sig_function_name);
|
||||
let mut sig_function_body_regex_str: String = String::new();
|
||||
sig_function_body_regex_str += &sig_function_name.replace("$", "\\$");
|
||||
sig_function_body_regex_str += "=function\\([a-zA-Z0-9_]+\\)\\{.+?\\}";
|
||||
|
|
Loading…
Reference in a new issue