phone_home_stat.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Ensures that the user is running this PHP script with root
  4. * permissions. If not running with root permissions, causes the
  5. * script to exit.
  6. */
  7. function exitIfNotRoot()
  8. {
  9. // Need to check that we are superuser before running this.
  10. if(posix_geteuid() != 0){
  11. echo "Must be root user.\n";
  12. exit(1);
  13. }
  14. }
  15. exitIfNotRoot();
  16. date_default_timezone_set("UTC");
  17. $values = parse_ini_file('/etc/airtime/airtime.conf', true);
  18. $CC_CONFIG['phpDir'] = $values['general']['airtime_dir'];
  19. require_once($CC_CONFIG['phpDir'].'/application/configs/conf.php');
  20. $CC_CONFIG = Config::getConfig();
  21. require_once($CC_CONFIG['phpDir'].'/application/configs/constants.php');
  22. require_once($CC_CONFIG['phpDir'].'/application/logging/Logging.php');
  23. Logging::setLogPath("/var/log/airtime/zendphp.log");
  24. // Ensure library/ is on include_path
  25. set_include_path(implode(PATH_SEPARATOR, array(
  26. get_include_path(),
  27. realpath($CC_CONFIG['phpDir'] . '/library'),
  28. realpath($CC_CONFIG['phpDir']),
  29. realpath($CC_CONFIG['phpDir'].'/application/models'),
  30. )));
  31. require_once 'propel/runtime/lib/Propel.php';
  32. Propel::init($CC_CONFIG['phpDir']."/application/configs/airtime-conf-production.php");
  33. //Zend framework
  34. if (file_exists('/usr/share/php/libzend-framework-php')){
  35. set_include_path('/usr/share/php/libzend-framework-php' . PATH_SEPARATOR . get_include_path());
  36. }
  37. require_once('Zend/Loader/Autoloader.php');
  38. $autoloader = Zend_Loader_Autoloader::getInstance();
  39. $autoloader->registerNamespace('Application_');
  40. $resourceLoader = new Zend_Loader_Autoloader_Resource(array(
  41. 'basePath' => $CC_CONFIG['phpDir'].'/'.'application',
  42. 'namespace' => 'Application',
  43. 'resourceTypes' => array(
  44. 'model' => array(
  45. 'path' => 'models/',
  46. 'namespace' => 'Model',
  47. ),
  48. 'common' => array(
  49. 'path' => 'common/',
  50. 'namespace' => 'Common',
  51. ),
  52. ),
  53. ));
  54. $infoArray = Application_Model_Preference::GetSystemInfo(true);
  55. if(Application_Model_Preference::GetSupportFeedback() == '1'){
  56. $url = 'http://stat.sourcefabric.org/index.php?p=airtime';
  57. //$url = 'http://localhost:9999/index.php?p=airtime';
  58. $ch = curl_init();
  59. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  60. curl_setopt($ch, CURLOPT_POST, 1);
  61. curl_setopt($ch, CURLOPT_URL, $url);
  62. $data = json_encode($infoArray);
  63. $dataArray = array("data" => $data );
  64. curl_setopt($ch, CURLOPT_POSTFIELDS, $dataArray);
  65. $result = curl_exec($ch);
  66. curl_close($ch);
  67. }
  68. // Get latest version from stat server and store to db
  69. if(Application_Model_Preference::GetPlanLevel() == 'disabled'){
  70. $url = 'http://stat.sourcefabric.org/airtime-stats/airtime_latest_version';
  71. //$url = 'http://localhost:9999/index.php?p=airtime';
  72. $ch = curl_init();
  73. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  74. curl_setopt($ch, CURLOPT_URL, $url);
  75. $result = curl_exec($ch);
  76. if(curl_errno($ch)) {
  77. echo "curl error: " . curl_error($ch) . "\n";
  78. } else {
  79. $resultArray = explode("\n", $result);
  80. if (isset($resultArray[0])) {
  81. Application_Model_Preference::SetLatestVersion($resultArray[0]);
  82. }
  83. if (isset($resultArray[1])) {
  84. Application_Model_Preference::SetLatestLink($resultArray[1]);
  85. }
  86. }
  87. curl_close($ch);
  88. }