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
398ae5bb
Commit
398ae5bb
authored
Jun 18, 2016
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
system: migrate setup_serial_port() and friends
parent
951a4ceb
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
107 additions
and
107 deletions
+107
-107
config.lib.inc
src/etc/inc/config.lib.inc
+0
-19
pfsense-utils.inc
src/etc/inc/pfsense-utils.inc
+0
-81
system.inc
src/etc/inc/system.inc
+100
-0
rc.initial.defaults
src/etc/rc.initial.defaults
+1
-2
diag_defaults.php
src/www/diag_defaults.php
+6
-5
No files found.
src/etc/inc/config.lib.inc
View file @
398ae5bb
...
@@ -193,25 +193,6 @@ function write_config($desc = '', $backup = true)
...
@@ -193,25 +193,6 @@ function write_config($desc = '', $backup = true)
return
$config
;
return
$config
;
}
}
/****f* config/reset_factory_defaults
* NAME
* reset_factory_defaults - Reset the system to its default configuration.
******/
function
reset_factory_defaults
(
$sync
=
true
)
{
mwexec
(
'/bin/rm -r /conf/*'
);
disable_security_checks
();
setup_serial_port
(
false
);
/* as we go through a special case directly reboot */
$shutdown_cmd
=
'/sbin/shutdown -or now'
;
if
(
$sync
)
{
mwexec
(
$shutdown_cmd
);
}
else
{
mwexec_bg
(
$shutdown_cmd
);
}
}
function
config_restore
(
$conffile
)
function
config_restore
(
$conffile
)
{
{
global
$config
;
global
$config
;
...
...
src/etc/inc/pfsense-utils.inc
View file @
398ae5bb
...
@@ -92,87 +92,6 @@ function restore_config_section($section_name, $new_contents)
...
@@ -92,87 +92,6 @@ function restore_config_section($section_name, $new_contents)
return
true
;
return
true
;
}
}
function
setup_serial_port
(
$sync
=
true
)
{
global
$config
;
$serialspeed
=
(
!
empty
(
$config
[
'system'
][
'serialspeed'
])
&&
is_numeric
(
$config
[
'system'
][
'serialspeed'
]))
?
$config
[
'system'
][
'serialspeed'
]
:
'115200'
;
$serial_enabled
=
isset
(
$config
[
'system'
][
'enableserial'
]);
// ** serial console - write out /boot.config
if
(
$serial_enabled
)
{
file_put_contents
(
'/boot.config'
,
"-S
{
$serialspeed
}
-D
\n
"
);
}
elseif
(
file_exists
(
'/boot.config'
))
{
unlink
(
'/boot.config'
);
}
// ** console settings in /boot/loader.conf
$new_boot_config
=
array
();
$new_boot_config
[
'boot_multicons'
]
=
$serial_enabled
?
'"YES"'
:
null
;
$new_boot_config
[
'boot_serial'
]
=
$serial_enabled
?
'"YES"'
:
null
;
if
(
$serial_enabled
)
{
$primaryconsole
=
!
empty
(
$config
[
'system'
][
'primaryconsole'
])
?
$config
[
'system'
][
'primaryconsole'
]
:
""
;
$new_boot_config
[
'console'
]
=
$primaryconsole
==
"video"
?
'"vidconsole,comconsole"'
:
'"comconsole,vidconsole"'
;
}
else
{
$new_boot_config
[
'console'
]
=
null
;
}
$new_boot_config
[
'comconsole_speed'
]
=
'"'
.
$serialspeed
.
'"'
;
$new_boot_config
[
'hw.usb.no_pf'
]
=
'"1"'
;
$new_boot_config
[
'autoboot_delay'
]
=
'"3"'
;
$new_loader_conf
=
""
;
// construct OPNsense config for /boot/loader.conf
foreach
(
$new_boot_config
as
$param
=>
$value
)
{
if
(
!
empty
(
$value
))
{
$new_loader_conf
.=
"
{
$param
}
=
{
$value
}
\n
"
;
}
}
// copy non matched settings in /boot/loader.conf
foreach
(
explode
(
"
\n
"
,
@
file_get_contents
(
'/boot/loader.conf'
))
as
$line
)
{
if
(
!
empty
(
$line
)
&&
!
array_key_exists
(
trim
(
explode
(
'='
,
$line
)[
0
]),
$new_boot_config
))
{
$new_loader_conf
.=
$line
.
"
\n
"
;
}
}
@
file_put_contents
(
'/boot/loader.conf'
,
$new_loader_conf
);
// ** setup /etc/ttys
// minimize chances of /etc/ttys corruption, keep a copy of the original ttys file
if
(
!
file_exists
(
'/etc/ttys.opnsense'
)
||
filesize
(
'/etc/ttys.opnsense'
)
<
100
)
{
copy
(
'/etc/ttys'
,
'/etc/ttys.opnsense'
);
}
$fd
=
fopen
(
"/etc/ttys"
,
"w"
);
$on_off
=
$serial_enabled
?
'on'
:
'off'
;
if
(
isset
(
$config
[
'system'
][
'disableconsolemenu'
]))
{
$console_type
=
'Pc'
;
$serial_type
=
'std.'
.
$serialspeed
;
}
else
{
$console_type
=
'al.Pc'
;
$serial_type
=
'al.'
.
$serialspeed
;
}
foreach
(
explode
(
"
\n
"
,
file_get_contents
(
"/etc/ttys.opnsense"
))
as
$tty
)
{
if
(
stristr
(
$tty
,
"ttyv0"
))
{
fwrite
(
$fd
,
"ttyv0
\"
/usr/libexec/getty
{
$console_type
}
\"
cons25 on secure
\n
"
);
}
elseif
(
stristr
(
$tty
,
"ttyu0"
))
{
fwrite
(
$fd
,
"ttyu0
\"
/usr/libexec/getty
{
$serial_type
}
\"
cons25
{
$on_off
}
secure
\n
"
);
}
elseif
(
!
empty
(
$tty
))
{
fwrite
(
$fd
,
$tty
.
"
\n
"
);
}
}
fclose
(
$fd
);
if
(
$sync
)
{
reload_ttys
();
}
}
function
reload_ttys
()
{
/* force init(8) to reload /etc/ttys */
exec
(
'/bin/kill -HUP 1'
);
}
/* This xml 2 array function is courtesy of the php.net comment section on xml_parse.
/* This xml 2 array function is courtesy of the php.net comment section on xml_parse.
* it is roughly 4 times faster then our existing pfSense parser but due to the large
* it is roughly 4 times faster then our existing pfSense parser but due to the large
* size of the RRD xml dumps this is required.
* size of the RRD xml dumps this is required.
...
...
src/etc/inc/system.inc
View file @
398ae5bb
...
@@ -1925,3 +1925,103 @@ function load_thermal_module()
...
@@ -1925,3 +1925,103 @@ function load_thermal_module()
mwexecf
(
'/sbin/kldload %s'
,
$config
[
'system'
][
'thermal_hardware'
],
true
);
mwexecf
(
'/sbin/kldload %s'
,
$config
[
'system'
][
'thermal_hardware'
],
true
);
}
}
}
}
function
setup_serial_port
(
$sync
=
true
)
{
global
$config
;
$serialspeed
=
(
!
empty
(
$config
[
'system'
][
'serialspeed'
])
&&
is_numeric
(
$config
[
'system'
][
'serialspeed'
]))
?
$config
[
'system'
][
'serialspeed'
]
:
'115200'
;
$serial_enabled
=
isset
(
$config
[
'system'
][
'enableserial'
]);
// ** serial console - write out /boot.config
if
(
$serial_enabled
)
{
file_put_contents
(
'/boot.config'
,
"-S
{
$serialspeed
}
-D
\n
"
);
}
elseif
(
file_exists
(
'/boot.config'
))
{
unlink
(
'/boot.config'
);
}
// ** console settings in /boot/loader.conf
$new_boot_config
=
array
();
$new_boot_config
[
'boot_multicons'
]
=
$serial_enabled
?
'"YES"'
:
null
;
$new_boot_config
[
'boot_serial'
]
=
$serial_enabled
?
'"YES"'
:
null
;
if
(
$serial_enabled
)
{
$primaryconsole
=
!
empty
(
$config
[
'system'
][
'primaryconsole'
])
?
$config
[
'system'
][
'primaryconsole'
]
:
""
;
$new_boot_config
[
'console'
]
=
$primaryconsole
==
"video"
?
'"vidconsole,comconsole"'
:
'"comconsole,vidconsole"'
;
}
else
{
$new_boot_config
[
'console'
]
=
null
;
}
$new_boot_config
[
'comconsole_speed'
]
=
'"'
.
$serialspeed
.
'"'
;
$new_boot_config
[
'hw.usb.no_pf'
]
=
'"1"'
;
$new_boot_config
[
'autoboot_delay'
]
=
'"3"'
;
$new_loader_conf
=
""
;
// construct OPNsense config for /boot/loader.conf
foreach
(
$new_boot_config
as
$param
=>
$value
)
{
if
(
!
empty
(
$value
))
{
$new_loader_conf
.=
"
{
$param
}
=
{
$value
}
\n
"
;
}
}
// copy non matched settings in /boot/loader.conf
foreach
(
explode
(
"
\n
"
,
@
file_get_contents
(
'/boot/loader.conf'
))
as
$line
)
{
if
(
!
empty
(
$line
)
&&
!
array_key_exists
(
trim
(
explode
(
'='
,
$line
)[
0
]),
$new_boot_config
))
{
$new_loader_conf
.=
$line
.
"
\n
"
;
}
}
@
file_put_contents
(
'/boot/loader.conf'
,
$new_loader_conf
);
// ** setup /etc/ttys
// minimize chances of /etc/ttys corruption, keep a copy of the original ttys file
if
(
!
file_exists
(
'/etc/ttys.opnsense'
)
||
filesize
(
'/etc/ttys.opnsense'
)
<
100
)
{
copy
(
'/etc/ttys'
,
'/etc/ttys.opnsense'
);
}
$fd
=
fopen
(
"/etc/ttys"
,
"w"
);
$on_off
=
$serial_enabled
?
'on'
:
'off'
;
if
(
isset
(
$config
[
'system'
][
'disableconsolemenu'
]))
{
$console_type
=
'Pc'
;
$serial_type
=
'std.'
.
$serialspeed
;
}
else
{
$console_type
=
'al.Pc'
;
$serial_type
=
'al.'
.
$serialspeed
;
}
foreach
(
explode
(
"
\n
"
,
file_get_contents
(
"/etc/ttys.opnsense"
))
as
$tty
)
{
if
(
stristr
(
$tty
,
"ttyv0"
))
{
fwrite
(
$fd
,
"ttyv0
\"
/usr/libexec/getty
{
$console_type
}
\"
cons25 on secure
\n
"
);
}
elseif
(
stristr
(
$tty
,
"ttyu0"
))
{
fwrite
(
$fd
,
"ttyu0
\"
/usr/libexec/getty
{
$serial_type
}
\"
cons25
{
$on_off
}
secure
\n
"
);
}
elseif
(
!
empty
(
$tty
))
{
fwrite
(
$fd
,
$tty
.
"
\n
"
);
}
}
fclose
(
$fd
);
if
(
$sync
)
{
reload_ttys
();
}
}
function
reload_ttys
()
{
/* force init(8) to reload /etc/ttys */
exec
(
'/bin/kill -HUP 1'
);
}
/****f* config/reset_factory_defaults
* NAME
* reset_factory_defaults - Reset the system to its default configuration.
******/
function
reset_factory_defaults
(
$sync
=
true
)
{
mwexec
(
'/bin/rm -r /conf/*'
);
disable_security_checks
();
setup_serial_port
(
false
);
/* as we go through a special case directly reboot */
$shutdown_cmd
=
'/sbin/shutdown -or now'
;
if
(
$sync
)
{
mwexec
(
$shutdown_cmd
);
}
else
{
mwexec_bg
(
$shutdown_cmd
);
}
}
src/etc/rc.initial.defaults
View file @
398ae5bb
...
@@ -27,10 +27,9 @@
...
@@ -27,10 +27,9 @@
POSSIBILITY OF SUCH DAMAGE.
POSSIBILITY OF SUCH DAMAGE.
*/
*/
/* parse the configuration and include all functions used below */
require_once
(
"util.inc"
);
require_once
(
"util.inc"
);
require_once
(
"config.lib.inc"
);
require_once
(
"config.lib.inc"
);
require_once
(
"
pfsense-utils
.inc"
);
require_once
(
"
system
.inc"
);
$fp
=
fopen
(
'php://stdin'
,
'r'
);
$fp
=
fopen
(
'php://stdin'
,
'r'
);
$yes_no_prompt
=
'[y|n]? '
;
$yes_no_prompt
=
'[y|n]? '
;
...
...
src/www/diag_defaults.php
View file @
398ae5bb
...
@@ -29,11 +29,11 @@
...
@@ -29,11 +29,11 @@
*/
*/
require_once
(
"guiconfig.inc"
);
require_once
(
"guiconfig.inc"
);
require_once
(
"
pfsense-utils
.inc"
);
require_once
(
"
system
.inc"
);
include
(
"head.inc"
);
include
(
"head.inc"
);
?>
?>
<body>
<body>
<?php
include
(
"fbegin.inc"
);
?>
<?php
include
(
"fbegin.inc"
);
?>
...
@@ -69,11 +69,12 @@ include("head.inc");
...
@@ -69,11 +69,12 @@ include("head.inc");
</div>
</div>
</div>
</div>
</section>
</section>
<?php
include
(
"foot.inc"
);
<?php
// reset to factory defaults when submit is pressed.
include
(
"foot.inc"
);
if
(
$_SERVER
[
'REQUEST_METHOD'
]
===
'POST'
)
{
if
(
$_SERVER
[
'REQUEST_METHOD'
]
===
'POST'
)
{
if
(
!
empty
(
$_POST
[
'Submit'
]))
{
if
(
!
empty
(
$_POST
[
'Submit'
]))
{
reset_factory_defaults
(
false
);
reset_factory_defaults
(
false
);
}
}
}
}
?>
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