Skip to content

Configurable squid url redirector (python3)

License

Notifications You must be signed in to change notification settings

GlobalRadio/squid-redirect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

squid-redirect

A json configurable squid(3.5) url_rewrite_program written in python3.

Usecase: We wanted to transparently point our ios simulators at different content servers without modifying the ios application under test. Each test run on our ci-servers can transparently alias different endpoints.

Examples

1.) Trial the url_rewrite_program flow in a terminal

    python3 squid-redirect.py --rewrite '{"www\.capitalfm\.com": "www.capitalfm.development.int.thisisglobal.com"}'
    0 http://www.capitalfm.com/_build/ -
    0 OK rewrite-url="http://www.capitalfm.development.int.thisisglobal.com/_build/"

2.) Startup an example squid server using our url_rewrite_program

    cat <<EOF > rules.json
    {
        "www\\\\.capitalfm\\\\.com": "www.capitalfm.development.int.thisisglobal.com"
    }
    EOF

    SQUID_CONF_SOURCE=/usr/local/etc/squid.conf
    SQUID_CONF=./squid.conf
    cp ${SQUID_CONF_SOURCE} ${SQUID_CONF}

    cat <<EOF >> ${SQUID_CONF}

    url_rewrite_children 3 startup=0 idle=1 concurrency=1
    url_rewrite_extras ""
    url_rewrite_program /usr/local/bin/python3 $(pwd)/squid-redirect.py --rewrite $(pwd)/rules.json
    EOF

    squid -N -f ${SQUID_CONF}

3.) Setup osx transparent webproxy.

Programs that respect webproxy:

  • chrome
  • ios_simulator

webproxy is not sufficient for system-level programs like:

  • firefox
  • curl
    NETWORK_DEVICE="Wi-Fi"
    PROXY_HOST="localhost"
    PROXY_PORT="3128"
    networksetup -setwebproxy ${NETWORK_DEVICE} ${PROXY_HOST} ${PROXY_PORT}
    networksetup -setsecurewebproxy ${NETWORK_DEVICE} ${PROXY_HOST} ${PROXY_PORT}

    networksetup -setwebproxy ${NETWORK_DEVICE} "" ""
    networksetup -setsecurewebproxy ${NETWORK_DEVICE} "" ""
    networksetup -setwebproxystate ${NETWORK_DEVICE} off
    networksetup -setsecurewebproxystate ${NETWORK_DEVICE} off

References

Squid Documentation

Alternate Example Implementations of url_rewrite_program

Releases

No releases published

Packages

No packages published

Languages