(root)/trunk/create_iso_template.php @ 3 - Редакция 2
Авторство |
Последнее изменение |
Открыть журнал
| RSS
<?PHP
//Проверяем авторизацию
session_start();
if ($_SESSION['$user_privileges'] < 16)
header("Location: index.php");
include "head.php";
include "config.php";
$template_id = $_GET['template_id'];
$db = mysql_connect("localhost", "linwin");
mysql_select_db("linwin", $db);
mysql_query("SET NAMES 'utf8';", $db);
//Загружем данные шаблона
$sql = "SELECT name FROM templates WHERE id = ". $template_id;
$query=mysql_query($sql, $db);
$template_name = mysql_result($query,0,0);
//Загружаем таблицу программ входящих в шаблон
$sql = "SELECT pid FROM prog_in_temp WHERE tid = ". $template_id;
$query=mysql_query($sql, $db);
$num_record = mysql_num_rows($query);
for($i = 0; $i < $num_record; $i++)
$mas_prog_in_temp_id[$i] = mysql_result($query,$i,0);
$sql_part = "('". $mas_prog_in_temp_id[0];
for ($i = 1; $i < count($mas_prog_in_temp_id); $i++)
{
$sql_part = $sql_part. "','". $mas_prog_in_temp_id[$i];
}
$sql_part = $sql_part. "')";
$sql = "SELECT id, name, description FROM program WHERE id in ". $sql_part. " ORDER BY name";
$query = mysql_query($sql, $db);
$mas_program_id = array();
$mas_program_name = array();
$mas_program_description = array();
$num_record = mysql_num_rows($query);
for ($i = 0; $i < $num_record; $i++)
{
$mas_program_id[] = mysql_result($query, $i, 0);
$mas_program_name[] = mysql_result($query, $i, 1);
$mas_program_description[] = mysql_result($query, $i, 2);
}
//Загружем таблицу урлов для программ данного шаблона
$sql = "SELECT id, description,url, local_mirror FROM url WHERE pid in ". $sql_part;
$query = mysql_query($sql, $db);
$mas_url_id = array();
$mas_url_description = array();
$mas_url_url = array();
$mas_local_mirror = array();
$num_record = mysql_num_rows($query);
for ($i = 0; $i < $num_record; $i++)
{
$mas_url_id[] = mysql_result($query, $i, 0);
$mas_url_description[] = mysql_result($query, $i, 1);
$mas_url_url[] = mysql_result($query, $i, 2);
$mas_url_local_mirror[] = mysql_result($query, $i, 3);
}
//Очищаем каталог временных файлов
$exec = "rm -rf $temp_dir"."* && /usr/bin/php-cgi -q $base_dir_linwin". "create_index.php template_id=". "$template_id > $temp_dir". "index.html";
if ($debug == "1")
print "<br/>Строка запуска rm:<br/>$exec<br/>";
$program_out = shell_exec($exec);
if ($debug == "1")
print "<br/>Что выдал exec после запуска:<br/>$program_out<br/>";
//Выкачиваем все урлы
for ($i = 0; $i < $num_record; $i++)
{
if ($mas_url_local_mirror[$i] == "1")
{
$exec = "cd $temp_dir && /usr/bin/wget -nH -x -N". " $base_url_software$mas_url_url[$i]";
if ($debug == "1")
print "<br/>Строка запуска wget:<br/>$exec<br/>";
$program_out = shell_exec($exec);
if ($debug == "1")
print "<br/>Что выдал exec после запуска:<br/>$program_out<br/>";
print "Выкачали($i из $num_record(не верно!!!)): ". "$mas_url_url[$i]". "<br/>";
}
}
//Подготавливаем html
$exec = "/usr/bin/php-cgi -q $base_dir_linwin". "create_index.php template_id=". "$template_id > $temp_dir". "index.html";
if ($debug == "1")
print "<br/>Строка запуска php-cgi:<br/>$exec<br/>";
$program_out = shell_exec($exec);
if ($debug == "1")
print "<br/>Что выдал exec после запуска:<br/>$program_out<br/>";
//Создаем iso образ
$exec = "/usr/bin/genisoimage -J -o $template_dir". "$template_name". ".iso $temp_dir";
if ($debug == "1")
print "<br/>Строка запуска genisoimage:<br/>$exec<br/>";
$program_out = shell_exec($exec);
if ($debug == "1")
print "<br/>Что выдал exec после запуска:<br/>$program_out<br/>";
//Создаем zip архив
$exec = "cd $temp_dir && /usr/bin/zip -9 -r $template_dir". "$template_name". " *";
$program_out = shell_exec($exec);
include "foot.php";
?>