コード例 #1
0
ファイル: Node.php プロジェクト: cnlangzi/wifidog-auth
 /**
  * Create a new Node in the database
  *
  * @param string $gw_id The Id of the gatewqay to be associated with
  * thisnode. If not present, a dummy value will be assigned.
  * @param object $network Network object.  The node's network.  If not
  *                        present, the current Network will be assigned
  *
  * @return mixed The newly created Node object, or null if there was
  *               an error
  *
  * @static
  * @access public
  */
 public static function createNewObject($gw_id = null, $network = null)
 {
     $db = AbstractDb::getObject();
     if (empty($gw_id)) {
         $gw_id = $db->escapeString(_('PUT_GATEWAY_ID_HERE'));
     } else {
         $gw_id = $db->escapeString($gw_id);
     }
     $node_id = get_guid();
     if (empty($network)) {
         $network = Network::getCurrentNetwork();
     }
     $network_id = $db->escapeString($network->getId());
     $node_deployment_status = $db->escapeString("IN_PLANNING");
     $node_name = _("New node");
     $duplicate = null;
     try {
         $duplicate = Node::getObjectByGatewayId($gw_id);
     } catch (Exception $e) {
     }
     if ($duplicate) {
         throw new Exception(sprintf(_('Sorry, a node for the gateway %s already exists.'), $gw_id));
     }
     $sql = "INSERT INTO nodes (node_id, gw_id, network_id, creation_date, node_deployment_status, name) VALUES ('{$node_id}', '{$gw_id}', '{$network_id}', CURRENT_TIMESTAMP,'{$node_deployment_status}', '{$node_name}')";
     if (!$db->execSqlUpdate($sql, false)) {
         throw new Exception(_('Unable to insert new node into database!'));
     }
     HotspotGraphElement::createNewObject($node_id, 'Node', $network);
     $object = self::getObject($node_id);
     return $object;
 }
コード例 #2
0
ファイル: Network.php プロジェクト: cnlangzi/wifidog-auth
 /**
  * Create a new Network object in the database
  *
  * @param string $network_id The network id of the new network.  If absent,
  *                           will be assigned a guid.
  *
  * @return mixed The newly created object, or null if there was an error
  *
  * @see GenericObject
  * @static
  * @access public
  */
 public static function createNewObject($network_id = null)
 {
     $db = AbstractDb::getObject();
     if (empty($network_id)) {
         $network_id = get_guid();
     }
     $network_id = $db->escapeString($network_id);
     $sql = "INSERT INTO networks (network_id, network_authenticator_class) VALUES ('{$network_id}', 'AuthenticatorLocalUser')";
     if (!$db->execSqlUpdate($sql, false)) {
         throw new Exception(_('Unable to insert the new network in the database!'));
     }
     HotspotGraphElement::createNewObject($network_id, 'Network');
     $object = self::getObject($network_id);
     require_once 'classes/Stakeholder.php';
     Stakeholder::add(null, Role::getObject('NETWORK_OWNER'), $object);
     return $object;
 }
コード例 #3
0
ファイル: NodeGroup.php プロジェクト: cnlangzi/wifidog-auth
 /**
  * Create a new Node group in the database
  *
  * @param string $ng_name The name of the new node group to create.  If empty a dummy value will be set
  * @param object $network Network object.  The node's network.  If not
  *                        present, the current Network will be assigned
  *
  * @return mixed The newly created Node Group object, or null if there was
  *               an error
  *
  * @static
  * @access public
  */
 public static function createNewObject($ng_name = null, $network = null)
 {
     $db = AbstractDb::getObject();
     if (empty($ng_name)) {
         $ng_name = $db->escapeString(_('New node group name'));
     } else {
         $ng_name = $db->escapeString($ng_name);
     }
     $node_group_id = get_guid();
     if (empty($network)) {
         $network = Network::getCurrentNetwork();
     }
     $network_id = $db->escapeString($network->getId());
     $duplicate = null;
     try {
         $duplicate = NodeGroup::getObjectByName($ng_name);
     } catch (Exception $e) {
     }
     if ($duplicate) {
         throw new Exception(sprintf(_('Sorry, a node group with the name %s already exists.'), $ng_name));
     }
     $sql = "INSERT INTO node_groups (node_group_id, name) VALUES ('{$node_group_id}', '{$ng_name}')";
     if (!$db->execSqlUpdate($sql, false)) {
         throw new Exception(_('Unable to insert new node group into database!'));
     }
     HotspotGraphElement::createNewObject($node_group_id, 'NodeGroup', $network);
     $object = self::getObject($node_group_id);
     return $object;
 }