Beispiel #1
0
 public function discoverNow($reloadWhat = null, $force = false, $quiet = false)
 {
     $last = mUserdata::getGlobalSettingValue("UPnPLastDiscover", 0);
     if (time() - $last < 3600 * 3.5 and !$force) {
         return;
     }
     $C = new phpUPnP();
     $result = $C->mSearch();
     #print_r($result);
     if (!$quiet) {
         echo "<p>Gefundene Geräte:</p>";
     }
     #$locations = array();
     $L = new HTMLList();
     $L->addListStyle("list-style-type:none;");
     $foundLocations = array();
     #echo "<pre style=\"padding:5px;font-size:9px;overflow:auto;height:400px;\">";
     #print_r($result);
     #echo "</pre>";
     foreach ($result as $r) {
         if (isset($foundLocations[$r["location"]])) {
             continue;
         }
         $info = file_get_contents($r["location"]);
         if ($info === false) {
             continue;
         }
         $xml = new SimpleXMLElement($info);
         $services = array();
         foreach ($xml->device->serviceList->service as $service) {
             foreach (self::$desiredServices as $k => $S) {
                 if ($service->serviceId[0] == $S) {
                     $services[$k] = $service;
                 }
             }
         }
         #echo "<pre>";
         #print_r($xml->device->UDN);
         #echo "</pre>";
         $F = new Factory("UPnP");
         $F->sA("UPnPUDN", $xml->device->UDN);
         $L->addItem($xml->device->friendlyName);
         $U = $F->exists(true);
         if ($U !== false) {
             $U->changeA("UPnPLocation", $r["location"]);
             #$U->changeA("UPnPName", $xml->device->friendlyName);
             $U->changeA("UPnPModelName", $xml->device->modelName);
             $U->changeA("UPnPUDN", $xml->device->UDN);
             foreach (self::$desiredServices as $S => $nil) {
                 $U->changeA("UPnP{$S}", 0);
             }
             foreach ($services as $S => $service) {
                 $U->changeA("UPnP{$S}", 1);
                 $U->changeA("UPnP" . $S . "SCPDURL", $service->SCPDURL[0] . "");
                 $U->changeA("UPnP" . $S . "controlURL", $service->controlURL[0] . "");
             }
             #echo "save";
             $U->saveMe();
         } else {
             $F->sA("UPnPLocation", $r["location"]);
             $F->sA("UPnPName", $xml->device->friendlyName);
             $F->sA("UPnPModelName", $xml->device->modelName);
             foreach (self::$desiredServices as $S => $nil) {
                 $F->sA("UPnP{$S}", 0);
             }
             foreach ($services as $S => $service) {
                 $F->sA("UPnP{$S}", 1);
                 $F->sA("UPnP" . $S . "SCPDURL", $service->SCPDURL[0] . "");
                 $F->sA("UPnP" . $S . "controlURL", $service->controlURL[0] . "");
             }
             #echo "store";
             $F->store();
         }
         $foundLocations[$r["location"]] = true;
     }
     $AC = anyC::get("UPnP");
     while ($U = $AC->getNextEntry()) {
         if (!isset($foundLocations[$U->A("UPnPLocation")])) {
             $U->deleteMe();
         }
     }
     if (!$quiet) {
         echo $L;
     }
     $B = new Button("OK", "bestaetigung");
     $B->style("float:right;margin:10px;");
     if ($reloadWhat == "targets") {
         $B->onclick(OnEvent::closePopup("mUPnP") . " UPnP.targetSelection();");
     }
     if ($reloadWhat == "sources") {
         $B->onclick(OnEvent::closePopup("mUPnP") . " UPnP.sourceSelection();");
     }
     if ($reloadWhat) {
         echo $B . "<div style=\"clear:both;\"></div>";
     }
     mUserdata::setUserdataS("UPnPLastDiscover", time(), "", -1);
     #echo "</pre>";
 }
Beispiel #2
0
<?php

if (isset($argv[1])) {
    $_GET["cloud"] = $argv[1];
}
if (isset($argv[2])) {
    $_SERVER["HTTP_HOST"] = $argv[2];
}
session_name("ExtConnUPnPServer");
require_once realpath(dirname(__FILE__) . "/../../system/connect.php");
registerClassPath("phpUPnP", dirname(__FILE__) . "/phpUPnP.class.php");
$S = new phpUPnP();
$S->mServer();