' ); $replace = array('&', '"', ''', '<', '>' ); $str = str_replace($search, $replace, $str); return $str; } function checkvm($vmname) { $shellout = shell_exec("/usr/bin/wrap-nlvmi checkvm $vmname bla");//){ if (preg_match_all('/running/', $shellout)){ return 0; } return 1; } //read config file $configfile = new SplFileObject("/etc/nlvmi/nlvmi.conf"); while (!$configfile->eof()) { $line = $configfile->fgets(); if (!preg_match('/^#/', $line)){ if (!preg_match('/^$/', $line)){ if (preg_match('/=/', $line)){ $configparam = explode('=', $line); $p = rtrim($configparam[1]); //echo "B$p"; $config[$configparam[0]]=str_replace('"', '', $p); } } } } $file = null; //check db connection if ($config['DATABASETYPE']=="sqlite"){ $db_handle = new SQLite3($config['SQLITEFILE']); $query = "SELECT name FROM sqlite_master WHERE type='table' AND name='vms';"; $db_handle->exec($query); $result = $db_handle->query($query); $row = $result->fetchArray(); if (!$row['name']=="vms"){ echo "DB connection failed!"; exit; } } include('header.php'); $mode=""; if (isset($_REQUEST['start'])){ $vmname = clean($_REQUEST['start']); $sql="SELECT * FROM vms WHERE vmname='$vmname'"; $res = $db_handle->query($sql); while ($row = $res->fetchArray(SQLITE3_ASSOC)){ $shellout = shell_exec("/usr/bin/wrap-nlvmi start $vmname bla"); echo $shellout; } } if (isset($_REQUEST['stop'])){ $vmname = clean($_REQUEST['stop']); $sql="SELECT * FROM vms WHERE vmname='$vmname'"; $res = $db_handle->query($sql); while ($row = $res->fetchArray(SQLITE3_ASSOC)){ if(checkvm($vmname)){ $shellout = shell_exec("/usr/bin/wrap-nlvmi stop $vmname bla"); echo $shellout; } } } //form for edit and new vms if (isset($_REQUEST['edit'])){ $mode="editvm"; $formname="editvm"; $eid=clean($_REQUEST['edit']); $sql="SELECT * FROM vms WHERE id='$eid'"; $res = $db_handle->query($sql); $editid = ""; while ($row = $res->fetchArray(SQLITE3_ASSOC)){ $e = $row; } } elseif(isset($_REQUEST['newvm'])) { $formname="newvm"; $editid=""; $mode="newvm"; } if (isset($formname)){ echo "