DoctorD90

PassLog.tcl 1.3.0

Apr 29th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 4.90 KB | None | 0 0
  1. ### PassLog.tcl 1.3.0 EiNWpxqn
  2.  
  3. #SUGGESTED
  4. # PBinSrc.tcl fMrtKqyq
  5. # TCLLoader.tcl smApj15u
  6.  
  7. #LICENSE
  8. # Copyright © 2013 Alberto Dietze "DoctorD90"
  9. #
  10. #    This program is free software: you can redistribute it and/or modify
  11. #    it under the terms of the GNU General Public License as published by
  12. #    the Free Software Foundation, either version 3 of the License, or
  13. #    (at your option) any later version.
  14. #
  15. #    This program is distributed in the hope that it will be useful,
  16. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. #    GNU General Public License for more details.
  19. #
  20. #    You should have received a copy of the GNU General Public License
  21. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. # Full GPLv3 Text: http://www.gnu.org/licenses/gpl.txt
  24.  
  25. #PATERNITY
  26. #Coder: DoctorD90
  27. #Network: irc.OnlineGamesNet.net
  28. #Chan: #eHito
  29. #Script's List: www.EggTcl.tk
  30. #
  31. #Thanks to guys on #egghelp on irc.freenode.net
  32. #Special thanks to
  33.  
  34. #PURPOSE
  35. #Store data in an encrypted base64 way.
  36.  
  37. #USAGE
  38. #Use commands that you set in SETTINGS section, in query.
  39. #Search: Pattern ?Pass?
  40. #Add: Pass Title Text
  41. #Del: Entry Line or Exact Title
  42.  
  43. #SETTINGS
  44. #Set query command to add data.
  45. set passlog(add) ".Pass+"
  46. #Set query command to list/search data.
  47. set passlog(see) ".Pass"
  48. #Set query command to del data.
  49. set passlog(del) ".Pass-"
  50.  
  51.  
  52. ### DON'T EDIT ANYTHING BELOW ###
  53.  
  54. bind pub n $passlog(see) pub_passlog
  55. proc pub_passlog {nick uhost hand chan text} {
  56.   set text [split $text]
  57.   set record [lindex $text 0]
  58.   set pass [lindex $text 1]
  59.   if {[file exists "text/PassLog.txt"]} {
  60.     set fs [open "text/PassLog.txt"]
  61.     set lines [split [read -nonewline $fs] "\n"]
  62.     close $fs
  63.   } else {
  64.     set lines ""
  65.   }
  66.   set l [lsearch -nocase -all -index 0 $lines "*$record*"]
  67.   if {[lindex $l 0] == "-1" || ![llength [split $l]]} {
  68.     lappend data "\002*${record}*\002 Not Found In DB"
  69.   } else {
  70.     foreach n [split $l] {
  71.       set title [lindex [split [lindex $lines $n]] 0]
  72.       set info [join [lrange [split [lindex $lines $n]] 1 end]]
  73.       lappend data "\002${n})$title\002: [decrypt $pass $info]"
  74.     }
  75.   }
  76.   foreach line $data {
  77.     putserv "NOTICE $nick :$line"
  78.   }
  79. }
  80.  
  81. bind pub n $passlog(add) pub_passlog+
  82. proc pub_passlog+ {nick uhost hand chan text} {
  83.   set text [split $text]
  84.   set pass [lindex $text 0]
  85.   if {![string length $pass]} {
  86.     putserv "NOTICE $nick :\002PassLog:\002 \037Pass\037, Title, Datas Required."
  87.     return
  88.   }
  89.   set title [lindex $text 1]
  90.   if {![string length $title]} {
  91.     putserv "NOTICE $nick :\002PassLog:\002 Pass, \037Title\037, Datas Required."
  92.     return
  93.   }
  94.   set info [join [lrange $text 2 end]]
  95.   if {![string length $info]} {
  96.     putserv "NOTICE $nick :\002PassLog\002 Pass, Title, \037Datas\037 Required."
  97.     return
  98.   }
  99.   set info [encrypt $pass $info]
  100.   if {[file exists "text/PassLog.txt"]} {
  101.     set fs [open "text/PassLog.txt"]
  102.     set lines [split [read -nonewline $fs] "\n"]
  103.     close $fs
  104.     set fs [open "text/PassLog.txt" a]
  105.   } else {
  106.     set lines ""
  107.     set fs [open "text/PassLog.txt" w]
  108.   }
  109.   puts $fs "$title $info"
  110.   close $fs
  111.   set l [lsearch -nocase $lines "*$title*"]
  112.   if {$l != "-1"} {
  113.     putserv "NOTICE $nick :\002PassLog:\002 Warn: an other record with same name yet exists."
  114.   }
  115.   putserv "NOTICE $nick :Pass Stored."
  116. }
  117.  
  118. bind pub n $passlog(del) msg_passlog-
  119. proc msg_passlog- {nick uhost hand chan text} {
  120.   set text [split $text]
  121.   if {![llength $text]} {
  122.     putserv "NOTICE $nick :\002PassLog\002 Data's Name or Line's Number Required."
  123.     return
  124.   }
  125.   set info [lindex $text 0]
  126.   if {[file exists "text/PassLog.txt"]} {
  127.     set fs [open "text/PassLog.txt"]
  128.     set lines [split [read -nonewline $fs] "\n"]
  129.     close $fs
  130.   }
  131.   if {![info exists lines] || ![string length [string trim [join $lines]]]} {
  132.     putserv "NOTICE $nick :\002PassLog:\002 No Data Stored."
  133.     return
  134.   }
  135.   if {![string is integer -strict $info]} {
  136.     set l [lsearch -all -index 0 $lines $info]
  137.   } else {
  138.     if {$info >= "0"} {
  139.       set l $info
  140.     } else {
  141.       set l "-1"
  142.     }
  143.     if {$info >= [llength $lines]} {
  144.       set l end
  145.     }
  146.   }
  147.   if {$l == "-1" || ![llength [split $l]]} {
  148.     putserv "NOTICE $nick :\002PassLog:\002 \002$info\002 Not Found In DB"
  149.     return
  150.   }
  151.   set a 0
  152.   foreach d [split $l] {
  153.     set n [expr {$d - $a}]
  154.     set lines [lreplace $lines $n $n]
  155.     incr a
  156.   }
  157.   if {![llength $lines]} {
  158.     file delete -force "text/PassLog.txt"
  159.   } else {
  160.     set fs [open "text/PassLog.txt" w]
  161.     puts $fs [join $lines "\n"]
  162.     close $fs
  163.   }
  164.   if {[string is integer -strict $info]} {
  165.     set info "Line \002$info\002"
  166.   } else {
  167.     set info "\002$info\002"
  168.   }
  169.   putserv "NOTICE $nick :$info Erased."
  170. }
  171.  
  172. ###
  173. putlog "PassLog.tcl LOADED"
Advertisement