Permalink
Browse files

Neue Module und Funktionen

  • Loading branch information...
Phhere committed Feb 13, 2012
1 parent d9ce89e commit de3ce69c5db67c8922b4c5f7a59636e7f9b8ed39
Showing with 227 additions and 30 deletions.
  1. +3 −4 boxes/status.php
  2. +9 −4 classes/QemuVm.php
  3. +8 −3 classes/login.php
  4. +8 −8 index.php
  5. +151 −0 module/images.php
  6. +1 −0 module/logout.php
  7. +4 −6 module/myvm.php
  8. +10 −2 module/system.php
  9. +32 −2 module/users.php
  10. +1 −1 style.css
View
@@ -1,5 +1,4 @@
<?php
-$get = mysql_query("SELECT COUNT(vmID),status FROM vm GROUP BY status");
-while($ds = mysql_fetch_assoc($get)){
- print_r($ds);
-}
+$get = mysql_query("SELECT count(vmID) AS `vms`, SUM(IF(status=1,1,0)) AS `vms_on` FROM vm");
+$data = mysql_fetch_assoc($get);
+echo "VMs: ".$data['vms']."<br/>VMs online:".$data['vms_on'];
View
@@ -41,9 +41,7 @@ public function startVM(){
$cmd .=" -M isapc";
$cmd .=" -monitor telnet:localhost:".$this->monitor_port.",server,nowait";
$cmd .=" -vnc :".$this->vmID;
-
- echo $cmd;
-
+
$this->executeStart($cmd);
$this->setStatus(QemuMonitor::RUNNING);
mysql_query("UPDATE vm SET lastrun=NOW() WHERE vmID='".$this->vmID."'");
@@ -177,12 +175,19 @@ public function createScreenshot($filename){
}
private function executeStart($cmd){
+ /**
+ * @Todo logging einbauen
+ * $cmd = $cmd.">".$GLOBALS['config']['log_path']."\\vm_".$this->vmID."_".date("d_m_Y_H_i").".log";
+ */
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$WshShell = new COM("WScript.Shell");
+ //$cmd = $cmd.">".$GLOBALS['config']['log_path']."\\vm_".$this->vmID."_".date("d_m_Y_H_i").".log";
$WshShell->Run($cmd, 0, false);
}
else{
- exec( $cmd." > /dev/null &");
+ //$cmd = $cmd." > ".$GLOBALS['config']['log_path']."\\vm_".$this->vmID."_".date("d.m.Y H:i").".log &";
+ $cmd = $cmd." &";
+ exec($cmd);
}
}
}
View
@@ -44,9 +44,14 @@ function getRoleName($roleID){
*/
function formatFileSize($bytes, $round = 2){
$units = array('Byte', 'kB', 'MB', 'GB', 'TB');
- $pow = floor(log($bytes)/log(1024));
- $pow = min($pow, count($units)-1);
- $bytes /= pow(1024,$pow);
+ if($bytes > 0){
+ $pow = floor(log($bytes)/log(1024));
+ $pow = min($pow, count($units)-1);
+ $bytes /= pow(1024,$pow);
+ }
+ else{
+ $pow = 0;
+ }
return round($bytes,$round)." ".$units[$pow];
}
View
@@ -33,17 +33,17 @@
<!-- ===================================== END HEADER ===================================== -->
<!-- Menu Horizontal -->
<ul class="menu">
- <li class="current"><a href="index.php">Startseite</a></li>
- <li><a href="index.php?site=myvm">Meine VMs</a></li>
- <li><a href=""><span class="icon">R</span>Verwaltung</a>
+ <li class="<?php echo (in_array($GLOBALS['site'],array("","start"))) ? 'current' : '';?>"><a href="index.php">Startseite</a></li>
+ <li class="<?php echo (in_array($GLOBALS['site'],array("myvm"))) ? 'current' : '';?>"><a href="index.php?site=myvm">Meine VMs</a></li>
+ <li class="<?php echo (in_array($GLOBALS['site'],array("images","vms","users","system"))) ? 'current' : '';?>"><a href=""><span class="icon">R</span>Verwaltung</a>
<ul>
- <li><a href=""><span class="icon">4</span>Vms</a></li>
- <li><a href=""><span class="icon">D</span>Images</a></li>
- <li class="divider"><a href="index.php?site=users"><span class="icon">u</span>Benutzer</a></li>
- <li class="divider"><a href="index.php?site=system"><span class="icon">S</span>Einstellungen</a></li>
+ <li class="<?php echo (in_array($GLOBALS['site'],array("vms"))) ? 'current' : '';?>"><a href=""><span class="icon">4</span>Vms</a></li>
+ <li class="<?php echo (in_array($GLOBALS['site'],array("images"))) ? 'current' : '';?>"><a href="index.php?site=images"><span class="icon">D</span>Images</a></li>
+ <li class="divider <?php echo (in_array($GLOBALS['site'],array("users"))) ? 'current' : '';?>"><a href="index.php?site=users"><span class="icon">u</span>Benutzer</a></li>
+ <li class="divider <?php echo (in_array($GLOBALS['site'],array("system"))) ? 'current' : '';?>"><a href="index.php?site=system"><span class="icon">S</span>Einstellungen</a></li>
</ul>
</li>
- <li><a href="">Item 4</a></li>
+ <li class="<?php echo (in_array($GLOBALS['site'],array("downloads"))) ? 'current' : '';?>"><a href="index.php?site=downloads">Downloads</a></li>
</ul>
<div class="col_12">
View
@@ -0,0 +1,151 @@
+<h3>Images</h3>
+<?php
+if(isset($_SESSION['user'])){
+ if($_SESSION['user']->role['image_create'] == 1 ||
+ $_SESSION['user']->role['image_edit'] == 1){
+
+ if(isset($_GET['action'])){
+ $action = $_GET['action'];
+ }
+ else {
+ $action = null;
+ }
+
+ if(isset($_POST['save_new'])){
+ if($_SESSION['user']->role['image_create'] == 1){
+ if(file_exists($_POST['path'])){
+ mysql_query("INSERT INTO images (name,path,type) VALUES ('".mysql_real_escape_string($_POST['name'])."', '".mysql_real_escape_string($_POST['path'])."', '".mysql_real_escape_string($_POST['type'])."' )");
+ echo '<div class="notice success">Neues Image angelegt</div>';
+ }
+ else{
+ echo '<div class="notice notice">Der Pfad existiert nicht.</div>';
+ $action = 'new';
+ }
+ }
+ }
+ elseif(isset($_POST['save_edit'])){
+ if($_SESSION['user']->role['image_edit'] == 1){
+ mysql_query("UPDATE images SET name = '".mysql_real_escape_string($_POST['name'])."',path = '".mysql_real_escape_string($_POST['path'])."',type = '".mysql_real_escape_string($_POST['type'])."' WHERE imageID='".$_POST['image']."'");
+ }
+ }
+ elseif($action =='delete'){
+ $id = $_GET['image'];
+ if(mysql_num_rows(mysql_query("SELECT vmID FROM vm WHERE status='".QemuMonitor::RUNNING."' AND image='".$id."'"))){
+ echo '<div class="notice notice">Das Image wird noch in einer VM genutzt</div>';
+ }
+ else{
+ mysql_query("DELETE FROM images WHERE imageID='".$id."'");
+ echo '<div class="notice success">Image erfolgreich gelöscht</div>';
+ }
+ }
+
+ if($action == 'new'){
+ if($_SESSION['user']->role['image_create'] == 1){
+ $types = '<option value="cdrom">CD-ROM</option>';
+ $types .= '<option value="hda">HDD A</option>';
+ $types .= '<option value="hdb">HDD B</option>';
+ $types .= '<option value="hdC">HDD C</option>';
+ $types .= '<option value="floppy">Floppy</option>';
+
+ if(isset($_POST['name'])){
+ $name = $_POST['name'];
+ }
+ else{
+ $name = '';
+ }
+
+ if(isset($_POST['path'])){
+ $path = $_POST['path'];
+ }
+ else{
+ $path = $GLOBALS['config']['qemu_image_folder'];
+ }
+
+ if(isset($_POST['type'])){
+ $types = str_replace('value="'.$_POST['type'].'"', 'value="'.$_POST['type'].'" selected="selected"', $types);
+ }
+
+ echo '<form action="index.php?site=images" method="post">';
+ echo '<table cellspacing="0" cellpadding="0">
+ <thead><tr>
+ <th colspan="2">new Image</th>
+ </tr></thead>';
+ echo '<tr><td>Name:</td><td><input type="text" class="no-margin" name="name" value="'.$name.'" /></td></tr>';
+ echo '<tr><td>Type:</td><td><select class="no-margin" name="type">'.$types.'</select></td></tr>';
+ echo '<tr><td>Path:</td><td><input type="text" class="no-margin" name="path" value="'.$path.'" /></td></tr>';
+
+ echo '</table>';
+ echo '<input type="submit" class="no-margin center" name="save_new" value="Speichern" />';
+ echo '</form>';
+ }
+ }
+ elseif($action == 'edit'){
+ if($_SESSION['user']->role['image_edit'] == 1){
+
+ $image = $_GET['image'];
+ $get = mysql_query("SELECT * FROM images WHERE imageID='".$image."'");
+ if(mysql_num_rows($get)){
+ $data = mysql_fetch_assoc($get);
+ $types = '<option value="cdrom">CD-ROM</option>';
+ $types .= '<option value="hda">HDD A</option>';
+ $types .= '<option value="hdb">HDD B</option>';
+ $types .= '<option value="hdC">HDD C</option>';
+ $types .= '<option value="floppy">Floppy</option>';
+ $types = str_replace('value="'.$data['type'].'"', 'value="'.$data['type'].'" selected="selected"', $types);
+
+ echo '<form action="index.php?site=images" method="post">';
+ echo '<table cellspacing="0" cellpadding="0">
+ <thead><tr>
+ <th colspan="2">edit Image</th>
+ </tr></thead>';
+ echo '<tr><td>Name:</td><td><input type="text" class="no-margin" name="name" value="'.$data['name'].'" /></td></tr>';
+ echo '<tr><td>Type:</td><td><select class="no-margin" name="type">'.$types.'</select></td></tr>';
+ echo '<tr><td>Path:</td><td><input type="text" class="no-margin" name="path" value="'.$data['path'].'" /></td></tr>';
+ echo '</table>';
+ echo '<input type="hidden" name="image" value="'.$data['imageID'].'"/><input type="submit" class="no-margin center" name="save_edit" value="Speichern" />';
+ echo '</form>';
+ }
+ else{
+ echo '<div class="notice warning">Es existiert kein Image mit dieser ID</div>';
+ }
+
+ }
+ }
+ else{
+
+ echo '<a href="index.php?site=images&action=new" class="button no-margin small center grey "><span class="icon">+</span>neues Image</a>';
+
+ $get = mysql_query("SELECT * FROM images");
+ echo '<table cellspacing="0" cellpadding="0">
+ <thead><tr>
+ <th width="100"> </th>
+ <th width="200">Type</th>
+ <th width="120">Options</th>
+ </tr></thead>';
+ if(mysql_num_rows($get)){
+ while($ds = mysql_fetch_assoc($get)){
+ $buttons = '';
+ if($_SESSION['user']->role['image_edit'] == 1){
+ $buttons .= '<a href="index.php?site=images&action=edit&image='.$ds['imageID'].'" class="button small center grey no-margin"><span class="icon">G</span>Edit</a>';
+ }
+ $buttons .= '<a href="index.php?site=images&action=delete&image='.$ds['imageID'].'" class="button small center grey no-margin"><span class="icon">T</span>delete</a>';
+ echo '<tr>
+ <th>'.$ds['name'].'</th>
+ <td>'.$ds['path'].'<br/><small>'.$ds['type'].'</small></td>
+ <td>'.$buttons.'</td>
+ </tr>';
+ }
+ }
+ else{
+ echo '<tr><td colspan="4">Kein Image vorhanden</td></tr>';
+ }
+ echo '</table>';
+ }
+ }
+ else{
+ echo "<div class='notice warning'>Sie haben keinen Zugriff.</div>";
+ }
+}
+else{
+ echo "<div class='notice warning'>Sie müssen eingeloggt sein</div>";
+}
View
@@ -1,5 +1,6 @@
<?php
if(isset($_SESSION['user'])){
unset($_SESSION['user']);
+ session_destroy();
echo "Sie sind nun ausgeloggt.";
}
View
@@ -67,9 +67,8 @@
<th width="80"> </th>
<th>Image</th>
<th>Ram</th>
- <th>Status</th>
<th width="120">Last Run</th>
- <th width="80">Options</th>
+ <th width="140">Options</th>
</tr></thead>';
while($ds = mysql_fetch_assoc($get)){
if($ds['lastrun'] != '0000-00-00'){
@@ -79,18 +78,17 @@
$lastrun = '---';
}
if($ds['status'] == QemuMonitor::RUNNING){
- $buttons = '<a href="index.php?site=myvm&action=stop&vmID='.$ds['vmID'].'" class="button red small center "><span class="icon">Q</span>Stop</a>';
+ $buttons = '<a href="index.php?site=myvm&action=stop&vmID='.$ds['vmID'].'" class="button red small center no-margin"><span class="icon">Q</span>Stop</a>';
$buttons .='<a href="vnc.php?vmID='.$ds['vmID'].'"class="button small center grey no-margin"><span class="icon">0</span>VNC</a>';
}
else{
- $buttons = '<a href="index.php?site=myvm&action=start&vmID='.$ds['vmID'].'" class="button green small center"><span class="icon">&nbsp;</span>Start</a><br/>';
- $buttons .='<a class="button small center no-margin grey "><span class="icon">G</span>Edit</a>';
+ $buttons = '<a href="index.php?site=myvm&action=start&vmID='.$ds['vmID'].'" class="button green small center no-margin"><span class="icon">&nbsp;</span>Start</a>';
+ $buttons .='<a class="button small center grey no-margin"><span class="icon">G</span>Edit</a>';
}
echo '<tr>
<th>'.$ds['name'].'</th>
<td>'.Image::getImagePath($ds['image']).'</td>
<td>'.$ds['ram'].' MB</td>
- <td>'.$ds['status'].'</td>
<td>'.$lastrun.'</td>
<td>'.$buttons.'</td>
</tr>';
View
@@ -6,10 +6,12 @@
$get = mysql_query("SELECT count(vmID) AS `vms`, SUM(IF(status=1,1,0)) AS `vms_on` FROM vm");
$data = mysql_fetch_assoc($get);
+ $images=mysql_num_rows(mysql_query("SELECT imageID FROM images"));
+
echo '<div class="col_5"><h4>VM Status</h4>
VMs: '.$data['vms'].'<br/>
VMs online: '.$data['vms_on'].'<br/>
- Images:
+ Images: '.$images.'
</div>';
echo '<div class="col_2"></div>';
@@ -33,7 +35,7 @@
CPU: '.$cpu_usage.'<br/>
Ram: '.$ram_usage.'<br/>
HDD: '.formatFileSize(disk_free_space ('/')).' / '.formatFileSize(disk_total_space('/')).'<br/>
- Temp: '.formatFileSize(foldersize('/tmp/')).'</div>';
+ Qemu Ram: '.formatFileSize(foldersize('/dev/shm')).'</div>';
echo '<h4>Einstellungen</h4>';
@@ -78,6 +80,12 @@
<td>VNC Startport</td>
<td><input type="text" class="no-margin" size="6" name="vncport_min" value="'.$GLOBALS['config']['vncport_min'].'" /></td>
</tr>';
+
+ echo '<tr>
+ <td>Log Path</td>
+ <td><input type="text" class="no-margin" name="log_path" value="'.$GLOBALS['config']['log_path'].'" /></td>
+ </tr>';
+
echo '</table>';
echo '<input type="submit" class="no-margin center" name="save" value="Speichern" />';
echo '</form>';
View
@@ -15,7 +15,9 @@
}
elseif(isset($_POST['save_edit'])){
-
+ if($_SESSION['user']->role['user_edit'] == 1){
+ mysql_query("UPDATE users SET role = '".$_POST['role']."' WHERE userID='".$_POST['user']."'");
+ }
}
elseif($action =='delete'){
@@ -25,7 +27,35 @@
}
elseif($action == 'edit'){
-
+ if($_SESSION['user']->role['user_edit'] == 1){
+
+ $user = $_GET['user'];
+ $get = mysql_query("SELECT * FROM users WHERE userID='".$user."'");
+ if(mysql_num_rows($get)){
+ $data = mysql_fetch_assoc($get);
+ $roles = '';
+ $get = mysql_query("SELECT * FROM roles");
+ while($ds = mysql_fetch_assoc($get)){
+ $roles .= '<option value="'.$ds['roleID'].'">'.$ds['name'].'</option>';
+ }
+
+ $user_role = str_replace('value="'.$data['role'].'"', 'value="'.$data['role'].'" selected="selected"', $roles);
+
+ echo '<form action="index.php?site=users" method="post">';
+ echo '<table cellspacing="0" cellpadding="0">
+ <thead><tr>
+ <th colspan="2">'.$data['email'].'</th>
+ </tr></thead>';
+ echo '<tr><td>Role:</td><td><select class="no-margin" name="role">'.$user_role.'</select></td></tr>';
+ echo '</table>';
+ echo '<input type="hidden" name="user" value="'.$data['userID'].'"/><input type="submit" class="no-margin center" name="save_edit" value="Speichern" />';
+ echo '</form>';
+ }
+ else{
+ echo '<div class="notice warning">Es existiert kein Nutzer mit dieser ID</div>';
+ }
+
+ }
}
else{
View
@@ -90,7 +90,7 @@ body {
}
.no-margin {
- margin-bottom: 0px;
+ margin-bottom: 0px !important;
}
input[size]{
width: auto;

0 comments on commit de3ce69

Please sign in to comment.