Example #1
0
 /** 
  * read subnets 
  */
 public function readSubnets()
 {
     //init subnet class
     $subnet = new Subnet();
     //set IP address format
     $subnet->format = $this->_params['format'];
     //get all subnets
     if ($this->_params['all']) {
         $subnet->all = true;
     } elseif ($this->_params['sectionId']) {
         $subnet->sectionId = $this->_params['sectionId'];
     } else {
         $subnet->id = $this->_params['id'];
     }
     //fetch results
     $res = $subnet->getSubnet();
     //return subnet(s) in array format
     return $res;
 }
Example #2
0
 /** 
  * delete subnet 
  */
 public function deleteSubnets()
 {
     //init subnet class
     $subnet = new Subnet();
     //provide id
     $subnet->id = $this->_params['id'];
     //delete also IPs?
     if (isset($this->_params['addresses'])) {
         if ($this->_params['addresses'] == false) {
             $subnet->addresses = false;
         } else {
             $subnet->addresses = true;
         }
     } else {
         $subnet->addresses = true;
     }
     //fetch results
     $res = $subnet->deleteSubnet();
     //return subnet(s) in array format
     return $res;
 }
 public function postAssignIP()
 {
     try {
         $user_id = Input::get('user_id', 0);
         $ip_id = Input::get('framed_ip', 0);
         Subnet::AssignIP($user_id, $ip_id);
         $this->notifySuccess("IP Assigned.");
     } catch (Exception $e) {
         $this->notifyError($e->getMessage());
         return Redirect::route('subscriber.services', $user_id);
     }
     return Redirect::route('subscriber.services', $user_id);
 }
 public static function remove($id)
 {
     DB::transaction(function () use($id) {
         $subnet = Subnet::findOrFail($id);
         $q = SubnetIP::where('subnet_id', $subnet->id)->whereNotNull('user_id');
         $count = $q->count();
         if ($count > 0) {
             throw new Exception("<b>CANNOT DELETE</b>. {$count} accounts have IPs from this subnet.");
         }
         if (!$subnet->delete()) {
             throw new Exception("Failed to delete subnet");
         }
         $q = SubnetIP::where('subnet_id', $subnet->id);
         if ($q->count() > 0 && !$q->delete()) {
             throw new Exception("Failed to delete associated IP range.");
         }
     });
 }
Example #5
0
 /**
  *	delete Section
  *		id must be provided
  *
  *		we must also delete all subnets and all IP addresses!
  */
 public function deleteSection()
 {
     //check input
     $this->Common->check_var("int", $this->id, null);
     //verify that it exists
     try {
         $this->readSection();
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
     }
     //do we need to delete also subnets?
     if ($this->subnets) {
         $Subnet = new Subnet();
         # get all belonging subnets
         $Subnet->sectionId = $this->id;
         $Subnet->addresses = $this->addresses;
         //flag to delete also IPs
         try {
             $allsubnets = $Subnet->readSubnet();
         } catch (Exception $e) {
             # empty?
             if (substr($e->getMessage(), 0, 32) == "Invalid section Id or no subnets") {
             } else {
                 throw new Exception($e->getMessage());
             }
         }
         # loop
         if (sizeof($allsubnets) > 0) {
             foreach ($allsubnets as $s) {
                 # provide id and parameters
                 $Subnet->id = $s['id'];
                 $Subnet->deleteSubnet();
             }
         }
     }
     //set query and execute
     $this->query = "delete from `sections` where `id` = " . $this->id . ";";
     $this->executeQuery();
     //set result
     $result['result'] = "success";
     $result['response'] = "section " . $this->id . " deleted successfully!";
     //return result
     return $result;
 }