;-------------------------------- ;.PAC-Editor.au3 ;.Released: February 08, 2017 ; Modified: March 05, 2017 ;..Version: 1.01 ;...Author: ripdad ;-------------------------------- ; #NoTrayIcon #include 'array.au3' Opt('MustDeclareVars', 1) Opt('TrayAutoPause', 0) ; Local Const $sTitle = 'PAC Editor v1.01' Local Const $sPathIcon = @WindowsDir & '\system32\shell32.dll' TraySetIcon($sPathIcon, 187) TraySetToolTip($sTitle) ; Local $sList = '[PAC]' & @CRLF $sList &= 'findproxyforurl.com (PAC Information)' & @CRLF & @CRLF $sList &= '[scripting]' & @CRLF $sList &= 'www.autoitscript.com (BASIC-like scripting language)' & @CRLF $sList &= 'www.w3schools.com (HTML, CSS, JAVASCRIPT, etc.)' & @CRLF & @CRLF ; Local $sPathWhitelist = @ScriptDir & '\whitelist.txt' If FileExists($sPathWhitelist) Then $sList = FileRead($sPathWhitelist) EndIf ; DllCall('uxtheme.dll', 'none', 'SetThemeAppProperties', 'int', 1) Local $ID_GUI = GUICreate($sTitle, 500, 400, Default, Default, 0x00CF0000) GUISetFont(9.0, Default, Default, 'Courier') GUISetIcon($sPathIcon, 187, $ID_GUI) Local $ID_EDT = GUICtrlCreateEdit($sList, 5, 5, 490, 350) Local $ID_BTN = GUICtrlCreateButton('Make PAC', 200, 365, 100, 25, 0x1002) GUISetState(@SW_SHOW, $ID_GUI) GUICtrlSetState($ID_EDT, 256) GUIRegisterMsg(0x0024, '_WM_GETMINMAXINFO') ; While 1 Switch GUIGetMsg() Case -3 GUIDelete($ID_GUI) Exit Case $ID_BTN $sList = GUICtrlRead($ID_EDT) BackupPAC($sList) Local $nError = @error If $nError <> 0 Then MsgBox(8208, 'BackupPAC', 'Error: ' & $nError & @TAB) ContinueLoop EndIf ; MakeWhitelistPAC($sList) Local $nError = @error If $nError <> 0 Then MsgBox(8208, 'MakeWhitelistPAC', 'Error: ' & $nError & @TAB) Else GUISetState(@SW_HIDE, $ID_GUI) DisplayPAC() GUISetState(@SW_SHOW, $ID_GUI) EndIf Case Else EndSwitch WEnd ; ;#FUNCTION# =========================================== ;........Name: MakeWhitelistPAC ;....Released: 2017-02-04 ;....Modified: 2017-02-08 - modified for editor ;....Modified: 2017-03-05 - optimized javascript PAC ;.....Version: 2.0 ;.Description: Generates a javascript for PAC ;====================================================== Func MakeWhitelistPAC($sList) $sList = StringStripWS($sList, 3) Local $a = StringSplit($sList, @CRLF, 1) Local $str $sList = '' ; For $i = 1 To $a[0] $str = StringStripWS($a[$i], 7) $str = StringRegExpReplace($str, '([^a-zA-Z0-9.-].*)', '') If StringInStr($str, '.') Then $sList &= $str & @CRLF EndIf Next ; $sList = StringStripWS($sList, 3) $a = StringSplit($sList, @CRLF, 1) _ArraySort($a, 0, 1) ;------------------------------------------------------------------ $str = '/*' & @CRLF $str &= ' Automatic Proxy Configuration (PAC)' & @CRLF $str &= ' File: whitelist.js' & @CRLF $str &= ' Version: 2.0' & @CRLF $str &= ' Date: ' & @YEAR & '-' & @MON & '-' & @MDAY & @CRLF $str &= ' Time: ' & @HOUR & ':' & @MIN & ':' & @SEC & @CRLF $str &= '*/' & @CRLF $str &= @CRLF $str &= "'use strict';" & @CRLF $str &= @CRLF $str &= 'var aHosts = [' & ($a[0] + 1) & '];' & @CRLF For $i = 1 To $a[0] $str &= "aHosts.push('" & $a[$i] & "');" & @CRLF Next $str &= @CRLF $str &= 'function FindProxyForURL(url, host) {' & @CRLF $str &= ' var i, myHost;' & @CRLF $str &= ' for (i = 1; i < aHosts[0]; i++) {' & @CRLF $str &= ' myHost = aHosts[i];' & @CRLF $str &= " if (host == myHost || (myHost.charAt(0) == '.' && host.search(myHost) > 0)) return 'DIRECT';" & @CRLF $str &= ' }' & @CRLF $str &= " return 'PROXY 127.0.0.1:8080';" & @CRLF $str &= '}' & @CRLF ;------------------------------------------------------------------ Local $hFile = FileOpen(@ScriptDir & '\whitelist.js', 2) If $hFile = -1 Then Return SetError(-1) EndIf FileWrite($hFile, $str) FileClose($hFile) EndFunc ; Func BackupPAC($sList) Local $sDate = @YEAR & @MON & @MDAY & '-' & @HOUR & @MIN & @SEC Local $sPathBackup = @ScriptDir & '\BackupPAC\whitelist_' & $sDate Local $hFile, $sPath ; ; #1 - backup whitelist.js $sPath = @ScriptDir & '\whitelist.js' If FileExists($sPath) Then $hFile = FileOpen($sPathBackup & '.js', 10) If $hFile = -1 Then Return SetError(-1) FileWrite($hFile, FileRead($sPath)) FileClose($hFile) EndIf ; ; #2 - backup whitelist.txt $sPath = @ScriptDir & '\whitelist.txt' If FileExists($sPath) Then $hFile = FileOpen($sPathBackup & '.txt', 10) If $hFile = -1 Then Return SetError(-2) FileWrite($hFile, FileRead($sPath)) FileClose($hFile) EndIf ; ; #3 - save new whitelist.txt $hFile = FileOpen($sPath, 2) If $hFile = -1 Then Return SetError(-3) FileWrite($hFile, $sList) FileClose($hFile) EndFunc ; ; no changes are made with this function (view only) Func DisplayPAC() Local $ID_GUI2 = GUICreate('Result of Javascript PAC', 600, 400) GUISetFont(9.0, Default, Default, 'Courier') GUISetIcon($sPathIcon, 187, $ID_GUI2) Local $sPAC = FileRead(@ScriptDir & '\whitelist.js') Local $ID_EDT2 = GUICtrlCreateEdit($sPAC, 5, 5, 590, 350) GUICtrlSetColor($ID_EDT2, 0x0000FF) Local $ID_BTN2 = GUICtrlCreateButton('OK', 250, 365, 100, 25, 0x1002) GUISetState(@SW_SHOW, $ID_GUI2) GUICtrlSetState($ID_EDT2, 256) ; While 1 Switch GUIGetMsg() Case -3, $ID_BTN2 GUIDelete($ID_GUI2) ExitLoop Case Else EndSwitch WEnd EndFunc ; Func _WM_GETMINMAXINFO($hwnd, $msg, $wParam, $lParam) Local $tagMaxinfo = DllStructCreate('int;int;int;int;int;int;int;int;int;int', $lParam) DllStructSetData($tagMaxinfo, 7, 500); min-width DllStructSetData($tagMaxinfo, 8, 400); min-height Return 'GUI_RUNDEFMSG' EndFunc ;