Merge branch 'release-1.34'
This commit is contained in:
commit
b482993d33
13
README.md
13
README.md
|
@ -22,12 +22,6 @@ https://github.com/ZoneMinder/zmdockerfiles
|
|||
|
||||
## Installation Methods
|
||||
|
||||
### Building from Source is Discouraged
|
||||
|
||||
Historically, installing ZoneMinder onto your system required building from source code by issuing the traditional configure, make, make install commands. To get ZoneMinder to build, all of its dependencies had to be determined and installed beforehand. Init and logrotate scripts had to be manually copied into place following the build. Optional packages such as jscalendar and Cambozola had to be manually installed. Uninstalls could leave stale files around, which could cause problems during an upgrade. Speaking of upgrades, when it comes time to upgrade all these manual steps must be repeated again.
|
||||
|
||||
Better methods exist today that do much of this for you. The current development team, along with other volunteers, have taken great strides in providing the resources necessary to avoid building from source.
|
||||
|
||||
### Install from a Package Repository
|
||||
|
||||
This is the recommended method to install ZoneMinder onto your system. ZoneMinder packages are maintained for the following distros:
|
||||
|
@ -43,6 +37,13 @@ This is the recommended method to install ZoneMinder onto your system. ZoneMinde
|
|||
|
||||
If a repository that hosts ZoneMinder packages is not available for your distro, then you are encouraged to build your own package, rather than build from source. While each distro is different in ways that set it apart from all the others, they are often similar enough to allow you to adapt another distro's package building instructions to your own.
|
||||
|
||||
### Building from Source is Discouraged
|
||||
|
||||
Historically, installing ZoneMinder onto your system required building from source code by issuing the traditional configure, make, make install commands. To get ZoneMinder to build, all of its dependencies had to be determined and installed beforehand. Init and logrotate scripts had to be manually copied into place following the build. Optional packages such as jscalendar and Cambozola had to be manually installed. Uninstalls could leave stale files around, which could cause problems during an upgrade. Speaking of upgrades, when it comes time to upgrade all these manual steps must be repeated again.
|
||||
|
||||
Better methods exist today that do much of this for you. The current development team, along with other volunteers, have taken great strides in providing the resources necessary to avoid building from source.
|
||||
|
||||
|
||||
### Building a ZoneMinder Package ###
|
||||
|
||||
Building ZoneMinder into a package is not any harder than building from source. As a matter of fact, if you have successfully built ZoneMinder from source in the past, then you may find these steps to be easier.
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
--
|
||||
-- This updates a 1.34.5 database to 1.34.6
|
||||
--
|
||||
-- No changes required
|
||||
--
|
|
@ -14,13 +14,13 @@ LANG_DEFAULT - ZoneMinder allows the web interface to use languages other than E
|
|||
|
||||
OPT_USE_AUTH - ZoneMinder can run in two modes. The simplest is an entirely unauthenticated mode where anyone can access ZoneMinder and perform all tasks. This is most suitable for installations where the web server access is limited in other ways. The other mode enables user accounts with varying sets of permissions. Users must login or authenticate to access ZoneMinder and are limited by their defined permissions. Authenticated mode alone should not be relied up for securing Internet connected ZoneMinder.
|
||||
|
||||
AUTH_TYPE - ZoneMinder can use two methods to authenticate users when running in authenticated mode. The first is a builtin method where ZoneMinder provides facilities for users to log in and maintains track of their identity. The second method allows interworking with other methods such as http basic authentication which passes an independently authentication 'remote' user via http. In this case ZoneMinder would use the supplied user without additional authentication provided such a user is configured ion ZoneMinder.
|
||||
AUTH_TYPE - ZoneMinder can use two methods to authenticate users when running in authenticated mode. The first is a builtin method where ZoneMinder provides facilities for users to log in and maintains track of their identity. The second method allows interworking with other methods such as http basic authentication which passes an independently authenticated 'remote' user via http. In this case ZoneMinder would use the supplied user without additional authentication provided such a user is configured in ZoneMinder.
|
||||
|
||||
AUTH_RELAY - When ZoneMinder is running in authenticated mode it can pass user details between the web pages and the back end processes. There are two methods for doing this. This first is to use a time limited hashed string which contains no direct username or password details, the second method is to pass the username and passwords around in plaintext. This method is not recommend except where you do not have the md5 libraries available on your system or you have a completely isolated system with no external access. You can also switch off authentication relaying if your system is isolated in other ways.
|
||||
|
||||
AUTH_HASH_SECRET - When ZoneMinder is running in hashed authenticated mode it is necessary to generate hashed strings containing encrypted sensitive information such as usernames and password. Although these string are reasonably secure the addition of a random secret increases security substantially. Note that if you are using the new token based APIs, then this field is mandatory with ZM 1.34 and above
|
||||
AUTH_HASH_SECRET - When ZoneMinder is running in hashed authenticated mode it is necessary to generate hashed strings containing encrypted sensitive information such as usernames and passwords. Although these strings are reasonably secure the addition of a random secret increases security substantially. Note that if you are using the new token based APIs, then this field is mandatory with ZM 1.34 and above.
|
||||
|
||||
AUTH_HASH_IPS - When ZoneMinder is running in hashed authenticated mode it can optionally include the requesting IP address in the resultant hash. This adds an extra level of security as only requests from that address may use that authentication key. However in some circumstances, such as access over mobile networks, the requesting address can change for each request which will cause most requests to fail. This option allows you to control whether IP addresses are included in the authentication hash on your system. If you experience intermitent problems with authentication, switching this option off may help. It is recommended you keep this off if you use mobile apps like zmNinja over mobile carrier networks - several APNs change the IP very frequently which may result in authentication failure.
|
||||
AUTH_HASH_IPS - When ZoneMinder is running in hashed authenticated mode it can optionally include the requesting IP address in the resultant hash. This adds an extra level of security as only requests from that address may use that authentication key. However in some circumstances, such as access over mobile networks, the requesting address can change for each request which will cause most requests to fail. This option allows you to control whether IP addresses are included in the authentication hash on your system. If you experience intermitent problems with authentication, switching this option off may help. It is recommended you keep this off if you use mobile apps like zmNinja over mobile carrier networks - several APNs change the IP very frequently which may result in authentication failures.
|
||||
|
||||
AUTH_HASH_TTL - Time before ZM auth will expire (does not apply to API tokens). The default has traditionally been 2 hours. A new hash will automatically be regenerated at half this value.
|
||||
|
||||
|
@ -34,11 +34,11 @@ OPT_USE_API - A global setting to enable/disable ZoneMinder APIs. If you are usi
|
|||
|
||||
OPT_USE_LEGACY_AUTH - Starting version 1.34.0, ZoneMinder uses a more secure Authentication mechanism using JWT tokens. Older versions used a less secure MD5 based auth hash. It is recommended you turn this off after you are sure you don't need it. If you are using a 3rd party app that relies on the older API auth mechanisms, you will have to update that app if you turn this off. Note that zmNinja 1.3.057 onwards supports the new token system.
|
||||
|
||||
OPT_USE_EVENT_NOTIFICATION - zmeventnotification is a 3rd party event notification server that is used to get notifications for alarms detected by ZoneMinder in real time. zmNinja requires this server for push notifications to mobile phones. This option only enables the server if its already installed. Please visit the `Event Notification Server project site <https://github.com/pliablepixels/zmeventserver>`__ for installation instructions.
|
||||
OPT_USE_EVENT_NOTIFICATION - zmeventnotification is a 3rd party event notification server that is used to get notifications for alarms detected by ZoneMinder in real time. zmNinja requires this server for push notifications to mobile phones. This option only enables the server if it is already installed. Please visit the `Event Notification Server project site <https://github.com/pliablepixels/zmeventserver>`__ for installation instructions.
|
||||
|
||||
OPT_USE_GOOG_RECAPTCHA - This option allows you to include a google reCaptcha validation at login. This means in addition to providing a valid usernane and password, you will also have to pass the reCaptcha test. Please note that enabling this option results in the zoneminder login page reach out to google servers for captcha validation. Also please note that enabling this option may break 3rd party clients if they rely on web based logins (Note that zmNinja now uses the API based token method and will not be affected if reCAPTCHA is enabled). If you enable this, you also need to specify your site and secret key (please refer to context help in the ZoneMinder system screen)
|
||||
OPT_USE_GOOG_RECAPTCHA - This option allows you to include a google reCaptcha validation at login. This means in addition to providing a valid username and password, you will also have to pass the reCaptcha test. Please note that enabling this option results in the zoneminder login page reaching out to google servers for captcha validation. Also please note that enabling this option may break 3rd party clients if they rely on web based logins (Note that zmNinja now uses the API based token method and will not be affected if reCAPTCHA is enabled). If you enable this, you also need to specify your site and secret key (please refer to context help in the ZoneMinder system screen).
|
||||
|
||||
SYSTEM_SHUTDOWN - this option decides if it is allowed to shutdown the full system via the ZM UI. The system will need to have sudo installed and the following added to /etc/sudoers:
|
||||
SYSTEM_SHUTDOWN - this option puts a poweroff icon in the header of the ZM UI for users with System privilege accessi. This icon will allow the user to shutdown the full system via the ZM UI. The system will need to have sudo installed and the following added to /etc/sudoers:
|
||||
|
||||
::
|
||||
|
||||
|
@ -46,9 +46,9 @@ SYSTEM_SHUTDOWN - this option decides if it is allowed to shutdown the full syst
|
|||
|
||||
to perform the shutdown or reboot
|
||||
|
||||
OPT_FAST_DELETE - Normally an event created as the result of an alarm consists of entries in one or more database tables plus the various files associated with it. When deleting events in the browser it can take a long time to remove all of this if your are trying to do a lot of events at once. **NOTE**: It is recommended that you keep this option OFF, unless you are running on an old or low-powered system.
|
||||
OPT_FAST_DELETE - Normally an event created as the result of an alarm consists of entries in one or more database tables plus the various files associated with it. When deleting events in the browser it can take a long time to remove all of this if youxr are trying to do a lot of events at once. **NOTE**: It is recommended that you keep this option OFF, unless you are running on an old or low-powered system.
|
||||
|
||||
FILTER_RELOAD_DELAY - ZoneMinder allows you to save filters to the database which allow events that match certain criteria to be emailed, deleted or uploaded to a remote machine etc. The zmfilter daemon loads these and does the actual operation. This option determines how often in seconds the filters are reloaded from the database to get the latest versions or new filters. If you don't change filters very often this value can be set to a large value.
|
||||
FILTER_RELOAD_DELAY - ZoneMinder allows you to save filters to the database which allow events that match certain criteria to be emailed, deleted or uploaded to a remote machine etc. The zmfilter daemon loads these and does the actual operation. This option determines how often in seconds the filters are reloaded from the database to get the latest versions or new filters. If you don't change filters very often this value can be set to a large value. As of 1.34.0 filters should be automatically reloaded when saving a filter so this setting should have little effect.
|
||||
|
||||
FILTER_EXECUTE_INTERVAL - ZoneMinder allows you to save filters to the database which allow events that match certain criteria to be emailed, deleted or uploaded to a remote machine etc. The zmfilter daemon loads these and does the actual operation. This option determines how often the filters are executed on the saved event in the database. If you want a rapid response to new events this should be a smaller value, however this may increase the overall load on the system and affect performance of other elements.
|
||||
|
||||
|
@ -58,9 +58,9 @@ STATUS_UPDATE_INTERVAL - The zmstats daemon performs various db queries related
|
|||
|
||||
WATCH_CHECK_INTERVAL - The zmwatch daemon checks the image capture performance of the capture daemons to ensure that they have not locked up (rarely a sync error may occur which blocks indefinitely). This option determines how often the daemons are checked.
|
||||
|
||||
WATCH_MAX_DELAY - The zmwatch daemon checks the image capture performance of the capture daemons to ensure that they have not locked up (rarely a sync error may occur which blocks indefinitely). This option determines the maximum delay to allow since the last captured frame. The daemon will be restarted if it has not captured any images after this period though the actual restart may take slightly longer in conjunction with the check interval value above.
|
||||
WATCH_MAX_DELAY - The zmwatch daemon checks the image capture performance of the capture daemons to ensure that they have not locked up (rarely a sync error may occur which blocks indefinitely). This option determines the maximum delay to allow since the last captured frame. The daemon will be restarted if it has not captured any images after this period though the actual restart may take slightly longer in conjunction with the check interval value above. Please note that some cameras can take up to 30 seconds to get a valid image, so this setting should be larger than that.
|
||||
|
||||
RUN_AUDIT - The zmaudit daemon exists to check that the saved information in the database and on the filesystem match and are consistent with each other. If an error occurs or if you are using 'fast deletes' it may be that database records are deleted but files remain. In this case, and similar, zmaudit will remove redundant information to synchronise the two data stores. This option controls whether zmaudit is run in the background and performs these checks and fixes continuously. It is recommended you keep this **OFF** in most systems.
|
||||
RUN_AUDIT - The zmaudit daemon exists to check that the saved information in the database and on the filesystem match and are consistent with each other. If an error occurs or if you are using 'fast deletes' it may be that database records are deleted but files remain. In this case, and similar, zmaudit will remove redundant information to synchronise the two data stores. This option controls whether zmaudit is run in the background and performs these checks and fixes continuously. It is recommended you keep this **OFF** in most systems and run it manually if needed after a system crash.
|
||||
|
||||
AUDIT_CHECK_INTERVAL - The zmaudit daemon exists to check that the saved information in the database and on the filesystem match and are consistent with each other. If an error occurs or if you are using 'fast deletes' it may be that database records are deleted but files remain. In this case, and similar, zmaudit will remove redundant information to synchronise the two data stores. The default check interval of 900 seconds (15 minutes) is fine for most systems however if you have a very large number of events the process of scanning the database and filesystem may take a long time and impact performance. In this case you may prefer to make this interval much larger to reduce the impact on your system. This option determines how often these checks are performed.
|
||||
|
||||
|
@ -70,11 +70,11 @@ OPT_CONTROL - ZoneMinder includes limited support for controllable cameras. A nu
|
|||
|
||||
OPT_TRIGGERS - ZoneMinder can interact with external systems which prompt or cancel alarms. This is done via the zmtrigger.pl script. This option indicates whether you want to use these external triggers. Most people will say no here.
|
||||
|
||||
CHECK_FOR_UPDATES - From ZoneMinder version 1.17.0 onwards new versions are expected to be more frequent. To save checking manually for each new version ZoneMinder can check with the zoneminder.com website to determine the most recent release. These checks are infrequent, about once per week, and no personal or system information is transmitted other than your current version number. If you do not wish these checks to take place or your ZoneMinder system has no internet access you can switch these check off with this configuration variable
|
||||
CHECK_FOR_UPDATES - To save checking manually for each new version ZoneMinder can check with the zoneminder.com website to determine the most recent release. These checks are infrequent, about once per week, and no personal or system information is transmitted other than your current version number. If you do not wish these checks to take place or your ZoneMinder system has no internet access you can switch these check off with this configuration variable.
|
||||
|
||||
TELEMETRY_DATA - Enable collection of usage information of the local system and send it to the ZoneMinder development team. This data will be used to determine things like who and where our customers are, how big their systems are, the underlying hardware and operating system, etc. This is being done for the sole purpose of creating a better product for our target audience. This script is intended to be completely transparent to the end user, and can be disabled from the web console under Options. For more details on what information we collect, please refer to Zoneminder's privacy statement (available in the contextual help of TELEMETRY_DATA on your installation).
|
||||
|
||||
UPDATE_CHECK_PROXY - If you use a proxy to access the internet then ZoneMinder needs to know so it can access zoneminder.com to check for updates. If you do use a proxy enter the full proxy url here in the form of ``http://<proxy host>:<proxy port>/``
|
||||
UPDATE_CHECK_PROXY - If you use a proxy to access the internet then ZoneMinder needs to know so it can access zoneminder.com to check for updates. If you do use a proxy enter the full proxy url here in the form of ``http://<proxy host>:<proxy port>/``.
|
||||
|
||||
SHM_KEY - ZoneMinder uses shared memory to speed up communication between modules. To identify the right area to use shared memory keys are used. This option controls what the base key is, each monitor will have it's Id or'ed with this to get the actual key used. You will not normally need to change this value unless it clashes with another instance of ZoneMinder on the same machine. Only the first four hex digits are used, the lower four will be masked out and ignored.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
function getDateScale( $scales, $range, $minLines, $maxLines ) {
|
||||
function getDateScale($scales, $range, $minLines, $maxLines) {
|
||||
foreach ( $scales as $scale ) {
|
||||
$align = isset($scale['align'])?$scale['align']:1;
|
||||
$scaleRange = (int)($range/($scale['factor']*$align));
|
||||
|
@ -18,10 +18,10 @@ function getDateScale( $scales, $range, $minLines, $maxLines ) {
|
|||
$scale['divisor']++;
|
||||
}
|
||||
$scale['lines'] = (int)($scale['range']/$scale['divisor']);
|
||||
return( $scale );
|
||||
return $scale;
|
||||
}
|
||||
|
||||
function getYScale( $range, $minLines, $maxLines ) {
|
||||
function getYScale($range, $minLines, $maxLines) {
|
||||
$scale['range'] = $range;
|
||||
$scale['divisor'] = 1;
|
||||
while ( $scale['range']/$scale['divisor'] > $maxLines ) {
|
||||
|
@ -29,20 +29,21 @@ function getYScale( $range, $minLines, $maxLines ) {
|
|||
}
|
||||
$scale['lines'] = (int)(($scale['range']-1)/$scale['divisor'])+1;
|
||||
|
||||
return( $scale );
|
||||
return $scale;
|
||||
}
|
||||
|
||||
function getSlotFrame( $slot ) {
|
||||
function getSlotFrame($slot) {
|
||||
$slotFrame = isset($slot['frame'])?$slot['frame']['FrameId']:1;
|
||||
# FIXME what's with this false?
|
||||
if ( false && $slotFrame ) {
|
||||
$slotFrame -= $monitor['PreEventCount'];
|
||||
if ( $slotFrame < 1 )
|
||||
$slotFrame = 1;
|
||||
}
|
||||
return( $slotFrame );
|
||||
return $slotFrame;
|
||||
}
|
||||
|
||||
function parseFilterToTree( $filter ) {
|
||||
function parseFilterToTree($filter) {
|
||||
if ( count($filter['terms']) <= 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -68,73 +69,82 @@ function parseFilterToTree( $filter ) {
|
|||
'or' => 4,
|
||||
);
|
||||
|
||||
for ( $i = 0; $i <= count($terms); $i++ ) {
|
||||
if ( !empty($terms[$i]['cnj']) ) {
|
||||
for ( $i = 0; $i < count($terms); $i++ ) {
|
||||
$term = $terms[$i];
|
||||
if ( !empty($term['cnj']) ) {
|
||||
while( true ) {
|
||||
if ( !count($postfixStack) ) {
|
||||
$postfixStack[] = array('type'=>'cnj', 'value'=>$terms[$i]['cnj'], 'sqlValue'=>$terms[$i]['cnj']);
|
||||
$postfixStack[] = array('type'=>'cnj', 'value'=>$term['cnj'], 'sqlValue'=>$term['cnj']);
|
||||
break;
|
||||
} elseif ( $postfixStack[count($postfixStack)-1]['type'] == 'obr' ) {
|
||||
$postfixStack[] = array('type'=>'cnj', 'value'=>$terms[$i]['cnj'], 'sqlValue'=>$terms[$i]['cnj']);
|
||||
$postfixStack[] = array('type'=>'cnj', 'value'=>$term['cnj'], 'sqlValue'=>$term['cnj']);
|
||||
break;
|
||||
} elseif ( $priorities[$terms[$i]['cnj']] < $priorities[$postfixStack[count($postfixStack)-1]['value']] ) {
|
||||
$postfixStack[] = array('type'=>'cnj', 'value'=>$terms[$i]['cnj'], 'sqlValue'=>$terms[$i]['cnj']);
|
||||
} elseif ( $priorities[$term['cnj']] < $priorities[$postfixStack[count($postfixStack)-1]['value']] ) {
|
||||
$postfixStack[] = array('type'=>'cnj', 'value'=>$term['cnj'], 'sqlValue'=>$term['cnj']);
|
||||
break;
|
||||
} else {
|
||||
$postfixExpr[] = array_pop($postfixStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !empty($terms[$i]['obr']) ) {
|
||||
for ( $j = 0; $j < $terms[$i]['obr']; $j++ ) {
|
||||
$postfixStack[] = array('type'=>'obr', 'value'=>$terms[$i]['obr']);
|
||||
} # end if ! empty cnj
|
||||
|
||||
if ( !empty($term['obr']) ) {
|
||||
for ( $j = 0; $j < $term['obr']; $j++ ) {
|
||||
$postfixStack[] = array('type'=>'obr', 'value'=>$term['obr']);
|
||||
}
|
||||
}
|
||||
if ( !empty($terms[$i]['attr']) ) {
|
||||
if ( !empty($term['attr']) ) {
|
||||
$dtAttr = false;
|
||||
switch ( $terms[$i]['attr']) {
|
||||
switch ( $term['attr']) {
|
||||
case 'MonitorName':
|
||||
$sqlValue = 'M.'.preg_replace( '/^Monitor/', '', $terms[$i]['attr']);
|
||||
$sqlValue = 'M.'.preg_replace( '/^Monitor/', '', $term['attr']);
|
||||
break;
|
||||
case 'ServerId':
|
||||
$sqlValue .= 'M.ServerId';
|
||||
break;
|
||||
break;
|
||||
case 'StorageServerId':
|
||||
$sqlValue .= 'S.ServerId';
|
||||
break;
|
||||
case 'FilterServerId':
|
||||
$sqlValue .= ZM_SERVER_ID;
|
||||
break;
|
||||
case 'DateTime':
|
||||
case 'StartDateTime':
|
||||
$sqlValue = "E.StartTime";
|
||||
$sqlValue = 'E.StartTime';
|
||||
$dtAttr = true;
|
||||
break;
|
||||
case 'Date':
|
||||
case 'StartDate':
|
||||
$sqlValue = "to_days( E.StartTime )";
|
||||
$sqlValue = 'to_days(E.StartTime)';
|
||||
$dtAttr = true;
|
||||
break;
|
||||
case 'Time':
|
||||
case 'StartTime':
|
||||
$sqlValue = "extract( hour_second from E.StartTime )";
|
||||
$sqlValue = 'extract(hour_second from E.StartTime)';
|
||||
break;
|
||||
case 'Weekday':
|
||||
case 'StartWeekday':
|
||||
$sqlValue = "weekday( E.StartTime )";
|
||||
$sqlValue = 'weekday(E.StartTime)';
|
||||
break;
|
||||
case 'EndDateTime':
|
||||
$sqlValue = "E.EndTime";
|
||||
$sqlValue = 'E.EndTime';
|
||||
$dtAttr = true;
|
||||
break;
|
||||
case 'EndDate':
|
||||
$sqlValue = "to_days( E.EndTime )";
|
||||
$sqlValue = 'to_days(E.EndTime)';
|
||||
$dtAttr = true;
|
||||
break;
|
||||
case 'EndTime':
|
||||
$sqlValue = "extract( hour_second from E.EndTime )";
|
||||
$sqlValue = 'extract(hour_second from E.EndTime)';
|
||||
break;
|
||||
case 'EndWeekday':
|
||||
$sqlValue = "weekday( E.EndTime )";
|
||||
$sqlValue = 'weekday(E.EndTime)';
|
||||
break;
|
||||
case 'Id':
|
||||
case 'Name':
|
||||
case 'MonitorId':
|
||||
case 'StorageId':
|
||||
case 'SecondaryStorageId':
|
||||
case 'Length':
|
||||
case 'Frames':
|
||||
case 'AlarmFrames':
|
||||
|
@ -145,7 +155,7 @@ function parseFilterToTree( $filter ) {
|
|||
case 'Notes':
|
||||
case 'StateId':
|
||||
case 'Archived':
|
||||
$sqlValue = "E.".$terms[$i]['attr'];
|
||||
$sqlValue = 'E.'.$term['attr'];
|
||||
break;
|
||||
case 'DiskPercent':
|
||||
// Need to specify a storage area, so need to look through other terms looking for a storage area, else we default to ZM_EVENTS_PATH
|
||||
|
@ -174,53 +184,66 @@ function parseFilterToTree( $filter ) {
|
|||
$sqlValue = getDiskBlocks($StorageArea);
|
||||
break;
|
||||
default :
|
||||
$sqlValue = $terms[$i]['attr'];
|
||||
$sqlValue = $term['attr'];
|
||||
break;
|
||||
}
|
||||
if ( $dtAttr ) {
|
||||
$postfixExpr[] = array('type'=>'attr', 'value'=>$terms[$i]['attr'], 'sqlValue'=>$sqlValue, 'dtAttr'=>true);
|
||||
$postfixExpr[] = array('type'=>'attr', 'value'=>$term['attr'], 'sqlValue'=>$sqlValue, 'dtAttr'=>true);
|
||||
} else {
|
||||
$postfixExpr[] = array('type'=>'attr', 'value'=>$terms[$i]['attr'], 'sqlValue'=>$sqlValue);
|
||||
$postfixExpr[] = array('type'=>'attr', 'value'=>$term['attr'], 'sqlValue'=>$sqlValue);
|
||||
}
|
||||
} # end if attr
|
||||
|
||||
if ( isset($terms[$i]['op']) ) {
|
||||
if ( empty($terms[$i]['op']) ) {
|
||||
$terms[$i]['op'] = '=';
|
||||
if ( isset($term['op']) ) {
|
||||
if ( empty($term['op']) ) {
|
||||
$term['op'] = '=';
|
||||
}
|
||||
switch ( $terms[$i]['op']) {
|
||||
switch ( $term['op']) {
|
||||
case '=' :
|
||||
case '!=' :
|
||||
case '>=' :
|
||||
case '>' :
|
||||
case '<' :
|
||||
case '<=' :
|
||||
$sqlValue = $terms[$i]['op'];
|
||||
case 'LIKE' :
|
||||
case 'NOT LIKE':
|
||||
$sqlValue = $term['op'];
|
||||
break;
|
||||
case '=~' :
|
||||
case '=~' :
|
||||
$sqlValue = 'regexp';
|
||||
break;
|
||||
case '!~' :
|
||||
$sqlValue = 'not regexp';
|
||||
break;
|
||||
case '=[]' :
|
||||
case 'IN' :
|
||||
$sqlValue = 'in (';
|
||||
break;
|
||||
case '![]' :
|
||||
$sqlValue = 'not in (';
|
||||
break;
|
||||
case 'IS' :
|
||||
case 'IS NOT' :
|
||||
if ( $term['val'] == 'Odd' ) {
|
||||
$sqlValue .= ' % 2 = 1';
|
||||
} else if ( $term['val'] == 'Even' ) {
|
||||
$sqlValue .= ' % 2 = 0';
|
||||
} else {
|
||||
$sqlValue .= ' '.$term['op'];
|
||||
}
|
||||
break;
|
||||
default :
|
||||
Error('Unknown operator in filter '. $terms[$i]['op']);
|
||||
ZM\Error('Unknown operator in filter '.$term['op']);
|
||||
}
|
||||
while( true ) {
|
||||
if ( !count($postfixStack) ) {
|
||||
$postfixStack[] = array('type'=>'op', 'value'=>$terms[$i]['op'], 'sqlValue'=>$sqlValue);
|
||||
$postfixStack[] = array('type'=>'op', 'value'=>$term['op'], 'sqlValue'=>$sqlValue);
|
||||
break;
|
||||
} elseif ( $postfixStack[count($postfixStack)-1]['type'] == 'obr' ) {
|
||||
$postfixStack[] = array('type'=>'op', 'value'=>$terms[$i]['op'], 'sqlValue'=>$sqlValue);
|
||||
$postfixStack[] = array('type'=>'op', 'value'=>$term['op'], 'sqlValue'=>$sqlValue);
|
||||
break;
|
||||
} elseif ( $priorities[$terms[$i]['op']] < $priorities[$postfixStack[count($postfixStack)-1]['value']] ) {
|
||||
$postfixStack[] = array('type'=>'op', 'value'=>$terms[$i]['op'], 'sqlValue'=>$sqlValue );
|
||||
} elseif ( $priorities[$term['op']] < $priorities[$postfixStack[count($postfixStack)-1]['value']] ) {
|
||||
$postfixStack[] = array('type'=>'op', 'value'=>$term['op'], 'sqlValue'=>$sqlValue );
|
||||
break;
|
||||
} else {
|
||||
$postfixExpr[] = array_pop($postfixStack);
|
||||
|
@ -228,17 +251,23 @@ function parseFilterToTree( $filter ) {
|
|||
} // end while
|
||||
} // end if operator
|
||||
|
||||
if ( isset($terms[$i]['val']) ) {
|
||||
if ( isset($term['val']) ) {
|
||||
$valueList = array();
|
||||
foreach ( preg_split('/["\'\s]*?,["\'\s]*?/', preg_replace('/^["\']+?(.+)["\']+?$/', '$1', $terms[$i]['val'])) as $value ) {
|
||||
switch ( $terms[$i]['attr'] ) {
|
||||
foreach ( preg_split('/["\'\s]*?,["\'\s]*?/', preg_replace('/^["\']+?(.+)["\']+?$/', '$1', $term['val'])) as $value ) {
|
||||
switch ( $term['attr'] ) {
|
||||
case 'MonitorName':
|
||||
case 'Name':
|
||||
case 'Cause':
|
||||
case 'Notes':
|
||||
$value = "'$value'";
|
||||
break;
|
||||
case 'ServerId':
|
||||
if ( $term['op'] == 'LIKE' || $term['op'] == 'NOT LIKE' ) {
|
||||
$value = '%'.$value.'%';
|
||||
}
|
||||
$value = dbEscape($value);
|
||||
break;
|
||||
case 'MonitorServerId':
|
||||
case 'FilterServerId':
|
||||
case 'StorageServerId':
|
||||
case 'ServerId':
|
||||
if ( $value == 'ZM_SERVER_ID' ) {
|
||||
$value = ZM_SERVER_ID;
|
||||
} else if ( $value == 'NULL' ) {
|
||||
|
@ -260,17 +289,17 @@ function parseFilterToTree( $filter ) {
|
|||
case 'Date':
|
||||
case 'EndDate':
|
||||
case 'StartDate':
|
||||
$value = "to_days('".strftime(STRF_FMT_DATETIME_DB, strtotime($value))."' )";
|
||||
$value = 'to_days(\''.strftime(STRF_FMT_DATETIME_DB, strtotime($value)).'\')';
|
||||
break;
|
||||
case 'Time':
|
||||
case 'EndTime':
|
||||
case 'StartTime':
|
||||
$value = "extract( hour_second from '".strftime(STRF_FMT_DATETIME_DB, strtotime($value))."' )";
|
||||
$value = 'extract(hour_second from \''.strftime(STRF_FMT_DATETIME_DB, strtotime($value)).'\')';
|
||||
break;
|
||||
case 'Weekday':
|
||||
case 'EndWeekday':
|
||||
case 'StartWeekday':
|
||||
$value = "weekday( '".strftime(STRF_FMT_DATETIME_DB, strtotime($value))."' )";
|
||||
$value = 'weekday(\''.strftime(STRF_FMT_DATETIME_DB, strtotime($value)).'\')';
|
||||
break;
|
||||
default :
|
||||
if ( $value != 'NULL' )
|
||||
|
@ -278,11 +307,11 @@ function parseFilterToTree( $filter ) {
|
|||
} // end switch attribute
|
||||
$valueList[] = $value;
|
||||
} // end foreach value
|
||||
$postfixExpr[] = array('type'=>'val', 'value'=>$terms[$i]['val'], 'sqlValue'=>join(',', $valueList));
|
||||
$postfixExpr[] = array('type'=>'val', 'value'=>$term['val'], 'sqlValue'=>join(',', $valueList));
|
||||
} // end if has val
|
||||
|
||||
if ( !empty($terms[$i]['cbr']) ) {
|
||||
for ( $j = 0; $j < $terms[$i]['cbr']; $j++ ) {
|
||||
if ( !empty($term['cbr']) ) {
|
||||
for ( $j = 0; $j < $term['cbr']; $j++ ) {
|
||||
while ( count($postfixStack) ) {
|
||||
$element = array_pop($postfixStack);
|
||||
if ( $element['type'] == 'obr' ) {
|
||||
|
@ -292,8 +321,9 @@ function parseFilterToTree( $filter ) {
|
|||
$postfixExpr[] = $element;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} #end if cbr
|
||||
} # end foreach term
|
||||
|
||||
while ( count($postfixStack) ) {
|
||||
$postfixExpr[] = array_pop($postfixStack);
|
||||
}
|
||||
|
@ -314,11 +344,11 @@ function parseFilterToTree( $filter ) {
|
|||
$node = array('data'=>$element, 'count'=>2+$left['count']+$right['count'], 'right'=>$right, 'left'=>$left);
|
||||
$exprStack[] = $node;
|
||||
} else {
|
||||
Fatal("Unexpected element type '".$element['type']."', value '".$element['value']."'");
|
||||
ZM\Fatal('Unexpected element type \''.$element['type'].'\', value \''.$element['value'].'\'');
|
||||
}
|
||||
}
|
||||
if ( count($exprStack) != 1 ) {
|
||||
Fatal('Expression stack has '.count($exprStack).' elements');
|
||||
ZM\Fatal('Expression stack has '.count($exprStack).' elements');
|
||||
}
|
||||
return array_pop($exprStack);
|
||||
}
|
||||
|
@ -345,188 +375,153 @@ function parseTreeToInfix($tree) {
|
|||
return _parseTreeToInfix($tree);
|
||||
}
|
||||
|
||||
function _parseTreeToSQL( $node, $cbr=false )
|
||||
{
|
||||
function _parseTreeToSQL($node, $cbr=false) {
|
||||
$expression = '';
|
||||
if ( $node )
|
||||
{
|
||||
if ( isset($node['left']) )
|
||||
{
|
||||
if ( !empty($node['data']['bracket']) )
|
||||
$expression .= '( ';
|
||||
$expression .= _parseTreeToSQL( $node['left'] );
|
||||
}
|
||||
$inExpr = $node['data']['type'] == 'op' && ($node['data']['value'] == '=[]' || $node['data']['value'] == '![]');
|
||||
$expression .= $node['data']['sqlValue'];
|
||||
if ( !$inExpr )
|
||||
$expression .= ' ';
|
||||
if ( $cbr )
|
||||
$expression .= ') ';
|
||||
if ( isset($node['right']) )
|
||||
{
|
||||
$expression .= _parseTreeToSQL( $node['right'], $inExpr );
|
||||
if ( !empty($node['data']['bracket']) )
|
||||
$expression .= ') ';
|
||||
}
|
||||
}
|
||||
return( $expression );
|
||||
if ( !$node )
|
||||
return $expression;
|
||||
|
||||
if ( isset($node['left']) ) {
|
||||
if ( !empty($node['data']['bracket']) )
|
||||
$expression .= '( ';
|
||||
$expression .= _parseTreeToSQL($node['left']);
|
||||
}
|
||||
$inExpr = $node['data']['type'] == 'op' && (
|
||||
$node['data']['value'] == '=[]'
|
||||
or
|
||||
$node['data']['value'] == '![]'
|
||||
or
|
||||
$node['data']['value'] == 'IN'
|
||||
or
|
||||
$node['data']['value'] == 'NOT IN'
|
||||
);
|
||||
$expression .= $node['data']['sqlValue'];
|
||||
if ( !$inExpr )
|
||||
$expression .= ' ';
|
||||
if ( $cbr )
|
||||
$expression .= ') ';
|
||||
if ( isset($node['right']) ) {
|
||||
$expression .= _parseTreeToSQL($node['right'], $inExpr);
|
||||
if ( !empty($node['data']['bracket']) )
|
||||
$expression .= ') ';
|
||||
} # end if right
|
||||
return $expression;
|
||||
}
|
||||
|
||||
function parseTreeToSQL( $tree )
|
||||
{
|
||||
return( _parseTreeToSQL( $tree ) );
|
||||
function parseTreeToSQL($tree) {
|
||||
return _parseTreeToSQL($tree);
|
||||
}
|
||||
|
||||
function _parseTreeToFilter( $node, &$terms, &$level )
|
||||
{
|
||||
function _parseTreeToFilter($node, &$terms, &$level) {
|
||||
$elements = array();
|
||||
if ( $node )
|
||||
{
|
||||
if ( isset($node['left']) )
|
||||
{
|
||||
if ( $node ) {
|
||||
if ( isset($node['left']) ) {
|
||||
if ( !empty($node['data']['bracket']) )
|
||||
$terms[$level]['obr'] = 1;
|
||||
_parseTreeToFilter( $node['left'], $terms, $level );
|
||||
}
|
||||
if ( $node['data']['type'] == 'cnj' )
|
||||
{
|
||||
if ( $node['data']['type'] == 'cnj' ) {
|
||||
$level++;
|
||||
}
|
||||
$terms[$level][$node['data']['type']] = $node['data']['value'];
|
||||
if ( isset($node['right']) )
|
||||
{
|
||||
_parseTreeToFilter( $node['right'], $terms, $level );
|
||||
if ( isset($node['right']) ) {
|
||||
_parseTreeToFilter($node['right'], $terms, $level);
|
||||
if ( !empty($node['data']['bracket']) )
|
||||
$terms[$level]['cbr'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function parseTreeToFilter( $tree )
|
||||
{
|
||||
function parseTreeToFilter($tree) {
|
||||
$terms = array();
|
||||
if ( isset($tree) )
|
||||
{
|
||||
if ( isset($tree) ) {
|
||||
$level = 0;
|
||||
_parseTreeToFilter( $tree, $terms, $level );
|
||||
_parseTreeToFilter($tree, $terms, $level);
|
||||
}
|
||||
return( array( 'Query' => array( 'terms' => $terms ) ) );
|
||||
return array('Query' => array('terms' => $terms));
|
||||
}
|
||||
|
||||
function parseTreeToQuery( $tree )
|
||||
{
|
||||
$filter = parseTreeToFilter( $tree );
|
||||
parseFilter( $filter, false, '&' );
|
||||
return( $filter['query'] );
|
||||
function parseTreeToQuery($tree) {
|
||||
$filter = parseTreeToFilter($tree);
|
||||
parseFilter($filter, false, '&');
|
||||
return $filter['query'];
|
||||
}
|
||||
|
||||
function _drawTree( $node, $level )
|
||||
{
|
||||
if ( isset($node['left']) )
|
||||
{
|
||||
_drawTree( $node['left'], $level+1 );
|
||||
function _drawTree($node, $level) {
|
||||
if ( isset($node['left']) ) {
|
||||
_drawTree($node['left'], $level+1);
|
||||
}
|
||||
echo str_repeat( ".", $level*2 ).$node['data']['value']."<br>";
|
||||
if ( isset($node['right']) )
|
||||
{
|
||||
_drawTree( $node['right'], $level+1 );
|
||||
echo str_repeat('.', $level*2).$node['data']['value'].'<br/>';
|
||||
if ( isset($node['right']) ) {
|
||||
_drawTree($node['right'], $level+1);
|
||||
}
|
||||
}
|
||||
|
||||
function drawTree( $tree )
|
||||
{
|
||||
_drawTree( $tree, 0 );
|
||||
function drawTree($tree) {
|
||||
_drawTree($tree, 0);
|
||||
}
|
||||
|
||||
function _extractDatetimeRange( &$node, &$minTime, &$maxTime, &$expandable, $subOr )
|
||||
{
|
||||
function _extractDatetimeRange(&$node, &$minTime, &$maxTime, &$expandable, $subOr) {
|
||||
$pruned = $leftPruned = $rightPruned = false;
|
||||
if ( $node )
|
||||
{
|
||||
if ( isset($node['left']) && isset($node['right']) )
|
||||
{
|
||||
if ( $node['data']['type'] == 'cnj' && $node['data']['value'] == 'or' )
|
||||
{
|
||||
$subOr = true;
|
||||
}
|
||||
elseif ( !empty($node['left']['data']['dtAttr']) )
|
||||
{
|
||||
if ( $subOr )
|
||||
{
|
||||
$expandable = false;
|
||||
}
|
||||
elseif ( $node['data']['type'] == 'op' )
|
||||
{
|
||||
if ( $node['data']['value'] == '>' || $node['data']['value'] == '>=' )
|
||||
{
|
||||
if ( !$minTime || $minTime > $node['right']['data']['sqlValue'] )
|
||||
{
|
||||
$minTime = $node['right']['data']['value'];
|
||||
return( true );
|
||||
}
|
||||
}
|
||||
if ( $node['data']['value'] == '<' || $node['data']['value'] == '<=' )
|
||||
{
|
||||
if ( !$maxTime || $maxTime < $node['right']['data']['sqlValue'] )
|
||||
{
|
||||
$maxTime = $node['right']['data']['value'];
|
||||
return( true );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Fatal( "Unexpected node type '".$node['data']['type']."'" );
|
||||
}
|
||||
return( false );
|
||||
}
|
||||
if ( !($node and isset($node['left']) and isset($node['right']) ) ) {
|
||||
return $pruned;
|
||||
}
|
||||
|
||||
$leftPruned = _extractDatetimeRange( $node['left'], $minTime, $maxTime, $expandable, $subOr );
|
||||
$rightPruned = _extractDatetimeRange( $node['right'], $minTime, $maxTime, $expandable, $subOr );
|
||||
if ( $node['data']['type'] == 'cnj' && $node['data']['value'] == 'or' ) {
|
||||
$subOr = true;
|
||||
} else if ( !empty($node['left']['data']['dtAttr']) ) {
|
||||
if ( $subOr ) {
|
||||
$expandable = false;
|
||||
} elseif ( $node['data']['type'] == 'op' ) {
|
||||
if ( $node['data']['value'] == '>' || $node['data']['value'] == '>=' ) {
|
||||
if ( !$minTime || $minTime > $node['right']['data']['sqlValue'] ) {
|
||||
$minTime = $node['right']['data']['value'];
|
||||
return true;
|
||||
}
|
||||
} else if ( $node['data']['value'] == '<' || $node['data']['value'] == '<=' ) {
|
||||
if ( !$maxTime || $maxTime < $node['right']['data']['sqlValue'] ) {
|
||||
$maxTime = $node['right']['data']['value'];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ZM\Fatal("Unexpected node type '".$node['data']['type']."'");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $leftPruned && $rightPruned )
|
||||
{
|
||||
$pruned = true;
|
||||
}
|
||||
elseif ( $leftPruned )
|
||||
{
|
||||
$node = $node['right'];
|
||||
}
|
||||
elseif ( $rightPruned )
|
||||
{
|
||||
$node = $node['left'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return( $pruned );
|
||||
$leftPruned = _extractDatetimeRange( $node['left'], $minTime, $maxTime, $expandable, $subOr );
|
||||
$rightPruned = _extractDatetimeRange( $node['right'], $minTime, $maxTime, $expandable, $subOr );
|
||||
|
||||
if ( $leftPruned && $rightPruned ) {
|
||||
$pruned = true;
|
||||
} else if ( $leftPruned ) {
|
||||
$node = $node['right'];
|
||||
} else if ( $rightPruned ) {
|
||||
$node = $node['left'];
|
||||
}
|
||||
return $pruned;
|
||||
}
|
||||
|
||||
function extractDatetimeRange( &$tree, &$minTime, &$maxTime, &$expandable )
|
||||
{
|
||||
$minTime = "";
|
||||
$maxTime = "";
|
||||
function extractDatetimeRange( &$tree, &$minTime, &$maxTime, &$expandable ) {
|
||||
$minTime = '';
|
||||
$maxTime = '';
|
||||
$expandable = true;
|
||||
|
||||
_extractDateTimeRange( $tree, $minTime, $maxTime, $expandable, false );
|
||||
}
|
||||
|
||||
function appendDatetimeRange( &$tree, $minTime, $maxTime=false )
|
||||
{
|
||||
function appendDatetimeRange( &$tree, $minTime, $maxTime=false ) {
|
||||
$attrNode = array( 'data'=>array( 'type'=>'attr', 'value'=>'StartDateTime', 'sqlValue'=>'E.StartTime', 'dtAttr'=>true ), 'count'=>0 );
|
||||
$valNode = array( 'data'=>array( 'type'=>'val', 'value'=>$minTime, 'sqlValue'=>$minTime ), 'count'=>0 );
|
||||
$opNode = array( 'data'=>array( 'type'=>'op', 'value'=>'>=', 'sqlValue'=>'>=' ), 'count'=>2, 'left'=>$attrNode, 'right'=>$valNode );
|
||||
if ( isset($tree) )
|
||||
{
|
||||
if ( isset($tree) ) {
|
||||
$cnjNode = array( 'data'=>array( 'type'=>'cnj', 'value'=>'and', 'sqlValue'=>'and' ), 'count'=>2+$tree['count']+$opNode['count'], 'left'=>$tree, 'right'=>$opNode );
|
||||
$tree = $cnjNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$tree = $opNode;
|
||||
}
|
||||
|
||||
if ( $maxTime )
|
||||
{
|
||||
if ( $maxTime ) {
|
||||
$attrNode = array( 'data'=>array( 'type'=>'attr', 'value'=>'StartDateTime', 'sqlValue'=>'E.StartTime', 'dtAttr'=>true ), 'count'=>0 );
|
||||
$valNode = array( 'data'=>array( 'type'=>'val', 'value'=>$maxTime, 'sqlValue'=>$maxTime ), 'count'=>0 );
|
||||
$opNode = array( 'data'=>array( 'type'=>'op', 'value'=>'<=', 'sqlValue'=>'<=' ), 'count'=>2, 'left'=>$attrNode, 'right'=>$valNode );
|
||||
|
|
|
@ -212,11 +212,14 @@ if ( isset($minTime) && isset($maxTime) ) {
|
|||
if ( !isset($minTime) || !isset($maxTime) ) {
|
||||
// Dynamically determine range
|
||||
$row = dbFetchOne($rangeSql);
|
||||
|
||||
if ( !isset($minTime) )
|
||||
$minTime = $row['MinTime'];
|
||||
if ( !isset($maxTime) )
|
||||
$maxTime = $row['MaxTime'];
|
||||
if ( $row ) {
|
||||
if ( !isset($minTime) )
|
||||
$minTime = $row['MinTime'];
|
||||
if ( !isset($maxTime) )
|
||||
$maxTime = $row['MaxTime'];
|
||||
} else {
|
||||
# Errors will be reported by db functions
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty($minTime) )
|
||||
|
@ -307,7 +310,7 @@ $monEventSlots = array();
|
|||
$monFrameSlots = array();
|
||||
$events_result = dbQuery($eventsSql);
|
||||
if ( !$events_result ) {
|
||||
Fatal('SQL-ERR');
|
||||
ZM\Fatal('SQL-ERR');
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -552,7 +555,7 @@ if ( $mode == 'overlay' ) {
|
|||
$top += $chart['graph']['activityBarHeight']+1+$chart['graph']['eventBarHeight']+1;
|
||||
}
|
||||
} else {
|
||||
Warning("No mode $mode");
|
||||
ZM\Warning("No mode $mode");
|
||||
}
|
||||
|
||||
preg_match('/^(\d+)-(\d+)-(\d+) (\d+):(\d+)/', $minTime, $startMatches);
|
||||
|
|
Loading…
Reference in New Issue