Proxy *mise a jour 1.1 final Rev2

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Proxy *mise a jour 1.1 final Rev2

Message par celtic88 »

bonjour à tous :D

:roll: inspiré de logiciel "Fiddler Web Debugger" j ai décidé de créer ce programme a la base simple!

C'est quoi un proxy web http://www.sebsauvage.net/comprendre/proxy/index.html

bon c'est un programme de proxy sur réseau locale ou en peut le connecter à un "proxy server"

les avantages :
contrôler les trafics "http" et "ssl" sur votre navigateur, comme voire ou modifier les Requêtes ou bloquer des site ...

-comment ça marche ?:
c'est simple il faut tout d'abord lancer le programme ensuite entrer le port de connexion et tu clique sur "start"

le serveur va se crée sur ip locale : "127.0.0.1" et le port que tu a choisi avant

ensuite tu entre l' ip locale et port dans votre navigateur pour les deux protocole "http_ et https ssl"

pour ceux qui ne savent pas Comment activer un proxy sur leur navigateur web voila le lien:
http://www.tomshardware.fr/faq/id-29519 ... r-web.html

**mise à jour Proxy v1.0

-Le code a été ré-écrit depuis le début
-Beaucoup d'erreurs ont été corrigés
-Ajouter la fonction connecter via un proxy externe avec ou son authentification

**mise a jour 1.1 final Rev2

bon j ai corrigé quelque bug un peu partout ,l'algorithme de code rest comme la version precedente.

utilisation:
pour démarrer le proxy local clic sur "Settings\Select a port" et tu entre le "port" ensuite "start".
pour connecter à un proxy server clic sur "Settings\use proxy" ensuit tu entre la config de proxy!
*conseil: certain "proxy server" sont fait pour l'espionnage et le fraude. !!!

normalement ce code marche pour win, mac, linux .

image
Image

le code

Code : Tout sélectionner

;;By Celtic88 Dz (c) v1.1 Final.

EnableExplicit

;http://www.purebasic.fr/french/viewtopic.php?f=1&t=16578&sid=f0e2814d1fbc90e05114b4e286cd433e
Macro ReceiveNetworkDataServer(sock,Buffer,sizebuffer)
  recv_(sock, Buffer, sizebuffer,0) 
EndMacro

Macro SendNetworkDataServer(sock,Buffer,sizebuffer)
  send_(sock, Buffer, sizebuffer,0) 
EndMacro

Structure Proxy_WindowInfo
  UniqId.l
  Clume.b
  StringTo.s
EndStructure

Structure Proxy
  UniqId.l
  RemoteSocketID.i
  RemoteSocket.i
  LocalSocketID.i
  LocalSocket.i  
  RemoteIsClosed.b
  LocalIsClosed.b
  TotalDownload.q
  TotalUpload.q
  ThreadId.i
  ;   iProxy_WindowInfo.Proxy_WindowInfo
;   Method.s{50}
  SaveHost.s{#MAX_PATH}
  *MemData
EndStructure

Structure Network_SendConnectionIsClosed
  ConnectionIsClosed.b
EndStructure

Structure Proxylist
  *Proxylist.Proxy
EndStructure

Structure Proxy_TotalDownSendInfo
  ProxyTotalDownload.q
  ProxyTotalUpload.q
  ProxyTotalDownloadSave.q
  ProxyTotalUploadSave.q
  ProxyTotalDownloadRate.q
  ProxyTotalUploadRate.q
  ProxyTimer.q
EndStructure

Enumeration #PB_Event_FirstCustomValue
  #Proxy_Evenement_StartConnection
  #Proxy_Evenement_FreeConnection
  #Proxy_Evenement_SetInfo
EndEnumeration

Enumeration 
  #Proxy_ListIcon_LocalId
  #Proxy_ListIcon_RemoteId
  #Proxy_ListIcon_Method
  #Proxy_ListIcon_WebSite
  #Proxy_ListIcon_Download
  #Proxy_ListIcon_Send
  #Proxy_ListIcon_LocalIsClosed
  #Proxy_ListIcon_RemoteIsClosed
  #Proxy_ListIcon_FreeConnection
  #Proxy_ListIcon_TimeoutDownload
  #Proxy_ListIcon_TimeoutSend
  #Proxy_ListIcon_Block
  #Proxy_ListIcon_Redirect
EndEnumeration

Enumeration
  #Proxy_menu
  #Proxy_addporr
  #Proxy_BlockSite
  #Proxy_AcceptCookies
  #Proxy_ConProxy
  #Proxy_Clearlist
  #Proxy_Exit
  #Proxy_PopupMenuRBlock
  #Proxy_PopupMenuRBlockDelete
  #Proxy_Me
EndEnumeration

#Proxy_WorkMemorySize = 1024*10

Global Window_Proxy,ListIcon_Proxy,StatusBar_Proxy
Global Window_ProxyListenPort,String_Proxy,Button_ProxyStart
Global Window_ProxyRBlock,String_ProxyRBlockSite,ListIcon_ProxyRBlock
Global Window_ProxySettings,Checkbox_ProxySt ,String_ProxyStip ,String_ProxyStport ,String_ProxyStlogin, String_ProxyStpass
Global iProxy_TotalDownSendInfo.Proxy_TotalDownSendInfo
Global Mutex_Proxy = CreateMutex()
Global NewList ProxyInfoList.Proxylist()
Global RemoteProxyID.l,LocalServerProxy
Global ProxyAcceptCookies.b =0
Global Proxy_Ssl_Connection_Established = UTF8("HTTP/1.1 200 Connection Established" + #CRLF$ + #CRLF$)
Global Proxy_Service_Unavailable = UTF8("HTTP/1.1 503 Service Unavailable"+#CRLF$ +"Content-Length: 0"+#CRLF$ +"Connection: close" + #CRLF$ + #CRLF$)
Global Proxy_BlockSiteStringlist.s

Global Proxy_UseProxy.b 
Global Proxy_UseProxyIp.s
Global Proxy_UseProxyPort.w
Global Proxy_UseProxyAuthCode.s

If InitNetwork() = 0
  MessageRequester("Error", "Can't initialize the network !", #PB_MessageRequester_Error )
  End
EndIf

Procedure.s __ByteGetdisplaysize(isize.f)
  Dim  abytes.s(4):abytes(0) =" Bytes":abytes(1) =" Kb":abytes(2) =" Mb":abytes(3) =" Go":abytes(4) =" Tb"
  Protected i.b,p.q
  For i.b = 4 To 0 Step -1
    p=Pow(1024, i)
    If isize >= p Or p = 1.0
      ProcedureReturn StrF((isize / p),Bool(Mod(isize ,p)>0)) + abytes(i)
    EndIf
  Next
EndProcedure

Procedure Proxy_WindowSetInfo(GadgetItem.l,Clume.b,StringTo.s)
  Protected *infom.Proxy_WindowInfo = AllocateMemory(SizeOf(Proxy_WindowInfo))
  If *infom
    With *infom
      \UniqId = GadgetItem
      \Clume = Clume
      \StringTo = StringTo
    EndWith
    PostEvent(#Proxy_Evenement_SetInfo,Window_Proxy,0,0,*infom)
  EndIf
EndProcedure

Procedure Proxy_SendNetworkData(ConID,*Data,SizeData.l,*pConnectionIsClosed.Network_SendConnectionIsClosed=0)
  Protected Ceven,Snd.l,Sndlen.l
  Repeat
    If *pConnectionIsClosed
      If *pConnectionIsClosed\ConnectionIsClosed
        ProcedureReturn
      EndIf
      Snd = SendNetworkDataServer(ConID,*Data+Sndlen,SizeData-Sndlen)
    Else
      If NetworkClientEvent(ConID) = #PB_NetworkEvent_Disconnect
        ProcedureReturn
      EndIf
      Snd = SendNetworkData(ConID,*Data+Sndlen,SizeData-Sndlen)
    EndIf
    
    If Snd > 0
      Sndlen + Snd
    Else
      Delay(1)
    EndIf
    If Sndlen = SizeData
      ProcedureReturn 1 
    EndIf
  ForEver
EndProcedure

Procedure Proxy_RequestSend(sIzemem.l,*ProxyInfoList.Proxy)
  Protected HeaderSize.l
  With *ProxyInfoList
    ;https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

    Protected sMethod.s = PeekS(\MemData,8, #PB_UTF8)
    sMethod = Left(sMethod,FindString(sMethod, " ")-1)
    
    If FindString("|GET|CONNECT|POST|HEAD|PUT|OPTIONS|TRACE|", "|"+sMethod+"|")
      
      Protected sHeader.s = PeekS(\MemData,-1, #PB_UTF8)
      sHeader = Left(sHeader,FindString(sHeader, #CRLF$ +#CRLF$)-1) + #CRLF$ +#CRLF$
      HeaderSize = StringByteLength(sHeader,#PB_UTF8)
      
      Protected modreq$="",RemoteHost$="",sreq$="",dd.l
      Protected kk.b,sf.s,ifis.w,iStr.s = "http://,https://,ftp://,ftps://"
      
      For dd = 1 To CountString(sHeader, #CRLF$)
        ; modify header
        sreq$ = StringField(sHeader,dd,#CRLF$)
        If CountString(sreq$, "Host:")
          RemoteHost$ = Mid(sreq$, 7) 
          If CountString(RemoteHost$, ":")
            RemoteHost$ = Left(RemoteHost$,FindString(RemoteHost$, ":")-1)
          EndIf
        EndIf
        
        If Not Proxy_UseProxy
          For kk=1 To 4
            sf = StringField(iStr,kk,",")
            ifis = FindString(sreq$,sf)
            If ifis And dd = 1
              sreq$ = ReplaceString(sreq$,Mid(sreq$, ifis,FindString(sreq$, "/",ifis+Len(sf))-ifis) ,"")
              Break
            EndIf 
          Next
          
          If CountString(sreq$, "Accept-Encoding:")
            sreq$ = "Accept-Encoding: identity"
          EndIf
          If CountString(sreq$, "Proxy-Connection")
            sreq$ = ReplaceString(sreq$, "Proxy-Connection", "Connection") 
          EndIf
        EndIf
        If Not ProxyAcceptCookies And CountString(sreq$, "Cookie:")
          Continue
        EndIf		
        modreq$+ sreq$ + #CRLF$
      Next
      Proxy_WindowSetInfo(\UniqId,#Proxy_ListIcon_Method,sMethod)
      
      Protected blockedSites.s = Proxy_BlockSiteStringlist
      Protected Finbr.l = FindString(blockedSites, "||"+RemoteHost$+"||",0,#PB_String_NoCase )
      If Finbr
        \SaveHost = RemoteHost$
        \RemoteIsClosed = 2
        Proxy_WindowSetInfo(\UniqId,#Proxy_ListIcon_Block,"**Blocked** " + RemoteHost$)
        ProcedureReturn
      EndIf
      
      Protected ProtocolSsl.b =  0,Port.w
      If sMethod = "CONNECT"
        ProtocolSsl = 1
        Port= 443
      Else
        Port = 80
      EndIf
      
      Protected RemoteHostSave$ = RemoteHost$,PortSave.w= Port
      If Proxy_UseProxy      
        RemoteHost$ = Proxy_UseProxyIp
        Port=Proxy_UseProxyPort
        modreq$ = ReplaceString(modreq$,#CRLF$+#CRLF$,Proxy_UseProxyAuthCode)
      EndIf
      
      Protected Scmodreq.l = StringByteLength(modreq$,#PB_UTF8)
      PokeS(\MemData,modreq$,-1,#PB_UTF8 )
      CopyMemory(\MemData+HeaderSize,\MemData+Scmodreq,sIzemem-HeaderSize)
      sIzemem = (sIzemem-HeaderSize)+Scmodreq
      
      If \SaveHost And RemoteHostSave$ <> \SaveHost
        If NetworkClientEvent(\RemoteSocket)  <> #PB_NetworkEvent_Disconnect
          CloseNetworkConnection(\RemoteSocket)
        EndIf
        \SaveHost = #Null$
      EndIf
      
      If \SaveHost = #Null$
        
        \RemoteSocket = OpenNetworkConnection(RemoteHost$,Port)
        
        If \RemoteSocket
          \SaveHost = RemoteHostSave$
          Proxy_WindowSetInfo(\UniqId,#Proxy_ListIcon_WebSite,RemoteHostSave$ +":"+Str(PortSave))
          Proxy_WindowSetInfo(\UniqId,#Proxy_ListIcon_RemoteId,Str( \RemoteSocket))
        Else
          \RemoteIsClosed = 2
          Proxy_WindowSetInfo(\UniqId,#Proxy_ListIcon_WebSite,"**Failed** " + RemoteHostSave$)
        EndIf
        
        If Not Proxy_UseProxy And \RemoteSocket And ProtocolSsl
          ProcedureReturn Proxy_SendNetworkData(\LocalSocket, Proxy_Ssl_Connection_Established,39,@\LocalIsClosed)
        EndIf
      EndIf
    EndIf
    
    If \RemoteSocket
      ProcedureReturn Proxy_SendNetworkData(\RemoteSocket, \MemData,sIzemem)
    EndIf
  EndWith
EndProcedure

Procedure Proxy_WorkThread(*ProxyInfoList.Proxy)
  Protected RcvSiz.l,timeroutDown.q,timeroutSend.q,upwtimeroutDown.q,upwtimeroutSend.q
  With *ProxyInfoList
    Repeat
      Delay(10)
      
      If timeroutDown And (ElapsedMilliseconds() - timeroutDown)>1000
        Proxy_WindowSetInfo(\UniqId,#Proxy_ListIcon_TimeoutDownload,__ByteGetdisplaysize(\TotalDownload))
        timeroutDown=0
      EndIf
      If timeroutSend And (ElapsedMilliseconds() - timeroutSend)>1000
        Proxy_WindowSetInfo(\UniqId,#Proxy_ListIcon_TimeoutSend,__ByteGetdisplaysize(\TotalUpload))
        timeroutSend=0
      EndIf
      
      If Not \LocalIsClosed
        RcvSiz = ReceiveNetworkDataServer(\LocalSocket, \MemData, #Proxy_WorkMemorySize) 
        If RcvSiz > 0 
          If Proxy_RequestSend(RcvSiz,*ProxyInfoList)
            \TotalUpload + RcvSiz
            iProxy_TotalDownSendInfo\ProxyTotalUpload+ RcvSiz
            If ElapsedMilliseconds() - upwtimeroutSend > 1000
              Proxy_WindowSetInfo(\UniqId,#Proxy_ListIcon_Send,__ByteGetdisplaysize(\TotalUpload))
              upwtimeroutSend = ElapsedMilliseconds()
            EndIf
            timeroutSend = ElapsedMilliseconds()
          EndIf
        EndIf
      Else
        Proxy_WindowSetInfo(\UniqId,#Proxy_ListIcon_LocalIsClosed,"1 Ok")
        Break
      EndIf
      
      If \RemoteSocket
        Select NetworkClientEvent(\RemoteSocket) 
          Case #PB_NetworkEvent_Data
            RcvSiz = ReceiveNetworkData(\RemoteSocket, \MemData,#Proxy_WorkMemorySize)
            If RcvSiz  > 0
              If Proxy_SendNetworkData(\LocalSocket, \MemData,RcvSiz,@\LocalIsClosed)
                \TotalDownload + RcvSiz
                iProxy_TotalDownSendInfo\ProxyTotalDownload +RcvSiz
                If ElapsedMilliseconds() - upwtimeroutDown > 1000
                  Proxy_WindowSetInfo(\UniqId,#Proxy_ListIcon_Download,__ByteGetdisplaysize(\TotalDownload))
                  upwtimeroutDown = ElapsedMilliseconds()
                EndIf        
                timeroutDown = ElapsedMilliseconds()
              EndIf
            EndIf
          Case #PB_NetworkEvent_Disconnect
            \RemoteIsClosed=1
        EndSelect
      EndIf   
      
      If \RemoteIsClosed
        Proxy_WindowSetInfo(\UniqId,#Proxy_ListIcon_RemoteIsClosed,"1 Ok")
        Break
      EndIf
    ForEver
    
    If \RemoteSocket And NetworkClientEvent(\RemoteSocket)  <> #PB_NetworkEvent_Disconnect
      CloseNetworkConnection(\RemoteSocket )
    EndIf  
  EndWith
  
  PostEvent(#Proxy_Evenement_FreeConnection,Window_Proxy,0,0,*ProxyInfoList)
EndProcedure

Procedure Proxy_LocalRemoteIsConnected(ClientID)
  Protected *ProxyInfoList.Proxy= AllocateMemory(SizeOf(Proxy)+#Proxy_WorkMemorySize)
  If *ProxyInfoList
    With *ProxyInfoList
      RemoteProxyID +1
      \MemData= *ProxyInfoList+SizeOf(Proxy)
      \LocalSocketID = ClientID
      \LocalSocket = ConnectionID(ClientID)
      \UniqId = RemoteProxyID        
      AddElement(ProxyInfoList())
      ProxyInfoList()\Proxylist= *ProxyInfoList
      \ThreadId = CreateThread(@Proxy_WorkThread(),*ProxyInfoList)
      If  \ThreadId
        ProcedureReturn PostEvent(#Proxy_Evenement_StartConnection,Window_Proxy,0,0,*ProxyInfoList)
      Else
        RemoteProxyID -1
        DeleteElement(ProxyInfoList() )
      EndIf
    EndWith
  EndIf
  
  CloseNetworkConnection(ClientID)
  If *ProxyInfoList
    FreeMemory(*ProxyInfoList)
  EndIf
EndProcedure

Procedure Proxy_ListFind(Ifind,ifindtype.b=0)
  Protected Ex.b
  ForEach ProxyInfoList()
    With ProxyInfoList()\Proxylist
      If ifindtype
        If Ifind = \UniqId
          Ex=1
          Break
        EndIf
      Else
        If Ifind = \LocalSocketID
          Ex=1
          Break
        EndIf
      EndIf
    EndWith
  Next
  ProcedureReturn Ex
EndProcedure

Procedure Proxy_thread(i)
  Protected SEvent,ClientID
  
  Repeat
    Delay(10)
    LockMutex(Mutex_Proxy)
    SEvent = NetworkServerEvent()
    If SEvent
      
      ClientID = EventClient()
      Select SEvent
          
        Case #PB_NetworkEvent_Connect
          Proxy_LocalRemoteIsConnected(ClientID)
          
        Case #PB_NetworkEvent_Disconnect
          If Proxy_ListFind(ClientID)
            Proxy_WindowSetInfo(ProxyInfoList()\Proxylist\UniqId,#Proxy_ListIcon_LocalIsClosed,"1")
            ProxyInfoList()\Proxylist\LocalIsClosed = 1          
          EndIf
          
      EndSelect
    EndIf
    
    UnlockMutex(Mutex_Proxy)
  ForEver
EndProcedure

Procedure Window_ProxyResize()
  Protected FormWindowWidth, FormWindowHeight
  FormWindowWidth = WindowWidth(Window_Proxy)
  FormWindowHeight = WindowHeight(Window_Proxy)
  ResizeGadget(ListIcon_Proxy, 10, 10, FormWindowWidth - 20, (FormWindowHeight - 40)-StatusBarHeight(StatusBar_Proxy))
EndProcedure

Procedure Window_ProxyClose()
  End
EndProcedure

Procedure Window_ProxyStartConnection()
  Protected evd = EventData()
  If evd 
    Protected *ProxyInfoList.Proxy=evd
    With *ProxyInfoList
      Protected GadgetItemC.l = CountGadgetItems(ListIcon_Proxy)
      AddGadgetItem(ListIcon_Proxy,GadgetItemC,Str(\LocalSocketID))
      SetGadgetItemData(ListIcon_Proxy,GadgetItemC,\UniqId)
    EndWith
  EndIf
EndProcedure

Procedure Window_ProxyGetGadgetItemByData(iData.l)
  Protected ll.l,iReturn.l=-1
  For ll = 0 To CountGadgetItems(ListIcon_Proxy)-1
    If iData = GetGadgetItemData(ListIcon_Proxy,ll)
      iReturn = ll
      Break 
    EndIf
  Next
  If iReturn = -1
    Debug ",,item data not found?? :/" +Str(iData)
  EndIf
  ProcedureReturn iReturn
EndProcedure

Procedure Window_ProxyFreeConnection()
  Protected evd = EventData()
  If evd
    Protected *ProxyInfoList.Proxy = evd
    With *ProxyInfoList
      
      LockMutex(Mutex_Proxy)
      If Proxy_ListFind(\UniqId,1)
        DeleteElement(ProxyInfoList())
      EndIf
      If Not \LocalIsClosed
        CloseNetworkConnection(\LocalSocketID)
      EndIf
      UnlockMutex(Mutex_Proxy)
      
      Protected GadgetItem =  Window_ProxyGetGadgetItemByData(\UniqId)
      If GadgetItem > -1
        If \SaveHost = #Null$
          RemoveGadgetItem(ListIcon_Proxy,GadgetItem)
        Else
          SetGadgetItemText(ListIcon_Proxy,GadgetItem,"1",#Proxy_ListIcon_FreeConnection)
          SetGadgetItemColor(ListIcon_Proxy,GadgetItem,#PB_Gadget_BackColor,$878DF9)
          If Not \LocalIsClosed
            SetGadgetItemColor(ListIcon_Proxy,GadgetItem,#PB_Gadget_BackColor,$84BBBF,#Proxy_ListIcon_FreeConnection)
          EndIf
          SetGadgetItemData(ListIcon_Proxy,GadgetItem,0)
        EndIf
      EndIf
      
      FreeMemory(*ProxyInfoList)
    EndWith
  EndIf
EndProcedure

Procedure Window_ProxyChekActiveCookies()
  If ProxyAcceptCookies
    SetMenuItemState(#Proxy_menu,#Proxy_AcceptCookies,#False)
    ProxyAcceptCookies =0
  Else
    SetMenuItemState(#Proxy_menu,#Proxy_AcceptCookies,#True)
    ProxyAcceptCookies=1
  EndIf
EndProcedure

Procedure Window_ProxyShowStatueInfo()
  Protected dowrat.l,sendrat.l,eltim.l
  With iProxy_TotalDownSendInfo
    eltim = ElapsedMilliseconds()-\ProxyTimer
    If eltim>= 1000
      \ProxyTotalDownloadRate=(\ProxyTotalDownload- \ProxyTotalDownloadSave)*1000/eltim
      \ProxyTotalUploadRate=(\ProxyTotalUpload- \ProxyTotalUploadSave)*1000/eltim
      \ProxyTotalDownloadSave=\ProxyTotalDownload
      \ProxyTotalUploadSave=\ProxyTotalUpload
      \ProxyTimer = ElapsedMilliseconds()
    EndIf
    If LocalServerProxy
      StatusBarText(StatusBar_Proxy, 0, " D:" +__ByteGetdisplaysize(\ProxyTotalDownload) + " Rate : " + __ByteGetdisplaysize( \ProxyTotalDownloadRate)+ " U:" + __ByteGetdisplaysize(\ProxyTotalUpload) + " Rate : " + __ByteGetdisplaysize( \ProxyTotalUploadRate))
    Else
      StatusBarText(StatusBar_Proxy, 0, "No listen...")      
    EndIf    
  EndWith
EndProcedure

Procedure Window_ProxyShowLicInfo()
  Protected evd = EventData()
  If evd
    Protected *infom.Proxy_WindowInfo = evd
    With *infom
      Protected GadgetItem =  Window_ProxyGetGadgetItemByData(\UniqId)
      If GadgetItem > -1
        Select \Clume
          Case #Proxy_ListIcon_WebSite
            SetGadgetItemColor(ListIcon_Proxy,GadgetItem,#PB_Gadget_BackColor,$85D4AB)
            If GetGadgetItemText(ListIcon_Proxy,GadgetItem,\Clume) <> #Null$
              SetGadgetItemColor(ListIcon_Proxy,GadgetItem,#PB_Gadget_BackColor,$C785D4,\Clume)
            EndIf
            SetGadgetItemText(ListIcon_Proxy,GadgetItem,\StringTo,\Clume)
          Case #Proxy_ListIcon_Download,#Proxy_ListIcon_Send
            SetGadgetItemColor(ListIcon_Proxy,GadgetItem,#PB_Gadget_BackColor,$D49F85,\Clume)
            SetGadgetItemText(ListIcon_Proxy,GadgetItem,\StringTo,\Clume)
          Case #Proxy_ListIcon_TimeoutDownload, #Proxy_ListIcon_TimeoutSend
            SetGadgetItemColor(ListIcon_Proxy,GadgetItem,#PB_Gadget_BackColor,$85D4AB,\Clume-5)
            SetGadgetItemText(ListIcon_Proxy,GadgetItem,\StringTo,\Clume-5)
          Case #Proxy_ListIcon_Redirect,#Proxy_ListIcon_Block
            SetGadgetItemText(ListIcon_Proxy,GadgetItem,\StringTo,#Proxy_ListIcon_WebSite)
          Default 
            SetGadgetItemText(ListIcon_Proxy,GadgetItem,\StringTo,\Clume)
        EndSelect
      EndIf
    EndWith
    FreeMemory(*infom)
  EndIf
EndProcedure

Procedure Window_ProxyClear()
  Protected ll.l
  For ll = 0 To CountGadgetItems(ListIcon_Proxy)-1
    If ll > CountGadgetItems(ListIcon_Proxy)-1
      Break
    EndIf
    If 0 = GetGadgetItemData(ListIcon_Proxy,ll)
      RemoveGadgetItem(ListIcon_Proxy,ll)
      ll - 1
    EndIf
  Next
EndProcedure

Procedure Window_ProxyRBlockClose()
  HideWindow(Window_ProxyRBlock,1)
EndProcedure

Procedure Window_ProxyRBlockShow()
  HideWindow(Window_ProxyRBlock,0,#PB_Window_ScreenCentered|#PB_Window_WindowCentered)
EndProcedure

Procedure Window_ProxyRBlockAdd()
  Protected GetSite.s = GetGadgetText(String_ProxyRBlockSite)
  If GetSite = #Null$
    ProcedureReturn
  EndIf
  AddGadgetItem(ListIcon_ProxyRBlock,-1,GetSite ) 
  Proxy_BlockSiteStringlist + "||"+GetSite+"||"
  SetMenuItemState(#Proxy_menu,#Proxy_BlockSite,#True)
EndProcedure

Procedure Window_ProxyRBlockDelete()
  Protected gsl = GetGadgetState(ListIcon_ProxyRBlock)
  If gsl =-1
    ProcedureReturn
  EndIf
  Proxy_BlockSiteStringlist=ReplaceString(Proxy_BlockSiteStringlist,"||"+GetGadgetItemText(ListIcon_ProxyRBlock,gsl,0)+"||","")
  RemoveGadgetItem(ListIcon_ProxyRBlock,gsl)
  If Proxy_BlockSiteStringlist=#Null$
    SetMenuItemState(#Proxy_menu,#Proxy_BlockSite,#False)
  EndIf
EndProcedure

Procedure Window_ProxyRBlockShowPopupMenu()
  DisplayPopupMenu(#Proxy_PopupMenuRBlock,WindowID(Window_ProxyRBlock))
EndProcedure

Procedure Window_ProxyRBlock()
  Window_ProxyRBlock = OpenWindow(#PB_Any, 0, 0, 280, 150, "Block Website", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_WindowCentered | #PB_Window_Invisible,WindowID(Window_Proxy))
  TextGadget(#PB_Any, 10, 10, 30, 20, "Site")
  String_ProxyRBlockSite = StringGadget(#PB_Any, 45, 10, 180, 20, "www.youtube.com")
  ListIcon_ProxyRBlock = ListIconGadget(#PB_Any, 10, 40, 260, 100, "Site", 300)
  BindGadgetEvent(ButtonGadget(#PB_Any, 230, 10, 40, 20, "+"),@Window_ProxyRBlockAdd(), #PB_EventType_LeftClick  )
  BindGadgetEvent(ListIcon_ProxyRBlock,@Window_ProxyRBlockShowPopupMenu(), #PB_EventType_RightClick  )
  BindEvent(#PB_Event_CloseWindow ,@Window_ProxyRBlockClose(),Window_ProxyRBlock)
  CreatePopupMenu(#Proxy_PopupMenuRBlock)    
  MenuItem(#Proxy_PopupMenuRBlockDelete, "&Delete")
  BindMenuEvent(#Proxy_PopupMenuRBlock,#Proxy_PopupMenuRBlockDelete,@Window_ProxyRBlockDelete())
EndProcedure

Procedure Window_ProxySettingsClose()
  If Not Proxy_UseProxy
    SetGadgetState(Checkbox_ProxySt,#PB_Checkbox_Unchecked)
  EndIf
  HideWindow(Window_ProxySettings,1)
EndProcedure

Procedure Window_ProxySettingsSave()
  Protected.s usip,usport,uslogin,uspass,uschek.b
  usip = GetGadgetText(String_ProxyStip)
  usport = GetGadgetText(String_ProxyStport)
  uslogin = GetGadgetText(String_ProxyStlogin)
  uspass = GetGadgetText(String_ProxyStpass)
  uschek =Bool( GetGadgetState(Checkbox_ProxySt)=#PB_Checkbox_Checked)
  If Not uschek
    Proxy_UseProxy=0
    StatusBarText(StatusBar_Proxy, 1, "Proxy off")
    SetMenuItemState(#Proxy_menu,#Proxy_ConProxy,#False)
    ProcedureReturn Window_ProxySettingsClose()
  EndIf
  If usip = #Null$ Or  usport = #Null$ 
    ProcedureReturn
  EndIf
  Proxy_UseProxy=1
  Proxy_UseProxyIp = usip
  Proxy_UseProxyPort = Val(usport)
  ;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization
  Protected  Proxy_tUseProxyAuthCode = UTF8(uslogin +":"+ uspass)
  Protected Proxy_UseProxyAuthCodeB64.s = Base64Encoder(Proxy_tUseProxyAuthCode, MemorySize(Proxy_tUseProxyAuthCode), #PB_Cipher_URL  )
  Proxy_UseProxyAuthCode = #CRLF$ + "Proxy-Authorization: Basic " + Proxy_UseProxyAuthCodeB64+#CRLF$+#CRLF$
  StatusBarText(StatusBar_Proxy, 1, "Proxy On : " + Proxy_UseProxyIp)
  SetMenuItemState(#Proxy_menu,#Proxy_ConProxy,#True)
  Window_ProxySettingsClose()
EndProcedure

Procedure Window_ProxySettingsShow()
  HideWindow(Window_ProxySettings,0)
EndProcedure

Procedure Window_ProxySettings()
  Window_ProxySettings = OpenWindow(#PB_Any, 0, 0, 250, 150, "Proxy Settings", #PB_Window_SystemMenu | #PB_Window_Invisible | #PB_Window_ScreenCentered | #PB_Window_WindowCentered | #PB_Window_Invisible,WindowID(Window_Proxy))
  Checkbox_ProxySt = CheckBoxGadget(#PB_Any, 10, 10, 100, 20, "Use Proxy")
  TextGadget(#PB_Any, 10, 40, 60, 20, "IP")
  TextGadget(#PB_Any, 10, 100, 60, 20, "Password")
  TextGadget(#PB_Any, 10, 60, 60, 20, "Port")
  TextGadget(#PB_Any, 10, 80, 60, 20, "Login")
  String_ProxyStip = StringGadget(#PB_Any, 80, 40, 160, 20, "89.163.152.242")
  String_ProxyStport = StringGadget(#PB_Any, 80, 60, 160, 20, "3128", #PB_String_Numeric)
  String_ProxyStlogin = StringGadget(#PB_Any, 80, 80, 160, 20, "")
  String_ProxyStpass = StringGadget(#PB_Any, 80, 100, 160, 20, "")
  Protected Button_ProxySt = ButtonGadget(#PB_Any, 200, 125, 40, 20, "Save")
  BindGadgetEvent(Button_ProxySt,@Window_ProxySettingsSave(), #PB_EventType_LeftClick)
  BindEvent(#PB_Event_CloseWindow ,@Window_ProxySettingsClose(),Window_ProxySettings)
EndProcedure

Procedure Window_ProxyListenPortClose()
  HideWindow(Window_ProxyListenPort,1)
EndProcedure

Procedure Window_ProxyListenPortShow()
  HideWindow(Window_ProxyListenPort,0,#PB_Window_ScreenCentered|#PB_Window_WindowCentered)
EndProcedure

Procedure Window_ProxyListenPortStop()
  If Not LocalServerProxy:ProcedureReturn:EndIf
  LockMutex(Mutex_Proxy)  
  CloseNetworkServer(LocalServerProxy)
  ForEach ProxyInfoList()
    ProxyInfoList()\Proxylist\LocalIsClosed=1
  Next
  LocalServerProxy=0
  UnlockMutex(Mutex_Proxy)
  SetGadgetText(Button_ProxyStart,"Start")
  SetMenuItemState(#Proxy_menu,#Proxy_addporr,#False)
EndProcedure

Procedure Window_ProxyListenPortSart()
  If LocalServerProxy:ProcedureReturn Window_ProxyListenPortStop():EndIf
  Protected GetPort.w = Val(GetGadgetText(String_Proxy))
  If Not GetPort
    ProcedureReturn
  EndIf
  LocalServerProxy = CreateNetworkServer(#PB_Any,Getport , #PB_Network_TCP|#PB_Network_IPv4,"127.0.0.1")
  If Not LocalServerProxy
    MessageRequester("Error  ", "Can't create the server on port " +Str(Getport)+", (port in use ?).", 0)
    ProcedureReturn
  EndIf
  SetGadgetText(Button_ProxyStart,"Stop")
  SetMenuItemState(#Proxy_menu,#Proxy_addporr,#True)
EndProcedure

Procedure Window_ProxyListenPort()
  Window_ProxyListenPort = OpenWindow(#PB_Any, 0, 0, 190, 40, "Listen Port", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_WindowCentered | #PB_Window_Invisible,WindowID(Window_Proxy))
  TextGadget(#PB_Any, 10, 10, 30, 20, "Port")
  String_Proxy = StringGadget(#PB_Any, 45, 10, 80, 20, "888", #PB_String_Numeric)
  Button_ProxyStart = ButtonGadget(#PB_Any, 130, 10, 50, 20, "Start")
  BindGadgetEvent(Button_ProxyStart,@Window_ProxyListenPortSart(), #PB_EventType_LeftClick  )
  BindEvent(#PB_Event_CloseWindow ,@Window_ProxyListenPortClose(),Window_ProxyListenPort)
EndProcedure

Procedure Window_Proxy()
  Window_Proxy = OpenWindow(#PB_Any, 0, 0, 400, 260, "Proxy", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered | #PB_Window_WindowCentered | #PB_Window_Invisible)
  StatusBar_Proxy=CreateStatusBar(#PB_Any, WindowID(Window_Proxy))
  AddStatusBarField(#PB_Ignore)
  AddStatusBarField(300)
  StatusBarText(StatusBar_Proxy, 1, "Proxy off")
  
  CreateMenu(#Proxy_menu, WindowID(Window_Proxy)) 
  MenuTitle("&Settings")
  MenuItem(#Proxy_addporr, "&Select a Port")
  BindMenuEvent(#Proxy_menu,#Proxy_addporr,@Window_ProxyListenPortShow())
  MenuItem(#Proxy_ConProxy, "&Use proxy")
  BindMenuEvent(#Proxy_menu,#Proxy_ConProxy,@Window_ProxySettingsShow())
  MenuItem(#Proxy_BlockSite, "&Block Site")
  BindMenuEvent(#Proxy_menu,#Proxy_BlockSite,@Window_ProxyRBlockShow())
  MenuItem(#Proxy_AcceptCookies, "&Accept Cookies")
  BindMenuEvent(#Proxy_menu,#Proxy_AcceptCookies,@Window_ProxyChekActiveCookies())
  MenuBar() 
  MenuItem(#Proxy_Clearlist, "Clear List")
  BindMenuEvent(#Proxy_menu,#Proxy_Clearlist,@Window_ProxyClear())
  MenuItem(#Proxy_Exit, "Exit")
  BindMenuEvent(#Proxy_menu,#Proxy_Exit,@Window_ProxyClose())
  MenuTitle("&About")
  MenuItem(#Proxy_Me, "By Celtic88 Dz(c) v1.1b")
  
  ListIcon_Proxy = ListIconGadget(#PB_Any, 10, 10, 380, 240-StatusBarHeight(StatusBar_Proxy),"Local ID",100,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
  AddGadgetColumn(ListIcon_Proxy,#Proxy_ListIcon_RemoteId,"Remote ID",100)
  AddGadgetColumn(ListIcon_Proxy,#Proxy_ListIcon_Method,"Method",100)
  AddGadgetColumn(ListIcon_Proxy,#Proxy_ListIcon_WebSite,"Web Site",100)
  AddGadgetColumn(ListIcon_Proxy,#Proxy_ListIcon_Download,"Download",100)
  AddGadgetColumn(ListIcon_Proxy,#Proxy_ListIcon_Send,"Send",100)
  AddGadgetColumn(ListIcon_Proxy,#Proxy_ListIcon_LocalIsClosed,"Local Is Closed",100)
  AddGadgetColumn(ListIcon_Proxy,#Proxy_ListIcon_RemoteIsClosed,"Remote Is Closed",100)
  AddGadgetColumn(ListIcon_Proxy,#Proxy_ListIcon_FreeConnection,"Free Connection",100)
  BindEvent(#PB_Event_CloseWindow ,@Window_ProxyClose(),Window_Proxy)
  BindEvent(#PB_Event_SizeWindow ,@Window_ProxyResize(),Window_Proxy)
  BindEvent(#Proxy_Evenement_FreeConnection ,@Window_ProxyFreeConnection(),Window_Proxy)
  BindEvent(#Proxy_Evenement_StartConnection ,@Window_ProxyStartConnection(),Window_Proxy)
  BindEvent(#PB_Event_Timer ,@Window_ProxyShowStatueInfo(),Window_Proxy)
  BindEvent(#Proxy_Evenement_SetInfo,@Window_ProxyShowLicInfo(),Window_Proxy)
  AddWindowTimer(Window_Proxy,0,500)
  StickyWindow(Window_Proxy,1)
  ResizeWindow(Window_Proxy, #PB_Ignore , #PB_Ignore ,800,400)
  HideWindow(Window_Proxy,0,#PB_Window_ScreenCentered|#PB_Window_WindowCentered)
EndProcedure

Window_Proxy()
Window_ProxyListenPort()
Window_ProxyRBlock()
Window_ProxySettings()
CreateThread(@Proxy_thread(),0)

Repeat:WaitWindowEvent():ForEver
amusez vous :D
Dernière modification par celtic88 le mar. 21/mars/2017 17:11, modifié 5 fois.
.....i Love Pb :)
Avatar de l’utilisateur
djes
Messages : 4252
Inscription : ven. 11/févr./2005 17:34
Localisation : Arras, France

Re: Mini Proxy localhost beta v0.01

Message par djes »

Très bon exemple, comme d'hab :)
Merci !
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: Mini Proxy localhost beta v0.01

Message par Kwai chang caine »

Bonjour CELTIC :D

Ayaihhhh !!!! je sais pourquoi tu as une chemise ROUGE !!!!
Parce que t'es le pere noel en vacance au soleil !!!!! :mrgreen:
Le genie a écrit :comme voire ou modifier les Requêtes
Incroyable je cherche à faire ça depuis noir de temps, j'en parlais juste avant à DJES sur un autre thread 8O
Va falloir que je me penche sur ton code pour essayer de comprendre :?

En tout cas du as déjà mérité un grand merci 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: Mini Proxy localhost beta v0.01

Message par Kwai chang caine »

Bon, j'ai fait un essai pas concluant :|
Mais je pense que c'est normal, car j'ai déjà un vrai PROXY ici
Je ferais des essais la ou il n'en a pas :wink:
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
boby
Messages : 261
Inscription : jeu. 07/juin/2007 22:54

Re: Mini Proxy localhost beta v0.01

Message par boby »

Voila un code qui semble très intéressant à éplucher !
Merci pour le partage ça devrais permettre d'apprendre dans de nouveaux domaines !
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Mini Proxy localhost beta v0.01

Message par celtic88 »

merci les mecs pour vos commentaires :)
Si j'ai le temps, je vais l'améliorer plus et corriger les erreurs a+
.....i Love Pb :)
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Mini Proxy localhost beta v0.01

Message par celtic88 »

Kwai chang caine a écrit :Bonjour CELTIC :D

Ayaihhhh !!!! je sais pourquoi tu as une chemise ROUGE !!!!
Parce que t'es le pere noel en vacance au soleil !!!!! :mrgreen:
Le genie a écrit :comme voire ou modifier les Requêtes
Incroyable je cherche à faire ça depuis noir de temps, j'en parlais juste avant à DJES sur un autre thread 8O
Va falloir que je me penche sur ton code pour essayer de comprendre :?

En tout cas du as déjà mérité un grand merci 8)
lol :D ,merci :wink:
.....i Love Pb :)
Avatar de l’utilisateur
venom
Messages : 3071
Inscription : jeu. 29/juil./2004 16:33
Localisation : Klyntar
Contact :

Re: Mini Proxy localhost beta v0.01

Message par venom »

Bravo celtic88,

Comme d'habitude, pas de blabla du résultat 8)






@++
Windows 10 x64, PureBasic 5.73 x86 & x64
GPU : radeon HD6370M, CPU : p6200 2.13Ghz
Avatar de l’utilisateur
ChaudEf
Messages : 179
Inscription : dim. 27/déc./2015 17:02
Localisation : Strasbourg

Re: Mini Proxy localhost beta v0.01

Message par ChaudEf »

Celtic il est extra ton code!!

On peut vraiment faire des belles choses en programation hein!!

Je ne sais pas si c'est un probleme chez moi ou pas, mais apres trente secondes le debugger quitte, et il y a une erreur d'acces memoire.
Windows 10 x64 -- Purebasic 5.70 LTS x86
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: Mini Proxy localhost beta v0.01

Message par celtic88 »

@ChaudEf
merci pour ton message :) , je vais le corriger dans prochaine version.
.....i Love Pb :)
Avatar de l’utilisateur
ChaudEf
Messages : 179
Inscription : dim. 27/déc./2015 17:02
Localisation : Strasbourg

Re: Mini Proxy localhost beta v0.01

Message par ChaudEf »

Ce qui serait vraiement cool (mais je ne sais pas si c'est faisable) serait de pouvoir bloquer des pages, et afficher a la place un message d'erreur personnalisé.
Windows 10 x64 -- Purebasic 5.70 LTS x86
Avatar de l’utilisateur
celtic88
Messages : 309
Inscription : sam. 12/sept./2015 14:31
Localisation : Alger

Re: *mise à jour Proxy v1.0

Message par celtic88 »

**mise à jour Proxy v1.0

-Le code a été ré-écrit depuis le début
-Beaucoup d'erreurs ont été corrigés
-Ajouter la fonction connecter via un proxy externe avec ou son authentification
.....i Love Pb :)
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: *mise à jour Proxy v1.0

Message par Kwai chang caine »

J'ai une erreur ligne 599 Base64Encoder() nb de paramètres incorrects :|
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: *mise à jour Proxy v1.0

Message par falsam »

Kwai chang caine a écrit :J'ai une erreur ligne 599 Base64Encoder() nb de paramètres incorrects :|
Compile avec la version 5.50 au lieu de 5.60
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: *mise à jour Proxy v1.0

Message par Kwai chang caine »

Merci FALSAM 8)
Put....alors pour une fois que je me fend d'avoir la derniere version de quelque chose :? :mrgreen: :lol:
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Répondre