Changeset 3389
- Timestamp:
- 12/20/06 08:38:51 (5 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
freepbx/trunk/amp_conf/htdocs/admin/functions.inc.php
r3388 r3389 1651 1651 } 1652 1652 1653 1654 function module_handleupload($uploaded_file) { 1655 global $amp_conf; 1656 $errors = array(); 1657 1658 if (!isset($uploaded_file['tmp_name']) || !file_exists($uploaded_file['tmp_name'])) { 1659 $errors[] = _("Error finding uploaded file - check your PHP and/or web server configuration"); 1660 return $errors; 1661 } 1662 1663 if (!preg_match('/\.(tar\.gz|tgz)$/', $uploaded_file['name'])) { 1664 $errors[] = _("File must be in tar+gzip (.tgz or .tar.gz) format"); 1665 return $errors; 1666 } 1667 1668 if (!preg_match('/^([A-Za-z][A-Za-z0-9_]+)\-([0-9a-z]+(\.[0-9a-z]+)*)\.(tar\.gz|tgz)$/', $uploaded_file['name'], $matches)) { 1669 $errors[] = _("Filename not in correct format: must be modulename-version.tar.gz (eg. custommodule-0.1.tar.gz)"); 1670 return $errors; 1671 } else { 1672 $modulename = $matches[1]; 1673 $moduleversion = $matches[2]; 1674 } 1675 1676 $temppath = $amp_conf['AMPWEBROOT'].'/admin/modules/_cache/'.uniqid("upload"); 1677 if (! @mkdir($temppath) ) { 1678 return array(sprintf(_("Error creating temporary directory: %s"), $temppath)); 1679 } 1680 $filename = $temppath.'/'.$uploaded_file['name']; 1681 1682 move_uploaded_file($uploaded_file['tmp_name'], $filename); 1683 1684 exec("tar ztf ".escapeshellarg($filename), $output, $exitcode); 1685 if ($exitcode != 0) { 1686 $errors[] = _("Error untaring uploaded file. Must be a tar+gzip file"); 1687 return $errors; 1688 } 1689 1690 foreach ($output as $line) { 1691 // make sure all lines start with "modulename/" 1692 if (!preg_match('/^'.$modulename.'\//', $line)) { 1693 $errors[] = 'File extracting to invalid location: '.$line; 1694 } 1695 } 1696 if (count($errors)) { 1697 return $errors; 1698 } 1699 1700 exec("tar zxf ".escapeshellarg($filename)." --directory=".escapeshellarg($amp_conf['AMPWEBROOT'].'/admin/modules/'), $output, $exitcode); 1701 if ($exitcode != 0) { 1702 $errors[] = _('Error untaring to modules directory.'); 1703 } 1704 1705 exec("rm -rf ".$temppath, $output, $exitcode); 1706 if ($exitcode != 0) { 1707 $errors[] = sprintf(_('Error removing temporary directory: %s'), $temppath); 1708 } 1709 1710 if (count($errors)) { 1711 return $errors; 1712 } 1713 1714 // finally, module installation is successful 1715 return true; 1716 } 1717 1718 1653 1719 /** Installs or upgrades a module from it's directory 1654 1720 * Checks dependencies, and enables freepbx/trunk/amp_conf/htdocs/admin/page.modules.php
r3388 r3389 427 427 428 428 break; 429 case 'upload': 430 // display links 431 echo "<a href='config.php?display=modules&type=tool'>"._("Manage local modules")."</a>\n"; 432 if (!EXTERNAL_PACKAGE_MANAGEMENT) { 433 echo " | <a href='config.php?display=modules&type=tool&online=1'>"._("Check for updates online")."</a>\n"; 434 } 435 436 if (isset($_FILES['uploadmod']) && !empty($_FILES['uploadmod']['name'])) { 437 // display upload link, only if they did upload something 438 echo " | <a href='config.php?display=modules&type=tool&extdisplay=upload'>"._("Upload module")."</a><br />\n"; 439 440 $res = module_handleupload($_FILES['uploadmod']); 441 if (is_array($res)) { 442 443 echo '<div class="error"><p>'; 444 echo sprintf(_('The following error(s) occured processing the uploaded file: %s'), 445 '<ul><li>'.implode('</li><li>',$res).'</li></ul>'); 446 echo sprintf(_('You should fix the problem or select another file and %s.'), 447 "<a href='config.php?display=modules&type=tool'>"._("try again")."</a>"); 448 echo "</p></div>\n"; 449 } else { 450 451 echo "<p>".sprintf(_("Module uploaded successfully. You need to enable the module using %s to make it available."), 452 "<a href='config.php?display=modules&type=tool'>"._("local module administration")."</a>") 453 ."</p>\n"; 454 } 455 456 } else { 457 echo "<p>"._('You can upload a tar gzip file containing a freePBX module from your local system. If a module with the same name already exists, it will be overwritten.')."</p>\n"; 458 459 echo "<form name=\"modulesGUI-upload\" action=\"config.php\" method=\"post\" enctype=\"multipart/form-data\">"; 460 echo "<input type=\"hidden\" name=\"display\" value=\"".$display."\" />"; 461 echo "<input type=\"hidden\" name=\"type\" value=\"".$type."\" />"; 462 echo "<input type=\"hidden\" name=\"extdisplay\" value=\"upload\" />"; 463 464 echo "<input type=\"file\" name=\"uploadmod\" /> "; 465 echo " <input type=\"submit\" value=\"Upload\" />"; 466 echo "</form>"; 467 } 468 469 break; 429 470 case 'online': 430 471 default: … … 453 494 echo "<a href='config.php?display=modules&type=tool&online=1'>"._("Check for updates online")."</a>\n"; 454 495 } 496 echo " | <a href='config.php?display=modules&type=tool&extdisplay=upload'>"._("Upload module")."</a><br />\n"; 455 497 } 456 498
