Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
21377312
Commit
21377312
authored
Jul 28, 2015
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sbin: apply PSR2 style
parent
b4845e62
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
198 additions
and
189 deletions
+198
-189
3gstats.php
src/sbin/3gstats.php
+46
-46
captiveportal_gather_stats.php
src/sbin/captiveportal_gather_stats.php
+45
-42
gmirror_status_check.php
src/sbin/gmirror_status_check.php
+41
-36
prefixes.php
src/sbin/prefixes.php
+66
-65
No files found.
src/sbin/3gstats.php
View file @
21377312
...
...
@@ -4,7 +4,7 @@ require_once("pfsense-utils.inc");
ini_set
(
"max_execution_time"
,
"0"
);
if
(
empty
(
$argv
[
1
]))
{
if
(
empty
(
$argv
[
1
]))
{
echo
"No modem device given
\n
"
;
exit
(
0
);
}
...
...
@@ -19,7 +19,7 @@ $i = 0;
$record
=
array
();
$handle
=
fopen
(
$device
,
"r"
);
if
(
!
$handle
)
{
if
(
!
$handle
)
{
echo
"Can not open modem stats device
\n
"
;
exit
(
1
);
}
...
...
@@ -36,7 +36,7 @@ $record['bwdownstream'] = 0;
$record
[
'simstate'
]
=
0
;
$record
[
'service'
]
=
0
;
while
(
true
)
{
while
(
true
)
{
$string
=
""
;
$string
=
fgets
(
$handle
,
256
);
...
...
@@ -45,7 +45,7 @@ while(true) {
$elements
[
0
]
=
trim
(
$elements
[
0
]);
$elements
[
1
]
=
trim
(
$elements
[
1
]);
switch
(
$elements
[
0
])
{
switch
(
$elements
[
0
])
{
case
"^MODE"
:
$record
[
'mode'
]
=
$elements
[
1
];
break
;
...
...
@@ -71,7 +71,7 @@ while(true) {
break
;
}
if
(
$i
>
10
)
{
if
(
$i
>
10
)
{
$csv
=
$header
;
$csv
.=
implode
(
","
,
$record
);
$csv
.=
"
\n
"
;
...
...
src/sbin/captiveportal_gather_stats.php
View file @
21377312
...
...
@@ -52,8 +52,9 @@ $current_user_count = 0;
/* tmp file to use to store old data (per interface)*/
$tmpfile
=
'/var/db/captiveportal_online_users'
;
if
(
empty
(
$type
))
if
(
empty
(
$type
))
{
exit
;
}
/* echo the rrd required syntax */
echo
"N:"
;
...
...
@@ -70,23 +71,25 @@ if ($type == "loggedin") {
if
(
$fd
)
{
while
(
!
feof
(
$fd
))
{
$line
=
trim
(
fgets
(
$fd
));
if
(
$line
)
if
(
$line
)
{
$previous_user_timestamp
=
$line
;
else
}
else
{
$previous_user_timestamp
=
0
;
}
}
}
else
{
$previous_user_timestamp
=
0
;
}
@
fclose
(
$fd
);
foreach
(
$cpdb
as
$user
)
{
foreach
(
$cpdb
as
$user
)
{
$user_ip
=
$user
[
2
];
// Record the timestamp
$timestamp
=
$user
[
0
];
if
(
$timestamp
>
$previous_user_timestamp
)
if
(
$timestamp
>
$previous_user_timestamp
)
{
$current_user_count
=
$current_user_count
+
1
;
}
}
// Write out the latest timestamp but not if it is empty
if
(
!
empty
(
$timestamp
))
{
...
...
@@ -100,9 +103,9 @@ if ($type == "loggedin") {
/* If $timestamp is less than or equal to previous_user_timestamp return 0,
* as we only want the 'X' number of users logged in since last RRD poll.
*/
if
(
$timestamp
<=
$previous_user_timestamp
)
if
(
$timestamp
<=
$previous_user_timestamp
)
{
$result
=
0
;
else
{
}
else
{
$result
=
$current_user_count
;
}
}
elseif
(
$type
==
"concurrent"
)
...
...
src/sbin/gmirror_status_check.php
View file @
21377312
...
...
@@ -45,8 +45,9 @@ if (file_exists($status_file)) {
sort
(
$previous_mirror_list
);
if
(
count
(
$previous_mirror_status
)
>
0
)
{
// Check list of current mirrors vs old mirrors, notify if one has appeared/disappeared
if
(
$mirror_list
!=
$previous_mirror_list
)
if
(
$mirror_list
!=
$previous_mirror_list
)
{
$notices
[]
=
sprintf
(
gettext
(
"List of mirrors changed. Old: (%s) New: (%s)"
),
implode
(
", "
,
$previous_mirror_list
),
implode
(
", "
,
$mirror_list
));
}
// For each mirror, check the mirror status, notify if changed
foreach
(
$mirror_list
as
$mirror
)
{
...
...
@@ -64,11 +65,14 @@ if (file_exists($status_file)) {
// Check the drive status as it may be different.
asort
(
$mirror_status
[
$mirror
][
'components'
]);
asort
(
$previous_mirror_status
[
$mirror
][
'components'
]);
if
(
$mirror_status
[
$mirror
][
'components'
]
!=
$previous_mirror_status
[
$mirror
][
'components'
])
$notices
[]
=
sprintf
(
gettext
(
"Mirror %s drive status changed. Old: (%s) New: (%s)"
),
if
(
$mirror_status
[
$mirror
][
'components'
]
!=
$previous_mirror_status
[
$mirror
][
'components'
])
{
$notices
[]
=
sprintf
(
gettext
(
"Mirror %s drive status changed. Old: (%s) New: (%s)"
),
$mirror
,
implode
(
", "
,
$previous_mirror_status
[
$mirror
][
'components'
]),
implode
(
", "
,
$mirror_status
[
$mirror
][
'components'
]));
implode
(
", "
,
$mirror_status
[
$mirror
][
'components'
])
);
}
}
}
}
...
...
@@ -78,5 +82,6 @@ if (count($notices)) {
file_notice
(
"gmirror"
,
implode
(
"
\n
"
,
$notices
),
"GEOM Mirror Status Change"
,
1
);
}
// Write out current status if changed
if
(
$mirror_status
!=
$previous_mirror_status
)
if
(
$mirror_status
!=
$previous_mirror_status
)
{
file_put_contents
(
$status_file
,
serialize
(
$mirror_status
));
}
src/sbin/prefixes.php
View file @
21377312
<?php
$leases_file
=
"/var/dhcpd/var/db/dhcpd6.leases"
;
if
(
!
file_exists
(
$leases_file
))
{
if
(
!
file_exists
(
$leases_file
))
{
exit
(
1
);
}
$duid_arr
=
array
();
foreach
(
file
(
$leases_file
)
as
$line
)
{
foreach
(
file
(
$leases_file
)
as
$line
)
{
// echo "$line";
if
(
preg_match
(
"/^(ia-[np][ad])[ ]+
\"
(.*?)
\"
/i "
,
$line
,
$duidmatch
))
{
if
(
preg_match
(
"/^(ia-[np][ad])[ ]+
\"
(.*?)
\"
/i "
,
$line
,
$duidmatch
))
{
$type
=
$duidmatch
[
1
];
$duid
=
$duidmatch
[
2
];
continue
;
}
/* is it active? otherwise just discard */
if
(
preg_match
(
"/binding state active/i"
,
$line
,
$activematch
))
{
if
(
preg_match
(
"/binding state active/i"
,
$line
,
$activematch
))
{
$active
=
true
;
continue
;
}
if
(
preg_match
(
"/iaaddr[ ]+([0-9a-f:]+)[ ]+/i"
,
$line
,
$addressmatch
))
{
if
(
preg_match
(
"/iaaddr[ ]+([0-9a-f:]+)[ ]+/i"
,
$line
,
$addressmatch
))
{
$ia_na
=
$addressmatch
[
1
];
continue
;
}
if
(
preg_match
(
"/iaprefix[ ]+([0-9a-f:\/]+)[ ]+/i"
,
$line
,
$prefixmatch
))
{
if
(
preg_match
(
"/iaprefix[ ]+([0-9a-f:\/]+)[ ]+/i"
,
$line
,
$prefixmatch
))
{
$ia_pd
=
$prefixmatch
[
1
];
continue
;
}
/* closing bracket */
if
(
preg_match
(
"/^}/i "
,
$line
))
{
switch
(
$type
)
{
if
(
preg_match
(
"/^}/i "
,
$line
))
{
switch
(
$type
)
{
case
"ia-na"
:
$duid_arr
[
$duid
][
$type
]
=
$ia_na
;
break
;
...
...
@@ -51,14 +51,14 @@ foreach(file($leases_file) as $line) {
$routes
=
array
();
foreach
(
$duid_arr
as
$entry
)
{
if
(
$entry
[
'ia-pd'
]
<>
""
)
{
if
(
$entry
[
'ia-pd'
]
<>
""
)
{
$routes
[
$entry
[
'ia-na'
]]
=
$entry
[
'ia-pd'
];
}
array_shift
(
$duid_arr
);
}
// echo "add routes\n";
if
(
count
(
$routes
)
>
0
)
{
if
(
count
(
$routes
)
>
0
)
{
foreach
(
$routes
as
$address
=>
$prefix
)
{
echo
"/sbin/route change -inet6
{
$prefix
}
{
$address
}
\n
"
;
}
...
...
@@ -67,28 +67,29 @@ if(count($routes) > 0) {
/* get clog from dhcpd */
$dhcpdlogfile
=
"/var/log/dhcpd.log"
;
$clog
=
array
();
if
(
file_exists
(
$dhcpdlogfile
))
if
(
file_exists
(
$dhcpdlogfile
))
{
exec
(
"clog
$dhcpdlogfile
"
,
$clog
,
$ret
);
}
if
(
$ret
>
0
)
if
(
$ret
>
0
)
{
$clog
=
array
();
}
$expires
=
array
();
foreach
(
$clog
as
$line
)
{
if
(
preg_match
(
"/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i"
,
$line
,
$expire
))
{
if
(
in_array
(
$expire
[
1
],
$routes
))
foreach
(
$clog
as
$line
)
{
if
(
preg_match
(
"/releases[ ]+prefix[ ]+([0-9a-f:]+\/[0-9]+)/i"
,
$line
,
$expire
))
{
if
(
in_array
(
$expire
[
1
],
$routes
))
{
continue
;
}
$expires
[
$expire
[
1
]]
=
$expire
[
1
];
}
array_shift
(
$clog
);
}
// echo "remove routes\n";
if
(
count
(
$expires
)
>
0
)
{
if
(
count
(
$expires
)
>
0
)
{
foreach
(
$expires
as
$prefix
)
{
echo
"/sbin/route delete -inet6
{
$prefix
[
'prefix'
]
}
\n
"
;
array_shift
(
$expires
);
}
}
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment