Ja, das passt alles. Nur das Stückchen hab ich als letztes bearbeitet.
aber ich poste hier mal den ganzen Code
PHP-Code:
<?php
// Prüfen ob die Session überhaupt existiert?
if(isset($_SESSION))
{
if($_SESSION['login'])
{
// Session existiert, session zerstören.
session_destroy();
}
}
ob_start();
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Web-Administration</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="author" content="Patrick_Lwe&Albert_Hobe" />
<meta name="description" content="Admin" />
<meta name="keywords" content="Webinterface, Administartor, Administration" />
<meta name="robots" content="noindex|follow|nofollow" />
<meta http-equiv="content-type" content="text/html" charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="main.css" />
<script type="text/javascript">
function einblenden()
{
if(document.getElementById("form").style.display == "block")
{
document.getElementById("show").style.display = "block";
document.getElementById("form").style.display = "none";
}
else
{
document.getElementById("show").style.display = "none";
document.getElementById("form").style.display = "block";
}
}
function edit(uid)
{
if(document.getElementById(uid).style.display == 'none')
{
document.getElementById(uid).style.display = "block";
}
else
{
document.getElementById(uid).style.display = "none";
}
}
function loesche(uid)
{
if(confirm("Sind Sie sicher, dass Sie den User loeschen moechten?"))
{
var formUid = document.getElementById(uid);
formUid.token.value = "loeschen";
formUid.submit();
}
}
</script>
</head>
<body>
<div class="banner">
</div>
<div class="menu bubplastic horizontal lime">
<ul>
<li><span class="menu_r"><a href="/admin/de/hauptmenude.php"><span class="menu_ar">Main</span></a></span></li>
<li class="highlight"><span class="menu_r"><a href="/admin/de/user.php"><span class="menu_ar">User</span></a></span></li>
<li><span class="menu_r"><a href="/admin/de/gruppen.php"><span class="menu_ar">Gruppen</span></a></span></li>
<li><span class="menu_r"><a href="/admin/de/samba.php"><span class="menu_ar">Samba</span></a></span></li>
<li><span class="menu_r"><a href="/admin/de/hilfe.php"><span class="menu_ar">Hilfe</span></a></span></li>
</ul>
<br class="clearit"/>
</div>
<!-- Verstecktes Formular zum löschen von Usern -->
<div id="loeschen" style="display:none">
<form name="loeschen" method="post">
<input type="hidden" name="token" />
<input type="hidden" name= "uid" />
</form>
</div>
<?php
if( isset($_POST['token']) )
{
if($_POST['token'] == 'step2')
{
$db = mysql_connect("localhost","root","admin"); // Verbindung zu DB Herstellen ;-)
if(!$db)
{
die('Verbindung fehlgeschlagen:'.mysql_error()); // Verbindung Checken
}
mysql_select_db('xxx',$db);
$pass = $_POST['passwort1'];
$passwort = md5($pass);
$sql = 'INSERT INTO user (username, pass, gid, kommentar) VALUES("'.$_POST['name'].'", "'.$passwort.'",
"'.$_POST['groupID'].'", "'.$_POST['kommentar'].'")'; // Daten von POST übernehmen
$command = "sudo ./user-add.sh {$_POST['passwort1']} {$_POST['name']}";
exec($command);
$errorMessage = exec($command, $output);
if(mysql_query($sql))
{
}
else
{
echo "Fehler beim Anlegen des Datensatzes!".mysql_error();
}
}
}
?>
<?php
/*
** Hier ist die Userausgabe und dass Formular dazu.
*/
echo'<div id="show" style="display:block; width: 100%; margin-top: 50px;"><center>'.
'<img src="http://free-hack.com/images/img/tbheader2.png" width="800px"/>'.
'<table width="700px" style="font-size:1.2em">';
$db = mysql_connect("localhost","root","admin"); // Verbindung zu DB Herstellen ;-)
if(!$db)
{
die('Verbindung fehlgeschlagen: '.mysql_error()); // Verbindung Checken
}
mysql_select_db('xxx',$db);
//Loesche funktion
if( isset($_POST['token']))
{
// Lösch Funktion.
if($_POST['token'] == 'loeschen' )
{
$sql2 = 'SELECT username FROM user WHERE uid="'.$_POST['uid'].'";';
$result = $db->query($sql2);
if(!$result)
{
die('Irgendwas stimmt nicht mit dem Query');
}
while($row = $result->fetch_assoc())
{
$row['username'] = $dbusername;
$sql = 'DELETE FROM user WHERE username="'.$dbusername.'";';
}
if(mysql_query($sql))
{
$command = "sudo ./user-del.sh {$dbusername}";
exec($command);
$errorMessage = exec($command, $output);
echo '<tr><td colspan="5"><h3 style = "color: green;">User "'.$row['username'].'" wurde gelöscht!</h3></td></tr>';
if( mysql_query($sql) )
{
// Shell-Script zum User vom Systementfernen
$command = "sudo ./user-del.sh {$erg}";
exec($command);
$errorMessage = exec($command, $output);
echo '<tr><td colspan="5"><h3 style = "color: green;">User "'.$_POST['name'].'" wurde gelöscht!</h3></td></tr>';
}
else
{
echo '<tr><td colspan="5"><h3 style="color: red;">User "'.$_POST['name'].'" wurde nicht gelöscht!</h3></td></tr>';
}
}
// Bearbeiten Funktion.
elseif( $_POST['token'] == 'save' )
{
$sql = 'UPDATE user SET username = "'.$_POST['name'].'" WHERE uid="'.$_POST['uid'].'";';
if( mysql_query($sql) )
{
// Benutzer name von Linux noch ändern? TODO
echo '<tr><td colspan="5"><h3 style="color: green;">User wurde aktualisiert!</h3></td></tr>';
}
else
{
echo '<tr><td colspan="5"><h3 style="color: red;">User wurde nicht aktualisiert! Eventuell existiert bereits ein Benutzer mit diesem Benutzernamen.</h3></td></tr>';
//echo mysql_error();
}
}
}
// Benutzer Liste ausgeben.
$sql = 'SELECT user.*, groups.* FROM user, groups WHERE user.gid=groups.gid ORDER BY uid DESC';
$res = mysql_query($sql);
while($row = mysql_fetch_array($res,MYSQL_ASSOC))
{
if($row['uid'] > 1)
{
echo '<tr><td style="width: 77px;"></td><td style="width: 185px;">'.$row['uid'].'</td>'.
'<td style="width: 350px;">'.$row['username'].'</td>'.
'<td>'.$row['gruppe'].'</td>'.
'<td>'.
'<img src="http://free-hack.com/images/loeschen.png" align="right"'.
'onclick="loesche('.$row['uid'].');"/>'.
'<img src="http://free-hack.com/images/edit.png" align="right"'.
'onclick="edit('.$row['uid'].');"/>'.
'</td></tr>'.
'<tr>
<td></td>
<td colspan="3">
<form method="post" id="'.$row['uid'].'" style="display: none;">
<input type ="hidden" name="uid" value="'.$row['uid'].'" />
<input type ="text" name="name" value="'.$row['username'].'" size="15" />
<input type ="hidden" name="token" value="save" />
<input type ="submit" value="save" />
</form>
</td>'.
'</tr>';
}
}
echo '</table>';
echo '<input type="button" value="Erstellen" onclick="einblenden()"/>';
echo '</center></div>';
mysql_close();
?>
<div id="form" style="display:none; margin-top: 50px;" >
<center>
<form id="formuser" align="center" action="" method="post">
<input type="hidden" name="token" value="step2"/>
<table cellspacing="2" cellpadding="2">
<tr>
<td>Accountname</td>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<td>
</td>
<td id="font">(z.B. K3nny)</td>
</tr>
<tr>
<td>Gruppen ID:</td>
<td><input type="text" name="groupID"/></td>
</tr>
<tr>
<td>
</td>
<td id="font">(z.B. 1=Admin 2=Mod 3=USER)</td>
</tr>
<tr>
<td>Passwort</td>
<td>
<input type="password" name="passwort1"/>
</td>
</tr>
<tr>
<td>
</td>
<td id="font">(Ein Password halt!)</td>
</tr>
<tr>
<td>Kommentar</td>
<td>
<input type="text" name="kommentar"/>
</td>
</tr>
<tr>
<td>
</td>
<td id="font">(Irgendwas, wenns wichtig ist)</td>
</tr>
</table>
<input type="submit" value="Okay"/>
</form>
<center>
</div>
</body>
</html>