| | 579 | |
|---|
| | 580 | function astdb_get($exclude = array()) { |
|---|
| | 581 | global $astman; |
|---|
| | 582 | $db = $astman->database_show(); |
|---|
| | 583 | $astdb = array(); |
|---|
| | 584 | |
|---|
| | 585 | foreach ($db as $k => $v) { |
|---|
| | 586 | if (!in_array($k, $exclude)) { |
|---|
| | 587 | $key = explode('/', trim($k, '/'), 2); |
|---|
| | 588 | //dbug($k, $key[1]); |
|---|
| | 589 | $astdb[$key[0]][$key[1]] = $v; |
|---|
| | 590 | } |
|---|
| | 591 | } |
|---|
| | 592 | |
|---|
| | 593 | return $astdb; |
|---|
| | 594 | } |
|---|
| | 595 | |
|---|
| | 596 | function astdb_put($astdb, $exclude = array()) { |
|---|
| | 597 | global $astman; |
|---|
| | 598 | $db = $astman->database_show(); |
|---|
| | 599 | |
|---|
| | 600 | foreach ($astdb as $family => $key) { |
|---|
| | 601 | |
|---|
| | 602 | if ($family && !in_array($family, $exclude)) { |
|---|
| | 603 | $astman->database_deltree($family); |
|---|
| | 604 | } |
|---|
| | 605 | |
|---|
| | 606 | foreach($key as $k => $v) { |
|---|
| | 607 | //if ($k == 'Array' && $v == '<bad value>') continue; |
|---|
| | 608 | $astman->database_put($family, $k, $v); |
|---|
| | 609 | } |
|---|
| | 610 | |
|---|
| | 611 | } |
|---|
| | 612 | return true; |
|---|
| | 613 | } |
|---|
| | 614 | |
|---|
| | 615 | /** |
|---|
| | 616 | * function scandirr |
|---|
| | 617 | * scans a directory just like scandir(), only recursively |
|---|
| | 618 | * returns a hierarchical array representing the directory structure |
|---|
| | 619 | * |
|---|
| | 620 | * @pram string |
|---|
| | 621 | * @returns array |
|---|
| | 622 | * |
|---|
| | 623 | * @TODO: there is much that can be done to make this more useful |
|---|
| | 624 | * for example, as option to return absolute paths |
|---|
| | 625 | */ |
|---|
| | 626 | function scandirr($dir) { |
|---|
| | 627 | $list = array(); |
|---|
| | 628 | |
|---|
| | 629 | //get directory contents |
|---|
| | 630 | foreach (scandir($dir) as $d) { |
|---|
| | 631 | |
|---|
| | 632 | //ignore any of the files in the array |
|---|
| | 633 | if (in_array($d, array('.', '..'))) { |
|---|
| | 634 | continue; |
|---|
| | 635 | } |
|---|
| | 636 | |
|---|
| | 637 | //if current file ($d) is a directory, call scandirr |
|---|
| | 638 | if (is_dir($dir . '/' . $d)) { |
|---|
| | 639 | $list[$d] = scandirr($dir . '/' . $d); |
|---|
| | 640 | |
|---|
| | 641 | //otherwise, add the file to the list |
|---|
| | 642 | } elseif (is_file($dir . '/' . $d) || is_link($dir . '/' . $d)) { |
|---|
| | 643 | $list[] = $d; |
|---|
| | 644 | } |
|---|
| | 645 | } |
|---|
| | 646 | |
|---|
| | 647 | return $list; |
|---|
| | 648 | } |
|---|
| | 649 | |
|---|
| | 650 | function dbug_printtree($dir, $indent = "\t") { |
|---|
| | 651 | static $t = 0; |
|---|
| | 652 | $foo = ''; |
|---|
| | 653 | foreach ($dir as $key => $val) { |
|---|
| | 654 | //if this item is an array, its probobly a direcotry |
|---|
| | 655 | if (is_array($val)) { |
|---|
| | 656 | for ($i = 0; $i < $t; $i++) { |
|---|
| | 657 | $foo .= $indent; |
|---|
| | 658 | } |
|---|
| | 659 | //return the directory name |
|---|
| | 660 | $foo .= '[' . $key . ']' . "\n"; |
|---|
| | 661 | ++$t; |
|---|
| | 662 | printtree($val, $indent); |
|---|
| | 663 | --$t; |
|---|
| | 664 | } else { |
|---|
| | 665 | for ($i = 0; $i < $t; $i++) { |
|---|
| | 666 | $foo .= $indent; |
|---|
| | 667 | } |
|---|
| | 668 | //return file name |
|---|
| | 669 | $foo .= $val . "\n"; |
|---|
| | 670 | } |
|---|
| | 671 | } |
|---|
| | 672 | } |
|---|
| | 673 | |
|---|
| | 674 | /** |
|---|
| | 675 | * returns the absolute path to a system application |
|---|
| | 676 | * |
|---|
| | 677 | * @auther Moshe Brevda mbrevda => gmail ~ com |
|---|
| | 678 | * @pram string |
|---|
| | 679 | * @retruns string |
|---|
| | 680 | */ |
|---|
| | 681 | function fpbx_which($app) { |
|---|
| | 682 | global $amp_conf, $freepbx_conf; |
|---|
| | 683 | |
|---|
| | 684 | //if we have the location cached return it |
|---|
| | 685 | if (isset($amp_conf['WHICH_' . $app]) && $amp_conf['WHICH_' . $app]) { |
|---|
| | 686 | return $amp_conf['WHICH_' . $app]; |
|---|
| | 687 | |
|---|
| | 688 | //otherwise, search for it |
|---|
| | 689 | } else { |
|---|
| | 690 | //ist of posible plases to find which |
|---|
| | 691 | |
|---|
| | 692 | $which = array( |
|---|
| | 693 | 'which', |
|---|
| | 694 | '/usr/bin/which' //centos/mac osx |
|---|
| | 695 | ); |
|---|
| | 696 | |
|---|
| | 697 | foreach ($which as $w) { |
|---|
| | 698 | exec($w . ' ' . $app, $path, $ret); |
|---|
| | 699 | |
|---|
| | 700 | //exit if we have a posotive find |
|---|
| | 701 | if ($ret === 0) { |
|---|
| | 702 | break; |
|---|
| | 703 | } |
|---|
| | 704 | } |
|---|
| | 705 | |
|---|
| | 706 | if($path[0]) { |
|---|
| | 707 | //if we have a path add it to freepbx settings |
|---|
| | 708 | $set = array( |
|---|
| | 709 | 'value' => $path[0], |
|---|
| | 710 | 'defaultval' => $path[0], |
|---|
| | 711 | 'readonly' => 0, |
|---|
| | 712 | 'hidden' => 0, |
|---|
| | 713 | 'level' => 2, |
|---|
| | 714 | 'module' => '', |
|---|
| | 715 | 'category' => 'System Apps', |
|---|
| | 716 | 'emptyok' => 1, |
|---|
| | 717 | 'name' => 'Path for ' . $app, |
|---|
| | 718 | 'description' => 'The path to ' . $app |
|---|
| | 719 | . ' as auto-determined by the system.' |
|---|
| | 720 | . ' Overwrite as necessary.', |
|---|
| | 721 | 'type' => CONF_TYPE_TEXT |
|---|
| | 722 | ); |
|---|
| | 723 | $freepbx_conf->define_conf_setting('WHICH_' . $app, $set); |
|---|
| | 724 | $freepbx_conf->commit_conf_settings(); |
|---|
| | 725 | print_r($set); |
|---|
| | 726 | //return the path |
|---|
| | 727 | return $path[0]; |
|---|
| | 728 | } else { |
|---|
| | 729 | return false; |
|---|
| | 730 | } |
|---|
| | 731 | } |
|---|
| | 732 | } |
|---|
| | 733 | |
|---|
| | 734 | |
|---|
| | 735 | |
|---|
| | 736 | |
|---|
| | 737 | |
|---|