Manejo de errores cambiado.
[reseter.git] / bas / Global.bas
blob5bb53e8df9224c96fd10b350ba17097eb3d0f26f
1 Attribute VB_Name = "Global"
2 Option Explicit
3 ' "Reseter", Copyright 2006-2007 TodoSV.com
4 ' Licencia adicional a: www.svcommunity.org y www.untercio.net
5 ' Mantenedores principales:
6 ' *Vlad
7 ' *Kikeuntercio
8 ' Para soporte, dudas, consultas, inquitudes y demás:
9 ' http://foro.todosv.com/reseter/
10 ' http://www.svcommunity.org/forum/index.php?topic=25095.0
11 ' http://www.svcommunity.org/forum/index.php?topic=59743.0
12 Private TiempoMax As Double
13 'Tipo
14 Enum e_Acceso
15 web
16 telnet
17 auro
18 End Enum
19 Enum e_AccionEX
20 ed_clic
21 ed_java
22 ed_llenar
23 ed_navegar
24 End Enum
25 Type t_Datos
26 Direccion As String 'Dirección a navegar
27 usuario As String 'Usuario del router
28 clave As String 'Clave del usuario del router
29 base As String 'Dirección de la puerta de enlace
30 puerto As Long 'Puerto de acceso
31 nForm As Integer
32 nCont As Integer
33 accionTipo As e_AccionEX
34 accionEX As String
35 accionEX2 As String
36 codigo As String 'Lista de codigos a ejecutarse
37 tipoAcceso As e_Acceso 'Tipo de acceso [Telnet | Web]
38 renovar As Boolean 'Ejecutar renovación de IP
39 asumirDes As Boolean 'Asumir desconexion o probar?
40 End Type
41 Public m_Datos As t_Datos
42 Public flag_Navegar As Boolean
43 Public IE As Object
44 Public TelnetComandos() As String
45 Public nComando As Integer
46 Public NetError As Boolean
47 Private Intentos_Realizados As Byte
48 Public pSocket As AuroNet
49 Public ppSocket As AuroNet
50 Public Tiempo As cTimer 'Uso general
51 Public TiempoEx As cTimer 'Uso secundario
52 Public TiempoEx2 As New cTimer 'Uso terciario
53 Public dXMR As String
54 Public dXMR_ok As Boolean
56 Public Sub Main()
57 'Activar_Temas_XP
58 'Rutas de archivos
59 '------------------------
60 '<EhHeader>
61 On Error GoTo Main_Err
62 '</EhHeader>
63 Set Tiempo = New cTimer
64 Set TiempoEx = New cTimer
65 'Empezamos a medir el tiempo que tarda en iniciar el programa
66 Tiempo.StartTimer
67 '------------------------
68 'Iniciamos los Sockets
69 Set pSocket = New AuroNet
70 Set ppSocket = New AuroNet
71 pSocket.Direccion = PaginaIP
72 ppSocket.Direccion = "www.google.com"
73 '------------------------
74 EthInfo
75 '------------------------
76 'Fichero INI con las opciones del programa
77 rINI_OPCIONES = App.Path & "\Reseter.ini"
78 'Fichero INI con los códigos de reseteo para los routers
79 rINI_ROUTERS = App.Path & "\Routers.ini"
80 '------------------------
81 Quieto = LeerINI("Opciones", "Quieto", False)
82 'Será que es mejor no iniciar el Objeto IE?
83 'Esto es util cuando se ha desinstalado el Explorer o en Wine
84 NoIE = LeerINI("Opciones", "NoIE", False)
85 ModoLinux = LeerINI("Opciones", "Linux:Compatibilidad", False)
86 '------------------------
87 frmPrincipal.Show
89 DoEvents
90 '------------------------
91 Registrar "Iniciando Reseter: " & App.Major & "." & App.Minor & "." & App.Revision & " " & EstadoVer
92 Registrar "Propiedad de todosv.com, svcommunity.org y untercio.net"
93 Registrar "Información: http://foro.todosv.com/reseter/"
94 Registrar "IP pública gracias a " & ObtenerDominio(PaginaIP)
96 '------------------------
97 'Objeto IE
98 If NoIE Then
99 Registrar "+Objeto IE: NoIE establecido."
100 Else
101 Crear_Objeto_IE
102 End If
104 Registrar "+IP Local: " & pSocket.IpLocal
105 Registrar "+IP Gateway: " & EthGateWay
106 Cambio_IP
107 Obtener_Lista_Externa
108 frmPrincipal.ComReset.Text = Predefinido
109 'Comprobando XMR
110 '------------------------
111 dXMR = App.Path & "\XMR.exe"
112 dXMR_ok = (Dir$(dXMR) = vbNullString)
113 Registrar "¿XMR?... " & IIf(dXMR_ok, "¡Si!", "No...")
114 '------------------------
115 'Interfaz
116 '------------------------
117 Registrar "Reestableciendo interfaz"
118 frmPrincipal.chkAvanzado.Value = LeerINI("Interfaz", "MAvanzado", Unchecked)
119 frmPrincipal.chkTerminal.Value = LeerINI("Interfaz", "MTerminal", Unchecked)
120 frmPrincipal.txtNumero.Text = LeerINI("Opciones", "Telefono", vbNullString)
121 'variables
122 Umbral_Desconexion = 30000
124 '------------------------
125 'Verificar si hay router predefinido y proceder
126 '------------------------
127 If HayPredefinido = True Then
128 Registrar "Router predefinido, 10segs. para reseteo o cancelar"
129 frmPrincipal.cmdPredefinir.Caption = "Cancelar"
130 frmPrincipal.cmdReset.Enabled = False
131 frmPrincipal.ComReset.Enabled = False
132 TiempoEx.StartTimer
133 TiempoEx2.StartTimer
135 'Esperamos los 10segs ó que la persona presione cancelar
136 Do Until TiempoEx.Elapsed > 10000 Or NetError = True
137 Esperar 0.1
138 frmPrincipal.lblTW.Caption = Fix((10000 - TiempoEx.Elapsed) / 1000)
140 If TiempoEx2.Elapsed > 1000 Then
141 Beep
142 TiempoEx2.StartTimer
143 End If
145 Loop
147 TiempoEx2.EndTimer
149 'Si no presionó cancelar
150 If Not NetError Then
151 Registrar "{[PRE]:Iniciando reseteo predefinido}"
152 Procesar_Codigo
153 Registrar "{[PRE]:Terminando programa}"
154 GuardarRegistro
155 Terminar
156 Else
157 'Si presionó cancelar
158 Registrar "Se ha cancelado el reseteo automatico"
159 NetError = False
160 End If
161 End If
163 TiempoEx.EndTimer
164 frmPrincipal.cmdReset.Enabled = True
165 frmPrincipal.ComReset.Enabled = True
166 Tiempo.EndTimer
167 '------------------------
168 Registrar "Reseter tardó " & Round(Tiempo.Elapsed / 1000, 2) & "segs. en cargar"
169 '<EhFooter>
170 Exit Sub
171 Main_Err:
172 Controlar_Error Erl, Err.Description, "Reseter.Global.Main"
173 Resume Next
174 '</EhFooter>
175 End Sub
177 Public Sub Reiniciar()
178 '<EhHeader>
179 On Error GoTo Reiniciar_Err
180 '</EhHeader>
181 Dim bIP As IP
182 Dim Detectado As Boolean
183 'Reseteamos las variables.
184 NetError = False
186 'Verificamos si existe el objeto IE y verificamos si debe o no
187 'de existir.
188 If IE Is Nothing And m_Datos.tipoAcceso = web Then
189 If NoIE Then
190 Registrar "!!!No hay objeto IE porque se especificó NoIE=-1"
191 Else
192 Registrar "!!!Por alguna causa el objeto IE no esta!"
193 End If
194 End If
196 'Verificamos el tipo de operación [Web | Telnet | AuroNet]
197 'y la ejecutamos
198 Select Case m_Datos.tipoAcceso
200 Case Is = e_Acceso.web
201 Registrar "+-Será un reseteo via WEB"
202 res_Web
204 Case Is = e_Acceso.telnet
205 Registrar "+-Será un reseteo via Telnet"
206 res_Telnet
208 Case Is = e_Acceso.auro
209 Registrar "+-Será un reseteo via WEB/AuroNet"
210 res_auro
211 End Select
213 'Si ocurrió algún error en el reinicio
214 If NetError = True Then
215 Registrar "!!! Ha ocurrido un error critico y el reseteo no continuará"
216 Exit Sub
217 End If
219 'Esperamos la reconexión
220 If m_Datos.asumirDes Or ModoLinux Then
221 Registrar "+--Esperando " & Fix((Umbral_Desconexion / 1000)) & "Segs. para asumir des/conexión de router"
222 Tiempo.StartTimer
225 Esperar 0.5
226 frmPrincipal.lblTW.Caption = Fix((Umbral_Desconexion - Tiempo.Elapsed) / 1000)
227 Loop Until Tiempo.Elapsed > Umbral_Desconexion Or NetError Or GetNetConnectString = False
229 Tiempo.EndTimer
231 If NetError Then Exit Sub
232 Else
233 Registrar "+--Esperando " & Fix(Umbral_Desconexion / 1000) & " segundos para desconexión de router"
234 Tiempo.StartTimer
237 Esperar 0.5
238 frmPrincipal.lblTW.Caption = Fix((Umbral_Desconexion - Tiempo.Elapsed) / 1000)
239 Loop Until Tiempo.Elapsed > Umbral_Desconexion Or NetError Or GetNetConnectString = False
241 Tiempo.EndTimer
243 If NetError Or Tiempo.Elapsed > Umbral_Desconexion Then
244 Registrar "+---El router nunca se desconectó o ocurrió otro error"
245 Error_Cel
246 NetError = True
247 Exit Sub
248 End If
250 Registrar "+--Esperando " & Fix(Umbral_Desconexion / 1000) & "segundos para reconexión de router"
251 Tiempo.StartTimer
254 Esperar 0.5
255 frmPrincipal.lblTW.Caption = Fix((Umbral_Desconexion - Tiempo.Elapsed) / 1000)
256 Loop Until Tiempo.Elapsed > Umbral_Desconexion Or NetError Or GetNetConnectString = True
258 Tiempo.EndTimer
260 If NetError Or Tiempo.Elapsed > Umbral_Desconexion Then
261 Registrar "+---El router nunca se conectó o ocurrió otro error"
262 Error_Cel
263 NetError = True
264 Exit Sub
265 End If
266 End If
268 'Esperar 5 minutos a que se recupere el internet
269 Registrar "+--Esperando recuperación de internet (máximo " & (Umbral_EsperarInternetMax / 60000) & "minutos)"
270 Tiempo.StartTimer
271 TiempoEx.StartTimer
272 Dim dTemporizador As Long
273 dTemporizador = SetTimer(0, 0, 1000, AddressOf lpActualizar)
274 Detectado = HayInternet
276 If Not Detectado Then
278 Do Until (Tiempo.Elapsed > Umbral_EsperarInternetMax) Or NetError
279 Esperar 0.5
281 'Chequear si ya hay internet
282 If TiempoEx.Elapsed > Umbral_ChequeoInternet Then
283 Detectado = HayInternet
285 If Detectado Then Exit Do
286 End If
288 Loop
290 End If
292 KillTimer 0, dTemporizador
293 Tiempo.EndTimer
294 TiempoEx.EndTimer
296 If Detectado And NetError = False Then
297 'Si hay internet entonces verificamos si la IP cambió
298 '1: Si no cambió entonces reseteamos el router de nuevo
299 '2: siempre y cuando no supere cierto limite de reintentos.
300 bIP = Cambio_IP
302 If bIP.Cambio = True Then
303 Registrar "++La IP no cambió, reintentando reseteo en " & (Umbral_Reintento / 1000) & "Segs."
304 Intentos_Realizados = Intentos_Realizados + 1
306 'Como no cambió reintentamos el reseteo
307 If Intentos_Realizados > Intentos_Maximos Then
308 'Si ya no nos quedan intentos...
309 Registrar "++-Se han hecho " & Intentos_Realizados & " intentos sin exito, deteniendo"
310 Registrar "+Se han cancelado los reintentos aútomaticos"
311 Exit Sub
312 Else
313 'Si aún nos quedan intentos...
314 Tiempo.StartTimer
315 'Esperar 30segs. para reintentar reseteo
316 Registrar "+Esperando " & Fix(Umbral_Reintento / 1000) & " segundos para intento #" & Intentos_Realizados + 1
319 Esperar 0.5
320 frmPrincipal.lblTW.Caption = Fix((Umbral_Desconexion - Tiempo.Elapsed) / 1000)
321 Loop Until Tiempo.Elapsed > Umbral_Reintento Or NetError
323 If Not NetError Then
324 Procesar_Codigo
325 Exit Sub
326 End If
327 End If
329 Else
330 Registrar "+El cambió fue satisfactorio"
332 If dXMR_ok And frmPrincipal.txtNumero.Text <> vbNullString Then
333 Registrar "Enviando mensaje de exito a usuario"
334 XMR_Enviar frmPrincipal.txtNumero.Text, "El reseteo fue exitoso, a las " & Now & " | nueva IP: " & bIP.IP_Actual
335 Else
336 Registrar "No habia numero para notificacion de usuario"
337 End If
339 frmPrincipal.lblTW.Caption = "Exito"
340 End If
342 Else
343 'Si no se detectó para nada el internet
344 Registrar "+El tiempo de espera se agotó y no se detecto conexión."
345 Registrar "++El servidor " & PaginaIP & " puede estar caido."
346 Registrar "+Se han cancelado los reintentos aútomaticos"
347 Error_Cel
348 frmPrincipal.lblTW.Caption = "Error"
349 End If
351 ' Reseteamos algunas variables
352 Umbral_Desconexion = 30000
353 '<EhFooter>
354 Exit Sub
355 Reiniciar_Err:
356 Controlar_Error Erl, Err.Description, "Reseter.Global.Reiniciar"
357 Resume Next
358 '</EhFooter>
359 End Sub
361 Public Function GuardarRegistro() As String
362 '<EhHeader>
363 On Error GoTo GuardarRegistro_Err
364 '</EhHeader>
365 Dim i As Byte
366 Dim Buffer As String
367 Static ocupado As Boolean
369 If ocupado Then Exit Function
370 ocupado = True
371 i = FreeFile
372 Buffer = frmPrincipal.txtSalida.Text
373 Open App.Path & "\" & Day(Now) & "-" & Month(Now) & ".txt" For Append Access Write As #i
374 Print #i, CStr(Now)
375 Print #i, CStr(Buffer)
376 Close #i
377 GuardarRegistro = (App.Path & "\" & Day(Now) & "-" & Month(Now) & ".txt")
378 ocupado = False
379 '<EhFooter>
380 Exit Function
381 GuardarRegistro_Err:
382 Controlar_Error Erl, Err.Description, "Reseter.Global.GuardarRegistro"
383 Resume Next
384 '</EhFooter>
385 End Function
387 'CSEH: Skip
388 Public Sub Controlar_Error(linea As Long, _
389 descripcion As String, _
390 lugar As String)
391 100 Registrar "¦¦¦""" & descripcion & """, erl #" & linea & " - """ & lugar & """"
393 102 If Quieto Then
394 104 GuardarRegistro
395 Else
397 106 If MsgBox("Ocurrió el error """ & descripcion & """, en linea #" & linea & " de """ & lugar & """" & vbNewLine & "Por favor notifica de este error al tema especifico de reseter en svcommunity.org ó todosv.com" & vbNewLine & "Se ha guardado un registro de error en """ & GuardarRegistro & """ por favor envielo a los creadores" & vbNewLine & "¿Desea terminar la aplicación?", vbCritical + vbYesNo) = vbYes Then End
398 End If
400 End Sub
402 Public Sub Predefinir(Valor As Boolean)
403 '<EhHeader>
404 On Error GoTo Predefinir_Err
405 '</EhHeader>
406 EscribirINI "Opciones", "BPredefinido", CStr(CInt(Valor))
407 EscribirINI "Opciones", "Predefinido", frmPrincipal.ComReset.Text
408 '<EhFooter>
409 Exit Sub
410 Predefinir_Err:
411 Controlar_Error Erl, Err.Description, "Reseter.Global.Predefinir"
412 Resume Next
413 '</EhFooter>
414 End Sub
416 Public Function Predefinido() As String
417 '<EhHeader>
418 On Error GoTo Predefinido_Err
419 '</EhHeader>
420 Predefinido = LeerINI("Opciones", "Predefinido", "Escoja su router/modem")
421 '<EhFooter>
422 Exit Function
423 Predefinido_Err:
424 Controlar_Error Erl, Err.Description, "Reseter.Global.Predefinido"
425 Resume Next
426 '</EhFooter>
427 End Function
429 Public Function ObtenerDominio(URL As String) As String
430 '<EhHeader>
431 On Error GoTo ObtenerDominio_Err
432 '</EhHeader>
433 Dim Buffer As Long
434 Buffer = InStr(8, URL, "/")
436 If Buffer > 0 Then ObtenerDominio = Replace$(Mid$(URL, 1, Buffer - 1), "http://", vbNullString) Else ObtenerDominio = URL
437 '<EhFooter>
438 Exit Function
439 ObtenerDominio_Err:
440 Controlar_Error Erl, Err.Description, "Reseter.Global.ObtenerDominio"
441 Resume Next
442 '</EhFooter>
443 End Function
445 Public Function HayPredefinido() As Boolean
446 '<EhHeader>
447 On Error GoTo HayPredefinido_Err
448 '</EhHeader>
449 HayPredefinido = LeerINI("Opciones", "BPredefinido", False)
450 '<EhFooter>
451 Exit Function
452 HayPredefinido_Err:
453 Controlar_Error Erl, Err.Description, "Reseter.Global.HayPredefinido"
454 Resume Next
455 '</EhFooter>
456 End Function
458 Public Sub XMR_Enviar(Numero As String, _
459 Mensaje As String)
460 'Gracias a Olatin por la idea de enviar mensaje con notificaciones!.
461 '<EhHeader>
462 On Error GoTo XMR_Enviar_Err
463 '</EhHeader>
464 ShellExecute frmPrincipal.hWnd, "", dXMR & " /x n=" & Numero & "|m=" & Mensaje & "|f=Reseter 4.0", "", "", 0
465 '<EhFooter>
466 Exit Sub
467 XMR_Enviar_Err:
468 Controlar_Error Erl, Err.Description, "Reseter.Global.XMR_Enviar"
469 Resume Next
470 '</EhFooter>
471 End Sub
473 Public Sub Error_Cel()
474 '<EhHeader>
475 On Error GoTo Error_Cel_Err
477 '</EhHeader>
478 If dXMR_ok And frmPrincipal.txtNumero.Text <> vbNullString Then
479 Registrar "Enviando mensaje de error a usuario"
480 XMR_Enviar frmPrincipal.txtNumero.Text, "El reseteo NO fue exitoso, fallo ocurrido en " & Now
481 End If
483 '<EhFooter>
484 Exit Sub
485 Error_Cel_Err:
486 Controlar_Error Erl, Err.Description, "Reseter.Global.Error_Cel"
487 Resume Next
488 '</EhFooter>
489 End Sub
491 Public Sub Procesar_Codigo()
492 'Primero quebramos el codigo en un array, donde cada elemento contendrá una linea de codigo básico.
493 '<EhHeader>
494 On Error GoTo Procesar_Codigo_Err
495 '</EhHeader>
496 Dim A_Codigo() As String
497 Dim i As Long
498 Dim cTimeEspera As New cTimer
499 A_Codigo = Split(m_Datos.codigo, Chr(254))
501 For i = 0 To UBound(A_Codigo)
503 'Saltar los comentarios
504 If Left(A_Codigo(i), 2) = "//" Then Registrar "PreProcesador: Comentario: '" & Mid$(A_Codigo(i), 3) & "'"
505 'Reemplazar variables
506 A_Codigo(i) = Replace$(A_Codigo(i), "$$GATEWAY$$", EthGateWay)
508 '#########################################################################################
509 ' Ejecutores
510 '#########################################################################################
511 'El codigo dice que tenemos que reiniciar?, bien, "tratemos"
512 If A_Codigo(i) = "objetivo.reiniciar" Then
513 Registrar "PreProcesador: 'objetivo.reiniciar' ejecutando 'Reiniciar'"
514 Reiniciar
515 Registrar "PreProcesador: 'objetivo.reiniciar' ejecutado."
516 End If
518 'El codigo dice que tenemos que ejecutemos el procesador Res_web?
519 If A_Codigo(i) = "web.procesar" Then
520 Registrar "PreProcesador: 'web.procesar' ejecutando 'Res_Web'"
521 res_Web
522 Registrar "PreProcesador: 'web.procesar' ejecutado."
523 End If
525 'El codigo diceque tenemos que esperar X segundos antes de seguir?
526 If InStr(1, A_Codigo(i), "mi.esperar=") Then
527 TiempoMax = CDbl(Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1)) * 1000
528 Registrar "PreProcesador: 'mi.esperar' iniciada [" & TiempoMax & "]"
529 cTimeEspera.StartTimer
532 Esperar 0.5
533 Loop Until cTimeEspera.Elapsed > TiempoMax
535 Registrar "PreProcesador: comando 'mi.esperar' concluido"
536 End If
538 '#########################################################################################
539 '#########################################################################################
540 '#########################################################################################
541 ' Banderas
542 '#########################################################################################
543 'El codigo dice que tenemos que hacer clic en la direccion indicada?
544 If A_Codigo(i) = "web.accion.clic" Then
545 m_Datos.accionTipo = ed_clic
546 Registrar "PreProcesador: 'web.accion.clic' traducido a 'm_Datos.accionTipo=ed_clic'"
547 End If
549 'El codigo dice que solo tenemos que navegar la direccion indicada? (codigo JAVA)
550 If A_Codigo(i) = "web.accion.java" Then
551 m_Datos.accionTipo = ed_java
552 Registrar "PreProcesador: 'web.accion.java' traducido a 'm_Datos.accionTipo=ed_java'"
553 End If
555 'El codigo dice que solo tenemos que navegar la direccion indicada?
556 If A_Codigo(i) = "web.accion.navegar" Then
557 m_Datos.accionTipo = ed_navegar
558 Registrar "PreProcesador: 'web.accion.navegar' traducido a 'm_Datos.accionTipo=ed_navegar'"
559 End If
561 'El codigo dice que tenemos que llenar información en la direccion y posición indicada?
562 If InStr(1, A_Codigo(i), "web.accion.llenar") Then
563 m_Datos.accionTipo = ed_llenar
564 Registrar "PreProcesador: 'web.accion.llenar' traducido a 'm_Datos.accionTipo=ed_llenar'"
565 End If
567 'Debemos asumir que el router se desconectará internamente?.
568 If InStr(1, A_Codigo(i), "objetivo.asumir.desconexion=") Then
569 m_Datos.asumirDes = CBool(Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1))
570 Registrar "PreProcesador: 'objetivo.asumir.desconexion' traducido a 'm_Datos.asumirDes=" & m_Datos.asumirDes & "'"
571 End If
573 'El codigo dice que tenemos que renovar despues de la operación?
574 If InStr(1, A_Codigo(i), "red.renovar=") Then
575 m_Datos.renovar = CBool(Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1))
576 Registrar "PreProcesador: 'red.renovar' traducido a 'm_Datos.renovar=" & m_Datos.renovar & "'"
577 End If
579 'El codigo dice que no tenemos que navegar en reiniciar.res_web y en web.procesar?
580 If InStr(1, A_Codigo(i), "web.navegar=") Then
581 flag_Navegar = CBool(Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1))
582 Registrar "PreProcesador: 'web.navegar' traducido a 'flag_Navegar=" & flag_Navegar & "'"
583 End If
585 'El codigo dice que tenemos que cambiar el limite para asumir desconexion -temporal-?
586 'mi.umbral.desconexion=<TIEMPO EN SEGUNDOS>
587 If InStr(1, A_Codigo(i), "mi.umbral.desconexion=") Then
588 Umbral_Desconexion = Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1) * 1000
589 Registrar "PreProcesador: 'mi.umbral.desconexion' traducido a 'Umbral_Desconexion=" & Umbral_Desconexion & "'"
590 End If
592 '#########################################################################################
593 '#########################################################################################
594 '#########################################################################################
595 ' Ajustes de parametros
596 '#########################################################################################
597 'El codigo dice que tenemos que ajustar las opciones para procesar telnet?
598 'telnet=<COMANDOS SEPARADOS POR ";">
599 If InStr(1, A_Codigo(i), "telnet.comando=") Then
600 m_Datos.tipoAcceso = telnet
601 m_Datos.accionEX = Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1)
602 Registrar "PreProcesador: 'telnet' traducido a 'm_Datos.accionEX=" & m_Datos.accionEX & "'"
603 End If
605 'El codigo dice que tenemos que ajustar las opciones para procesar web?
606 If InStr(1, A_Codigo(i), "web.url=") Then
607 m_Datos.accionEX = Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1)
608 m_Datos.tipoAcceso = web
609 Registrar "PreProcesador: 'web.url' traducido a 'm_Datos.accionEX=" & m_Datos.accionEX & "'"
610 End If
612 'El codigo nos da datos para EX2
613 If InStr(1, A_Codigo(i), "web.datos=") Then
614 m_Datos.accionEX2 = Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1)
615 Registrar "PreProcesador: 'web.datos' traducido a 'm_Datos.accionEX2=" & m_Datos.accionEX2 & "'"
616 End If
618 'El codigo especifica el puerto a usar?
619 If InStr(1, A_Codigo(i), "puerto=") Then
620 m_Datos.puerto = Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1)
621 Registrar "PreProcesador: 'puerto' traducido a 'm_Datos.puerto=" & m_Datos.puerto & "'"
622 End If
624 'El codigo especifica el control a usar?
625 If InStr(1, A_Codigo(i), "web.control=") Then
626 m_Datos.nCont = Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1)
627 Registrar "PreProcesador: 'web.control' traducido a 'm_Datos.nCont=" & m_Datos.nCont & "'"
628 End If
630 'El codigo especifica el formulario a usar?
631 If InStr(1, A_Codigo(i), "web.formulario=") Then
632 m_Datos.nForm = Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1)
633 Registrar "PreProcesador: 'web.formulario' traducido a 'm_Datos.nForm=" & m_Datos.nForm & "'"
634 End If
636 'El codigo especifica el usuario a usar?
637 If InStr(1, A_Codigo(i), "web.usuario=") Then
638 m_Datos.usuario = Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1)
639 Registrar "PreProcesador: 'web.usuario' traducido a 'm_Datos.usuario=" & m_Datos.usuario & "'"
640 End If
642 'El codigo especifica la clave a usar?
643 If InStr(1, A_Codigo(i), "web.clave=") Then
644 m_Datos.clave = Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1)
645 Registrar "PreProcesador: 'clave' traducido a 'm_Datos.clave=" & m_Datos.clave & "'"
646 End If
648 'El codigo especifica la dirección base a usar?
649 If InStr(1, A_Codigo(i), "objetivo.ip=") Then
650 m_Datos.base = Mid$(A_Codigo(i), InStr(1, A_Codigo(i), "=") + 1)
651 Registrar "PreProcesador: 'base' traducido a 'm_Datos.base=" & m_Datos.base & "'"
652 End If
654 '#########################################################################################
655 '#########################################################################################
656 Next
658 '<EhFooter>
659 Exit Sub
660 Procesar_Codigo_Err:
661 Controlar_Error Erl, Err.Description, "Reseter.Global.Procesar_Codigo"
662 Resume Next
663 '</EhFooter>
664 End Sub
666 Public Function HayInternet() As Boolean
667 '<EhHeader>
668 On Error GoTo HayInternet_Err
670 '</EhHeader>
671 If m_Datos.renovar = True Then RenovarLAN
672 Registrar "+---Chequeando conexión a internet... espere"
673 Esperar 0.5
675 If ppSocket.HTML_CONSULTAR Then
676 Registrar "+----Chequeo -> Se detectó internet"
677 HayInternet = True
678 Else
679 Registrar "+----Chequeo -> Aún no hay internet"
680 TiempoEx.StartTimer
681 End If
683 '<EhFooter>
684 Exit Function
685 HayInternet_Err:
686 Controlar_Error Erl, Err.Description, "Reseter.Global.HayInternet"
687 Resume Next
688 '</EhFooter>
689 End Function
691 Public Sub Restablecer_Todo()
692 '<EhHeader>
693 On Error GoTo Restablecer_Todo_Err
694 '</EhHeader>
695 flag_Navegar = True
696 TelnetComandos = Split("")
697 nComando = 0
698 NetError = False
699 Intentos_Realizados = 0
701 With m_Datos
702 .accionEX = ""
703 .accionEX2 = ""
704 .accionTipo = ed_clic
705 .asumirDes = False
706 .base = ""
707 .clave = ""
708 .codigo = ""
709 .Direccion = ""
710 .nCont = -1
711 .nForm = -1
712 .puerto = 0
713 .renovar = True
714 .tipoAcceso = web
715 .usuario = ""
716 End With
718 '<EhFooter>
719 Exit Sub
720 Restablecer_Todo_Err:
721 Controlar_Error Erl, Err.Description, "Reseter.Global.Restablecer_Todo"
722 Resume Next
723 '</EhFooter>
724 End Sub
726 Public Sub Terminar()
727 '<EhHeader>
728 On Error GoTo Terminar_Err
729 '</EhHeader>
730 Destruir_Conexion
731 EscribirINI "Opciones", "Quieto", CStr(CInt(Quieto))
732 EscribirINI "Opciones", "NoIE", CStr(CInt(NoIE))
733 EscribirINI "Opciones", "Telefono", CStr(frmPrincipal.txtNumero.Text)
734 EscribirINI "Opciones", "Linux:Compatibilidad", CStr(CInt(ModoLinux))
735 Set pSocket = Nothing
736 Set ppSocket = Nothing
737 Dim f As Form
739 For Each f In Forms
740 Unload f
741 Next
744 '<EhFooter>
745 Exit Sub
746 Terminar_Err:
747 Controlar_Error Erl, Err.Description, "Reseter.Global.Terminar"
748 Resume Next
749 '</EhFooter>
750 End Sub