Advertisement
Guest User

automatic way to stop the seeding in uTorrent

a guest
Jan 25th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     '// Leecher app is an automatic way to stop the seeding in BitTorrent/uTorrent client.
  2.     '// This app works on all Win32 (MS Windows).
  3.     '//
  4.     '// Leecher
  5.     '// (C) Rui Branco - rmrbranco@gmail.com
  6.     '// Project home https://googledrive.com/host/0B5MAgOEuMAVadE1oZnJxUzVrTDA/
  7.     '//
  8.     '// Resources
  9.     '// The language and compiler http://www.libertybasic.com/
  10.     '// The compiler to make single exe and console app http://www.lbbooster.com/
  11.     '// uTorrent software http://www.utorrent.com or BitTorrent software http://www.bittorrent.com
  12.     '// The Webui http://www.utorrent.com/intl/en/help/guides/webui and Webui API http://forum.utorrent.com/viewtopic.php?pid=318056#p318056
  13.     '// Support token authentication http://forum.utorrent.com/viewtopic.php?id=58111 or https://github.com/bittorrent/webui/wiki/TokenSystem
  14.     '// Sendmail http://www.glob.com.au/sendmail/
  15.     '// MS-DOS cmd.exe http://www.microsoft.com/resources/
  16.  
  17.  
  18.  
  19.  
  20.     '// Changelog:
  21.     '// 25-01-2014 - Info,    the app works great and put everything need to work. I will adapt the code again when in resources exists changes
  22.     '// 25-01-2014 - Added,   token authentication
  23.     '// 25-01-2014 - Added,   a better way to rename files and folders
  24.     '// 19-01-2014 - Added,   improvements, adjustments and comments
  25.     '// 19-01-2014 - Added,   function to check if Internet connection and webui is avaiable
  26.     '// 18-01-2014 - Fix,     bugfix
  27.     '// 17-01-2014 - Added,   adapted code to new features
  28.     '// 17-01-2014 - Added,   functions to protect data in config.conf in your machine(encryption passswords only)
  29.     '// 15-01-2014 - Info,    I and my account was banned from utorrent.com and bittorrent.com forums
  30.     '// 15-01-2014 - Fix,     adapting the code to BitTorrent client
  31.     '// 15-01-2014 - Added,   support to email notifications
  32.     '// 12-01-2014 - Added,   option in config to choose stop start pause remove... actions for webui
  33.     '// 11-01-2014 - Added,   webui support.
  34.     '// 07-01-2014 - Added,   anti collision names of files and folders.
  35.     '// 07-01-2014 - Added,   several checks existence of content.
  36.     '// 07-01-2014 - Added,   retry sending wm_close command in the case of the window not closing.
  37.     '// 06-01-2014 - Added,   function to save the steps in output.log.
  38.  
  39.  
  40.  
  41.  
  42.     '// Nomainwin somewhere in the program source code prevents the window from opening.
  43.     '// You can uncomment if you want silent mode
  44.     'NOMAINWIN
  45.  
  46.     '// Put the arguments sent by BitTorrent/uTorrent in lowercase and send for strings
  47.     argut$ = lower$(CommandLine$)
  48.     dir$ = lower$(CommandLine$)
  49.     title$ = lower$(CommandLine$)
  50.     hash$ = lower$(CommandLine$)
  51.  
  52.     '// Use and get dir from appdata variable
  53.     utdir$ = Environ$("APPDATA")
  54.  
  55.     '// Set 0 if is a first time to run app
  56.     firsttime = 0
  57.  
  58.     '// Load config
  59.     gosub [loadconfig]
  60.  
  61.     '// If first time to run app then create config
  62.     if firsttime = 1 then
  63.         gosub [createconfig]
  64.         'Relaod config
  65.         gosub [loadconfig]
  66.     end if
  67.  
  68.     '// If you change password to new password the code will encrypt the same
  69.     if encrypta = 1 or encryptb = 1 then
  70.         gosub [createconfig]
  71.         'At the end encryption passwords, go to load settings and put in strings
  72.         gosub [loadconfig]
  73.     end if
  74.  
  75.     '// If argument is nothing will call the sub info
  76.     if not(argut$ <> "") then
  77.         gosub [info]
  78.  
  79.         '// Wait the user to close the window
  80.         wait
  81.  
  82.         '// Exit app
  83.         end
  84.  
  85.     else
  86.  
  87.         '// If in argument exists bittorrent/utorrent word, the title will fitrate and put in strings
  88.         if instr(argut$, "utorrent") or instr(argut$, "�torrent") or instr(argut$, "bittorrent") then
  89.             if instr(argut$, "�torrent") or instr(argut$, "utorrent") then
  90.                 arg$ = mid$(argut$, 10, 6)
  91.                 resulta$ = "�Torrent";arg$ : defdir$ = "uTorrent"
  92.             end if
  93.             if instr(argut$, "bittorrent") then
  94.                 arg$ = mid$(argut$, 12, 6)
  95.                 resulta$ = "bittorrent";arg$ : defdir$ = word$(resulta$,1)
  96.             end if
  97.  
  98.             '// Fitrate dir, title and hash and put in strings
  99.             dir$ = word$(dir$, 4, chr$(34))
  100.             title$ = word$(title$, 6, chr$(34))
  101.             hash$ = word$(hash$, 8, chr$(34))
  102.  
  103.             '// Call cmd command line put the title and send info to the console window
  104.             Run "cmd.exe /C title Leecher"
  105.             print "Leecher - automatic way to stop the seeding in BitTorrent/uTorrent"
  106.             print ""
  107.             print ""
  108.             print "Output:"
  109.  
  110.             '// Create log with sub output
  111.             output$ = " " : gosub [output]
  112.             output$ = "- Start ";date$();" - ";time$() : gosub [output]
  113.             output$ = "Arg. ";argut$ : gosub [output]
  114.             if yesno$ = "no" then output$ = "Version ";arg$ : gosub [output]
  115.             if yesno$ = "no" then output$ = "Real Window name ";resulta$ : gosub [output]
  116.             if yesno$ = "no" then output$ = "Dir ";dir$ : gosub [output]
  117.             if yesno$ = "no" then output$ = "Title ";title$ : gosub [output]
  118.             if yesno$ = "yes" then output$ = "Hash ";hash$ : gosub [output]
  119.  
  120.             '// If you config to use webui will go to webui
  121.             if yesno$ = "yes" then
  122.  
  123.                 if tokenyesno$ = "no" then
  124.  
  125.                     '// The address with the data available in conf to make the request. The request is make without token auth
  126.                     address$ = "http://";login$;":";password$;"@";ip$;"/gui/?action=";action$;"&hash=";hash$
  127.                     gosub [webui]
  128.  
  129.                     if instr(Buffer$, "build") then
  130.  
  131.                         '// Create output
  132.                         output$ = "Action " ; action$ ; " " ; title$ : gosub [output]
  133.                         output$ = "Webui output is ok " ; Buffer$ : gosub [output]
  134.  
  135.                     else
  136.  
  137.                         if instr(Buffer$, "invalid request") or instr(Buffer$, "") = 0 and resulticc = 0  then
  138.  
  139.                             output$ = "Webui output is not ok. You have internet connection but... login/password problem? or port problem? " ; Buffer$ : gosub [output]
  140.                             notifyemail$ = "no"
  141.  
  142.                         end if
  143.  
  144.                     end if
  145.  
  146.                     '// Send email
  147.                     if notifyemail$ = "yes" then gosub [send.email]
  148.  
  149.                 else
  150.  
  151.                     '// The address with the data available in conf to make the request. The request is make with token auth
  152.                     address$ = "http://";login$;":";password$;"@";ip$;"/gui/token.html"
  153.                     gosub [webui]
  154.  
  155.                     if instr(Buffer$, "token") then
  156.  
  157.                         '// Create output
  158.                         output$ = "Action " ; action$ ; " " ; title$ : gosub [output]
  159.                         output$ = "Webui output is ok " ; Buffer$ : gosub [output]
  160.  
  161.                         '// Get token value and make the request
  162.                         tokena$ =  word$(Buffer$, 2, ";'>") : tokenresult$ =  word$(tokena$, 1, "</")
  163.                         address$ = "http://";ip$;"/gui/?token=";tokenresult$;"&action=";action$;"&hash=";hash$
  164.                         gosub [webui]
  165.  
  166.                     else
  167.  
  168.                         if resulticc = 0 then
  169.  
  170.                             output$ = "Webui output is not ok. You have internet connection but... login/password problem? or port problem? " ; Buffer$ : gosub [output]
  171.                             notifyemail$ = "no"
  172.  
  173.                         end if
  174.  
  175.                     end if
  176.  
  177.                     '// Send email
  178.                     if notifyemail$ = "yes" then gosub [send.email]
  179.  
  180.                 end if
  181.  
  182.                 '// Exit app
  183.                 gosub [end]
  184.  
  185.             end if
  186.  
  187.         else
  188.  
  189.             '// If argument is nothing will call the sub info
  190.             gosub [info]
  191.  
  192.             '// Wait the user to close the window
  193.             wait
  194.  
  195.             '// Exit app
  196.             end
  197.  
  198.         end if
  199.  
  200.     end if
  201.  
  202.     '// Send close command to BitTorrent/uTorrent
  203.     gosub [sendclose]
  204.  
  205.     '// The Loop is for the case of the window have not closed
  206. [loop]
  207.     '// Start perform action in torrent client
  208.     '// -when window close rename the folder name or file name and kill the torrent file
  209.     if ut = 0 then
  210.         dim info$(10, 10)
  211.         if fileExists(dir$, title$) then
  212.  
  213.             '// Get file extension
  214.             gosub [extension]
  215.  
  216.             '// Create output. The time$() is a simple way to prevent collision of names
  217.             output$ = "Rename file " ; dir$ ; title$ ; " as " ; dir$  ; title$ ; "  -  " ; time$("milliseconds") ; "." ; extension$ : gosub [output]
  218.  
  219.             '// Rename file
  220.             name dir$ ; title$ as dir$ ; title$ ; "  -  " ; time$("milliseconds") ; "." ; extension$
  221.  
  222.         else
  223.  
  224.             dim info$(10,10 )
  225.             if folderExists(dir$) then
  226.  
  227.                 '// Create output. The time$() is a simple way to prevent collision of names
  228.                 output$ = "Rename folder ";dir$; "  -  " ; time$("milliseconds") : gosub [output]
  229.  
  230.                 '// Rename folder
  231.                 name dir$ as dir$;"  -  " ; time$("milliseconds")
  232.  
  233.             else
  234.  
  235.                 '// Create output
  236.                 output$ = "The folder or file does not exist at this location ";dir$ : gosub [output]
  237.  
  238.             end if
  239.  
  240.         end if
  241.  
  242.         dim info$(10, 10)
  243.         if fileExists(utdir$;"\";defdir$;"\", title$;".torrent") then
  244.  
  245.             '// Create output
  246.             output$ = "Kill torrent file ";utdir$;"\";defdir$;"\";title$;".torrent" : gosub [output]
  247.  
  248.             '// Kill .torrent file
  249.             kill utdir$;"\";defdir$;"\";title$;".torrent"
  250.  
  251.         else
  252.  
  253.             '// Create output
  254.             output$ = "The file .torrent does not exist at this location ";utdir$;"\";defdir$;"\";title$;".torrent" : gosub [output]
  255.  
  256.         end if
  257.  
  258.     else
  259.  
  260.         '// Retry sending close command
  261.         gosub [sendclose]
  262.  
  263.         '// Returned from the sub, now recheck BitTorrent/uTorrent is already closed
  264.         goto [loop]
  265.  
  266.     end if
  267.  
  268.     '// Check if client BitTorrent/uTorrent.exe exists
  269.     dim info$(10, 10)
  270.     if fileExists(utdir$;"\";defdir$;"\", defdir$;".exe") then
  271.  
  272.         '// Create output
  273.         output$ = "Start ";defdir$;" ";utdir$;"\";defdir$;"\";defdir$;".exe" : gosub [output]
  274.  
  275.         '// Finally run BitTorrent/utorrent and show minimized
  276.         run utdir$;"\";defdir$;"\";defdir$;".exe", SHOWMINIMIZED
  277.  
  278.         '// Send email
  279.         if notifyemail$ = "yes" then gosub [send.email]
  280.  
  281.     else
  282.  
  283.         '// Create output
  284.         output$ = "The file ";defdir$;".exe does not exist at this location ";utdir$;"\";defdir$;"\";defdir$;".exe" : gosub [output]
  285.  
  286.     end if
  287.  
  288.     '// Exit app
  289.     gosub [end]
  290.     '// End perform action in torrent client
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.     '// Location of Subs and Functions
  317.  
  318. [end]
  319.     '// Create output and exit app
  320.     output$ = "- End ";date$();" - ";time$() : gosub [output]
  321.     End
  322.  
  323.  
  324. [info]
  325.     '// Show info
  326.  
  327.     '// Call cmd command line put the title and send info to the console window
  328.     Run "cmd.exe /C title Leecher"
  329.  
  330.     print "-Help, using Leecher in BitTorrent/uTorrent(desktop):"
  331.     print " "
  332.     print "You need the exactly title of the BitTorrent/uTorrent window and parameters."
  333.     print ""
  334.     print "(1) In BitTorrent/uTorrent go to,"
  335.     print "    Options/preferences/UI Settings."
  336.     print "    Remove value true in (Close button closes uT to tray)"
  337.     print ""
  338.     print "(2) Options/preferences/UI Settings."
  339.     print "    Remove value true in (Show confirmation dialog on exit)"
  340.     print ""
  341.     print "(3) Options/preferences/UI Settings."
  342.     print "    Remove value true in (Confirm exit if critical seeder)"
  343.     print ""
  344.     print "(4) Options/preferences/Advanced/Run Program."
  345.     print "    In box (...when a torrent finishes) put app this way"
  346.     print "    "+ chr$(34) +"C:\..\.\Leecher.exe" + chr$(34) + " " + chr$(34) + "uTorrent 3.3.2" + chr$(34) + " " + chr$(34) + "%D" + chr$(34) + " " + chr$(34) + "%N" + chr$(34)
  347.     print ""
  348.     print ""
  349.     print "-Help, using Leecher in BitTorrent/uTorrent with Webui(Web)"
  350.     print ""
  351.     print "(1) If you want to perform these actions via webui only. "
  352.     print "    go to Options/preferences/Advanced/Run Program. In box"
  353.     print "    (...when a torrent finishes) put app this way"
  354.     print "    "+ chr$(34) +"C:\..\.\Leecher.exe" + chr$(34) + " " + chr$(34) + "uTorrent 3.3.2" + chr$(34) + " " + chr$(34) + "%D" + chr$(34) + " " + chr$(34) + "%N" + chr$(34) + " " + chr$(34) + "%I" + chr$(34)
  355.     print ""
  356.     print "(2) Go to Options/preferences/Advanced/"
  357.     print "    search for webui.token_auth and change the value to true."
  358.     print ""
  359.     print "(3) Finally, open config.conf and enter the required data"
  360.     print ""
  361.     print ""
  362.     print ""
  363.     print "Leecher - an automatic way to stop the seeding in BitTorrent/uTorrent client"
  364.     print "by Rui Branco - rmrbranco@gmail.com"
  365.     print "Project home https://googledrive.com/host/0B5MAgOEuMAVadE1oZnJxUzVrTDA/"
  366.     print ""
  367.     print ""
  368.     print "Press CTRL+C to close window"
  369.  
  370.  
  371.     RETURN
  372.  
  373.  
  374. [extension]
  375.     '// Get file  extension
  376.     extension$ = title$
  377.     bsPos = len(title$)
  378.     while mid$(title$, bsPos, 1) <> "." and bsPos > 0
  379.         bsPos = bsPos - 1
  380.     wend
  381.  
  382.     if bsPos <> 0 then extension$ = right$(title$,len(title$) - bsPos)
  383.  
  384.  
  385.     RETURN
  386.  
  387.  
  388. [webui]
  389.     '// Perform action in Webui
  390.     '// By Brent D. Thorn, 9/2005 and modified for the purpose by Rui Branco - rmrbranco@gmail.com
  391.  
  392.     '// Verify if BitTorrent/uTorrent have webui avaiable
  393.     ip$ = ip$ : gosub [ping]
  394.     if resulticc = 0 then output$ = "The webui server on " ; resulta$ ; " is avaiable?" : gosub [output]
  395.  
  396.     '// Enough bytes to hold a single line of HTML
  397.     CHUNK.SIZE = 512
  398.  
  399.     Open "wininet" For DLL As #inet
  400.  
  401.     '// Register a new user agent. Use proxy settings
  402.     '// set up in Internet Options Control Panel.
  403.     CallDLL #inet, "InternetOpenA", _
  404.         "My User Agent" As Ptr, _
  405.         0 As Long, _ 'INTERNET_OPEN_TYPE_PRECONFIG
  406.         _NULL As Long, _
  407.         _NULL As Long, _
  408.         0 As ULong, _
  409.         hInet As ULong
  410.     If hInet = 0 Then [ErrExit]
  411.  
  412.     '// Open a request to a remote file
  413.     CallDLL #inet, "InternetOpenUrlA", _
  414.         hInet As ULong, _
  415.         address$ As Ptr, _
  416.         _NULL As Long, _
  417.         0 As Long, _
  418.         2147483648 As ULong, _ 'INTERNET_FLAG_RELOAD
  419.         _NULL As Long, _
  420.         hFile As ULong
  421.     If hFile = 0 Then [ErrExit]
  422.  
  423.     '// Start reading in the file by chunks.
  424.     Buffer$ = ""
  425.     chunk$ = Space$(CHUNK.SIZE)+Chr$(0)
  426.     Struct pdw, NumberOfBytesRead As ULong
  427.     Do
  428.     CallDLL #inet, "InternetReadFile", _
  429.         hFile As ULong, _
  430.         chunk$ As Ptr, _
  431.         CHUNK.SIZE As ULong, _
  432.         pdw As Struct, _
  433.         ret As Long
  434.  
  435.     If pdw.NumberOfBytesRead.struct = 0 Then Exit Do
  436.  
  437.     Buffer$ = Buffer$ + Left$(chunk$, pdw.NumberOfBytesRead.struct)
  438.     Loop Until 0
  439.  
  440. [ErrExit]
  441.     '// If you get an error, find GetLastError on MSDN. There you will find a link to a list of error codes.
  442.     CallDLL #kernel32, "GetLastError", ret As ULong
  443.     If ret Then output$ = "Error InternetReadFile ";ret  : gosub [output]
  444.  
  445.     '// Free the handles we created and exit.
  446.     If hFile Then _
  447.         CallDLL #inet, "InternetCloseHandle", _
  448.         hFile As ULong, ret As Long
  449.  
  450.     If hInet Then _
  451.         CallDLL #inet, "InternetCloseHandle", _
  452.         hInet As ULong, ret As Long
  453.  
  454.     '// Strangely, the next line causes LB to hang for around 45 seconds on my computer, a 2.2 GHz running XP on dial-up.
  455.     Close #inet
  456.  
  457.  
  458.     RETURN
  459.  
  460.  
  461. [output]
  462.     '// Create and show output info
  463.     open "output.log" for append as #log
  464.     print #log, output$
  465.     close #log
  466.  
  467.     print output$
  468.  
  469.  
  470.     RETURN
  471.  
  472.  
  473. [sendclose]
  474.     '// Find BitTorrent/utorrent window
  475.     CallDLL #user32, "FindWindowA",_
  476.         _NULL as ulong,_
  477.         resulta$ as ptr,_
  478.         ut as ulong
  479.  
  480.     '// Create output
  481.     if ut = 0 then
  482.         output$ = "Window " ; resulta$ ; " looks closed " ;  ut : gosub [output]
  483.     else
  484.         output$ = "Get Window " ; resulta$ ; " " ; ut : gosub [output]
  485.     end if
  486.  
  487.     '// Send Close command to BitTorrent/utorrent
  488.     Calldll #user32, "SendMessageA", _
  489.         ut as ulong, _
  490.         _WM_CLOSE as long, _
  491.         result as long
  492.  
  493.     '// Create output
  494.     if ut = 0 then
  495.         output$ = "Window " ; resulta$ ; " is closed ";ut : gosub [output]
  496.     else
  497.         output$ = "Send close to Window " ; resulta$ ; " "; ut : gosub [output]
  498.     end if
  499.  
  500.  
  501.     RETURN
  502.  
  503.  
  504. [send.email]
  505.     '// Create sendmail.ini
  506.  
  507.     '// To send email you must have an Internet connection, will check this
  508.     ip$ = "www.google.com:80" : gosub [ping]
  509.     if resulticc = 0 then output$ = "You dont have internet connection!" : gosub [output]
  510.  
  511.     '// Check if sendmail exists
  512.     dim info$(10, 10)
  513.     if fileExists(DefaultDir$, "sendmail.exe") = 0 then
  514.  
  515.         output$ = "Email not send, sendmail.exe not exists!" : gosub [output]
  516.         RETURN
  517.  
  518.     end if
  519.  
  520.     '// Create sendmail.ini
  521.     open "sendmail.ini" for output as #sini
  522.     print #sini, "[sendmail]"
  523.     print #sini, "smtp_server=";smtpserver$
  524.     print #sini, "smtp_port=";smtport$
  525.     print #sini, "smtp_ssl=";smtpssl$
  526.     print #sini, ";default_domain=";defaultdomain$
  527.     print #sini, "error_logfile=";errorlogfile
  528.     print #sini, ";debug_logfile=";debuglogfile$
  529.     print #sini, "auth_username=";authusername$
  530.     print #sini, "auth_password=";authpassword$
  531.     print #sini, "pop3_server=";pop3server$
  532.     print #sini, "pop3_username=";pop3username$
  533.     print #sini, "pop3_password=";pop3password$
  534.     print #sini, "force_sender=";forcesender$
  535.     print #sini, "force_recipient=";forcerecipient$
  536.     print #sini, "hostname=";hostname$
  537.     close #sini
  538.  
  539.     '// Create a temporary file, temp.mail
  540.     open "temp.mail" for output as #tempm
  541.     print #tempm, "From: ";authusername$
  542.     print #tempm, "To: ";to$
  543.     print #tempm, "Subject: ";"Leecher: " ; title$
  544.     print #tempm, "Content-Type: text/html"
  545.     print #tempm, "<p>Dear " ; to$ ; ",</p>"
  546.     print #tempm, "<p>" ; body$ ; title$ ; "</p>"
  547.     print #tempm, "<p> </p>"
  548.     print #tempm, "<p> </p>"
  549.     print #tempm, "<p> </p>"
  550.     print #tempm, "<p>-</p>"
  551.     print #tempm, "<p>Leecher - an automatic way to stop the seeding in BitTorrent/uTorrent client.</p>Leecher project https://googledrive.com/host/0B5MAgOEuMAVadE1oZnJxUzVrTDA/"
  552.     close #tempm
  553.  
  554.     '// Sends the email and checks the process
  555.     SEEMASKNOCLOSEPROCESS = 64 '0x40
  556.  
  557.     Struct s, cbSize as ulong, fMask as ulong, hwnd as ulong,_
  558.         lpVerb$ as ptr, lpFile$ as ptr, lpParameters$ as ptr ,_
  559.         lpDirectory$ as ptr, nShow as long, hInstApp as ulong,_
  560.         lpIDList as long, lpClass as long, hkeyClass as ulong,_
  561.         dwHotKey as ulong, hIcon as ulong, hProcess as ulong
  562.  
  563.     s.cbSize.struct=len(s.struct)
  564.     s.fMask.struct=SEEMASKNOCLOSEPROCESS
  565.     s.hwnd.struct=0
  566.     s.lpVerb$.struct="open"
  567.     s.lpFile$.struct="cmd.exe"
  568.     s.lpParameters$.struct="/c sendmail.exe -t < temp.mail"
  569.     s.lpDirectory$.struct=DefaultDir$
  570.     s.nShow.struct=_SW_HIDE
  571.  
  572.     calldll #shell32 , "ShellExecuteExA",s as struct,r as long
  573.  
  574.     if r<>0 then
  575.  
  576.         hProcess=s.hProcess.struct
  577.  
  578.     else
  579.  
  580.         output$ = "Email notification not sent, run sendmail.exe problem. Please see the logs" : gosub [output]
  581.  
  582.  
  583.         RETURN
  584.  
  585.     end if
  586.  
  587.     waitResult=-1
  588.     while waitResult<>0
  589.         calldll #kernel32, "WaitForSingleObject",_
  590.             hProcess as long,0 as long,_
  591.             waitResult as long
  592.     wend
  593.  
  594.     dim info$(10, 10)
  595.     if fileExists(DefaultDir$, "crash.txt") = 1 or fileExists(DefaultDir$, "0") = 1 then
  596.  
  597.         output$ = "Email notification not send, Login/password problem... Please see the logs" : gosub [output]
  598.  
  599.     else
  600.  
  601.         output$ = "Email notification sent " : gosub [output]
  602.  
  603.         '// Kill old data or data created by sending error email
  604.         if fileExists(DefaultDir$, "temp.mail") then kill "temp.mail"
  605.         if fileExists(DefaultDir$, "sendmail.ini") then kill "sendmail.ini"
  606.         if fileExists(DefaultDir$, "0") then kill "0"
  607.         if fileExists(DefaultDir$, "crash.txt") then kill "crash.txt"
  608.         if fileExists(DefaultDir$, "crash-1.txt") then kill "crash-1.txt"
  609.         if fileExists(DefaultDir$, "crash-2.txt") then kill "crash-2.txt"
  610.         if fileExists(DefaultDir$, "crash-3.txt") then kill "crash-3.txt"
  611.  
  612.     end if
  613.  
  614.  
  615.     RETURN
  616.  
  617.  
  618. [loadconfig]
  619.     '// Check if config exists
  620.     dim info$(10, 10)
  621.     if fileExists(DefaultDir$, "config.conf") then
  622.  
  623.         open "config.conf" for input as #lconf
  624.         LINE INPUT #lconf, null$
  625.         LINE INPUT #lconf, null$
  626.         LINE INPUT #lconf, null$
  627.         LINE INPUT #lconf, yesno$
  628.         LINE INPUT #lconf, null$
  629.         LINE INPUT #lconf, null$
  630.         LINE INPUT #lconf, ip$
  631.         LINE INPUT #lconf, null$
  632.         LINE INPUT #lconf, null$
  633.         LINE INPUT #lconf, tokenyesno$
  634.         LINE INPUT #lconf, null$
  635.         LINE INPUT #lconf, null$
  636.         LINE INPUT #lconf, login$
  637.         LINE INPUT #lconf, null$
  638.         LINE INPUT #lconf, null$
  639.         LINE INPUT #lconf, password$
  640.         LINE INPUT #lconf, null$
  641.         LINE INPUT #lconf, null$
  642.         LINE INPUT #lconf, action$
  643.         LINE INPUT #lconf, null$
  644.         LINE INPUT #lconf, null$
  645.         LINE INPUT #lconf, null$
  646.         LINE INPUT #lconf, null$
  647.         LINE INPUT #lconf, notifyemail$
  648.         LINE INPUT #lconf, null$
  649.         LINE INPUT #lconf, null$
  650.         LINE INPUT #lconf, smtpserver$
  651.         LINE INPUT #lconf, null$
  652.         LINE INPUT #lconf, null$
  653.         LINE INPUT #lconf, smtport$
  654.         LINE INPUT #lconf, null$
  655.         LINE INPUT #lconf, null$
  656.         LINE INPUT #lconf, smtpssl$
  657.         LINE INPUT #lconf, null$
  658.         LINE INPUT #lconf, null$
  659.         LINE INPUT #lconf, authusername$
  660.         LINE INPUT #lconf, null$
  661.         LINE INPUT #lconf, null$
  662.         LINE INPUT #lconf, authpassword$
  663.         LINE INPUT #lconf, null$
  664.         LINE INPUT #lconf, null$
  665.         LINE INPUT #lconf, to$
  666.         LINE INPUT #lconf, null$
  667.         LINE INPUT #lconf, null$
  668.         LINE INPUT #lconf, body$
  669.         close #lconf
  670.  
  671.         '// Decrypt passwords
  672.         if firsttime = 0 and not(password$ = "password") and not(instr(password$, "encrypted")) then
  673.  
  674.             encrypta = 1
  675.  
  676.         end if
  677.  
  678.         if instr(password$, "encrypted") then
  679.  
  680.             encrypted$ = word$(password$,1,"encrypted")
  681.             gosub [decrypt]
  682.             password$ = decrypted$
  683.  
  684.         end if
  685.  
  686.         '// Decrypt passwords
  687.         if firsttime = 0 and not(authpassword$ = "password") and not(instr(authpassword$, "encrypted")) then
  688.  
  689.             encryptb = 1
  690.  
  691.         end if
  692.  
  693.         if instr(authpassword$, "encrypted") then
  694.  
  695.             encrypted$ = word$(authpassword$,1,"encrypted")
  696.             gosub [decrypt]
  697.             authpassword$ = decrypted$
  698.  
  699.         end if
  700.  
  701.     else
  702.  
  703.         '// If not exist config create a default config
  704.         firsttime = 1
  705.  
  706.     end if
  707.  
  708.  
  709.     RETURN
  710.  
  711.  
  712. [createconfig]
  713.     '// Create a default config if first time
  714.     if firsttime = 1 then
  715.  
  716.         password$ = "password"
  717.         authpassword$ = "password"
  718.  
  719.     end if
  720.  
  721.     '// Encrypt passwords
  722.     if encrypta = 1 or encryptb = 1 and firsttime = 0 then
  723.  
  724.         string$ = password$
  725.         gosub [encrypt]
  726.         password$ = encrypted$;"encrypted"
  727.  
  728.         string$ = authpassword$
  729.         gosub [encrypt]
  730.         authpassword$ = encrypted$;"encrypted"
  731.  
  732.         encrypta = 0
  733.         encryptb = 0
  734.  
  735.     end if
  736.  
  737.     open "config.conf" for output as #cconf
  738.     print #cconf, "[Leecher, Webui CONFIG]"
  739.     print #cconf, " "
  740.     print #cconf, "#Use Webui [yes|no]"
  741.     if firsttime = 1 then print #cconf, "no"
  742.     if firsttime = 0 then print #cconf, yesno$
  743.     print #cconf, " "
  744.     print #cconf, "#Webui [ip:port]"
  745.     if firsttime = 1 then print #cconf, "localhost:8080"
  746.     if firsttime = 0 then print #cconf, ip$
  747.     print #cconf, " "
  748.     print #cconf, "#Use Token auth [yes|no]"
  749.     if firsttime = 1 then print #cconf, "no"
  750.     if firsttime = 0 then print #cconf, tokenyesno$
  751.     print #cconf, " "
  752.     print #cconf, "#Webui [login]"
  753.     if firsttime = 1 then print #cconf, "jonh"
  754.     if firsttime = 0 then print #cconf, login$
  755.     print #cconf, " "
  756.     print #cconf, "#Webui [password]. All passwords will be encrypted"
  757.     print #cconf, password$
  758.     print #cconf, " "
  759.     print #cconf, "#Webui actions [stop|start|pause|remove]"
  760.     if firsttime = 1 then print #cconf, "stop"
  761.     if firsttime = 0 then print #cconf, action$
  762.     print #cconf, " "
  763.     print #cconf, "[Leecher, Email Notification CONFIG]"
  764.     print #cconf, " "
  765.     print #cconf, "#Use notification email [yes|no]"
  766.     if firsttime = 1 then print #cconf, "no"
  767.     if firsttime = 0 then print #cconf, notifyemail$
  768.     print #cconf, " "
  769.     print #cconf, "#SMTP server [smtp.gmail.com or smtp.live.com]"
  770.     if firsttime = 1 then print #cconf, "smtp.gmail.com"
  771.     if firsttime = 0 then print #cconf, smtpserver$
  772.     print #cconf, " "
  773.     print #cconf, "#SMTP Port, [25] is ok"
  774.     if firsttime = 1 then print #cconf, "25"
  775.     if firsttime = 0 then print #cconf, smtport$
  776.     print #cconf, " "
  777.     print #cconf, "#SMTP SSL [auto|yes|no], [auto] is ok"
  778.     if firsttime = 1 then print #cconf, "auto"
  779.     if firsttime = 0 then print #cconf, smtpssl$
  780.     print #cconf, " "
  781.     print #cconf, "#Auth username, send email from"
  782.     if firsttime = 1 then print #cconf, "username@gmail.com"
  783.     if firsttime = 0 then print #cconf, authusername$
  784.     print #cconf, " "
  785.     print #cconf, "#Auth password. All passwords will be encrypted"
  786.     print #cconf, authpassword$
  787.     print #cconf, " "
  788.     print #cconf, "#Recipient, send email to"
  789.     if firsttime = 1 then print #cconf, "username@gmail.com"
  790.     if firsttime = 0 then print #cconf, to$
  791.     print #cconf, " "
  792.     print #cconf, "#Body, message to send for recipient"
  793.     if firsttime = 1 then print #cconf, "The downloading the torrent has finished: "
  794.     if firsttime = 0 then print #cconf, body$
  795.     close #cconf
  796.     firsttime = 0
  797.  
  798.  
  799.     RETURN
  800.  
  801.  
  802. [encrypt]
  803.     '// Encrypt
  804.     key=3
  805.     encrypted$=""
  806.     for i = 1 to len(string$)
  807.         encrypted$ = encrypted$ + chr$(asc(mid$(string$, i, 1)) xor key)
  808.     next i
  809.  
  810.  
  811.     RETURN
  812.  
  813.  
  814. [decrypt]
  815.     '// Decrypt
  816.     key=3
  817.     decrypted$=""
  818.     for i = 1 to len(encrypted$)
  819.         decrypted$ = decrypted$ + chr$(asc(mid$(encrypted$, i, 1)) xor key)
  820.     next i
  821.  
  822.  
  823.     RETURN
  824.  
  825.  
  826. [ping]
  827.     '// Get connected state
  828.     lpszURL$ = "http://";ip$
  829.     FLAG.ICC.FORCE.CONNECTION=1
  830.  
  831.     open "wininet.dll" for dll as #win
  832.  
  833.     calldll #win, "InternetCheckConnectionA",_
  834.         lpszURL$ As ptr, _
  835.         FLAG.ICC.FORCE.CONNECTION As Long,_
  836.         dwReserved As Long, _
  837.         resulticc As ulong
  838.  
  839.     close #win
  840.  
  841.  
  842.     RETURN
  843.  
  844.  
  845.     '// Retrieves the contents of the specified variable from the environment block of the calling process.
  846. Function Environ$(varName$)
  847.     retBufr$ = space$(127) : nSize = len(retBufr$)
  848.     CallDll #kernel32, "GetEnvironmentVariableA",_
  849.         varName$ as ptr,_
  850.         retBufr$ as ptr,_
  851.         nSize as long,_
  852.         ret as long
  853.     Environ$ = trim$(retBufr$)
  854. End Function
  855.  
  856.  
  857. '// Function which can be used to test if a file exists on disk.
  858. function fileExists(path$, filename$)
  859.     files path$, filename$, info$()
  860.     fileExists = val(info$(0, 0))
  861. end function
  862.  
  863.  
  864. '// Function which can be used to test if a folder exists on disk.
  865. function folderExists(path$)
  866.     folderExists = fileExists(path$, "nul")
  867. end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement