function homePage() { $t = new Template('home.html'); $t->replace('BACKGROUND', $_SESSION['userconf']['general']['background']); $t->replace('CSS', 'css.html'); $t->replace('NAVBAR', 'navbar.html'); $t->replace('DATA_COUNT', DataC::getCount($_SESSION['userid'])); $t->replace('FEED_COUNT', FeedC::getCount($_SESSION['userid'])); $t->replace('RUNNING_COUNT', FeedC::getRunningCount($_SESSION['userid'])); $t->replace('PLUGIN', PluginC::getHTML()); $t->replace('FEED_ALL', FeedC::getAllHTML($_SESSION['userid'])); $t->replace('MODAL_DDROP', 'modal_ddrop.html'); $t->replace('MODAL_TAG', 'modal_tag.html'); $t->replace('TAGS_LIST', TagC::getTagsList()); $t->replace('PLUGINS_LIST', PluginC::getPluginsList()); $t->replace('MODAL_PREVIEW', 'feed_data_preview.html'); $t->replace('FOOTER', 'footer.html'); $t->replace('JAVASCRIPT_LIBS', 'javascript.libs.php'); $t->replace('JAVASCRIPT_CHRIS', 'javascript.chris.html'); $t->replace('USERNAME', ucfirst($_SESSION['username'])); $t->replace('CHRIS_VERSION', CHRIS_VERSION); // ui $t->replace('CHRIS_UI_CHECKBOX', 'ui_checkbox.html'); if (CHRIS_MAINTENANCE) { $t->replace('MAINTENANCE', 'display:block'); } else { $t->replace('MAINTENANCE', 'display:none'); } return $t; }
} } break; case "get": if ($what == 'feed_updates') { $result['result'] = FeedC::updateClient($_SESSION['userid'], $parameters[0]); } else { if ($what == 'feed_previous') { $result['result'] = FeedC::scrollClient($_SESSION['userid'], $parameters[0], $parameters[1]); } else { if ($what == 'feed_search') { // if 'TAGPLUGIN flan, we do a quick search' if (isset($parameters[1]) && $parameters[1] == 'TAGPLUGIN') { $result['result'] = FeedC::searchTagPlugin($_SESSION['userid'], $parameters[0]); } else { $result['result'] = FeedC::searchClient($_SESSION['userid'], $parameters[0]); } } else { if ($what == 'file') { $name = joinPaths(CHRIS_USERS, $parameters); // enable cross origin requests header("Access-Control-Allow-Origin: *"); // if the file does not exist, just die if (!is_file($name)) { die; } $fp = fopen($name, 'rb'); fpassthru($fp); die; } else { if ($what == 'users') {
# run command as locally ChRIS! $ssh2 = new Net_SSH2('localhost'); $key = new Crypt_RSA(); $sshkey = joinPaths(CHRIS_HOME, '.ssh/id_rsa'); $key->loadKey(file_get_contents($sshkey)); if (!$ssh2->login('chris', $key)) { exit('Login as ChRIS local user failed...!'); } $local_command = "/bin/bash umask 0002;/bin/bash {$runfile};"; $nohup_wrap = 'bash -c \'nohup bash -c "' . $local_command . '" > /dev/null 2>&1 &\''; $ssh2->exec($nohup_wrap); $pid = -1; } else { if ($status == 100) { // run locally $ssh->exec('bash -c \' /bin/bash ' . $runfile . '\''); $pid = -1; } else { // run on cluster and return pid $cluster_command = str_replace("{MEMORY}", $memory, CLUSTER_RUN); $cluster_command = str_replace("{FEED_ID}", $feed_id, $cluster_command); $cluster_command = str_replace("{COMMAND}", "/bin/bash " . $runfile, $cluster_command); $pid = $ssh->exec('bash -c \'' . $cluster_command . '\''); } } // attach pid to feed $metaObject = new Meta(); $metaObject->name = "pid"; $metaObject->value = $pid; FeedC::addMeta($feed_id, array(0 => $metaObject)); echo $feed_id;
public static function share($feed_ids, $ownerid, $ownername, $targetname, &$ssh_connection) { foreach ($feed_ids as $feed_id) { // get target user id $userMapper = new Mapper('User'); $userMapper->filter('username = (?)', $targetname); $userResult = $userMapper->get(); if (count($userResult['User']) >= 1) { // get feed to be shared $feedMapper = new Mapper('Feed'); $feedMapper->filter('id = (?)', $feed_id); $feedResult = $feedMapper->get(); if (count($feedResult['Feed']) >= 1) { $feedResult['Feed'][0]->id = 0; $feedResult['Feed'][0]->user_id = $userResult['User'][0]->id; $feedResult['Feed'][0]->time = microtime(true); $feedResult['Feed'][0]->favorite = 0; $new_id = Mapper::add($feedResult['Feed'][0]); // get parameters, owner meta information $metaMapper = new Mapper('Meta'); // OR confiton between all filters $metaMapper->filter('', '', 0, 'OR'); // first filters $metaMapper->filter('name = (?)', 'root_id', 1); $metaMapper->filter('target_id = (?)', $feed_id, 1); $metaMapper->filter('target_type = (?)', 'feed', 1); // second filters $metaMapper->filter('name = (?)', 'parameters', 2); $metaMapper->filter('target_id = (?)', $feed_id, 2); $metaMapper->filter('target_type = (?)', 'feed', 2); // second filters $metaMapper->filter('name = (?)', 'pid', 3); $metaMapper->filter('target_id = (?)', $feed_id, 3); $metaMapper->filter('target_type = (?)', 'feed', 3); // get results $metaResult = $metaMapper->get(); // for earch result, create same meta with different target id if (count($metaResult['Meta']) >= 1) { foreach ($metaResult['Meta'] as $k0 => $v0) { $v0->id = 0; $v0->target_id = $new_id; // make sure to properly update the root_id if ($v0->name == 'root_id') { $v0->value = $feed_id; } Mapper::add($v0); } } // add sharer FeedC::addMetaS($new_id, 'sharer_id', (string) $ownerid, 'simple'); // link files on file system $targetDirectory = CHRIS_USERS . '/' . $ownername . '/' . $feedResult['Feed'][0]->plugin . '/' . $feedResult['Feed'][0]->name . '-' . $feed_id; $destinationDirectory = CHRIS_USERS . '/' . $targetname . '/' . $feedResult['Feed'][0]->plugin; if (!is_dir($destinationDirectory)) { // 777? 775 $old = umask(); umask(00); mkdir($destinationDirectory, 0775, true); umask($old); } $destinationDirectory .= '/' . $feedResult['Feed'][0]->name . '-' . $new_id; // just a link? symlink($targetDirectory, $destinationDirectory); // we need to change the permission of the target directory to 777 (as the owner) // so that the other user can write to this folder // but only if the targetDirectory is a directory and not a link (a link means it was re-shared) if (is_dir($targetDirectory)) { $ssh_connection->exec('chmod -R 777 ' . $targetDirectory); } //if(!is_dir($destinationDirectory)){ // recurse_copy($targetDirectory, $destinationDirectory); //} } else { return "Invalid feed id: " . $feed_id; } } else { return "Invalid target name: " . $targetname; } } return ''; }