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
338f71c2
Commit
338f71c2
authored
Apr 01, 2015
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rc|vouchers: shuffle around the backup invoke; merge halt/reboot glue
parent
ad5065e0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
90 additions
and
87 deletions
+90
-87
system.inc
src/etc/inc/system.inc
+2
-4
voucher.inc
src/etc/inc/voucher.inc
+61
-53
rc.halt
src/etc/rc.halt
+3
-15
rc.halt.common
src/etc/rc.halt.common
+21
-0
rc.reboot
src/etc/rc.reboot
+3
-15
No files found.
src/etc/inc/system.inc
View file @
338f71c2
...
...
@@ -1645,10 +1645,10 @@ function system_reboot($sync = false)
mwexec
(
$cmd
);
}
function
system_reboot_cleanup
()
{
function
system_reboot_cleanup
()
{
global
$config
,
$cpzone
;
mwexec
(
"/usr/local/bin/beep.sh stop"
);
require_once
(
"captiveportal.inc"
);
if
(
is_array
(
$config
[
'captiveportal'
]))
{
foreach
(
$config
[
'captiveportal'
]
as
$cpzone
=>
$cp
)
{
...
...
@@ -1656,8 +1656,6 @@ function system_reboot_cleanup() {
captiveportal_send_server_accounting
(
true
);
}
}
require_once
(
"voucher.inc"
);
voucher_save_db_to_config
();
}
function
system_console_configure
()
...
...
src/etc/inc/voucher.inc
View file @
338f71c2
<?php
/*
Copyright (C) 2010-2012 Ermal Luci <eri@pfsense.org>
Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2010-2012 Ermal Luci <eri@pfsense.org>
Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2007 Marcel Wiget <mwiget@mac.com>
All rights reserved.
...
...
@@ -28,15 +29,8 @@
*/
/*
pfSense_BUILDER_BINARIES: /usr/local/bin/voucher
pfSense_MODULE: captiveportal
*/
/* include all configuration functions */
if
(
!
function_exists
(
'captiveportal_syslog'
))
require_once
(
"captiveportal.inc"
);
require_once
(
"captiveportal.inc"
);
function
voucher_expire
(
$voucher_received
)
{
global
$g
,
$config
,
$cpzone
;
...
...
@@ -276,8 +270,9 @@ function voucher_auth($voucher_received, $test = 0) {
return
$total_minutes
;
}
function
voucher_configure
(
$sync
=
false
)
{
global
$config
,
$g
,
$cpzone
;
function
voucher_configure
(
$sync
=
false
)
{
global
$config
,
$cpzone
;
if
(
is_array
(
$config
[
'voucher'
]))
{
foreach
(
$config
[
'voucher'
]
as
$voucherzone
=>
$vcfg
)
{
...
...
@@ -474,57 +469,70 @@ function voucher_log($priority, $message) {
closelog
();
}
/* Save active and used voucher DB into XML config and write it to flash
* Called during reboot -> system_reboot_cleanup() and every active voucher change
/*
* Save active and used voucher DB into XML config and write it to config
* Called during reboot and every active voucher change
*/
function
voucher_save_db_to_config
()
{
global
$config
,
$g
,
$cpzone
;
function
voucher_save_db_to_config
()
{
global
$config
,
$cpzone
;
if
(
is_array
(
$config
[
'voucher'
]))
{
foreach
(
$config
[
'voucher'
]
as
$voucherzone
=>
$vcfg
)
{
$cpzone
=
$voucherzone
;
voucher_save_db_to_config_zone
();
}
if
(
!
isset
(
$config
[
'voucher'
]))
{
return
;
}
$needs_write
=
0
;
foreach
(
$config
[
'voucher'
]
as
$voucherzone
=>
$vcfg
)
{
$cpzone
=
$voucherzone
;
$needs_write
+=
voucher_save_db_to_config_zone
();
}
if
(
$needs_write
)
{
write_config
(
"Backing up vouchers"
);
}
}
function
voucher_save_db_to_config_zone
()
{
global
$config
,
$g
,
$cpzone
;
function
voucher_save_db_to_config_zone
()
{
global
$config
,
$cpzone
;
if
(
!
isset
(
$config
[
'voucher'
][
$cpzone
][
'enable'
]))
return
;
// no vouchers or don't want to save DB's
if
(
!
isset
(
$config
[
'voucher'
][
$cpzone
][
'enable'
]))
{
// no vouchers or don't want to save DB's
return
0
;
}
if
(
!
is_array
(
$config
[
'voucher'
][
$cpzone
][
'roll'
]))
return
;
if
(
!
isset
(
$config
[
'voucher'
][
$cpzone
][
'roll'
]))
{
return
0
;
}
$voucherlck
=
lock
(
"voucher
{
$cpzone
}
"
,
LOCK_EX
);
$voucherlck
=
lock
(
"voucher
{
$cpzone
}
"
,
LOCK_EX
);
// walk all active rolls and save runtime DB's to flash
$a_roll
=
&
$config
[
'voucher'
][
$cpzone
][
'roll'
];
while
(
list
(
$key
,
$value
)
=
each
(
$a_roll
))
{
$rollent
=
&
$a_roll
[
$key
];
$roll
=
$rollent
[
'number'
];
$bitmask
=
voucher_read_used_db
(
$roll
);
$rollent
[
'used'
]
=
base64_encode
(
$bitmask
);
$active_vouchers
=
voucher_read_active_db
(
$roll
);
$db
=
array
();
// walk all active rolls and save runtime DBs
$a_roll
=
&
$config
[
'voucher'
][
$cpzone
][
'roll'
];
while
(
list
(
$key
,
$value
)
=
each
(
$a_roll
))
{
$rollent
=
&
$a_roll
[
$key
];
$roll
=
$rollent
[
'number'
];
$bitmask
=
voucher_read_used_db
(
$roll
);
$rollent
[
'used'
]
=
base64_encode
(
$bitmask
);
$active_vouchers
=
voucher_read_active_db
(
$roll
);
$db
=
array
();
$dbi
=
1
;
foreach
(
$active_vouchers
as
$voucher
=>
$line
)
{
list
(
$timestamp
,
$minutes
)
=
explode
(
","
,
$line
);
$activent
[
'voucher'
]
=
$voucher
;
$activent
[
'timestamp'
]
=
$timestamp
;
$activent
[
'minutes'
]
=
$minutes
;
$db
[
"v
{
$dbi
}
"
]
=
$activent
;
$dbi
++
;
}
$rollent
[
'active'
]
=
$db
;
unset
(
$active_vouchers
);
}
unlock
(
$voucherlck
);
foreach
(
$active_vouchers
as
$voucher
=>
$line
)
{
list
(
$timestamp
,
$minutes
)
=
explode
(
','
,
$line
);
$activent
[
'voucher'
]
=
$voucher
;
$activent
[
'timestamp'
]
=
$timestamp
;
$activent
[
'minutes'
]
=
$minutes
;
$db
[
"v
{
$dbi
}
"
]
=
$activent
;
$dbi
++
;
}
write_config
(
"Synching vouchers"
)
;
return
;
}
$rollent
[
'active'
]
=
$db
;
unset
(
$active_vouchers
)
;
}
?>
unlock
(
$voucherlck
);
return
1
;
}
src/etc/rc.halt
View file @
338f71c2
#!/bin/sh
# shutdown rc scripts
/usr/local/etc/rc.opnsense stop
/usr/local/etc/rc.backup_rrd
/usr/local/etc/rc.backup_dhcpleases
# wait for config lock to release
php
-a
>
/dev/null
<<
EOF
\$
fp = fopen('/conf/config.xml', "w+");
if (flock(
\$
fp, LOCK_EX)) {
flock(
\$
fp, LOCK_UN);
fclose(
\$
fp);
}
EOF
# invoke shared powerdown routines
.
/usr/local/etc/rc.halt.common
# power down the system
/sbin/shutdown
-op
now
src/etc/rc.halt.common
0 → 100755
View file @
338f71c2
#!/bin/sh
# shutdown rc scripts
/usr/local/etc/rc.opnsense stop
# backup volatile internals
/usr/local/etc/rc.backup_rrd
/usr/local/etc/rc.backup_dhcpleases
/usr/local/etc/rc.savevouchers
# wait for config lock to release
php
-a
>
/dev/null
<<
EOF
\$
fp = fopen('/conf/config.xml', "w+");
if (flock(
\$
fp, LOCK_EX)) {
flock(
\$
fp, LOCK_UN);
fclose(
\$
fp);
}
EOF
# run beep sequence if enabled
/usr/local/bin/beep.sh stop
src/etc/rc.reboot
View file @
338f71c2
#!/bin/sh
# shutdown rc scripts
/usr/local/etc/rc.opnsense stop
/usr/local/etc/rc.backup_rrd
/usr/local/etc/rc.backup_dhcpleases
# wait for config lock to release
php
-a
>
/dev/null
<<
EOF
\$
fp = fopen('/conf/config.xml', "w+");
if (flock(
\$
fp, LOCK_EX)) {
flock(
\$
fp, LOCK_UN);
fclose(
\$
fp);
}
EOF
# invoke shared powerdown routines
.
/usr/local/etc/rc.halt.common
# reboot the system
/sbin/shutdown
-or
now
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