mirror of
https://github.com/KeymonSoft/Monitor-Keymon.git
synced 2026-04-17 21:06:19 +00:00
- Se agregó que guarde en base de datos el estatus de "Activo", asi si se desactiva el servicio, cuando se reinicia, o el sistema lo mata y luego reinicia, mantiene el estatus seleccionado.
416 lines
16 KiB
QBasic
416 lines
16 KiB
QBasic
B4A=true
|
|
Group=Default Group
|
|
ModulesStructureVersion=1
|
|
Type=Class
|
|
Version=9.85
|
|
@EndOfDesignText@
|
|
#Region Shared Files
|
|
'#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
|
|
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
|
|
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
|
|
'###########################################################################################################
|
|
'###################### PULL #############################################################
|
|
'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=git&Args=pull
|
|
'###########################################################################################################
|
|
'###################### PUSH #############################################################
|
|
'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=github&Args=..\..\
|
|
'###########################################################################################################
|
|
'###################### PUSH TORTOISE GIT #########################################################
|
|
'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=TortoiseGitProc&Args=/command:commit&Args=/path:"./../../"&Args=/closeonend:2
|
|
'###########################################################################################################
|
|
#End Region
|
|
|
|
'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=github&Args=..\..\
|
|
|
|
Sub Class_Globals
|
|
Private Root As B4XView
|
|
Private xui As XUI
|
|
Dim ph As Phone
|
|
Public login As B4XMainPage
|
|
Dim s As C_Subs
|
|
Private b_monitorActivo As Button
|
|
' Private p_bMonitor As Panel
|
|
Private l_version As Label
|
|
Dim l_status As Label
|
|
Private p_estatus As Panel
|
|
Dim cb_conexion As CheckBox
|
|
Dim cb_internet As CheckBox
|
|
' Dim cb_dbreqserver As CheckBox
|
|
' Dim cb_db As CheckBox
|
|
' Private b_intervalo As Button
|
|
' Private b_server As Button
|
|
Private et_server As EditText
|
|
Private lv_server As ListView
|
|
Private i_engrane As ImageView
|
|
Private p_engrane As Panel
|
|
Dim b_ping As Button
|
|
Private cd1 As ColorDrawable
|
|
Dim l_ultimoPing As Label
|
|
Private p_intervalo As Panel
|
|
Private et_intervalo As EditText
|
|
Private p_timeout As Panel
|
|
Private et_timeout As EditText
|
|
Private l_timeout As Label
|
|
' Private b_timeout As Button
|
|
Private Label1 As Label
|
|
Private b_notifAccess As Button
|
|
Dim logger As Boolean = False
|
|
Private clv_server As CustomListView
|
|
Private p_listItemServer As Panel
|
|
Private l_server As Label
|
|
Private l_info As Label
|
|
Private b_guardaCambios As Button
|
|
Dim servidores As List
|
|
Dim lv_servidores As ListView
|
|
Dim lbl, lbl2, lbl3 As B4XView
|
|
Private p_dbreqServidores As Panel
|
|
Private l_db As Label
|
|
Private l_dbreqServer As Label
|
|
Dim lv_dbs As ListView
|
|
Private p_dbs As Panel
|
|
Private p_servidoresActivos As Panel
|
|
Private lv_servidoresActivos As ListView
|
|
' Dim jsn As JSONParser
|
|
' Dim jsnGnr As JSONGenerator
|
|
Dim rp As RuntimePermissions
|
|
End Sub
|
|
|
|
Public Sub Initialize
|
|
' B4XPages.GetManager.LogEvents = True
|
|
End Sub
|
|
|
|
'This event will be called once, before the page becomes visible.
|
|
Private Sub B4XPage_Created (Root1 As B4XView)
|
|
Root = Root1
|
|
' Log(567)
|
|
Root.LoadLayout("login")
|
|
B4XPages.SetTitle(Me, "Monitor Keymon")
|
|
B4XPages.AddPage("Login", login)
|
|
s.Initialize
|
|
l_version.Text = Application.VersionName
|
|
' lv_server.AddSingleLine("http://keymon.lat:1782")
|
|
' lv_server.AddSingleLine("http://10.0.0.205:1782")
|
|
' lv_server.AddSingleLine("http://40.123.36.38:1782")
|
|
|
|
clv_server.Add(CreateListItem("http://keymon.lat:1782", clv_server.AsView.Width, 35dip), "http://keymon.lat:1782")
|
|
clv_server.Add(CreateListItem("http://10.0.0.205:1782", clv_server.AsView.Width, 35dip), "http://10.0.0.205:1782")
|
|
clv_server.Add(CreateListItem("http://40.123.36.38:1782", clv_server.AsView.Width, 35dip), "http://40.123.36.38:1782")
|
|
et_server.Text = Starter.DBReqServer
|
|
#if not(DEBUG)
|
|
logger = False
|
|
#end if
|
|
s.centraEtiqueta(l_info, Root.Width)
|
|
servidores.Initialize
|
|
' Private srv1 As Map = CreateMap("nombre": "1781", "servidor": "http://keymon.lat:1781", "intervalo": 30, "timeout": 11000)
|
|
' Private srv2 As Map = CreateMap("nombre": "1782", "servidor": "http://keymon.lat:1782", "intervalo": 30, "timeout": 11000)
|
|
' Private srv3 As Map = CreateMap("nombre": "1783", "servidor": "http://keymon.lat:1783", "intervalo": 30, "timeout": 11000)
|
|
' servidores.AddAll(Array As Object (srv1, srv2, srv3))
|
|
' Private srvrsMap As Map
|
|
' srvrsMap.Initialize
|
|
' srvrsMap.Put("1781", srv1)
|
|
' srvrsMap.Put("1782", srv2)
|
|
' srvrsMap.Put("1783", srv3)
|
|
' Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'servidores'"$)
|
|
' jsnGnr.Initialize2(servidores)
|
|
' Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("servidores", '${jsnGnr.ToString}')"$)
|
|
|
|
|
|
' Starter.skmt.ExecNonQuery("insert into cat_servidores (nombre, url, intervalo, timeout) values ('1781', 'http://keymon.lat:1781', '30', '11000')")
|
|
' Starter.skmt.ExecNonQuery("insert into cat_servidores (nombre, url, intervalo, timeout) values ('1782', 'http://keymon.lat:1782', '30', '11000')")
|
|
' Starter.skmt.ExecNonQuery("insert into cat_servidores (nombre, url, intervalo, timeout) values ('1783', 'http://keymon.lat:1783', '30', '11000')")
|
|
lv_servidores.SingleLineLayout.ItemHeight = 22dip
|
|
lbl = lv_servidores.SingleLineLayout.Label
|
|
lbl.TextColor = Colors.black
|
|
lbl.SetTextAlignment("CENTER", "CENTER")
|
|
lbl.TextSize = 14
|
|
lv_dbs.SingleLineLayout.ItemHeight = 22dip
|
|
lbl2 = lv_dbs.SingleLineLayout.Label
|
|
lbl2.TextColor = Colors.black
|
|
lbl2.SetTextAlignment("CENTER", "CENTER")
|
|
lbl2.TextSize = 14
|
|
lv_servidoresActivos.SingleLineLayout.ItemHeight = 30dip
|
|
lbl3 = lv_servidoresActivos.SingleLineLayout.Label
|
|
lbl3.TextColor = Colors.black
|
|
lbl3.SetTextAlignment("CENTER", "CENTER")
|
|
lbl3.TextSize = 16
|
|
p_dbreqServidores.Left = (p_estatus.Width / 2) - (lv_servidores.Width / 2)
|
|
lv_servidores.Top = 10
|
|
lv_servidores.Left = 0
|
|
s.centraEtiqueta(l_dbreqServer, p_estatus.Width)
|
|
s.centraEtiqueta(l_db, p_estatus.Width)
|
|
s.borraArribaDeXXXErrores(3000)
|
|
rp.CheckAndRequest(rp.PERMISSION_POST_NOTIFICATIONS)
|
|
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean) 'change to Activity_PermissionResult if non-B4XPages.
|
|
|
|
' Log(999)
|
|
' rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
|
|
' Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean) 'change to Activity_PermissionResult if non-B4XPages.
|
|
' Log(888)
|
|
S.CheckAndRequestNotificationPermission
|
|
End Sub
|
|
|
|
Sub B4XPage_Appear
|
|
' reqManager.Initialize(Me, Starter.DBReqServer)
|
|
cd1.Initialize(Colors.RGB(16, 141, 0), 10dip)
|
|
b_ping.Background = cd1
|
|
b_monitorActivo.Left = (Root.Width / 2) - (b_monitorActivo.Width / 2)
|
|
b_ping.Left = (Root.Width / 2) - (b_ping.Width / 2)
|
|
s.centraPanel(p_estatus, Root.Width)
|
|
s.centraEtiqueta(l_status, Root.Width)
|
|
s.centraEtiqueta(l_ultimoPing, Root.Width)
|
|
' s.centraPanel(p_intervalo, Root.Width)
|
|
s.centraEtiqueta(Label1, Root.Width)
|
|
If Not(CheckNotificationAccess) Then
|
|
Msgbox2Async($"Se necesita acceso a las notificaciones, haga clic en "Aceptar" y en la siguiente pantalla permita el acceso a la aplicación "${Application.LabelName}"."$, "Permisos necesarios", "Aceptar", "Cancelar", "", Null, True)
|
|
Wait For Msgbox_Result (resultado As Int)
|
|
If resultado = DialogResponse.POSITIVE Then
|
|
b_notifAccess_Click
|
|
End If
|
|
Private cd1 As ColorDrawable
|
|
cd1.Initialize(Colors.red, 10dip)
|
|
b_notifAccess.Background = cd1
|
|
b_notifAccess.TextColor = Colors.White
|
|
b_notifAccess.Text = "Activar Permisos"
|
|
Else
|
|
Private cd1 As ColorDrawable
|
|
cd1.Initialize(Colors.RGB(109, 221, 101), 10dip)
|
|
b_notifAccess.Background = cd1
|
|
b_notifAccess.TextColor = Colors.White
|
|
b_notifAccess.Text = "Permisos Activos"
|
|
End If
|
|
CallSubDelayed(Monitor, "Timer1_Tick")
|
|
If Not(s.traeActivo) Then
|
|
cd1.Initialize(Colors.red, 10dip)
|
|
b_monitorActivo.Background = cd1
|
|
b_monitorActivo.Text = "Monitor Apagado"
|
|
l_status.Text = "Monitor Apagado"
|
|
b_ping.Text = "En pausa"
|
|
Monitor.Timer1.Enabled = False
|
|
Else
|
|
cd1.Initialize(Colors.RGB(16, 141, 0), 10dip)
|
|
b_monitorActivo.Background = cd1
|
|
b_monitorActivo.Text = "Monitor Activo"
|
|
l_status.Text = "Monitor Activo"
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub B4XPage_CloseRequest As ResumableSub
|
|
If Starter.logger Then Log("closreq")
|
|
Sleep(0)
|
|
If p_engrane.Visible Then
|
|
p_engrane.Visible = False
|
|
Return False
|
|
Else
|
|
Return True
|
|
End If
|
|
End Sub
|
|
|
|
'Revisa si la aplicación tiene permiso para acceder a las notificaciones.
|
|
Sub CheckNotificationAccess As Boolean
|
|
Dim nstr, pstr As String
|
|
Dim r As Reflector
|
|
pstr = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
|
|
nstr = ph.GetSettings("enabled_notification_listeners")
|
|
Return nstr.Contains(pstr)
|
|
End Sub
|
|
|
|
Private Sub tb_monitorActivo_CheckedChange(Checked As Boolean)
|
|
|
|
End Sub
|
|
|
|
Private Sub b_monitorActivo_Click
|
|
If logger Then Log(Starter.DBReqServer)
|
|
Log("YYY: " & Starter.monitorActivo)
|
|
If s.traeActivo Then
|
|
cd1.Initialize(Colors.red, 10dip)
|
|
b_monitorActivo.Background = cd1
|
|
b_monitorActivo.Text = "Monitor Apagado"
|
|
l_status.Text = "Monitor Apagado"
|
|
' Starter.monitorActivo = False
|
|
s.notiHigh("Con internet ✅", $"Monitor APAGADO ❌"$, Monitor.nid, Main)
|
|
Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where nombre = ?", Array As Object ("monitorActivo"))
|
|
Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(nombre, valor) VALUES (?,?)", Array As Object ("monitorActivo","0"))
|
|
Monitor.Timer1.Enabled = False
|
|
b_ping.Text = "En pausa"
|
|
Else
|
|
cd1.Initialize(Colors.RGB(16, 141, 0), 10dip)
|
|
b_monitorActivo.Background = cd1
|
|
b_monitorActivo.Text = "Monitor Activo"
|
|
l_status.Text = "Monitor Activo"
|
|
CallSubDelayed(Monitor, "Timer1_Tick")
|
|
' Starter.monitorActivo = True
|
|
Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where nombre = ?", Array As Object ("monitorActivo"))
|
|
Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(nombre, valor) VALUES (?,?)", Array As Object ("monitorActivo","1"))
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub lv_server_ItemClick (Position As Int, Value As Object)
|
|
If logger Then Log(Value)
|
|
et_server.Text = Value
|
|
Starter.DBReqServer = Value
|
|
Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'servidor'"$)
|
|
Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("servidor", '${Value}')"$)
|
|
CallSubDelayed(Monitor, "reinicializaReqManager")
|
|
ToastMessageShow($"Servidor modificado"$, False)
|
|
End Sub
|
|
|
|
Private Sub clv_server_ItemClick (Index As Int, Value As Object)
|
|
If logger Then Log(Value)
|
|
et_server.Text = Value
|
|
Starter.DBReqServer = Value
|
|
Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'servidor'"$)
|
|
Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("servidor", '${Value}')"$)
|
|
CallSubDelayed(Monitor, "reinicializaReqManager")
|
|
ToastMessageShow($"Servidor modificado"$, False)
|
|
End Sub
|
|
|
|
Private Sub b_server_Click
|
|
' Starter.DBReqServer = et_server.text
|
|
' Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'servidor'"$)
|
|
' Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("servidor", '${et_server.text}')"$)
|
|
' CallSubDelayed(Monitor, "reinicializaReqManager")
|
|
' ToastMessageShow($"Servidor modificado"$, False)
|
|
' p_engrane.Visible = False
|
|
' CallSubDelayed(Monitor, "Timer1_Tick")
|
|
End Sub
|
|
|
|
Private Sub b_intervalo_Click
|
|
' Monitor.Interval = et_intervalo.text
|
|
' Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'intervalo'"$)
|
|
' Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("intervalo", '${et_intervalo.text}')"$)
|
|
' ToastMessageShow($"Intervalo modificado"$, False)
|
|
' CallSubDelayed(Monitor, "Timer1_Tick")
|
|
' p_engrane.Visible = False
|
|
End Sub
|
|
|
|
Private Sub i_engrane_Click
|
|
et_intervalo.Text = s.traeIntervaloDeBD
|
|
et_timeout.Text = s.traeTimeoutDeBD
|
|
p_engrane.Width = Root.Width
|
|
p_engrane.Height = Root.Height
|
|
Private sa As Cursor = Starter.skmt.ExecQuery("select * from cat_servidores")
|
|
If sa.RowCount > 0 Then
|
|
lv_servidoresActivos.Clear
|
|
For i = 0 To sa.RowCount - 1
|
|
sa.Position = i
|
|
lv_servidoresActivos.AddSingleLine(sa.GetString("url"))
|
|
Next
|
|
End If
|
|
|
|
s.panelVisible(p_engrane, 0, 0)
|
|
End Sub
|
|
|
|
Private Sub p_engrane_Click
|
|
|
|
End Sub
|
|
|
|
Private Sub b_ping_Click
|
|
cd1.Initialize(Colors.RGB(5, 104, 0), 10dip)
|
|
b_ping.Background = cd1
|
|
b_ping.Text = "Buscando ..."
|
|
CallSubDelayed(Monitor, "Timer1_Tick")
|
|
' CallSubDelayed(Monitor, "probamosConexion")
|
|
' Wait For (ph.ShellAsync("ping", Array As String("-c 1","-W 2", "8.8.8.8"))) Complete (Success As Boolean, ExitValue As Int, StdOut As String, StdErr As String)
|
|
' If Success Then
|
|
' Log("ExitValue:" & ExitValue)
|
|
' Log("StdError:" & StdErr)
|
|
' LogColor("StdOut: " & StdOut, Colors.Magenta)
|
|
' Else
|
|
' Log("Error: " & LastException)
|
|
' End If
|
|
End Sub
|
|
|
|
Private Sub b_timeout_Click
|
|
' Monitor.timeout = et_timeout.text
|
|
' Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'timeout'"$)
|
|
' Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("timeout", '${et_timeout.text}')"$)
|
|
' ToastMessageShow($"Intervalo modificado"$, False)
|
|
' CallSubDelayed(Monitor, "Timer1_Tick")
|
|
' p_engrane.Visible = False
|
|
End Sub
|
|
|
|
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
|
Sub b_notifAccess_Click
|
|
Dim In As Intent
|
|
In.Initialize("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS", "")
|
|
StartActivity(In)
|
|
End Sub
|
|
|
|
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel 'ignore
|
|
Dim p As B4XView = xui.CreatePanel("")
|
|
p.SetLayoutAnimated(0, 0, 0, Width, Height)
|
|
p.LoadLayout("listItem")
|
|
l_server.Height = Height
|
|
l_server.Text = Text
|
|
' i_prod.Bitmap = img
|
|
Return p
|
|
End Sub
|
|
|
|
Private Sub l_info_Click
|
|
l_info.Visible = False
|
|
End Sub
|
|
|
|
Private Sub l_db_Click
|
|
l_info.Visible = True
|
|
End Sub
|
|
|
|
Private Sub l_dbreqserver_Click
|
|
l_info.Visible = True
|
|
End Sub
|
|
|
|
Private Sub l_internet_Click
|
|
l_info.Visible = True
|
|
End Sub
|
|
|
|
Private Sub l_conexion_Click
|
|
l_info.Visible = True
|
|
End Sub
|
|
|
|
Private Sub p_Main_Click
|
|
l_info.Visible = False
|
|
End Sub
|
|
|
|
Private Sub b_guardaCambios_Click
|
|
'Guardamos Intervalo
|
|
Monitor.Interval = et_intervalo.text
|
|
Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'intervalo'"$)
|
|
Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("intervalo", '${et_intervalo.text}')"$)
|
|
Starter.skmt.ExecNonQuery($"delete from cat_servidores where url = '${et_server.text}'"$)
|
|
Starter.skmt.ExecNonQuery($"insert into cat_servidores (url, intervalo, timeout) values ('${et_server.text}', '${et_intervalo.text}', '${et_timeout.text}')"$)
|
|
' CallSubDelayed(Monitor, "Timer1_Tick")
|
|
p_engrane.Visible = False
|
|
'Guardamos DBReqServer
|
|
Starter.DBReqServer = et_server.text
|
|
Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'servidor'"$)
|
|
Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("servidor", '${et_server.text}')"$)
|
|
CallSubDelayed(Monitor, "reinicializaReqManager")
|
|
p_engrane.Visible = False
|
|
' CallSubDelayed(Monitor, "Timer1_Tick")
|
|
'Guardamos Timeout
|
|
Monitor.timeout = et_timeout.text
|
|
Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'timeout'"$)
|
|
Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("timeout", '${et_timeout.text}')"$)
|
|
CallSubDelayed(Monitor, "Timer1_Tick")
|
|
p_engrane.Visible = False
|
|
ToastMessageShow($"Cambios guardados"$, False)
|
|
End Sub
|
|
|
|
|
|
Private Sub lv_servidoresActivos_ItemClick (Position As Int, Value As Object)
|
|
Private sa As Cursor = Starter.skmt.ExecQuery($"select * from cat_servidores where url = '${Value}'"$)
|
|
If sa.RowCount > 0 Then
|
|
sa.Position = 0
|
|
et_server.Text = sa.GetString("url")
|
|
et_intervalo.Text = sa.GetString("intervalo")
|
|
et_timeout.Text = sa.GetString("timeout")
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub lv_servidoresActivos_ItemLongClick (Position As Int, Value As Object)
|
|
Msgbox2Async($"Esta seguro que desea borrar el servidor ${Value}"$, "AVISO", "SI", "", "NO", Null, True)
|
|
Wait For Msgbox_Result (Result As Int)
|
|
If Result = DialogResponse.POSITIVE Then
|
|
Starter.skmt.ExecNonQuery($"delete from cat_servidores where url = '${Value}'"$)
|
|
i_engrane_Click
|
|
End If
|
|
End Sub |