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
4765db05
Commit
4765db05
authored
Apr 16, 2016
by
Franco Fichtner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
services: improve reload by making service script unique
parent
cef101f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
45 deletions
+44
-45
services.inc
src/etc/inc/services.inc
+43
-29
status_services.php
src/www/status_services.php
+1
-16
No files found.
src/etc/inc/services.inc
View file @
4765db05
...
...
@@ -2782,50 +2782,64 @@ function get_service_status_icon($service, $withtext = true, $smallicon = false)
return
$output
;
}
function
get_service_control_links
(
$service
,
$addname
=
false
,
$add_script
=
true
)
function
get_service_control_links
(
$service
,
$addname
=
false
)
{
$stitle
=
$addname
?
$service
[
'name'
]
.
' '
:
''
;
if
(
$add_script
)
{
$output
=
"
$service_id
=
isset
(
$service
[
'id'
])
?
$service
[
'id'
]
:
''
;
$service_act
=
sprintf
(
'srv_status_act_%s%s'
,
$service
[
'name'
],
$service_id
);
$service_title
=
$addname
?
$service
[
'name'
]
.
' '
:
''
;
$template
=
'<span data-service_id="%s" data-service_action="%s" data-service="%s" '
;
$template
.=
'data-toggle="tooltip" data-placement="bottom" title="%s" '
;
$template
.=
'class="btn btn-default %s %s"></span>'
.
PHP_EOL
;
$output
=
"
<script type='text/javascript'>
$( document ).ready(function() {
$('.
srv_status_act
').click(function(event){
$('.
{
$service_act
}
').click(function(event){
event.preventDefault();
params = {};
params['action'] = $(this).data('service_action');
params['service'] = $(this).data('service');
params['id'] = $(this).data('service_id');
$.post('/status_services.php',params, function(data) {
// refresh page after service action
//location.reload(
);
// refresh page after service action
via server
location.reload(true
);
});
});
});
</script>
"
;
}
"
;
if
(
get_service_status
(
$service
))
{
if
(
isset
(
$service
[
'id'
]))
{
$service_id
=
$service
[
'id'
];
}
else
{
$service_id
=
""
;
}
$output
.=
"<span data-service_id=
\"
{
$service_id
}
\"
data-service_action=
\"
restart
\"
data-service=
\"
{
$service
[
'name'
]
}
\"
"
;
$output
.=
" data-toggle=
\"
tooltip
\"
data-placement=
\"
bottom
\"
title=
\"
"
;
$output
.=
sprintf
(
gettext
(
"Restart %sService"
),
$stitle
)
;
$output
.=
"
\"
class=
\"
btn btn-default srv_status_act glyphicon glyphicon-refresh
\"
></span>
\n
"
;
$output
.=
"<span data-service_id=
\"
{
$service_id
}
\"
data-service_action=
\"
stop
\"
data-service=
\"
{
$service
[
'name'
]
}
\"
"
;
$output
.=
" data-toggle=
\"
tooltip
\"
data-placement=
\"
bottom
\"
title=
\"
"
;
$output
.=
sprintf
(
gettext
(
"Stop %sService"
),
$stitle
)
;
$output
.=
"
\"
class=
\"
btn btn-default srv_status_act glyphicon glyphicon-stop
\"
></span>
\n
"
;
}
else
{
/* start service button */
$output
.=
"<span data-service_id=
\"
{
$service_id
}
\"
data-service_action=
\"
start
\"
data-service=
\"
{
$service
[
'name'
]
}
\"
"
;
$output
.=
" data-toggle=
\"
tooltip
\"
data-placement=
\"
bottom
\"
title=
\"
"
;
$output
.=
sprintf
(
gettext
(
"Start %sService"
),
$stitle
)
;
$output
.=
"
\"
class=
\"
btn btn-default srv_status_act glyphicon glyphicon-play
\"
></span>
\n
"
;
$output
.=
sprintf
(
$template
,
$service_id
,
'restart'
,
$service
[
'name'
],
sprintf
(
gettext
(
'Restart %sService'
),
$service_title
),
$service_act
,
'glyphicon glyphicon-refresh'
);
$output
.=
sprintf
(
$template
,
$service_id
,
'stop'
,
$service
[
'name'
],
sprintf
(
gettext
(
'Stop %sService'
),
$service_title
),
$service_act
,
'glyphicon glyphicon-stop'
);
}
else
{
$output
.=
sprintf
(
$template
,
$service_id
,
'start'
,
$service
[
'name'
],
sprintf
(
gettext
(
'Start %sService'
),
$service_title
),
$service_act
,
'glyphicon glyphicon-play'
);
}
return
$output
;
...
...
src/www/status_services.php
View file @
4765db05
...
...
@@ -179,21 +179,6 @@ include("head.inc");
?>
<body>
<script
type=
'text/javascript'
>
$
(
document
).
ready
(
function
()
{
$
(
'
.srv_status_act
'
).
click
(
function
(
event
){
event
.
preventDefault
();
params
=
{};
params
[
'
action
'
]
=
$
(
this
).
data
(
'
service_action
'
);
params
[
'
service
'
]
=
$
(
this
).
data
(
'
service
'
);
params
[
'
id
'
]
=
$
(
this
).
data
(
'
service_id
'
);
$
.
post
(
'
/status_services.php
'
,
params
,
function
(
data
)
{
// refresh page after service action
location
.
reload
();
});
});
});
</script>
<?php
include
(
"fbegin.inc"
);
?>
<section
class=
"page-content-main"
>
...
...
@@ -220,7 +205,7 @@ include("head.inc");
<td>
<?=
$service
[
'description'
];
?>
</td>
<td>
<?=
get_service_status_icon
(
$service
,
true
,
true
);
?>
<?=
get_service_control_links
(
$service
,
false
,
false
);
?>
<?=
get_service_control_links
(
$service
,
false
);
?>
</td>
</tr>
<?php
...
...
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