forked from jerrm/endpointman
-
Notifications
You must be signed in to change notification settings - Fork 5
/
emportal
132 lines (113 loc) · 2.78 KB
/
emportal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/php
<?php
$colors = new Escape_Colors;
$bootstrap_settings['freepbx_auth'] = false;
if (!@include_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) {
include_once('/etc/asterisk/freepbx.conf');
}
if(!isset($amp_conf)) {
die($colors->fg_color("bold_red", "Sorry FreePBX 2.9+ is required\n"));
}
require_once 'includes/functions.inc';
if(!include_once 'Console/Getopt.php') {
die($colors->fg_color("bold_red", "Pear Console_Getopt Required\nTry to run 'pear install Console_Getopt'"));
}
$debug = NULL;
$endpoint = new endpointmanager();
echo $colors->fg_color("bold_red", "Endpoint Manager CLI\n\n");
$cg = new Console_Getopt();
$args = $cg->readPHPArgv();
array_shift($args);
$shortOpts = 'h::';
$longOpts = array('user=', 'group=');
$params = $cg->getopt2($args, $shortOpts, $longOpts);
print_r(condense_arguments($params));
echo "\n";
if (PEAR::isError($params)) {
echo 'Error: ' . $params->getMessage() . "\n";
exit(1);
}
function &condense_arguments($params)
{
$new_params = array();
foreach ($params[0] as $param) {
$new_params[$param[0]] = $param[1];
}
return $new_params;
}
/**
* Color escapes for bash output
*/
class Escape_Colors
{
private static $foreground = array(
'black' => '0;30',
'dark_gray' => '1;30',
'red' => '0;31',
'bold_red' => '1;31',
'green' => '0;32',
'bold_green' => '1;32',
'brown' => '0;33',
'yellow' => '1;33',
'blue' => '0;34',
'bold_blue' => '1;34',
'purple' => '0;35',
'bold_purple' => '1;35',
'cyan' => '0;36',
'bold_cyan' => '1;36',
'white' => '1;37',
'bold_gray' => '0;37',
);
private static $background = array(
'black' => '40',
'red' => '41',
'magenta' => '45',
'yellow' => '43',
'green' => '42',
'blue' => '44',
'cyan' => '46',
'light_gray' => '47',
);
/**
* Make string appear in color
*/
public static function fg_color($color, $string)
{
if (!isset(self::$foreground[$color]))
{
throw new Exception('Foreground color is not defined');
}
return "\033[" . self::$foreground[$color] . "m" . $string . "\033[0m";
}
/**
* Make string appear with background color
*/
public static function bg_color($color, $string)
{
if (!isset(self::$background[$color]))
{
throw new Exception('Background color is not defined');
}
return "\033[" . self::$background[$color] . 'm' . $string . "\033[0m";
}
/**
* See what they all look like
*/
public static function all_fg()
{
foreach (self::$foreground as $color => $code)
{
echo "$color - " . self::fg_color($color, 'Hello, world!') . PHP_EOL;
}
}
/**
* See what they all look like
*/
public static function all_bg()
{
foreach (self::$background as $color => $code)
{
echo "$color - " . self::bg_color($color, 'Hello, world!') . PHP_EOL;
}
}
}