Revision fbc24b62
Added by Colin Smith over 20 years ago
- get_package_xml_depends($pkg_name): Return a package's XML dependencies (additional tabs etc)
- reverse_strrchr($haystack, $needle): Return everything in $haystack up to the last instance of $needle.
etc/inc/pfsense-utils.inc | ||
---|---|---|
587 | 587 |
} |
588 | 588 |
|
589 | 589 |
/* |
590 |
* sweep_package_processes() Periodically kill a package's unnecessary processes that may still be running (a server that does not automatically timeout, for example) |
|
590 |
* sweep_package_processes(): Periodically kill a package's unnecessary processes |
|
591 |
* that may still be running (a server that does not automatically timeout, for example) |
|
591 | 592 |
*/ |
592 | 593 |
function sweep_package_processes() { |
593 | 594 |
global $config; |
... | ... | |
604 | 605 |
/* |
605 | 606 |
* gather_altq_queue_stats(): gather alq queue stats and return an array that |
606 | 607 |
* is queuename|qlength|measured_packets |
607 |
* NOTE: this commandt takes 5 seconds to run
|
|
608 |
* NOTE: this command takes 5 seconds to run |
|
608 | 609 |
*/ |
609 | 610 |
function gather_altq_queue_stats($dont_return_root_queues) { |
610 | 611 |
mwexec("/usr/bin/killall -9 pfctl"); |
... | ... | |
632 | 633 |
return $queue_stats; |
633 | 634 |
} |
634 | 635 |
|
636 |
/* |
|
637 |
* reverse_strrchr($haystack, $needle): Return everything in $haystack up to the *last* instance of $needle. |
|
638 |
* Useful for finding paths and stripping file extensions. |
|
639 |
*/ |
|
640 |
function reverse_strrchr($haystack, $needle) { |
|
641 |
$pos = strrpos($haystack, $needle); |
|
642 |
if($post === false) { |
|
643 |
return $haystack; |
|
644 |
} |
|
645 |
return substr($haystack, 0, $post + 1); |
|
646 |
} |
|
647 |
|
|
648 |
/* |
|
649 |
* get_package_xml_depends($pkg_name): Return a package's XML dependencies (additional tabs etc) |
|
650 |
*/ |
|
651 |
function get_package_xml_depends($pkg_name) { |
|
652 |
global $config; |
|
653 |
if ($config['installedpackages'][$pkg_name] != "") { // Make sure this package really exists before continuing. |
|
654 |
$package = $config['installedpackages'][$pkg_name]; |
|
655 |
if(!file_exists("/usr/local/pkg/" . $package['configurationfile'])) { // If the package's config file doesn't exist, log an error and fetch it. |
|
656 |
log_error("Fetching missing configuration XML for " . $pkg_name); |
|
657 |
mwexec("/usr/bin/fetch -o /usr/local/pkg/" . $package['configurationfile'] . " http://www.pfsense.com/packages/config/" . $package['configurationfile']); |
|
658 |
} |
|
659 |
} else { |
|
660 |
return; // This package isn't installed. |
|
661 |
} |
|
662 |
$pkg_xml = parse_xml_config_pkg("/usr/local/pkg" . $package['configurationfile'], "packagegui"); |
|
663 |
if($pkg_xml['additional_files_needed'] != "") { |
|
664 |
foreach($pkg_xml['additional_files_needed'] as $item) { |
|
665 |
$depend_file = substr(strrchr($item['item'], "/"),1); // Strip URLs down to filenames. |
|
666 |
if(!preg_match("/\.xml/i", $depend_file)) break; // If the file doesn't end in .xml (case-insensitive) exit the loop. |
|
667 |
if(!file_exists("/usr/local/pkg/" . $pkg_name)) { |
|
668 |
$depend_name = reverse_strrchr($depend_file, "."); // Strip filename down to (guessed) dependency name. |
|
669 |
log_error("Fetching missing dependency \(" . $depend_name . "\) for " . $pkg_name); |
|
670 |
mwexec("/usr/bin/fetch -o /usr/local/pkg/" . $depend_file . " " . $item['item']); |
|
671 |
} |
|
672 |
$depends[] = $depend_file; |
|
673 |
} |
|
674 |
} |
|
675 |
return $depends; |
|
676 |
} |
|
677 |
|
|
635 | 678 |
/* |
636 | 679 |
* is_service_running($service_name): checks to see if a service is running. |
637 | 680 |
* if the service is running returns 1. |
... | ... | |
643 | 686 |
foreach ($status_split as $ss) $counter++; |
644 | 687 |
if($counter > 1) return 1; |
645 | 688 |
return 0; |
646 |
|
|
647 | 689 |
} |
648 |
|
|
649 | 690 |
?> |
Also available in: Unified diff