diff --git a/web/index.php b/web/index.php
index 82f830b..ba09c51 100644
--- a/web/index.php
+++ b/web/index.php
@@ -155,8 +155,18 @@ function checkmacfree($vmname,$mac,$db_handle){
return 0;
}
+if (isset($_POST['checkmac'])){
+ $mac = clean($_POST['checkmac']);
+ $mf = checkmacfree('novm', $mac, $db_handle);
+ if ($mf == 0){
+ echo "mac is free";
+ } else {
+ echo "mac not free";
+ }
+ exit;
+
//delete vms
-if (isset($_SESSION['username'])){
+} elseif (isset($_SESSION['username'])){
if ((isset($_POST['deleteid']))&&(isset($_POST['deletename']))&&($_POST['delwhat']=="vm")){
if($_SESSION['isadmin']!=1){
echo "you are not allowed to delete vms!";
@@ -777,7 +787,7 @@ if (isset($_SESSION['username'])){
} elseif (preg_match('/tapdev/', $arrColnames[$col])) {
echo "
$arrColnames[$col]
";
} elseif (preg_match('/macaddr/', $arrColnames[$col])) {
- echo "
$arrColnames[$col]
";
+ echo "
$arrColnames[$col]
gen
";
} elseif (preg_match('/brdev/', $arrColnames[$col])) {
echo "
$arrColnames[$col]
";
} elseif (preg_match('/drive/', $arrColnames[$col])){
diff --git a/web/nlvmi.js b/web/nlvmi.js
index 88954f9..261b935 100644
--- a/web/nlvmi.js
+++ b/web/nlvmi.js
@@ -215,3 +215,34 @@ function createimg(){
}
});
}
+
+function genmac(field){
+ freemacfound = "no";
+ while (freemacfound == "no"){
+ var text = "";
+ var possible = "abcdef0123456789";
+ for (j=0; j < 4; j++){
+ text += ":";
+ for (var i = 0; i < 2; i++)
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
+ }
+ var newmac = "52:54:00"+ text;
+ freemacfound = checkmac(newmac, field);
+ }
+}
+
+function checkmac(newmac,field){
+ $.ajax({
+ type: 'POST',
+ url: "?rand="+ makeid(),
+ data: "checkmac="+ newmac,
+ success: function(response){
+ if (response == "mac is free"){
+ $('#'+ field).val(newmac);
+ return newmac;
+ } else {
+ return "no";
+ }
+ }
+ });
+}