Changeset 12462
- Timestamp:
- 08/30/11 14:14:48 (2 years ago)
- Files:
-
- freepbx/trunk/install_amp (modified) (38 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
freepbx/trunk/install_amp
r12411 r12462 77 77 $file = file($filename); 78 78 foreach ($file as $line) { 79 if (preg_match("/^\s*([a-zA-Z0-9]+)\s*=\s*(.*)\s*([;#].*)?/",$line,$matches)) { 79 if (preg_match("/^\s*([a-zA-Z0-9]+)\s*=\s*(.*)\s*([;#].*)?/",$line,$matches)) { 80 80 $conf[ $matches[1] ] = $matches[2]; 81 81 } … … 86 86 $conf["AMPDBENGINE"] = "mysql"; 87 87 } 88 88 89 89 if ( !isset($conf["AMPDBNAME"]) || ($conf["AMPDBNAME"] == "")) { 90 90 $conf["AMPDBNAME"] = "asterisk"; 91 91 } 92 92 93 93 if ( !isset($conf["AMPENGINE"]) || ($conf["AMPENGINE"] == "")) { 94 94 $conf["AMPENGINE"] = "asterisk"; … … 101 101 $file = file($filename); 102 102 foreach ($file as $line) { 103 if (preg_match("/^\s*([a-zA-Z0-9]+)\s* => \s*(.*)\s*([;#].*)?/",$line,$matches)) { 103 if (preg_match("/^\s*([a-zA-Z0-9]+)\s* => \s*(.*)\s*([;#].*)?/",$line,$matches)) { 104 104 $conf[ $matches[1] ] = $matches[2]; 105 105 } … … 133 133 } 134 134 } 135 136 135 // add new entries 137 136 foreach ($conf as $key=>$val) { 138 137 $file[] = $key."=".$val."\n"; 139 138 } 140 139 141 140 // write the file 142 141 if (!$fd = fopen($filename, "w")) { … … 154 153 $key = fgets(STDIN,1024); 155 154 switch (strtolower($key[0])) { 156 case "y": return true; 155 case "y": return true; 157 156 case "a": $check_md5s=false; return true; 158 157 case "n": return false; 159 case "d": 158 case "d": 160 159 out(""); 161 160 // w = ignore whitespace, u = unified … … 169 168 out("-> Original file: ".$file2); 170 169 out("-> New file: ".$file1); 171 172 170 $pid = pcntl_fork(); 173 171 if ($pid == -1) { … … 180 178 pcntl_exec($shell, array(), $_ENV); 181 179 } 182 183 180 out("Returned from shell"); 184 181 } else { 185 182 out("[ERROR] PHP not built with process control (--enable-pcntl) support: cannot spawn shell"); 186 183 } 187 188 break; 189 case "x": 184 break; 185 case "x": 190 186 out("-> Original file: ".$file2); 191 187 out("-> New file: ".$file1); … … 205 201 global $debug; 206 202 global $runas_uid; 207 203 208 204 out("Generating Configurations.conf, (if Asterisk is not running, you will get an error"); 209 205 out("In case of error, start Asterisk and hit the red bar in the GUI to generate the Configurations.conf files"); … … 234 230 235 231 out("Creating new $filename"); 236 232 237 233 if ($scripted == true) { 238 234 # Scripted install. Everything should have been set for us, don't ask questions. … … 262 258 return; 263 259 } 264 260 265 261 outn("Enter your USERNAME to connect to the '$dbname' database:\n [".($dbuser ? $dbuser : $asterisk_user) . "] "); 266 262 $key = trim(fgets(STDIN,1024)); 267 if (preg_match('/^$/',$key)) 263 if (preg_match('/^$/',$key)) 268 264 $amp_conf["AMPDBUSER"] = ($dbuser ? $dbuser : $asterisk_user); 269 else 265 else 270 266 $amp_conf["AMPDBUSER"] = $key; 271 267 272 268 outn("Enter your PASSWORD to connect to the '$dbname' database:\n [".($dbpass ? $dbpass : $asterisk_pass)."] "); 273 269 $key = trim(fgets(STDIN,1024)); 274 if (preg_match('/^$/',$key)) 270 if (preg_match('/^$/',$key)) 275 271 $amp_conf["AMPDBPASS"] = ($dbpass ? $dbpass : $asterisk_pass); 276 else 272 else 277 273 $amp_conf["AMPDBPASS"] = $key; 278 274 279 275 outn("Enter the hostname of the '$dbname' database:\n [".($dbhost ? $dbhost : "localhost")."] "); 280 276 $key = trim(fgets(STDIN,1024)); 281 if (preg_match('/^$/',$key)) 277 if (preg_match('/^$/',$key)) 282 278 $amp_conf["AMPDBHOST"] = ($dbhost ? $dbhost : "localhost"); 283 else 279 else 284 280 $amp_conf["AMPDBHOST"] = $key; 285 281 286 282 outn("Enter a USERNAME to connect to the Asterisk Manager interface:\n [admin] "); 287 283 $key = trim(fgets(STDIN,1024)); 288 284 if (preg_match('/^$/',$key)) $amp_conf["AMPMGRUSER"] = "admin"; 289 285 else $amp_conf["AMPMGRUSER"] = $key; 290 286 291 287 outn("Enter a PASSWORD to connect to the Asterisk Manager interface:\n [amp111] "); 292 288 $key = trim(fgets(STDIN,1024)); 293 289 if (preg_match('/^$/',$key)) $amp_conf["AMPMGRPASS"] = "amp111"; 294 290 else $amp_conf["AMPMGRPASS"] = $key; 295 291 296 292 do { 297 293 out("Enter the path to use for your AMP web root:\n [$webroot] "); 298 294 $key = trim(fgets(STDIN,1024)); 299 if (preg_match('/^$/',$key)) 295 if (preg_match('/^$/',$key)) 300 296 $amp_conf["AMPWEBROOT"] = "$webroot"; 301 else 297 else 302 298 $amp_conf["AMPWEBROOT"] = rtrim($key,'/'); 303 299 … … 311 307 } 312 308 } while(1); 313 309 314 310 // Really no need to ask, is there. 315 311 if (empty($fopwebroot)) … … 317 313 else 318 314 $amp_conf["FOPWEBROOT"] = $fopwebroot; 319 315 320 316 outn("Enter the IP ADDRESS or hostname used to access the AMP web-admin:\n [$freepbxip] "); 321 317 $key = trim(fgets(STDIN,1024)); 322 318 if (preg_match('/^$/',$key)) $amp_conf["AMPWEBADDRESS"] = $freepbxip; 323 319 else $amp_conf["AMPWEBADDRESS"] = $key; 324 320 325 321 outn("Enter a PASSWORD to perform call transfers with the Flash Operator Panel:\n [passw0rd] "); 326 322 $key = trim(fgets(STDIN,1024)); 327 323 if (preg_match('/^$/',$key)) $amp_conf["FOPPASSWORD"] = "passw0rd"; 328 324 else $amp_conf["FOPPASSWORD"] = $key; 329 325 330 326 outn("Use simple Extensions [extensions] admin or separate Devices and Users [deviceanduser]?\n [extensions] "); 331 327 $key = trim(fgets(STDIN,1024)); 332 328 if (preg_match('/^$/',$key)) $amp_conf["AMPEXTENSIONS"] = "extensions"; 333 329 else $amp_conf["AMPEXTENSIONS"] = $key; 334 330 335 331 do { 336 332 out("Enter directory in which to store AMP executable scripts:\n [$ampbin_dir] "); 337 333 $key = trim(fgets(STDIN,1024)); 338 if (preg_match('/^$/',$key)) 334 if (preg_match('/^$/',$key)) 339 335 $amp_conf["AMPBIN"] = $ampbin_dir; 340 else 336 else 341 337 $amp_conf["AMPBIN"] = rtrim($key,'/'); 342 338 … … 350 346 } 351 347 } while(1); 352 348 353 349 do { 354 350 out("Enter directory in which to store super-user scripts:\n [$ampsbin_dir] "); 355 351 $key = trim(fgets(STDIN,1024)); 356 if (preg_match('/^$/',$key)) 352 if (preg_match('/^$/',$key)) 357 353 $amp_conf["AMPSBIN"] = "$ampsbin_dir"; 358 else 354 else 359 355 $amp_conf["AMPSBIN"] = rtrim($key,'/'); 360 356 … … 368 364 } 369 365 } while(1); 370 366 371 367 // write amportal.conf 372 368 write_amportal_conf($filename, $amp_conf); … … 448 444 // 449 445 switch ($up_module) { 450 case 'framework':451 case 'fw_ari':452 case 'fw_fop':453 system($amp_conf['AMPBIN']."/module_admin --no-warnings -f install $up_module");454 out("installed");446 case 'framework': 447 case 'fw_ari': 448 case 'fw_fop': 449 system($amp_conf['AMPBIN']."/module_admin --no-warnings -f install $up_module"); 450 out("installed"); 455 451 break; 456 default:457 system($amp_conf['AMPBIN']."/module_admin --no-warnings -f install $up_module");458 system($amp_conf['AMPBIN']."/module_admin --no-warnings -f enable $up_module");459 out("installed");452 default: 453 system($amp_conf['AMPBIN']."/module_admin --no-warnings -f install $up_module"); 454 system($amp_conf['AMPBIN']."/module_admin --no-warnings -f enable $up_module"); 455 out("installed"); 460 456 } 461 457 unset($included_modules[$id]); … … 464 460 } 465 461 } 466 }462 } 467 463 } 468 464 … … 497 493 // 498 494 $sql = "SELECT version FROM modules WHERE modulename = '$module'"; 499 $result = $db->getCol($sql); 500 if(DB::IsError($result)) { 501 fatal("error accessing version table: ".$result->getMessage()); 495 $result = $db->getCol($sql); 496 if(DB::IsError($result)) { 497 fatal("error accessing version table: ".$result->getMessage()); 502 498 } 503 499 $sql = ""; … … 519 515 if ($sql) { 520 516 debug($sql); 521 $result = $db->query($sql); 522 if(DB::IsError($result)) { 523 fatal("error writing to version table: ".$result->getMessage()); 517 $result = $db->query($sql); 518 if(DB::IsError($result)) { 519 fatal("error writing to version table: ".$result->getMessage()); 524 520 } 525 521 return "updated to $version"; … … 555 551 register_shutdown_function( create_function( '' , 'fclose(STDIN); fclose(STDOUT); fclose(STDERR); return true;' ) ); 556 552 } 557 553 558 554 // **** Make sure we have PEAR's DB.php, and include it 559 555 … … 597 593 598 594 //initialize variables to avoid php notices 599 $dbhost = null; 600 $dbname = 'asterisk'; 595 $dbhost = null; 596 $dbname = 'asterisk'; 601 597 $new_username = null; 602 598 $new_password = null; … … 612 608 showHelp(); 613 609 exit(10); 614 break;610 break; 615 611 case "--dry-run": 616 612 out("Dry-run only, nothing will be changed"); 617 613 $dryrun = true; 618 break;614 break; 619 615 case "--debug": 620 616 $debug = true; 621 617 debug("Debug mode enabled"); 622 break;618 break; 623 619 case "--username": case "u": 624 620 out("Using username: ".$arg[1]); 625 621 $new_username = $arg[1]; 626 break;622 break; 627 623 case "--password": case "p": 628 624 out("Using password: ".str_repeat("*",strlen($arg[1]))); 629 625 $new_password = $arg[1]; 630 break;626 break; 631 627 case "--force-version": 632 628 $version = $arg[1]; 633 629 out("Forcing upgrade from version ".$version); 634 break;630 break; 635 631 case "--dbhost": 636 632 $dbhost = $arg[1]; 637 633 out("Using remote database server at ".$dbhost); 638 break;634 break; 639 635 case "--dbname": 640 636 $dbname = $arg[1]; 641 637 out("Using database ".$dbname); 642 break;638 break; 643 639 case "--no-files": 644 640 $install_files = false; 645 641 out("Running upgrade only, without installing files."); 646 break;642 break; 647 643 case "--force-overwrite": 648 $check_md5s = false;644 $check_md5s = false; 649 645 out("Overwriting all files including modified ones."); 650 break;646 break; 651 647 case "--my-svn-is-correct": 652 648 $override_astvers = true; 653 break;649 break; 654 650 case "--engine": 655 651 if ($arg[1] != 'asterisk') { … … 657 653 } 658 654 $pbx_engine = $arg[1]; 659 break;655 break; 660 656 case "--install-moh": 661 657 $install_moh = true; 662 break;658 break; 663 659 case "--install-fop": 664 660 if(strtolower($arg[1]) == "false") { … … 668 664 out("FOP will be installed and activated."); 669 665 } 670 break;666 break; 671 667 case "--make-links-devel": 672 668 case "--dev-links": 673 669 $make_links = true; 674 break;670 break; 675 671 case "--skip-module-install": 676 672 $module_install = false; 677 break;673 break; 678 674 case "--fopwebroot": 679 675 $fopwebroot = $arg[1]; 680 676 out("Using fop at ".$fopwebroot); 681 break;677 break; 682 678 case "--webroot": 683 679 $webroot = $arg[1]; 684 680 out("Using Webroot at ".$webroot); 685 break;681 break; 686 682 case "--cgibin": 687 683 $cgibin = $arg[1]; 688 684 out("Using CGI-BIN at ".$cgibin); 689 break;685 break; 690 686 case "--bin": 691 687 $ampbin_dir = $arg[1]; 692 688 out("Using bin at ".$ampbin_dir); 693 break;689 break; 694 690 case "--sbin": 695 691 $ampsbin_dir = $arg[1]; 696 692 out("Using sbin at ".$ampsbin_dir); 697 break;693 break; 698 694 case "--asteriskuser": 699 695 $asterisk_user = $arg[1]; 700 696 out("Using Asterisk user ".$asterisk_user); 701 break;697 break; 702 698 case "--asteriskpass": 703 699 $asterisk_pass = $arg[1]; 704 700 out("Using asteriskpass ".str_repeat("*",strlen($arg[1]))); 705 break;701 break; 706 702 case "--uid": 707 703 $runas_uid = $arg[1]; 708 704 out("Setting ownership (user) to ".$runas_uid); 709 break;705 break; 710 706 case "--gid": 711 707 $runas_gid = $arg[1]; 712 708 out("Setting ownership (group) to ".$runas_gid); 713 break;709 break; 714 710 case "--scripted": 715 711 $scripted = true; 716 712 out("Unattended installation. No questions will be asked"); 717 break;713 break; 718 714 case "--freepbxip": 719 $freepbxip = $arg[1]; 715 $freepbxip = $arg[1]; 720 716 out("Setting IP address of web interface to $freepbxip"); 721 break;717 break; 722 718 case "--asteriskip": 723 $asteriskip = $arg[1]; 719 $asteriskip = $arg[1]; 724 720 out("Setting IP address of asterisk to $asteriskip"); 725 break; 726 721 break; 727 722 728 723 } … … 764 759 // this file contains password and should not be a+r 765 760 // this addresses http://freepbx.org/trac/ticket/1878 766 chown(AMP_CONF, $runas_uid); 767 chgrp(AMP_CONF, $runas_gid); 768 chmod(AMP_CONF, 0640); 761 chown(AMP_CONF, $runas_uid); 762 chgrp(AMP_CONF, $runas_gid); 763 chmod(AMP_CONF, 0640); 769 764 770 765 collect_settings(AMP_CONF, $dbhost, $new_username, $new_password, $dbname); … … 840 835 if (isset($amp_conf['FOPDISABLE']) && (strtolower(trim($amp_conf['FOPDISABLE'])) == 'true' || strtolower(trim($amp_conf['FOPDISABLE'])) == 'yes' || strtolower(trim($amp_conf['FOPDISABLE'])) == 'y') ) { 841 836 $install_fop = false; 842 } 837 } 843 838 // write amportal.conf 844 839 // TODO: if we boostrapped we don't want to write amportal.conf, or do we? e.g. if we are running out of the file vs. the … … 924 919 $asterisk_version = $matches[1]; 925 920 926 } elseif (preg_match('/^Asterisk ([ABC]\.\d+(\.\d+)*)(-?(.*))$/', $verinfo, $matches)) { 921 } elseif (preg_match('/^Asterisk ([ABC]\.\d+(\.\d+)*)(-?(.*))$/', $verinfo, $matches)) { 927 922 if (substr($matches[1], 0, 1) == "A") { 928 923 fatal("Asterisk Business Edition B or C is required for this version of FreePBX. Detected version is: ".$matches[1]); … … 956 951 if (strtolower($tmpoutput[0]) === "enabled") { 957 952 // this method seems better because disabled and permissive are the same 958 // if a user installs and realizes selinux is running the other method 953 // if a user installs and realizes selinux is running the other method 959 954 // requires a reboot to get selinuxenabled to work after editing the selinux config 960 955 // this will allow you to use setenforce 0 which turns selinux into permissive mode which … … 978 973 $db_name = $amp_conf["AMPDBNAME"]; 979 974 980 // we still support older configurations, and fall back 975 // we still support older configurations, and fall back 981 976 // into mysql when no other engine is defined 982 977 if ($db_engine == "") … … 984 979 $db_engine = "mysql"; 985 980 } 986 987 981 switch ($db_engine) 988 982 { 989 983 case "pgsql": 990 984 case "mysql": 991 // datasource in in this style: dbengine://username:password@host/database 985 // datasource in in this style: dbengine://username:password@host/database 992 986 if (!function_exists($db_engine.'_connect')) { 993 987 out("FAILED"); 994 988 fatal($db_engine." PHP libraries not installed"); 995 989 } 996 997 990 $datasource = $db_engine.'://'.$db_user.':'.$db_pass.'@'.$db_host.'/'.$db_name; 998 991 $db = DB::connect($datasource); // attempt connection 999 992 break; 1000 1001 993 case "sqlite": 1002 994 die_freepbx("SQLite2 support is deprecated. Please use sqlite3 only."); 1003 995 break; 1004 1005 996 case "sqlite3": 1006 997 if (!isset($amp_conf["AMPDBFILE"])) 1007 998 die("You must setup properly AMPDBFILE in /etc/amportal.conf"); 1008 1009 999 if (isset($amp_conf["AMPDBFILE"]) == "") 1010 1000 die("AMPDBFILE in /etc/amportal.conf cannot be blank"); 1011 1012 1001 /* on centos this extension is not loaded by default */ 1013 1002 if (! extension_loaded('sqlite3.so') && ! extension_loaded('SQLITE3')) 1014 1003 dl('sqlite3.so'); 1015 1016 if (! @require_once('DB/sqlite3.php') ) 1017 { 1004 if (! @require_once('DB/sqlite3.php') ) { 1018 1005 out("FAILED"); 1019 1006 fatal( "Your PHP installation has no PEAR/SQLite3 support. Please install php-sqlite3 and php-pear."); 1020 1007 } 1021 1022 1008 $datasource = "sqlite3:///" . $amp_conf["AMPDBFILE"] . "?mode=0666"; 1023 1009 $db = DB::connect($datasource); 1024 1010 break; 1025 1026 1011 default: 1027 1012 die( "Unknown SQL engine: [$db_engine]"); … … 1033 1018 out("Try running ".$argv[0]." --username=user --password=pass (using your own user and pass)"); 1034 1019 fatal("Cannot connect to database"); 1035 1020 1036 1021 } 1037 1022 out("OK"); … … 1056 1041 // is not there. 1057 1042 // 1058 $sql = "SELECT count(*) FROM freepbx_settings"; 1059 $num_settings = $db->getOne($sql); 1043 $sql = "SELECT count(*) FROM freepbx_settings"; 1044 $num_settings = $db->getOne($sql); 1060 1045 $force_amportal_conf = DB::IsError($num_settings) || $num_settings < 5; 1061 1046 … … 1074 1059 // link the packed js library for ARI, if there the error will indicate that 1075 1060 $libfreepbx = $amp_conf['AMPWEBROOT'].'/admin/common/libfreepbx.javascripts.js'; 1076 $dest_libfreepbx = $amp_conf['AMPWEBROOT'].'/recordings/theme/js/libfreepbx.javascripts.js'; 1061 $dest_libfreepbx = $amp_conf['AMPWEBROOT'].'/recordings/theme/js/libfreepbx.javascripts.js'; 1077 1062 if (!file_exists($amp_conf['AMPWEBROOT'].'/recordings/theme/js')) { 1078 1063 mkdir($amp_conf['AMPWEBROOT'].'/recordings/theme/js',0755, true); … … 1089 1074 1090 1075 // **** Apply amportal.conf configuration to files 1091 if (file_exists(dirname(__FILE__)."/apply_conf.sh")) { 1092 debug("Running ".dirname(__FILE__)."/apply_conf.sh");1076 if (file_exists(dirname(__FILE__)."/apply_conf.sh")) { 1077 debug("Running ".dirname(__FILE__)."/apply_conf.sh"); 1093 1078 } 1094 1079 … … 1142 1127 // 1143 1128 outn("apply username/password changes to conf files.."); 1144 if (file_exists(dirname(__FILE__)."/apply_conf.sh")) { 1129 if (file_exists(dirname(__FILE__)."/apply_conf.sh")) { 1145 1130 if ($force_amportal_conf) { 1146 1131 putenv('FORCE_AMPORTAL_CONF=1'); 1147 exec(dirname(__FILE__)."/apply_conf.sh ".AMP_CONF);1132 exec(dirname(__FILE__)."/apply_conf.sh ".AMP_CONF); 1148 1133 putenv('FORCE_AMPORTAL_CONF='); 1149 1134 } else { 1150 exec(dirname(__FILE__)."/apply_conf.sh");1135 exec(dirname(__FILE__)."/apply_conf.sh"); 1151 1136 } 1152 1137 } … … 1154 1139 1155 1140 /* As of Asterisk 1.4.16 or there about, a missing #include file will make the reload fail. So 1156 we need to make sure that we have such for everything that is in our configs. We will simply1157 look for the #include statements and touch the files vs. trying to inventory everything we may1158 need and then forgetting something.1141 we need to make sure that we have such for everything that is in our configs. We will simply 1142 look for the #include statements and touch the files vs. trying to inventory everything we may 1143 need and then forgetting something. 1159 1144 */ 1160 1145 1161 1146 outn("creating missing #include files.."); 1162 1147 $include_err = false; … … 1182 1167 if (!file_exists($target)) { 1183 1168 exec("sudo -u $asteriskuser touch $target", $output, $retcode); 1184 if ($retcode != 0) {1169 if ($retcode != 0) { 1185 1170 out("Error code $retcode: trying to create empty file $target"); 1186 1171 $include_err = true; … … 1217 1202 outn("Setting permissions on files.."); 1218 1203 if (!$dryrun) { 1219 if ($force_amportal_conf) {1220 putenv('FORCE_AMPORTAL_CONF=1');1221 }1204 if ($force_amportal_conf) { 1205 putenv('FORCE_AMPORTAL_CONF=1'); 1206 } 1222 1207 exec($amp_conf["AMPSBIN"]."/amportal chown"); 1223 if ($force_amportal_conf) {1224 putenv('FORCE_AMPORTAL_CONF=');1225 }1208 if ($force_amportal_conf) { 1209 putenv('FORCE_AMPORTAL_CONF='); 1210 } 1226 1211 } 1227 1212 out("OK"); … … 1280 1265 out("* upgrade is in progress. *",false); 1281 1266 out("*************************************************************************",false); 1282 // vim: set ts=4 sw=4 : //1283 // Ensure you 'set modeline' in your ~/.vimrc to activate this //1284 1267 ?>
