Commit Graph
31 Commits
Author SHA1 Message Date
Jash 8e0794d427 fix: zmcamtool keeps the control Id on overwrite, exports over a DB socket, validates --topreset ids refs #6429 2026-11-16 15:41:11 +05:30
Jash a5c82d453c fix: quote the database user and pass the password through MYSQL_PWD in zmcamtool fixes #5692 2026-11-15 09:49:07 +05:30
Jash 3ddd7e2cb9 fix: make zmcamtool and zmeventtool use the --user and --pass they are given refs #5906 2026-11-14 22:58:02 +05:30
Jash 9872927bd3 fix: stop zmcamtool --export when the name has invalid characters refs #5906 2026-11-14 22:58:02 +05:30
Jash 7c121cfae1 fix: give zmcamtool --topreset a value for every MonitorPresets column refs #5906 2026-11-14 22:58:02 +05:30
Isaac ConnorandClaude Opus 5 faa8d2f20c fix: make zmcamtool --export use the configured database and keep every value
Two problems, both in exportsql.

The mysqldump command ended with a hardcoded database name, so --export
always read from a database called zm whatever ZM_DB_NAME said. It now
uses the configured name.

The primary keys were then blanked with a regex that replaced everything
between VALUES ( and the first quoted string:

  s/VALUES \((.*?),'/VALUES \(NULL,'/ig

That holds only if the id is immediately followed by a quoted value. A
MonitorPresets row starts id,ModelId and both are unquoted, so the
pattern swallowed the pair into a single NULL and left the row one value
short of its columns. On the shipped data that corrupted all 75 preset
rows of a 126 row export; the 51 control rows came through intact, which
is presumably why it went unnoticed.

Replaced with the same parse the import now uses: split the values on
top level commas, find the id by column name, and blank just that one,
re-emitting the row in the form it arrived in. A row whose value count
does not match its table is left alone with a warning rather than
rewritten on a guess.

Verified against a real dump of the seed data: 126 rows, every one with
its id blanked, and not one value-count change -- against 75 corrupted
by the old pattern. Round-tripped the export back through --import into
an empty database: 51 controls and 74 presets, no broken names, no
unresolved control references, and every column identical to the source
apart from the one preset row whose name is a duplicate of another,
which the import has always collapsed because it keys on Name.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Isaac ConnorandClaude Opus 5 c0e908f5d7 fix: make zmcamtool --import find and parse the seed rows correctly
The import read zm_create.sql line by line and pulled the Controls and
MonitorPresets rows out with a regex. Two things were wrong with that.

It found no controls at all. The seed rows moved to db/controls.sql,
which zm_create.sql only pulls in with a `source` directive, and the
loop did not follow it, so --import silently stopped importing ptz
controls entirely.

The regex also mis-parsed the rows it did find. It assumed every INSERT
was positional with the id first and the name straight after, then
replaced everything before the first ,' with NULL. Ten of the shipped
controls are written with an explicit column list, where the first value
is the name, so it overwrote the name with NULL and keyed the row on the
protocol instead:

  IN : INSERT INTO `Controls` (`Name`,`Protocol`,`CanReset`)
                       VALUES ('Amcrest ASH42-B RPC','Dahua_RPC',1);
  OUT: INSERT INTO `Controls` (`Name`,`Protocol`,`CanReset`)
                       VALUES (NULL,'Dahua_RPC',1);

It also happened to work for MonitorPresets only because the two columns
before the name are numeric and unquoted.

Replaces it with a parser that reads the column list when there is one
and asks the database for the column order when there is not, so nothing
depends on the name sitting at a fixed offset -- it is the second column
of Controls but the third of MonitorPresets. Values are split on top
level commas only, leaving quoted strings and parenthesised subqueries
intact, which matters now that a name may contain a comma and a preset
resolves its control with a SELECT. The id is blanked wherever it
appears so the row still gets a fresh one, and a row whose value count
does not match the table is skipped with a warning rather than inserted
crookedly.

`source` is followed, relative to the including file, so the controls
come back. A file that cannot be read warns instead of dying, since
zm_create.sql sources several that are optional.

Verified against the real seed data: 51 controls parsed where it
previously found none, 74 presets, no row imported with a null or empty
name, the ten explicit-column controls landing with their name and
protocol intact, every preset's control subquery resolving, and names
containing commas preserved. Exercised the splitter directly on a
positional row, an explicit-column row, a row with both a comma in the
name and a subquery, and a doubled-quote escape. Round-tripped a
mysqldump export back through the import. Generated script passes
perl -Tc.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Y6FieTwEXuLhhR4e2yiax
2026-10-10 09:32:17 -04:00
Steve GilvarryandClaude Opus 5 ba49bbb33c fix: make the Perl scripts' taint-safe PATH configurable
The scripts run under -T, so they cannot trust the caller's PATH and set
their own. Sixteen of them hardcoded /bin:/usr/bin:/usr/local/bin, which
assumes everything they shell out to lives under /usr or /usr/local.

ZoneMinder::General::findDbCommand looks for a database client on that
PATH, and zmupdate.pl and zmcamtool.pl run what it finds. So an install
whose client sits anywhere else cannot apply schema changes:

  sh: mysql: command not found
  Command 'mysql -u'zmuser' ... ' exited with status: 127

even with the client on the caller's PATH. Homebrew on Apple Silicon is
the case that surfaced it - the client is in /opt/homebrew/bin - but a
--prefix=/opt install on Linux has the same shape, as does anything that
keeps its database client outside the FHS locations.

Replaced the literal with @ZM_SCRIPT_PATH@, defaulting to the same three
directories plus wherever cmake actually found a client, and overridable
for packagers who want to pin it. Warn at configure time when no client
is found at all, since that failure otherwise appears much later and
says something unrelated.

Nothing changes for an install whose client is already under /usr/bin:
the directory is only appended when it is not in the list, so the
default stays exactly as it was.

Memory.pm is deliberately left alone. It has a narrower PATH of
/bin:/usr/bin, and the only command it runs is uname through an absolute
path from ZM_PATH_UNAME, so it does not need widening.

Verified on macOS across the three cases: with the client in
/opt/homebrew/bin the directory is appended; -DZM_SCRIPT_PATH= is
respected verbatim; and pointing detection at /usr/bin/mariadb leaves
the default untouched. Build clean, suite 146 cases.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B5KL9Xbi7K5aGsauLtd8tG
2026-09-13 13:04:59 +10:00
Nic BoetandClaude Opus 4.6 d66a3525bd feat: detect MariaDB-native command names with fallback to MySQL legacy names
MariaDB is deprecating mysql-prefixed utility names (mysqldump,
mysql) in favour of its own (mariadb-dump, mariadb). Add
findDbCommand() to ZoneMinder::General that probes for the
MariaDB-native binary first and falls back to the legacy name.
Results are cached per-process. Update the three call sites in
zmupdate.pl.in and zmcamtool.pl.in.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 13:19:32 -06:00
Isaac Connor 42a284d9ac Add quotes around dbUser and dbPass to prevent command injection 2024-01-02 14:00:34 -05:00
Alejandro Criado-Pérez 871bf1772f fix: messages 2023-07-05 01:03:48 +02:00
Isaac Connor 258ae23fb9 out an error if name contains invalid characters 2020-02-19 09:42:54 -05:00
zlodag 1168db9df0 Fixed regexp in zmcamtool to accept names for currently existing MonitorPresets 2020-02-19 22:47:40 +13:00
zlodag 2c51b1436c cleaned input for "zmcamtool.pl --export <control_or_preset_name>" to fix error when running in taint mode 2020-02-16 11:41:06 +13:00
Isaac Connor 766a59884d Don't hard code perl path. Use PERL_EXECUTABLE cmake var 2019-09-23 12:54:27 -04:00
Isaac Connor c55814647c fix spacing, braces, quotes 2017-06-07 15:28:31 -04:00
Isaac Connor ac88490338 When use warnings is on and there is a null value in the monitor data it causes warnings. So add skip if __git_main is not defined. 2017-01-02 12:49:37 -05:00
Andy Bauer 254fcbcef7 update gpl 2 mailing address in source files 2016-12-26 09:23:16 -06:00
Dmitry Smirnov 5bcc414038 codespell: misc. spelling corrections
Signed-off-by: Dmitry Smirnov <onlyjob@member.fsf.org>
2016-02-08 20:41:36 +11:00
Dmitry Smirnov 53907eeba1 zmcamtool.pl: readability 2015-04-11 00:35:40 +10:00
Dmitry Smirnov 90fa57788a zmcamtool.pl: pod2usage 2015-04-11 00:35:35 +10:00
Dmitry Smirnov 4dee542e99 zmcamtool.pl: tabs-to-spaces 2015-04-11 00:07:36 +10:00
Isaac Connor 76d0dfa475 Add -v --version command line param to zmcamtool.pl 2015-01-07 08:43:51 -05:00
Andrew Bauer f5ce597609 final cleanup and changes before 1.27 release 2014-02-01 12:17:46 -06:00
Andrew Bauer e707e72fe3 Perl::Critic recommended a couple minor changes 2014-01-25 12:42:33 -06:00
Andrew Bauer dbe6fc539c Additional error checking 2014-01-25 11:26:29 -06:00
Andrew Bauer ae1731477b further refinements 2014-01-25 10:39:38 -06:00
Andrew Bauer 2037afb3ca new subroutine runQuery 2014-01-23 08:41:47 -06:00
Andrew Bauer 869a139809 create rmName subroutine 2014-01-22 19:18:08 -06:00
Andy Bauer 91b0676343 Call checkName for certain reptitive tasks 2014-01-22 09:20:56 -06:00
Andrew Bauer f00e72be1e Initial commit for new zmcamtool.pl script 2014-01-21 16:22:30 -06:00