function getUrl()
 {
     $remoteNode = sotf_Node::getNodeById($this->get('node_id'));
     if ($remoteNode) {
         return $remoteNode->get('url');
     }
     return $this->get('pending_url');
 }
 /** static */
 function getHomeNodeRootUrl($obj)
 {
     if ($obj->isLocal()) {
         global $config;
         return $config['rootUrl'];
     } else {
         $node = sotf_Node::getNodeById($obj->getNodeId());
         if (!$node) {
             raiseError("Could not find home node for programme: " . $obj->id);
         }
         return $node->get('url');
     }
 }
 function addProg($prg, $fileid = '')
 {
     if (empty($fileid)) {
         // find a file to listen
         $fileid = $prg->selectFileToListen();
         if (!$fileid) {
             raiseError("no_file_to_listen");
         }
     }
     $file = new sotf_NodeObject("sotf_media_files", $fileid);
     if (!$prg->isLocal()) {
         $node = sotf_Node::getNodeById($file->getNodeId());
         $path = $node->get('url') . "/listen.php?id=" . $prg->id . "&fileid=" . $file->id;
         $this->add(array('path' => $path, 'url' => $path));
         return;
     }
     if ($prg->get('published') != 't' || $file->get('stream_access') != 't') {
         raiseError("no_listen_access");
     }
     $filepath = $prg->getFilePath($file);
     $index = sotf_AudioCheck::getRequestIndex(new sotf_AudioFile($filepath));
     debug("audio index", $index);
     if (!$index) {
         $index = '0';
     }
     // add jingle for station (if exists)
     $station = $prg->getStation();
     $jfile = $station->getJingle($index);
     if ($jfile) {
         $this->add(array('id' => $station->id, 'path' => $jfile, 'jingle' => 1, 'name' => 'station_jingle'));
     }
     // add jingle for series (if exists)
     $series = $prg->getSeries();
     if ($series) {
         $jfile = $series->getJingle($index);
         if ($jfile) {
             $this->add(array('id' => $series->id, 'path' => $jfile, 'jingle' => 1, 'name' => 'series_jingle'));
         }
     }
     // add program file
     $filepath = $prg->getFilePath($file);
     $this->add(array('id' => $prg->id, 'path' => $filepath, 'name' => urlencode($prg->get('title'))));
     // temp: set title
     $title = $prg->get("title");
     $title = preg_replace('/\\s+/', '_', $title);
     $this->name = urlencode($title);
     // save stats
     $prg->addStat($file->get('id'), 'listens');
 }
Example #4
0
    $page->addStatusMsg($msg, false);
    $page->redirect("admin.php");
    exit;
}
// generate output
$localNode = sotf_Node::getLocalNode();
if (!$localNode) {
    $localNode = new sotf_Node();
    $localNode->set('node_id', $nodeId);
    $localNode->set('name', $nodeName);
    $localNode->set('url', $rootdir);
    $localNode->create();
}
$smarty->assign("LOCAL_NODE", $localNode->getAll());
// nodes
//$nodes = sotf_Node::countAll();
//$smarty->assign('NODES',$nodeData);
// neighbours
$neighbours = sotf_Neighbour::listAll();
while (list(, $nei) = each($neighbours)) {
    $node = sotf_Node::getNodeById($nei->get('node_id'));
    $data = $nei->getAll();
    if ($node) {
        $data['node'] = $node->getAll();
    }
    $neighbourData[] = $data;
}
$smarty->assign('NEIGHBOURS', $neighbourData);
// user permissions: editors and managers
$smarty->assign('PERMISSIONS', $permissions->listUsersAndPermissionsLocalized('node'));
$page->send();
require "init.inc.php";
$smarty->assign('PAGETITLE', $page->getlocalized('AdminPage'));
$page->forceLogin();
$page->popup = true;
$page->errorURL = "createNeighbour.php";
if (!hasPerm('node', "change")) {
    raiseError("You have no permission to change node settings!");
}
$url = sotf_Utils::getParameter('url');
$nid = sotf_Utils::getParameter('node_id');
//
$createNew = sotf_Utils::getParameter('create_new_node');
if ($createNew) {
    if (!$url) {
        $page->addStatusMsg('no_url_given');
    } elseif (sotf_Node::getNodeById($nid)) {
        $page->addStatusMsg('node_id_occupied');
    } else {
        $neighbor = new sotf_Neighbour();
        $neighbor->set('node_id', $nid);
        $neighbor->set('use_for_outgoing', 'f');
        $neighbor->set('accept_incoming', 't');
        $neighbor->set('pending_url', $url);
        $neighbor->create();
        $page->redirect("closeAndRefresh.php?anchor=network");
        exit;
    }
    $page->redirect("createNeighbour.php?node_id={$nid}&url=" . urlencode($url) . "#network");
    exit;
}
// generate output
function forwardResp($params)
{
    debug("incoming FORWARD request");
    $chunkInfo = xmlrpc_decoder($params->getParam(0));
    $fromNode = $chunkInfo['from_node'];
    $objects = xmlrpc_decoder($params->getParam(1));
    $node = sotf_Node::getNodeById($fromNode);
    if (!$node) {
        logError("No access: you are not in my node list!");
        return new xmlrpcresp(0, XMLRPC_ERR_NO_ACCESS, "No access: you are not in my node list!");
    }
    $msg = checkAccess($node->get('url'), $fromNode);
    if ($msg) {
        logError($msg);
        return new xmlrpcresp(0, XMLRPC_ERR_NO_ACCESS, "No access: {$msg}!");
    }
    $retval = $node->forwardResponse($chunkInfo, $objects);
    // send response
    $retval = xmlrpc_encoder($retval);
    return new xmlrpcresp($retval);
}
 function sync($console = false)
 {
     global $db, $page, $config;
     $remoteId = $this->get('node_id');
     if (!$console && $this->get('use_for_outgoing') != 't') {
         debug("node {$remoteId} is not used for outgoing sync");
         return;
     }
     debug("SYNCing with ", $this->get("node_id"));
     $rpc = new rpc_Utils();
     if ($config['debug']) {
         $rpc->debug = true;
     }
     $timestamp = $db->getTimestampTz();
     $url = $this->getUrl();
     // remove trailing '/'
     while (substr($url, -1) == '/') {
         $url = substr($url, 0, -1);
     }
     // collect local data to send
     $localNode = sotf_Node::getLocalNode();
     // check if url is correct...
     if ($localNode->get('url') != $config['rootUrl']) {
         $localNode->set('url', $config['rootUrl']);
         $localNode->update();
     }
     //debug("localNode", $localNode);
     //debug("neighbour", $this);
     $localNodeData = $localNode->getAll();
     // calculate chunking
     $thisChunk = 1;
     // do XML-RPC conversation
     $objectsSent = 0;
     $more = sotf_NodeObject::countModifiedObjects($remoteId);
     if (!$more) {
         debug("No new objects to send");
     }
     while ($more) {
         $db->begin(true);
         $modifiedObjects = sotf_NodeObject::getModifiedObjects($remoteId, $this->objectsPerRPCRequest);
         $remaining = sotf_NodeObject::countModifiedObjects($remoteId);
         if (count($modifiedObjects) == 0 && $remaining > 0) {
             logError("DATA integrity problem", "{$remaining} objects remained in sotf_object_status after sync");
         }
         if ($remaining == 0 || count($modifiedObjects) == 0) {
             $more = false;
         } else {
             $more = true;
         }
         $chunkInfo = array('this_chunk' => $thisChunk, 'node' => $localNodeData, 'objects_remaining' => $remaining);
         debug("chunk info", $chunkInfo);
         debug("number of sent objects", count($modifiedObjects));
         $objectsSent = $objectsSent + count($modifiedObjects);
         $objs = array($chunkInfo, $modifiedObjects);
         $response = $rpc->call($url . "/xmlrpcServer.php/sync/{$thisChunk}", 'sotf.sync', $objs);
         // error handling
         $replyInfo = $response[0];
         debug("replyInfo", $replyInfo);
         if (is_null($response) || $replyInfo['error']) {
             $this->set('errors', $this->get('errors') + 1);
             $this->update();
             $db->rollback();
             return;
         }
         $db->commit();
         // save received data
         $thisChunk++;
     }
     debug("total number of objects sent", $objectsSent);
     //$this->log($console, "number of updated objects: " .count($updatedObjects));
     // save node and neighbour stats
     if ($error) {
         $this->set('errors', $this->get('errors') + 1);
     } else {
         $this->set('success', $this->get('success') + 1);
     }
     $this->set('last_sync_out', $timestamp);
     $localNode->set('last_sync_out', $timestamp);
     // take out from pending nodes
     if ($this->get('pending_url')) {
         $remoteNode = sotf_Node::getNodeById($remoteId);
         // TODO: problem is that if this is first sync or one-way connection, then object fro remote node may not exist
         if ($remoteNode) {
             $this->set('pending_url', '');
         }
         $localNode->set('neighbours', $this->getNeighbourString());
     }
     $this->update();
     $localNode->update();
 }
 * $Id: editNeighbour.php 339 2003-12-03 08:39:25Z andras $
 * Created for the StreamOnTheFly project (IST-2001-32226)
 * Authors: András Micsik, Máté Pataki, Tamás Déri 
 *          at MTA SZTAKI DSD, http://dsd.sztaki.hu
 */
require "init.inc.php";
$smarty->assign('PAGETITLE', $page->getlocalized('AdminPage'));
$page->forceLogin();
$page->popup = true;
$page->errorURL = "editNeighbour.php";
checkPerm('node', "change");
$nid = sotf_Utils::getParameter('nodeid');
$nei = sotf_Neighbour::getById($nid);
if (!$nei) {
    raiseError("No such node: {$nid}");
}
// save changes
if (sotf_Utils::getParameter('save')) {
    $nei->set('use_for_outgoing', sotf_Utils::getParameter('use_out') ? 't' : 'f');
    $nei->set('accept_incoming', sotf_Utils::getParameter('use_in') ? 't' : 'f');
    $nei->update();
    $page->redirect("closeAndRefresh.php?anchor=network");
    exit;
}
// generate output
$node = sotf_Node::getNodeById($nid);
if ($node) {
    $smarty->assign('NODE', $node->getAll());
}
$smarty->assign('NEI', $nei->getAll());
$page->sendPopup();
 /** 
  * @method static getLocalNode
  */
 function getLocalNode()
 {
     global $db, $nodeId;
     return sotf_Node::getNodeById($nodeId);
 }
 /** 
  * @method static getLocalNode
  */
 function getLocalNode()
 {
     global $db, $config;
     return sotf_Node::getNodeById($config['nodeId']);
 }