kamila 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/classes/Array2D.html +221 -0
- data/doc/classes/Array2D.src/M000001.html +19 -0
- data/doc/classes/Array2D.src/M000002.html +18 -0
- data/doc/classes/Array2D.src/M000003.html +18 -0
- data/doc/classes/Array2D.src/M000004.html +23 -0
- data/doc/classes/CfYiyi.html +172 -0
- data/doc/classes/CfYiyi.src/M000011.html +17 -0
- data/doc/classes/CfYiyi.src/M000012.html +26 -0
- data/doc/classes/EscapeShellCmd.html +157 -0
- data/doc/classes/EscapeShellCmd.src/M000013.html +18 -0
- data/doc/classes/Example.html +184 -0
- data/doc/classes/Example.src/M000005.html +17 -0
- data/doc/classes/Example.src/M000006.html +19 -0
- data/doc/classes/Example.src/M000007.html +19 -0
- data/doc/classes/Example.src/M000008.html +20 -0
- data/doc/classes/Method/Overload.html +123 -0
- data/doc/classes/Method/Signature.html +315 -0
- data/doc/classes/Method/Signature.src/M000015.html +20 -0
- data/doc/classes/Method/Signature.src/M000016.html +18 -0
- data/doc/classes/Method/Signature.src/M000017.html +18 -0
- data/doc/classes/Method/Signature.src/M000018.html +18 -0
- data/doc/classes/Method/Signature.src/M000019.html +22 -0
- data/doc/classes/Method/Signature.src/M000020.html +18 -0
- data/doc/classes/Method/Signature.src/M000021.html +21 -0
- data/doc/classes/Method/Signature.src/M000022.html +26 -0
- data/doc/classes/Method/Signature.src/M000023.html +36 -0
- data/doc/classes/Method/Signature.src/M000024.html +18 -0
- data/doc/classes/Method/Signature.src/M000025.html +24 -0
- data/doc/classes/Method/Signature.src/M000026.html +18 -0
- data/doc/classes/Method.html +144 -0
- data/doc/classes/Method.src/M000014.html +33 -0
- data/doc/classes/Module.html +111 -0
- data/doc/classes/MyCGI.html +137 -0
- data/doc/classes/MyCGI.src/M000034.html +18 -0
- data/doc/classes/ScanearDisco.html +251 -0
- data/doc/classes/ScanearDisco.src/M000027.html +24 -0
- data/doc/classes/ScanearDisco.src/M000028.html +28 -0
- data/doc/classes/ScanearDisco.src/M000029.html +52 -0
- data/doc/classes/ScanearDisco.src/M000030.html +19 -0
- data/doc/classes/ScanearDisco.src/M000031.html +48 -0
- data/doc/classes/ScanearDisco.src/M000032.html +40 -0
- data/doc/classes/TestEscapeShellCmd.html +137 -0
- data/doc/classes/TestEscapeShellCmd.src/M000033.html +19 -0
- data/doc/classes/Utilidades.html +173 -0
- data/doc/classes/Utilidades.src/M000009.html +17 -0
- data/doc/classes/Utilidades.src/M000010.html +28 -0
- data/doc/created.rid +1 -0
- data/doc/files/lib/Array2D_rb.html +120 -0
- data/doc/files/lib/cf_yiyi_rb.html +120 -0
- data/doc/files/lib/escape_shell_cmd_rb.html +121 -0
- data/doc/files/lib/mycgi_rb.html +127 -0
- data/doc/files/lib/overload_rb.html +101 -0
- data/doc/files/lib/scanear_disco_rb.html +140 -0
- data/doc/files/lib/utilidades_rb.html +120 -0
- data/doc/files/test/testEscapeShellCmd_rb.html +116 -0
- data/doc/files/test/testmycgi_rb.html +109 -0
- data/doc/files/test/testoverload_rb.html +101 -0
- data/doc/fr_class_index.html +38 -0
- data/doc/fr_file_index.html +36 -0
- data/doc/fr_method_index.html +60 -0
- data/doc/index.html +24 -0
- data/lib/Array2D.rb +33 -0
- data/lib/application.rb +3509 -0
- data/lib/cerrar.sh +2 -0
- data/lib/cf_yiyi.rb +26 -0
- data/lib/escape_shell_cmd.rb +24 -0
- data/lib/kamila.rb +452 -0
- data/lib/mycgi.rb +41 -0
- data/lib/mypdf.rb +215 -0
- data/lib/overload.rb +197 -0
- data/lib/scanear_disco.rb +169 -0
- data/lib/smtp_tls.rb +66 -0
- data/lib/utilidades.rb +29 -0
- data/test/testEscapeShellCmd.rb +12 -0
- metadata +133 -0
data/lib/mypdf.rb
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
# ******************** kamila version 1.0.1 - Framework *********************
|
2
|
+
#
|
3
|
+
# Copyright (C) 2008 Edgar Gonzalez (egonzale.wordpress.com)
|
4
|
+
#
|
5
|
+
# This framework is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This framework is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this framework; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
#
|
19
|
+
# Este framework es software libre; puedes redistribuirlo y/o modificarlo
|
20
|
+
# bajo los terminos de la licencia publica general GNU tal y como fue publicada
|
21
|
+
# por la Fundacion del Software Libre; desde la version 2.1 o cualquier
|
22
|
+
# versión superior.
|
23
|
+
#
|
24
|
+
# Este framework es distribuido con la esperanza de ser util pero SIN NINGUN
|
25
|
+
# TIPO DE GARANTIA; sin dejar atras su LADO MERCANTIL o PARA FAVORECER ALGUN
|
26
|
+
# FIN EN PARTICULAR. Lee la licencia publica general para mas detalles.
|
27
|
+
#
|
28
|
+
# Debes recibir una copia de la Licencia Publica General GNU junto con este
|
29
|
+
# framework, si no es asi, escribe a Fundacion del Software Libre Inc.,
|
30
|
+
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
31
|
+
# ***************************************************************************
|
32
|
+
=begin
|
33
|
+
super class: FPDF
|
34
|
+
class : Mypdf
|
35
|
+
Source : mypdf.rb
|
36
|
+
Autor : Edgar Gonzalez
|
37
|
+
Email : edgargonzalezmunoz@gmail.com
|
38
|
+
Blog : egonzale.wordpress.com
|
39
|
+
Website : www.myjavaserver.com/~egonzale
|
40
|
+
Framework : kamila versión 1.0.1
|
41
|
+
Fecha : 18 de Julio del 2008
|
42
|
+
|
43
|
+
This is based directly on the fifth tutorial example given on the
|
44
|
+
FPDF website (http://www.fpdf.org).
|
45
|
+
=end
|
46
|
+
require 'rubygems'
|
47
|
+
require 'fpdf'
|
48
|
+
|
49
|
+
class Mypdf < FPDF
|
50
|
+
private
|
51
|
+
@font = nil
|
52
|
+
@fontf = nil
|
53
|
+
@image1 = nil
|
54
|
+
@image2 = nil
|
55
|
+
@xy1 = nil
|
56
|
+
@xy2 = nil
|
57
|
+
@xy3 = nil
|
58
|
+
@xy4 = nil
|
59
|
+
@title1 = nil
|
60
|
+
@title2 = nil
|
61
|
+
@title3 = nil
|
62
|
+
@title4 = nil
|
63
|
+
@lines = nil
|
64
|
+
@y = nil
|
65
|
+
@pagef = nil
|
66
|
+
|
67
|
+
public
|
68
|
+
#Encabezado de Pagina. Metodo agregado por Edgargonzalezmunoz@gmail.com
|
69
|
+
def HeaderPage(font,image1,image2,xy1,title1,xy2,title2,xy3,title3,xy4,title4,lines)
|
70
|
+
@font = font
|
71
|
+
@image1 = image1
|
72
|
+
@image2 = image2
|
73
|
+
@xy1 = xy1
|
74
|
+
@xy2 = xy2
|
75
|
+
@xy3 = xy3
|
76
|
+
@xy4 = xy4
|
77
|
+
@title1 = title1
|
78
|
+
@title2 = title2
|
79
|
+
@title3 = title3
|
80
|
+
@title4 = title4
|
81
|
+
@lines = lines
|
82
|
+
end
|
83
|
+
|
84
|
+
def Header()
|
85
|
+
#Font
|
86
|
+
SetFont(@font[0].to_s,@font[1].to_s,@font[2])
|
87
|
+
# Logos
|
88
|
+
Image(@image1[0].to_s,@image1[1],@image1[2],@image1[3],@image1[4])
|
89
|
+
Image(@image2[0].to_s,@image2[1],@image2[2],@image2[3],@image2[4])
|
90
|
+
# titulos 4 lineas de encabezado
|
91
|
+
SetXY(@xy1[0],@xy1[1])
|
92
|
+
Cell(@title1[0],@title1[1],@title1[2].to_s,@title1[3],@title1[4],@title1[5].to_s)
|
93
|
+
SetXY(@xy2[0],@xy2[1])
|
94
|
+
Cell(@title2[0],@title2[1],@title2[2].to_s,@title2[3],@title2[4],@title2[5].to_s)
|
95
|
+
SetXY(@xy3[0],@xy3[1])
|
96
|
+
Cell(@title3[0],@title3[1],@title3[2].to_s,@title3[3],@title3[4],@title3[5].to_s)
|
97
|
+
SetXY(@xy4[0],@xy4[1])
|
98
|
+
Cell(@title4[0],@title4[1],@title4[2].to_s,@title4[3],@title4[4],@title4[5].to_s)
|
99
|
+
# Salto de lineas
|
100
|
+
Ln(@lines)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Pie de pagina. Metodo agregado por Edgargonzalezmunoz@gmail.com
|
104
|
+
def FooterPage(font,y,page)
|
105
|
+
@fontf = font
|
106
|
+
@y = y
|
107
|
+
@pagef = page
|
108
|
+
end
|
109
|
+
|
110
|
+
def Footer()
|
111
|
+
# font
|
112
|
+
SetFont(@fontf[0].to_s,@fontf[1].to_s,@fontf[2])
|
113
|
+
# Posicion: a -y cms del final
|
114
|
+
SetY(@y)
|
115
|
+
# Numero de pagina
|
116
|
+
nro = PageNo()
|
117
|
+
Cell(@pagef[0],@pagef[1],@pagef[2].to_s+nro.to_s+'/{nb}',@pagef[3],@pagef[4],@pagef[5].to_s)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Load data
|
121
|
+
def LoadData(file)
|
122
|
+
data = Array.new
|
123
|
+
# Read file lines
|
124
|
+
IO.foreach(file) {|line| data.push(line.chop.split(';'))}
|
125
|
+
return data
|
126
|
+
end
|
127
|
+
|
128
|
+
# Simple table
|
129
|
+
def BasicTable(header, data)
|
130
|
+
# Header
|
131
|
+
header.each do |col|
|
132
|
+
Cell(40, 7, col, 1)
|
133
|
+
end
|
134
|
+
Ln()
|
135
|
+
# Data
|
136
|
+
data.each do |row|
|
137
|
+
row.each {|col| Cell(40, 6, col, 1)}
|
138
|
+
Ln()
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Better table
|
143
|
+
def ImprovedTable(header, data, wh, wd)
|
144
|
+
# Column widths
|
145
|
+
j=0
|
146
|
+
0.upto(header.length - 1) do |i|
|
147
|
+
Cell(wh[i,j], wh[i,j+1], header[i], wh[i,j+2], wh[i,j+3], wh[i,j+4].to_s)
|
148
|
+
end
|
149
|
+
Ln()
|
150
|
+
# Data
|
151
|
+
i=0
|
152
|
+
k=0
|
153
|
+
longitud = data.length
|
154
|
+
data.each do |row|
|
155
|
+
row.each do |col|
|
156
|
+
#col.to_s.reverse.gsub(/\d{3}(?=\d)/, '\&,').reverse
|
157
|
+
Cell(wd[i,j], wd[i,j+1], col.to_s, wd[i,j+2].to_s, wd[i,j+3], wd[i,j+4].to_s)
|
158
|
+
i=i+1
|
159
|
+
end
|
160
|
+
if k!=longitud
|
161
|
+
Ln()
|
162
|
+
end
|
163
|
+
k=k+1
|
164
|
+
end
|
165
|
+
# Closure line
|
166
|
+
sum = 0
|
167
|
+
for i in 0..header.length-1
|
168
|
+
sum += wh[i,0]
|
169
|
+
end
|
170
|
+
Cell(sum, 0, '', 'T')
|
171
|
+
end
|
172
|
+
|
173
|
+
# Colored table
|
174
|
+
def FancyTable(header, data, wh, wd, fillcolor, textcolor, drawcolor, linewidth, font, fillcolorRestart, textcolorRestart, fontRestart)
|
175
|
+
# Colors, line width and bold font
|
176
|
+
SetFillColor(fillcolor[0], fillcolor[1], fillcolor[2])
|
177
|
+
SetTextColor(textcolor)
|
178
|
+
SetDrawColor(drawcolor[0], drawcolor[1], drawcolor[2])
|
179
|
+
SetLineWidth(linewidth)
|
180
|
+
SetFont(font[0].to_s,font[1].to_s,font[2])
|
181
|
+
# Column widths
|
182
|
+
j=0
|
183
|
+
0.upto(header.length - 1) do |i|
|
184
|
+
Cell(wh[i,j], wh[i,j+1], header[i], wh[i,j+2], wh[i,j+3], wh[i,j+4].to_s,1)
|
185
|
+
end
|
186
|
+
Ln()
|
187
|
+
# Color and font restoration
|
188
|
+
SetFillColor(fillcolorRestart[0], fillcolorRestart[1], fillcolorRestart[2])
|
189
|
+
SetTextColor(textcolorRestart)
|
190
|
+
SetFont(fontRestart[0].to_s,fontRestart[1].to_s,fontRestart[2])
|
191
|
+
# Data
|
192
|
+
fill = 0
|
193
|
+
# Data
|
194
|
+
i=0
|
195
|
+
k=0
|
196
|
+
longitud = data.length
|
197
|
+
data.each do |row|
|
198
|
+
row.each do |col|
|
199
|
+
Cell(wd[i,j], wd[i,j+1], col.to_s, wd[i,j+2].to_s, wd[i,j+3], wd[i,j+4].to_s,fill)
|
200
|
+
i=i+1
|
201
|
+
end
|
202
|
+
if k!=longitud
|
203
|
+
Ln()
|
204
|
+
end
|
205
|
+
k=k+1
|
206
|
+
fill = (fill == 0 ? 1 : 0)
|
207
|
+
end
|
208
|
+
# Closure line
|
209
|
+
sum = 0
|
210
|
+
for i in 0..header.length-1
|
211
|
+
sum += wh[i,0]
|
212
|
+
end
|
213
|
+
Cell(sum, 0, '', 'T')
|
214
|
+
end
|
215
|
+
end
|
data/lib/overload.rb
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
# ******************** kamila version 1.0.1 - Framework *********************
|
2
|
+
#
|
3
|
+
# Copyright (C) 2008 Edgar Gonzalez (egonzale.wordpress.com)
|
4
|
+
#
|
5
|
+
# This framework is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This framework is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this framework; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
#
|
19
|
+
# Este framework es software libre; puedes redistribuirlo y/o modificarlo
|
20
|
+
# bajo los terminos de la licencia publica general GNU tal y como fue publicada
|
21
|
+
# por la Fundacion del Software Libre; desde la version 2.1 o cualquier
|
22
|
+
# versión superior.
|
23
|
+
#
|
24
|
+
# Este framework es distribuido con la esperanza de ser util pero SIN NINGUN
|
25
|
+
# TIPO DE GARANTIA; sin dejar atras su LADO MERCANTIL o PARA FAVORECER ALGUN
|
26
|
+
# FIN EN PARTICULAR. Lee la licencia publica general para mas detalles.
|
27
|
+
#
|
28
|
+
# Debes recibir una copia de la Licencia Publica General GNU junto con este
|
29
|
+
# framework, si no es asi, escribe a Fundacion del Software Libre Inc.,
|
30
|
+
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
31
|
+
# ***************************************************************************
|
32
|
+
|
33
|
+
class Method
|
34
|
+
module Overload
|
35
|
+
Version = %w$Revision: 0.6 $[1] # -*- package version -*-
|
36
|
+
end
|
37
|
+
|
38
|
+
class Signature < Array
|
39
|
+
defined?(NoMethodError) or NoMethodError = NameError
|
40
|
+
|
41
|
+
def invalid(func = nil)
|
42
|
+
msg = "Invalid signature: "
|
43
|
+
msg << func.to_s if func
|
44
|
+
TypeError.new(msg << to_s)
|
45
|
+
end
|
46
|
+
|
47
|
+
def nomatch(recv, func, level = 1)
|
48
|
+
raise NoMethodError, "no method match to `#{func}#{self}' for #{recv.class}", caller(level)
|
49
|
+
end
|
50
|
+
|
51
|
+
def varargs?
|
52
|
+
!(empty? or last)
|
53
|
+
end
|
54
|
+
|
55
|
+
def arity
|
56
|
+
varargs? ? -length : length
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_str
|
60
|
+
sig = Array[*self]
|
61
|
+
sig.pop if v = varargs?
|
62
|
+
sig = sig.inspect
|
63
|
+
sig[-1, 0] = ', ...' if v
|
64
|
+
sig
|
65
|
+
end
|
66
|
+
|
67
|
+
def inspect
|
68
|
+
self.class.name+self
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_s
|
72
|
+
sig = to_str
|
73
|
+
sig[0] = ?(
|
74
|
+
sig[-1] = ?)
|
75
|
+
sig
|
76
|
+
end
|
77
|
+
|
78
|
+
def ===(args)
|
79
|
+
if varargs?
|
80
|
+
(l = length-1) <= args.length or return false
|
81
|
+
else
|
82
|
+
(l = length) == args.length or return false
|
83
|
+
end
|
84
|
+
l.times {|i| self[i] === args[i] or return false}
|
85
|
+
true
|
86
|
+
rescue StandardError
|
87
|
+
false
|
88
|
+
end
|
89
|
+
|
90
|
+
def >(sig)
|
91
|
+
v1, l1 = varargs?, length
|
92
|
+
v2, l2 = sig.varargs?, sig.length
|
93
|
+
l1 -= 1 if v1
|
94
|
+
l2 -= 1 if v2
|
95
|
+
begin
|
96
|
+
[l1, l2].min.times do |i|
|
97
|
+
return false if sig[i] > self[i]
|
98
|
+
end
|
99
|
+
rescue TypeError
|
100
|
+
return false
|
101
|
+
end
|
102
|
+
if v1
|
103
|
+
return false if l1 > l2
|
104
|
+
elsif v2
|
105
|
+
return false
|
106
|
+
else
|
107
|
+
return false unless l1 == l2
|
108
|
+
end
|
109
|
+
true
|
110
|
+
end
|
111
|
+
|
112
|
+
def <(sig)
|
113
|
+
sig > self
|
114
|
+
end
|
115
|
+
|
116
|
+
def <=>(sig)
|
117
|
+
if self > sig
|
118
|
+
1
|
119
|
+
elsif sig > self
|
120
|
+
-1
|
121
|
+
else
|
122
|
+
0
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def dispatch(*types, &block)
|
127
|
+
throw :dispatched, yield(*self) if self.class[*types] === self
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
module Overload
|
132
|
+
Signature = Signature
|
133
|
+
|
134
|
+
private
|
135
|
+
|
136
|
+
def overload(args)
|
137
|
+
args = Signature[*args]
|
138
|
+
catch(:dispatched) do
|
139
|
+
yield args
|
140
|
+
raise args.invalid
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.dispatch(recv, func, args, block)
|
146
|
+
klass = tbl = sig = meth = nil
|
147
|
+
recv.class.ancestors.find do |klass|
|
148
|
+
tbl = klass.instance_eval {defined?(@overload) and @overload} or next
|
149
|
+
tbl = tbl[func] or next
|
150
|
+
sig, meth = tbl.find {|sig, meth| sig === args}
|
151
|
+
meth
|
152
|
+
end
|
153
|
+
meth or Signature[*args].nomatch(recv, func, 3)
|
154
|
+
begin
|
155
|
+
recv.__send__(meth, *args, &block)
|
156
|
+
rescue Exception
|
157
|
+
n = -caller.size
|
158
|
+
$@[n-2, 3] = nil
|
159
|
+
$@[n].sub!(/\`#{func}\'\z/, "\`#{meth}\'")
|
160
|
+
raise
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
class Module
|
166
|
+
private
|
167
|
+
|
168
|
+
def overload(func, *types)
|
169
|
+
func = func.intern if func.respond_to? :intern
|
170
|
+
sig = Method::Signature[*types]
|
171
|
+
meth = instance_method(func)
|
172
|
+
if meth.arity < 0
|
173
|
+
sig << nil unless sig.varargs?
|
174
|
+
elsif meth.arity > sig.length
|
175
|
+
sig.concat(Array.new(meth.arity - sig.length, Object))
|
176
|
+
elsif meth.arity < sig.length
|
177
|
+
raise ArgumentError, "too many arguments for #{func}(#{sig.length} for #{meth.arity})"
|
178
|
+
end
|
179
|
+
alias_method(meth = "#{func}#{sig}".intern, func)
|
180
|
+
tbl = @overload ||= {}
|
181
|
+
(tbl[func] ||= []) << [sig, meth]
|
182
|
+
module_eval "def #{func}(*a, &b) Method.dispatch(self, :#{func}, a, b) end", __FILE__, __LINE__
|
183
|
+
if $VERBOSE
|
184
|
+
dummy = "!"
|
185
|
+
undef_method(dummy) if method_defined?(dummy)
|
186
|
+
alias_method(dummy, func)
|
187
|
+
undef_method(dummy)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def unoverload(func, *types)
|
192
|
+
func = func.intern if func.respond_to? :intern
|
193
|
+
sig = Method::Signature[*types]
|
194
|
+
remove_method("#{func}#{sig}".intern)
|
195
|
+
tbl = @overload[func] and tbl.delete(sig) if @overload
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
# /****************************************************************************/
|
2
|
+
# /* clase ScanearDisco */
|
3
|
+
# /* */
|
4
|
+
# /* Clase que crea un arbol de un directorio dado, depende de tree-0.2.1.gem */
|
5
|
+
# /* Fuente del gem: http://gems.ruby.inoack.com/ */
|
6
|
+
# /****************************************************************************/
|
7
|
+
# /*
|
8
|
+
# Version: 1.0 en ruby 1.8.x
|
9
|
+
# Fecha : 28 de Marzo 2008
|
10
|
+
# Autor : Prof. Edgar Gonzalez
|
11
|
+
# Email : edgargonzalezmunoz@gmail.com
|
12
|
+
# */
|
13
|
+
require 'cf_yiyi'
|
14
|
+
require "fileutils"
|
15
|
+
require 'tree'
|
16
|
+
require 'open-uri'
|
17
|
+
require 'rexml/document'
|
18
|
+
# Usa el modulo de construccion REXML
|
19
|
+
include REXML
|
20
|
+
|
21
|
+
class ScanearDisco
|
22
|
+
private
|
23
|
+
@control = false
|
24
|
+
@directorio = nil
|
25
|
+
@nivel = nil
|
26
|
+
@raiz = nil
|
27
|
+
|
28
|
+
public
|
29
|
+
attr_reader :directorio,:nivel,:raiz
|
30
|
+
|
31
|
+
#/** Constructor */
|
32
|
+
def initialize()
|
33
|
+
#puts "Scaneando..."
|
34
|
+
cf = CfYiyi.new()
|
35
|
+
if (cf.control())
|
36
|
+
@control = true
|
37
|
+
@directorio = Array.new
|
38
|
+
@nivel = -1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
public
|
43
|
+
def getArchivo(archivo)
|
44
|
+
nombrearchivo = ""
|
45
|
+
r=archivo.to_s.size()
|
46
|
+
while r>=0
|
47
|
+
if archivo.to_s[r,1] != "/"
|
48
|
+
nombrearchivo = archivo.to_s[r,1] + nombrearchivo
|
49
|
+
else
|
50
|
+
r=0
|
51
|
+
end
|
52
|
+
r=r-1
|
53
|
+
end
|
54
|
+
return nombrearchivo
|
55
|
+
end
|
56
|
+
|
57
|
+
public
|
58
|
+
#/* Scanea el disco a partir de un directorio.
|
59
|
+
# * Para el parametro
|
60
|
+
# * nodo siempre debe ser: nil para la primera llamada
|
61
|
+
# * DirActual usar para:
|
62
|
+
# * windows: C:/archivos de programa
|
63
|
+
# * linux : /var/lib
|
64
|
+
# */
|
65
|
+
def scandisco(nodo,dirActual)
|
66
|
+
if nodo == nil
|
67
|
+
nombrearchivo = getArchivo(dirActual)
|
68
|
+
nodo = Tree::TreeNode.new(nombrearchivo, dirActual)
|
69
|
+
@raiz = nodo
|
70
|
+
end
|
71
|
+
existe = false
|
72
|
+
if (@control)
|
73
|
+
if (File.directory?(dirActual))
|
74
|
+
existe = true
|
75
|
+
@nivel = @nivel + 1
|
76
|
+
@directorio[@nivel] = dirActual
|
77
|
+
Dir.chdir(dirActual)
|
78
|
+
archivos = Dir.glob('*')
|
79
|
+
if (archivos.size()-1>=0)
|
80
|
+
j = archivos.size()-1
|
81
|
+
for i in 0..j
|
82
|
+
nombrearchivo = getArchivo(archivos[i].to_s)
|
83
|
+
rama = Tree::TreeNode.new(nombrearchivo, dirActual+'/'+archivos[i].to_s)
|
84
|
+
nodo.add(rama)
|
85
|
+
if (File.directory?(archivos[i].to_s))
|
86
|
+
dirActual = dirActual+'/'+archivos[i].to_s
|
87
|
+
scandisco(rama,dirActual)
|
88
|
+
@nivel = @nivel - 1
|
89
|
+
dirActual = @directorio[@nivel]
|
90
|
+
Dir.chdir(dirActual)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
else
|
96
|
+
existe = false
|
97
|
+
dirActual = new String("")
|
98
|
+
#puts "Directorio no existe"
|
99
|
+
end
|
100
|
+
return existe
|
101
|
+
end
|
102
|
+
|
103
|
+
def imprimirArbol()
|
104
|
+
#@raiz.each { |node| node.content.reverse; puts node }
|
105
|
+
@raiz.printTree(3)
|
106
|
+
end
|
107
|
+
|
108
|
+
def adicionarElementos(elementoArray,rama)
|
109
|
+
elementorow = nil
|
110
|
+
if rama.isRoot?
|
111
|
+
elementorow = Element.new("rows")
|
112
|
+
elementoArray.pop()
|
113
|
+
elementoArray.push(elementorow)
|
114
|
+
elementorow = Element.new("row")
|
115
|
+
elementorow.attributes["id"] = rama.content
|
116
|
+
elementocell = Element.new("cell")
|
117
|
+
elementocell.attributes["image"] = "folder.gif"
|
118
|
+
elementocell.text = rama.name
|
119
|
+
elementorow.add elementocell
|
120
|
+
elementoArray.push(elementorow)
|
121
|
+
else
|
122
|
+
elementorow = Element.new("row")
|
123
|
+
elementorow.attributes["id"] = rama.content
|
124
|
+
elementocell = Element.new("cell")
|
125
|
+
elementocell.attributes["image"] = "folder.gif"
|
126
|
+
elementocell.text = rama.name
|
127
|
+
elementorow.add elementocell
|
128
|
+
elementoArray.push(elementorow)
|
129
|
+
end
|
130
|
+
if rama.hasChildren?
|
131
|
+
hijos = rama.children
|
132
|
+
for i in 0..hijos.length()-1
|
133
|
+
adicionarElementos(elementoArray,hijos[i])
|
134
|
+
end
|
135
|
+
end
|
136
|
+
elemento2 = elementoArray.pop()
|
137
|
+
elemento1 = elementoArray.pop()
|
138
|
+
elemento1.add elemento2
|
139
|
+
elementoArray.push(elemento1)
|
140
|
+
end
|
141
|
+
|
142
|
+
def generarXML(archivo)
|
143
|
+
raiz = @raiz
|
144
|
+
file = Kernel.open(archivo.to_s,"w+")
|
145
|
+
linea = '<?xml version="1.0" encoding="UTF-8"?>' + "\n"
|
146
|
+
linea = linea + '<!DOCTYPE rows SYSTEM "dhtmlxtreegrid.dtd">' + "\n"
|
147
|
+
doc = Document.new(linea)
|
148
|
+
#doc << XMLDecl.new()
|
149
|
+
docArray = Array.new
|
150
|
+
docArray.push(doc)
|
151
|
+
elemento = nil
|
152
|
+
elementoArray = Array.new
|
153
|
+
elementoArray.push(elemento)
|
154
|
+
adicionarElementos(elementoArray,raiz)
|
155
|
+
j=0
|
156
|
+
while j<elementoArray.length()-1
|
157
|
+
elemento2 = elementoArray.pop()
|
158
|
+
elemento1 = elementoArray.pop()
|
159
|
+
elemento1.add elemento2
|
160
|
+
elementoArray.push(elemento1)
|
161
|
+
end
|
162
|
+
elemento = elementoArray.pop()
|
163
|
+
doc.add_element elemento
|
164
|
+
doc.write(file,0)
|
165
|
+
file.close()
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
data/lib/smtp_tls.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require "openssl"
|
2
|
+
require "net/smtp"
|
3
|
+
|
4
|
+
Net::SMTP.class_eval do
|
5
|
+
private
|
6
|
+
def do_start(helodomain, user, secret, authtype)
|
7
|
+
raise IOError, 'SMTP session already started' if @started
|
8
|
+
check_auth_args user, secret, authtype if user or secret
|
9
|
+
|
10
|
+
sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
|
11
|
+
@socket = Net::InternetMessageIO.new(sock)
|
12
|
+
@socket.read_timeout = 60 #@read_timeout
|
13
|
+
|
14
|
+
check_response(critical { recv_response() })
|
15
|
+
do_helo(helodomain)
|
16
|
+
|
17
|
+
if starttls
|
18
|
+
raise 'openssl library not installed' unless defined?(OpenSSL)
|
19
|
+
ssl = OpenSSL::SSL::SSLSocket.new(sock)
|
20
|
+
ssl.sync_close = true
|
21
|
+
ssl.connect
|
22
|
+
@socket = Net::InternetMessageIO.new(ssl)
|
23
|
+
@socket.read_timeout = 60 #@read_timeout
|
24
|
+
do_helo(helodomain)
|
25
|
+
end
|
26
|
+
|
27
|
+
authenticate user, secret, authtype if user
|
28
|
+
@started = true
|
29
|
+
ensure
|
30
|
+
unless @started
|
31
|
+
# authentication failed, cancel connection.
|
32
|
+
@socket.close if not @started and @socket and not @socket.closed?
|
33
|
+
@socket = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def do_helo(helodomain)
|
38
|
+
begin
|
39
|
+
if @esmtp
|
40
|
+
ehlo helodomain
|
41
|
+
else
|
42
|
+
helo helodomain
|
43
|
+
end
|
44
|
+
rescue Net::ProtocolError
|
45
|
+
if @esmtp
|
46
|
+
@esmtp = false
|
47
|
+
@error_occured = false
|
48
|
+
retry
|
49
|
+
end
|
50
|
+
raise
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def starttls
|
55
|
+
getok('STARTTLS') rescue return false
|
56
|
+
return true
|
57
|
+
end
|
58
|
+
|
59
|
+
def quit
|
60
|
+
begin
|
61
|
+
getok('QUIT')
|
62
|
+
rescue EOFError
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
data/lib/utilidades.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# /****************************************************************************/
|
2
|
+
# /* clase Utilidades */
|
3
|
+
# /* */
|
4
|
+
# /* Clase con funcionalidades generales */
|
5
|
+
# /****************************************************************************/
|
6
|
+
# /*
|
7
|
+
# Version: 1.0 en ruby 1.8.x
|
8
|
+
# Fecha : 18 de Abril 2008
|
9
|
+
# Autor : Prof. Edgar Gonzalez
|
10
|
+
# Email : edgargonzalezmunoz@gmail.com
|
11
|
+
# */
|
12
|
+
|
13
|
+
class Utilidades
|
14
|
+
def initialize()
|
15
|
+
end
|
16
|
+
def getNombreArchivo(archivo)
|
17
|
+
nombrearchivo = ""
|
18
|
+
r=archivo.to_s.size()
|
19
|
+
while r>=0
|
20
|
+
if archivo.to_s[r,1] != "/"
|
21
|
+
nombrearchivo = archivo.to_s[r,1] + nombrearchivo
|
22
|
+
else
|
23
|
+
r=0
|
24
|
+
end
|
25
|
+
r=r-1
|
26
|
+
end
|
27
|
+
return nombrearchivo
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!ruby
|
2
|
+
# fuente: http://d.hatena.ne.jp/babie/20051201/p1
|
3
|
+
require 'test/unit'
|
4
|
+
require 'escape_shell_cmd'
|
5
|
+
|
6
|
+
class TestEscapeShellCmd < Test::Unit::TestCase
|
7
|
+
def test_escape_semicolon
|
8
|
+
cmd = 'date;date'
|
9
|
+
assert_equal('date\;date', escape_shell_cmd(cmd), ';(semi-colon) must be escaped')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|