Ajout API

- fonction API ajouté
- utilisation API pour Management-OSMW ( Multi OSMW Seveur)
This commit is contained in:
Fgagod
2022-12-11 19:22:48 +01:00
parent 2a065e6bd5
commit 20b5249488
2 changed files with 39 additions and 54 deletions
+34 -54
View File
@@ -1,32 +1,23 @@
<?php
/*
foreach($_POST as $key => $val) echo '$_POST["'.$key.'"]='.$val.'<br />';
foreach($_GET as $key => $val) echo '$_GET["'.$key.'"]='.$val.'<br />';
foreach($_SESSION as $key => $val) echo '$_SESSION["'.$key.'"]='.$val.'<br />';
*/
/*
$api_key ="TRn9bh2Jg4dw1kBWf35mcF6KDrSNsQixUYZyHuEMCzGt8XL7jepqvoVAaP";
// Return Ok else NOK
//http://YOUR_OSMW_WEBSERVER/api/?api_key=API_KEY_CONFIG&opensim_select=NAME_OPENSIMULATOR&cmd=COMMANDE
// COMMANDE FOR SIMULATOR:
Start
Stop
Restart
Alerte General&msg_alert=MESSAGE
Region Root
Update Client
FCache Assets
FCache ClearF
Generate Map
Estate
Windlight enable
Windlight disable
Windlight load
Elevate
Lower
StartLogin
StopLogin
StatusLogin
@@ -44,10 +35,17 @@ tmux_kill
// COMMANDE FOR TMUX:
tmux_load_all
tmux_kill_all
//http://YOUR_OSMW_WEBSERVER/api/?api_key=API_KEY_CONFIG&opensim_select=NAME_OPENSIMULATOR&cmd_gest=COMMANDE
// COMMANDE DE GESTION
list_simu
list_regions
*/
require_once ('../inc/config/config.php');
require_once ('../inc/config/fonctions.php');
if ($_GET['api_key'] == $api_key || $_POST['api_key'] == $api_key)
{
$_SESSION['authentification_api'] = "autorized";
@@ -104,25 +102,19 @@ if (isset($_SESSION['authentification_api']))
$messageInfo = "OK";
}
if($_GET['cmd'] == 'Restart') {$parameters = array('command' => 'restart');}
if($_GET['cmd'] == 'Alerte General') {$parameters = array('command' => 'alert '.$_GET["msg_alert"]);}
if($_GET['cmd'] == 'Region Root') {$parameters = array('command' => 'change region root');}
if($_GET['cmd'] == 'Update Client') {$parameters = array('command' => 'force update');}
if($_GET['cmd'] == 'FCache Assets') {$parameters = array('command' => 'fcache assets');}
if($_GET['cmd'] == 'FCache ClearF') {$parameters = array('command' => 'fcache clear file');}
if($_GET['cmd'] == 'Update Client') {$parameters = array('command' => 'force update');}
if($_GET['cmd'] == 'Generate Map') {$parameters = array('command' => 'generate map');}
if($_GET['cmd'] == 'Windlight enable') {$parameters = array('command' => 'windlight enable');}
if($_GET['cmd'] == 'Windlight disable') {$parameters = array('command' => 'windlight disable');}
if($_GET['cmd'] == 'Windlight load') {$parameters = array('command' => 'windlight load');}
if($_GET['cmd'] == 'Elevate') {$parameters = array('command' => 'terrain elevate 1');}
if($_GET['cmd'] == 'Lower') {$parameters = array('command' => 'terrain lower 1');}
if($_GET['cmd'] == 'StartLogin') {$parameters = array('command' => 'login enable');}
if($_GET['cmd'] == 'StopLogin') {$parameters = array('command' => 'login disable');}
if($_GET['cmd'] == 'StatusLogin') {$parameters = array('command' => 'login status');}
if($_GET['cmd'] == 'kick_user') { $kick = 'kick user '.$_GET["avatar_name"].' ejected by administrator.' ;$parameters = array('command' => $kick );}
if($_GET['cmd'] == 'appearance_user') { $appearance = 'appearance show '.$_GET["avatar_name"] ;$parameters = array('command' => $appearance );}
if($_GET['cmd'] == 'estate_name') {$estate_name = 'estate set name 101 "'.$_GET["estate_name"].'"' ;$parameters = array('command' => $estate_name );}
if($_GET['cmd'] == 'estate_owner') {$estate_owner = 'estate set owner 101 '.$_GET["estate_owner"] ;$parameters = array('command' => $estate_owner );}
if($_GET['cmd']<>"")
{
$myRemoteAdmin = new RemoteAdmin(trim($hostname), trim($RemotePort), trim($access_password2));
@@ -181,42 +173,30 @@ if (isset($_SESSION['authentification_api']))
}
}
//#################################################################################################################
if (isset($_GET['cmd_gest']))
{
$osmw_simu =$_GET['opensim_select'];
// on se connecte a MySQL
try{$bdd = new PDO('mysql:host='.$hostnameBDD.';dbname='.$database.';charset=utf8', $userBDD, $passBDD);}
catch (Exception $e){ die('Erreur : ' . $e->getMessage()); }
if($_GET['cmd_tmux'] == 'list_simu')
{
$messageInfo = "OK";
}
if($_GET['cmd_tmux'] == 'list_regions')
{
$messageInfo = "OK";
}
}
//#################################################################################################################
echo $messageInfo;
$_SESSION = array();
}
else {echo "NO API KEY";}
//--------------------------------------------------------------------------------------------
/* Fonction envoi commande SSH */
function CommandeSSH($hostname2,$usernameSSH2,$passwordSSH2,$commande)
{
if($commande <> '')
{
if (!function_exists("ssh2_connect")) die(" function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
if(!($con = ssh2_connect($hostname2, 22))){
echo " fail: unable to establish connection\n";
} else
{// try to authenticate with username root, password secretpassword
if(!ssh2_auth_password($con,$usernameSSH2,$passwordSSH2)) {
echo "fail: unable to authenticate\n";
} else {
//echo " ok: logged in...\n";
if (!($stream = ssh2_exec($con, $commande ))) {
echo " fail: unable to execute command\n";
} else {
// collect returning data from command
stream_set_blocking($stream, true); $data = "";
while ($buf = fread($stream,4096))
{
$data .= $buf."\n";}
// echo $data;
fclose($stream);
}
}
}
return $data;
}
}
?>
+5
View File
@@ -107,6 +107,11 @@ $userBDD = "'. $login .'"; // login
$passBDD = "'. $pass .'"; // password
$database = "'. $base .'"; // Name of BDD
$hostname = "ip_host";
$usernameSSH = "user_ssh_tmux";
$passwordSSH = "pass_user_tmux";
$api_key ="";
/* Position center of your MAP */
$px = 7000;