Merge branch 'develop' into feature/ticket#2463-monitor-detail-show-monitors

This commit is contained in:
Arturo Gonzalez Diaz 2015-07-20 10:43:46 +02:00
commit afd0ac6490
44 changed files with 1790 additions and 884 deletions

@ -1,5 +1,5 @@
package: pandorafms-agent-unix
Version: 6.0dev-150715
Version: 6.0dev-150720
Architecture: all
Priority: optional
Section: admin

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
pandora_version="6.0dev-150715"
pandora_version="6.0dev-150720"
echo "Test if you has the tools for to make the packages."
whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null

@ -41,7 +41,7 @@ my $Sem = undef;
my $ThreadSem = undef;
use constant AGENT_VERSION => '6.0dev';
use constant AGENT_BUILD => '150715';
use constant AGENT_BUILD => '150720';
# Commands to retrieve total memory information in kB
use constant TOTALMEMORY_CMDS => {

@ -3,7 +3,7 @@
#
%define name pandorafms_agent_unix
%define version 6.0dev
%define release 150715
%define release 150720
Summary: Pandora FMS Linux agent, PERL version
Name: %{name}

@ -3,7 +3,7 @@
#
%define name pandorafms_agent_unix
%define version 6.0dev
%define release 150715
%define release 150720
Summary: Pandora FMS Linux agent, PERL version
Name: %{name}

@ -187,94 +187,100 @@ module_end
#Antivirus monitoring
#This modules checks the antivirus is running on your system, if there is and antivirus
#This module gets the last date the signature file was updated and send this date to pandora.
module_begin
module_name Antivirus Last Update
module_type async_string
module_precondition =~ avguard.exe cmd.exe /c tasklist | grep avguard.exe | gawk "{print $1}"
module_exec dir "%ProgramFiles%\Avira\AntiVir Desktop\aevdf.dat" | grep aevdf.dat | gawk "{print $1\" \"$2}"
module_description Last update for Antivirus Signature file
module_end
#module_begin
#module_name Antivirus Last Update
#module_type async_string
#module_precondition =~ avguard.exe cmd.exe /c tasklist | grep avguard.exe | gawk "{print $1}"
#module_exec dir "%ProgramFiles%\Avira\AntiVir Desktop\aevdf.dat" | grep aevdf.dat | gawk "{print $1\" \"$2}"
#module_description Last update for Antivirus Signature file
#module_end
# Windows inventory module (This information will be displayed only in enterprise version)
# Windows inventory module (This information will be displayed only in enterprise version)^M
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\cpuinfo.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\moboinfo.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\diskdrives.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\cdromdrives.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\videocardinfo.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\ifaces.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\monitors.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\printers.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\raminfo.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\software_installed.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\userslogged.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\productkey.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\productID.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\architecture.vbs"
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\win_cf.vbs"
module_crontab * 12-15 * * 1
module_timeout 50
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\domain.vbs"
module_crontab * 12-15 * * 1
module_end
module_begin
module_plugin cscript.exe //B "%PROGRAMFILES%\Pandora_Agent\util\osversion.vbs"
module_crontab * 12-15 * * 1
module_end
# ----------------------------------------------------------------------------------------------------
# This samples below need to be reconfigured and uncommented. Please read documentation

@ -2,7 +2,8 @@
' (c) 2015 Sancho Lerena <slerena@artica.es>
' (c) 2015 Borja Sanchez <fborja.sanchez@artica.es>
' This plugin extends agent inventory feature. Only enterprise version
' --------------------------------------------------------------------------
' Warning: If the system has the WMI corrupted, call this script with nowmi argument
' ------------------------------------------------------------------------------------
on error resume next
Class ObjectList
@ -31,7 +32,7 @@ Class ObjectList
End Class
class AppClass
dim InstallDate,Caption,Version,Vendor
dim InstallDate,Caption,Version,Vendor
end class
' Print the XML structure
@ -43,46 +44,50 @@ Wscript.StdOut.WriteLine "<datalist>"
'------ Checks if an item exists on the main collection
function isItemInArray(objeto,coleccion)
for each id in coleccion.List
if (strComp(objeto,coleccion.List(id).caption) = 0) then
isItemInArray=true
exit function
end if
next
isItemInArray=false
for each id in coleccion.List
if (strComp(objeto,coleccion.List(id).caption) = 0) then
isItemInArray=true
exit function
end if
next
isItemInArray=false
end function
'------ main collection definition
dim colObjSW : set colObjSW = new ObjectList
strComputer = "."
'------ Retrieve the WMI registers first
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery ("SELECT installstate,caption,installdate,Version,vendor FROM Win32_Product")
' Disable by arguments WMI queries - corrupted WMI host
If (not WScript.Arguments(0) = "nowmi") Then
'------ Retrieve the WMI registers first
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery ("SELECT installstate,caption,installdate,Version,vendor FROM Win32_Product",,48)
'------ Check all
'-- first) add all unique WMI (unique) entries to main collector
'-- second) add all unique REGISTRY items to main collector
'------ Check all
'-- first) add all unique WMI (unique) entries to main collector
'-- second) add all unique REGISTRY items to main collector
for each objSoftware in colSoftware
if ( objSoftware.installstate = 5 ) then
if ( isItemInArray(objSoftware.caption, colObjSW) = false ) then
' It doesn't exists, added.
With colObjSW.Append(New AppClass)
.caption = objSoftware.caption
.InstallDate = objSoftware.InstallDate
.version = objSoftware.version
.vendor = objSoftware.vendor
End with
' Add to XML the verified ones
Wscript.StdOut.WriteLine "<data><![CDATA[" _
& objSoftware.caption & ";" _
& objSoftware.version _
& "]]></data>"
end if
end if
next
for each objSoftware in colSoftware
if ( objSoftware.installstate = 5 ) then
if ( isItemInArray(objSoftware.caption, colObjSW) = false ) then
' It doesn't exists, added.
With colObjSW.Append(New AppClass)
.caption = objSoftware.caption
.InstallDate = objSoftware.InstallDate
.version = objSoftware.version
.vendor = objSoftware.vendor
End with
' Add to XML the verified ones
Wscript.StdOut.WriteLine "<data><![CDATA[" _
& objSoftware.caption & ";" _
& objSoftware.version _
& "]]></data>"
end if
end if
next
End If
' ------ Getting the REGISTRY
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
@ -123,12 +128,12 @@ For Each strSubkey In arrSubkeys
' foreach registry item, check if exists in the main collector
' it it exists, it doesn't be added.
if ( isItemInArray(appname, colObjSW) = false ) then
' as item doesn't exist, we add it to main collector and to XML
With colObjSW.Append(New AppClass)
.caption = appname
.version = appversion
End with
Wscript.StdOut.WriteLine "<data><![CDATA[" & appname & ";" & appversion & "]]></data>"
' as item doesn't exist, we add it to main collector and to XML
With colObjSW.Append(New AppClass)
.caption = appname
.version = appversion
End with
Wscript.StdOut.WriteLine "<data><![CDATA[" & appname & ";" & appversion & "]]></data>"
end if
end if
next

@ -0,0 +1,292 @@
' Pandora FMS Agent Custom Field Plugin for Microsoft Windows (All platfforms)
' (c) 2015 Borja Sanchez <fborja.sanchez@artica.es>
' This plugin extends agent inventory feature. Only enterprise version
' -------------------------------------------
' Custom fields information generator
'
' Basic structure:
' <custom_fields>
' <field>
' <name><![CDATA[]></name>
' <value><![CDATA[]></value>
' </field>
' </custom_fields>
'
' --------------------------------------------------------------------------
' Custom Fields: Windows Agent
' SET CORRECT BASE_DIR!!
Set WshShell = WScript.CreateObject("WScript.Shell")
AGENT_HOME_DIR = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES%") & "\pandora_agent\"
Function BASE_DIR (subitem)
BASE_DIR = chr(34) & AGENT_HOME_DIR & subitem & chr(34)
End Function
randomize
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'---------------------------------------------------------------------
' Parses the pandora_agent configuration file to extract the
' fields agent_name, parent_agent_name and group
'---------------------------------------------------------------------
Sub parse_conf_file ()
If WScript.Arguments.Count = 0 Then
pandora_agent_base_path = AGENT_HOME_DIR
Else
pandora_agent_base_path = WScript.Arguments(0)
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
If (Not objFSO.FileExists(pandora_agent_base_path & "pandora_agent.conf" ) ) Then
Exit Sub
End If
Set objFile = objFSO.OpenTextFile(pandora_agent_base_path & "pandora_agent.conf", 1)
name_flag = 1
do until objFile.AtEndOfStream
'"agent_name", "agent_name"
'"parent", "parent_agent_name"
'"group", "group"
line = objFile.ReadLine
If (Not "#" = Left(line, 1) ) Then
lc = InStr(4, line," ")
If (lc > 0 ) Then
field = Left(line, lc -1)
value = Mid(line, lc +1, Len(line))
Select Case field
Case "agent_name"
If (Not value = "") Then
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[" & field & "]]></name>"
WScript.StdOut.WriteLine "<value><![CDATA[" & replace (value,"""", "") &"]]></value>"
Wscript.StdOut.WriteLine "</field>"
name_flag = 0
End If
Case "parent_agent_name","group"
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[" & field & "]]></name>"
WScript.StdOut.WriteLine "<value><![CDATA[" & replace (value,"""", "") &"]]></value>"
Wscript.StdOut.WriteLine "</field>"
End Select
End If
End If
loop
If (name_flag = 1) Then
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[agent_name]]></name>"
Set cols = objWMIService.ExecQuery("SELECT caption FROM Win32_ComputerSystem")
on error resume next
flag = cols.Count
If (err.number <> 0) Then
flag = true
Else
flag = false
End If
on error goto 0
If (NOT flag) Then
For Each data In cols
Wscript.StdOut.WriteLine "<value><![CDATA[" & data.caption & "]]></value>"
Next
End If
Wscript.StdOut.WriteLine "</field>"
End If
objFile.Close
If objFSO.FileExists(OUT_FILE) Then
objFSO.DeleteFile OUT_FILE
End If
End Sub
' FILE STARTS
WScript.StdOut.WriteLine "<custom_fields>"
'--------------------------------
' Custom Field: os_version
'--------------------------------
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[os_version]]></name>"
Set cols = objWMIService.ExecQuery("SELECT version from win32_operatingsystem")
For Each data In cols
Wscript.StdOut.WriteLine "<value><![CDATA[" & data.version & "]]></value>"
Next
Wscript.StdOut.WriteLine "</field>"
'--------------------------------
'--------------------------------
' Custom Field: Domain
'--------------------------------
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[Domain]]></name>"
Set cols = objWMIService.ExecQuery("SELECT Domain FROM Win32_ComputerSystem")
For Each data In cols
Wscript.StdOut.WriteLine "<value><![CDATA[" & data.Domain & "]]></value>"
Next
Wscript.StdOut.WriteLine "</field>"
'--------------------------------
'--------------------------------
' Custom Field: Architecture
'--------------------------------
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[Architecture]]></name>"
Set cols = objWMIService.ExecQuery("SELECT osarchitecture FROM Win32_OperatingSystem")
on error resume next
flag = cols.Count
If (err.number <> 0) Then
flag = true
Else
flag = false
End If
on error goto 0
If flag Then
Wscript.StdOut.WriteLine "<value><![CDATA[32 bits]]></value>"
Else
For Each data In cols
If ( NOT IsNull(data.osarchitecture) ) Then
Wscript.StdOut.WriteLine "<value><![CDATA[" & data.osarchitecture & "]]></value>"
Else
Wscript.StdOut.WriteLine "<value><![CDATA[32 bits]]></value>"
End If
Next
End If
Wscript.StdOut.WriteLine "</field>"
'--------------------------------
'--------------------------------
' Extract info
'--------------------------------
parse_conf_file
'--------------------------------
'----------------------------------------------------
' Custom Field: IP, IPv6 AND MAC -> XXX First found.
'----------------------------------------------------
Set cols = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter " & _
"Where not PNPDeviceID like 'ROOT%%' " & _
"and not PNPDeviceID like 'SW%%' " & _
"and not ServiceName is null " & _
"and not ServiceName like 'vwifimp' ")
on error resume next
flag = cols.Count
If (err.number <> 0) Then
flag = true
Else
flag = false
End If
on error goto 0
If (NOT flag) Then
For Each iface In cols
' return model MACAddress IPAddress
set ifaces_cfg = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration Where Caption='" & iface.caption & "'")
for each iface_cfg in ifaces_cfg
if ( NOT IsNull(iface_cfg.IPAddress) ) then
on error resume next
IP = trim(iface_cfg.IPAddress(0))
If ( err.number <> 0 ) Then
IP = NULL
End If
MAC = iface.MACAddress
If ( err.number <> 0 ) Then
MAC = NULL
End If
IPv6 = trim(iface_cfg.IPAddress(1))
If ( err.number <> 0 ) Then
IPv6 = NULL
End If
on error goto 0
end if
next
Next
End If
If (NOT IsNull(IP)) Then
WScript.StdOut.WriteLine "<field>"
WScript.StdOut.WriteLine "<name><![CDATA[IP]]></name>"
WScript.StdOut.WriteLine "<value><![CDATA[" & IP & "]]></value>"
WScript.StdOut.WriteLine "</field>"
End If
If (NOT IsNull(IPv6)) Then
WScript.StdOut.WriteLine "<field>"
WScript.StdOut.WriteLine "<name><![CDATA[IPv6]]></name>"
WScript.StdOut.WriteLine "<value><![CDATA[" & IPv6 & "]]></value>"
WScript.StdOut.WriteLine "</field>"
End If
If (NOT IsNull(MAC)) Then
WScript.StdOut.WriteLine "<field>"
WScript.StdOut.WriteLine "<name><![CDATA[MAC]]></name>"
WScript.StdOut.WriteLine "<value><![CDATA[" & MAC & "]]></value>"
WScript.StdOut.WriteLine "</field>"
End If
'--------------------------------
'--------------------------------
' Custom Field: Hostname
'--------------------------------
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[hostname]]></name>"
Set cols = objWMIService.ExecQuery("SELECT caption FROM Win32_ComputerSystem")
on error resume next
flag = cols.Count
If (err.number <> 0) Then
flag = true
Else
flag = false
End If
on error goto 0
If (NOT flag) Then
For Each data In cols
Wscript.StdOut.WriteLine "<value><![CDATA[" & data.caption & "]]></value>"
Next
End If
Wscript.StdOut.WriteLine "</field>"
'--------------------------------
WScript.StdOut.WriteLine "</custom_fields>"
' FILE ENDS

@ -0,0 +1,281 @@
' Pandora FMS Agent Custom Field Plugin for Microsoft Windows Xp
' (c) 2015 Borja Sanchez <fborja.sanchez@artica.es>
' This plugin extends agent inventory feature. Only enterprise version
' -------------------------------------------
' Custom fields information generator
'
' Basic structure:
' <custom_fields>
' <field>
' <name><![CDATA[]></name>
' <value><![CDATA[]></value>
' </field>
' </custom_fields>
'
' --------------------------------------------------------------------------
' Custom Fields: Windows Agent
' SET CORRECT BASE_DIR!!
Set WshShell = WScript.CreateObject("WScript.Shell")
AGENT_HOME_DIR = wshShell.ExpandEnvironmentStrings("%PROGRAMFILES%") & "\pandora_agent\"
Function BASE_DIR (subitem)
BASE_DIR = chr(34) & AGENT_HOME_DIR & subitem & chr(34)
End Function
randomize
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'---------------------------------------------------------------------
' Parses the pandora_agent configuration file to extract the
' fields agent_name, parent_agent_name and group
'---------------------------------------------------------------------
Sub parse_conf_file ()
If WScript.Arguments.Count = 0 Then
pandora_agent_base_path = AGENT_HOME_DIR
Else
pandora_agent_base_path = WScript.Arguments(0)
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
If (Not objFSO.FileExists(pandora_agent_base_path & "pandora_agent.conf" ) ) Then
Exit Sub
End If
Set objFile = objFSO.OpenTextFile(pandora_agent_base_path & "pandora_agent.conf", 1)
name_flag = 1
do until objFile.AtEndOfStream
'"agent_name", "agent_name"
'"parent", "parent_agent_name"
'"group", "group"
line = objFile.ReadLine
If (Not "#" = Left(line, 1) ) Then
lc = InStr(4, line," ")
If (lc > 0 ) Then
field = Left(line, lc -1)
value = Mid(line, lc +1, Len(line))
Select Case field
Case "agent_name"
If (Not value = "") Then
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[" & field & "]]></name>"
WScript.StdOut.WriteLine "<value><![CDATA[" & replace (value,"""", "") &"]]></value>"
Wscript.StdOut.WriteLine "</field>"
name_flag = 0
End If
Case "parent_agent_name","group"
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[" & field & "]]></name>"
WScript.StdOut.WriteLine "<value><![CDATA[" & replace (value,"""", "") &"]]></value>"
Wscript.StdOut.WriteLine "</field>"
End Select
End If
End If
loop
If (name_flag = 1) Then
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[agent_name]]></name>"
Set cols = objWMIService.ExecQuery("SELECT caption FROM Win32_ComputerSystem")
on error resume next
flag = cols.Count
If (err.number <> 0) Then
flag = true
Else
flag = false
End If
on error goto 0
If (NOT flag) Then
For Each data In cols
Wscript.StdOut.WriteLine "<value><![CDATA[" & data.caption & "]]></value>"
Next
End If
Wscript.StdOut.WriteLine "</field>"
End If
objFile.Close
If objFSO.FileExists(OUT_FILE) Then
objFSO.DeleteFile OUT_FILE
End If
End Sub
' FILE STARTS
WScript.StdOut.WriteLine "<custom_fields>"
'--------------------------------
' Custom Field: os_version
'--------------------------------
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[os_version]]></name>"
Set cols = objWMIService.ExecQuery("SELECT version from win32_operatingsystem")
For Each data In cols
Wscript.StdOut.WriteLine "<value><![CDATA[" & data.version & "]]></value>"
Next
Wscript.StdOut.WriteLine "</field>"
'--------------------------------
'--------------------------------
' Custom Field: Domain
'--------------------------------
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[Domain]]></name>"
Set cols = objWMIService.ExecQuery("SELECT Domain FROM Win32_ComputerSystem")
For Each data In cols
Wscript.StdOut.WriteLine "<value><![CDATA[" & data.Domain & "]]></value>"
Next
Wscript.StdOut.WriteLine "</field>"
'--------------------------------
'--------------------------------
' Custom Field: Architecture
'--------------------------------
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[Architecture]]></name>"
Set cols = objWMIService.ExecQuery("SELECT osarchitecture FROM Win32_OperatingSystem")
on error resume next
flag = cols.Count
If (err.number <> 0) Then
flag = true
Else
flag = false
End If
on error goto 0
If flag Then
Wscript.StdOut.WriteLine "<value><![CDATA[32 bits]]></value>"
Else
For Each data In cols
If ( NOT IsNull(data.osarchitecture) ) Then
Wscript.StdOut.WriteLine "<value><![CDATA[" & data.osarchitecture & "]]></value>"
Else
Wscript.StdOut.WriteLine "<value><![CDATA[32 bits]]></value>"
End If
Next
End If
Wscript.StdOut.WriteLine "</field>"
'--------------------------------
'--------------------------------
' Extract info
'--------------------------------
parse_conf_file
'--------------------------------
'----------------------------------------------------
' Custom Field: IP, IPv6 AND MAC -> XXX First found.
'----------------------------------------------------
Set cols = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter " & _
"Where not PNPDeviceID like 'ROOT%%' " & _
"and not PNPDeviceID like 'SW%%' " & _
"and not ServiceName is null " & _
"and not ServiceName like 'vwifimp' ")
on error resume next
flag = cols.Count
If (err.number <> 0) Then
flag = true
Else
flag = false
End If
on error goto 0
If (NOT flag) Then
For Each iface In cols
' return model MACAddress IPAddress
set ifaces_cfg = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration Where Caption='" & iface.caption & "'")
for each iface_cfg in ifaces_cfg
if ( NOT IsNull(iface_cfg.IPAddress) ) then
on error resume next
IP = trim(iface_cfg.IPAddress(0))
If ( err.number <> 0 ) Then
IP = NULL
End If
MAC = iface.MACAddress
If ( err.number <> 0 ) Then
MAC = NULL
End If
on error goto 0
end if
next
Next
End If
If (NOT IsNull(IP)) Then
WScript.StdOut.WriteLine "<field>"
WScript.StdOut.WriteLine "<name><![CDATA[IP]]></name>"
WScript.StdOut.WriteLine "<value><![CDATA[" & IP & "]]></value>"
WScript.StdOut.WriteLine "</field>"
End If
If (NOT IsNull(MAC)) Then
WScript.StdOut.WriteLine "<field>"
WScript.StdOut.WriteLine "<name><![CDATA[MAC]]></name>"
WScript.StdOut.WriteLine "<value><![CDATA[" & MAC & "]]></value>"
WScript.StdOut.WriteLine "</field>"
End If
'--------------------------------
'--------------------------------
' Custom Field: Hostname
'--------------------------------
Wscript.StdOut.WriteLine "<field>"
Wscript.StdOut.WriteLine "<name><![CDATA[hostname]]></name>"
Set cols = objWMIService.ExecQuery("SELECT caption FROM Win32_ComputerSystem")
on error resume next
flag = cols.Count
If (err.number <> 0) Then
flag = true
Else
flag = false
End If
on error goto 0
If (NOT flag) Then
For Each data In cols
Wscript.StdOut.WriteLine "<value><![CDATA[" & data.caption & "]]></value>"
Next
End If
Wscript.StdOut.WriteLine "</field>"
'--------------------------------
WScript.StdOut.WriteLine "</custom_fields>"
' FILE ENDS

@ -186,7 +186,7 @@ UpgradeApplicationID
{}
Version
{150715}
{150720}
ViewReadme
{Yes}

@ -30,7 +30,7 @@ using namespace Pandora;
using namespace Pandora_Strutils;
#define PATH_SIZE _MAX_PATH+1
#define PANDORA_VERSION ("6.0dev(Build 150715)")
#define PANDORA_VERSION ("6.0dev(Build 150720)")
string pandora_path;
string pandora_dir;

@ -11,7 +11,7 @@ BEGIN
VALUE "LegalCopyright", "Artica ST"
VALUE "OriginalFilename", "PandoraAgent.exe"
VALUE "ProductName", "Pandora FMS Windows Agent"
VALUE "ProductVersion", "(6.0dev(Build 150715))"
VALUE "ProductVersion", "(6.0dev(Build 150720))"
VALUE "FileVersion", "1.0.0.0"
END
END

@ -1,5 +1,5 @@
package: pandorafms-console
Version: 6.0dev-150715
Version: 6.0dev-150720
Architecture: all
Priority: optional
Section: admin

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
pandora_version="6.0dev-150715"
pandora_version="6.0dev-150720"
package_pear=0
package_pandora=1

@ -25,7 +25,8 @@ if (! check_acl ($config['id_user'], 0, "AW")) {
return;
}
$config["past_planned_downtimes"] = isset($config["past_planned_downtimes"]) ? $config["past_planned_downtimes"] : 1;
// Default
set_unless_defined ($config["past_planned_downtimes"], 1);
require_once ('include/functions_users.php');
@ -81,45 +82,59 @@ $id_agent = (int) get_parameter ('id_agent');
$insert_downtime_agent = (int) get_parameter ('insert_downtime_agent');
$delete_downtime_agent = (int) get_parameter ('delete_downtime_agent');
$groups = users_get_groups ();
// User groups with AW permission for ACL checks
$user_groups_aw = array_keys(users_get_groups($config['id_user'], 'AW'));
// INSERT A NEW DOWNTIME_AGENT ASSOCIATION
if ($insert_downtime_agent === 1) {
// Check AW permission on downtime
$downtime_group = db_get_value('id_group', 'tplanned_downtime', 'id', $id_downtime);
if ($downtime_group === false || !in_array($downtime_group, $user_groups_aw)) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
$agents = (array) get_parameter ('id_agents');
$module_names = (array) get_parameter ('module');
$all_modules = false;
if (empty($module_names)) {
$all_modules = true;
}
else {
//It is empty.
if ($module_names[0] == "0")
$all_modules = true;
}
$all_modules = (empty($module_names) || in_array(0, $module_names));
$executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($executed == 1) {
// 'Is running' check
$is_running = (bool) db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($is_running) {
ui_print_error_message(__("This elements cannot be modified while the downtime is being executed"));
}
else {
$num_agents = count($agents);
for ($a = 0; $a < $num_agents; $a++) {
$id_agente_dt = $agents[$a];
foreach ($agents as $agent_id) {
// Check AW permission on agent
$agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $agent_id);
if ($agent_group === false || !in_array($agent_group, $user_groups_aw)) {
continue;
}
$values = array(
'id_downtime' => $id_downtime,
'id_agent' => $id_agente_dt,
'id_agent' => $agent_id,
'all_modules' => $all_modules
);
$result = db_process_sql_insert('tplanned_downtime_agents', $values);
if ($result && !$all_modules) {
foreach ($module_names as $module_name) {
$module = modules_get_agentmodule_id($module_name, $id_agente_dt);
$module = modules_get_agentmodule_id($module_name, $agent_id);
if (empty($module))
continue;
$values = array(
'id_downtime' => $id_downtime,
'id_agent' => $id_agente_dt,
'id_agent' => $agent_id,
'id_agent_module' => $module["id_agente_modulo"]
);
$result = db_process_sql_insert('tplanned_downtime_modules', $values);
@ -140,8 +155,29 @@ if ($delete_downtime_agent === 1) {
$id_da = (int) get_parameter ('id_downtime_agent');
$executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($executed == 1) {
// Check AW permission on downtime
$downtime_group = db_get_value('id_group', 'tplanned_downtime', 'id', $id_downtime);
if ($downtime_group === false || !in_array($downtime_group, $user_groups_aw)) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
// Check AW permission on agent
$agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $id_agent);
if ($agent_group === false || !in_array($agent_group, $user_groups_aw)) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
// 'Is running' check
$is_running = (bool) db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($is_running) {
ui_print_error_message(__("This elements cannot be modified while the downtime is being executed"));
}
else {
@ -160,11 +196,11 @@ if ($delete_downtime_agent === 1) {
// UPDATE OR CREATE A DOWNTIME (MAIN DATA, NOT AGENT ASSOCIATION)
if ($create_downtime || $update_downtime) {
$check = db_get_value ('name', 'tplanned_downtime', 'name', $name);
$check = (bool) db_get_value ('name', 'tplanned_downtime', 'name', $name);
$datetime_from = strtotime ($once_date_from . ' ' . $once_time_from);
$datetime_to = strtotime ($once_date_to . ' ' . $once_time_to);
$now = strtotime(date(DATE_FORMAT). ' ' . date(TIME_FORMAT));
$now = time();
if ($type_execution == 'once' && !$config["past_planned_downtimes"] && $datetime_from < $now) {
ui_print_error_message(__('Not created. Error inserting data. Start time must be higher than the current time' ));
@ -186,6 +222,15 @@ if ($create_downtime || $update_downtime) {
else {
$sql = '';
if ($create_downtime) {
// Check AW permission on new downtime
if (!in_array($id_group, $user_groups_aw)) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
if (trim(io_safe_output($name)) != '') {
if (!$check) {
$values = array(
@ -230,44 +275,65 @@ if ($create_downtime || $update_downtime) {
}
}
else if ($update_downtime) {
$has_been_executed = db_get_value ('executed', 'tplanned_downtime', 'name', $name);
$old_downtime = db_get_row('tplanned_downtime', 'id', $id_downtime);
// Check AW permission on OLD downtime
if (empty($old_downtime) || !in_array($old_downtime['id_group'], $user_groups_aw)) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
// Check AW permission on NEW downtime group
if (!in_array($id_group, $user_groups_aw)) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
// 'Is running' check
$is_running = (bool) $old_downtime['executed'];
$values = array();
if (trim(io_safe_output($name)) == '') {
ui_print_error_message(__('Planned downtime must have a name'));
}
else if ($has_been_executed == 1 && $type_execution == 'once') {
// When running only certain items can be modified for the 'once' type
else if ($is_running && $type_execution == 'once') {
$values = array(
'description' => $description,
'date_to' => $datetime_to,
'id_user' => $config['id_user']
);
}
else if ($has_been_executed == 1) {
ui_print_error_message(__('No updates. Planned Downtime has been executed'));
else if ($is_running) {
ui_print_error_message(__('Cannot be modified while the downtime is being executed'));
}
else {
$values = array(
'name' => $name,
'description' => $description,
'date_from' => $datetime_from,
'date_to' => $datetime_to,
'id_group' => $id_group,
'only_alerts' => 0,
'monday' => $monday,
'tuesday' => $tuesday,
'wednesday' => $wednesday,
'thursday' => $thursday,
'friday' => $friday,
'saturday' => $saturday,
'sunday' => $sunday,
'periodically_time_from' => $periodically_time_from,
'periodically_time_to' => $periodically_time_to,
'periodically_day_from' => $periodically_day_from,
'periodically_day_to' => $periodically_day_to,
'type_downtime' => $type_downtime,
'type_execution' => $type_execution,
'type_periodicity' => $type_periodicity,
'id_user' => $config['id_user']
'name' => $name,
'description' => $description,
'date_from' => $datetime_from,
'date_to' => $datetime_to,
'id_group' => $id_group,
'only_alerts' => 0,
'monday' => $monday,
'tuesday' => $tuesday,
'wednesday' => $wednesday,
'thursday' => $thursday,
'friday' => $friday,
'saturday' => $saturday,
'sunday' => $sunday,
'periodically_time_from' => $periodically_time_from,
'periodically_time_to' => $periodically_time_to,
'periodically_day_from' => $periodically_day_from,
'periodically_day_to' => $periodically_day_to,
'type_downtime' => $type_downtime,
'type_execution' => $type_execution,
'type_periodicity' => $type_periodicity,
'id_user' => $config['id_user']
);
if ($config["dbtype"] == 'oracle') {
$values['periodically_time_from'] = '1970/01/01 ' . $values['periodically_time_from'];
@ -358,8 +424,17 @@ if ($id_downtime > 0) {
$result = db_get_row_sql ($sql);
// Permission check for the downtime with the AW user groups
if (empty($result) || !in_array($result['id_group'], $user_groups_aw) ){
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
$name = (string) $result["name"];
$id_group = (int) $result['id_group'];
$description = (string) $result["description"];
$type_downtime = (string) $result['type_downtime'];
@ -384,11 +459,11 @@ if ($id_downtime > 0) {
$saturday = (bool) $result['saturday'];
$sunday = (bool) $result['sunday'];
$executed = (bool) $result['executed'];
$running = (bool) $result['executed'];
}
// when the planned down time is in execution, only action to postpone on once type is enabled and the other are disabled.
$disabled_in_execution = $executed ? 1 : 0;
// when the planned downtime is in execution, only action to postpone on once type is enabled and the other are disabled.
$disabled_in_execution = (int) $running;
$table = new StdClass();
$table->class = 'databox filters';
@ -555,33 +630,42 @@ if ($id_downtime > 0) {
// Show available agents to include into downtime
echo '<h4>' . __('Available agents') . ':</h4>';
$filter_group = get_parameter("filter_group", 0);
$filter_group = (int) get_parameter("filter_group", 0);
// User AW groups to str for the filter
$id_groups_str = implode(",", $user_groups_aw);
if (empty($id_groups_str)) {
// Restrictive filter on error. This will filter all the downtimes
$id_groups_str = '-1';
}
$filter_cond = '';
if ($filter_group > 0)
$filter_cond = " AND id_grupo = $filter_group ";
$sql = sprintf ("SELECT tagente.id_agente, tagente.nombre,
tagente.id_grupo
$sql = sprintf("SELECT tagente.id_agente, tagente.nombre
FROM tagente
WHERE tagente.id_agente NOT IN (
SELECT tagente.id_agente
FROM tagente, tplanned_downtime_agents
WHERE tplanned_downtime_agents.id_agent = tagente.id_agente
AND tplanned_downtime_agents.id_downtime = %d
) AND disabled = 0 $filter_cond
ORDER by tagente.nombre", $id_downtime);
$downtimes = db_get_all_rows_sql ($sql);
$data = array ();
if ($downtimes) {
foreach ($downtimes as $downtime) {
if (check_acl ($config["id_user"], $downtime['id_grupo'], "AW")) {
$data[$downtime['id_agente']] = $downtime['nombre'];
}
}
}
) AND disabled = 0 %s
AND tagente.id_grupo IN (%s)
ORDER BY tagente.nombre", $id_downtime, $filter_cond, $id_groups_str);
$agents = db_get_all_rows_sql ($sql);
if (empty($agents))
$agents = array();
$agent_ids = extract_column($agents, 'id_agente');
$agent_names = extract_column($agents, 'nombre');
// item[<id>] = <name>;
$agents = array_combine($agent_ids, $agent_names);
if ($agents === false)
$agents = array();
$disabled_add_button = false;
if (empty($data) || $disabled_in_execution) {
if (empty($agents) || $disabled_in_execution) {
$disabled_add_button = true;
}
@ -595,7 +679,7 @@ if ($id_downtime > 0) {
echo "<form method=post action='index.php?sec=estado&sec2=godmode/agentes/planned_downtime.editor&insert_downtime_agent=1&id_downtime=$id_downtime'>";
echo html_print_select ($data, "id_agents[]", '', '', '', 0, false, true, true, '', false, 'width: 180px;');
echo html_print_select ($agents, "id_agents[]", '', '', '', 0, false, true, true, '', false, 'width: 180px;');
echo '<h4>' . __('Available modules:') .
ui_print_help_tip (__('Only for type Quiet for downtimes.'), true) . '</h4>';
@ -613,17 +697,20 @@ if ($id_downtime > 0) {
//Start Overview of existing planned downtime
echo '<h4>'.__('Agents planned for this downtime').':</h4>';
$sql = sprintf ("SELECT tagente.nombre, tplanned_downtime_agents.id,
tagente.id_os, tagente.id_agente, tagente.id_grupo,
tagente.ultimo_contacto, tplanned_downtime_agents.all_modules
FROM tagente, tplanned_downtime_agents
WHERE tplanned_downtime_agents.id_agent = tagente.id_agente
AND tplanned_downtime_agents.id_downtime = %d ", $id_downtime);
// User the $id_groups_str built before
$sql = sprintf("SELECT ta.nombre, tpda.id,
ta.id_os, ta.id_agente, ta.id_grupo,
ta.ultimo_contacto, tpda.all_modules
FROM tagente ta
INNER JOIN tplanned_downtime_agents tpda
ON ta.id_agente = tpda.id_agent
AND tpda.id_downtime = %d
WHERE ta.id_grupo IN (%s)",
$id_downtime, $id_groups_str);
$downtimes_agents = db_get_all_rows_sql ($sql);
$downtimes = db_get_all_rows_sql ($sql);
if ($downtimes === false) {
echo '<div class="nf">' .
__('There are no scheduled downtimes') . '</div>';
if (empty($downtimes_agents)) {
echo '<div class="nf">' . __('There are no agents') . '</div>';
}
else {
$table = new stdClass();
@ -638,24 +725,24 @@ if ($id_downtime > 0) {
$table->head[3] = __('Last contact');
$table->head['count_modules'] = __('Modules');
if (!$executed) {
if (!$running) {
$table->head[5] = __('Actions');
$table->align[5] = "center";
$table->size[5] = "5%";
}
foreach ($downtimes as $downtime) {
foreach ($downtimes_agents as $downtime_agent) {
$data = array ();
$data[0] = $downtime['nombre'];
$data[0] = $downtime_agent['nombre'];
$data[1] = db_get_sql ("SELECT nombre
FROM tgrupo
WHERE id_grupo = " . $downtime["id_grupo"]);
WHERE id_grupo = " . $downtime_agent["id_grupo"]);
$data[2] = ui_print_os_icon($downtime["id_os"], true, true);
$data[2] = ui_print_os_icon($downtime_agent["id_os"], true, true);
$data[3] = $downtime["ultimo_contacto"];
$data[3] = $downtime_agent["ultimo_contacto"];
if ($type_downtime == 'disable_agents_alerts') {
$data['count_modules'] = __("All alerts");
@ -664,7 +751,7 @@ if ($id_downtime > 0) {
$data['count_modules'] = __("Entire agent");
}
else {
if ($downtime["all_modules"]) {
if ($downtime_agent["all_modules"]) {
$data['count_modules'] = __("All modules");
}
else {
@ -672,19 +759,19 @@ if ($id_downtime > 0) {
}
}
if (!$executed) {
if (!$running) {
$data[5] = '';
if ($type_downtime != 'disable_agents_alerts' && $type_downtime != 'disable_agents') {
$data[5] = '<a href="javascript:show_editor_module(' . $downtime["id_agente"] . ');">' .
$data[5] = '<a href="javascript:show_editor_module(' . $downtime_agent["id_agente"] . ');">' .
html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Delete'))) . "</a>";
}
$data[5] .= '<a href="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor&id_agent=' . $downtime["id_agente"] .
'&delete_downtime_agent=1&id_downtime_agent=' . $downtime["id"] . '&id_downtime=' . $id_downtime . '">' .
$data[5] .= '<a href="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor&id_agent=' . $downtime_agent["id_agente"] .
'&delete_downtime_agent=1&id_downtime_agent=' . $downtime_agent["id"] . '&id_downtime=' . $id_downtime . '">' .
html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete'))) . "</a>";
}
$table->data['agent_' . $downtime["id_agente"]] = $data;
$table->data['agent_' . $downtime_agent["id_agente"]] = $data;
}
html_print_table ($table);
}

@ -20,9 +20,10 @@ require_once ("../../include/functions.php");
require_once ("../../include/functions_db.php");
require_once ("../../include/functions_users.php");
require_once ("../../include/functions_groups.php");
require_once ("../../include/functions_reporting.php");
$config["id_user"] = $_SESSION["id_usuario"];
if (! check_acl ($config['id_user'], 0, "AW")) {
if (! check_acl ($config['id_user'], 0, "AR")) {
db_pandora_audit("ACL Violation", "Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
@ -43,75 +44,80 @@ $module_name = !empty($module_id) ? (string) get_parameter('module_name') : "";
$separator = (string) get_parameter("separator", ";");
$items_separator = (string) get_parameter("items_separator", ",");
// SQL QUERY CREATION
$where_values = "1=1";
$groups = users_get_groups();
$groups_string = implode (",", array_keys ($groups));
$where_values .= " AND id_group IN ($groups_string)";
if (!empty($groups)) {
// SQL QUERY CREATION
$where_values = "1=1";
if (!empty($search_text)) {
$where_values .= " AND (name LIKE '%$search_text%' OR description LIKE '%$search_text%')";
}
$groups_string = implode (",", array_keys ($groups));
$where_values .= " AND id_group IN ($groups_string)";
if (!empty($execution_type)) {
$where_values .= " AND type_execution = '$execution_type'";
}
if (!empty($date_from)) {
$where_values .= " AND (type_execution = 'periodically' OR (type_execution = 'once' AND date_from >= '".strtotime("$date_from 00:00:00")."'))";
}
if (!empty($date_to)) {
$periodically_monthly_w = "type_periodicity = 'monthly' AND (periodically_day_from <= '".date('d', strtotime($date_from))."' AND periodically_time_to >= '".date('d', strtotime($date_to))."')";
$periodically_weekly_days = array();
$date_from_aux = strtotime($date_from);
$date_end = strtotime($date_to);
$days_number = 0;
while ($date_from_aux <= $date_end && $days_number < 7) {
$weekday_actual = strtolower(date('l', $date_from_aux));
$periodically_weekly_days[] = "$weekday_actual = 1";
$date_from_aux = $date_from_aux + SECONDS_1DAY;
$days_number++;
if (!empty($search_text)) {
$where_values .= " AND (name LIKE '%$search_text%' OR description LIKE '%$search_text%')";
}
$periodically_weekly_w = "type_periodicity = 'weekly' AND (".implode(" OR ", $periodically_weekly_days).")";
$periodically_w = "type_execution = 'periodically' AND (($periodically_monthly_w) OR ($periodically_weekly_w))";
$once_w = "type_execution = 'once' AND date_to <= '".strtotime("$date_to 23:59:59")."'";
$where_values .= " AND (($periodically_w) OR ($once_w))";
}
if (!empty($execution_type)) {
$where_values .= " AND type_execution = '$execution_type'";
}
if (!$show_archived) {
$where_values .= " AND (type_execution = 'periodically' OR (type_execution = 'once' AND date_to >= '".time()."'))";
}
if (!empty($date_from)) {
$where_values .= " AND (type_execution = 'periodically' OR (type_execution = 'once' AND date_from >= '".strtotime("$date_from 00:00:00")."'))";
}
if (!empty($agent_id)) {
$where_values .= " AND id IN (SELECT id_downtime FROM tplanned_downtime_agents WHERE id_agent = $agent_id)";
}
if (!empty($date_to)) {
$periodically_monthly_w = "type_periodicity = 'monthly'
AND ((periodically_day_from <= '".date('d', strtotime($date_from))."' AND periodically_day_to >= '".date('d', strtotime($date_to))."')
OR (periodically_day_from > periodically_day_to
AND (periodically_day_from <= '".date('d', strtotime($date_from))."' OR periodically_day_to >= '".date('d', strtotime($date_to))."')))";
$periodically_weekly_days = array();
$date_from_aux = strtotime($date_from);
$date_end = strtotime($date_to);
$days_number = 0;
if (!empty($module_id)) {
$where_values .= " AND (id IN (SELECT id_downtime
FROM tplanned_downtime_modules
WHERE id_agent_module = $module_id)
OR id IN (SELECT id_downtime
FROM tplanned_downtime_agents tpda, tagente_modulo tam
WHERE tpda.id_agent = tam.id_agente
AND tam.id_agente_modulo = $module_id
AND tpda.all_modules = 1))";
}
while ($date_from_aux <= $date_end && $days_number < 7) {
$weekday_actual = strtolower(date('l', $date_from_aux));
$periodically_weekly_days[] = "$weekday_actual = 1";
$sql = "SELECT *
FROM tplanned_downtime
WHERE $where_values
ORDER BY type_execution DESC, date_from DESC";
$downtimes = @db_get_all_rows_sql($sql);
$date_from_aux = $date_from_aux + SECONDS_1DAY;
$days_number++;
}
$periodically_weekly_w = "type_periodicity = 'weekly' AND (".implode(" OR ", $periodically_weekly_days).")";
$periodically_w = "type_execution = 'periodically' AND (($periodically_monthly_w) OR ($periodically_weekly_w))";
$once_w = "type_execution = 'once' AND date_to <= '".strtotime("$date_to 23:59:59")."'";
$where_values .= " AND (($periodically_w) OR ($once_w))";
}
if (!$show_archived) {
$where_values .= " AND (type_execution = 'periodically' OR (type_execution = 'once' AND date_to >= '".time()."'))";
}
if (!empty($agent_id)) {
$where_values .= " AND id IN (SELECT id_downtime FROM tplanned_downtime_agents WHERE id_agent = $agent_id)";
}
if (!empty($module_id)) {
$where_values .= " AND (id IN (SELECT id_downtime
FROM tplanned_downtime_modules
WHERE id_agent_module = $module_id)
OR id IN (SELECT id_downtime
FROM tplanned_downtime_agents tpda, tagente_modulo tam
WHERE tpda.id_agent = tam.id_agente
AND tam.id_agente_modulo = $module_id
AND tpda.all_modules = 1))";
}
$sql = "SELECT *
FROM tplanned_downtime
WHERE $where_values
ORDER BY type_execution DESC, date_from DESC";
$downtimes = @db_get_all_rows_sql($sql);
}
if (!empty($downtimes)) {
ob_clean();
@ -139,61 +145,8 @@ if (!empty($downtimes)) {
$group = ucfirst(io_safe_output(groups_get_name($downtime['id_group'])));
$type = ucfirst(io_safe_output($downtime['type_downtime']));
$execution_type = ucfirst(io_safe_output($downtime['type_execution']));
switch ($downtime['type_execution']) {
case 'once':
$execution_date = date ("Y-m-d H:i", $downtime['date_from']) .
"&nbsp;" . __('to') . "&nbsp;".
date ("Y-m-d H:i", $downtime['date_to']);
break;
case 'periodically':
switch ($downtime['type_periodicity']) {
case 'weekly':
$execution_date = __('Weekly:');
$execution_date .= "&nbsp;";
if ($downtime['monday']) {
$execution_date .= __('Mon');
$execution_date .= "&nbsp;";
}
if ($downtime['tuesday']) {
$execution_date .= __('Tue');
$execution_date .= "&nbsp;";
}
if ($downtime['wednesday']) {
$execution_date .= __('Wed');
$execution_date .= "&nbsp;";
}
if ($downtime['thursday']) {
$execution_date .= __('Thu');
$execution_date .= "&nbsp;";
}
if ($downtime['friday']) {
$execution_date .= __('Fri');
$execution_date .= "&nbsp;";
}
if ($downtime['saturday']) {
$execution_date .= __('Sat');
$execution_date .= "&nbsp;";
}
if ($downtime['sunday']) {
$execution_date .= __('Sun');
$execution_date .= "&nbsp;";
}
$execution_date .= "&nbsp;(" . $downtime['periodically_time_from'];
$execution_date .= "-" . $downtime['periodically_time_to'] . ")";
break;
case 'monthly':
$execution_date = __('Monthly:');
$execution_date .= __('From day') . "&nbsp;" . $downtime['periodically_day_from'];
$execution_date .= "/" . __('To day') . "&nbsp;";
$execution_date .= $downtime['periodically_day_to'];
$execution_date .= "&nbsp;(" . $downtime['periodically_time_from'];
$execution_date .= "-" . $downtime['periodically_time_to'] . ")";
break;
}
break;
}
$execution_date = io_safe_output($execution_date);
$execution_date = io_safe_output(reporting_format_planned_downtime_dates($downtime));
$affected_items = array();

@ -18,7 +18,10 @@ global $config;
check_login();
if (! check_acl ($config['id_user'], 0, "AW")) {
$read_permisson = check_acl ($config['id_user'], 0, "AR");
$write_permisson = check_acl ($config['id_user'], 0, "AW");
if (! $read_permisson) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
@ -28,6 +31,7 @@ if (! check_acl ($config['id_user'], 0, "AW")) {
require_once ('include/functions_users.php');
require_once ('include/functions_events.php');
require_once ('include/functions_planned_downtimes.php');
require_once ('include/functions_reporting.php');
$malformed_downtimes = planned_downtimes_get_malformed();
$malformed_downtimes_exist = !empty($malformed_downtimes) ? true : false;
@ -52,7 +56,6 @@ ui_print_page_header(
true,
"");
$delete_downtime = (int) get_parameter ('delete_downtime');
$id_downtime = (int) get_parameter ('id_downtime', 0);
$stop_downtime = (bool) get_parameter ('stop_downtime');
@ -60,138 +63,47 @@ $stop_downtime = (bool) get_parameter ('stop_downtime');
if ($stop_downtime) {
$downtime = db_get_row('tplanned_downtime', 'id', $id_downtime);
switch ($downtime['type_execution']) {
case 'once':
$date_stop = date ("Y-m-j", get_system_time ());
$time_stop = date ("h:iA", get_system_time ());
$values = array(
'executed' => 0,
'date_to' => strtotime($date_stop . ' ' . $time_stop)
);
$result = db_process_sql_update('tplanned_downtime',
$values, array ('id' => $id_downtime));
break;
case 'periodically':
break;
// Check AW permission on the downtime
if (empty($downtime) || ! check_acl ($config['id_user'], $downtime['id_group'], "AW")) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
ui_print_result_message($result,
__('Succesful stopped the Downtime'),
__('Unsuccesful stopped the Downtime'));
$result = planned_downtimes_stop($downtime);
if ($result) {
events_create_event ("Manual stop downtime ".
$downtime['name'] . " (" . $downtime['id'] . ") by " .
$config['id_user'], 0, 0, EVENT_STATUS_NEW, $config["id_user"],
"system", 1);
db_pandora_audit("Planned Downtime management",
"Manual stop downtime " . $downtime['name'] . " (ID " . $downtime['id'] . ")",
false, true);
//Reenabled the Agents or Modules or alerts...depends of type
$downtime = db_get_row('tplanned_downtime', 'id', $id_downtime);
switch ($downtime['type_downtime']) {
case 'quiet':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
if ($agent['all_modules']) {
$result = db_process_sql_update('tagente',
array('quiet' => 0),
array('id_agente' => $agent['id_agent']));
if ($result)
$count++;
}
else {
$modules = db_get_all_rows_filter(
'tplanned_downtime_modules',
array('id_agent' => $agent['id_agent'],
'id_downtime' => $id_downtime));
if (empty($modules))
$modules = array();
foreach ($modules as $module) {
$result = db_process_sql_update(
'tagente_modulo',
array('quiet' => 0),
array('id_agente_modulo' =>
$module['id_agent_module']));
if ($result)
$count++;
}
}
}
break;
case 'disable_agents':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
$result = db_process_sql_update('tagente',
array('disabled' => 0),
array('id_agente' => $agent['id_agent']));
if ($result)
$count++;
}
break;
case 'disable_agents_alerts':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
$modules = db_get_all_rows_filter(
'tagente_modulo',
array('id_agente' => $agent['id_agent']));
if (empty($modules))
$modules = array();
foreach ($modules as $module) {
$result = db_process_sql_update(
'talert_template_modules',
array('disabled' => 0),
array('id_agent_module' =>
$module['id_agente_modulo']));
if ($result)
$count++;
}
}
break;
}
ui_print_info_message(
sprintf(__('Enabled %s elements from the downtime'), $count));
if ($result === false) {
ui_print_error_message(__('An error occurred stopping the planned downtime'));
}
else {
echo $result['message'];
}
}
$delete_downtime = (int) get_parameter ('delete_downtime');
// DELETE WHOLE DOWNTIME!
if ($delete_downtime) {
$result = db_process_sql_delete('tplanned_downtime', array('id' => $id_downtime));
$downtime = db_get_row('tplanned_downtime', 'id', $id_downtime);
if ($result === false) {
ui_print_error_message(__('Not deleted. Error deleting data'));
// Check AW permission on the downtime
if (empty($downtime) || ! check_acl ($config['id_user'], $downtime['id_group'], "AW")) {
db_pandora_audit("ACL Violation",
"Trying to access downtime scheduler");
require ("general/noaccess.php");
return;
}
// The downtime shouldn't be running!!
if ($downtime['executed']) {
ui_print_error_message(__('This planned downtime is running'));
}
else {
ui_print_success_message(__('Successfully deleted'));
$result = db_process_sql_delete('tplanned_downtime', array('id' => $id_downtime));
ui_print_result_message($result,
__('Successfully deleted'),
__('Not deleted. Error deleting data'));
}
}
@ -263,31 +175,7 @@ $row[] = __('Module') . '&nbsp;' . html_print_autocomplete_modules('module_name'
$row[] = html_print_submit_button('Search', 'search', false, 'class="sub search"', true);
$table_form->data[] = $row;
// View available downtimes present in database (if any of them)
$table = new StdClass();
$table->class = 'databox data';
//Start Overview of existing planned downtime
$table->width = '100%';
$table->cellstyle = array();
$table->data = array();
$table->head = array();
$table->head[0] = __('Name #Ag.');
$table->head[1] = __('Description');
$table->head[2] = __('Group');
$table->head[3] = __('Type');
$table->head[4] = __('Execution');
$table->head[5] = __('Configuration');
$table->head[6] = __('Running');
$table->head[7] = __('Stop downtime');
$table->head[8] = __('Edit');
$table->head[9] = __('Delete');
$table->align[2] = "center";
$table->align[6] = "center";
$table->align[7] = "center";
$table->align[8] = "center";
$table->align[9] = "center";
// End of table filter
$groups = users_get_groups ();
if (!empty($groups)) {
@ -443,121 +331,115 @@ else {
echo "</form>";
ui_pagination($downtimes_number, "index.php?sec=estado&sec2=godmode/agentes/planned_downtime.list&$filter_params_str", $offset);
// User groups with AW permission
$groupsAW = users_get_groups($config['id_user'], 'AW');
$groupsAW = array_keys($groupsAW);
// View available downtimes present in database (if any of them)
$table = new StdClass();
$table->class = 'databox data';
$table->width = '100%';
$table->cellstyle = array();
$table->head = array();
$table->head['name'] = __('Name #Ag.');
$table->head['description'] = __('Description');
$table->head['group'] = __('Group');
$table->head['type'] = __('Type');
$table->head['execution'] = __('Execution');
$table->head['configuration'] = __('Configuration');
$table->head['running'] = __('Running');
if ($write_permisson) {
$table->head['stop'] = __('Stop downtime');
$table->head['edit'] = __('Edit');
$table->head['delete'] = __('Delete');
}
$table->align = array();
$table->align['group'] = "center";
$table->align['running'] = "center";
if ($write_permisson) {
$table->align['stop'] = "center";
$table->align['edit'] = "center";
$table->align['delete'] = "center";
}
$table->data = array();
foreach ($downtimes as $downtime) {
$data = array();
$total = db_get_sql ("SELECT COUNT(id_agent)
FROM tplanned_downtime_agents
WHERE id_downtime = ".$downtime["id"]);
$data[0] = $downtime['name']. " ($total)";
$data[1] = $downtime['description'];
$data[2] = ui_print_group_icon ($downtime['id_group'], true);
$data['name'] = $downtime['name']. " ($total)";
$data['description'] = $downtime['description'];
$data['group'] = ui_print_group_icon ($downtime['id_group'], true);
$type_text = array('quiet' => __('Quiet'),
'disable_agents' => __('Disabled Agents'),
'disable_agents_alerts' => __('Disabled only Alerts'));
$data[3] = $type_text[$downtime['type_downtime']];
$data['type'] = $type_text[$downtime['type_downtime']];
$execution_text = array('once' => __('once'),
'periodically' => __('Periodically'));
$data[4] = $execution_text[$downtime['type_execution']];
$data['execution'] = $execution_text[$downtime['type_execution']];
switch ($downtime['type_execution']) {
case 'once':
$data[5] = date ("Y-m-d H:i:s", $downtime['date_from']) .
"&nbsp;" . __('to') . "&nbsp;".
date ("Y-m-d H:i:s", $downtime['date_to']);
break;
case 'periodically':
switch ($downtime['type_periodicity']) {
case 'weekly':
$data[5] = __('Weekly:');
$data[5] .= "&nbsp;";
if ($downtime['monday']) {
$data[5] .= __('Mon');
$data[5] .= "&nbsp;";
}
if ($downtime['tuesday']) {
$data[5] .= __('Tue');
$data[5] .= "&nbsp;";
}
if ($downtime['wednesday']) {
$data[5] .= __('Wed');
$data[5] .= "&nbsp;";
}
if ($downtime['thursday']) {
$data[5] .= __('Thu');
$data[5] .= "&nbsp;";
}
if ($downtime['friday']) {
$data[5] .= __('Fri');
$data[5] .= "&nbsp;";
}
if ($downtime['saturday']) {
$data[5] .= __('Sat');
$data[5] .= "&nbsp;";
}
if ($downtime['sunday']) {
$data[5] .= __('Sun');
$data[5] .= "&nbsp;";
}
$data[5] .= "&nbsp;(" . $downtime['periodically_time_from'];
$data[5] .= "-" . $downtime['periodically_time_to'] . ")";
break;
case 'monthly':
$data[5] = __('Monthly:');
$data[5] .= __('From day') . "&nbsp;" . $downtime['periodically_day_from'];
$data[5] .= "/" . __('To day') . "&nbsp;";
$data[5] .= $downtime['periodically_day_to'];
$data[5] .= "&nbsp;(" . $downtime['periodically_time_from'];
$data[5] .= "-" . $downtime['periodically_time_to'] . ")";
break;
}
break;
}
$data['configuration'] = reporting_format_planned_downtime_dates($downtime);
if ($downtime["executed"] == 0) {
$data[6] = html_print_image ("images/pixel_red.png", true,
array ('width' => 20, 'height' => 20, 'alt' => __('Executed')));
$data['running'] = html_print_image ("images/pixel_red.png", true,
array ('width' => 20, 'height' => 20, 'title' => __('Not running')));
}
else {
$data[6] = html_print_image ("images/pixel_green.png", true,
array ('width' => 20, 'height' => 20, 'alt' => __('Not executed')));
$data['running'] = html_print_image ("images/pixel_green.png", true,
array ('width' => 20, 'height' => 20, 'title' => __('Running')));
}
if ($downtime['type_execution'] == 'once' && $downtime["executed"] == 1) {
// If user have writting permissions
if (in_array($downtime['id_group'], $groupsAW)) {
// Stop button
if ($downtime['type_execution'] == 'once' && $downtime["executed"] == 1) {
$data['stop'] = '<a href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list' .
'&stop_downtime=1&id_downtime=' . $downtime['id'] . '&' . $filter_params_str . '">' .
html_print_image("images/cancel.png", true, array("title" => __('Stop downtime')));
}
else {
$data['stop'] = "";
}
$data[7] .= '<a href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list' .
'&stop_downtime=1&id_downtime=' . $downtime['id'] . '&' . $filter_params_str . '">' .
html_print_image("images/cancel.png", true, array("border" => '0', "alt" => __('Stop downtime')));
// Edit & delete buttons
if ($downtime["executed"] == 0) {
// Edit
$data['edit'] = '<a href="index.php?sec=estado&sec2=godmode/agentes/planned_downtime.editor&edit_downtime=1&id_downtime='.$downtime['id'].'">' .
html_print_image("images/config.png", true, array("title" => __('Update'))) . '</a>';
// Delete
$data['delete'] = '<a id="delete_downtime" href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list'.
'&delete_downtime=1&id_downtime=' . $downtime['id'] . '&' . $filter_params_str . '">' .
html_print_image("images/cross.png", true, array("title" => __('Delete')));
}
else if ($downtime["executed"] == 1 && $downtime['type_execution'] == 'once') {
// Edit
$data['edit'] = '<a href="index.php?sec=estado&sec2=godmode/agentes/planned_downtime.editor&edit_downtime=1&id_downtime=' . $downtime['id'] . '">' .
html_print_image("images/config.png", true, array("title" => __('Update'))) . '</a>';
// Delete
$data['delete']= __('N/A');
}
else {
$data['edit']= '';
$data['delete']= '';
}
}
else {
$data[7] = "";
}
if ($downtime["executed"] == 0) {
$data[8] = '<a href="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor&amp;edit_downtime=1&amp;id_downtime='.$downtime['id'].'">' .
html_print_image("images/config.png", true, array("border" => '0', "alt" => __('Update'))) . '</a>';
$data[9] = '<a id="delete_downtime" href="index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list'.
'&delete_downtime=1&id_downtime=' . $downtime['id'] . '&' . $filter_params_str . '">' .
html_print_image("images/cross.png", true, array("border" => '0', "alt" => __('Delete')));
}
elseif ($downtime["executed"] == 1
&& $downtime['type_execution'] == 'once') {
$data[8] = '<a href="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor&amp;' .
'edit_downtime=1&amp;id_downtime=' . $downtime['id'] . '">' .
html_print_image("images/config.png", true,
array("border" => '0', "alt" => __('Update'))) . '</a>';
$data[9]= "N/A";
}
else {
$data[8]= "N/A";
$data[9]= "N/A";
$data['stop'] = '';
$data['edit'] = '';
$data['delete'] = '';
}
if (!empty($malformed_downtimes_exist) && isset($malformed_downtimes[$downtime['id']])) {
@ -571,23 +453,28 @@ else {
array_push ($table->data, $data);
}
html_print_table ($table);
echo '<div class="action-buttons" style="width: '.$table->width.'">';
echo '<br>';
// CSV export button
echo '<div style="display: inline;">';
html_print_button(__('Export to CSV'), 'csv_export', false,
"location.href='godmode/agentes/planned_downtime.export_csv.php?$filter_params_str'", 'class="sub next"');
echo '</div>';
echo '&nbsp;';
echo '<form method="post" action="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor" style="display: inline;">';
html_print_submit_button (__('Create'), 'create', false, 'class="sub next"');
echo '</form>';
// Create button
if ($write_permisson) {
echo '&nbsp;';
echo '<form method="post" action="index.php?sec=estado&amp;sec2=godmode/agentes/planned_downtime.editor" style="display: inline;">';
html_print_submit_button (__('Create'), 'create', false, 'class="sub next"');
echo '</form>';
}
echo '</div>';
}
ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/");
?>

@ -43,7 +43,7 @@ if (!defined('METACONSOLE')) {
$id_layout = (int) get_parameter ('id_layout');
$copy_layout = (bool) get_parameter ('copy_layout');
$delete_layout = (bool) get_parameter ('delete_layout');
$refr = (int) get_parameter('refr');
$refr = (int) get_parameter('refr', 60);
$offset = (int) get_parameter('offset', 0);
$pagination = (int) get_parameter ("pagination", $config["block_size"]);
@ -238,7 +238,8 @@ else {
if ($own_info['is_admin'] || $vconsoles_read) {
$maps = visual_map_get_user_layouts (0,false,$filters);
$total_maps = count(visual_map_get_user_layouts());
} else {
}
else {
$maps = visual_map_get_user_layouts ($config['id_user'], false,
$filters, false);
$total_maps = count(visual_map_get_user_layouts ($config['id_user'], false,

@ -121,6 +121,9 @@ if (isset($_GET["update"]) || (isset($_GET["crt"]))) {
$parent_detection = $row["parent_detection"];
$parent_recursion = $row["parent_recursion"];
$macros = $row["macros"];
$name_script = db_get_value('name',
'trecon_script', 'id_recon_script', $id_recon_script);
}
}
elseif (isset($_GET["create"]) || isset($_GET["crt"])) {
@ -217,7 +220,7 @@ $table->data[2][1] = html_print_select ($fields, "mode", $mode, '', '', 0, true)
// Network
$table->data[3][0] = "<b>".__('Network');
$table->data[3][0] = "<b>" . __('Network') . "</b>";
$table->data[3][1] = html_print_input_text ('network', $network, '', 25, 0, true);
// Interval
@ -236,7 +239,7 @@ $table->data[4][1] .= '</span>';
// Module template
$table->data[5][0] = "<b>".__('Module template');
$table->data[5][0] = "<b>" . __('Module template') . "</b>";
$sql = 'SELECT id_np, name
FROM tnetwork_profile
@ -245,17 +248,23 @@ $table->data[5][1] = html_print_select_from_sql ($sql, "id_network_profile", $id
// Recon script
$data[1] = '';
$table->data[6][0] = "<b>".__('Recon script');
$table->data[6][0] = "<b>" . __('Recon script') . "</b>";
$sql = 'SELECT id_recon_script, name
FROM trecon_script
WHERE name <> "IPAM Recon"
ORDER BY name';
$table->data[6][1] = html_print_select_from_sql ($sql, "id_recon_script", $id_recon_script, '', '', '', true);
$table->data[6][1] .= "<span id='spinner_recon_script' style='display: none;'>" . html_print_image ("images/spinner.gif", true) . "</span>";
$table->data[6][1] .= $data[1] .= html_print_input_hidden('macros', base64_encode($macros),true);
if ($name_script != "IPAM Recon") {
$table->data[6][1] = html_print_select_from_sql ($sql, "id_recon_script", $id_recon_script, '', '', '', true);
$table->data[6][1] .= "<span id='spinner_recon_script' style='display: none;'>" . html_print_image ("images/spinner.gif", true) . "</span>";
$table->data[6][1] .= $data[1] .= html_print_input_hidden('macros', base64_encode($macros),true);
}
else {
$table->data[6][1] = "IPAM Recon";
}
// OS
$table->data[7][0] = "<b>".__('OS');
$table->data[7][0] = "<b>" . __('OS') . "</b>";
$sql = 'SELECT id_os, name
FROM tconfig_os
@ -263,7 +272,7 @@ $sql = 'SELECT id_os, name
$table->data[7][1] = html_print_select_from_sql ($sql, "id_os", $id_os, '', __('Any'), -1, true);
// Recon ports
$table->data[8][0] = "<b>".__('Ports');
$table->data[8][0] = "<b>" . __('Ports') . "</b>";
$table->data[8][1] = html_print_input_text ('recon_ports', $recon_ports, '', 25, 0, true);
$table->data[8][1] .= ui_print_help_tip(
__('Ports defined like: 80 or 80,443,512 or even 0-1024 (Like Nmap command line format). If dont want to do a sweep using portscan, left it in blank'), true);
@ -346,10 +355,15 @@ $table->data[21][1] = html_print_input_text ('parent_recursion', $parent_recurs
echo '<form name="modulo" method="post" action="index.php?sec=gservers&sec2=godmode/servers/manage_recontask&'.(($id_rt != -1) ? 'update='.$id_rt : 'create=1').'">';
html_print_table ($table);
echo '<div class="action-buttons" style="width: '.$table->width.'">';
if ($id_rt != -1)
html_print_submit_button (__('Update'), "crt", false, 'class="sub upd"');
else
if ($id_rt != -1) {
if ($name_script != "IPAM Recon") {
html_print_submit_button (__('Update'), "crt", false, 'class="sub upd"');
}
}
else {
html_print_submit_button (__('Add'), "crt", false, 'class="sub wand"');
}
echo "</div>";
echo "</form>";

@ -19,8 +19,6 @@ global $config;
// Check login and ACLs
check_login ();
enterprise_hook('open_meta_frame');
if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) {
db_pandora_audit("ACL Violation", "Trying to access Tag Management");
require ("general/noaccess.php");
@ -32,12 +30,20 @@ require_once ($config['homedir'].'/include/functions_tags.php');
// Get parameters
$delete = (int) get_parameter ("delete_tag", 0);
$search = (int) get_parameter ("search_tag", 0);
$tag_name = (string) get_parameter ("tag_name","");
$tab = (string) get_parameter ("tab", "list");
// Metaconsole nodes
$servers = false;
if (is_metaconsole()) {
enterprise_include_once('include/functions_metaconsole.php');
$servers = metaconsole_get_servers();
}
//Ajax tooltip to deploy module's count info of a tag.
if (is_ajax ()) {
ob_clean();
$get_tag_tooltip = (bool) get_parameter ('get_tag_tooltip', 0);
if ($get_tag_tooltip) {
@ -46,19 +52,43 @@ if (is_ajax ()) {
if ($tag === false)
return;
$local_modules_count = 0;
if (is_metaconsole() && !empty($servers)) {
$local_modules_count = array_reduce($servers, function($counter, $server) use ($id_tag) {
if (metaconsole_connect($server) === NOERR)
$counter += tags_get_local_modules_count($id_tag);
return $counter;
}, 0);
}
else {
$local_modules_count = tags_get_local_modules_count($id_tag);
}
$policy_modules_count = 0;
if (is_metaconsole() && !empty($servers)) {
$policy_modules_count = array_reduce($servers, function($counter, $server) use ($id_tag) {
if (metaconsole_connect($server) === NOERR)
$counter += tags_get_policy_modules_count($id_tag);
return $counter;
}, 0);
}
else {
$policy_modules_count = tags_get_policy_modules_count($id_tag);
}
echo '<h3>'.$tag['name'].'</h3>';
echo '<strong>'.__('Number of modules').': </strong> ' .
tags_get_local_modules_count($id_tag);
echo '<strong>'.__('Number of modules').': </strong> ' . $local_modules_count;
echo '<br>';
echo '<strong>'.__('Number of policy modules').': </strong>' .
tags_get_policy_modules_count($id_tag);
echo '<strong>'.__('Number of policy modules').': </strong>' . $policy_modules_count;
return;
}
return;
}
if (defined('METACONSOLE'))
enterprise_hook('open_meta_frame');
if (is_metaconsole())
$sec = 'advanced';
else
$sec = 'gmodules';
@ -71,20 +101,15 @@ $buttons = array(
$buttons[$tab]['active'] = true;
if (defined('METACONSOLE')) {
if (is_metaconsole()) {
// Print header
ui_meta_print_header(__('Tags'), "", $buttons);
}
else {
// Header
ui_print_page_header (__('Tags configuration'), "images/tag.png", false, "tags_config", true, $buttons);
}
// Two actions can performed in this page: search and delete tags
// Delete action: This will delete a tag
@ -101,59 +126,54 @@ if ($delete != 0) {
}
}
// statements for pagination
$url = ui_get_url_refresh ();
$total_tags = tags_get_tag_count();
// Search action: This will filter the display tag view
$filter = array();
// Filtered view?
if (!empty($tag_name)) {
$filter['name'] = $tag_name;
}
// If the user has filtered the view
$filter_performed = !empty($filter);
$filter['offset'] = (int) get_parameter ('offset');
$filter['limit'] = (int) $config['block_size'];
// Search action: This will filter the display tag view
$result = false;
// Filtered view?
if ($search != 0) {
$result = tags_search_tag($tag_name, $filter);
}
else {
$result = tags_search_tag(false, $filter);
}
// statements for pagination
$url = ui_get_url_refresh ();
$total_tags = tags_get_tag_count($filter);
$result = tags_search_tag(false, $filter);
// Filter form
$table = new StdClass();
$table->class = 'databox filters';
$table->width = '100%';
$table->data = array();
$row = array();
$name_input = __("Name") . " / " . __("Description");
$name_input .= "&nbsp;&nbsp;";
$name_input .= html_print_input_text ('tag_name', $tag_name, '', 30, 255, true);
$row[] = $name_input;
$filter_button = html_print_submit_button (__('Filter'), 'filter_button', false, 'class="sub search"',true);
$row[] = $filter_button;
$table->data[] = $row;
$filter_form = '<form method="POST" action="index.php?sec='.$sec.'&sec2=godmode/tag/tag&delete_tag=0">';
$filter_form .= html_print_table($table, true);
$filter_form .= "</form>";
// End of filter form
if (!empty($result)) {
// Form to add new tags or search tags
if (!defined('METACONSOLE')) {
echo "<table border=0 cellpadding=4 cellspacing=4 class='databox data' width=100%>";
echo "<tr>";
echo "<td>";
echo '<b>' . __("Name") . "/" . __("Description") . '</b>';
echo "</td>";
echo "<td align=center>";
echo '<form method=post action="index.php?sec='.$sec.'&sec2=godmode/tag/tag&delete_tag=0">';
html_print_input_hidden ("search_tag", "1");
html_print_input_text ('tag_name', $tag_name, '', 30, 255, false);
echo "&nbsp;&nbsp;&nbsp;";
html_print_submit_button (__('Filter'), 'filter_button', false, 'class="sub search"');
echo "</form>";
echo "</td>";
echo "</tr>";
echo "</table>";
if (!is_metaconsole()) {
echo $filter_form;
}
else {
$filters = '<form method=post class="" action="index.php?sec='.$sec.'&sec2=godmode/tag/tag&delete_tag=0">';
$filters .= "<table border=0 cellpadding=0 cellspacing=0 class='databox filters' width=100%>";
$filters .= "<tr>";
$filters .= "<td>";
$filters .= __("Name") . "/" . __("Description");
$filters .= "&nbsp;&nbsp;";
$filters .= html_print_input_hidden ("search_tag", "1",true);
$filters .= html_print_input_text ('tag_name', $tag_name, '', 30, 255, true);
$filters .= "</td>";
$filters .= "<td>";
$filters .= html_print_submit_button (__('Filter'), 'filter_button', false, 'class="sub search"',true);
$filters .= "</td>";
$filters .= "</tr>";
$filters .= "</table>";
$filters .= "</form>";
ui_toggle($filters, __("Show Options"));
ui_toggle($filter_form, __("Show Options"));
}
// Prepare pagination
@ -162,8 +182,6 @@ if (!empty($result)) {
// Display tags previously filtered or not
$rowPair = true;
$iterator = 0;
$table = new stdClass();
$table->width = '100%';
@ -199,11 +217,27 @@ if (!empty($result)) {
$data[0] = "<a href='index.php?sec=".$sec."&sec2=godmode/tag/edit_tag&action=update&id_tag=" . $tag["id_tag"] . "'>" . $tag["name"] . "</a>";
$data[1] = ui_print_truncate_text($tag["description"], 'description', false);
$data[2] = '<a href="' . $tag["url"] . '">' . $tag["url"] . '</a>';
$data[3] = ' <a class="tag_details"
href="' . ui_get_full_url(false, false, false, false) . '/ajax.php?page=godmode/tag/tag&get_tag_tooltip=1&id_tag=' . $tag['id_tag'] . '">' .
html_print_image("images/zoom.png", true, array("id" => 'tag-details-'.$tag['id_tag'], "class" => "img_help")) . '</a> ';
$data[3] .= tags_get_modules_count($tag["id_tag"]);
// The tooltip needs a title on the item, don't delete the title
$data[3] = '<a class="tag_details img_help" title="'.__('Tag details').'"
href="' . ui_get_full_url(false, false, false, false) . '/ajax.php?page=godmode/tag/tag&get_tag_tooltip=1&id_tag=' . $tag['id_tag'] . '">' .
html_print_image("images/zoom.png", true) . '</a> ';
$modules_count = 0;
if (is_metaconsole() && !empty($servers)) {
$tag_id = $tag['id_tag'];
$modules_count = array_reduce($servers, function($counter, $server) use ($tag_id) {
if (metaconsole_connect($server) === NOERR)
$counter += tags_get_modules_count($tag_id);
return $counter;
}, 0);
}
else {
$modules_count = tags_get_modules_count($tag["id_tag"]);
}
$data[3] .= $modules_count;
$email_large = io_safe_output($tag["email"]);
$email_small = substr($email_large,0, 24);
@ -242,15 +276,20 @@ if (!empty($result)) {
html_print_table ($table);
}
else{
if(!defined("METACONSOLE")){
require_once ($config['homedir'] . "/general/firts_task/tags.php");
else {
if (is_metaconsole()) {
ui_toggle($filter_form, __("Show Options"));
ui_print_info_message(array("no_close" => true, "message" => __("No tags defined")));
}
else if ($filter_performed) {
echo $filter_form;
}
else {
require ($config['homedir'] . "/general/firts_task/tags.php");
return;
}
else{
ui_print_info_message(array("no_close"=>true,"message"=>__("No tags defined.")));
}
}
echo "<table border=0 cellpadding=0 cellspacing=0 width=100%>";
echo "<tr>";
echo "<td align=right>";
@ -265,44 +304,55 @@ echo "</table>";
enterprise_hook('close_meta_frame');
ui_require_css_file ('cluetip');
ui_require_jquery_file ('cluetip');
?>
<script type="text/javascript">
/* <![CDATA[ */
$("a.tag_details").cluetip ({
arrows: true,
attribute: 'href',
cluetipClass: 'default'
})
.click (function () {
return false;
});
/* ]]> */
</script>
<script type="text/javascript">
$(document).ready(function () {
$(".email_large").dialog(
{
autoOpen: false,
resizable: true,
width: 400,
height: 200
});
$(".phone_large").dialog(
{
autoOpen: false,
resizable: true,
width: 400,
height: 200
});
$("a.tag_details")
.tooltip({
track: true,
content: '<?php html_print_image("images/spinner.gif"); ?>',
open: function (evt, ui) {
var elem = $(this);
var uri = elem.prop('href');
if (typeof uri !== 'undefined' && uri.length > 0) {
var jqXHR = $.ajax(uri).done(function(data) {
elem.tooltip('option', 'content', data);
});
// Store the connection handler
elem.data('jqXHR', jqXHR);
}
$(".ui-tooltip>.ui-tooltip-content:not(.cluetip-default)")
.addClass("cluetip-default");
},
close: function (evt, ui) {
var elem = $(this);
var jqXHR = elem.data('jqXHR');
// Close the connection handler
if (typeof jqXHR !== 'undefined')
jqXHR.abort();
}
})
.click (function (event) {
event.preventDefault();
})
.css('cursor', 'help');
$(".email_large, .phone_large").dialog({
autoOpen: false,
resizable: true,
width: 400,
height: 200
});
function show_dialog(id) {
$("#email_large_" + id).dialog("open");
}
function show_phone_dialog(id) {
$("#phone_large_" + id).dialog("open");
}
</script>

@ -32,114 +32,6 @@ $change_module_relation_updates = (bool) get_parameter('change_module_relation_u
$get_id_tag = (bool) get_parameter('get_id_tag', 0);
$list_modules = (bool) get_parameter('list_modules', 0);
$get_agent_modules_json_for_multiple_agents = (bool)get_parameter(
"get_agent_modules_json_for_multiple_agents");
if ($get_agent_modules_json_for_multiple_agents) {
$idAgents = (array)get_parameter('id_agent');
$custom_condition = get_parameter('custom_condition', '');
$selection_mode = get_parameter('selection_mode', 'common');
$serialized = get_parameter('serialized', '');
$id_server = (int)get_parameter('id_server', 0);
$metaconsole_server_name = null;
$all = (string)get_parameter('all', 'all');
switch ($all) {
default:
case 'all':
$enabled = '1 = 1';
break;
case 'enabled':
$enabled = 'disabled = 0';
break;
}
$result = array();
if (defined("METACONSOLE")) {
$rows = db_get_all_rows_filter('tmetaconsole_agent',
array("id_tagente" => $idAgents),
array('id_agente', 'id_tmetaconsole_setup'));
$agents = array();
foreach ($rows as $row) {
$agents[$row['id_tmetaconsole_setup']][] =
$row['id_agente'];
}
foreach ($idAgents as $id_agent) {
$id_tmetaconsole_setup = db_get_value_filter(
'id_tmetaconsole_setup', 'tmetaconsole_agent',
array("id_tagente" => $idAgents));
if (metaconsole_connect(null, $id_tmetaconsole_setup) != NOERR) {
continue;
}
metaconsole_restore_db();
}
}
else {
$agents[0] = $idAgents;
}
$result = array();
foreach ($agents as $id_server => $agents) {
if ($id_server) {
if (metaconsole_connect(null, $id_server) != NOERR) {
continue;
}
}
$sql = 'SELECT DISTINCT(nombre)
FROM tagente_modulo t1
WHERE ' . $enabled .
io_safe_output($custom_condition) . '
AND delete_pending = 0
AND id_agente IN (' . implode(',', $idAgents) . ')';
if ($selection_mode == 'common') {
$sql .= ' AND (
SELECT count(nombre)
FROM tagente_modulo t2
WHERE delete_pending = 0 AND t1.nombre = t2.nombre
AND id_agente IN (' . implode(',', $idAgents) . ')) = (' . count($idAgents) . ')';
}
$sql .= ' ORDER BY nombre';
$nameModules = db_get_all_rows_sql($sql);
if ($nameModules == false) {
$nameModules = array();
}
$temp = array();
foreach ($nameModules as $nameModule) {
if (empty($serialized))
$temp[io_safe_output($nameModule['nombre'])] =
ui_print_truncate_text(
io_safe_output($nameModule['nombre']), 'module_medium', false, true);
else
$temp[io_safe_output($nameModule['nombre']).'$*$'.implode('|', $idAgents)] = ui_print_truncate_text(io_safe_output($nameModule['nombre']), 'module_medium', false, true);
}
if ($id_server) {
metaconsole_restore_db();
}
foreach ($temp as $i => $t) {
$result[$i] = $t;
}
}
echo json_encode($result);
return;
}
if ($get_plugin_macros) {
$id_plugin = get_parameter('id_plugin', 0);
@ -194,7 +86,7 @@ if ($get_module_detail) {
$agentId = (int) get_parameter("id_agent");
$server_name = (string) get_parameter('server_name');
if (defined ('METACONSOLE')) {
if (is_metaconsole()) {
$server = metaconsole_get_connection ($server_name);
if (metaconsole_connect($server) != NOERR)
@ -381,10 +273,15 @@ if ($get_module_detail) {
else {
// Just a string of alphanumerical data... just do print
//Fixed the data from Selenium Plugin
if ($row[$attr[0]] != strip_tags($row[$attr[0]]))
if ($row[$attr[0]] != strip_tags($row[$attr[0]])) {
$data[] = io_safe_input($row[$attr[0]]);
else
}
else if (is_numeric($row[$attr[0]])) {
$data[] = (double) $row[$attr[0]];
}
else {
$data[] = $row[$attr[0]];
}
}
}
@ -401,7 +298,7 @@ if ($get_module_detail) {
html_print_table($table);
}
if (defined ('METACONSOLE'))
if (is_metaconsole())
metaconsole_restore_db();
return;

@ -17,10 +17,16 @@
include_once($config['homedir'] . "/include/functions_io.php");
include_once($config['homedir'] . "/include/functions_db.php");
include_once($config['homedir'] . "/include/functions_modules.php");
include_once($config['homedir'] . "/include/functions_groups.php");
$get_modules_downtime = (bool)get_parameter('get_modules_downtime', 0);
$delete_module_from_downtime = (bool)get_parameter('delete_module_from_downtime', 0);
$add_module_into_downtime = (bool)get_parameter('add_module_into_downtime', 0);
ob_clean();
$get_modules_downtime = (bool)get_parameter('get_modules_downtime', 0);
$delete_module_from_downtime = (bool)get_parameter('delete_module_from_downtime', 0);
$add_module_into_downtime = (bool)get_parameter('add_module_into_downtime', 0);
// User groups with AW permission for ACL checks
$user_groups_aw = array_keys(users_get_groups($config['id_user'], 'AW'));
if ($get_modules_downtime) {
$return = array();
@ -28,38 +34,58 @@ if ($get_modules_downtime) {
$return['in_agent'] = array();
$return['in_downtime'] = array();
$id_agent = (int)get_parameter('id_agent', 0);
$id_downtime = (int)get_parameter('id_downtime', 0);
$none_value = (bool)get_parameter('none_value', false);
$id_agent = (int) get_parameter('id_agent', 0);
$id_downtime = (int) get_parameter('id_downtime', 0);
$none_value = (bool) get_parameter('none_value', false);
$rows = db_get_all_rows_filter('tplanned_downtime_modules',
array('id_agent' => $id_agent, 'id_downtime' => $id_downtime));
if (empty($rows))
$rows = array();
$id_modules_downtime = array();
foreach ($rows as $row) {
$id_modules_downtime[$row['id_agent_module']] = true;
// Check AW permission on downtime
$downtime_group = db_get_value('id_group', 'tplanned_downtime', 'id', $id_downtime);
if ($downtime_group === false || !in_array($downtime_group, $user_groups_aw)) {
$return['correct'] = 0;
echo json_encode($return);
return;
}
$modules = db_get_all_rows_filter('tagente_modulo', array('id_agente' => $id_agent));
// Check AW permission on agent
$agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $id_agent);
if ($agent_group === false || !in_array($agent_group, $user_groups_aw)) {
$return['correct'] = 0;
echo json_encode($return);
return;
}
$filter = array(
'id_agent' => $id_agent,
'id_downtime' => $id_downtime
);
$downtime_modules = db_get_all_rows_filter('tplanned_downtime_modules', $filter);
if (empty($downtime_modules))
$downtime_modules = array();
$downtime_module_ids = extract_column($downtime_modules, 'id_agent_module');
$downtime_modules = array_fill_keys($downtime_module_ids, true);
$filter = array(
'id_agente' => $id_agent
);
$modules = db_get_all_rows_filter('tagente_modulo', $filter);
if (empty($modules))
$modules = array();
foreach ($modules as $module) {
if (empty($id_modules_downtime[$module['id_agente_modulo']])) {
$return['in_agent'][$module['id_agente_modulo']] = io_safe_output($module['nombre']);
}
else {
$return['in_downtime'][$module['id_agente_modulo']] = io_safe_output($module['nombre']);
}
}
$module_ids = extract_column($modules, 'id_agente_modulo');
$module_names = extract_column($modules, 'nombre');
$modules = array_combine($module_ids, $module_names);
if ($none_value) {
$return['in_downtime'] = array_intersect_key($modules, $downtime_modules);
$return['in_agent'] = array_diff($modules, $return['in_downtime']);
if ($none_value)
$return['in_agent'][0] = __('None');
}
echo json_encode($return);
exit;
return;
}
if ($delete_module_from_downtime) {
@ -68,45 +94,65 @@ if ($delete_module_from_downtime) {
$return['all_modules'] = 0;
$return['id_agent'] = 0;
$id_module = (int)get_parameter('id_module', 0);
$id_downtime = (int)get_parameter('id_downtime', 0);
$id_module = (int) get_parameter('id_module', 0);
$id_downtime = (int) get_parameter('id_downtime', 0);
$id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $id_module);
$executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($executed) {
// Check AW permission on downtime
$downtime_group = db_get_value('id_group', 'tplanned_downtime', 'id', $id_downtime);
if ($downtime_group === false || !in_array($downtime_group, $user_groups_aw)) {
$return['correct'] = 0;
echo json_encode($return);
return;
}
// Check AW permission on agent
$agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $id_agent);
if ($id_agent === false || $agent_group === false || !in_array($agent_group, $user_groups_aw)) {
$return['correct'] = 0;
echo json_encode($return);
return;
}
$is_running = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($is_running) {
$return['executed'] = 1;
echo json_encode($return);
exit;
return;
}
$row = db_get_row_filter('tplanned_downtime_modules',
array('id_agent_module' => $id_module,
'id_downtime' => $id_downtime));
$return['id_agent'] = $row['id_agent'];
$result = db_process_sql_delete('tplanned_downtime_modules',
array('id_downtime' => $id_downtime,
'id_agent_module' => $id_module));
$return['id_agent'] = $id_agent;
$filter = array(
'id_agent_module' => $id_module,
'id_downtime' => $id_downtime
);
$result = db_process_sql_delete('tplanned_downtime_modules', $filter);
if ($result) {
$rows = db_get_all_rows_filter('tplanned_downtime_modules',
array('id_downtime' => $id_downtime,
'id_agent' => $row['id_agent']));
db_clean_cache();
$filter = array(
'id_agent' => $id_agent,
'id_downtime' => $id_downtime
);
$rows = db_get_all_rows_filter('tplanned_downtime_modules', $filter);
if (empty($rows)) {
db_process_sql_update('tplanned_downtime_agents',
array('all_modules' => 1),
array('id_agent' => $row['id_agent'],
'id_downtime' => $id_downtime));
$values = array('all_modules' => 1);
db_process_sql_update('tplanned_downtime_agents', $values, $filter);
$return['all_modules'] = 1;
$return['id_agent'] = $row['id_agent'];
$return['id_agent'] = $id_agent;
}
$return['correct'] = 1;
}
echo json_encode($return);
exit;
return;
}
if ($add_module_into_downtime) {
@ -114,15 +160,33 @@ if ($add_module_into_downtime) {
$return['correct'] = 0;
$return['name'] = '';
$id_agent = (int)get_parameter('id_agent', 0);
$id_module = (int)get_parameter('id_module', 0);
$id_downtime = (int)get_parameter('id_downtime', 0);
$id_agent = (int) get_parameter('id_agent', 0);
$id_module = (int) get_parameter('id_module', 0);
$id_downtime = (int) get_parameter('id_downtime', 0);
$executed = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($executed) {
// Check AW permission on downtime
$downtime_group = db_get_value('id_group', 'tplanned_downtime', 'id', $id_downtime);
if ($downtime_group === false || !in_array($downtime_group, $user_groups_aw)) {
$return['correct'] = 0;
echo json_encode($return);
return;
}
// Check AW permission on agent
$agent_group = db_get_value('id_grupo', 'tagente', 'id_agente', $id_agent);
if ($agent_group === false || !in_array($agent_group, $user_groups_aw)) {
$return['correct'] = 0;
echo json_encode($return);
return;
}
$is_running = db_get_value ('executed', 'tplanned_downtime', 'id', $id_downtime);
if ($is_running) {
$return['executed'] = 1;
echo json_encode($return);
exit;
return;
}
$values = array();
@ -144,7 +208,7 @@ if ($add_module_into_downtime) {
}
echo json_encode($return);
exit;
return;
}
?>

@ -22,7 +22,7 @@
/**
* Pandora build version and version
*/
$build_version = 'PC150715';
$build_version = 'PC150720';
$pandora_version = 'v6.0dev';
// Do not overwrite default timezone set if defined.

@ -43,7 +43,7 @@ function oracle_connect_db($host = null, $db = null, $user = null, $pass = null,
$datetime_tz_format = oci_parse($connect_id , 'alter session set NLS_TIMESTAMP_TZ_FORMAT =\'YYYY-MM-DD HH24:MI:SS\'');
$datetime_format = oci_parse($connect_id , 'alter session set NLS_TIMESTAMP_FORMAT =\'YYYY-MM-DD HH24:MI:SS\'');
$date_format = oci_parse($connect_id , 'alter session set NLS_DATE_FORMAT =\'YYYY-MM-DD HH24:MI:SS\'');
$decimal_separator = oci_parse($connect_id , 'alter session set NLS_NUMERIC_CHARACTERS =\',.\'');
$decimal_separator = oci_parse($connect_id , 'alter session set NLS_NUMERIC_CHARACTERS =\'.,\'');
oci_execute($datetime_tz_format);
oci_execute($datetime_format);

@ -2443,7 +2443,7 @@ function array2XML($data, $root = null, $xml = NULL) {
}
}
return html_entity_decode($xml->asXML());
return $xml->asXML();
}
/**
@ -2457,7 +2457,7 @@ function array2XML($data, $root = null, $xml = NULL) {
function extract_column ($array, $column) {
$column_is_arr = is_array($column);
return array_map(function($item) {
return array_map(function($item) use ($column_is_arr, $column) {
if ($column_is_arr) {
return array_reduce($column, function($carry, $col) use ($item) {
$carry[$col] = $item[$col];

@ -25,7 +25,7 @@ global $config;
/**
* Include the usual functions
*/
// require_once($config["homedir"] . "/include/functions.php");
require_once($config["homedir"] . "/include/functions_ui.php");
// enterprise_include_once('include/functions_inventory.php');
function planned_downtimes_check_dates ($type_execution = 'once', $type_periodicity = '', $datetime_from = false, $datetime_to = false, $periodically_time_from = false, $periodically_time_to = false, $periodically_day_from = false, $periodically_day_to = false) {
@ -518,4 +518,142 @@ function planned_downtimes_migrate_malformed_downtimes_copy_items ($original_dow
return $new_planned_downtimes_exists;
}
/**
* Stop a planned downtime.
*
* @param array Planned downtime data.
*
* @return mixes False on error or an array with the result and a message of the operation.
*/
function planned_downtimes_stop ($downtime) {
$result = false;
$message = '';
if (empty($downtime))
return false;
$id_downtime = $downtime['id'];
switch ($downtime['type_execution']) {
case 'once':
$values = array(
'executed' => 0,
'date_to' => time()
);
$result = db_process_sql_update('tplanned_downtime',
$values, array ('id' => $id_downtime));
break;
case 'periodically':
return false;
break;
}
$message .= ui_print_result_message($result,
__('Succesful stopped the Downtime'),
__('Unsuccesful stopped the Downtime'),
true);
if ($result) {
events_create_event ("Manual stop downtime ".
$downtime['name'] . " (" . $downtime['id'] . ") by " .
$config['id_user'], 0, 0, EVENT_STATUS_NEW, $config["id_user"],
"system", 1);
db_pandora_audit("Planned Downtime management",
"Manual stop downtime " . $downtime['name'] . " (ID " . $downtime['id'] . ")",
false, true);
//Reenabled the Agents or Modules or alerts...depends of type
switch ($downtime['type_downtime']) {
case 'quiet':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
if ($agent['all_modules']) {
$result = db_process_sql_update('tagente',
array('quiet' => 0),
array('id_agente' => $agent['id_agent']));
if ($result)
$count++;
}
else {
$modules = db_get_all_rows_filter(
'tplanned_downtime_modules',
array('id_agent' => $agent['id_agent'],
'id_downtime' => $id_downtime));
if (empty($modules))
$modules = array();
foreach ($modules as $module) {
$result = db_process_sql_update(
'tagente_modulo',
array('quiet' => 0),
array('id_agente_modulo' =>
$module['id_agent_module']));
if ($result)
$count++;
}
}
}
break;
case 'disable_agents':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
$result = db_process_sql_update('tagente',
array('disabled' => 0),
array('id_agente' => $agent['id_agent']));
if ($result)
$count++;
}
break;
case 'disable_agents_alerts':
$agents = db_get_all_rows_filter(
'tplanned_downtime_agents',
array('id_downtime' => $id_downtime));
if (empty($agents))
$agents = array();
$count = 0;
foreach ($agents as $agent) {
$modules = db_get_all_rows_filter(
'tagente_modulo',
array('id_agente' => $agent['id_agent']));
if (empty($modules))
$modules = array();
foreach ($modules as $module) {
$result = db_process_sql_update(
'talert_template_modules',
array('disabled' => 0),
array('id_agent_module' =>
$module['id_agente_modulo']));
if ($result)
$count++;
}
}
break;
}
$message .= ui_print_info_message(
sprintf(__('Enabled %s elements from the downtime'), $count), true);
}
return array('result' => $result, 'message' => $message);
}
?>

@ -25,59 +25,62 @@
* @param string $tag_name_description Name or description of the tag that it's currently searched.
* @param array $filter Array with pagination parameters.
* @param bool $only_names Whether to return only names or all fields.
* @param bool $count To return the number of items.
*
* @return mixed Returns an array with the tag selected by name or false.
* When the count parameter is enabled, returns an integer.
*/
function tags_search_tag ($tag_name_description = false, $filter = false, $only_names = false) {
function tags_search_tag ($tag_name_description = false, $filter = false, $only_names = false, $count = false) {
global $config;
if ($filter === false)
$filter = array();
if (isset($filter['name'])) {
if (empty($tag_name_description))
$tag_name_description = $filter['name'];
unset($filter['name']);
}
if ($tag_name_description) {
switch ($config["dbtype"]) {
case "mysql":
$sql = 'SELECT *
FROM ttag
WHERE ((name COLLATE utf8_general_ci LIKE "%'. $tag_name_description .'%") OR
(description COLLATE utf8_general_ci LIKE "%'. $tag_name_description .'%")) ORDER BY name';
$filter[] = '((name COLLATE utf8_general_ci LIKE "%'. $tag_name_description .'%") OR
(description COLLATE utf8_general_ci LIKE "%'. $tag_name_description .'%"))';
break;
case "postgresql":
$sql = 'SELECT *
FROM ttag
WHERE ((name COLLATE utf8_general_ci LIKE \'%'. $tag_name_description .'%\') OR
(description COLLATE utf8_general_ci LIKE \'%'. $tag_name_description .'%\')) ORDER BY name';
$filter[] = '((name LIKE \'%'. $tag_name_description .'%\') OR
(description LIKE \'%'. $tag_name_description .'%\'))';
break;
case "oracle":
$sql = 'SELECT *
FROM ttag
WHERE (UPPER(name) LIKE UPPER (\'%'. $tag_name_description .'%\') OR
UPPER(dbms_lob.substr(description, 4000, 1)) LIKE UPPER (\'%'. $tag_name_description .'%\')) ORDER BY name';
$filter[] = '(UPPER(name) LIKE UPPER (\'%'. $tag_name_description .'%\') OR
UPPER(dbms_lob.substr(description, 4000, 1)) LIKE UPPER (\'%'. $tag_name_description .'%\'))';
break;
}
}
else {
$sql = 'SELECT * FROM ttag ORDER BY name';
// Default order
set_unless_defined($filter['order'], 'name');
$fields = '*';
if ($only_names) {
$fields = array('id_tag', 'name');
}
if ($filter !== false) {
switch ($config["dbtype"]) {
case "mysql":
$result = db_get_all_rows_sql ($sql . ' LIMIT ' . $filter['offset'] . ',' . $filter['limit']);
break;
case "postgresql":
$result = db_get_all_rows_sql ($sql . ' OFFSET ' . $filter['offset'] . ' LIMIT ' . $filter['limit']);
break;
case "oracle":
$result = oracle_recode_query ($sql, $filter, 'AND', false);
if ($components != false) {
for ($i=0; $i < count($components); $i++) {
unset($result[$i]['rnum']);
}
}
break;
}
}
else {
$result = db_get_all_rows_sql ($sql);
// It will return the count
if ($count) {
unset($filter['order']);
unset($filter['limit']);
unset($filter['offset']);
if (!empty($filter))
return (int) db_get_value_filter('COUNT(id_tag)', 'ttag', $filter);
else
return (int) db_get_value('COUNT(id_tag)', 'ttag');
}
$result = db_get_all_rows_filter('ttag', $filter, $fields);
if ($result === false)
$result = array();
@ -172,11 +175,11 @@ function tags_get_url($id) {
*
* @param array $id Int with tag id info.
*
* @return mixed Int with the tag's count or false.
* @return int Tag's count.
*/
function tags_get_modules_count($id) {
$num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', array('id_tag' => $id));
$num_policy_modules = (int)db_get_value_filter('count(*)', 'ttag_policy_module', array('id_tag' => $id));
function tags_get_modules_count ($id) {
$num_modules = tags_get_local_modules_count($id);
$num_policy_modules = tags_get_policy_modules_count($id);
return $num_modules + $num_policy_modules;
}
@ -186,23 +189,29 @@ function tags_get_modules_count($id) {
*
* @param array $id Int with tag id info.
*
* @return mixed Int with the tag's count or false.
* @return int Local module tag's count.
*/
function tags_get_local_modules_count($id) {
$num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', array('id_tag' => $id));
function tags_get_local_modules_count ($id) {
$field = 'COUNT(id_tag)';
$filter = array('id_tag' => $id);
$num_modules = (int) db_get_value_filter($field, 'ttag_module', $filter);
return $num_modules;
}
/**
* Get tag's local module count.
* Get module tag's count.
*
* @param array $id Int with tag id info.
* @param array $id Int with agent module id info.
*
* @return mixed Int with the tag's count or false.
* @return int Module tag's count.
*/
function tags_get_modules_tag_count($id) {
$num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', array('id_agente_modulo' => $id));
function tags_get_modules_tag_count ($id) {
$field = 'COUNT(id_agente_modulo)';
$filter = array('id_agente_modulo' => $id);
$num_modules = (int) db_get_value_filter($field, 'ttag_module', $filter);
return $num_modules;
}
@ -212,16 +221,17 @@ function tags_get_modules_tag_count($id) {
*
* @param array $id Int with tag id info.
*
* @return mixed Int with the tag's count or false.
* @return int Policy module tag's count.
*/
function tags_get_policy_modules_count($id) {
$num_policy_modules = (int)db_get_value_filter('count(*)', 'ttag_policy_module', array('id_tag' => $id));
function tags_get_policy_modules_count ($id) {
$field = 'COUNT(id_tag)';
$filter = array('id_tag' => $id);
$num_policy_modules = (int) db_get_value_filter($field, 'ttag_policy_module', $filter);
return $num_policy_modules;
}
/**
* Updates a tag by id.
*
@ -278,8 +288,15 @@ function tags_remove_tag($id_tag, $id_module) {
*
* @return mixed Int with the tag's count.
*/
function tags_get_tag_count() {
return (int)db_get_value('count(*)', 'ttag');
function tags_get_tag_count($filter = false) {
$tag_name = false;
if (isset($filter['name'])) {
$tag_name = $filter['name'];
unset($filter['name']);
}
return tags_search_tag($tag_name, $filter, false, true);
}
/**

@ -1894,6 +1894,9 @@ function visual_map_get_user_layouts ($id_user = 0, $only_names = false, $filter
$groups = users_get_groups ($id_user, 'RR', false);
if (!empty($groups)) {
if (empty($where))
$where = "";
if ($where != '') {
$where .= ' AND ';
}

@ -201,7 +201,7 @@ function agent_changed_by_multiple_agents (event, id_agent, selected) {
jQuery.post (homedir + '/ajax.php',
{
"page": "include/ajax/module",
"page": "operation/agentes/ver_agente",
"get_agent_modules_json_for_multiple_agents": 1,
"id_agent[]": idAgents,
"all": find_modules,

@ -1507,10 +1507,10 @@ div#main_pure {
background-color: #fefefe;
text-align: left;
margin-bottom: 25px;
margin-top: 10px;
margin-top: 30px;
margin-left: 10px;
margin-right: 10px;
height: auto;
height: 1000px;
width: 98%;
position: static;
}
@ -2592,9 +2592,10 @@ div#agent_wizard_subtabs {
#container_servicemap_legend {
position: absolute;
width: 200px;
background: #F4F4F4;
background: #FFF;
margin-top: 10px;
right: 2px;
border: 1px solid #E2E2E2;
border-radius: 5px;
padding: 10px;
opacity: .90;

@ -63,7 +63,7 @@
<div style='height: 10px'>
<?php
$version = '6.0dev';
$build = '150715';
$build = '150720';
$banner = "v$version Build $build";
error_reporting(0);

@ -14,19 +14,20 @@
// GNU General Public License for more details.
// Global & session management
require_once ('../../include/config.php');
require_once ('../../include/auth/mysql.php');
if (! isset($_SESSION['id_usuario'])) {
session_start();
session_write_close();
//session_write_close();
}
require_once ('../../include/config.php');
require_once ($config['homedir'] . '/include/auth/mysql.php');
require_once ($config['homedir'] . '/include/functions.php');
require_once ($config['homedir'] . '/include/functions_db.php');
require_once ($config['homedir'] . '/include/functions_ui.php');
require_once ($config['homedir'] . '/include/functions_reporting.php');
require_once ($config['homedir'] . '/include/functions_graph.php');
require_once ($config['homedir'] . '/include/functions_modules.php');
require_once ($config['homedir'] . '/include/functions_agents.php');
require_once ($config['homedir'] . '/include/functions_tags.php');
check_login ();

@ -35,6 +35,7 @@ if (is_ajax ()) {
$get_agent_modules_json = (bool) get_parameter ('get_agent_modules_json');
$get_agent_status_tooltip = (bool) get_parameter ("get_agent_status_tooltip");
$get_agents_group_json = (bool) get_parameter ("get_agents_group_json");
$get_agent_modules_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_json_for_multiple_agents");
$get_agent_modules_alerts_json_for_multiple_agents = (bool) get_parameter("get_agent_modules_alerts_json_for_multiple_agents");
$get_agents_json_for_multiple_modules = (bool) get_parameter("get_agents_json_for_multiple_modules");
$get_agent_modules_json_for_multiple_agents_id = (bool) get_parameter("get_agent_modules_json_for_multiple_agents_id");
@ -171,6 +172,219 @@ if (is_ajax ()) {
return;
}
if ($get_agent_modules_alerts_json_for_multiple_agents) {
$idAgents = get_parameter('id_agent');
$id_template = get_parameter('template');
$selection_mode = get_parameter('selection_mode','common');
$sql = 'SELECT DISTINCT(nombre)
FROM tagente_modulo t1, talert_template_modules t2
WHERE t2.id_agent_module = t1.id_agente_modulo
AND delete_pending = 0
AND id_alert_template = '.$id_template.'
AND id_agente IN (' . implode(',', $idAgents) . ')';
if ($selection_mode == 'common') {
$sql .= ' AND (
SELECT count(nombre)
FROM tagente_modulo t3, talert_template_modules t4
WHERE t4.id_agent_module = t3.id_agente_modulo
AND delete_pending = 0 AND t1.nombre = t3.nombre
AND id_agente IN (' . implode(',', $idAgents) . ')
AND id_alert_template = '.$id_template.') = (' . count($idAgents) . ')';
}
$sql .= ' ORDER BY t1.nombre';
$nameModules = db_get_all_rows_sql($sql);
if ($nameModules == false) {
$nameModules = array();
}
$result = array();
foreach($nameModules as $nameModule) {
$result[] = io_safe_output($nameModule['nombre']);
}
echo json_encode($result);
return;
}
if ($get_agent_modules_json_for_multiple_agents) {
$idAgents = get_parameter('id_agent');
$custom_condition = get_parameter('custom_condition', '');
$selection_mode = get_parameter('selection_mode', 'common');
$serialized = get_parameter('serialized', '');
$id_server = (int) get_parameter('id_server', 0);
$metaconsole_server_name = null;
if ($id_server != 0) {
$metaconsole_server_name = db_get_value('server_name',
'tmetaconsole_setup', 'id', $id_server);
}
$all = (string)get_parameter('all', 'all');
switch ($all) {
default:
case 'all':
$enabled = '1 = 1';
break;
case 'enabled':
$enabled = 'disabled = 0';
break;
}
if (is_metaconsole()) {
$result = array();
$nameModules = array();
$temp = array();
$first = true;
$temp_element = array();
$counter = 0;
$first_elements = array();
$array_mapped = array_map(function($item) use ($metaconsole_server_name) {
if (empty($metaconsole_server_name)) {
if (strstr($item, "|@_@|")) {
$row = explode ('|@_@|', $item);
}
else {
$row = explode ('|', $item);
}
$server_name = array_shift($row);
$id_agent = array_shift($row);
}
else {
$server_name = $metaconsole_server_name;
$id_agent = $item;
}
return array(
'server_name' => $server_name,
'id_agent' => $id_agent
);
}, $idAgents);
$array_reduced = array_reduce($array_mapped, function($carry, $item) {
if (!isset($carry[$item['server_name']]))
$carry[$item['server_name']] = array();
$carry[$item['server_name']][] = $item['id_agent'];
return $carry;
}, array());
$last_modules_set = array();
foreach ($array_reduced as $server_name => $id_agents) {
//Metaconsole db connection
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) != NOERR) {
continue;
}
//Get agent's modules
$sql = sprintf('SELECT t1.id_agente, t1.id_agente_modulo, t1.nombre
FROM tagente_modulo t1
WHERE %s
AND t1.delete_pending = 0
AND t1.id_agente IN (%s)
AND (
SELECT COUNT(nombre)
FROM tagente_modulo t2
WHERE t2.delete_pending = 0
AND t1.nombre = t2.nombre
AND t2.id_agente IN (%s)) = (%d)',
$enabled, implode(',', $id_agents),
implode(',', $id_agents), count($id_agents));
$modules = db_get_all_rows_sql($sql);
if (empty($modules))
$modules = array();
$modules_aux = array();
foreach ($modules as $key => $module) {
// Don't change this order, is used in the serialization
$module_data = array(
'id_module' => $module['id_agente_modulo'],
'id_agent' => $module['id_agente'],
'server_name' => $server_name
);
if (!isset($modules_aux[$module['nombre']]))
$modules_aux[$module['nombre']] = array();
$modules_aux[$module['nombre']][] = $module_data;
}
$modules = $modules_aux;
// Build the next array using the common values
if (!empty($last_modules_set)) {
$modules = array_intersect_key($modules, $last_modules_set);
array_walk($modules, function(&$module_data, $module_name) use ($last_modules_set) {
$module_data = array_merge($module_data, $last_modules_set[$module_name]);
});
}
$last_modules_set = $modules;
//Restore db connection
metaconsole_restore_db();
}
$result = array();
foreach ($last_modules_set as $module_name => $module_data) {
$value = ui_print_truncate_text(io_safe_output($module_name), 'module_medium', false, true);
$module_data_processed = array_map(function($item) {
// data: -> id_module | id_agent | server_name;
return implode('|', $item);
}, $module_data);
$key = implode(';', $module_data_processed);
$result[$key] = $value;
}
}
else {
$sql = 'SELECT DISTINCT(nombre)
FROM tagente_modulo t1
WHERE ' . $enabled .
io_safe_output($custom_condition) . '
AND delete_pending = 0
AND id_agente IN (' . implode(',', $idAgents) . ')';
if ($selection_mode == 'common') {
$sql .= ' AND (
SELECT count(nombre)
FROM tagente_modulo t2
WHERE delete_pending = 0 AND t1.nombre = t2.nombre
AND id_agente IN (' . implode(',', $idAgents) . ')) = (' . count($idAgents) . ')';
}
$sql .= ' ORDER BY nombre';
$nameModules = db_get_all_rows_sql($sql);
if ($nameModules == false) {
$nameModules = array();
}
$result = array();
foreach ($nameModules as $nameModule) {
if (empty($serialized))
$result[io_safe_output($nameModule['nombre'])] =
ui_print_truncate_text(
io_safe_output($nameModule['nombre']), 'module_medium', false, true);
else
$result[io_safe_output($nameModule['nombre']).'$*$'.implode('|', $idAgents)] = ui_print_truncate_text(io_safe_output($nameModule['nombre']), 'module_medium', false, true);
}
}
echo json_encode($result);
return;
}
if ($get_agent_modules_json) {
$id_agent = (int) get_parameter ('id_agent');

@ -271,10 +271,5 @@ ui_require_javascript_file ('pandora_visual_console');
?>
});
$(window).load(function() {
if (typeof(lines) != 'undefined') {
draw_lines (lines, 'layout_map');
}
});
/* ]]> */
</script>

@ -3,7 +3,7 @@
#
%define name pandorafms_console
%define version 6.0dev
%define release 150715
%define release 150720
# User and Group under which Apache is running
%define httpd_name httpd

@ -3,7 +3,7 @@
#
%define name pandorafms_console
%define version 6.0dev
%define release 150715
%define release 150720
%define httpd_name httpd
# User and Group under which Apache is running
%define httpd_name apache2

@ -38,7 +38,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
('graph_res','5'),
('step_compact','1'),
('db_scheme_version','6.0dev'),
('db_scheme_build','PD150715'),
('db_scheme_build','PD150720'),
('show_unknown','0'),
('show_lastalerts','1'),
('style','pandora'),

@ -1,5 +1,5 @@
package: pandorafms-server
Version: 6.0dev-150715
Version: 6.0dev-150720
Architecture: all
Priority: optional
Section: admin

@ -14,7 +14,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
pandora_version="6.0dev-150715"
pandora_version="6.0dev-150720"
package_cpan=0
package_pandora=1

@ -43,7 +43,7 @@ our @EXPORT = qw(
# version: Defines actual version of Pandora Server for this module only
my $pandora_version = "6.0dev";
my $pandora_build = "150715";
my $pandora_build = "150720";
our $VERSION = $pandora_version." ".$pandora_build;
# Setup hash

@ -3,7 +3,7 @@
#
%define name pandorafms_server
%define version 6.0dev
%define release 150715
%define release 150720
Summary: Pandora FMS Server
Name: %{name}

@ -3,7 +3,7 @@
#
%define name pandorafms_server
%define version 6.0dev
%define release 150715
%define release 150720
Summary: Pandora FMS Server
Name: %{name}

@ -33,7 +33,7 @@ use PandoraFMS::Tools;
use PandoraFMS::DB;
# version: define current version
my $version = "6.0dev PS150715";
my $version = "6.0dev PS150720";
# Pandora server configuration
my %conf;

@ -35,7 +35,7 @@ use Encode::Locale;
Encode::Locale::decode_argv;
# version: define current version
my $version = "6.0dev PS150715";
my $version = "6.0dev PS150720";
# save program name for logging
my $progname = basename($0);