-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chenhai Hu
committed
Apr 25, 2017
1 parent
5022737
commit 7bf1ae5
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
//Specify Log File | ||
$LogFile = "/root/scripts/brokerload.log"; | ||
$basepath = "/srv/candoc/commitment/"; | ||
$path = "/srv/candoc/Autofile/"; | ||
$error = "/srv/candoc/Autofile/error/"; | ||
|
||
$pattern = '/^\d+/'; | ||
//Running this job as a crontab requires the timezone be set | ||
//$fh = fopen($LogFile, 'ab') or die("can't open file"); | ||
//Open Log File for writing | ||
date_default_timezone_set('America/Toronto'); | ||
|
||
if(is_dir($path)) | ||
{ | ||
$FileList = scandir($path); | ||
foreach (array_diff($FileList, ['.','..','error']) as $filename) { | ||
$rawname = $filename; | ||
$filename=ltrim(str_ireplace('RE','', str_ireplace ('FW','', $filename))); | ||
$CommitNum=(preg_match($pattern, $filename,$result)==1)?(int)$result[0]:0; | ||
$basename = pathinfo($rawname,PATHINFO_FILENAME); | ||
$oldfile = "$path$rawname"; | ||
print_r("Filename:".$filename."\n"); | ||
if($CommitNum!=0&&file_exists("$basepath$CommitNum/$rawname")){ | ||
$ext = pathinfo($rawname,PATHINFO_EXTENSION); | ||
$newfile = "$basepath"."$CommitNum/"."$rawname-".date('Ymd\THis\Z').".$ext"; | ||
|
||
if(!rename($oldfile,$newfile)) | ||
rename($oldfile,"$error$rawname"); | ||
|
||
} | ||
elseif($CommitNum!=0){ | ||
if(!rename($oldfile, "$basepath"."$CommitNum/"."$rawname")) | ||
rename($oldfile,"$error$rawname"); | ||
} | ||
else rename($oldfile,"$error$rawname"); | ||
|
||
|
||
|
||
} | ||
|
||
} else | ||
{ | ||
$LogEntry = "File added to _Errors - " . date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . " - $basepath does not exist"; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
//iterate dirs, check for Final directory and create if none exists | ||
|
||
$path = '/srv/candoc/commitment/'; //change paths for testing - production //dont forget the last / | ||
|
||
if ($handle = opendir($path)) { | ||
$blacklist = array('.', '..', 'somedir', 'somefile.php'); //hardcode blacklist files | ||
while (false !== ($file = readdir($handle))) { | ||
if (!in_array($file, $blacklist)) { | ||
if(is_numeric($file)){ | ||
echo "$file\n"; | ||
@mkdir($path . $file."/final"); | ||
@chown($path . $file."/final", "sambashare"); | ||
@chgrp($path . $file."/final", "sambashare"); | ||
} | ||
} | ||
} | ||
closedir($handle); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
<?php | ||
|
||
/* connect to gmail */ | ||
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; | ||
$username = 'test@gmail.com'; | ||
$password = 'test'; | ||
|
||
/* try to connect */ | ||
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); | ||
|
||
/* grab emails */ | ||
$emails = imap_search($inbox,'ALL'); | ||
|
||
/* if emails are returned, cycle through each... */ | ||
if($emails) { | ||
|
||
/* begin output var */ | ||
$output = ''; | ||
/* put the newest emails on top */ | ||
rsort($emails); | ||
/* for every email... */ | ||
foreach($emails as $email_number) { | ||
$overview = imap_fetch_overview($inbox,$email_number,0); | ||
$fp = fopen('/srv/candoc/Autofile/'.$overview[0]->subject.'.eml','w') or die('failed to write files'); | ||
imap_savebody($inbox,$fp,$email_number); | ||
fclose($fp); | ||
imap_mail_move($inbox,$email_number,'[Gmail]/Bin'); | ||
} | ||
|
||
} | ||
/* close the connection */ | ||
imap_close($inbox); | ||
|
||
?> |