up
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
from os import system
|
||||
from os.path import exists, expanduser
|
||||
from requests import get
|
||||
from re import search
|
||||
from subprocess import check_output
|
||||
|
||||
from proxychains4_conf import *
|
||||
|
||||
# --------------------------------------
|
||||
# Variables
|
||||
# --------------------------------------
|
||||
REPO_URL="https://api.github.com/repos/rofl0r/proxychains-ng/releases/latest"
|
||||
VERSION_FILE="proxychains_version.txt"
|
||||
# --------------- END ------------------
|
||||
|
||||
|
||||
# --------------------------------------
|
||||
# Functions
|
||||
# --------------------------------------
|
||||
def download_latest(latest_info):
|
||||
print('Downloading .tar.gz...')
|
||||
download_url = latest_info['assets'][0]['browser_download_url']
|
||||
downloaded = get(download_url).content
|
||||
with open('proxychains.tar.gz', 'wb') as f:
|
||||
f.write(downloaded)
|
||||
print('Downloaded.')
|
||||
|
||||
def write_version(version):
|
||||
with open(VERSION_FILE, 'w') as f:
|
||||
f.write(version)
|
||||
f.close()
|
||||
def get_version():
|
||||
with open(VERSION_FILE, 'r') as f:
|
||||
version = f.read()
|
||||
f.close()
|
||||
return version
|
||||
# --------------- END ------------------
|
||||
|
||||
|
||||
# --------------------------------------
|
||||
# MAIN CODE
|
||||
# --------------------------------------
|
||||
update_binaries = False # If version updated or version not exist
|
||||
if exists(VERSION_FILE):
|
||||
latest_info = get(REPO_URL)
|
||||
if latest_info.status_code == 200:
|
||||
latest_info = latest_info.json() # To json
|
||||
|
||||
local_version = get_version()
|
||||
remote_version = latest_info['tag_name']
|
||||
if local_version != remote_version:
|
||||
download_latest(latest_info)
|
||||
write_version(remote_version)
|
||||
update_binaries = True
|
||||
else:
|
||||
latest_info = get(REPO_URL)
|
||||
if latest_info.status_code == 200:
|
||||
latest_info = latest_info.json() # To json
|
||||
latest_version = latest_info['tag_name']
|
||||
|
||||
download_latest(latest_info)
|
||||
write_version(latest_version)
|
||||
update_binaries = True
|
||||
else:
|
||||
print('Error while get info about last release.')
|
||||
exit(0)
|
||||
|
||||
if update_binaries:
|
||||
print('Unarchive')
|
||||
system('tar -xf proxychains.tar.gz')
|
||||
print('cd && make')
|
||||
system('cd proxychains-ng-* && ./configure && make')
|
||||
print('Create ~/proxychains && copy binaries')
|
||||
system('mkdir ~/proxychains && cp proxychains-ng-*/proxychains4 proxychains-ng-*/libproxychains4.so ~/proxychains/')
|
||||
|
||||
print('\n-------- Setup conf --------')
|
||||
print('(VALUE) - value by default')
|
||||
print('Enter "s" to skip setup')
|
||||
host = input('Enter host (127.0.0.1): ')
|
||||
if not host:
|
||||
host = '127.0.0.1'
|
||||
# If not skiped
|
||||
if host != 's':
|
||||
port = input('Enter port (2080): ')
|
||||
if not port:
|
||||
port = '2080'
|
||||
print('----------- END ------------\n')
|
||||
print('Create proxychains4.conf')
|
||||
CONF += f'\nsocks5 {host} {port}'
|
||||
with open(expanduser('~/proxychains/proxychains4.conf'), 'w') as f:
|
||||
f.write(CONF)
|
||||
f.close()
|
||||
print('\n-------- Setup run ---------')
|
||||
print('Example of app name: org.mozilla.firefox (look at `flatpak list`)')
|
||||
app_name = input('Enter app name: ')
|
||||
flatpak_info = check_output(['flatpak', 'info', '--show-metadata', app_name])
|
||||
run_command = search(r'command=(\S+)', flatpak_info.decode('utf-8')).group(1)
|
||||
print('----------- END ------------\n')
|
||||
print('Generating proxy script')
|
||||
with open(expanduser(f'~/proxychains/{app_name}_proxy.sh'), 'w') as f:
|
||||
f.write(f'proxychains/proxychains4 -f proxychains/proxychains4.conf {run_command}')
|
||||
f.close()
|
||||
system(f'chmod +x ~/proxychains/{app_name}_proxy.sh')
|
||||
print('\n---- Generated command -----')
|
||||
print('Here your command for running proxyfied app (save it to some place, idk)')
|
||||
print('You can make alias in .bashrc or script and place in shortcut, whatever you want.\n')
|
||||
print(f'COMMAND: flatpak run --filesystem="~/proxychains:ro" --command="proxychains/{app_name}_proxy.sh" {app_name}')
|
||||
print('----------- END ------------\n')
|
||||
|
||||
|
||||
# --------------- END ------------------
|
||||
Reference in New Issue
Block a user