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
b2653d0e
Commit
b2653d0e
authored
Apr 01, 2015
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
voucher: try to pin down where boot import fails; style update while at it
parent
14b3fa5c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
64 deletions
+69
-64
voucher.inc
src/etc/inc/voucher.inc
+66
-61
rc.bootup
src/etc/rc.bootup
+3
-3
No files found.
src/etc/inc/voucher.inc
View file @
b2653d0e
...
...
@@ -274,84 +274,89 @@ function voucher_configure($sync = false)
{
global
$config
,
$cpzone
;
if
(
is_array
(
$config
[
'voucher'
]))
{
foreach
(
$config
[
'voucher'
]
as
$voucherzone
=>
$vcfg
)
{
if
(
file_exists
(
"/var/run/booting"
))
echo
gettext
(
"Enabling voucher support... "
);
$cpzone
=
$voucherzone
;
$error
=
voucher_configure_zone
(
$sync
);
if
(
file_exists
(
"/var/run/booting"
))
{
if
(
$error
)
echo
"error
\n
"
;
else
echo
"done
\n
"
;
}
$ret
=
true
;
if
(
!
is_array
(
$config
[
'voucher'
]))
{
return
$ret
;
}
foreach
(
$config
[
'voucher'
]
as
$voucherzone
=>
$vcfg
)
{
$cpzone
=
$voucherzone
;
$error
=
voucher_configure_zone
(
$sync
);
if
(
$error
)
{
$ret
=
false
;
}
}
return
$ret
;
}
function
voucher_configure_zone
(
$sync
=
false
)
{
function
voucher_configure_zone
(
$sync
=
false
)
{
global
$config
,
$g
,
$cpzone
;
if
(
!
isset
(
$config
[
'voucher'
][
$cpzone
][
'enable'
]))
if
(
!
isset
(
$config
[
'voucher'
][
$cpzone
][
'enable'
]))
{
return
0
;
if
(
$sync
==
true
)
captiveportal_syslog
(
"Writing voucher db from sync data..."
);
}
$voucherlck
=
lock
(
"voucher
{
$cpzone
}
"
,
LOCK_EX
);
/* write public key used to verify vouchers */
$pubkey
=
base64_decode
(
$config
[
'voucher'
][
$cpzone
][
'publickey'
]);
$fd
=
fopen
(
"
{
$g
[
'varetc_path'
]
}
/voucher_
{
$cpzone
}
.public"
,
"w"
);
if
(
!
$fd
)
{
captiveportal_syslog
(
"Voucher error: cannot write voucher.public
\n
"
);
unlock
(
$voucherlck
);
return
1
;
}
fwrite
(
$fd
,
$pubkey
);
fclose
(
$fd
);
@
chmod
(
"
{
$g
[
'varetc_path'
]
}
/voucher_
{
$cpzone
}
.public"
,
0600
);
/* write config file used by voucher binary to decode vouchers */
$fd
=
fopen
(
"
{
$g
[
'varetc_path'
]
}
/voucher_
{
$cpzone
}
.cfg"
,
"w"
);
if
(
!
$fd
)
{
printf
(
gettext
(
"Error: cannot write voucher.cfg"
)
.
"
\n
"
);
unlock
(
$voucherlck
);
return
1
;
}
fwrite
(
$fd
,
"
{
$config
[
'voucher'
][
$cpzone
][
'rollbits'
]
}
,
{
$config
[
'voucher'
][
$cpzone
][
'ticketbits'
]
}
,
{
$config
[
'voucher'
][
$cpzone
][
'checksumbits'
]
}
,
{
$config
[
'voucher'
][
$cpzone
][
'magic'
]
}
,
{
$config
[
'voucher'
][
$cpzone
][
'charset'
]
}
\n
"
);
fclose
(
$fd
);
@
chmod
(
"
{
$g
[
'varetc_path'
]
}
/voucher_
{
$cpzone
}
.cfg"
,
0600
);
/* write public key used to verify vouchers */
$pubkey
=
base64_decode
(
$config
[
'voucher'
][
$cpzone
][
'publickey'
]);
$fd
=
fopen
(
"
{
$g
[
'varetc_path'
]
}
/voucher_
{
$cpzone
}
.public"
,
"w"
);
if
(
!
$fd
)
{
captiveportal_syslog
(
"Voucher error: cannot write voucher.public
\n
"
);
unlock
(
$voucherlck
);
return
1
;
}
fwrite
(
$fd
,
$pubkey
);
fclose
(
$fd
);
@
chmod
(
"
{
$g
[
'varetc_path'
]
}
/voucher_
{
$cpzone
}
.public"
,
0600
);
/* write config file used by voucher binary to decode vouchers */
$fd
=
fopen
(
"
{
$g
[
'varetc_path'
]
}
/voucher_
{
$cpzone
}
.cfg"
,
"w"
);
if
(
!
$fd
)
{
captiveportal_syslog
(
gettext
(
"Error: cannot write voucher.cfg"
)
.
"
\n
"
);
unlock
(
$voucherlck
);
return
1
;
}
fwrite
(
$fd
,
"
{
$config
[
'voucher'
][
$cpzone
][
'rollbits'
]
}
,
{
$config
[
'voucher'
][
$cpzone
][
'ticketbits'
]
}
,
{
$config
[
'voucher'
][
$cpzone
][
'checksumbits'
]
}
,
{
$config
[
'voucher'
][
$cpzone
][
'magic'
]
}
,
{
$config
[
'voucher'
][
$cpzone
][
'charset'
]
}
\n
"
);
fclose
(
$fd
);
@
chmod
(
"
{
$g
[
'varetc_path'
]
}
/voucher_
{
$cpzone
}
.cfg"
,
0600
);
unlock
(
$voucherlck
);
if
((
file_exists
(
"/var/run/booting"
)
||
$sync
==
true
)
&&
is_array
(
$config
[
'voucher'
][
$cpzone
][
'roll'
]))
{
if
(
!
$sync
)
{
return
0
;
}
captiveportal_syslog
(
'Writing voucher db from sync data...'
);
if
(
isset
(
$config
[
'voucher'
][
$cpzone
][
'roll'
]))
{
$voucherlck
=
lock
(
"voucher
{
$cpzone
}
"
,
LOCK_EX
);
// create active and used DB per roll on ramdisk from config
foreach
(
$config
[
'voucher'
][
$cpzone
][
'roll'
]
as
$rollent
)
{
$roll
=
$rollent
[
'number'
]
;
voucher_write_used_db
(
$roll
,
$rollent
[
'used'
])
;
$minutes
=
$rollent
[
'minutes'
]
;
$active_vouchers
=
array
()
;
$a_active
=
&
$rollent
[
'active'
];
if
(
is_array
(
$a_active
)
)
{
foreach
(
$a_active
as
$activent
)
{
$voucher
=
$activent
[
'voucher
'
];
$timestamp
=
$activent
[
'timestamp
'
];
$minutes
=
$activent
[
'minutes'
];
// its tempting to check for expired timestamps, but during
// bootup, we most likely don't have the correct time time.
$active_vouchers
[
$voucher
]
=
"
$timestamp
,
$minutes
"
;
}
}
voucher_write_active_db
(
$roll
,
$active_vouchers
);
}
// create active and used DB per roll on ramdisk from config
foreach
(
$config
[
'voucher'
][
$cpzone
][
'roll'
]
as
$rollent
)
{
$roll
=
$rollent
[
'number'
];
voucher_write_used_db
(
$roll
,
$rollent
[
'used'
])
;
$minutes
=
$rollent
[
'minutes'
]
;
$active_vouchers
=
array
()
;
$a_active
=
&
$rollent
[
'active'
]
;
if
(
is_array
(
$a_active
))
{
foreach
(
$a_active
as
$activent
)
{
$voucher
=
$activent
[
'voucher'
];
$timestamp
=
$activent
[
'timestamp
'
];
$minutes
=
$activent
[
'minutes
'
];
// its tempting to check for expired timestamps, but during
// bootup, we most likely don't have the correct time time.
$active_vouchers
[
$voucher
]
=
"
$timestamp
,
$minutes
"
;
}
}
voucher_write_active_db
(
$roll
,
$active_vouchers
);
}
unlock
(
$voucherlck
);
}
}
return
0
;
}
...
...
src/etc/rc.bootup
View file @
b2653d0e
...
...
@@ -294,12 +294,12 @@ filter_configure_sync();
/* setup pppoe and pptp */
vpn_setup
();
/* start Voucher support */
echo
'Enabling voucher support...'
.
(
voucher_configure
(
true
)
?
'done.'
:
'failed.'
);
/* start the captive portal */
captiveportal_configure
();
/* start Voucher support */
voucher_configure
();
/* start IPsec tunnels */
$ipsec_dynamic_hosts
=
vpn_ipsec_configure
();
...
...
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