#!/usr/local/bin/php "-", 2 => "-" ); $ifd = fopen( "index.txt", "r" ); $line = fgets( $ifd ); while( $line ) { list( $cam, $file ) = explode( "/", trim($line) ); if( !is_file( $file ) ) { $jpg = $file; if( endswith( $jpg, ".md5" ) ) { $jpg = substr( $jpg, 0, -4 ); } else if( endswith( $jpg, ".timv" ) ) { $jpg = substr( $jpg, 0, -5 ); } $qryval[1] = $cam; $qryval[2] = $jpg; $id = sql_quick_fetch( $conn, $qry, $qryval, "ff_id" ); // echo "qry = '$qry'\n"; // print_r( $qryval ); // echo gettype($id) . "\n"; // echo "id = '$id'\n"; if( !$id ) { echo "wget $url/$cam/$file\n"; if( $DO_DOWNLOAD ) { $rc = 999999; system( "wget -c -O $file.tmp $url/$cam/$file\n", $rc ); if( $rc == 0 ) { rename( "$file.tmp", "$file" ); } } } else { echo "$cam/$file has id $id.\n"; } } else { echo "$cam/$file already downloaded.\n"; } $line = fgets( $ifd ); // break; } fclose( $ifd ); } function get_ip() { $ip = getenv( "IP" ); if( $ip != "" ) { return $ip; } $ifd = popen( "tty", "r" ); if( !$ifd ) { return ""; } $ttystr = fread( $ifd, 32 ); pclose( $ifd ); $ttyarr = explode( "/", trim($ttystr) ); $n = count( $ttyarr ); $tty = $ttyarr[$n-1]; echo "tty = '$tty'\n"; $ifd = popen( "who", "r" ); if( !$ifd ) { return ""; } $ip = ""; $ipre = "/^\\(\\d+\\.\\d+\\.\\d+\\.\\d+\\)\$/"; $line = fgets( $ifd ); while( $line ) { $parts = preg_split( "/[ \\t]/", trim($line), -1, PREG_SPLIT_NO_EMPTY ); $n = count( $parts ); if( $parts[1] == $tty && preg_match( $ipre, $parts[$n-1] ) ) { $ip = substr( $parts[$n-1], 1, -1 ); echo "ip = '$ip'\n"; } $line = fgets( $ifd ); } pclose( $ifd ); return $ip; } function main( $urlbase ) { global $G_CFG_DB_CONNECTION; global $G_CFG_DIR_INC; chdir( $G_CFG_DIR_INC ); $ip = get_ip(); if( $ip == "" ) { echo "Couldn't get download IP.\n"; exit; } $url = "http://$ip/$urlbase"; $conn = pg_pconnect( $G_CFG_DB_CONNECTION ); if( !$conn ) { echo "Can't connect to database.\n"; exit; } download( $conn, $url ); } main( "pics/incoming" ); ?>