Jump to content
pyth0n3

Proxy setup Firefox [DEV]

Recommended Posts

Posted (edited)

Am plecat de la o singura optiune de switch si m-am bagat putin mai departe

Ar fi trebui sa iasa putin mai complicat si cu mai multe feature, printre care multiproxy , dar las balta proiectul

Schimba proxy in firefox (functioneaza doar pentru cei care au doar un profil de default)

Daca cineva vrea sa il modifie , poate sa o faca ,

E o versiune Alpha ,

Pentru documentare:

Proxy auto-config - Wikipedia, the free encyclopedia

Prefs.js file - MozillaZine Knowledge Base

In rest codul nu e caligrafic deoarece am facut diverse modificari in diverse locuri

Functioneaza doar in linux cu firefox

#!/usr/bin/python
#Date:21.07.2011
#Author:Pyth0n3
#Purpose: Proxy setup Firefox
#Blog: http://pyth0n3.blogspot.com/


from __future__ import print_function
import commands
import socket
import sys
import os

hand = os.getenv('HOME')

def display():
print ('''Usage: setproxy.py with:
setauto - to set automatic config (required once)
noauto - just change proxy option
Note:setauto must be set at least once before noauto''')
sys.exit()



if len(sys.argv) < 2:
display()

disp1 = 'noauto'
disp2 = sys.argv[1]
disp3 = 'setauto'


while True:
if disp2 == disp1 or disp2 == disp3 :break
else:
display()

igot = disp2

if igot == 'setauto':
hand = os.getenv('HOME')
os.chdir(hand)
rootdir='.mozilla'

for subdir,dirs, files in os.walk(rootdir):
for file in files:
if file == "prefs.js":
file_path = hand + '/' + subdir + '/' + file
search_file = open(file_path)
match = False
for line in search_file:
if 'user_pref("network.proxy.type", 2);' in line:
match = True
break

t=match

n = 'proxy.pac'
if t == True:
print ('Already checked , you can run without setauto option')
else:
f = open (file_path, 'a')
f.write('user_pref("network.proxy.autoconfig_url", "file://'+hand+'/'+n+'");\n')
f.write('user_pref("network.proxy.type", 2);\n')
f.close()







checking = commands.getoutput('ps -A')
if 'firefox' in checking:
print ('Firefox is running , you must restart it to work')


#get_host function declaration
def get_host():
while True:
my_host = raw_input('Enter proxy here: ')
if len(my_host) < 30 : break
else:
print ('Too large')
return my_host

#execute get_host here

y = get_host()
print ('You have entered',str(y))

try:
socket.inet_aton(y)
except socket.error:
print ('You have entered an ilegal address, it may not work')




#get_port function declaration
def get_port():
while True:
try:
port = int(raw_input('Enter the port: ' ))
if port in range(1023,65535) : break
else:
print ('Port number out of range ')
print ('Must be > 1023 or < 65535 ')
except ValueError:
print ('Invalid Number')
print ('Must be > 1023 or < 65535 ')

return port


#execute get_port here
x = get_port()
print ('You have entered: ', x)

#get the home directory
hand = os.getenv('HOME')
os.chdir(hand)


#write data to proxy file
f = open ('proxy.pac', 'w')
f.write ('function FindProxyForURL(url, host)\n')
f.write ('{\n')
f.write('\treturn "PROXY ' +str(y)+':'+str(x)+'; DIRECT";\n')
f.write('}\n')
f.close()

Download:

wget http://sprunge.us/NBQe -O setproxy.py

Edited by pyth0n3

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...