Ejemplo n.º 1
0
 public function _StoreNodeNetwork($pSource, $pMethods, $pDescription, $pVersion, $pTrusted = array(), $pDiscovered = array(), $pBlocked = array())
 {
     if (!$pTrusted) {
         $pTrusted = array();
     }
     if (!$pDiscovered) {
         $pDiscovered = array();
     }
     if (!$pBlocked) {
         $pBlocked = array();
     }
     $nodes = $this->_CachedNodeInformation;
     $inherit = false;
     $All = array_unique(array_merge($pTrusted, $pDiscovered, $pBlocked));
     $NodeNetwork = array_merge($this->_CachedNodeNetwork[0], $this->_CachedNodeNetwork[1], $this->_CachedNodeNetwork[2]);
     $NodeNetwork = array_map("strtolower", $NodeNetwork);
     $model = new cModel('NetworkNodes');
     // Update the recieved information
     if (in_array(strtolower($pSource), $NodeNetwork)) {
         $model->Retrieve(array('Domain' => $pSource));
         $model->Fetch();
         $model->Set('Description', $pDescription);
         $model->Set('Methods', $pMethods);
         $model->Set('Version', $pVersion);
         $model->Set('Updated', NOW());
         $model->Set('Contacted', NOW());
         $model->Set('Status', true);
         $model->Save();
     } else {
         $model->Destroy('Node_PK');
         $model->Set('Description', $pDescription);
         $model->Set('Domain', $pSource);
         $model->Set('Source', $pSource);
         $model->Set('Methods', $pMethods);
         $model->Set('Inherit', false);
         $model->Set('Trust', 'discovered');
         $model->Set('Access', 'public');
         $model->Set('Created', NOW());
         $model->Set('Updated', NOW());
         $model->Set('Contacted', NOW());
         $model->Set('Version', $pVersion);
         $model->Set('Status', true);
         $model->Save();
     }
     foreach ($nodes as $n => $node) {
         // Check if we are inheriting this source's values.
         if ($node['Domain'] == $pSource) {
             if ($node['Inherit'] == true) {
                 $inherit = true;
             }
         }
         if (in_array(strtolower($node['Domain']), $pTrusted) or in_array(strtolower($node['Domain']), $pDiscovered) or in_array(strtolower($node['Domain']), $pBlocked)) {
             $update[$node['Node_PK']] = $node['Domain'];
         }
         if (!in_array(strtolower($node['Domain']), $All)) {
             $insert[] = $node['Domain'];
         }
     }
     // Add the trusted nodes.
     foreach ($pTrusted as $t => $trusted) {
         if (strtolower($trusted) == strtolower(QUICKSOCIAL_DOMAIN)) {
             continue;
         }
         if (strtolower($trusted) == 'localhost') {
             continue;
         }
         if (strtolower($trusted) == '127.0.0.1') {
             continue;
         }
         // Update the recieved information
         if (!in_array(strtolower($trusted), $NodeNetwork)) {
             $model->Destroy('Node_PK');
             $model->Set('Description', null);
             $model->Set('Domain', $trusted);
             $model->Set('Source', $pSource);
             $model->Set('Methods', null);
             $model->Set('Inherit', false);
             if ($inherit) {
                 $model->Set('Trust', 'trusted');
             } else {
                 $model->Set('Trust', 'discovered');
             }
             $model->Set('Access', 'public');
             $model->Set('Created', NOW());
             $model->Set('Updated', NOW());
             $model->Set('Contacted', NOW());
             $model->Set('Version', null);
             $model->Set('Status', false);
             $model->Save();
         }
     }
     // Add the discovered nodes.
     foreach ($pDiscovered as $d => $discovered) {
         if (strtolower($discovered) == strtolower(QUICKSOCIAL_DOMAIN)) {
             continue;
         }
         if (strtolower($discovered) == 'localhost') {
             continue;
         }
         if (strtolower($discovered) == '127.0.0.1') {
             continue;
         }
         // Update the recieved information
         if (!in_array(strtolower($discovered), $NodeNetwork)) {
             $model->Destroy('Node_PK');
             $model->Set('Description', null);
             $model->Set('Domain', $discovered);
             $model->Set('Source', $pSource);
             $model->Set('Methods', null);
             $model->Set('Inherit', false);
             $model->Set('Trust', 'discovered');
             $model->Set('Access', 'public');
             $model->Set('Created', NOW());
             $model->Set('Updated', NOW());
             $model->Set('Contacted', NOW());
             $model->Set('Version', null);
             $model->Set('Status', false);
             $model->Save();
         }
     }
     // Only add the blocked nodes if we're inheriting.
     if ($inherit) {
         // Add the blocked nodes.
         foreach ($pBlocked as $b => $blocked) {
             if (strtolower($blocked) == strtolower(QUICKSOCIAL_DOMAIN)) {
                 continue;
             }
             if (strtolower($blocked) == 'localhost') {
                 continue;
             }
             if (strtolower($blocked) == '127.0.0.1') {
                 continue;
             }
             // Update the recieved information
             if (in_array(strtolower($blocked), $NodeNetwork)) {
                 $model->Retrieve(array('Domain' => $blocked));
                 $model->Fetch();
                 $model->Set('Trust', 'blocked');
                 $model->Save();
             } else {
                 $model->Destroy('Node_PK');
                 $model->Set('Description', null);
                 $model->Set('Domain', $blocked);
                 $model->Set('Source', $pSource);
                 $model->Set('Methods', null);
                 $model->Set('Inherit', false);
                 $model->Set('Trust', 'blocked');
                 $model->Set('Access', 'public');
                 $model->Set('Created', NOW());
                 $model->Set('Updated', NOW());
                 $model->Set('Contacted', NOW());
                 $model->Set('Version', null);
                 $model->Set('Status', false);
                 $model->Save();
             }
         }
     }
     // For some reason, duplicate entries are getting created.  For now, delete duplicates.
     $query = "\n\t\t\tDELETE FROM #__NetworkNodes\n\t\t\t\tUSING #__NetworkNodes, #__NetworkNodes as vtable\n\t\t\t\tWHERE (#__NetworkNodes.Node_PK > vtable.Node_PK)\n\t\t\t\tAND (#__NetworkNodes.Domain=vtable.Domain);\n\t\t";
     $model->Query($query);
     return true;
 }