Page 1 of 1
FTP questions
Posted: Fri Feb 10, 2006 1:39 pm
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.
Posted: Thu Feb 16, 2006 7:06 am
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
Posted: Tue Feb 21, 2006 5:36 pm
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.
Posted: Tue Feb 21, 2006 7:19 pm
by Carbide_tipped
If you find or write a script to remote ftp file management please post. I too need this.
Posted: Wed Mar 01, 2006 9:25 pm
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.
Posted: Fri Mar 03, 2006 3:40 am
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
!
Posted: Fri Mar 03, 2006 8:40 am
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.
Posted: Fri Mar 03, 2006 4:33 pm
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.
Posted: Sun Mar 05, 2006 7:29 pm
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.
Posted: Thu Mar 16, 2006 6:11 pm
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]
Posted: Thu Mar 16, 2006 11:16 pm
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.
Posted: Mon Mar 20, 2006 11:16 am
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
Posted: Mon Mar 20, 2006 2:00 pm
by Carbide_tipped
Awesome kevin..thank you.