pierovdfn

Scemoutilities

Jul 18th, 2011
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 8.26 KB | None | 0 0
  1. #NoTrayIcon
  2. #Include <Constants.au3>
  3. #include <GUIConstantsEx.au3>
  4. #include <WindowsConstants.au3>
  5. #include <EditConstants.au3>
  6.  
  7. Opt('MustDeclareVars', 1)
  8. Opt('TrayMenuMode', 1)
  9.  
  10. Dim $configurazione[8]
  11. Global $confiurazione, $mainPid
  12.  
  13. Func Impostazioni()
  14.     Local $msg, $btnok, $btnsalva, $btnannulla
  15.     Global $proxy, $username, $password, $proxyr, $dest, $newport, $browser, $header, $configurazione
  16.  
  17.     GUICreate('Scemo Utilities', 275, 440) ; will create a dialog box that when displayed is centered
  18.     GUISetState(@SW_SHOW) ; will display an empty dialog box
  19.  
  20.     ; Opzione: indirizzo Proxy
  21.     GUICtrlCreateGroup('Proxy (indirizzo:porta)', 10, 5, 250, 50)
  22.     $proxy = GUICtrlCreateInput($configurazione[0], 20, 25, 200, 20)
  23.     GUICtrlSetTip(-1, 'Il Proxy locale a cui ci si deve connettere.')
  24.     GUICtrlCreateGroup('', -99, -99, 1, 1)  ;close group
  25.  
  26.     ; Opzione: Username e password proxy
  27.     GUICtrlCreateGroup('Credenziali di accesso', 10, 60, 250, 50)
  28.     $username = GUICtrlCreateInput($configurazione[1], 20, 80, 95, 20)
  29.     GUICtrlSetTip(-1, 'Usename per il proxy (può essere lasciato vuoto)')
  30.     $password = GUICtrlCreateInput($configurazione[2], 125, 80, 95, 20, $ES_PASSWORD)
  31.     GUICtrlSetTip(-1, 'Password per il proxy')
  32.     GUICtrlCreateGroup('', -99, -99, 1, 1)
  33.  
  34.     ; Opzione: indirizzo Proxy Secondario
  35.     GUICtrlCreateGroup('Proxy Secondario (indirizzo:porta)', 10, 115, 250, 50)
  36.     $proxyr = GUICtrlCreateInput($configurazione[3], 20, 135, 200, 20)
  37.     GUICtrlSetTip(-1, 'Il Proxy remoto a cui ci si deve connettere.')
  38.     GUICtrlCreateGroup('', -99, -99, 1, 1)
  39.  
  40.     ; Opzione: indirizzo di Destinazione
  41.     GUICtrlCreateGroup('Destinazione (indirizzo:porta)', 10, 170, 250, 50)
  42.     $dest = GUICtrlCreateInput($configurazione[4], 20, 190, 200, 20)
  43.     GUICtrlSetTip(-1, 'La destinazione a cui ci si vuole connettere.')
  44.     GUICtrlCreateGroup('', -99, -99, 1, 1)
  45.  
  46.     ; Opzione: nuova porta
  47.     GUICtrlCreateGroup('Porta interna', 10, 225, 250, 50)
  48.     $newport = GUICtrlCreateInput($configurazione[5], 20, 245, 200, 20, $ES_NUMBER)
  49.     GUICtrlSetTip(-1, 'Porta a cui i programmi si devono connettere')
  50.     GUICtrlCreateGroup('', -99, -99, 1, 1)
  51.  
  52.     ; Opzione: Browser
  53.     GUICtrlCreateGroup('Header User-agent', 10, 280, 250, 50)
  54.     $browser = GUICtrlCreateInput($configurazione[6], 20, 300, 200, 20)
  55.     GUICtrlSetTip(-1, 'User-agent del browser con cui si vuole fingere di connettersi')
  56.     GUICtrlCreateGroup('', -99, -99, 1, 1)
  57.  
  58.     ; Opzione: Header aggiuntivo
  59.     GUICtrlCreateGroup('Header Aggiuntivo', 10, 335, 250, 50)
  60.     $header = GUICtrlCreateInput($configurazione[7], 20, 355, 200, 20)
  61.     GUICtrlSetTip(-1, 'Un qualsiasi header aggiuntivo da passare al server')
  62.     GUICtrlCreateGroup('', -99, -99, 1, 1)
  63.  
  64.     $btnok = GUICtrlCreateButton('&Ok', 12, 395, 75)
  65.     GUICtrlSetTip(-1, 'Connettiti usando queste informazioni')
  66.     $btnsalva = GUICtrlCreateButton('&Salva', 98, 395, 75)
  67.     GUICtrlSetTip(-1, 'Salva queste come impostazioni di default')
  68.     $btnannulla = GUICtrlCreateButton('&Annulla', 183, 395, 75)
  69.     GUICtrlSetTip(-1, 'Chiudi la finestra senza salvare')
  70.  
  71.     ; Run the GUI until the dialog is closed
  72.     While 1
  73.         $msg = GUIGetMsg()
  74.  
  75.         Switch Int($msg)
  76.             Case $GUI_EVENT_CLOSE
  77.                 GUIDelete()
  78.                 ExitLoop
  79.             Case $btnok
  80.                 Impostazioni_Configura()
  81.                 Chiudi_Proxytunnel()
  82.                 Avvia_Proxytunnel()
  83.                 GUIDelete()
  84.                 ExitLoop
  85.             Case $btnsalva
  86.                 Impostazioni_Configura()
  87.                 Salva_Impostazioni()
  88.             Case $btnannulla
  89.                 GUIDelete()
  90.                 ExitLoop
  91.         EndSwitch
  92.     WEnd
  93. EndFunc
  94.  
  95. Func Impostazioni_Configura()
  96.     Global $proxy, $username, $password, $proxyr, $dest, $newport, $browser, $header, $configurazione
  97.     $configurazione[0]=GUICtrlRead($proxy)
  98.     $configurazione[1]=GUICtrlRead($username)
  99.     $configurazione[2]=GUICtrlRead($password)
  100.     $configurazione[3]=GUICtrlRead($proxyr)
  101.     $configurazione[4]=GUICtrlRead($dest)
  102.     $configurazione[5]=GUICtrlRead($newport)
  103.     $configurazione[6]=GUICtrlRead($browser)
  104.     $configurazione[7]=GUICtrlRead($header)
  105. EndFunc
  106.  
  107. Func Carica_Impostazioni()
  108.     Global $configurazione
  109.     Local $file
  110.     $file='impostazioni.ini'
  111.     $configurazione[0]=IniRead($file, 'Proxytunnel', 'proxy', '')
  112.     $configurazione[1]=IniRead($file, 'Proxytunnel', 'username', '')
  113.     $configurazione[2]=IniRead($file, 'Proxytunnel', 'password', '')
  114.     $configurazione[3]=IniRead($file, 'Proxytunnel', 'proxyr', '')
  115.     $configurazione[4]=IniRead($file, 'Proxytunnel', 'dest', '')
  116.     $configurazione[5]=IniRead($file, 'Proxytunnel', 'newport', '46637')
  117.     $configurazione[6]=IniRead($file, 'Proxytunnel', 'browser', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12')
  118.     $configurazione[7]=IniRead($file, 'Proxytunnel', 'header', '')
  119. EndFunc
  120.  
  121. Func Salva_Impostazioni()
  122.     Global $configurazione
  123.     Local $file
  124.     $file='impostazioni.ini'
  125.     IniWrite($file, 'Proxytunnel', 'proxy', $configurazione[0])
  126.     IniWrite($file, 'Proxytunnel', 'username', $configurazione[1])
  127.     IniWrite($file, 'Proxytunnel', 'password', $configurazione[2])
  128.     IniWrite($file, 'Proxytunnel', 'proxyr', $configurazione[3])
  129.     IniWrite($file, 'Proxytunnel', 'dest', $configurazione[4])
  130.     IniWrite($file, 'Proxytunnel', 'newport', $configurazione[5])
  131.     IniWrite($file, 'Proxytunnel', 'browser', $configurazione[6])
  132.     IniWrite($file, 'Proxytunnel', 'header', $configurazione[7])
  133. EndFunc
  134.  
  135. Func Avvia_Proxytunnel()
  136.     Global $confiurazione, $mainPid
  137.     Local $cmd
  138.     $cmd='proxytunnel.exe -q -a ' & $configurazione[5] & ' -p ' & $configurazione[0] & ' -d ' & $configurazione[4]
  139.     if $configurazione[1] <> '' AND $configurazione[2] <> '' Then
  140.         $cmd=$cmd & ' -u ' & $configurazione[1] & ' -s ' & $configurazione[2]
  141.     EndIf
  142.     If $configurazione[3] <> '' Then
  143.         $cmd=$cmd & ' -r ' & $configurazione[3]
  144.     EndIf
  145.     $cmd=$cmd & ' -H "' & StringReplace($configurazione[6], '"', '') & '"'
  146.     If $configurazione[4] <> '' Then
  147.         $cmd=$cmd & ' -H "' & StringReplace($configurazione[7], '"', '') & '"'
  148.     EndIf
  149.     $mainPid=Run($cmd, '', @SW_HIDE)
  150.     If ProcessExists($mainPid) Then
  151.         TrayTip('Proxytunnel', 'Proxytunnel è stato avviato', 5)
  152.         Auto_Firewall()
  153.         return 1
  154.     Else
  155.         TrayTip('Proxytunnel', 'Non è stato possibile avviare ProxyTunnel', 5)
  156.         return 0
  157.     EndIf
  158. EndFunc
  159.  
  160. Func Chiudi_Proxytunnel()
  161.     Global $mainPid
  162.     Local $list
  163.     ProcessClose($mainPid)
  164.     $list=ProcessList('proxytunnel.exe')
  165.     for $i = 1 to $list[0][0]
  166.         ProcessClose($list[$i][0])
  167.     next
  168.     TrayTip('Proxytunnel', 'Proxytunnel è stato chiuso', 5)
  169. EndFunc
  170.  
  171. Func Auto_Firewall()
  172.     Local $list
  173.     Sleep(400)
  174.     WinActivate('Avviso di protezione Windows') ; Windows Firewall ;-)
  175.     $list=WinList('Avviso di protezione Windows')
  176.     If $list[0][0]>0 Then
  177.         Send('{TAB}')
  178.         Send('{TAB}')
  179.         Send('{TAB}')
  180.         Send('{TAB}')
  181.         Send('{TAB}')
  182.         Send('{ENTER}')
  183.     EndIf
  184. EndFunc
  185.  
  186. Carica_Impostazioni()
  187.  
  188. Local $status_tray, $prefsitem, $aboutitem, $exititem, $msg
  189.  
  190. $status_tray=TrayCreateItem('Proxytunnel avviato')
  191. TrayItemSetState($status_tray, 0)
  192. TrayCreateItem('')
  193. $prefsitem=TrayCreateItem('Impostazioni')
  194. TrayCreateItem('')
  195. $aboutitem=TrayCreateItem('About')
  196. $exititem=TrayCreateItem('Esci')
  197.  
  198. TraySetState()
  199.  
  200. TraySetToolTip('Proxytunnel')
  201. If Avvia_Proxytunnel()=1 Then
  202.     TrayItemSetState($status_tray, ($TRAY_CHECKED+$TRAY_ENABLE))
  203.     OnAutoItExitRegister('Chiudi_Proxytunnel')
  204. Else
  205.     TrayItemSetState($status_tray, $TRAY_ENABLE+$TRAY_UNCHECKED)
  206.     TrayItemSetText($status_tray, 'Proxytunnel chiuso')
  207. EndIf
  208.  
  209. While 1
  210.     $msg = TrayGetMsg()
  211.     Select
  212.         Case $msg=0
  213.             ContinueLoop
  214.         Case $msg=$status_tray
  215.             If (($TRAY_ENABLE+$TRAY_UNCHECKED)=TrayItemGetState($status_tray)) Then
  216.                 Chiudi_Proxytunnel()
  217.                 TrayItemSetState($status_tray, $TRAY_ENABLE+$TRAY_UNCHECKED)
  218.                 TrayItemSetText($status_tray, 'Proxytunnel chiuso')
  219.             Else
  220.                 If Avvia_Proxytunnel()=1 Then
  221.                     TrayItemSetState($status_tray, $TRAY_ENABLE+$TRAY_CHECKED)
  222.                     TrayItemSetText($status_tray,'Proxytunnel avviato')
  223.                 Else
  224.                     TrayItemSetState($status_tray, $TRAY_ENABLE+$TRAY_UNCHECKED)
  225.                     TrayItemSetText($status_tray, 'Proxytunnel chiuso')
  226.                 EndIf
  227.             EndIf
  228.             ContinueLoop
  229.         Case $msg=$prefsitem
  230.             Impostazioni()
  231.             TrayItemSetState($prefsitem, $TRAY_UNCHECKED)
  232.             ContinueLoop
  233.         Case $msg=$aboutitem
  234.             TrayItemSetState($aboutitem, $TRAY_UNCHECKED)
  235.             Msgbox(64, 'About', 'Proxytunnel GUI. Powered by Piero VDFN')
  236.             ContinueLoop
  237.         Case $msg=$exititem
  238.             TrayItemSetState($exititem, $TRAY_UNCHECKED)
  239.             Exit
  240.             ExitLoop
  241.     EndSelect
  242. WEnd
  243.  
  244. Exit
Advertisement
Add Comment
Please, Sign In to add comment