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
36b9cb78
Commit
36b9cb78
authored
Mar 27, 2015
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inc: remove more legacy package service glue
parent
c4782349
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
276 deletions
+16
-276
service-utils.inc
src/etc/inc/service-utils.inc
+9
-176
system.inc
src/etc/inc/system.inc
+4
-7
openntpd.inc
src/pkg/openntpd.inc
+0
-55
openntpd.xml
src/pkg/openntpd.xml
+0
-29
services_ntpd.php
src/www/services_ntpd.php
+3
-9
No files found.
src/etc/inc/service-utils.inc
View file @
36b9cb78
...
...
@@ -34,166 +34,6 @@ require_once("vpn.inc");
require_once
(
"vslb.inc"
);
require_once
(
"gwlb.inc"
);
define
(
"RCFILEPREFIX"
,
"/usr/local/etc/rc.d/"
);
if
(
!
function_exists
(
'write_rcfile'
))
{
function
write_rcfile
(
$params
)
{
global
$g
;
safe_mkdir
(
RCFILEPREFIX
);
$rcfile_fullname
=
RCFILEPREFIX
.
$params
[
'file'
];
if
(
!
file_exists
(
$rcfile_fullname
)
&&
!
is_link
(
$rcfile_fullname
)
&&
!
touch
(
$rcfile_fullname
))
return
false
;
if
(
!
is_writable
(
$rcfile_fullname
)
||
empty
(
$params
[
'start'
]))
return
false
;
$towrite
=
"#!/bin/sh
\n
"
;
$towrite
.=
"# This file was automatically generated
\n
# by the
{
$g
[
'product_name'
]
}
service handler.
\n\n
"
;
/* write our rc functions */
$towrite
.=
"rc_start() {\n"
;
$towrite
.=
"
\t
{
$params
[
'start'
]
}
\n
"
;
$towrite
.=
"}
\n\n
"
;
if
(
!
empty
(
$params
[
'stop'
]))
{
$tokill
=&
$params
[
'stop'
];
}
else
if
(
!
empty
(
$params
[
'executable'
]))
{
/* just nuke the executable */
$tokill
=
"/usr/bin/killall "
.
escapeshellarg
(
$params
[
'executable'
]);
}
else
{
/* make an educated guess (bad) */
$tokill
=
array_pop
(
explode
(
'/'
,
array_shift
(
explode
(
' '
,
$params
[
'start'
]))));
}
$towrite
.=
"rc_stop() {\n"
;
$towrite
.=
"
\t
{
$tokill
}
\n
"
;
$towrite
.=
"}
\n\n
"
;
/* begin rcfile logic */
$towrite
.=
"case
\$
1 in
\n\t
start)
\n\t\t
rc_start
\n\t\t
;;
\n\t
stop)
\n\t\t
rc_stop
\n\t\t
;;
\n\t
restart)
\n\t\t
rc_stop
\n\t\t
rc_start
\n\t\t
;;
\n
esac
\n\n
"
;
@
file_put_contents
(
$rcfile_fullname
,
$towrite
);
unset
(
$towrite
);
@
chmod
(
"
{
$rcfile_fullname
}
"
,
0755
);
return
;
}
}
if
(
!
function_exists
(
'start_service'
))
{
function
start_service
(
$name
)
{
global
$config
;
if
(
empty
(
$name
))
return
;
if
(
is_array
(
$config
[
'installedpackages'
])
&&
is_array
(
$config
[
'installedpackages'
][
'service'
]))
{
foreach
(
$config
[
'installedpackages'
][
'service'
]
as
$service
)
{
if
(
strtolower
(
$service
[
'name'
])
==
strtolower
(
$name
))
{
if
(
$service
[
'rcfile'
])
{
$prefix
=
RCFILEPREFIX
;
if
(
!
empty
(
$service
[
'prefix'
]))
{
$prefix
=&
$service
[
'prefix'
];
}
if
(
file_exists
(
"
{
$prefix
}{
$service
[
'rcfile'
]
}
"
)
||
is_link
(
"
{
$prefix
}{
$service
[
'rcfile'
]
}
"
))
{
mwexec_bg
(
"
{
$prefix
}{
$service
[
'rcfile'
]
}
start"
);
}
}
if
(
!
empty
(
$service
[
'startcmd'
]))
eval
(
$service
[
'startcmd'
]);
break
;
}
}
}
}
}
if
(
!
function_exists
(
'stop_service'
))
{
function
stop_service
(
$name
)
{
global
$config
;
if
(
empty
(
$name
))
return
;
if
(
is_array
(
$config
[
'installedpackages'
])
&&
is_array
(
$config
[
'installedpackages'
][
'service'
]))
{
foreach
(
$config
[
'installedpackages'
][
'service'
]
as
$service
)
{
if
(
strtolower
(
$service
[
'name'
])
==
strtolower
(
$name
))
{
if
(
$service
[
'rcfile'
])
{
$prefix
=
RCFILEPREFIX
;
if
(
!
empty
(
$service
[
'prefix'
]))
{
$prefix
=&
$service
[
'prefix'
];
}
if
(
file_exists
(
"
{
$prefix
}{
$service
[
'rcfile'
]
}
"
)
||
is_link
(
"
{
$prefix
}{
$service
[
'rcfile'
]
}
"
))
{
mwexec
(
"
{
$prefix
}{
$service
[
'rcfile'
]
}
stop"
);
}
return
;
}
if
(
!
empty
(
$service
[
'stopcmd'
]))
eval
(
$service
[
'stopcmd'
]);
break
;
}
}
}
}
}
if
(
!
function_exists
(
'restart_service'
))
{
function
restart_service
(
$name
)
{
global
$config
;
if
(
empty
(
$name
))
return
;
stop_service
(
$name
);
start_service
(
$name
);
if
(
is_array
(
$config
[
'installedpackages'
])
&&
is_array
(
$config
[
'installedpackages'
][
'service'
]))
{
foreach
(
$config
[
'installedpackages'
][
'service'
]
as
$service
)
{
if
(
strtolower
(
$service
[
'name'
])
==
strtolower
(
$name
))
{
if
(
$service
[
'restartcmd'
])
{
eval
(
$service
[
'restartcmd'
]);
}
break
;
}
}
}
}
}
if
(
!
function_exists
(
'is_pid_running'
))
{
function
is_pid_running
(
$pidfile
)
{
if
(
!
file_exists
(
$pidfile
))
return
false
;
return
(
isvalidpid
(
$pidfile
));
}
}
if
(
!
function_exists
(
'is_dhcp_running'
))
{
function
is_dhcp_running
(
$interface
)
{
$status
=
find_dhclient_process
(
$interface
);
if
(
$status
!=
0
)
return
true
;
return
false
;
}
}
if
(
!
function_exists
(
'restart_service_if_running'
))
{
function
restart_service_if_running
(
$service
)
{
global
$config
;
if
(
is_service_running
(
$service
))
restart_service
(
$service
);
return
;
}
}
if
(
!
function_exists
(
'is_service_enabled'
))
{
function
is_service_enabled
(
$service_name
)
{
...
...
@@ -473,21 +313,21 @@ if (!function_exists('get_service_status')) {
global
$g
;
switch
(
$service
[
'name'
])
{
case
"openvpn"
:
$running
=
is
_pid_running
(
"
{
$g
[
'varrun_path'
]
}
/openvpn_
{
$service
[
'mode'
]
}{
$service
[
'vpnid'
]
}
.pid"
);
$running
=
is
validpid
(
"
{
$g
[
'varrun_path'
]
}
/openvpn_
{
$service
[
'mode'
]
}{
$service
[
'vpnid'
]
}
.pid"
);
break
;
case
"captiveportal"
:
$running
=
is
_pid_running
(
"
{
$g
[
'varrun_path'
]
}
/lighty-
{
$service
[
'zone'
]
}
-CaptivePortal.pid"
);
$running
=
is
validpid
(
"
{
$g
[
'varrun_path'
]
}
/lighty-
{
$service
[
'zone'
]
}
-CaptivePortal.pid"
);
if
(
isset
(
$config
[
'captiveportal'
][
$service
[
'zone'
]][
'httpslogin'
]))
$running
=
$running
&&
is
_pid_running
(
"
{
$g
[
'varrun_path'
]
}
/lighty-
{
$service
[
'zone'
]
}
-CaptivePortal-SSL.pid"
);
$running
=
$running
&&
is
validpid
(
"
{
$g
[
'varrun_path'
]
}
/lighty-
{
$service
[
'zone'
]
}
-CaptivePortal-SSL.pid"
);
break
;
case
"vhosts-http"
:
$running
=
is
_pid_running
(
"
{
$g
[
'varrun_path'
]
}
/vhosts-http.pid"
);
$running
=
is
validpid
(
"
{
$g
[
'varrun_path'
]
}
/vhosts-http.pid"
);
break
;
case
"dhcrelay6"
:
$running
=
is
_pid_running
(
"
{
$g
[
'varrun_path'
]
}
/dhcrelay6.pid"
);
$running
=
is
validpid
(
"
{
$g
[
'varrun_path'
]
}
/dhcrelay6.pid"
);
break
;
case
'ipsec'
:
$running
=
is
_pid_running
(
"
{
$g
[
'varrun_path'
]
}
/charon.pid"
);
$running
=
is
validpid
(
"
{
$g
[
'varrun_path'
]
}
/charon.pid"
);
break
;
default
:
$running
=
is_service_running
(
$service
[
'name'
]);
...
...
@@ -592,7 +432,6 @@ if (!function_exists('service_control_start')) {
captiveportal_init_webgui_zonename
(
$zone
);
break
;
case
'ntpd'
:
case
'openntpd'
:
system_ntp_configure
();
break
;
case
'apinger'
:
...
...
@@ -638,7 +477,7 @@ if (!function_exists('service_control_start')) {
relayd_configure
();
break
;
default
:
start_service
(
$name
);
log_error
(
gettext
(
"Could not start unknown service `%s'"
,
$name
)
);
break
;
}
return
sprintf
(
gettext
(
"%s has been started."
),
htmlspecialchars
(
$name
));
...
...
@@ -663,9 +502,6 @@ if (!function_exists('service_control_stop')) {
case
'ntpd'
:
killbyname
(
"ntpd"
);
break
;
case
'openntpd'
:
killbyname
(
"openntpd"
);
break
;
case
'apinger'
:
killbypid
(
"
{
$g
[
'varrun_path'
]
}
/apinger.pid"
);
break
;
...
...
@@ -714,7 +550,7 @@ if (!function_exists('service_control_stop')) {
mwexec
(
'pkill relayd'
);
break
;
default
:
stop_service
(
$name
);
log_error
(
gettext
(
"Could not stop unknown service `%s'"
,
$name
)
);
break
;
}
return
sprintf
(
gettext
(
"%s has been stopped."
),
htmlspecialchars
(
$name
));
...
...
@@ -740,7 +576,6 @@ if (!function_exists('service_control_restart')) {
captiveportal_configure
();
break
;
case
'ntpd'
:
case
'openntpd'
:
system_ntp_configure
();
break
;
case
'apinger'
:
...
...
@@ -790,11 +625,9 @@ if (!function_exists('service_control_restart')) {
relayd_configure
(
true
);
break
;
default
:
restart_service
(
$name
);
log_error
(
gettext
(
"Could not restart unknown service `%s'"
,
$name
)
);
break
;
}
return
sprintf
(
gettext
(
"%s has been restarted."
),
htmlspecialchars
(
$name
));
}
}
?>
src/etc/inc/system.inc
View file @
36b9cb78
...
...
@@ -1588,13 +1588,10 @@ function system_ntp_configure($start_ntpd = true)
}
if
(
empty
(
$config
[
'ntpd'
][
'interface'
]))
if
(
is_array
(
$config
[
'installedpackages'
][
'openntpd'
])
&&
!
empty
(
$config
[
'installedpackages'
][
'openntpd'
][
'config'
][
0
][
'interface'
]))
$interfaces
=
explode
(
","
,
$config
[
'installedpackages'
][
'openntpd'
][
'config'
][
0
][
'interface'
]);
else
$interfaces
=
array
();
else
$interfaces
=
explode
(
","
,
$config
[
'ntpd'
][
'interface'
]);
$interfaces
=
array
();
if
(
isset
(
$config
[
'ntpd'
][
'interface'
]))
{
$interfaces
=
explode
(
','
,
$config
[
'ntpd'
][
'interface'
]);
}
if
(
is_array
(
$interfaces
)
&&
count
(
$interfaces
))
{
$ntpcfg
.=
"interface ignore all
\n
"
;
...
...
src/pkg/openntpd.inc
deleted
100644 → 0
View file @
c4782349
<?php
require_once
(
'config.inc'
);
require_once
(
'globals.inc'
);
require_once
(
'service-utils.inc'
);
function
openntpd_install
()
{
global
$g
;
$config_file
=
$g
[
'varetc_path'
]
.
'/openntpd.conf'
;
$rcfile
=
array
();
$rcfile
[
'file'
]
=
'openntpd.sh'
;
$rcfile
[
'start'
]
=
<<<EOD
if [ -f $config_file ]; then
ntpd -f $config_file
fi
EOD;
$rcfile
[
'stop'
]
=
"killall ntpd"
;
write_rcfile
(
$rcfile
);
}
function
openntpd_get_iface_ip
(
$iface
)
{
$iface
=
convert_friendly_interface_to_real_interface_name
(
$iface
);
$line
=
trim
(
shell_exec
(
"ifconfig "
.
escapeshellarg
(
$iface
)
.
" | grep inet | grep -v inet6"
));
list
(
$dummy
,
$ip
,
$dummy2
,
$dummy3
)
=
explode
(
' '
,
$line
);
return
$ip
;
}
function
openntpd_resync
()
{
global
$g
,
$config
;
$settings
=
$config
[
'installedpackages'
][
'openntpd'
][
'config'
][
0
];
$config_file
=
$g
[
'varetc_path'
]
.
'/openntpd.conf'
;
if
(
$settings
[
'enable'
]
==
'on'
)
{
$conf
=
''
;
$ifaces
=
explode
(
','
,
$settings
[
'interface'
]);
$ips
=
array_map
(
'openntpd_get_iface_ip'
,
$ifaces
);
foreach
(
$ips
as
$ip
)
$conf
.=
"listen on
$ip
\n
"
;
$servers
=
explode
(
','
,
$config
[
'system'
][
'timeservers'
]);
foreach
(
$servers
as
$server
)
$conf
.=
"servers
$server
\n
"
;
file_put_contents
(
$config_file
,
$conf
);
}
else
{
if
(
file_exists
(
$config_file
))
unlink
(
$config_file
);
}
restart_service
(
'openntpd'
);
}
src/pkg/openntpd.xml
deleted
100644 → 0
View file @
c4782349
<?xml version="1.0" encoding="utf-8"?>
<packagegui>
<include_file>
system.inc
</include_file>
<name>
openntpd
</name>
<title>
NTP server
</title>
<fields>
<field>
<fieldname>
enable
</fieldname>
<fielddescr>
Enable
</fielddescr>
<description>
Check this to enable the NTP server.
</description>
<type>
checkbox
</type>
</field>
<field>
<fieldname>
interface
</fieldname>
<fielddescr>
Interface
</fielddescr>
<description>
Select the interface(s) the NTP server will listen on.
</description>
<default_value>
lan
</default_value>
<multiple/>
<type>
select_source
</type>
<source>
<![CDATA[get_possible_listen_ips()]]>
</source>
<source_name>
name
</source_name>
<source_value>
value
</source_value>
</field>
</fields>
<custom_php_resync_config_command>
system_ntp_configure();
</custom_php_resync_config_command>
</packagegui>
src/www/services_ntpd.php
View file @
36b9cb78
...
...
@@ -35,18 +35,12 @@ if (!is_array($config['ntpd']))
$config
[
'ntpd'
]
=
array
();
if
(
empty
(
$config
[
'ntpd'
][
'interface'
]))
{
if
(
is_array
(
$config
[
'installedpackages'
][
'openntpd'
])
&&
is_array
(
$config
[
'installedpackages'
][
'openntpd'
][
'config'
])
&&
is_array
(
$config
[
'installedpackages'
][
'openntpd'
][
'config'
][
0
])
&&
!
empty
(
$config
[
'installedpackages'
][
'openntpd'
][
'config'
][
0
][
'interface'
]))
{
$pconfig
[
'interface'
]
=
explode
(
","
,
$config
[
'installedpackages'
][
'openntpd'
][
'config'
][
0
][
'interface'
]);
unset
(
$config
[
'installedpackages'
][
'openntpd'
]);
write_config
(
"Upgraded settings from openttpd"
);
}
else
$pconfig
[
'interface'
]
=
array
();
}
else
$pconfig
[
'interface'
]
=
array
();
}
else
{
$pconfig
[
'interface'
]
=
explode
(
","
,
$config
[
'ntpd'
][
'interface'
]);
}
if
(
$_POST
)
{
unset
(
$input_errors
);
$pconfig
=
$_POST
;
...
...
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