install.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. if (!class_exists('install')) {
  3. class install {
  4. /**
  5. * declare the variables
  6. */
  7. private $app_name;
  8. private $app_uuid;
  9. public $message;
  10. public $database_host;
  11. public $database_port;
  12. public $database_name;
  13. public $database_username;
  14. public $database_password;
  15. /**
  16. * called when the object is created
  17. */
  18. public function __construct() {
  19. //assign the variables
  20. $this->app_name = 'install';
  21. $this->app_uuid = '75507e6e-891e-11e5-af63-feff819cdc9f';
  22. }
  23. /**
  24. * <p>Used to create the config.conf file.</p>
  25. * <p>BSD /usr/local/etc/fusionpbx</p>
  26. * <p>Linux /etc/fusionpbx</p>
  27. * @return boolean
  28. */
  29. public function config() {
  30. //set the default config file location
  31. $os = strtoupper(substr(PHP_OS, 0, 3));
  32. switch ($os) {
  33. case "FRE":
  34. case "OPE":
  35. case "NET":
  36. case "BSD":
  37. $config_path = '/usr/local/etc/fusionpbx';
  38. $config_file = $config_path.'/config.conf';
  39. $document_root = '/usr/local/www/fusionpbx';
  40. $conf_dir = '/usr/local/etc/freeswitch';
  41. $sounds_dir = '/usr/share/freeswitch/sounds';
  42. $database_dir = '/var/lib/freeswitch/db';
  43. $recordings_dir = '/var/lib/freeswitch/recordings';
  44. $storage_dir = '/var/lib/freeswitch/storage';
  45. $voicemail_dir = '/var/lib/freeswitch/storage/voicemail';
  46. $scripts_dir = '/usr/share/freeswitch/scripts';
  47. $php_dir = PHP_BINDIR;
  48. $cache_location = '/var/cache/fusionpbx';
  49. break;
  50. case "LIN":
  51. $config_path = '/etc/fusionpbx/';
  52. $config_file = $config_path.'/config.conf';
  53. $document_root = '/var/www/fusionpbx';
  54. $conf_dir = '/etc/freeswitch';
  55. $sounds_dir = '/usr/share/freeswitch/sounds';
  56. $database_dir = '/var/lib/freeswitch/db';
  57. $recordings_dir = '/var/lib/freeswitch/recordings';
  58. $storage_dir = '/var/lib/freeswitch/storage';
  59. $voicemail_dir = '/var/lib/freeswitch/storage/voicemail';
  60. $scripts_dir = '/usr/share/freeswitch/scripts';
  61. $php_dir = PHP_BINDIR;
  62. $cache_location = '/var/cache/fusionpbx';
  63. break;
  64. case "WIN":
  65. $system_drive = getenv('SystemDrive');
  66. $config_path = $system_drive . DIRECTORY_SEPARATOR . 'ProgramData' . DIRECTORY_SEPARATOR . 'fusionpbx' ;
  67. $config_file = $config_path.DIRECTORY_SEPARATOR.'config.conf';
  68. $document_root = $_SERVER["DOCUMENT_ROOT"];
  69. $conf_dir = $_SERVER['ProgramFiles'].DIRECTORY_SEPARATOR.'freeswitch'.DIRECTORY_SEPARATOR.'conf';
  70. $sounds_dir = $_SERVER['ProgramFiles'].DIRECTORY_SEPARATOR.'freeswitch'.DIRECTORY_SEPARATOR.'sounds';
  71. $database_dir = $_SERVER['ProgramFiles'].DIRECTORY_SEPARATOR.'freeswitch'.DIRECTORY_SEPARATOR.'db';
  72. $recordings_dir = $_SERVER['ProgramFiles'].DIRECTORY_SEPARATOR.'freeswitch'.DIRECTORY_SEPARATOR.'recordings';
  73. $storage_dir = $_SERVER['ProgramFiles'].DIRECTORY_SEPARATOR.'freeswitch'.DIRECTORY_SEPARATOR.'storage';
  74. $voicemail_dir = $_SERVER['ProgramFiles'].DIRECTORY_SEPARATOR.'freeswitch'.DIRECTORY_SEPARATOR.'voicemail';
  75. $scripts_dir = $_SERVER['ProgramFiles'].DIRECTORY_SEPARATOR.'freeswitch'.DIRECTORY_SEPARATOR.'scripts';
  76. $php_dir = dirname(PHP_BINARY);
  77. $cache_location = dirname($_SERVER['DOCUMENT_ROOT']).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'fusionpbx';
  78. break;
  79. }
  80. //end the script if the config path is not set
  81. if (!isset($config_path)) {
  82. $this->message = "Config file path not found\n";
  83. return false;
  84. }
  85. //config directory is not writable
  86. if (!is_writable($config_path)) {
  87. $this->message = "Check permissions ".$config_path." must be writable.\n";
  88. return false;
  89. }
  90. //make the config directory
  91. if (isset($config_path)) {
  92. system('mkdir -p '.$config_path);
  93. }
  94. //build the config file
  95. $conf = "\n";
  96. $conf .= "#database system settings\n";
  97. $conf .= "database.0.type = pgsql\n";
  98. $conf .= "database.0.host = ".$this->database_host."\n";
  99. $conf .= "database.0.port = ".$this->database_port."\n";
  100. $conf .= "database.0.sslmode = prefer\n";
  101. $conf .= "database.0.name = ".$this->database_name."\n";
  102. $conf .= "database.0.username = ".$this->database_username."\n";
  103. $conf .= "database.0.password = ".$this->database_password."\n";
  104. $conf .= "\n";
  105. $conf .= "#database switch settings\n";
  106. $conf .= "database.1.type = sqlite\n";
  107. $conf .= "database.1.path = ".$database_dir."\n";
  108. $conf .= "database.1.name = core.db\n";
  109. //$conf .= "database.1.backend.base64 = \n";
  110. $conf .= "\n";
  111. $conf .= "#general settings\n";
  112. $conf .= "document.root = ".$document_root."\n";
  113. $conf .= "project.path =\n";
  114. $conf .= "temp.dir = /tmp\n";
  115. $conf .= "php.dir = ".$php_dir."\n";
  116. $conf .= "php.bin = php\n";
  117. $conf .= "\n";
  118. $conf .= "#cache settings\n";
  119. $conf .= "cache.method = file\n";
  120. $conf .= "cache.location = ".$cache_location."\n";
  121. $conf .= "cache.settings = true\n";
  122. $conf .= "\n";
  123. $conf .= "#switch settings\n";
  124. $conf .= "switch.conf.dir = ".$conf_dir."\n";
  125. $conf .= "switch.sounds.dir = ".$sounds_dir."\n";
  126. $conf .= "switch.database.dir = ".$database_dir."\n";
  127. $conf .= "switch.recordings.dir = ".$recordings_dir."\n";
  128. $conf .= "switch.storage.dir = ".$storage_dir."\n";
  129. $conf .= "switch.voicemail.dir = ".$voicemail_dir."\n";
  130. $conf .= "switch.scripts.dir = ".$scripts_dir."\n";
  131. $conf .= "\n";
  132. $conf .= "#switch xml handler\n";
  133. $conf .= "xml_handler.fs_path = false\n";
  134. $conf .= "xml_handler.reg_as_number_alias = false\n";
  135. $conf .= "xml_handler.number_as_presence_id = true\n";
  136. $conf .= "\n";
  137. $conf .= "#error reporting options: user,dev,all\n";
  138. $conf .= "error.reporting = user\n";
  139. //write the config file
  140. $file_handle = fopen($config_file,"w");
  141. if(!$file_handle) { return; }
  142. fwrite($file_handle, $conf);
  143. fclose($file_handle);
  144. //if the config.conf file was saved return true
  145. if (file_exists($config_file)) {
  146. return true;
  147. }
  148. else {
  149. return false;
  150. }
  151. }
  152. }
  153. }
  154. ?>