Private GIT
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
phpipam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vlbox
phpipam
Commits
86aa3463
Commit
86aa3463
authored
Jan 3, 2018
by
Gary Allan
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup: switch mastersubnet-dropdown to fetch_overlapping_subnets()
Cleanup: class.Menus.php
parent
53478c35
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/subnets/mastersubnet-dropdown.php
+27
-38
27 additions, 38 deletions
app/subnets/mastersubnet-dropdown.php
functions/classes/class.Menu.php
+28
-26
28 additions, 26 deletions
functions/classes/class.Menu.php
with
55 additions
and
64 deletions
app/subnets/mastersubnet-dropdown.php
+
27
−
38
View file @
86aa3463
...
@@ -16,41 +16,29 @@ $Subnets = new Subnets ($Database);
...
@@ -16,41 +16,29 @@ $Subnets = new Subnets ($Database);
# verify that user is logged in
# verify that user is logged in
$User
->
check_user_session
();
$User
->
check_user_session
();
/**
/**
* Return array of valid subnets satisfying strict subnet requirements
* Return array of valid subnets satisfying strict subnet requirements
* @param Subnets $Subnets [description]
* @param Subnets $Subnets
* @param array $search [description]
* @param integer $sectionId
* @param string $cidr [description]
* @param string $cidr
* @return array [description]
* @param array|string $result_fields
* @return array
*/
*/
function
get_strict_subnets
(
$Subnets
,
$search
,
$cidr
)
{
function
get_strict_subnets
(
$Subnets
,
$sectionId
,
$cidr
,
$result_fields
=
"*"
)
{
$strict_subnets
=
array
();
if
(
$Subnets
->
verify_cidr_address
(
$cidr
)
!==
true
)
{
return
array
();
}
if
(
$Subnets
->
verify_cidr_address
(
$cidr
)
!==
true
)
{
return
array
();
}
list
(
$cidr_addr
,
$cidr_mask
)
=
explode
(
'/'
,
$cidr
);
list
(
$cidr_addr
,
$cidr_mask
)
=
explode
(
'/'
,
$cidr
);
$bmask
=
$Subnets
->
get_network_bitmasks
();
$strict_subnets
=
$Subnets
->
fetch_overlapping_subnets
(
$cidr
,
'sectionId'
,
$sectionId
,
$result_fields
);
if
(
!
array
(
$strict_subnets
))
return
array
();
$cidr_decimal
=
$Subnets
->
transform_to_decimal
(
$cidr_addr
);
$cidr_type
=
$Subnets
->
identify_address
(
$cidr_addr
);
// Calculate what the parent subnet decimal address would be for each mask and check if it exists
$search_mask
=
$cidr_mask
-
1
;
while
(
$search_mask
>=
0
)
{
$search_subnet
=
gmp_strval
(
gmp_and
(
$cidr_decimal
,
$bmask
[
$cidr_type
][
$search_mask
][
'lo'
]));
if
(
is_array
(
$search
[
$cidr_type
][
$search_mask
][
$search_
subnet
])
)
{
foreach
(
$strict_subnets
as
$i
=>
$
subnet
)
{
$strict_subnets
=
array_merge
(
$strict_subnets
,
$search
[
$cidr_type
][
$search_mask
][
$search_subnet
])
;
if
(
$subnet
->
mask
>=
$cidr_mask
)
unset
(
$strict_subnets
[
$i
]);
else
break
;
}
}
$search_mask
--
;
}
return
$strict_subnets
;
return
$strict_subnets
;
}
}
$sectionId
=
isset
(
$_GET
[
'section'
])
?
(
int
)
$_GET
[
'section'
]
:
0
;
$sectionId
=
isset
(
$_GET
[
'section'
])
?
(
int
)
$_GET
[
'section'
]
:
0
;
$cidr
=
isset
(
$_GET
[
'cidr'
])
?
$_GET
[
'cidr'
]
:
''
;
$cidr
=
isset
(
$_GET
[
'cidr'
])
?
$_GET
[
'cidr'
]
:
''
;
$previously_selected
=
isset
(
$_GET
[
'prev'
])
?
(
int
)
$_GET
[
'prev'
]
:
-
1
;
$previously_selected
=
isset
(
$_GET
[
'prev'
])
?
(
int
)
$_GET
[
'prev'
]
:
-
1
;
...
@@ -58,38 +46,39 @@ $previously_selected = isset($_GET['prev']) ? (int) $_GET['prev'] : -1;
...
@@ -58,38 +46,39 @@ $previously_selected = isset($_GET['prev']) ? (int) $_GET['prev'] : -1;
$section
=
$Sections
->
fetch_section
(
'id'
,
$sectionId
);
$section
=
$Sections
->
fetch_section
(
'id'
,
$sectionId
);
if
(
!
is_object
(
$section
))
{
return
''
;
}
if
(
!
is_object
(
$section
))
{
return
''
;
}
$folders
=
array
();
// Don't fetch all fields
$search
=
array
();
$fields
=
array
(
'id'
,
'masterSubnetId'
,
'isFolder'
,
'subnet'
,
'mask'
,
'description'
);
$all_subnets
=
$Subnets
->
fetch_section_subnets
(
$sectionId
,
array
(
'id'
,
'masterSubnetId'
,
'isFolder'
,
'subnet'
,
'mask'
,
'description'
));
if
(
!
is_array
(
$all_subnets
))
$all_subnets
=
array
();
foreach
(
$all_subnets
as
$subnet
)
{
if
(
$subnet
->
isFolder
)
{
$folders
[]
=
clone
$subnet
;
$subnet
->
disabled
=
1
;
}
else
{
$subnet
->
type
=
$Subnets
->
identify_address
(
$subnet
->
subnet
);
$search
[
$subnet
->
type
][
$subnet
->
mask
][
$subnet
->
subnet
][]
=
$subnet
;
}
}
$strict_subnets
=
get_strict_subnets
(
$Subnets
,
$se
arch
,
$cidr
);
$strict_subnets
=
get_strict_subnets
(
$Subnets
,
$se
ctionId
,
$cidr
,
$fields
);
$folders
=
$Subnets
->
fetch_multiple_objects
(
'subnets'
,
'isFolder'
,
'1'
,
'id'
,
true
,
null
,
$fields
);
if
(
!
is_array
(
$folders
))
$folders
=
array
();
// Generate HTML <options> dropdown menu
// Generate HTML <options> dropdown menu
$dropdown
=
new
MasterSubnetDropDown
(
$Subnets
,
$previously_selected
);
$dropdown
=
new
MasterSubnetDropDown
(
$Subnets
,
$previously_selected
);
// Show overlapping subnets (possible parents)
if
(
!
empty
(
$strict_subnets
))
{
if
(
!
empty
(
$strict_subnets
))
{
$dropdown
->
optgroup_open
(
_
(
'Strict Subnets'
));
$dropdown
->
optgroup_open
(
_
(
'Strict Subnets'
));
foreach
(
$strict_subnets
as
$subnet
)
{
$dropdown
->
subnets_add_object
(
$subnet
);
}
foreach
(
$strict_subnets
as
$subnet
)
{
$dropdown
->
subnets_add_object
(
$subnet
);
}
}
}
// Show folders
$dropdown
->
optgroup_open
(
_
(
'Folders'
));
$dropdown
->
optgroup_open
(
_
(
'Folders'
));
foreach
(
$folders
as
$folder
)
{
$dropdown
->
subnets_tree_add
(
$folder
);
}
foreach
(
$folders
as
$folder
)
{
$dropdown
->
subnets_tree_add
(
$folder
);
}
$dropdown
->
subnets_tree_render
(
true
);
$dropdown
->
subnets_tree_render
(
true
);
if
(
$section
->
strictMode
==
0
)
{
if
(
$section
->
strictMode
==
0
)
{
// Strict mode is disabled, allow nested chaos....
$all_subnets
=
$Subnets
->
fetch_section_subnets
(
$sectionId
,
$fields
);
if
(
!
is_array
(
$all_subnets
))
$all_subnets
=
array
();
foreach
(
$all_subnets
as
$subnet
)
{
if
(
$subnet
->
isFolder
)
$subnet
->
disabled
=
1
;
else
break
;
}
// Show all subnets
$dropdown
->
optgroup_open
(
_
(
'Subnets'
));
$dropdown
->
optgroup_open
(
_
(
'Subnets'
));
foreach
(
$all_subnets
as
$subnet
)
{
$dropdown
->
subnets_tree_add
(
$subnet
);
}
foreach
(
$all_subnets
as
$subnet
)
{
$dropdown
->
subnets_tree_add
(
$subnet
);
}
$dropdown
->
subnets_tree_render
(
false
);
$dropdown
->
subnets_tree_render
(
false
);
...
...
This diff is collapsed.
Click to expand it.
functions/classes/class.Menu.php
+
28
−
26
View file @
86aa3463
...
@@ -65,6 +65,8 @@ class MasterSubnetDropDown {
...
@@ -65,6 +65,8 @@ class MasterSubnetDropDown {
* @param string $name
* @param string $name
*/
*/
public
function
optgroup_open
(
$name
)
{
public
function
optgroup_open
(
$name
)
{
if
(
empty
(
$name
))
return
;
$this
->
optgroup_close
();
$this
->
optgroup_close
();
$this
->
options_group
=
$name
;
$this
->
options_group
=
$name
;
$this
->
html
[]
=
'<optgroup label="'
.
$name
.
'">'
;
$this
->
html
[]
=
'<optgroup label="'
.
$name
.
'">'
;
...
@@ -74,27 +76,26 @@ class MasterSubnetDropDown {
...
@@ -74,27 +76,26 @@ class MasterSubnetDropDown {
* Close an open html </optgroup>
* Close an open html </optgroup>
*/
*/
public
function
optgroup_close
()
{
public
function
optgroup_close
()
{
if
(
$this
->
options_group
)
{
$this
->
html
[]
=
'</optgroup>'
;
}
if
(
!
empty
(
$this
->
options_group
)
)
$this
->
html
[]
=
'</optgroup>'
;
$this
->
options_group
=
null
;
$this
->
options_group
=
null
;
}
}
/**
/**
* Return <option> customisations
* Return <option> customisations
* @param stdObject
|null
$subnet
* @param stdObject $subnet
* @return string
* @return string
*/
*/
private
function
get_subnet_options
(
$subnet
)
{
private
function
get_subnet_options
(
$subnet
)
{
$options
=
array
();
$options
=
array
();
// selected="selected"
// selected="selected"
$id
=
is_object
(
$subnet
)
?
$subnet
->
id
:
0
;
if
(
$subnet
->
id
==
$this
->
previously_selected
)
{
if
(
$id
==
$this
->
previously_selected
)
{
$this
->
previously_selected
=
-
1
;
$this
->
previously_selected
=
-
1
;
$options
[]
=
'selected="selected"'
;
$options
[]
=
'selected="selected"'
;
}
}
// disabled
// disabled
if
(
is_object
(
$subnet
)
&&
isset
(
$subnet
->
disabled
)
&&
$subnet
->
disabled
==
1
)
{
if
(
isset
(
$subnet
->
disabled
)
&&
$subnet
->
disabled
==
1
)
{
$options
[]
=
'disabled'
;
$options
[]
=
'disabled'
;
}
}
...
@@ -103,16 +104,13 @@ class MasterSubnetDropDown {
...
@@ -103,16 +104,13 @@ class MasterSubnetDropDown {
/**
/**
* Generate menu item from subnet object
* Generate menu item from subnet object
* @param stdObject
|null
$subnet
* @param stdObject $subnet
* @param integer $level
(de)
* @param integer $level
*/
*/
public
function
subnets_add_object
(
$subnet
,
$level
=
0
)
{
public
function
subnets_add_object
(
$subnet
,
$level
=
0
)
{
$options
=
$this
->
get_subnet_options
(
$subnet
);
if
(
!
is_object
(
$subnet
)
)
return
;
if
(
!
is_object
(
$subnet
))
{
$options
=
$this
->
get_subnet_options
(
$subnet
);
$this
->
html
[]
=
"<option
$options
value='0'>"
.
_
(
"Root folder"
)
.
"</option>"
;
return
;
}
if
(
strlen
(
$subnet
->
description
)
>
34
)
$subnet
->
description
=
substr
(
$subnet
->
description
,
0
,
31
)
.
'...'
;
if
(
strlen
(
$subnet
->
description
)
>
34
)
$subnet
->
description
=
substr
(
$subnet
->
description
,
0
,
31
)
.
'...'
;
$prefix
=
str_repeat
(
' - '
,
$level
);
$prefix
=
str_repeat
(
' - '
,
$level
);
...
@@ -149,7 +147,11 @@ class MasterSubnetDropDown {
...
@@ -149,7 +147,11 @@ class MasterSubnetDropDown {
*/
*/
public
function
subnets_tree_reset
()
{
public
function
subnets_tree_reset
()
{
$this
->
children_by_parent_id
=
array
();
$this
->
children_by_parent_id
=
array
();
$this
->
subnets_by_id
=
array
(
null
);
$root
=
new
stdClass
();
$root
->
id
=
0
;
$root
->
isFolder
=
1
;
$root
->
description
=
_
(
"Root folder"
);
$this
->
subnets_by_id
=
array
(
0
=>
$root
);
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment