function oneTask($task) { if ($task['type'] == 0) { $this_path = ProdsDir::fromURI($task['src'], false); $new_path = ProdsDir::fromURI($task['dest'], false); } else { $this_path = ProdsFile::fromURI($task['src'], false); $new_path = ProdsFile::fromURI($task['dest'], false); } if (empty($parent->account->pass)) { $acct = $_SESSION['acct_manager']->findAcct($this_path->account); if (empty($acct)) { $response = array('success' => false, 'errmsg' => 'Authentication Required'); echo json_encode($response); exit(0); } $this_path->account = $acct; } if (empty($this_path->account->zone)) { $this_path->account->getUserInfo(); } $this_path->rename($new_path->path_str); }
/** * fopen() handler. * * @access private */ public function stream_open($path, $mode, $options, &$opened_path) { // get rid of tailing 'b', if any. if ($mode[strlen($mode) - 1] == 'b' && strlen($mode) > 1) { $mode = substr($mode, 0, strlen($mode) - 1); } try { $this->file = ProdsFile::fromURI($path); $this->file->open($mode); return true; } catch (Exception $e) { trigger_error("Got an exception:{$e}", E_USER_WARNING); return false; } }
if (empty($acct)) { if (empty($account->pass)) { $response = array('success' => false, 'errmsg' => 'Authentication Required'); echo json_encode($response); exit(0); } else { $_SESSION['acct_manager']->add($account); } } $account = $acct; $mservices = array(); $input_params = array("*desc_resc" => $resc); $num_files = 0; foreach ($files as $fileuri) { if (strlen($fileuri) > 0) { $myfile = ProdsFile::fromURI($fileuri); $mservices[] = "msiDataObjRepl(*desc_file{$num_files},*desc_resc,*outbuf)"; $input_params["*desc_file{$num_files}"] = $myfile->getPath(); $num_files++; } } $num_dirs = 0; foreach ($dirs as $diruri) { if (strlen($diruri) > 0) { $mydir = ProdsDir::fromURI($diruri); $mservices[] = "msiReplColl(*desc_dir{$num_dirs},*desc_resc,backupMode,*outbuf)"; $input_params["*desc_dir{$num_dirs}"] = $mydir->getPath(); $num_dirs++; } } $rule_body = 'myTestRule||' . 'delayExec(<PLUSET>0m</PLUSET>,' . implode("##", $mservices) . ',nop)|nop';
$user = '******'; $pass = '******'; /** * This simple script reads JPEG/TIFF files stored in iRODS, extract * its EXIF information, and set it as userdefined metadata. * Note: EXIF php module is required for this program to work properly * http://us2.php.net/manual/en/ref.exif.php * * Example: php -f exif2meta.php /tempZone/home/rods/test2/RIMG0087.jpg */ //----------don't modify below this line!! ----------- require_once "../src/Prods.inc.php"; $target_file = $argv[1]; try { $account = new RODSAccount($host, $port, $user, $pass); $irodsfile = new ProdsFile($account, $target_file, true); $metas = $irodsfile->getMeta(); $metaalreadyset = false; foreach ($metas as $meta) { if ($meta->name == 'EXIF.ExifVersion') { $metaalreadyset = true; break; } } if ($metaalreadyset === true) { $time = '[' . date('c') . ']'; echo "{$time} 0: metadata already set for '{$target_file}'\n"; exit(0); } // download file from irods to tmp $localfile = '/tmp/' . basename($target_file);
<?php require_once "/Path/to/Prods/src/Prods.inc.php"; // make an iRODS account object for connection, assuming: // username: demouser, password: demopass, server: srbbrick15.sdsc.edu, port: 1247 $account = new RODSAccount("srbbrick15.sdsc.edu", 1247, "demouser", "demopass"); //create an file object for read, assuming the path is "/tempZone/home/demouser/test_read.txt" $myfile = new ProdsFile($account, "/tempZone/home/demouser/test_read.txt"); //read and print out the file $myfile->open("r"); echo "the file reads: <pre>"; while ($str = $myfile->read(4096)) { echo $str; } echo "</pre>"; //close the file pointer $myfile->close(); //create an file object for write, assuming the path is "/tempZone/home/demouser/test_write.txt" $myfile = new ProdsFile($account, "/tempZone/home/demouser/test_write.txt"); //write hello world to the file, onto "demoResc" as resource. Note that resource name is //required here by method open(), because iRODS needs to know which resource to write to. $myfile->open("w+", "demoResc"); $bytes = $myfile->write("Hello world!\n"); //print the number of bytes writen echo "{$bytes} bytes written <br/>\n"; $myfile->close();
$myfile->open("w+", "demoResc"); $bytes = $myfile->write("Hello world from Sifang!\n"); echo "{$bytes} bytes written <br/>\n"; $myfile->close(); $myfile->open("r", "demoResc", true); $str = $myfile->read(200); echo "the file reads: <pre>{$str}</pre>"; $myfile->close(); $file_src = new ProdsFile($account, "/tempZone/home/rods/test.php"); $file_dest = new ProdsFile($account, "/tempZone/home/rods/test.sifang.txt"); //$file_src->cpMeta($file_dest); foreach ($file_dest->getMeta() as $meta) { echo "{$file_dest->path_str}: {$meta->name}; {$meta->value}; {$meta->units} <br/> \n"; } $meta = array(new RODSMeta("test1", "1")); $files = ProdsPath::queryMeta($account, $meta); foreach ($files as $file) { echo "{$file} <br/>\n"; } echo "<hr/>"; $dirs = ProdsPath::queryMeta($account, $meta, 1); foreach ($dirs as $dir) { echo "{$dir} <br/>\n"; } $file = new ProdsFile($account, "/tempZone/home/rods/test.php"); var_dump($file->getStats()); echo "<br/>--- connection successful! #2--- " . microtime() . " <br/>\n"; } catch (RODSException $e) { echo $e; echo $e->showStackTrace(); }
$response = array('success' => false, 'errmsg' => "Mal-formated Mod batch"); echo json_encode($response); exit(0); } } } if ($action == NULL) { $response = array('success' => false, 'errmsg' => 'Expected type not specified'); echo json_encode($response); exit(0); } try { if ($type == 0) { $this_path = ProdsDir::fromURI($ruri, false); } else { $this_path = ProdsFile::fromURI($ruri, false); } if (empty($parent->account->pass)) { $acct = $_SESSION['acct_manager']->findAcct($this_path->account); if (empty($acct)) { $response = array('success' => false, 'errmsg' => 'Authentication Required'); echo json_encode($response); exit(0); } $this_path->account = $acct; } if (empty($this_path->account->zone)) { $this_path->account->getUserInfo(); } switch ($action) { case "get":
$response = array('success' => false, 'log' => 'Resource name not specified'); echo json_encode($response); exit(0); } try { $parent = ProdsDir::fromURI($ruri, false); if (empty($parent->account->pass)) { $acct = $_SESSION['acct_manager']->findAcct($parent->account); if (empty($acct)) { $response = array('success' => false, 'log' => 'Authentication Required'); echo json_encode($response); exit(0); } $parent->account = $acct; } if (empty($parent->account->zone)) { $parent->account->getUserInfo(); } $file = new ProdsFile($parent->account, $parent->path_str . '/' . $name); if ($file->exists()) { $response = array('success' => false, 'log' => 'Path ' . $parent->path_str . '/' . $name . ' already exists!'); } else { $file->open('w', $resc); $file->close(); $response = array('success' => true, 'log' => "new file '{$name}' created!"); } echo json_encode($response); } catch (Exception $e) { $response = array('success' => false, 'log' => $e->getMessage()); echo json_encode($response); }
$resource = $_REQUEST['resource']; } else { $response = array('success' => false, 'errmsg' => 'Expected resource not found'); echo json_encode($response); exit(0); } $action = ""; if (isset($_REQUEST['action'])) { $action = $_REQUEST['action']; } else { $response = array('success' => false, 'errmsg' => 'Expected action not found'); echo json_encode($response); exit(0); } try { $file = ProdsFile::fromURI($ruri, false); if (empty($file->account->pass)) { $acct = $_SESSION['acct_manager']->findAcct($file->account); if (empty($acct)) { $response = array('success' => false, 'errmsg' => 'Authentication Required'); echo json_encode($response); exit(0); } $file->account = $acct; } switch ($action) { case 'add': $file->repl($resource, array('backupMode' => true)); $response = array('success' => true, 'log' => "file replicated to resource {$resource}"); break; case 'remove':
if (empty($parent->account->pass)) { $acct = $_SESSION['acct_manager']->findAcct($parent->account); if (empty($acct)) { $response = array('success' => false, 'errmsg' => 'Authentication Required'); echo json_encode($response); exit(0); } $parent->account = $acct; } if (empty($parent->account->zone)) { $parent->account->getUserInfo(); } $num_files = 0; foreach ($files as $filename) { if (strlen($filename) > 0) { $myfile = new ProdsFile($parent->account, $parent->path_str . '/' . $filename); $myfile->unlink(NULL, $force_delete); $num_files++; } } $num_dirs = 0; foreach ($dirs as $dirname) { if (strlen($dirname) > 0) { $mydir = new ProdsDir($parent->account, $parent->path_str . '/' . $dirname); $mydir->rmdir(true, $force_delete); $num_dirs++; } } $response = array('success' => true, 'log' => "{$num_files} files and {$num_dirs} collections deleted!"); echo json_encode($response); } catch (Exception $e) {
<?php /** * Developer: Daniel Speichert * Date: 14.12.12 * Time: 13:40 */ require_once "../src/Prods.inc.php"; require_once "../src/ProdsStreamer.class.php"; error_reporting(-1); try { // make an iRODS account object for connection, assuming: // username: demouser, password: demopass, server: srbbrick15.sdsc.edu, port: 1247 // $host, $port, $user, $pass, $zone = "", $default_resc = "", $ticket = '' //$account = new RODSAccount('localhost', 1247, 'rods', 'rods'); $account = new RODSAccount('localhost', 1247, 'a', 'a', '', '', 'RpO7kyGvh40egRz'); $myfile = new ProdsFile($account, "/tempZone/home/rods/phrases.html"); //header('Content-Type: image/png'); //read and print out the file $myfile->open("r"); //while($str=$myfile->read(4096)) //$str=file_get_contents("rods://*****:*****@localhost:1247/tempZone/home/rods/testphoto.png"); $str = file_get_contents("rods+ticket://a#RpO7kyGvh40egRz:a@localhost:1247/tempZone/home/rods/phrases.html"); echo $str; //close the file pointer $myfile->close(); } catch (RODSException $e) { echo "--- test failed! --- <br/>\n"; echo $e; echo $e->showStackTrace(); }
if (empty($filename)) { continue; } if ($srcfile['error'] != UPLOAD_ERR_OK) { if (isset($upload_error_msg[$srcfile['error']])) { $response = array('success' => false, 'errmsg' => $upload_error_msg[$srcfile['error']], 'errcode' => $srcfile['error']); } else { $response = array('success' => false, 'errmsg' => 'Unknow errors', 'errcode' => $srcfile['error']); } $error = true; break; } $tempuploadfilepath = tempnam(dirname($srcfile['tmp_name']), 'RODS_Web_Upload'); move_uploaded_file($srcfile['tmp_name'], $tempuploadfilepath); //copy($srcfile['tmp_name'], $srcfile['name']); $destfile = new ProdsFile($collection->account, $collection->path_str . "/" . $filename); /* $response=array('success'=> false,'log'=> ''.$collection->account); echo json_encode($response); exit(0); */ $destfile->open('w', $resource); $destfile->write(file_get_contents($tempuploadfilepath)); $destfile->close(); if (AUTO_EXTRACT_EXIF === true) { extactExif($tempuploadfilepath, $destfile); } $numfiles++; unlink($tempuploadfilepath); } if ($error === false) {
<?php require_once "/Path/to/Prods/src/Prods.inc.php"; // make an iRODS account object for connection, assuming: // username: demouser, password: demopass, server: srbbrick15.sdsc.edu, port: 1247 $account = new RODSAccount("srbbrick15.sdsc.edu", 1247, "demouser", "demopass"); //create an file object for read, assuming the path is "/tempZone/home/demouser/test_read.txt" $myfile = new ProdsFile($account, "/tempZone/home/demouser/test_read.txt"); //create an metadata entry and associate it with the file $meta = new RODSMeta("myname", "myvalue"); $myfile->addMeta($meta); //get all metadata of the file, and print them //the output should look like "Name: Myname | Value: myvalue" $metadatas = $myfile->getMeta(); foreach ($metadatas as $meta) { echo 'Name: ' . $meta->name . " | " . $meta->value . "\n"; }
<?php require_once "../src/Prods.inc.php"; $account = new RODSAccount("localhost", 1247, "rods", "rods", "tempZone"); $target_file = '/tempZone/home/rods/test/SantaMonica.jpg'; try { $start_time = microtime(true); $myfile = new ProdsFile($account, $target_file); $numbytes = $myfile->repl('resc2', array('backupMode' => true)); echo "Replication successful! {$numbytes} bytes written <br/>\n"; $end_time = microtime(true); $exec_time = $end_time - $start_time; echo "--- test successful! in ({$exec_time} sec) --- <br/>\n"; } catch (RODSException $e) { echo "--- test failed! --- <br/>\n"; echo $e; echo $e->showStackTrace(); }
<?php require_once "../src/Prods.inc.php"; $account = new RODSAccount("localhost", 1247, "rods", "rods", "tempZone"); $target_file = '/tempZone/home/rods/repl_test/ruleInp1'; try { $start_time = microtime(true); $myfile = new ProdsFile($account, $target_file); $replinfo = $myfile->getReplInfo(); var_dump($replinfo); $end_time = microtime(true); $exec_time = $end_time - $start_time; echo "--- test successful! in ({$exec_time} sec) --- <br/>\n"; } catch (RODSException $e) { echo "--- test failed! --- <br/>\n"; echo $e; echo $e->showStackTrace(); }
/** * fopen() handler. * * @access private */ public function stream_open($path, $mode, $options, &$opened_path) { // get rid of tailing 'b', if any. if ($mode[strlen($mode) - 1] == 'b' && strlen($mode) > 1) { $mode = substr($mode, 0, strlen($mode) - 1); } try { if ($mode === 'm' || $mode === 'm-') { $url = parse_url($path); $args = array(); parse_str($url['query'], $args); unset($url['query']); $path = strstr($path, '?', true); $this->file = ProdsFile::fromURI($path); $old = NULL; if (!empty($args['id'])) { $oldMeta = $this->file->getMeta(); foreach ($oldMeta as $meta) { if ($meta->id === $args['id']) { $old = $meta; break; } } } if ($mode === 'm-') { if (!empty($old)) { $this->file->rmMeta($old); } else { // meta doesn't exist - already deleted? } return true; } if (!empty($old)) { $new = new RODSMeta($old->name, $old->value, $old->units, $old->id); if ($args['name'] === 'name') { $new->name = $args['value']; } else { if ($args['name'] === 'value') { $new->value = $args['value']; } else { if ($args['name'] === 'units') { $new->units = $args['value']; } } } $this->file->updateMeta($old, $new); } else { $new = new RODSMeta("name", "value", "units"); if ($args['name'] === 'name') { $new->name = $args['value']; } else { if ($args['name'] === 'value') { $new->value = $args['value']; } else { if ($args['name'] == 'units') { $new->units = $args['units']; } } } $this->file->addMeta($new); } $this->metadata = $this->file->getMeta(); return true; } $this->file = ProdsFile::fromURI($path); $this->file->open($mode); $this->metadata = $this->file->getMeta(); return true; } catch (Exception $e) { trigger_error("Got an exception:{$e} while trying to stream_open {$path} with mode {$mode}", E_USER_WARNING); return false; } }
$ruri = $_REQUEST['ruri']; } else { $response = array('success' => false, 'errmsg' => 'Required RODS URI not found'); echo json_encode($response); exit(0); } $action = ""; if (isset($_REQUEST['action'])) { $action = $_REQUEST['action']; } else { $response = array('success' => false, 'errmsg' => 'Action type not specified'); echo json_encode($response); exit(0); } try { $file = ProdsFile::fromURI($ruri); if (empty($file->account->pass)) { $acct = $_SESSION['acct_manager']->findAcct($file->account); if (empty($acct)) { $response = array('success' => false, 'errmsg' => 'Authentication Required'); echo json_encode($response); exit(0); } $file->account = $acct; } switch ($action) { case 'replica': $repl_info = $file->getReplInfo(); $response = array('success' => true, 'totalCount' => count($repl_info), 'que_results' => $repl_info); $str = json_encode($response); echo "({$str})";