| 1313 | | { |
|---|
| 1314 | | my $home = $_[0] ; |
|---|
| 1315 | | my $mac = toMacFileName($_[1]) ; |
|---|
| 1316 | | |
|---|
| 1317 | | my $defaultpos = 0 ; |
|---|
| 1318 | | my @menus = () ; |
|---|
| 1319 | | |
|---|
| 1320 | | my $menupath = $home . "/cfg/" . $mac ; |
|---|
| 1321 | | my $imagepath = $home . "/images/" . $mac ; |
|---|
| 1322 | | my $menuheader = "" ; |
|---|
| 1323 | | my $bootmenu = "" ; |
|---|
| 1324 | | my $one = "" ; |
|---|
| 1325 | | my $m ; |
|---|
| 1326 | | my $numselect = 0 ; |
|---|
| 1327 | | my %hdr ; |
|---|
| 1328 | | my %minfo ; |
|---|
| 1329 | | my $hostconf = $home . "/images/" . $mac . "/header.lst" ; |
|---|
| 1330 | | my $imgname ; |
|---|
| 1331 | | |
|---|
| 1332 | | my $copynumdata; |
|---|
| 1333 | | my $basenumdata ; |
|---|
| 1334 | | |
|---|
| 1335 | | if (not hdrLoad($hostconf, \%hdr)) { |
|---|
| 1336 | | lbsError("makeUserMenu","FILE_LOAD",$hostconf) ; |
|---|
| 1337 | | return 0 ; |
|---|
| 1338 | | } |
|---|
| 1339 | | |
|---|
| 1340 | | if (-f "$imagepath/COPYNUM") { |
|---|
| 1341 | | fileLoad("$imagepath/COPYNUM", \$copynumdata) ; |
|---|
| 1342 | | chomp($copynumdata); |
|---|
| 1343 | | } |
|---|
| 1344 | | else { |
|---|
| 1345 | | $copynumdata = "COPYNUM" ; |
|---|
| 1346 | | } |
|---|
| 1347 | | |
|---|
| 1348 | | |
|---|
| 1349 | | if (-f "$home/imgbase/BASENUM") { |
|---|
| 1350 | | fileLoad("$home/imgbase/BASENUM", \$basenumdata) ; |
|---|
| 1351 | | chomp($basenumdata); |
|---|
| 1352 | | } |
|---|
| 1353 | | else { |
|---|
| 1354 | | $basenumdata = "BASENUM" ; |
|---|
| 1355 | | } |
|---|
| 1356 | | |
|---|
| 1357 | | # |
|---|
| 1358 | | my %conf = (); |
|---|
| 1359 | | iniLoad("/etc/webmin/lbs/config", \%conf); |
|---|
| 1360 | | my $revorestore = iniGetVal(\%conf, "-", "restore_type"); |
|---|
| 1361 | | my $revowait = iniGetVal(\%conf, "-", "mtftp_wait"); |
|---|
| 1362 | | my $grub_splashimage = iniGetVal(\%conf, "-", "grub_splashimage"); |
|---|
| | 1313 | { |
|---|
| | 1314 | my $home = $_[0] ; |
|---|
| | 1315 | my $mac = toMacFileName($_[1]) ; |
|---|
| | 1316 | |
|---|
| | 1317 | my $defaultpos = 0 ; |
|---|
| | 1318 | my @menus = () ; |
|---|
| | 1319 | |
|---|
| | 1320 | my $menupath = $home . "/cfg/" . $mac ; |
|---|
| | 1321 | my $imagepath = $home . "/images/" . $mac ; |
|---|
| | 1322 | my $menuheader = "" ; |
|---|
| | 1323 | my $bootmenu = "" ; |
|---|
| | 1324 | my $one = "" ; |
|---|
| | 1325 | my $m ; |
|---|
| | 1326 | my $numselect = 0 ; |
|---|
| | 1327 | my %hdr ; |
|---|
| | 1328 | my %minfo ; |
|---|
| | 1329 | my $hostconf = $home . "/images/" . $mac . "/header.lst" ; |
|---|
| | 1330 | my $imgname ; |
|---|
| | 1331 | |
|---|
| | 1332 | my $copynumdata; |
|---|
| | 1333 | my $basenumdata ; |
|---|
| | 1334 | |
|---|
| | 1335 | # WOL requested ? |
|---|
| | 1336 | if (-f $home . "/images/" . $mac . "/wol") { |
|---|
| | 1337 | # check if the timestamp is not too old |
|---|
| | 1338 | my $wol = $home . "/images/" . $mac . "/wol"; |
|---|
| | 1339 | my $ts = (stat($wol))[9]; |
|---|
| | 1340 | if (time() - $ts > 600) { |
|---|
| | 1341 | # 10 minutes: the wol request has expired ... |
|---|
| | 1342 | # we should tell the admin |
|---|
| | 1343 | } else { |
|---|
| | 1344 | # wol requested, use the alternate menu |
|---|
| | 1345 | $hostconf = $home . "/images/" . $mac . "/header.lst.wol"; |
|---|
| | 1346 | } |
|---|
| | 1347 | unlink($wol); |
|---|
| | 1348 | } |
|---|
| | 1349 | |
|---|
| | 1350 | # Load header.lst |
|---|
| | 1351 | if (not hdrLoad($hostconf, \%hdr)) { |
|---|
| | 1352 | lbsError("makeUserMenu","FILE_LOAD",$hostconf) ; |
|---|
| | 1353 | return 0 ; |
|---|
| | 1354 | } |
|---|
| | 1355 | |
|---|
| | 1356 | if (-f "$imagepath/COPYNUM") { |
|---|
| | 1357 | fileLoad("$imagepath/COPYNUM", \$copynumdata) ; |
|---|
| | 1358 | chomp($copynumdata); |
|---|
| | 1359 | } else { |
|---|
| | 1360 | $copynumdata = "COPYNUM" ; |
|---|
| | 1361 | } |
|---|
| | 1362 | |
|---|
| | 1363 | |
|---|
| | 1364 | if (-f "$home/imgbase/BASENUM") { |
|---|
| | 1365 | fileLoad("$home/imgbase/BASENUM", \$basenumdata) ; |
|---|
| | 1366 | chomp($basenumdata); |
|---|
| | 1367 | } else { |
|---|
| | 1368 | $basenumdata = "BASENUM" ; |
|---|
| | 1369 | } |
|---|
| | 1370 | |
|---|
| | 1371 | # |
|---|
| | 1372 | my %conf = (); |
|---|
| | 1373 | iniLoad("/etc/webmin/lbs/config", \%conf); |
|---|
| | 1374 | my $revorestore = iniGetVal(\%conf, "-", "restore_type"); |
|---|
| | 1375 | my $revowait = iniGetVal(\%conf, "-", "mtftp_wait"); |
|---|
| | 1376 | my $grub_splashimage = iniGetVal(\%conf, "-", "grub_splashimage"); |
|---|
| 1364 | | # |
|---|
| 1365 | | my $eth = "0"; |
|---|
| 1366 | | $eth = hdrGetVal(\%hdr, "header", "ethnum"); |
|---|
| 1367 | | my $kernelopts = ""; |
|---|
| 1368 | | $kernelopts = hdrGetVal(\%hdr, "header", "kernelopts"); |
|---|
| 1369 | | |
|---|
| 1370 | | @menus = hdrGetMenuNames(\%hdr) ; |
|---|
| 1371 | | |
|---|
| 1372 | | foreach $m (@menus) { |
|---|
| 1373 | | |
|---|
| 1374 | | hdrGetMenuInfo(\%hdr, $m, \%minfo) ; |
|---|
| 1375 | | |
|---|
| 1376 | | if ($minfo{'visu'} eq "yes") { |
|---|
| 1377 | | # Determiner la pos du menu par defaut: |
|---|
| 1378 | | $defaultpos = $numselect if ($minfo{'def'} eq "yes") ; |
|---|
| | 1378 | # |
|---|
| | 1379 | my $eth = "0"; |
|---|
| | 1380 | $eth = hdrGetVal(\%hdr, "header", "ethnum"); |
|---|
| | 1381 | my $kernelopts = ""; |
|---|
| | 1382 | $kernelopts = hdrGetVal(\%hdr, "header", "kernelopts"); |
|---|
| | 1383 | |
|---|
| | 1384 | @menus = hdrGetMenuNames(\%hdr) ; |
|---|
| | 1385 | |
|---|
| | 1386 | foreach $m (@menus) { |
|---|
| | 1387 | |
|---|
| | 1388 | hdrGetMenuInfo(\%hdr, $m, \%minfo) ; |
|---|
| | 1389 | |
|---|
| | 1390 | if ($minfo{'visu'} eq "yes") { |
|---|
| | 1391 | # Determiner la pos du menu par defaut: |
|---|
| | 1392 | $defaultpos = $numselect if ($minfo{'def'} eq "yes") ; |
|---|
| 1380 | | $one = hdrConcatMenuItems(\%hdr, $m) ; |
|---|
| 1381 | | $one = encodeCP850($one) ; |
|---|
| 1382 | | |
|---|
| 1383 | | $imgname = $minfo{'image'} ; |
|---|
| 1384 | | |
|---|
| 1385 | | $one =~ s/MAC/$mac/ ; |
|---|
| 1386 | | $one =~ s/PATH/$imagepath\/$imgname/g ; |
|---|
| 1387 | | |
|---|
| 1388 | | $one =~ s/COPYNUM/$copynumdata/ ; |
|---|
| 1389 | | $one =~ s/BASENUM/$basenumdata/ ; |
|---|
| | 1394 | $one = hdrConcatMenuItems(\%hdr, $m) ; |
|---|
| | 1395 | |
|---|
| | 1396 | $one = encodeCP850($one) ; |
|---|
| | 1397 | |
|---|
| | 1398 | $imgname = $minfo{'image'} ; |
|---|
| | 1399 | |
|---|
| | 1400 | $one =~ s/MAC/$mac/ ; |
|---|
| | 1401 | $one =~ s/PATH/$imagepath\/$imgname/g ; |
|---|
| | 1402 | |
|---|
| | 1403 | $one =~ s/COPYNUM/$copynumdata/ ; |
|---|
| | 1404 | $one =~ s/BASENUM/$basenumdata/ ; |
|---|
| 1392 | | if ($revorestore eq "" || $revorestore eq "0") { |
|---|
| 1393 | | # tftp grub restore |
|---|
| 1394 | | # nothing to do |
|---|
| 1395 | | } else { |
|---|
| 1396 | | # linux based restore |
|---|
| 1397 | | if ($minfo{'image'} =~ /((Base|Local)-[0-9].*)/) |
|---|
| 1398 | | { |
|---|
| 1399 | | # base image restoration |
|---|
| 1400 | | my $imgt = "imgbase"; |
|---|
| 1401 | | my $imgo = "revorestore"; |
|---|
| 1402 | | |
|---|
| 1403 | | if ($revorestore eq "1") { |
|---|
| 1404 | | $imgo = "revorestorenfs"; |
|---|
| 1405 | | } elsif ($revowait ne "0") { |
|---|
| 1406 | | $imgo .= " revowait=$revowait"; |
|---|
| 1407 | | } |
|---|
| 1408 | | if ($minfo{'image'} =~ /Local/) { |
|---|
| 1409 | | $imgt = "images/$mac"; |
|---|
| 1410 | | } |
|---|
| | 1407 | if ($revorestore eq "" || $revorestore eq "0") { |
|---|
| | 1408 | # tftp grub restore |
|---|
| | 1409 | # nothing to do |
|---|
| | 1410 | } else { |
|---|
| | 1411 | # linux based restore |
|---|
| | 1412 | if ($minfo{'image'} =~ /((Base|Local)-[0-9].*)/) { |
|---|
| | 1413 | # base image restoration |
|---|
| | 1414 | my $imgt = "imgbase"; |
|---|
| | 1415 | my $imgo = "revorestore"; |
|---|
| | 1416 | |
|---|
| | 1417 | if ($revorestore eq "1") { |
|---|
| | 1418 | $imgo = "revorestorenfs"; |
|---|
| | 1419 | } elsif ($revowait ne "0") { |
|---|
| | 1420 | $imgo .= " revowait=$revowait"; |
|---|
| | 1421 | } |
|---|
| | 1422 | if ($minfo{'image'} =~ /Local/) { |
|---|
| | 1423 | $imgt = "images/$mac"; |
|---|
| | 1424 | } |
|---|
| 1412 | | #print "$1 $revorestore \n"; |
|---|
| 1413 | | my $o_title = ""; |
|---|
| 1414 | | my $o_desc = ""; |
|---|
| 1415 | | foreach my $line (split (/\n/, $one)) |
|---|
| 1416 | | { |
|---|
| 1417 | | if ($line =~ /^\s*title /) { |
|---|
| 1418 | | $o_title = $line; |
|---|
| 1419 | | } |
|---|
| 1420 | | if ($line =~ /^\s*desc /) { |
|---|
| 1421 | | $o_desc = $line; |
|---|
| 1422 | | } |
|---|
| 1423 | | } |
|---|
| 1424 | | $one = "$o_title\n$o_desc"; |
|---|
| 1425 | | if ($revorestore eq "1") { |
|---|
| 1426 | | $one =~ s/(^\s*title.*)/$1 (NFS)/; |
|---|
| 1427 | | } elsif ($revorestore eq "2") { |
|---|
| 1428 | | $one =~ s/(^\s*title.*)/$1 (MTFTP)/; |
|---|
| 1429 | | } |
|---|
| 1430 | | $one .= " |
|---|
| | 1426 | #print "$1 $revorestore \n"; |
|---|
| | 1427 | my $o_title = ""; |
|---|
| | 1428 | my $o_desc = ""; |
|---|
| | 1429 | foreach my $line (split (/\n/, $one)) { |
|---|
| | 1430 | if ($line =~ /^\s*title /) { |
|---|
| | 1431 | $o_title = $line; |
|---|
| | 1432 | } |
|---|
| | 1433 | if ($line =~ /^\s*desc /) { |
|---|
| | 1434 | $o_desc = $line; |
|---|
| | 1435 | } |
|---|
| | 1436 | } |
|---|
| | 1437 | $one = "$o_title\n$o_desc"; |
|---|
| | 1438 | if ($revorestore eq "1") { |
|---|
| | 1439 | $one =~ s/(^\s*title.*)/$1 (NFS)/; |
|---|
| | 1440 | } elsif ($revorestore eq "2") { |
|---|
| | 1441 | $one =~ s/(^\s*title.*)/$1 (MTFTP)/; |
|---|
| | 1442 | } |
|---|
| | 1443 | $one .= " |
|---|
| 1450 | | $numselect++ ; |
|---|
| 1451 | | } |
|---|
| 1452 | | } |
|---|
| 1453 | | |
|---|
| 1454 | | $menuheader = hdrConcatMenuItems(\%hdr, "header") ; |
|---|
| 1455 | | $menuheader =~ s/DEFNUM/$defaultpos/ ; |
|---|
| 1456 | | if ($grub_splashimage ne "") { |
|---|
| 1457 | | $menuheader .= "\nsplashimage (nd)$grub_splashimage\n"; |
|---|
| 1458 | | } |
|---|
| 1459 | | $menuheader = addEmptyLine($menuheader) ; |
|---|
| 1460 | | |
|---|
| 1461 | | # Generation du fichier final: |
|---|
| 1462 | | if (not open FF, "> $menupath") { |
|---|
| 1463 | | lbsError("makeUserMenu","RAW","Writing '$menupath': $!") ; |
|---|
| 1464 | | return 0 ; |
|---|
| 1465 | | } |
|---|
| 1466 | | |
|---|
| 1467 | | print FF $menuheader ; |
|---|
| 1468 | | print FF $bootmenu ; |
|---|
| 1469 | | |
|---|
| 1470 | | close(FF) ; |
|---|
| 1471 | | |
|---|
| 1472 | | return 1 ; |
|---|
| 1473 | | } |
|---|
| | 1463 | $numselect++ ; |
|---|
| | 1464 | } |
|---|
| | 1465 | } |
|---|
| | 1466 | |
|---|
| | 1467 | $menuheader = hdrConcatMenuItems(\%hdr, "header") ; |
|---|
| | 1468 | $menuheader =~ s/DEFNUM/$defaultpos/ ; |
|---|
| | 1469 | if ($grub_splashimage ne "") { |
|---|
| | 1470 | $menuheader .= "\nsplashimage (nd)$grub_splashimage\n"; |
|---|
| | 1471 | } |
|---|
| | 1472 | $menuheader = addEmptyLine($menuheader) ; |
|---|
| | 1473 | |
|---|
| | 1474 | # Generation du fichier final: |
|---|
| | 1475 | if (not open FF, "> $menupath") { |
|---|
| | 1476 | lbsError("makeUserMenu","RAW","Writing '$menupath': $!") ; |
|---|
| | 1477 | return 0 ; |
|---|
| | 1478 | } |
|---|
| | 1479 | |
|---|
| | 1480 | print FF $menuheader ; |
|---|
| | 1481 | print FF $bootmenu ; |
|---|
| | 1482 | |
|---|
| | 1483 | close(FF) ; |
|---|
| | 1484 | |
|---|
| | 1485 | return 1 ; |
|---|
| | 1486 | } |
|---|
| | 1711 | |
|---|
| | 1712 | # regular and scheduled menus should be sync before entering this menu |
|---|
| | 1713 | # so either we should copy regular to scheduled, or |
|---|
| | 1714 | # we commit the previous changes to the existing file |
|---|
| | 1715 | if (-f "$hostconf.$WOL_EXTENSION") { |
|---|
| | 1716 | my %schedhdr; |
|---|
| | 1717 | hdrLoad("$hostconf.$WOL_EXTENSION", \%schedhdr); |
|---|
| | 1718 | hdrAddMenu(\%schedhdr, $menu); |
|---|
| | 1719 | hdrSetVal(\%schedhdr, $menu, "def", "no") ; |
|---|
| | 1720 | hdrSetVal(\%schedhdr, $menu, "visu", "yes") ; |
|---|
| | 1721 | hdrSetVal(\%schedhdr, $menu, "image", $image) ; |
|---|
| | 1722 | hdrSetVal(\%schedhdr, $menu, "include", $include) if (length($include)) ; |
|---|
| | 1723 | hdrSave("$hostconf.$WOL_EXTENSION",\%schedhdr) ; |
|---|
| | 1724 | } else { |
|---|
| | 1725 | system("cp -a $hostconf $hostconf.$WOL_EXTENSION") ; |
|---|
| | 1726 | } |
|---|
| 1823 | | |
|---|
| | 1863 | |
|---|
| | 1864 | # regular and scheduled menus should be sync before entering this menu |
|---|
| | 1865 | # so either we should copy regular to scheduled, or |
|---|
| | 1866 | # we commit the previous changes to the existing file |
|---|
| | 1867 | if (-f "$hostconf.$WOL_EXTENSION") { |
|---|
| | 1868 | my %schedhdr; |
|---|
| | 1869 | hdrLoad("$hostconf.$WOL_EXTENSION", \%schedhdr); |
|---|
| | 1870 | hdrAddMenu(\%schedhdr, $menu); |
|---|
| | 1871 | hdrSetVal(\%schedhdr, $menu, "def", "no") ; |
|---|
| | 1872 | hdrSetVal(\%schedhdr, $menu, "visu", "no") ; |
|---|
| | 1873 | hdrSetVal(\%schedhdr, $menu, "image", $image) ; |
|---|
| | 1874 | hdrSetVal(\%schedhdr, $menu, "include", $include) if (length($include)) ; |
|---|
| | 1875 | hdrSave("$hostconf.$WOL_EXTENSION",\%schedhdr) ; |
|---|
| | 1876 | } else { |
|---|
| | 1877 | system("cp -a $hostconf $hostconf.$WOL_EXTENSION") ; |
|---|
| | 1878 | } |
|---|
| | 1879 | |
|---|