shoes 0.2.0

A multi-protocol proxy server.
#!/usr/bin/env python3
"""
Replace all Command::new("curl") calls with helpers::curl:: function calls
"""

import re

def replace_curl_commands(content):
    """Replace curl command patterns with helper function calls"""

    # Pattern 1: Direct HTTP/HTTPS via proxy (no spawn_blocking)
    # Command::new("curl")
    #     .arg("--proxy")
    #     .arg(&format!("http://127.0.0.1:{}", http_port))
    #     .arg("--silent")
    #     .arg("--show-error")
    #     .arg("--max-time")
    #     .arg("30")
    #     .arg("http://www.google.com")
    #     .output()?

    pattern1 = r'Command::new\("curl"\)\s+\.arg\("--proxy"\)\s+\.arg\(&format!\("http://127\.0\.0\.1:\{\}", http_port\)\)\s+\.arg\("--silent"\)\s+\.arg\("--show-error"\)\s+\.arg\("--max-time"\)\s+\.arg\("30"\)\s+\.arg\("(http[s]?://[^"]+)"\)\s+\.output\(\)\?'

    def repl1(m):
        url = m.group(1)
        return f'''helpers::curl::run_curl(
        "{url}",
        helpers::curl::CurlOptions::new()
            .proxy(&format!("http://127.0.0.1:{{}}", http_port))
            .timeout(30),
    )
    .await?'''

    content = re.sub(pattern1, repl1, content)

    # Pattern 2: With spawn_blocking for local HTTP server (HTTP)
    # tokio::task::spawn_blocking(move || {
    #     Command::new("curl")
    #         .arg("--proxy")
    #         .arg(&format!("http://127.0.0.1:{}", http_port))
    #         .arg("--silent")
    #         .arg("--show-error")
    #         .arg("--max-time")
    #         .arg("30")
    #         .arg(&url)
    #         .output()
    # })
    # .await??

    pattern2 = r'tokio::task::spawn_blocking\(move \|\| \{\s+Command::new\("curl"\)\s+\.arg\("--proxy"\)\s+\.arg\(&format!\("http://127\.0\.0\.1:\{\}", http_port\)\)\s+\.arg\("--silent"\)\s+\.arg\("--show-error"\)\s+\.arg\("--max-time"\)\s+\.arg\("30"\)\s+\.arg\(&url\)\s+\.output\(\)\s+\}\)\s+\.await\?\?'

    repl2 = '''helpers::curl::run_curl(
        &url,
        helpers::curl::CurlOptions::new()
            .proxy(&format!("http://127.0.0.1:{}", http_port))
            .timeout(30),
    )
    .await?'''

    content = re.sub(pattern2, repl2, content)

    # Pattern 3: With spawn_blocking for local HTTPS server (HTTPS + insecure)
    # tokio::task::spawn_blocking(move || {
    #     Command::new("curl")
    #         .arg("--proxy")
    #         .arg(&format!("http://127.0.0.1:{}", http_port))
    #         .arg("--insecure")
    #         .arg("--silent")
    #         .arg("--show-error")
    #         .arg("--max-time")
    #         .arg("30")
    #         .arg(&url)
    #         .output()
    # })
    # .await??

    pattern3 = r'tokio::task::spawn_blocking\(move \|\| \{\s+Command::new\("curl"\)\s+\.arg\("--proxy"\)\s+\.arg\(&format!\("http://127\.0\.0\.1:\{\}", http_port\)\)\s+\.arg\("--insecure"\)\s+\.arg\("--silent"\)\s+\.arg\("--show-error"\)\s+\.arg\("--max-time"\)\s+\.arg\("30"\)\s+\.arg\(&url\)\s+\.output\(\)\s+\}\)\s+\.await\?\?'

    repl3 = '''helpers::curl::run_curl(
        &url,
        helpers::curl::CurlOptions::new()
            .proxy(&format!("http://127.0.0.1:{}", http_port))
            .insecure(true)
            .timeout(30),
    )
    .await?'''

    content = re.sub(pattern3, repl3, content)

    # Pattern 4: With spawn_blocking for local HTTPS/TLS1.2 server
    # tokio::task::spawn_blocking(move || {
    #     Command::new("curl")
    #         .arg("--proxy")
    #         .arg(&format!("http://127.0.0.1:{}", http_port))
    #         .arg("--insecure")
    #         .arg("--tlsv1.2")
    #         .arg("--tls-max")
    #         .arg("1.2")
    #         .arg("--silent")
    #         .arg("--show-error")
    #         .arg("--max-time")
    #         .arg("30")
    #         .arg(&url)
    #         .output()
    # })
    # .await??

    pattern4 = r'tokio::task::spawn_blocking\(move \|\| \{\s+Command::new\("curl"\)\s+\.arg\("--proxy"\)\s+\.arg\(&format!\("http://127\.0\.0\.1:\{\}", http_port\)\)\s+\.arg\("--insecure"\)\s+\.arg\("--tlsv1\.2"\)\s+\.arg\("--tls-max"\)\s+\.arg\("1\.2"\)\s+\.arg\("--silent"\)\s+\.arg\("--show-error"\)\s+\.arg\("--max-time"\)\s+\.arg\("30"\)\s+\.arg\(&url\)\s+\.output\(\)\s+\}\)\s+\.await\?\?'

    repl4 = '''helpers::curl::run_curl(
        &url,
        helpers::curl::CurlOptions::new()
            .proxy(&format!("http://127.0.0.1:{}", http_port))
            .insecure(true)
            .tls_version("1.2")
            .tls_max_version("1.2")
            .timeout(30),
    )
    .await?'''

    content = re.sub(pattern4, repl4, content)

    # Pattern 5: Direct to local server (no proxy) - HTTP
    # tokio::task::spawn_blocking(move || {
    #     Command::new("curl")
    #         .arg(&url)
    #         .arg("--silent")
    #         .arg("--max-time")
    #         .arg("5")
    #         .output()
    # })
    # .await??

    pattern5 = r'tokio::task::spawn_blocking\(move \|\| \{\s+Command::new\("curl"\)\s+\.arg\(&url\)\s+\.arg\("--silent"\)\s+\.arg\("--max-time"\)\s+\.arg\("5"\)\s+\.output\(\)\s+\}\)\s+\.await\?\?'

    repl5 = '''helpers::curl::curl_direct(&url).await?'''

    content = re.sub(pattern5, repl5, content)

    # Pattern 6: Direct to local server (no proxy) - HTTPS insecure
    # tokio::task::spawn_blocking(move || {
    #     Command::new("curl")
    #         .arg(&url)
    #         .arg("--insecure")
    #         .arg("--silent")
    #         .arg("--max-time")
    #         .arg("5")
    #         .output()
    # })
    # .await??

    pattern6 = r'tokio::task::spawn_blocking\(move \|\| \{\s+Command::new\("curl"\)\s+\.arg\(&url\)\s+\.arg\("--insecure"\)\s+\.arg\("--silent"\)\s+\.arg\("--max-time"\)\s+\.arg\("5"\)\s+\.output\(\)\s+\}\)\s+\.await\?\?'

    repl6 = '''helpers::curl::curl_https_insecure_direct(&url).await?'''

    content = re.sub(pattern6, repl6, content)

    # Pattern 7: Direct to local server (no proxy) - HTTPS TLS 1.2
    # tokio::task::spawn_blocking(move || {
    #     Command::new("curl")
    #         .arg(&url)
    #         .arg("--insecure")
    #         .arg("--tlsv1.2")
    #         .arg("--tls-max")
    #         .arg("1.2")
    #         .arg("--silent")
    #         .arg("--max-time")
    #         .arg("5")
    #         .output()
    # })
    # .await??

    pattern7 = r'tokio::task::spawn_blocking\(move \|\| \{\s+Command::new\("curl"\)\s+\.arg\(&url\)\s+\.arg\("--insecure"\)\s+\.arg\("--tlsv1\.2"\)\s+\.arg\("--tls-max"\)\s+\.arg\("1\.2"\)\s+\.arg\("--silent"\)\s+\.arg\("--max-time"\)\s+\.arg\("5"\)\s+\.output\(\)\s+\}\)\s+\.await\?\?'

    repl7 = '''helpers::curl::curl_https_tls12_direct(&url).await?'''

    content = re.sub(pattern7, repl7, content)

    return content

def main():
    with open('/shoes/tests/vless_integration.rs', 'r') as f:
        content = f.read()

    new_content = replace_curl_commands(content)

    with open('/shoes/tests/vless_integration.rs', 'w') as f:
        f.write(new_content)

    print("Replacements complete!")

if __name__ == '__main__':
    main()