Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Chenhai Hu committed Apr 25, 2017
1 parent 5022737 commit 7bf1ae5
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
Empty file modified README.md
100644 → 100755
Empty file.
52 changes: 52 additions & 0 deletions canrisc_file_manager.php
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";
}





?>
22 changes: 22 additions & 0 deletions create_final_dirs.php
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);
}

?>
35 changes: 35 additions & 0 deletions readgmail.php
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);

?>

0 comments on commit 7bf1ae5

Please sign in to comment.