コード例 #1
0
ファイル: system.php プロジェクト: cherry-wb/Qemu
 public function action_default()
 {
     if (Modul::hasAccess('system') == false) {
         return '<div class="notice error">Sie haben keinen Zugriff</div>';
     }
     $query = $GLOBALS['pdo']->prepare("SELECT count(vmID) AS `vms`, SUM(IF(status=1,1,0)) AS `vms_on` FROM vm");
     $query->execute();
     $data = $query->fetch();
     $query = $GLOBALS['pdo']->prepare("SELECT imageID FROM images");
     $query->execute();
     $images = $query->rowCount();
     $tmp = new RainTPL();
     $tmp->assign('vms', $data['vms']);
     $tmp->assign('vms_on', $data['vms_on']);
     $tmp->assign('images', $images);
     $ram = Server::getRamSettings();
     if ($ram) {
         $ram_usage = FileSystem::formatFileSize($ram['used']) . ' / ' . FileSystem::formatFileSize($ram['all']);
     } else {
         $ram_usage = 'linux only';
     }
     $tmp->assign('ram_usage', $ram_usage);
     $cpu = Server::getCPUusage();
     if ($cpu) {
         $cpu_usage = implode(" ", array_values($cpu));
     } else {
         $cpu_usage = 'linux only';
     }
     $tmp->assign('cpu_usage', $cpu_usage);
     $free = disk_free_space('/');
     $all = disk_total_space('/');
     $tmp->assign('free', FileSystem::formatFileSize($all - $free));
     $tmp->assign('all', FileSystem::formatFileSize($all));
     $qemu_ram = Server::getQemuRamTemp();
     if ($qemu_ram !== false) {
         $tmp->assign('ram_qemu', FileSystem::formatFileSize($qemu_ram));
     } else {
         $tmp->assign('ram_qemu', 'linux only');
     }
     $roles = '';
     $query = $GLOBALS['pdo']->prepare("SELECT * FROM roles");
     $query->execute();
     while ($ds = $query->fetch()) {
         $roles .= '<option value="' . $ds['roleID'] . '">' . $ds['name'] . '</option>';
     }
     $roles = str_replace('value="' . $GLOBALS['config']['default_role'] . '"', 'value="' . $GLOBALS['config']['default_role'] . '" selected="selected"', $roles);
     $tmp->assign('roles', $roles);
     foreach ($GLOBALS['config'] as $key => $value) {
         $tmp->assign($key, $value);
     }
     return $tmp->draw('system', true);
 }
コード例 #2
0
ファイル: images.php プロジェクト: cherry-wb/Qemu
 public function action_default()
 {
     if (Modul::hasAccess('image_edit', 'image_create', 'image_clone', 'image_remove') == false) {
         return '<div class="notice error">Sie haben keinen Zugriff</div>';
     }
     $tmp2 = new RainTPL();
     $query = $GLOBALS['pdo']->prepare("SELECT i.*,v.status FROM images i LEFT JOIN vm_images t ON t.imageID = i.imageID LEFT JOIN vm v ON v.vmID = t.vmID");
     $query->execute();
     $vms = array();
     if ($query->rowCount()) {
         while ($ds = $query->fetch()) {
             $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"><span class="icon" data-icon="G"></span>Edit</a>';
             }
             if (Image::isUsed($ds['imageID']) == false && ($ds['owner'] == $_SESSION['user']->id || Modul::hasAccess('image_remove'))) {
                 $buttons .= '<a href="index.php?site=images&action=delete&image=' . $ds['imageID'] . '" class="button small center grey"><span class="icon" data-icon="T"></span>delete</a>';
             }
             if ($ds['status'] == QemuMonitor::SHUTDOWN && $ds['type'] != 'usb') {
                 $buttons .= '<a href="index.php?site=images&action=status&image=' . $ds['imageID'] . '" class="button small center grey"><span class="icon" data-icon="v"></span> Status</a>';
             }
             if ($ds['type'] != 'usb' && is_dir($ds['path']) == false) {
                 $buttons .= '<a href="index.php?site=images&action=clone&image=' . $ds['imageID'] . '" class="button small center grey"><span class="icon" data-icon="R"></span>Clone</a>';
             }
             $obj = array();
             $obj['buttons'] = $buttons;
             $obj['name'] = $ds['name'];
             if ($ds['type'] == "usb") {
                 $obj['path'] = Server::getUsbDeviceName($ds['path']);
                 $obj['type'] = $ds['type'] . " - " . $ds['path'];
             } else {
                 $obj['path'] = $ds['path'];
                 $obj['type'] = $ds['type'];
             }
             $vms[] = $obj;
         }
         $tmp2->assign('vms', $vms);
     } else {
         $tmp2->assign('vms', '<tr><td colspan="4">Kein Image vorhanden</td></tr>');
     }
     return $tmp2->draw('images_main', true);
 }
コード例 #3
0
ファイル: users.php プロジェクト: cherry-wb/Qemu
 public function action_default()
 {
     if (Modul::hasAccess('user_edit', 'user_create', 'user_delete') == false) {
         return '<div class="notice error">Sie haben keinen Zugriff</div>';
     }
     $tmp2 = new RainTPL();
     $query = $GLOBALS['pdo']->prepare("SELECT * FROM users");
     $query->execute();
     $query2 = $GLOBALS['pdo']->prepare("SELECT * FROM vm WHERE owner= :user");
     $query2->bindParam(":user", $user, PDO::PARAM_INT);
     if ($query->rowCount() > 0) {
         $users = array();
         while ($ds = $query->fetch()) {
             $buttons = '';
             if ($_SESSION['user']->role['user_edit'] == 1) {
                 $buttons .= '<a href="index.php?site=users&action=edit&user='******'userID'] . '" class="button grey small center"><span class="icon" data-icon="G"></span>Edit</a>';
             }
             if ($_SESSION['user']->role['vm_create'] == 1) {
                 $buttons .= '<a href="index.php?site=users&action=addVM&user='******'userID'] . '" class="button green small center"><span class="icon" data-icon="+"></span>add VM</a>';
             }
             if ($_SESSION['user']->role['user_remove'] == 1) {
                 $buttons .= '<a href="index.php?site=users&action=delete&user='******'userID'] . '" class="button red small center"><span class="icon" data-icon="x"></span>delete</a>';
             }
             $user = $ds['userID'];
             $query2->execute();
             $user_vms = array();
             if ($query2->rowCount()) {
                 while ($vm = $query2->fetch()) {
                     $user_vms[] = '<a href="index.php?site=vms&action=edit&vmID=' . $vm['vmID'] . '">' . $vm['name'] . '</a>';
                 }
                 $user_vms = implode(", ", $user_vms);
             } else {
                 $user_vms = 'Keine zugewiesen';
             }
             $user = array();
             $user['mail'] = $ds['email'];
             $user['role'] = Helper::getRoleName($ds['role']);
             $user['vms'] = $user_vms;
             $user['buttons'] = $buttons;
             $users[] = $user;
         }
         $tmp2->assign('users', $users);
     } else {
         $tmp2->assign('users', '<tr><td colspan="4">Keine Nutzer vorhanden</td></tr>');
     }
     return $tmp2->draw('users_table', true);
 }
コード例 #4
0
ファイル: vms.php プロジェクト: cherry-wb/Qemu
 public function action_default()
 {
     if (Modul::hasAccess('vm_edit', 'vm_create', 'vm_remove') == false) {
         return '<div class="notice error">Sie haben keinen Zugriff</div>';
     }
     $tmp2 = new RainTPL();
     $query = $GLOBALS['pdo']->query("SELECT * FROM vm");
     $query2 = $GLOBALS['pdo']->prepare("SELECT *,i.path,i.type FROM vm_images v JOIN images i ON i.imageID=v.imageID WHERE v.vmID = :vmID");
     $query2->bindParam(':vmID', $vmID, PDO::PARAM_INT);
     if ($query->rowCount()) {
         $vms = array();
         while ($ds = $query->fetch()) {
             $vmID = $ds['vmID'];
             if ($ds['lastrun'] != '0000-00-00 00:00:00') {
                 $lastrun = date("d.m.Y H:i", strtotime($ds['lastrun']));
             } else {
                 $lastrun = '---';
             }
             if ($ds['status'] == QemuMonitor::RUNNING) {
                 $buttons = '<a href="index.php?site=vms&action=stop&vmID=' . $ds['vmID'] . '" class="button red small center "><span class="icon" data-icon="Q"></span>Stop</a>';
                 $buttons .= '<a href="vnc.php?vmID=' . $ds['vmID'] . '"class="button small center grey"><span class="icon" data-icon="0"></span>VNC</a>';
             } else {
                 $buttons = '<a href="index.php?site=vms&action=start&vmID=' . $ds['vmID'] . '" class="button green small center"><span class="icon" data-icon="&nbsp;"></span>Start</a>';
                 $buttons .= '<a href="index.php?site=vms&action=edit&vmID=' . $ds['vmID'] . '" class="button small center grey"><span class="icon" data-icon="G"></span>Edit</a>';
                 $buttons .= '<a href="index.php?site=vms&action=clone&vmID=' . $ds['vmID'] . '" class="button small center grey"><span class="icon" data-icon="R"></span>Clone</a>';
                 $buttons .= '<a href="index.php?site=vms&action=delete&vmID=' . $ds['vmID'] . '" class="button small center grey"><span class="icon" data-icon="T"></span>Delete</a>';
             }
             $vm = array();
             $vm['name'] = $ds['name'];
             $vm['owner'] = User::getUserName($ds['owner']);
             $vm['ram'] = FileSystem::formatFileSize($ds['ram'] * 1024 * 1024, 0);
             $vm['lastrun'] = $lastrun;
             $vm['buttons'] = $buttons;
             $images = array();
             $query2->execute();
             while ($dq = $query2->fetch()) {
                 $images[] = $dq['name'];
             }
             $vm['images'] = implode(", ", $images);
             $vms[] = $vm;
         }
         $tmp2->assign('vms', $vms);
     } else {
         $tmp2->assign('vms', "Es gibt noch keine VMs.");
     }
     return $tmp2->draw('vms_main', true);
 }