From 2eb2d5ecac5231f3c02fc396e0730e45ab94b410 Mon Sep 17 00:00:00 2001 From: sogaoh Date: Sun, 10 Jun 2018 00:06:40 +0900 Subject: [PATCH 01/16] adjust - file names - indents delete - default? source files --- .gitignore | 2 + README.md | 10 +- {screenshots => _doc/screenshots}/Hosts1.png | Bin {screenshots => _doc/screenshots}/Hosts2.png | Bin .../screenshots}/Networks1.png | Bin application/controllers/Cidr.php | 43 + application/controllers/Hello.php | 19 - application/controllers/Hosts.php | 245 +++-- application/controllers/Networks.php | 306 +++--- application/controllers/Note.php | 19 +- application/controllers/Pages.php | 10 +- application/controllers/Private_address.php | 40 + application/controllers/Test.php | 10 - application/controllers/Top.php | 59 +- application/controllers/View.php | 13 +- application/controllers/Welcome.php | 25 - application/controllers/cidr.php | 36 - application/controllers/private_address.php | 36 - application/helpers/myip_helper.php | 2 +- application/models/Ipam.php | 86 +- application/views/cidr_view.php | 926 ++++++++++++------ application/views/home.php | 14 - application/views/hosts_csv.php | 227 ++--- application/views/hosts_view.php | 479 +++++---- application/views/networks_csv.php | 221 ++--- application/views/networks_view.php | 4 +- application/views/private_address_view.php | 88 +- application/views/top_view.php | 43 +- application/views/view.php | 12 - application/views/welcome_message.php | 89 -- 30 files changed, 1588 insertions(+), 1476 deletions(-) rename {screenshots => _doc/screenshots}/Hosts1.png (100%) rename {screenshots => _doc/screenshots}/Hosts2.png (100%) rename {screenshots => _doc/screenshots}/Networks1.png (100%) create mode 100644 application/controllers/Cidr.php delete mode 100644 application/controllers/Hello.php create mode 100644 application/controllers/Private_address.php delete mode 100644 application/controllers/Test.php delete mode 100644 application/controllers/Welcome.php delete mode 100644 application/controllers/cidr.php delete mode 100644 application/controllers/private_address.php delete mode 100644 application/views/home.php delete mode 100644 application/views/view.php delete mode 100644 application/views/welcome_message.php diff --git a/.gitignore b/.gitignore index b048aa2..06967d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.idea + uploads/*.csv sqlite/*.db diff --git a/README.md b/README.md index 09dd661..f71811e 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ This is very simple and very useful. ## Screenshots #### Screenshot1 -![Network1](screenshots/Networks1.png) +![Network1](_doc/screenshots/Networks1.png) #### Screenshot2 -![Hosts1](screenshots/Hosts1.png) +![Hosts1](_doc/screenshots/Hosts1.png) #### Screenshot3 -![Hosts2](screenshots/Hosts2.png) +![Hosts2](_doc/screenshots/Hosts2.png) ## Features @@ -24,7 +24,7 @@ This is very simple and very useful. ## Dependencies * PHP >= 5.3.7 (recommends PHP 5.4 or newer) -* Apache (Nginx etc) +* Apache * SQLite3 ## Using @@ -40,7 +40,7 @@ This is very simple and very useful. ## Installation - Download SimpeIPAM with GitHub -- Upload SimpeIPAM in Document Root in Nginx # /var/www/html/simpleipam +- Upload SimpeIPAM in Document Root in Apache # /var/www/html/simpleipam - Copy ipam.db.sample to ipam.db # sqlite/ipam.db diff --git a/screenshots/Hosts1.png b/_doc/screenshots/Hosts1.png similarity index 100% rename from screenshots/Hosts1.png rename to _doc/screenshots/Hosts1.png diff --git a/screenshots/Hosts2.png b/_doc/screenshots/Hosts2.png similarity index 100% rename from screenshots/Hosts2.png rename to _doc/screenshots/Hosts2.png diff --git a/screenshots/Networks1.png b/_doc/screenshots/Networks1.png similarity index 100% rename from screenshots/Networks1.png rename to _doc/screenshots/Networks1.png diff --git a/application/controllers/Cidr.php b/application/controllers/Cidr.php new file mode 100644 index 0000000..21b3bc1 --- /dev/null +++ b/application/controllers/Cidr.php @@ -0,0 +1,43 @@ +load->helper('url'); + $this->load->helper('form'); + //$this->load->helper('myip'); + + //library + //$this->load->library('session'); + //$this->load->library('csvimport'); + //$this->load->library('pagination'); + + //model + //$this->load->model('Ipam'); + } + + /** + * + */ + public function index() + { + $data["host_name"] = ""; //this is form in header + + $data['title'] = 'SimpleIPAM Cidr Note'; + $this->load->view('template/header', $data); + $this->load->view('cidr_view'); + $this->load->view('template/footer'); + } + +} diff --git a/application/controllers/Hello.php b/application/controllers/Hello.php deleted file mode 100644 index a561aeb..0000000 --- a/application/controllers/Hello.php +++ /dev/null @@ -1,19 +0,0 @@ -"; - echo "$param2
"; - } -} -?> diff --git a/application/controllers/Hosts.php b/application/controllers/Hosts.php index f3bc402..53484b1 100644 --- a/application/controllers/Hosts.php +++ b/application/controllers/Hosts.php @@ -1,19 +1,21 @@ load->helper('url'); $this->load->helper('form'); $this->load->helper('myip'); //$this->load->helper(array('form','url')); - + //library - $this->load->library('session'); + $this->load->library('session'); $this->load->library('csvimport'); $this->load->library('pagination'); @@ -23,10 +25,10 @@ function __construct() { } - public function index() - { + public function index() + { - $data["host_name"]=""; + $data["host_name"] = ""; //pagination settings $config['base_url'] = site_url("hosts/search/NIL"); @@ -34,7 +36,7 @@ public function index() $data['total_rows'] = $config['total_rows']; $config['per_page'] = "5"; $config["uri_segment"] = 4; - $choice = $config["total_rows"]/$config["per_page"]; + $choice = $config["total_rows"] / $config["per_page"]; $config["num_links"] = floor($choice); // integrate bootstrap pagination @@ -64,34 +66,36 @@ public function index() $data['hosts'] = $this->Ipam->get_hosts($config["per_page"], $data['page'], NULL); $data['pagination'] = $this->pagination->create_links(); - + //$data['hosts'] =$this->Ipam->get_all_hosts(); $data['total_rows'] = $config['total_rows']; $data['start'] = $data['page'] + 1; - $data['end'] = $data['start'] + $config['per_page'] - 1 ; + $data['end'] = $data['start'] + $config['per_page'] - 1; - $data['title'] = 'SimpleIPAM Hosts'; - $this->load->view('template/header', $data); - $this->load->view('hosts_view'); - $this->load->view('template/footer'); - } + $data['title'] = 'SimpleIPAM Hosts'; + $this->load->view('template/header', $data); + $this->load->view('hosts_view'); + $this->load->view('template/footer'); + } function search() { - $data["host_name"]=""; //this is form in header + $data["host_name"] = ""; //this is form in header //input search // post - $search = ($this->input->post("host_name"))? $this->input->post("host_name") : "NIL"; + $search = ($this->input->post("host_name")) ? $this->input->post("host_name") : "NIL"; // get $search = ($this->uri->segment(3)) ? $this->uri->segment(3) : $search; // url encode for japanese - $search= urldecode($search); + $search = urldecode($search); + - - empty($search) ? $data["host_name"]="" : $data["host_name"]=$search; - if($search == "NIL" ){ $data["host_name"]=""; } + empty($search) ? $data["host_name"] = "" : $data["host_name"] = $search; + if ($search == "NIL") { + $data["host_name"] = ""; + } // pagination settings @@ -100,7 +104,7 @@ function search() $config['total_rows'] = $this->Ipam->get_hosts_count($search); $config['per_page'] = "5"; $config["uri_segment"] = 4; - $choice = $config["total_rows"]/$config["per_page"]; + $choice = $config["total_rows"] / $config["per_page"]; $config["num_links"] = floor($choice); // integrate bootstrap pagination @@ -132,58 +136,57 @@ function search() $data['total_rows'] = $config['total_rows']; $data['start'] = $data['page'] + 1; - $data['end'] = $data['start'] + $config['per_page'] - 1 ; + $data['end'] = $data['start'] + $config['per_page'] - 1; //load view - $data['title'] = 'SimpleIPAM Hosts'; - $this->load->view('template/header', $data); - $this->load->view('hosts_view', $data ); - $this->load->view('template/footer' ); + $data['title'] = 'SimpleIPAM Hosts'; + $this->load->view('template/header', $data); + $this->load->view('hosts_view', $data); + $this->load->view('template/footer'); + } + + + public function hosts_add() + { + $this->_validate(); + $data = array( + 'ip_address' => $this->input->post('ip_address'), + 'subnet_mask' => $this->input->post('subnet_mask'), + 'host' => $this->input->post('host'), + 'note' => $this->input->post('note'), + ); + $insert = $this->Ipam->hosts_add($data); + echo json_encode(array("status" => TRUE)); } - - public function hosts_add() - { + public function ajax_edit($id) + { + $data = $this->Ipam->hosts_get_by_id($id); + + echo json_encode($data); + } + + + public function hosts_update() + { $this->_validate(); - $data = array( - 'ip_address' => $this->input->post('ip_address'), - 'subnet_mask' => $this->input->post('subnet_mask'), - 'host' => $this->input->post('host'), - 'note' => $this->input->post('note'), - ); - $insert = $this->Ipam->hosts_add($data); - echo json_encode(array("status" => TRUE)); - } - - public function ajax_edit($id) - { - $data = $this->Ipam->hosts_get_by_id($id); - - echo json_encode($data); - } - - - public function hosts_update() - { - $this->_validate(); - $data = array( - 'ip_address' => $this->input->post('ip_address'), - 'subnet_mask' => $this->input->post('subnet_mask'), - 'host' => $this->input->post('host'), - 'note' => $this->input->post('note'), - ); - $this->Ipam->hosts_update(array('id' => $this->input->post('id')), $data); - echo json_encode(array("status" => TRUE)); - } - - - public function hosts_delete($id) - { - $this->Ipam->hosts_delete_by_id($id); - echo json_encode(array("status" => TRUE)); - } + $data = array( + 'ip_address' => $this->input->post('ip_address'), + 'subnet_mask' => $this->input->post('subnet_mask'), + 'host' => $this->input->post('host'), + 'note' => $this->input->post('note'), + ); + $this->Ipam->hosts_update(array('id' => $this->input->post('id')), $data); + echo json_encode(array("status" => TRUE)); + } + + public function hosts_delete($id) + { + $this->Ipam->hosts_delete_by_id($id); + echo json_encode(array("status" => TRUE)); + } private function _validate() @@ -192,16 +195,15 @@ private function _validate() $data['error_string'] = array(); $data['inputerror'] = array(); $data['status'] = TRUE; - - if($this->input->post('ip_address') == '') - { + + if ($this->input->post('ip_address') == '') { $data['inputerror'][] = 'ip_address'; $data['error_string'][] = 'IP Address is required'; $data['status'] = FALSE; } - $subnet_mask=$this->input->post('subnet_mask'); + $subnet_mask = $this->input->post('subnet_mask'); /* if (!is_numeric($subnet_mask)) { @@ -210,8 +212,7 @@ private function _validate() $data['status'] = FALSE; } */ - if($subnet_mask == '') - { + if ($subnet_mask == '') { $data['inputerror'][] = 'subnet_mask'; $data['error_string'][] = 'Subnet mask is required'; $data['status'] = FALSE; @@ -225,21 +226,19 @@ private function _validate() $data['status'] = FALSE; } */ - - if($this->input->post('host') == '') - { + + if ($this->input->post('host') == '') { $data['inputerror'][] = 'host'; $data['error_string'][] = 'host is required'; $data['status'] = FALSE; } - - if($data['status'] === FALSE) - { + + if ($data['status'] === FALSE) { echo json_encode($data); exit(); } - + } @@ -248,78 +247,76 @@ private function _validate() * CSV *====================================================== */ - public function csv() - { - $data["host_name"]=""; //this is form in header - $data['title'] = 'SimpleIPAM Hosts'; - - $this->load->view('template/header', $data); - $this->load->view('hosts_csv'); - $this->load->view('template/footer' ); - } - - public function export_csv() { - $file_name = 'hosts_'.date("Y-m-d h-i-s").'.csv'; - $delimiter = ","; + public function csv() + { + $data["host_name"] = ""; //this is form in header + $data['title'] = 'SimpleIPAM Hosts'; + + $this->load->view('template/header', $data); + $this->load->view('hosts_csv'); + $this->load->view('template/footer'); + } + + public function export_csv() + { + $file_name = 'hosts_' . date("Y-m-d h-i-s") . '.csv'; + $delimiter = ","; $newline = "\r\n"; $sql_order = " order by CAST(substr(trim(ip_address),1,instr(trim(ip_address),'.')-1) AS INTEGER), CAST(substr(substr(trim(ip_address),length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)) ,1, instr(substr(trim(ip_address),length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)),'.')-1) AS INTEGER), CAST(substr(substr(trim(ip_address),length(substr(substr(trim(ip_address),length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)) ,1, instr(substr(trim(ip_address),length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)),'.')))+length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)) ,1, instr(substr(trim(ip_address),length(substr(substr(trim(ip_address),length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)) ,1, instr(substr(trim(ip_address),length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)),'.')))+length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)),'.')-1) AS INTEGER), CAST(substr(trim(ip_address),length(substr(substr(trim(ip_address),length(substr(substr(trim(ip_address),length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)) ,1, instr(substr(trim(ip_address),length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)),'.')))+length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)) ,1, instr(substr(trim(ip_address),length(substr(substr(trim(ip_address),length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)) ,1, instr(substr(trim(ip_address),length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)),'.')))+length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)),'.')))+ length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+length(substr(substr(trim(ip_address),length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)) ,1, instr(substr(trim(ip_address),length(substr(trim(ip_address),1,instr(trim(ip_address),'.')))+1,length(ip_address)),'.')))+1,length(trim(ip_address))) AS INTEGER) "; - $query = $this->db->query('SELECT ip_address, subnet_mask, host, note FROM hosts WHERE 1'.$sql_order); - $this->load->dbutil(); - $data = $this->dbutil->csv_from_result($query, $delimiter, $newline); - $this->load->helper('download'); - force_download($file_name, $data); - exit(); - } + $query = $this->db->query('SELECT ip_address, subnet_mask, host, note FROM hosts WHERE 1' . $sql_order); + $this->load->dbutil(); + $data = $this->dbutil->csv_from_result($query, $delimiter, $newline); + $this->load->helper('download'); + force_download($file_name, $data); + exit(); + } - function import_csv() { + function import_csv() + { $data['error'] = ''; //initialize image upload error array to empty - + $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'csv'; $config['max_size'] = '50000'; //50,000KB = 50MB - + $this->load->library('upload', $config); - + // If upload failed, display error if (!$this->upload->do_upload()) { $data['error'] = $this->upload->display_errors(); - - $this->load->view('template/header', $data); - $this->load->view('hosts_csv', $data); - $this->load->view('template/footer' ); + + $this->load->view('template/header', $data); + $this->load->view('hosts_csv', $data); + $this->load->view('template/footer'); } else { $file_data = $this->upload->data(); - $file_path = './uploads/'.$file_data['file_name']; - + $file_path = './uploads/' . $file_data['file_name']; + if ($this->csvimport->get_array($file_path)) { $csv_array = $this->csvimport->get_array($file_path); foreach ($csv_array as $row) { $insert_data = array( - 'ip_address'=>$row['ip_address'], - 'subnet_mask'=>$row['subnet_mask'], - 'host'=>$row['host'], - 'note'=>$row['note'], + 'ip_address' => $row['ip_address'], + 'subnet_mask' => $row['subnet_mask'], + 'host' => $row['host'], + 'note' => $row['note'], ); $this->Ipam->hosts_insert_csv($insert_data); } $this->session->set_flashdata('success', 'Csv Data Imported Succesfully'); //redirect(base_url().'networks/export_csv'); //echo "
"; print_r($insert_data);
-            } else 
-				$data['error'] = "Error occured";
-				$this->load->view('template/header', $data);
-				$this->load->view('hosts_csv', $data);
-				$this->load->view('template/footer' );
+            } else
+                $data['error'] = "Error occured";
+            $this->load->view('template/header', $data);
+            $this->load->view('hosts_csv', $data);
+            $this->load->view('template/footer');
         }
         //echo "$file_path";
         unlink($file_path);
-	}    
-
-
-
-
+    }
 
 
 }
diff --git a/application/controllers/Networks.php b/application/controllers/Networks.php
index 3c7a738..0ffffce 100644
--- a/application/controllers/Networks.php
+++ b/application/controllers/Networks.php
@@ -1,19 +1,21 @@
 load->helper('url');
         $this->load->helper('form');
         $this->load->helper('myip');
         //$this->load->helper(array('form','url'));
-        
+
         //library
-		$this->load->library('session');
+        $this->load->library('session');
         $this->load->library('csvimport');
         $this->load->library('pagination');
 
@@ -23,10 +25,10 @@ function __construct() {
     }
 
 
-	public function index()
-	{
-        $data["host_name"]="";    //this is form in header
-        $data["network_name"]="";
+    public function index()
+    {
+        $data["host_name"] = "";    //this is form in header
+        $data["network_name"] = "";
 
         //pagination settings
         $config['base_url'] = site_url("networks/search/NIL");
@@ -34,7 +36,7 @@ public function index()
         $data['total_rows'] = $config['total_rows'];
         $config['per_page'] = "5";
         $config["uri_segment"] = 4;
-        $choice = $config["total_rows"]/$config["per_page"];
+        $choice = $config["total_rows"] / $config["per_page"];
         $config["num_links"] = floor($choice);
 
         // integrate bootstrap pagination
@@ -59,39 +61,41 @@ public function index()
         $this->pagination->initialize($config);
 
         $data['page'] = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
-        
+
         // get networks list
         $data['networks'] = $this->Ipam->get_networks($config["per_page"], $data['page'], NULL);
-        
+
         $data['pagination'] = $this->pagination->create_links();
 
         //$data['networks'] =$this->Ipam->get_all_networks();
 
         $data['total_rows'] = $config['total_rows'];
         $data['start'] = $data['page'] + 1;
-        $data['end'] = $data['start'] + $config['per_page'] - 1 ;
+        $data['end'] = $data['start'] + $config['per_page'] - 1;
 
-		$data['title'] = 'SimpleIPAM Networks';
-		$this->load->view('template/header', $data);
-		$this->load->view('networks_view', $data );
-		$this->load->view('template/footer' );
+        $data['title'] = 'SimpleIPAM Networks';
+        $this->load->view('template/header', $data);
+        $this->load->view('networks_view', $data);
+        $this->load->view('template/footer');
     }
-    
+
 
     function search()
     {
-        $data["host_name"]="";    //this is form in header
+        $data["host_name"] = "";    //this is form in header
         //input search
         // post
-        $search = ($this->input->post("network_name"))? $this->input->post("network_name") : "NIL";
+        $search = ($this->input->post("network_name")) ? $this->input->post("network_name") : "NIL";
         // get
         $search = ($this->uri->segment(3)) ? $this->uri->segment(3) : $search;
         // url encode for japanese
-        $search= urldecode($search);
+        $search = urldecode($search);
 
-        
-        empty($search) ? $data["network_name"]="" : $data["network_name"]=$search;
-        if($search == "NIL" ){ $data["network_name"]=""; }
+
+        empty($search) ? $data["network_name"] = "" : $data["network_name"] = $search;
+        if ($search == "NIL") {
+            $data["network_name"] = "";
+        }
 
 
         // pagination settings
@@ -100,7 +104,7 @@ function search()
         $config['total_rows'] = $this->Ipam->get_networks_count($search);
         $config['per_page'] = "5";
         $config["uri_segment"] = 4;
-        $choice = $config["total_rows"]/$config["per_page"];
+        $choice = $config["total_rows"] / $config["per_page"];
         $config["num_links"] = floor($choice);
 
         // integrate bootstrap pagination
@@ -132,61 +136,61 @@ function search()
 
         $data['total_rows'] = $config['total_rows'];
         $data['start'] = $data['page'] + 1;
-        $data['end'] = $data['start'] + $config['per_page'] - 1 ;
+        $data['end'] = $data['start'] + $config['per_page'] - 1;
 
 
         //load view
-		$data['title'] = 'SimpleIPAM Networks';
-		$this->load->view('template/header', $data);
-		$this->load->view('networks_view', $data );
-		$this->load->view('template/footer' );
+        $data['title'] = 'SimpleIPAM Networks';
+        $this->load->view('template/header', $data);
+        $this->load->view('networks_view', $data);
+        $this->load->view('template/footer');
+    }
+
+
+    public function networks_add()
+    {
+        $this->_validate();
+        $data = array(
+            'networks' => $this->input->post('networks'),
+            'cidr' => $this->input->post('cidr'),
+            'broadcast_address' => $this->input->post('broadcast_address'),
+            'vlan_id' => $this->input->post('vlan_id'),
+            'note1' => $this->input->post('note1'),
+            'note2' => $this->input->post('note2'),
+        );
+        $insert = $this->Ipam->networks_add($data);
+        echo json_encode(array("status" => TRUE));
+    }
+
+    public function ajax_edit($id)
+    {
+        $data = $this->Ipam->networks_get_by_id($id);
+
+        echo json_encode($data);
     }
 
-	
-	public function networks_add()
-	{
+
+    public function networks_update()
+    {
         $this->_validate();
-		$data = array(
-				'networks' => $this->input->post('networks'),
-				'cidr' => $this->input->post('cidr'),
-				'broadcast_address' => $this->input->post('broadcast_address'),
-				'vlan_id' => $this->input->post('vlan_id'),
-				'note1' => $this->input->post('note1'),
-				'note2' => $this->input->post('note2'),
-			);
-		$insert = $this->Ipam->networks_add($data);
-		echo json_encode(array("status" => TRUE));
-	}
-
-	public function ajax_edit($id)
-	{
-		$data = $this->Ipam->networks_get_by_id($id);
-
-		echo json_encode($data);
-	}
-
-
-	public function networks_update()
-	{
-    $this->_validate();
-	$data = array(
-		'networks' => $this->input->post('networks'),
-		'cidr' => $this->input->post('cidr'),
-		'broadcast_address' => $this->input->post('broadcast_address'),
-		'vlan_id' => $this->input->post('vlan_id'),
-		'note1' => $this->input->post('note1'),
-		'note2' => $this->input->post('note2'),
-		);
-	$this->Ipam->networks_update(array('id' => $this->input->post('id')), $data);
-	echo json_encode(array("status" => TRUE));
-	}
-
-
-	public function networks_delete($id)
-	{
-		$this->Ipam->networks_delete_by_id($id);
-		echo json_encode(array("status" => TRUE));
-	}
+        $data = array(
+            'networks' => $this->input->post('networks'),
+            'cidr' => $this->input->post('cidr'),
+            'broadcast_address' => $this->input->post('broadcast_address'),
+            'vlan_id' => $this->input->post('vlan_id'),
+            'note1' => $this->input->post('note1'),
+            'note2' => $this->input->post('note2'),
+        );
+        $this->Ipam->networks_update(array('id' => $this->input->post('id')), $data);
+        echo json_encode(array("status" => TRUE));
+    }
+
+
+    public function networks_delete($id)
+    {
+        $this->Ipam->networks_delete_by_id($id);
+        echo json_encode(array("status" => TRUE));
+    }
 
 
     private function _validate()
@@ -195,24 +199,21 @@ private function _validate()
         $data['error_string'] = array();
         $data['inputerror'] = array();
         $data['status'] = TRUE;
- 
-        if($this->input->post('networks') == '')
-        {
+
+        if ($this->input->post('networks') == '') {
             $data['inputerror'][] = 'networks';
             $data['error_string'][] = 'Networks is required';
             $data['status'] = FALSE;
         }
 
 
-        $cidr=$this->input->post('cidr');
-        if (!is_numeric($cidr))
-        {
+        $cidr = $this->input->post('cidr');
+        if (!is_numeric($cidr)) {
             $data['inputerror'][] = 'cidr';
             $data['error_string'][] = 'Cidr must be number';
             $data['status'] = FALSE;
         }
-        if($cidr == '')
-        {
+        if ($cidr == '') {
             $data['inputerror'][] = 'cidr';
             $data['error_string'][] = 'Cidr is required';
             $data['status'] = FALSE;
@@ -226,17 +227,15 @@ private function _validate()
             $data['status'] = FALSE;
         }
         */
- 
-        if($this->input->post('broadcast_address') == '')
-        {
+
+        if ($this->input->post('broadcast_address') == '') {
             $data['inputerror'][] = 'broadcast_address';
             $data['error_string'][] = 'Broadcast Address is required';
             $data['status'] = FALSE;
         }
 
- 
-        if($data['status'] === FALSE)
-        {
+
+        if ($data['status'] === FALSE) {
             echo json_encode($data);
             exit();
         }
@@ -247,81 +246,84 @@ private function _validate()
      * CSV
      *======================================================
     */
-	public function csv()
-	{
-        $data["host_name"]="";    //this is form in header
-		$data['title'] = 'SimpleIPAM Networks';
-
-		$this->load->view('template/header', $data);
-		$this->load->view('networks_csv');
-		$this->load->view('template/footer' );
-	}
-
-	public function export_csv() {
-		$file_name = 'networks_'.date("Y-m-d h-i-s").'.csv';
-		$delimiter = ",";
+    public function csv()
+    {
+        $data["host_name"] = "";    //this is form in header
+        $data['title'] = 'SimpleIPAM Networks';
+
+        $this->load->view('template/header', $data);
+        $this->load->view('networks_csv');
+        $this->load->view('template/footer');
+    }
+
+    public function export_csv()
+    {
+        $file_name = 'networks_' . date("Y-m-d h-i-s") . '.csv';
+        $delimiter = ",";
         $newline = "\r\n";
         $sql_order = " order by CAST(substr(trim(networks),1,instr(trim(networks),'.')-1) AS INTEGER), CAST(substr(substr(trim(networks),length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)) ,1, instr(substr(trim(networks),length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)),'.')-1) AS INTEGER), CAST(substr(substr(trim(networks),length(substr(substr(trim(networks),length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)) ,1, instr(substr(trim(networks),length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)),'.')))+length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)) ,1, instr(substr(trim(networks),length(substr(substr(trim(networks),length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)) ,1, instr(substr(trim(networks),length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)),'.')))+length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)),'.')-1) AS INTEGER), CAST(substr(trim(networks),length(substr(substr(trim(networks),length(substr(substr(trim(networks),length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)) ,1, instr(substr(trim(networks),length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)),'.')))+length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)) ,1, instr(substr(trim(networks),length(substr(substr(trim(networks),length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)) ,1, instr(substr(trim(networks),length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)),'.')))+length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)),'.')))+ length(substr(trim(networks),1,instr(trim(networks),'.')))+length(substr(substr(trim(networks),length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)) ,1, instr(substr(trim(networks),length(substr(trim(networks),1,instr(trim(networks),'.')))+1,length(networks)),'.')))+1,length(trim(networks))) AS INTEGER) ";
-		$query = $this->db->query('SELECT networks, cidr, broadcast_address, vlan_id, note1, note2 FROM networks WHERE 1'.$sql_order);
-		$this->load->dbutil();
-		$data = $this->dbutil->csv_from_result($query, $delimiter, $newline);
-		$this->load->helper('download');
-		force_download($file_name, $data);  
-		exit();
-	}
-
-	function import_csv() {
-        $data["host_name"]="";    //this is form in header
+        $query = $this->db->query('SELECT networks, cidr, broadcast_address, vlan_id, note1, note2 FROM networks WHERE 1' . $sql_order);
+        $this->load->dbutil();
+        $data = $this->dbutil->csv_from_result($query, $delimiter, $newline);
+        $this->load->helper('download');
+        force_download($file_name, $data);
+        exit();
+    }
+
+    function import_csv()
+    {
+        $data["host_name"] = "";    //this is form in header
         $data['error'] = '';    //initialize image upload error array to empty
- 
+
         $config['upload_path'] = './uploads/';
         $config['allowed_types'] = 'csv';
         $config['max_size'] = '50000';  //50,000KB = 50MB
- 
+
         $this->load->library('upload', $config);
- 
+
 
         // If upload failed, display error
         if (!$this->upload->do_upload()) {
             $data['error'] = $this->upload->display_errors();
- 
-			$this->load->view('template/header', $data);
-			$this->load->view('networks_csv', $data);
-			$this->load->view('template/footer' );
+
+            $this->load->view('template/header', $data);
+            $this->load->view('networks_csv', $data);
+            $this->load->view('template/footer');
         } else {
             $file_data = $this->upload->data();
-            $file_path =  './uploads/'.$file_data['file_name'];
- 
+            $file_path = './uploads/' . $file_data['file_name'];
+
             if ($this->csvimport->get_array($file_path)) {
                 $csv_array = $this->csvimport->get_array($file_path);
                 foreach ($csv_array as $row) {
                     $insert_data = array(
-                        'networks'=>$row['networks'],
-                        'cidr'=>$row['cidr'],
-						'broadcast_address'=>$row['broadcast_address'],
-						'vlan_id'=>$row['vlan_id'],
-						'note1'=>$row['note1'],
-						'note2'=>$row['note2'],
+                        'networks' => $row['networks'],
+                        'cidr' => $row['cidr'],
+                        'broadcast_address' => $row['broadcast_address'],
+                        'vlan_id' => $row['vlan_id'],
+                        'note1' => $row['note1'],
+                        'note2' => $row['note2'],
                     );
                     $this->Ipam->networks_insert_csv($insert_data);
                 }
                 $this->session->set_flashdata('success', 'Csv Data Imported Succesfully');
                 //redirect(base_url().'networks/export_csv');
                 //echo "
"; print_r($insert_data);
-            } else 
-				$data['error'] = "Error occured";
-				$this->load->view('template/header', $data);
-				$this->load->view('networks_csv', $data);
-                $this->load->view('template/footer' );
+            } else
+                $data['error'] = "Error occured";
+            $this->load->view('template/header', $data);
+            $this->load->view('networks_csv', $data);
+            $this->load->view('template/footer');
 
         }
         //echo "$file_path";
         unlink($file_path);
- 
-	}
 
- 
-     function importcsv_purge_add() {
+    }
+
+
+    function importcsv_purge_add()
+    {
         $data['error'] = '';    //initialize image upload error array to empty
         $config['upload_path'] = './uploads/';
         $config['allowed_types'] = 'csv';
@@ -336,33 +338,33 @@ function importcsv_purge_add() {
 
             $this->load->view('template/header', $data);
             $this->load->view('networks_csv', $data);
-            $this->load->view('template/footer' );
+            $this->load->view('template/footer');
         } else {
             $file_data = $this->upload->data();
-            $file_path =  './uploads/'.$file_data['file_name'];
+            $file_path = './uploads/' . $file_data['file_name'];
             if ($this->csvimport->get_array($file_path)) {
-                    //import csv
-                    $csv_array = $this->csvimport->get_array($file_path);
-                    foreach ($csv_array as $row) {
-                        $insert_data = array(
-                        'id'=>$row['id'],
-                        'networks'=>$row['networks'],
-                        'cidr'=>$row['cidr'],
-                        'broadcast_address'=>$row['broadcast_address'],
-                        'vlan_id'=>$row['vlan_id'],
-                        'note1'=>$row['note1'],
-                        'note2'=>$row['note2'],
+                //import csv
+                $csv_array = $this->csvimport->get_array($file_path);
+                foreach ($csv_array as $row) {
+                    $insert_data = array(
+                        'id' => $row['id'],
+                        'networks' => $row['networks'],
+                        'cidr' => $row['cidr'],
+                        'broadcast_address' => $row['broadcast_address'],
+                        'vlan_id' => $row['vlan_id'],
+                        'note1' => $row['note1'],
+                        'note2' => $row['note2'],
                     );
                     $this->Ipam->networks_insert_csv($insert_data);
                 }
                 $this->session->set_flashdata('success', 'Csv Data Imported Succesfully');
                 //redirect(base_url().'networks/export_csv');
                 //echo "
"; print_r($insert_data);
-            } else 
+            } else
                 $data['error'] = "Error occured";
-                $this->load->view('template/header', $data);
-                $this->load->view('networks_csv', $data);
-                $this->load->view('template/footer' );
+            $this->load->view('template/header', $data);
+            $this->load->view('networks_csv', $data);
+            $this->load->view('template/footer');
         }
     }
 
diff --git a/application/controllers/Note.php b/application/controllers/Note.php
index 88c741f..a9881e2 100644
--- a/application/controllers/Note.php
+++ b/application/controllers/Note.php
@@ -1,15 +1,16 @@
 load->helper('url');
+    public function index()
+    {
+        $this->load->helper('url');
 
-		$data['title'] = 'SimpleIPAM IP List';
-		$this->load->view('template/header', $data);
-		$this->load->view('result');
-		$this->load->view('template/footer');
-	}
+        $data['title'] = 'SimpleIPAM IP List';
+        $this->load->view('template/header', $data);
+        $this->load->view('result');
+        $this->load->view('template/footer');
+    }
 }
diff --git a/application/controllers/Pages.php b/application/controllers/Pages.php
index 3ecd566..7b4dbc6 100644
--- a/application/controllers/Pages.php
+++ b/application/controllers/Pages.php
@@ -1,7 +1,9 @@
 load->helper('url');
+        $this->load->helper('form');
+        //$this->load->helper('myip');
+
+        //library
+        //$this->load->library('session');
+        //$this->load->library('csvimport');
+        //$this->load->library('pagination');
+
+        //model
+        //$this->load->model('Ipam');
+    }
+
+    /**
+     *
+     */
+    public function index()
+    {
+        $data["host_name"] = "";     //this is form in header
+
+        $data['title'] = 'SimpleIPAM Private Address Note';
+        $this->load->view('template/header', $data);
+        $this->load->view('private_address_view');
+        $this->load->view('template/footer');
+    }
+
+}
diff --git a/application/controllers/Test.php b/application/controllers/Test.php
deleted file mode 100644
index 197eeaa..0000000
--- a/application/controllers/Test.php
+++ /dev/null
@@ -1,10 +0,0 @@
-load->view('welcome_message');
-	}
-}
diff --git a/application/controllers/Top.php b/application/controllers/Top.php
index 303626b..1534382 100644
--- a/application/controllers/Top.php
+++ b/application/controllers/Top.php
@@ -1,18 +1,22 @@
 load->helper('url');
         $this->load->helper('form');
         //$this->load->helper('myip');
-        
+
         //library
-		//$this->load->library('session');
+        //$this->load->library('session');
         //$this->load->library('csvimport');
         //$this->load->library('pagination');
 
@@ -20,34 +24,19 @@ function __construct() {
         //$this->load->model('Ipam');
     }
 
+    /**
+     *
+     */
+    public function index()
+    {
+        $data["host_name"] = "";     //this is form in header
+
+        $data['title'] = 'SimpleIPAM Top';
+        $this->load->view('template/header', $data);
+        $this->load->view('top_view');
+        $this->load->view('template/footer');
+
+
+    }
 
-	public function index()
-	{
-		$data["host_name"]="";     //this is form in header
-
-		$data['title'] = 'SimpleIPAM Top';
-		$this->load->view('template/header', $data);
-		$this->load->view('top_view');
-		$this->load->view('template/footer');
-
-
-	}
-
-	
-/*
-	public function result()
-	{
-		$data['title'] = 'SimpleIPAM Top';
-		$this->load->view('template/header', $data);
-		$this->load->view('result');
-		$this->load->view('template/footer');
-	}
-	public function note()
-	{
-		$data['title'] = 'SimpleIPAM Top';
-		$this->load->view('template/header', $data);
-		$this->load->view('note');
-		$this->load->view('template/footer');
-	}
-*/
 }
diff --git a/application/controllers/View.php b/application/controllers/View.php
index f645e0a..37a9403 100644
--- a/application/controllers/View.php
+++ b/application/controllers/View.php
@@ -1,12 +1,17 @@
 load->view('view', $data);
     }
 }
-?>
+
diff --git a/application/controllers/Welcome.php b/application/controllers/Welcome.php
deleted file mode 100644
index 9213c0c..0000000
--- a/application/controllers/Welcome.php
+++ /dev/null
@@ -1,25 +0,0 @@
-
-	 * @see https://codeigniter.com/user_guide/general/urls.html
-	 */
-	public function index()
-	{
-		$this->load->view('welcome_message');
-	}
-}
diff --git a/application/controllers/cidr.php b/application/controllers/cidr.php
deleted file mode 100644
index 723b489..0000000
--- a/application/controllers/cidr.php
+++ /dev/null
@@ -1,36 +0,0 @@
-load->helper('url');
-        $this->load->helper('form');
-        //$this->load->helper('myip');
-        
-        //library
-		//$this->load->library('session');
-        //$this->load->library('csvimport');
-        //$this->load->library('pagination');
-
-        //model
-        //$this->load->model('Ipam');
-    }
-
-
-	public function index()
-	{
-		$data["host_name"]="";     //this is form in header
-
-		$data['title'] = 'SimpleIPAM Private Address';
-		$this->load->view('template/header', $data);
-		$this->load->view('cidr_view');
-		$this->load->view('template/footer');
-
-
-	}
-
-}
diff --git a/application/controllers/private_address.php b/application/controllers/private_address.php
deleted file mode 100644
index 55e0204..0000000
--- a/application/controllers/private_address.php
+++ /dev/null
@@ -1,36 +0,0 @@
-load->helper('url');
-        $this->load->helper('form');
-        //$this->load->helper('myip');
-        
-        //library
-		//$this->load->library('session');
-        //$this->load->library('csvimport');
-        //$this->load->library('pagination');
-
-        //model
-        //$this->load->model('Ipam');
-    }
-
-
-	public function index()
-	{
-		$data["host_name"]="";     //this is form in header
-
-		$data['title'] = 'SimpleIPAM Private Address';
-		$this->load->view('template/header', $data);
-		$this->load->view('private_address_view');
-		$this->load->view('template/footer');
-
-
-	}
-
-}
diff --git a/application/helpers/myip_helper.php b/application/helpers/myip_helper.php
index a7da6ed..3f7df89 100644
--- a/application/helpers/myip_helper.php
+++ b/application/helpers/myip_helper.php
@@ -13,7 +13,7 @@
  */
 
    /**
-     * get only host address from IP adress
+     * get only host address from IP address
      *
      * @access  private
      * @return  void
diff --git a/application/models/Ipam.php b/application/models/Ipam.php
index de10827..13c3b31 100644
--- a/application/models/Ipam.php
+++ b/application/models/Ipam.php
@@ -74,34 +74,34 @@ function networks_search($str) {
     }
 
 
-	public function networks_get_by_id($id)
-	{
+    public function networks_get_by_id($id)
+    {
         //$this->db->from($this->table);
         $this->db->from("networks");
-		$this->db->where('id',$id);
-		$query = $this->db->get();
+        $this->db->where('id',$id);
+        $query = $this->db->get();
  
-		return $query->row();
-	}
+        return $query->row();
+    }
  
-	public function networks_add($data)
-	{
-		$this->db->insert($this->table, $data);
-		return $this->db->insert_id();
-	}
+    public function networks_add($data)
+    {
+        $this->db->insert($this->table, $data);
+        return $this->db->insert_id();
+    }
  
-	public function networks_update($where, $data)
-	{
-		//$this->db->update($this->table, $data, $where);
-		$this->db->update("networks", $data, $where);
-		return $this->db->affected_rows();
-	}
+    public function networks_update($where, $data)
+    {
+        //$this->db->update($this->table, $data, $where);
+        $this->db->update("networks", $data, $where);
+        return $this->db->affected_rows();
+    }
  
-	public function networks_delete_by_id($id)
-	{
-		$this->db->where('id', $id);
-		$this->db->delete($this->table);
-	}
+    public function networks_delete_by_id($id)
+    {
+        $this->db->where('id', $id);
+        $this->db->delete($this->table);
+    }
 
     public function networks_insert_csv($data) {
         $this->db->insert('networks', $data);
@@ -176,36 +176,36 @@ function hosts_search($str) {
     }
 
 
-	public function hosts_get_by_id($id)
-	{
+    public function hosts_get_by_id($id)
+    {
         //$this->db->from($this->table);
         $this->db->from("hosts");
-		$this->db->where('id',$id);
-		$query = $this->db->get();
+        $this->db->where('id',$id);
+        $query = $this->db->get();
  
-		return $query->row();
-	}
+        return $query->row();
+    }
 
-	public function hosts_add($data)
-	{
+    public function hosts_add($data)
+    {
         //$this->db->insert($this->table, $data);
         $this->db->insert("hosts", $data);
-		return $this->db->insert_id();
-	}
+        return $this->db->insert_id();
+    }
  
-	public function hosts_update($where, $data)
-	{
-		//$this->db->update($this->table, $data, $where);
-		$this->db->update("hosts", $data, $where);
-		return $this->db->affected_rows();
-	}
-
-	public function hosts_delete_by_id($id)
-	{
-		$this->db->where('id', $id);
+    public function hosts_update($where, $data)
+    {
+        //$this->db->update($this->table, $data, $where);
+        $this->db->update("hosts", $data, $where);
+        return $this->db->affected_rows();
+    }
+
+    public function hosts_delete_by_id($id)
+    {
+        $this->db->where('id', $id);
         //$this->db->delete($this->table);
         $this->db->delete("hosts");
-	}
+    }
 
     public function hosts_insert_csv($data) {
         $this->db->insert('hosts', $data);
diff --git a/application/views/cidr_view.php b/application/views/cidr_view.php
index 0101cac..77ac8b7 100644
--- a/application/views/cidr_view.php
+++ b/application/views/cidr_view.php
@@ -1,311 +1,647 @@
 
-

Note : CIDR

+

Note : CIDR

-
-

This page is a quote from https://cmdref.net/network/ip.html

+
+

This page is a quote from https://cmdref.net/network/ip.html +

-
-
+
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CIDRMaskHoststhe number of available host
/32255.255.255.2551-
/31 255.255.255.254 2 0
/30 255.255.255.252 4 2
/29 255.255.255.248 8 6
/28 255.255.255.240 16 14
/27 255.255.255.224 32 30
/26 255.255.255.192 64 62
/25 255.255.255.128 128 126
/24 255.255.255.0 256 254
/23 255.255.254.0 512 510
/22 255.255.252.0 1,024 1,022
/21 255.255.248.0 2,048 2,046
/20 255.255.240.0 4,096 4,094
/19 255.255.224.0 8,192 8,190
/16 255.255.0.0 131,072 131,070
/8 255.0.0.0 16,777,216 16,777,214
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CIDRMaskHoststhe number of available host
/32255.255.255.2551-
/31255.255.255.25420
/30255.255.255.25242
/29255.255.255.24886
/28255.255.255.2401614
/27255.255.255.2243230
/26255.255.255.1926462
/25255.255.255.128128126
/24255.255.255.0256254
/23255.255.254.0512510
/22255.255.252.01,0241,022
/21255.255.248.02,0482,046
/20255.255.240.04,0964,094
/19255.255.224.08,1928,190
/16255.255.0.0131,072131,070
/8255.0.0.016,777,21616,777,214
-
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/23 /24 /25 /26 /27 /28 /29 /30
255.255.254.0 255.255.255.0 255.255.255.128 255.255.255.192 255.255.255.224 255.255.255.240 255.255.255.248 255.255.255.252
510 254 126 62 30 14 6 2
10.1.0.0 10.1.0.0 10.1.0.0 10.1.0.0 10.1.0.0
10.1.0.32
10.1.0.64 10.1.0.64
10.1.0.96
10.1.0.128 10.1.0.128 10.1.0.128
10.1.0.160
10.1.0.192 10.1.0.192
10.1.0.224
10.1.1.0 10.1.1.0 10.1.1.0 10.1.1.0
10.1.1.32
10.1.1.64 10.1.1.64
10.1.1.96
10.1.1.128 10.1.1.128 10.1.1.128
10.1.1.160
10.1.1.192 10.1.1.192
10.1.1.224
10.1.2.0 10.1.2.0
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/23 /24 /25 /26 /27 /28 /29 /30
255.255.254.0 255.255.255.0 255.255.255.128 255.255.255.192 255.255.255.224 255.255.255.240 255.255.255.248 255.255.255.252
510 254 126 62 30 14 6 2
10.1.0.0 10.1.0.0 10.1.0.0 10.1.0.0 10.1.0.0
10.1.0.32
10.1.0.64 10.1.0.64
10.1.0.96
10.1.0.128 10.1.0.128 10.1.0.128
10.1.0.160
10.1.0.192 10.1.0.192
10.1.0.224
10.1.1.0 10.1.1.0 10.1.1.0 10.1.1.0
10.1.1.32
10.1.1.64 10.1.1.64
10.1.1.96
10.1.1.128 10.1.1.128 10.1.1.128
10.1.1.160
10.1.1.192 10.1.1.192
10.1.1.224
10.1.2.0 10.1.2.0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/30 /29 /28 /27
192.168.0.X 2 6 14 30
0 the network itself the network itself the network itself the network itself
1 host1 host1 host1 host1
2 host2 host2 host2 host2
3 broadcast address host3 host3 host3
4 the network itself host4 host4 host4
5 host1 host5 host5 host5
6 host2 host6 host6 host6
7 broadcast address the network itself host7 host7
8 the network itself the network itself host8 host8
9 host1 host1 host9 host9
10 host2 host2 host10 host10
11 broadcast address host3 host11 host11
12 the network itself host4 host12 host12
13 host1 host5 host13 host13
14 host2 host6 host14 host14
15 broadcast address broadcast address broadcast address host15
16 the network itself the network itself the network itself host16
17 host1 host1 host1 host17
18 host2 host2 host2 host18
19 broadcast address host3 host3 host19
20 the network itself host4 host4 host20
21 host1 host5 host5 host21
22 host2 host6 host6 host22
23 broadcast address broadcast address host7 host23
24 the network itself the network itself host8 host24
25 host1 host1 host9 host25
26 host2 host2 host10 host26
27 broadcast address host3 host11 host27
28 the network itself host4 host12 host28
29 host1 host5 host13 host29
30 host2 host6 host14 host30
31 broadcast address broadcast address broadcast address broadcast address
abbr abbr abbr abbr abbr
240 the network itself the network itself the network itself
241 host1 host1 host1
242 host2 host2 host2
243 broadcast address host3 host3
244 the network itself host4 host4
245 host1 host5 host5
246 host2 host6 host6
247 broadcast address broadcast address host7
248 the network itself the network itself host8
249 host1 host1 host9
250 host2 host2 host10
251 broadcast address host3 host11
252 the network itself host4 host12
253 host1 host5 host13
254 host2 host6 host14
255 broadcast address broadcast address broadcast address
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
/30 /29 /28 /27
192.168.0.X 2 6 14 30
0 the network itself the network itself the network itself the network itself
1 host1 host1 host1 host1
2 host2 host2 host2 host2
3 broadcast address host3 host3 host3
4 the network itself host4 host4 host4
5 host1 host5 host5 host5
6 host2 host6 host6 host6
7 broadcast address the network itself host7 host7
8 the network itself the network itself host8 host8
9 host1 host1 host9 host9
10 host2 host2 host10 host10
11 broadcast address host3 host11 host11
12 the network itself host4 host12 host12
13 host1 host5 host13 host13
14 host2 host6 host14 host14
15 broadcast address broadcast address broadcast address host15
16 the network itself the network itself the network itself host16
17 host1 host1 host1 host17
18 host2 host2 host2 host18
19 broadcast address host3 host3 host19
20 the network itself host4 host4 host20
21 host1 host5 host5 host21
22 host2 host6 host6 host22
23 broadcast address broadcast address host7 host23
24 the network itself the network itself host8 host24
25 host1 host1 host9 host25
26 host2 host2 host10 host26
27 broadcast address host3 host11 host27
28 the network itself host4 host12 host28
29 host1 host5 host13 host29
30 host2 host6 host14 host30
31 broadcast address broadcast address broadcast address broadcast address
abbr abbr abbr abbr abbr
240 the network itself the network itself the network itself
241 host1 host1 host1
242 host2 host2 host2
243 broadcast address host3 host3
244 the network itself host4 host4
245 host1 host5 host5
246 host2 host6 host6
247 broadcast address broadcast address host7
248 the network itself the network itself host8
249 host1 host1 host9
250 host2 host2 host10
251 broadcast address host3 host11
252 the network itself host4 host12
253 host1 host5 host13
254 host2 host6 host14
255 broadcast address broadcast address broadcast address
- - - - + + + + diff --git a/application/views/home.php b/application/views/home.php deleted file mode 100644 index c384c73..0000000 --- a/application/views/home.php +++ /dev/null @@ -1,14 +0,0 @@ -public function view($page = 'home') -{ - if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php')) - { - // Whoops, we don't have a page for that! - show_404(); - } - - $data['title'] = ucfirst($page); // Capitalize the first letter - - $this->load->view('templates/header', $data); - $this->load->view('pages/'.$page, $data); - $this->load->view('templates/footer', $data); -} diff --git a/application/views/hosts_csv.php b/application/views/hosts_csv.php index 50bb7ad..4247b6a 100644 --- a/application/views/hosts_csv.php +++ b/application/views/hosts_csv.php @@ -1,112 +1,89 @@
-

Hosts CSV Import & Export

- - -
-
-
-
- -
-
- - -
-
-
-
-
-
-

Import from CSV

Add CSV to the last line

-
-
- -
+

Hosts + CSV Import & Export +

+ + +
+
+
+
+ +
+
+ + +
+
+
+
+
+
+

Import from CSV

+

Add CSV to the last line

+
+
+ +
session->flashdata('success') == TRUE): ?> -
session->flashdata('success'); ?>
- +
session->flashdata('success'); ?>
+ -
-

- -
+
+

+ +
+
-
-
-
-
-
-

CSV Example

-
+    
+
+
+
+

CSV Example

+
 "ip_address","subnet_mask","host","note"
 "10.0.0.1","255.255.255.0","test-l3","Global IP xx.xx.xx.xx"
 "10.0.0.3","255.255.255.0","test-host2","bbbb"
 "10.0.0.4","255.255.255.0","test-host3","bbbb"
 "10.0.0.5","255.255.255.0","test-host4","bbbb"
 "10.0.0.6","255.255.255.0","test-host5","bbbb"
-
-
    -
  • networks column must be not null and unique.
  • -
  • CSV Import isn't work validation.
  • -
-
-
- - - - -
-
-
-
- -
-
-
-
-

Export to CSV

-
-
-
"> - -
-
-
- -
-
-
-
-

CSV Example

-
+            
+
    +
  • networks column must be not null and unique.
  • +
  • CSV Import isn't work validation.
  • +
+
+
+ +
+
+
+
+ +
+
+
+
+

Export to CSV

+
+
+
"> + +
+
+
+ +
+
+
+
+

CSV Example

+
 "ip_address","subnet_mask","host","note"
 "10.0.0.1","255.255.255.0","test-l3","Global IP xx.xx.xx.xx"
 "10.0.0.3","255.255.255.0","test-host2","bbbb"
@@ -114,37 +91,35 @@
 "10.0.0.5","255.255.255.0","test-host4","bbbb"
 "10.0.0.6","255.255.255.0","test-host5","bbbb"
 "10.0.0.7","255.255.255.0","test-host6","bbbb"
-
-
-
- - - - - -
-
-
-
-
-
-
-
-

Purge Table

-
-
- -
-
-
-
-

I'm not preparing to purge table from the Web.
- If you want to purge table, you use SQLite database manager or execute the following command in Linux

-
+            
+
+
+ + +
+
+
+
+
+
+
+
+

Purge Table

+
+
+ +
+
+
+
+

I'm not preparing to purge table from the Web.
+ If you want to purge table, you use SQLite database manager or execute the following command in Linux +

+
 SQLite> DELETE FROM COMPANY;
 SQLite> VACUUM;
-
+
+
-
diff --git a/application/views/hosts_view.php b/application/views/hosts_view.php index 475e900..be41f03 100644 --- a/application/views/hosts_view.php +++ b/application/views/hosts_view.php @@ -1,302 +1,287 @@
-

Hosts

- -
- -
-
- "form-horizontal", "role" => "form", "id" => "form1", "name" => "form1"); - echo form_open("hosts/search", $attr);?> - - -
-
- - -
+

Hosts

+ +
+ +
+
+ "form-horizontal", "role" => "form", "id" => "form1", "name" => "form1"); + echo form_open("hosts/search", $attr); ?> + + +
+
+ + +
-
+
- - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IP AddressSubnet maskHostNoteOperation
- - -
IP AddressSubnet maskHostNoteOperation
IP AddressSubnet maskHostNoteOperation
+ + +
IP AddressSubnet maskHostNoteOperation

-
-
- - -
-
- -
-
+
+
+ + +
+
+ +
+
- - - - - - + + + + + + - + location.reload(); + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('Error deleting data'); + } + }); + } + } + - -
    -
  • networks column must be not null and unique.
  • +
  • hosts column must be not null and unique.
  • CSV Import isn't work validation.
From 8cecb2a15f2449a0d48418481e84de1cdd2301cc Mon Sep 17 00:00:00 2001 From: sogaoh Date: Sun, 10 Jun 2018 00:24:49 +0900 Subject: [PATCH 03/16] increase page max --- application/controllers/Hosts.php | 2 +- application/controllers/Networks.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/controllers/Hosts.php b/application/controllers/Hosts.php index 53484b1..26e0b7e 100644 --- a/application/controllers/Hosts.php +++ b/application/controllers/Hosts.php @@ -34,7 +34,7 @@ public function index() $config['base_url'] = site_url("hosts/search/NIL"); $config['total_rows'] = $this->db->count_all('hosts'); $data['total_rows'] = $config['total_rows']; - $config['per_page'] = "5"; + $config['per_page'] = "20"; $config["uri_segment"] = 4; $choice = $config["total_rows"] / $config["per_page"]; $config["num_links"] = floor($choice); diff --git a/application/controllers/Networks.php b/application/controllers/Networks.php index 0ffffce..2278706 100644 --- a/application/controllers/Networks.php +++ b/application/controllers/Networks.php @@ -34,7 +34,7 @@ public function index() $config['base_url'] = site_url("networks/search/NIL"); $config['total_rows'] = $this->db->count_all('networks'); $data['total_rows'] = $config['total_rows']; - $config['per_page'] = "5"; + $config['per_page'] = "10"; $config["uri_segment"] = 4; $choice = $config["total_rows"] / $config["per_page"]; $config["num_links"] = floor($choice); From 9f94d64cc07d8414235da3993032eea3c0e097ce Mon Sep 17 00:00:00 2001 From: sogaoh Date: Sun, 10 Jun 2018 00:29:58 +0900 Subject: [PATCH 04/16] hide Author (sorry..) --- application/views/template/footer.php | 2 ++ application/views/top_view.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/application/views/template/footer.php b/application/views/template/footer.php index 7c581f9..f28c553 100644 --- a/application/views/template/footer.php +++ b/application/views/template/footer.php @@ -5,10 +5,12 @@

+

diff --git a/application/views/top_view.php b/application/views/top_view.php index 76df8d7..bfad7b1 100644 --- a/application/views/top_view.php +++ b/application/views/top_view.php @@ -9,7 +9,9 @@

SimpleIPAM is IP address management(IPAM) for Small and medium-sized enterprises.
This can manage IP address and networks like VLAN.
This is very simple and very useful.

+

SiteMap

From 8407888f2b6fcaa8e339e5a09f0946b6880300ab Mon Sep 17 00:00:00 2001 From: sogaoh Date: Sun, 10 Jun 2018 21:08:58 +0900 Subject: [PATCH 05/16] adjust indents, correct word, remove `$table` variable from models\Ipam.php --- application/models/Ipam.php | 120 ++++--- application/views/networks_view.php | 511 ++++++++++++++-------------- 2 files changed, 308 insertions(+), 323 deletions(-) diff --git a/application/models/Ipam.php b/application/models/Ipam.php index 13c3b31..20a9ab6 100644 --- a/application/models/Ipam.php +++ b/application/models/Ipam.php @@ -1,26 +1,27 @@ load->database(); - } + public function __construct() + { + parent::__construct(); + $this->load->database(); + } /*====================================================== - *Networks + * Networks *====================================================== */ - function get_all_networks() { + function get_all_networks() + { $this->db->order_by("networks", 'ASC'); $query = $this->db->get("networks"); return $query->result_array(); - + //if($query->num_rows() > 0) { // return $query->result_array(); //} @@ -41,10 +42,9 @@ function get_networks($limit, $start, $st = NULL) $sql_limit = " limit " . $start . ", " . $limit; $sql = "$sql1 $sql2 $sql3 $sql_order $sql_limit"; $query = $this->db->query($sql); - //return $query->result(); return $query->result_array(); } - + function get_networks_count($st = NULL) { if ($st == "NIL") $st = ""; @@ -58,12 +58,13 @@ function get_networks_count($st = NULL) } - function networks_search($str) { + function networks_search($str) + { $str = urldecode($str); // for japanese $this->db->like('networks', "$str"); - $this->db->or_like('note1', $str); - $this->db->or_like('note2', $str); - $this->db->order_by("networks", "ASC"); + $this->db->or_like('note1', $str); + $this->db->or_like('note2', $str); + $this->db->order_by("networks", "ASC"); $query = $this->db->get('networks'); if ($query->num_rows() <= 0) { @@ -76,41 +77,41 @@ function networks_search($str) { public function networks_get_by_id($id) { - //$this->db->from($this->table); $this->db->from("networks"); - $this->db->where('id',$id); + $this->db->where('id', $id); $query = $this->db->get(); - + return $query->row(); } - + public function networks_add($data) { - $this->db->insert($this->table, $data); + $this->db->insert("networks", $data); return $this->db->insert_id(); } - + public function networks_update($where, $data) { - //$this->db->update($this->table, $data, $where); $this->db->update("networks", $data, $where); return $this->db->affected_rows(); } - + public function networks_delete_by_id($id) { $this->db->where('id', $id); - $this->db->delete($this->table); + $this->db->delete("networks"); } - public function networks_insert_csv($data) { + public function networks_insert_csv($data) + { $this->db->insert('networks', $data); } - function truncate_networks() { + function truncate_networks() + { $sql = 'delete from networks where id > 0 '; $this->db->query($sql); - + $sql = 'VACUUM;'; $this->db->query($sql); @@ -121,10 +122,11 @@ function truncate_networks() { * Hosts *====================================================== */ - function get_all_hosts() { + function get_all_hosts() + { $query = $this->db->get("hosts"); return $query->result_array(); - + //if($query->num_rows() > 0) { // return $query->result_array(); //} @@ -144,10 +146,9 @@ function get_hosts($limit, $start, $st = NULL) $sql_limit = " limit " . $start . ", " . $limit; $sql = "$sql1 $sql2 $sql_order $sql_limit"; $query = $this->db->query($sql); - //return $query->result(); return $query->result_array(); } - + function get_hosts_count($st = NULL) { if ($st == "NIL") $st = ""; @@ -160,12 +161,13 @@ function get_hosts_count($st = NULL) } - function hosts_search($str) { + function hosts_search($str) + { $str = urldecode($str); // for japanese $this->db->like('ip_address', "$str"); - $this->db->or_like('host', $str); - $this->db->or_like('note', $str); - $this->db->order_by("hosts", "ASC"); + $this->db->or_like('host', $str); + $this->db->or_like('note', $str); + $this->db->order_by("hosts", "ASC"); $query = $this->db->get('hosts'); if ($query->num_rows() <= 0) { @@ -178,24 +180,21 @@ function hosts_search($str) { public function hosts_get_by_id($id) { - //$this->db->from($this->table); $this->db->from("hosts"); - $this->db->where('id',$id); + $this->db->where('id', $id); $query = $this->db->get(); - + return $query->row(); } public function hosts_add($data) { - //$this->db->insert($this->table, $data); $this->db->insert("hosts", $data); return $this->db->insert_id(); } - + public function hosts_update($where, $data) { - //$this->db->update($this->table, $data, $where); $this->db->update("hosts", $data, $where); return $this->db->affected_rows(); } @@ -203,11 +202,11 @@ public function hosts_update($where, $data) public function hosts_delete_by_id($id) { $this->db->where('id', $id); - //$this->db->delete($this->table); $this->db->delete("hosts"); } - public function hosts_insert_csv($data) { + public function hosts_insert_csv($data) + { $this->db->insert('hosts', $data); } @@ -218,38 +217,34 @@ public function hosts_insert_csv($data) { */ private function _get_datatables_query() { - + $this->db->from($this->table); - + $i = 0; - + foreach ($this->column_search as $item) // loop column { - if($_POST['search']['value']) // if datatable send POST for search + if ($_POST['search']['value']) // if datatable send POST for search { - - if($i===0) // first loop + + if ($i === 0) // first loop { $this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND. $this->db->like($item, $_POST['search']['value']); - } - else - { + } else { $this->db->or_like($item, $_POST['search']['value']); } - - if(count($this->column_search) - 1 == $i) //last loop + + if (count($this->column_search) - 1 == $i) //last loop $this->db->group_end(); //close bracket } $i++; } - - if(isset($_POST['order'])) // here order processing + + if (isset($_POST['order'])) // here order processing { $this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']); - } - else if(isset($this->order)) - { + } else if (isset($this->order)) { $order = $this->order; $this->db->order_by(key($order), $order[key($order)]); } @@ -259,12 +254,11 @@ private function _get_datatables_query() function get_datatables() { $this->_get_datatables_query(); - if($_POST['length'] != -1) - $this->db->limit($_POST['length'], $_POST['start']); + if ($_POST['length'] != -1) + $this->db->limit($_POST['length'], $_POST['start']); $query = $this->db->get("hosts"); return $query->result(); } - } diff --git a/application/views/networks_view.php b/application/views/networks_view.php index 2372d2d..a605bb2 100644 --- a/application/views/networks_view.php +++ b/application/views/networks_view.php @@ -2,317 +2,308 @@

Networks

-
+
-
- "form-horizontal", "role" => "form", "id" => "form1", "name" => "form1"); - echo form_open("networks/search", $attr);?> - - -
-
- - -
+
+ "form-horizontal", "role" => "form", "id" => "form1", "name" => "form1"); + echo form_open("networks/search", $attr); ?> + + +
+
+ + +
-
+
- - + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - -
NetworksCIDRBroadcastVLAN IDNote1Note2Operation
- - +
NetworksCIDRBroadcastVLAN IDNote1Note2Operation
+ +
NetworksCIDRBroadcastVLAN IDNote1Note2Operation
- -
-
-
- - -
-
- -
-
+ + Networks + CIDR + Broadcast + VLAN ID + Note1 + Note2 + Operation + + + + +
+
+
+ + +
+
+ +
+ + - - - - - - + + + + + + - + - - -