| Line 92... |
Line 92... |
| 92 |
}
|
92 |
}
|
| 93 |
|
93 |
|
| 94 |
//fonction pour faire une action (start,stop,restart) sur un service
|
94 |
//fonction pour faire une action (start,stop,restart) sur un service
|
| 95 |
function serviceExec($service, $action){
|
95 |
function serviceExec($service, $action){
|
| 96 |
if (($action == "start")||($action == "stop")||($action == "restart")){
|
96 |
if (($action == "start")||($action == "stop")||($action == "restart")){
|
| 97 |
exec("sudo /usr/bin/systemctl $action $service",$retval, $retstatus);
|
97 |
exec("sudo /usr/bin/systemctl $action ".escapeshellarg($service), $retval, $retstatus);
|
| 98 |
if ($service == "sshd"){
|
98 |
if ($service == "sshd"){
|
| 99 |
if ($action == "start"){
|
99 |
if ($action == "start"){
|
| 100 |
exec("sudo /usr/bin/systemctl enable $service");
|
100 |
exec("sudo /usr/bin/systemctl enable ".escapeshellarg($service));
|
| 101 |
file_put_contents(CONF_FILE, str_replace('SSH=off', 'SSH=on', file_get_contents(CONF_FILE)));
|
101 |
file_put_contents(CONF_FILE, str_replace('SSH=off', 'SSH=on', file_get_contents(CONF_FILE)));
|
| 102 |
exec ("sudo /usr/local/bin/alcasar-iptables.sh");
|
102 |
exec("sudo /usr/local/bin/alcasar-iptables.sh");
|
| 103 |
}
|
103 |
}
|
| 104 |
if ($action == "stop"){
|
104 |
if ($action == "stop"){
|
| 105 |
exec("sudo /usr/bin/systemctl disable $service");
|
105 |
exec("sudo /usr/bin/systemctl disable ".escapeshellarg($service));
|
| 106 |
file_put_contents(CONF_FILE, str_replace('SSH=on', 'SSH=off', file_get_contents(CONF_FILE)));
|
106 |
file_put_contents(CONF_FILE, str_replace('SSH=on', 'SSH=off', file_get_contents(CONF_FILE)));
|
| 107 |
exec ("sudo /usr/local/bin/alcasar-iptables.sh");
|
107 |
exec("sudo /usr/local/bin/alcasar-iptables.sh");
|
| 108 |
}
|
108 |
}
|
| 109 |
}
|
109 |
}
|
| 110 |
return $retstatus;
|
110 |
return $retstatus;
|
| 111 |
} else {
|
111 |
} else {
|
| 112 |
return false;
|
112 |
return false;
|
| Line 114... |
Line 114... |
| 114 |
}
|
114 |
}
|
| 115 |
//fonction définissant le status d'un service
|
115 |
//fonction définissant le status d'un service
|
| 116 |
//(en fonction de la présence d'un mot clé dans la valeur de status)
|
116 |
//(en fonction de la présence d'un mot clé dans la valeur de status)
|
| 117 |
function checkServiceStatus($service){
|
117 |
function checkServiceStatus($service){
|
| 118 |
$response = false;
|
118 |
$response = false;
|
| 119 |
exec("sudo /usr/bin/systemctl is-active $service.service",$retval);
|
119 |
exec("sudo /usr/bin/systemctl is-active ".escapeshellarg("$service.service"), $retval);
|
| 120 |
foreach( $retval as $val ) {
|
120 |
foreach( $retval as $val ) {
|
| 121 |
if ($val == "active"){
|
121 |
if ($val == "active"){
|
| 122 |
$response = true;
|
122 |
$response = true;
|
| 123 |
break;
|
123 |
break;
|
| 124 |
}
|
124 |
}
|