DoctorD90

PassLog.tcl 1.4.0

May 7th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 4.84 KB | None | 0 0
  1. ### PassLog.tcl 1.4.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. #PURPOSE
  32. #Store data in an encrypted base64 way.
  33.  
  34. #USAGE
  35. #Use commands that you set in SETTINGS section, in query.
  36. #Search: Pattern ?Title? ?Pass?
  37. #Add: Pass Title Text
  38. #Del: Entry Line or Exact Title
  39.  
  40. #SETTINGS
  41. #Set query command to add data.
  42. set passlog(qadd) ".Pass+"
  43. #Set query command to list/search data.
  44. set passlog(qsee) ".Pass"
  45. #Set query command to del data.
  46. set passlog(qdel) ".Pass-"
  47.  
  48.  
  49. ### DON'T EDIT ANYTHING BELOW ###
  50.  
  51. bind pub n $passlog(qsee) pub_passlog
  52. proc pub_passlog {nick uhost hand chan text} {
  53.   set text [split $text]
  54.   set record [lindex $text 0]
  55.   set pass [lindex $text 1]
  56.   if {[file exists "text/PassLog.txt"]} {
  57.     set fs [open "text/PassLog.txt"]
  58.     set lines [split [read -nonewline $fs] "\n"]
  59.     close $fs
  60.   } else {
  61.     set lines ""
  62.   }
  63.   set l [lsearch -nocase -all -index 0 $lines "*$record*"]
  64.   if {[lindex $l 0] == "-1" || ![llength [split $l]]} {
  65.     lappend data "\002*${record}*\002 Not Found In DB"
  66.   } else {
  67.     foreach n [split $l] {
  68.       set title [lindex [split [lindex $lines $n]] 0]
  69.       set info [join [lrange [split [lindex $lines $n]] 1 end]]
  70.       lappend data "\002${n})$title\002: [decrypt $pass $info]"
  71.     }
  72.   }
  73.   foreach line $data {
  74.     putserv "NOTICE $nick :$line"
  75.   }
  76. }
  77.  
  78. bind pub n $passlog(qadd) pub_passlog+
  79. proc pub_passlog+ {nick uhost hand chan text} {
  80.   set text [split $text]
  81.   set pass [lindex $text 0]
  82.   if {![string length $pass]} {
  83.     putserv "NOTICE $nick :\002PassLog:\002 \037Pass\037, Title, Datas Required."
  84.     return
  85.   }
  86.   set title [lindex $text 1]
  87.   if {![string length $title]} {
  88.     putserv "NOTICE $nick :\002PassLog:\002 Pass, \037Title\037, Datas Required."
  89.     return
  90.   }
  91.   set info [join [lrange $text 2 end]]
  92.   if {![string length $info]} {
  93.     putserv "NOTICE $nick :\002PassLog\002 Pass, Title, \037Datas\037 Required."
  94.     return
  95.   }
  96.   set info [encrypt $pass $info]
  97.   if {[file exists "text/PassLog.txt"]} {
  98.     set fs [open "text/PassLog.txt"]
  99.     set lines [split [read -nonewline $fs] "\n"]
  100.     close $fs
  101.     set fs [open "text/PassLog.txt" a]
  102.   } else {
  103.     set lines ""
  104.     set fs [open "text/PassLog.txt" w]
  105.   }
  106.   puts $fs "$title $info"
  107.   close $fs
  108.   set l [lsearch -nocase $lines "*$title*"]
  109.   if {$l != "-1"} {
  110.     putserv "NOTICE $nick :\002PassLog:\002 Warn: an other record with same name yet exists."
  111.   }
  112.   putserv "NOTICE $nick :Pass Stored."
  113. }
  114.  
  115. bind pub n $passlog(qdel) msg_passlog-
  116. proc msg_passlog- {nick uhost hand chan text} {
  117.   set text [split $text]
  118.   if {![llength $text]} {
  119.     putserv "NOTICE $nick :\002PassLog\002 Data's Name or Line's Number Required."
  120.     return
  121.   }
  122.   set info [lindex $text 0]
  123.   if {[file exists "text/PassLog.txt"]} {
  124.     set fs [open "text/PassLog.txt"]
  125.     set lines [split [read -nonewline $fs] "\n"]
  126.     close $fs
  127.   }
  128.   if {![info exists lines] || ![string length [string trim [join $lines]]]} {
  129.     putserv "NOTICE $nick :\002PassLog:\002 No Data Stored."
  130.     return
  131.   }
  132.   if {![string is integer -strict $info]} {
  133.     set l [lsearch -all -index 0 $lines $info]
  134.   } else {
  135.     if {$info >= "0"} {
  136.       set l $info
  137.     } else {
  138.       set l "-1"
  139.     }
  140.     if {$info >= [llength $lines]} {
  141.       set l end
  142.     }
  143.   }
  144.   if {$l == "-1" || ![llength [split $l]]} {
  145.     putserv "NOTICE $nick :\002PassLog:\002 \002$info\002 Not Found In DB"
  146.     return
  147.   }
  148.   set a 0
  149.   foreach d [split $l] {
  150.     set n [expr {$d - $a}]
  151.     set lines [lreplace $lines $n $n]
  152.     incr a
  153.   }
  154.   if {![llength $lines]} {
  155.     file delete -force "text/PassLog.txt"
  156.   } else {
  157.     set fs [open "text/PassLog.txt" w]
  158.     puts $fs [join $lines "\n"]
  159.     close $fs
  160.   }
  161.   if {[string is integer -strict $info]} {
  162.     set info "Line \002$info\002"
  163.   } else {
  164.     set info "\002$info\002"
  165.   }
  166.   putserv "NOTICE $nick :$info Erased."
  167. }
  168.  
  169. ###
  170. putlog "PassLog.tcl LOADED"
Advertisement