FTP questions

Support and queries relating to all previous versions of ZoneMinder
Locked
kevin_robson
Posts: 247
Joined: Sun Jan 16, 2005 11:26 am

FTP questions

Post by kevin_robson »

I would like to set up FTPing of files once an alert is triggered, so if my PC is stolen I would still have the evidence.

The problem is my ftp freespace is limited - 10M. I'd therefore need a seperate job to prune this down every minute or so. Has anyone written any scripts or set anything up to do something like this.

Or any other ideas?

I was also wondering if anyone has signed up for a free web hosting ftp space. I've seen plenty of free ones offering 100M or so, but was worried I might get barred for just uploading lots of files and not really using it as a homepage.

Any other thoughts?

Thanks in advance.
kevin_robson
Posts: 247
Joined: Sun Jan 16, 2005 11:26 am

Post by kevin_robson »

Does anyone out there archive to ftp?
If so is there any advice you can give me on this?

If not, how about an enhancement request to either:
1. Move and delete files to create space before ftp'ing
2. run a before ftp/after ftp command in order that I could write a shell script to do this myself.

Many Thanks
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

If you want anything more complicated than the basic options offered by the filters then the best thing is to write your own custom script and have the filters run that. Then you can do anything you want with it.
Phil
User avatar
Carbide_tipped
Posts: 16
Joined: Mon Jul 19, 2004 2:00 pm
Location: Minnesota, USA

Post by Carbide_tipped »

If you find or write a script to remote ftp file management please post. I too need this.
I'm in control till it's out of control
kevin_robson
Posts: 247
Joined: Sun Jan 16, 2005 11:26 am

Post by kevin_robson »

I'm happy to have a go at writing my own script. It will have to be in shell though - I'm no programmer. How do I go about integrating the script into the zoneminder ftp process?

Could you explain briefly what is called when the filter tries to ftp the files? If I can plug a script into ZM then that would be great.
delton
Posts: 1
Joined: Wed Mar 01, 2006 3:57 am

Post by delton »

Carbide_tipped wrote:If you find or write a script to remote ftp file management please post. I too need this.
Try this method.

#!/bin/sh
ftp -n localhost <<!
quote user YourUserName
quote pass YourPassword
binary
put file1 file2
quit
!
kevin_robson
Posts: 247
Joined: Sun Jan 16, 2005 11:26 am

Post by kevin_robson »

Thanks, but its the file management we need to get working - ZM already ftps files.

Any idea what script/procedure it calls when it attempts to ftp the files.

What I want to do is intercept this, and clear down enough space on my ftp server first to make way for the new event before it sends it.
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

The script is zmfilter.pl, this controls all filtering activities not just ftp. However as you can specify a custom script from the web interface you might find that easier to do than hacking zmfilter. If you do decide to hack it you should be able to find the ftp dialog quite easily though it uses perl modules to do the actual work.
Phil
kevin_robson
Posts: 247
Joined: Sun Jan 16, 2005 11:26 am

Post by kevin_robson »

Cheers for the info.
I will take a look at it and see what I can do. If I get this working I'll post on the forums - pretty busy at the minute though so expect it to take me a few weeks.
kevin_robson
Posts: 247
Joined: Sun Jan 16, 2005 11:26 am

Post by kevin_robson »

OK. I need some perl help!
I've written a shell script (I dont know perl) to do this.
You pass it the name of the file, and it checks to see if there is enough space in the ftp area, and then deletes files until enough room exists.
Works fine.

I'm now trying to plug it into zmfilter.pl - plan was to put it here:

$ftp->login( ZM_UPLOAD_FTP_USER, ZM_UPLOAD_FTP_PASS ) or warn( "FTP - Can't login" );
$ftp->binary() or warn( "FTP - Can't go binary" );
$ftp->cwd( ZM_UPLOAD_FTP_REM_DIR ) or warn( "FTP - Can't cwd" );

################################
# Just before we put, lets clear space on ftp server
exec "echo hello > /tmp/TEST.out";
#######################################
$ftp->put( $arch_file ) or warn( "FTP - Can't upload '$arch_file'" );
$ftp->quit() or warn( "FTP - Can't quit" );
unlink( $arch_file );
my $sql = "update Events set Uploaded = 1 where Id = ?";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
my $res = $sth->execute( $event->{Id} ) or die( "Can't execute '$sql': ".$sth->errstr() );

The Echo Hello line would instead call my script - I am only testing. At the minute I can't get it to run the echo command - but get no errors in the log file.

If I create a simple test script:

#!/usr/bin/perl -Tw
exec "echo hello > /tmp/TeSt.out";

I get the error:

Insecure $ENV{PATH} while running with -T switch at test.pl line 2.

But it works fine if I remove the -T switch. I assume this is a security issue.

How do I go about integrating a shell script into the zmfilter.pl script, or is it not posssible? I'm assuming I need to remove the -T from zmfilter.pl, but would also have to remove it from the calling script too?

Thanks in advance. [/b]
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

This is related to the perl tainting of arguments which have come from outside the script. Basically this mode enables perl to identify anything that might have been user supplied and so might be dangerous to execute. You are correct in that it is the -T flag.

If you create a script that uses -T you have to detaint anything from outside before you can use it. This basically verifies that you have decided it is kosher and acceptable. If you notice in zmfilter.pl this detaints various environment variable and I think your script will have to do the same, e.g.

Code: Select all

$ENV{PATH}  = '/bin:/usr/bin';
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
if you want to run in taint mode.

I would suggest googling for perl taint for some background also.
Phil
kevin_robson
Posts: 247
Joined: Sun Jan 16, 2005 11:26 am

Post by kevin_robson »

Thanks. I got that working once I read about perl tainting.

I've uploaded my code to the user contributions forum in case anyone else wants it. See FTP Server Maintainance
User avatar
Carbide_tipped
Posts: 16
Joined: Mon Jul 19, 2004 2:00 pm
Location: Minnesota, USA

Post by Carbide_tipped »

Awesome kevin..thank you.
I'm in control till it's out of control
Locked