require('./conf/config.php');
/*******************************************************************************************
*
*
* addUserDB($idLogin)
* delUserDB($idLogin)
* addUserCMD($user, $command)
* selectUserCMD($idLogin)
* delUserCMD($user, $command)
* addUserService($user, $service)
* selectUserService($idLogin)
* delUserService($user, $service)
* addUserCMDSwitch($command, $user, $switch)
* selectUserCMDSwitch($command, $user,$switch)
* delUserCMDSwitch($command, $user, $switch)
*
*
********************************************************************************************/
function auth_user($idLogin, $passwdUser) {
$resultat = selectUser($idLogin) ;
if ( !is_string($resultat) ) {
while ( $row = mysql_fetch_assoc($resultat) ) {
if ( $row['passwdUser'] == md5($passwdUser) ) {
return 1;
}else{
$buffer = "Authentification FOR USER $idLogin [FAILED]: error password";
return $buffer;
}
}
}else{
$buffer = "Authentification FOR USER $idLogin [FAILED]: $resultat";
return $buffer;
}
return "Authentification Web Klask: [FAILED]";
}
function addUserDB($idLogin, $passwdUser) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
//Check if user exist
if ( ctrlUnixAccount($idLogin) == 0 ) {
$buffer = "L'utilisateur n'existe pas sur dans le fichier /etc/passwd";
return $buffer ;
}
//TODO: to clean
//md5 du mot de passe; si auth ldap md5 chaine vide
//echo "LibUser.AddUser " . md5($passwdUser) . " @- md5 saisie ". md5("adm") ." MD5 adm et passwd base ". $row['passwdUser'] ."
";
$passwdUser= md5($passwdUser);
//$sql= "INSERT INTO USER VALUE('$adminApp', '$passwdAdminApp');";
//Add user
//echo "libUser.addUser " . $passwdUser ."
";
$sql = "INSERT INTO USER VALUE('$idLogin', '$passwdUser');";
if (mysql_query($sql, $link)) {
$buffer = 1;
} else {
$buffer = "Create USER $idLogin: [FAILED] :" . mysql_error() ;
}
return $buffer;
}
function selectUser($idLogin) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
if (empty($idLogin)) {
$sql = "SELECT * FROM USER";
}else{
$sql = "SELECT * FROM USER WHERE idUser='$idLogin'; ";
}
if ($result = mysql_query($sql, $link)) {
//test if $return is_array
return $result ;
} else {
$buffer = "SELECT USER $idLogin: [FAILED] :" . mysql_error() ;
return $buffer ;
}
}
function delUserDB($idLogin) {
//connect DB
$buffer = "";
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
if ( $idLogin == $GLOBALS['adminApp'] ) {
$buffer = "DELETE USER $idLogin : [FAILED] : CAN'T DELETE USER ADMIN APPLICATION";
return $buffer ;
}
//Before del user of Table USER, del user in all others Table
//Del user from CMDUSER
$sql = "DELETE FROM CMDUSER WHERE idUser = '$idLogin';";
if (mysql_query($sql, $link)) {
$buffer .= "DELETE USER $idLogin FROM TABLE CMDUSER: [OK]
";
} else {
$buffer = "DELETE USER $idLogin FROM TABLE CMDUSER: [FAILED] :" . mysql_error() ;
return $buffer;
}
//Del user from CMDSWITCH
$sql = "DELETE FROM CMDSWITCH WHERE idUser = '$idLogin';";
if (mysql_query($sql, $link)) {
$buffer .= "DELETE USER $idLogin FROM TABLE CMDSWITCH: [OK]
";
} else {
$buffer = "DELETE USER $idLogin FROM TABLE CMDSWITCH: [FAILED] :" . mysql_error() ;
return $buffer;
}
//del user from SERVICEUSER
$sql = "DELETE FROM SERVICEUSER WHERE idUser = '$idLogin';";
if (mysql_query($sql, $link)) {
$buffer .= "DELETE USER $idLogin FROM TABLE SERVICEUSER: [OK]
";
} else {
$buffer = "DELETE USER $idLogin FROM TABLE SERVICEUSER: [FAILED] :" . mysql_error() ;
return $buffer;
}
//Del user
$sql = "DELETE FROM USER WHERE idUser = '$idLogin';";
if (mysql_query($sql, $link)) {
$buffer .= "DELETE USER $idLogin FROM TABLE USER: [OK]
";
} else {
$buffer = "DELETE USER $idLogin FROM TABLE USER: [FAILED] :" . mysql_error() ;
return $buffer;
}
return $buffer;
}
function addUserCMD($user, $command) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
//add power for user in table cmdUser
$sql = "INSERT INTO CMDUSER VALUE('$command' , '$user' );";
if (mysql_query($sql, $link)) {
$buffer = 1;
} else {
$buffer = "ADD SERVICE $command FOR $user: [FAILED] :" . mysql_error() ;
return $buffer;
}
return $buffer;
}
function selectUserCMD($idLogin, $idPower) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
if (empty($idLogin) && empty($idPower) ) {
$sql = "SELECT * FROM CMDUSER";
}else{
if ( !empty($idLogin) && empty($idPower) ) {
$sql = "SELECT * FROM CMDUSER WHERE idUser='$idLogin'; ";
}else{
if ( empty($idService) && !empty($idPower) ) {
$sql = "SELECT * FROM CMDUSER WHERE idPower='$idPower'; ";
}else{
$sql = "SELECT * FROM CMDUSER WHERE idUser='$idLogin' AND idPower='$idPower'; ";
}
}
}
if ($result = mysql_query($sql, $link)) {
//test if $return is_array
return $result ;
} else {
$buffer = "SELECT POWERFOR USER $idLogin: [FAILED] :" . mysql_error() ;
return $buffer ;
}
}
function delUserCMD($user, $command) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
if ( $user == $GLOBALS['adminApp'] ) {
$buffer = "DELETE RIGHT FOR $idLogin : [FAILED] : CAN'T DELETE RIGHT FOR USER ADMIN APPLICATION";
return $buffer ;
}
//del power for user in table cmdUser
$sql = "DELETE FROM CMDUSER WHERE idUser='$user'
AND idPower='$command' ;";
if (mysql_query($sql, $link)) {
$buffer =1;
} else {
$buffer = "DELETE SERVICE $command FOR $user: [FAILED] :" . mysql_error() ;
return $buffer;
}
return $buffer;
}
function addUserService($user, $service) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
//add service for user
$sql = "INSERT INTO SERVICEUSER VALUE('$user', '$service');";
if (mysql_query($sql, $link)) {
$buffer = 1;
} else {
$buffer = "ADD SERVICE $service FOR $user: [FAILED] :" . mysql_error() ;
return $buffer;
}
return $buffer;
}
function selectUserService($idLogin, $idService) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
if (empty($idLogin) && empty($idService) ) {
$sql = "SELECT * FROM SERVICEUSER";
}else{
if ( !empty($idLogin) && empty($idService) ) {
$sql = "SELECT * FROM SERVICEUSER WHERE idUser='$idLogin'; ";
}else{
if ( empty($idLogin) && !empty($idService) ) {
$sql = "SELECT * FROM SERVICEUSER WHERE idService='$idService'; ";
}else{
$sql = "SELECT * FROM SERVICEUSER WHERE idService='$idService' AND idUser='$idLogin'; ";
}
}
}
if ($result = mysql_query($sql, $link)) {
//test if $return is_array
return $result ;
} else {
$buffer = "SELECT SERVICE FOR USER $idLogin: [FAILED] :" . mysql_error() ;
return $buffer ;
}
}
function delUserService($user, $service) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
//del service for user
$sql = "DELETE FROM SERVICEUSER WHERE idUser='$user'
AND idService='$service';";
if (mysql_query($sql, $link)) {
$buffer = "DELETE SERVICE $service FOR $user: [OK]
";
} else {
$buffer = "DELETE SERVICE $service FOR $user: [FAILED] :" . mysql_error() ;
return $buffer;
}
return $buffer;
}
function addUserCMDSwitch($command, $user, $switch) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
//add power for user for switch
$sql = "INSERT INTO CMDSWITCH VALUES('$command', '$switch', '$user');";
if (mysql_query($sql, $link)) {
$buffer = "ADD POWER $command FOR $user ON $switch: [OK]
";
} else {
$buffer = "ADD POWER $command FOR $user ON $switch: [FAILED] :" . mysql_error() ;
return $buffer;
}
return $buffer;
}
function selectUserCMDSwitch($idPower, $idLogin,$idSwitch) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
if ( empty($idSwitch) && empty($idLogin) && empty($idPower) ) {
$sql = "SELECT * FROM CMDSWITCH";
}else{
if ( !empty($idSwitch) && !empty($idLogin) && !empty($idPower) ) {
$sql = "SELECT * FROM CMDSWITCH
WHERE idSwitch='$idSwitch'
AND idLogin='$idLogin'
AND idPower='$command';";
}else{
if ( !empty($idSwitch) && empty($idLogin) && empty($idPower) ) {
$sql = "SELECT * FROM SERVICESWITCH
WHERE idSwitch='$idSwitch';";
}else{
if ( !empty($idSwitch) && !empty($idLogin) && empty($idPower) ) {
$sql = "SELECT * FROM SERVICESWITCH
WHERE idSwitch='$idSwitch'
AND idLogin='$idLogin';";
}else{
if ( !empty($idSwitch) && empty($idLogin) && !empty($idPower) ) {
$sql = "SELECT * FROM SERVICESWITCH
WHERE idSwitch='$idSwitch'
AND idPower='$idPower';";
}else{
if ( !empty($idLogin) && empty($idSwitch) && empty($idPower) ) {
$sql = "SELECT * FROM SERVICESWITCH
WHERE idLogin='$idLogin';";
}else{
if ( !empty($idLogin) && empty($idSwitch) && !empty($idPower) ) {
$sql = "SELECT * FROM SERVICESWITCH
WHERE idLogin='$idLogin'
AND idPower='$idPower';";
}else{
if ( !empty($idPower) && empty($idLogin) && empty($idSwitch) ) {
$sql = "SELECT * FROM SERVICESWITCH
WHERE idPower='$idPower';";
}
}
}
}
}
}
}
}
if (mysql_query($sql, $link)) {
$buffer = 1 ;
}else{
$buffer = "SELECT SWITCH $idSwitch for SERVICE $idService : [FAILED] :" . mysql_error() ;
}
}
function delUserCMDSwitch($command, $user, $switch) {
//connect DB
$link = mysql_connect($GLOBALS['hostDB'], $GLOBALS['userDB'], $GLOBALS['passwdDB']);
if (!$link) {
$buffer = "Connexion [FAILED]: " . mysql_error() ;
return $buffer;
}
$db_selected = @mysql_select_db($GLOBALS['nameDB'], $link);
if (!$db_selected) {
$buffer .= "Impossible de sélectionner la base de données :$nameDB" . mysql_error();
}
//del power for user for switch
$sql = "DELETE FROM CMDSWITCH VALUES('$command', '$switch', '$user');";
if (mysql_query($sql, $link)) {
$buffer = "DELETE POWER $command FOR $user ON $switch: [OK]";
} else {
$buffer = "DELETE POWER $command FOR $user ON $switch: [FAILED] :" . mysql_error() ;
return $buffer;
}
return $buffer;
}
?>