PageRenderTime 53ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/php/config.php

http://github.com/newscloud/open-social-media-toolkit
PHP | 267 lines | 204 code | 15 blank | 48 comment | 34 complexity | f426c8c957c86d12e17d0aafcdb3f924 MD5 | raw file
  1. <?php
  2. /* INSTALLATION MENU */
  3. /* Used for preparing the application */
  4. // check for database
  5. global $init; // global handle to the secret keys
  6. $database = $init['database'];
  7. $username = $init['username'];
  8. $password = $init['password'];
  9. $hostname = $init['hostname'];
  10. $con = mysql_connect($hostname, $username, $password);
  11. if (!$con)
  12. {
  13. die('Could not connect: ' . mysql_error());
  14. }
  15. if (mysql_num_rows(mysql_query("SHOW DATABASES like '$database'"))==0) {
  16. if (mysql_query("CREATE DATABASE $database")) {
  17. echo "Database created<br />";
  18. } else
  19. {
  20. echo "Error creating database: " . mysql_error();
  21. }
  22. }
  23. /* initialize database and libraries */
  24. include_once ('initialize.php');
  25. /* Process incoming variable requests */
  26. if (isset($_GET['apiKey'])) {
  27. $apiKey=$_GET['apiKey'];
  28. if (strlen($apiKey)>35) die('API key is invalid');
  29. }
  30. if (!defined('NO_SECURITY') OR !NO_SECURITY) {
  31. if (!isset($_GET['apiKey']))
  32. {
  33. echo 'You need to include your secret as an argument in your url.';
  34. die();
  35. } else {
  36. // verify api key
  37. if ($init['apiKey']<>$apiKey) {
  38. echo 'Invalid access!';
  39. die();
  40. }
  41. }
  42. }
  43. if (isset($_GET['action'])) {
  44. $action=$_GET['action'];
  45. if (strlen($action)>15) exit();
  46. } else
  47. $action='menu';
  48. $menu='<a name="menu" /><h1>Welcome to the NewsCloud Social Media Toolkit</h1>';
  49. $menu.='<p>Connected to the '.$db->database.' database</p>';
  50. $menu.='<h3>Installation Menu:</h3><ol>';
  51. $menu.='<li style="list-style-type: decimal;"><a href="?p=config&action=initDB&apiKey='.$apiKey.'">Initialize the database</a></li>';
  52. $menu.='<li style="list-style-type: decimal;"><a href="?p=config&action=addTestData&apiKey='.$apiKey.'">Populate test data</a></li>';
  53. $menu.='<li style="list-style-type: decimal;"><a href="?p=config&action=uploadSettings&apiKey='.$apiKey.'">Upload your Application settings to Facebook</a></li>';
  54. $menu.='<li style="list-style-type: decimal;">Visit your <a target="_fbapp" href="'.URL_CANVAS.'">Application on Facebook</a></li>';
  55. $menu.='<li style="list-style-type: decimal;">Visit the <a target="_fbmc" href="'.URL_CONSOLE.'">Management Console</a></li>';
  56. $menu.='<li style="list-style-type: decimal;">Remove <a href="?p=config&action=removeTestData&apiKey='.$apiKey.'">test data</a></li>';
  57. $menu.='<li style="list-style-type: decimal;"><a target="_fbhelp" href="http://support.newscloud.com/discussions/site-gallery">Add your site</a> to our public gallery</li>';
  58. $menu.='</ol>';
  59. // deprecated - $menu.='<li><a href="?p=config&action=reSync&apiKey='.$apiKey.'">Synchronize the database</a> with the remote NewsCloud server</li>';
  60. // deprecated - $menu.='<li>Hit p=config, action=cleanupUser with userid param set to userid to clean out their user records</li>';
  61. // deprecated - $menu.='<li><a href="?p=config&action=rewardBetaTesters&apiKey='.$apiKey.'">Submits beta tester\'s emails for Beta Test HotDish challenge (1-time)</a></li>';
  62. //$menu.='<li><a href="?p=config&action=resetDB&apiKey='.$apiKey.'">Reset the database</a> - erases everything</li>';
  63. //$menu.='<li><a href="?p=config&action=resetLog&apiKey='.$apiKey.'">Reset the log</a> - erases all user activities</li>';
  64. switch ($action) {
  65. default:
  66. break;
  67. case 'initDB':
  68. echo 'Scroll down to the <a href="#menu">installation menu</a> when complete<br /><br />';
  69. // override default time limit
  70. set_time_limit(300);
  71. include_once PATH_CORE."utilities/initDatabase.php";
  72. require_once(PATH_CORE.'/classes/cron.class.php');
  73. $cObj=new cron($init['apiKey']);
  74. $cObj->initJobs();
  75. $cObj->resetJobs();
  76. break;
  77. case 'addTestData':
  78. include_once PATH_CORE."utilities/populateTestData.php";
  79. break;
  80. case 'removeTestData':
  81. include_once PATH_CORE."utilities/removeTestData.php";
  82. break;
  83. case 'uploadSettings':
  84. echo 'Uploading settings in SystemStatus table up to Facebook Developer application<br />';
  85. require_once (PATH_CORE.'/classes/systemStatus.class.php');
  86. $ssObj=new systemStatus();
  87. $propList=$ssObj->loadFacebookProperties();
  88. echo 'These settings will be uploaded:<br />';
  89. print_r($propList);
  90. echo '<br />';
  91. require_once PATH_FACEBOOK."/classes/app.class.php";
  92. $app=new app(NULL,true);
  93. $facebook=&$app->loadFacebookLibrary();
  94. $props=$facebook->api_client->admin_setAppProperties($propList);
  95. echo 'Completed settings upload. Visit the <a href="http://www.facebook.com/developers/apps.php?app_id='.$init['fbAppId'].'">Facebook Developer app</a> to review them.<br />';
  96. break;
  97. case 'populateSubscriptions':
  98. require_once(PATH_CORE.'/classes/subscriptions.class.php');
  99. $subObj=new SubscriptionsManager($db);
  100. $subObj->populateSubscriptions();
  101. break;
  102. case 'resetDB':
  103. require_once(PATH_CORE.'/classes/cleanup.class.php');
  104. $cObj=new cleanup($db);
  105. $cObj->flushDatabase();
  106. if (MODULE_FACEBOOK)
  107. {
  108. echo 'cleaning up fb tables<br />';
  109. require_once(PATH_FACEBOOK.'/classes/cleanupFacebook.class.php');
  110. $cleanupObj=new cleanupFacebook($db,'');
  111. $cleanupObj->flushDatabase();
  112. echo 'fb/st Database cleansed<br />';
  113. }
  114. break;
  115. case 'resetLog':
  116. $db->delete("Log"); // for debug purposes
  117. break;
  118. case 'testJob':
  119. $job = $_GET['job'];
  120. echo 'Testing job:'. $job. '<br>';
  121. require_once(PATH_CORE.'/classes/cron.class.php');
  122. $cObj=new cron($init['apiKey']);
  123. $cObj->forceJob($job);
  124. break;
  125. case 'cleanupUser':
  126. require_once (PATH_CORE. '/classes/teamBackend.class.php');
  127. $teamObj = new teamBackend($db);
  128. $teamObj->cleanupUser($_GET['userid']);
  129. break;
  130. /* deprecated
  131. case 'rewardBetaTesters':
  132. require_once (PATH_CORE. '/classes/teamBackend.class.php');
  133. $teamObj = new teamBackend($db);
  134. $teamObj->rewardBetaTesters();
  135. break;
  136. case 'reSync':
  137. // call all cron jobs with new sync info
  138. require_once(PATH_CORE.'/classes/cron.class.php');
  139. $cObj=new cron($init['apiKey']);
  140. $db->update("cronJobs","nextRun=0","1=1");
  141. $cObj->fetchJobs();
  142. break;
  143. */
  144. }
  145. // check for warnings
  146. // re-run
  147. $warnings=checkWarnings($db);
  148. echo $menu.$warnings;
  149. $resources='<h3>Useful resources:</h3><ul>';
  150. $resources.='<li><a target="_fbhelp" href="http://support.newscloud.com">NewsCloud Open Source Support Community </a></li>';
  151. $resources.='<li><a target="_fbhelp" href="http://opensource.newscloud.com">NewsCloud Open Source Blog</a></li>';
  152. $resources.='<li><a target="_fbhelp" href="http://blog.newscloud.com/services.html">NewsCloud Consulting Services</a></li>';
  153. $resources.='<li><a target="_fbhelp" href="http://youreyelevel.com/smt/">Eye Level Design Consulting</a></li>';
  154. $resources.='</ul>';
  155. $resources.='<p><a href="http://www.twitter.com/newscloud"><img src="http://twitter-badges.s3.amazonaws.com/follow_bird-c.png" alt="Follow newscloud on Twitter"/></a>';
  156. echo $resources;
  157. function checkWarnings(&$db) {
  158. $warnings='';
  159. $q=$db->query("SHOW TABLES;"); // check if db has been configured
  160. if ($db->countQ($q)>0) {
  161. $q=$db->query("SELECT * FROM User,UserInfo WHERE User.userid=UserInfo.userid AND isAdmin=1");
  162. if ($db->countQ($q)==0) {
  163. $warnings.='<p><span style="color:red;"><strong>WARNING: No administrator yet.</strong></span> Set admin email in constants and run populate test data.</p>';
  164. } else {
  165. $data=$db->readQ($q);
  166. if ($data->fbId==0) {
  167. $warnings.='<p><span style="color:red;"><strong>WARNING: Administrator Facebook account not configured. <a href="'.URL_CANVAS.'?p=setAdmin">Configure now</a></strong></span></p>';
  168. }
  169. }
  170. }
  171. // check for write access to cache directory for CSS, JS files
  172. try {
  173. $tempStr=' <p><span style="color:red;"><strong>WARNING:</strong></span>Caching problem with CSS stylesheets and Javascript files - could not open or write to '.PATH_CACHE.' - set ownership for Apache Web service e.g. chown www-user:www-user '.PATH_CACHE.' and set write permissions for the directory chmod -R 755 '.PATH_CACHE.'</p>';
  174. $handle = fopen(PATH_CACHE.DS.'configTest.txt', "a");
  175. if (!$handle)
  176. $warnings.=$tempStr;
  177. else {
  178. $res=fwrite($handle,"config.php cache test");
  179. if (!$res) $warnings.=$tempStr;
  180. }
  181. } catch (Exception $e) {
  182. $warnings.=$tempStr;
  183. }
  184. if (defined('NO_SECURITY') AND NO_SECURITY) {
  185. global $init;
  186. $warnings.='<p><span style="color:red;"><strong>WARNING: Security is turned off</strong></span> Before you launch, be sure to turn security on in constants.php. <strong>Important</strong>: Bookmark <strong><a href="'.SITE_DOMAIN.'?p=config&apiKey='.$init['apiKey'].'">this link</a></strong> before you turn security on. After you turn security on, you can reach the management console from the Admin link in the footer of your Facebook application.</p>';
  187. }
  188. if (defined('NO_CACHE') AND NO_CACHE) {
  189. $warnings.='<p><span style="color:orange;"><strong>NOTICE: Caching is turned off</strong></span> When you are ready to launch, you can turn on caching in constants.php to enhance performance. You will need to permission the '.PATH_CACHE.' directory for Apache to write to.</p>';
  190. }
  191. if (defined('NO_LOGGING') AND NO_LOGGING) {
  192. $warnings.='<p><span style="color:orange;"><strong>NOTICE: Logging is turned off</strong></span> You can turn it on constants.php. You will need to touch and permission the specified /var/logs/*.log files for Apache to write to.</p>';
  193. } else {
  194. try {
  195. $tempStr=' <p><span style="color:red;"><strong>WARNING:</strong></span> Logging problem - could not open or write to '.PATH_LOGFILE.' - create the file e.g. touch '.PATH_LOGFILE.', then set ownership for Apache Web service e.g. chown www-data:www-data '.PATH_LOGFILE.'</p>';
  196. $handle = fopen(PATH_LOGFILE, "a");
  197. if (!$handle)
  198. $warnings.=$tempStr;
  199. else {
  200. $res=fwrite($handle,"config.php log test");
  201. if (!$res) $warnings.=$tempStr;
  202. }
  203. } catch (Exception $e) {
  204. $warnings.=$tempStr;
  205. }
  206. }
  207. // check for write access to uploaded file directories - PATH_UPLOAD_IMAGES
  208. try {
  209. $tempStr=' <p><span style="color:yellow;"><strong>Warning:</strong></span> Uploading user submissions - could not open or write to '.PATH_UPLOAD_IMAGES.' - set ownership for Apache Web service e.g. chown www-user:www-user '.PATH_UPLOAD_IMAGES.' and set write permissions for the directory chmod -R 755 '.PATH_UPLOAD_IMAGES.'</p>';
  210. $handle = fopen(PATH_UPLOAD_IMAGES.'configTest.txt', "a");
  211. if (!$handle)
  212. $warnings.=$tempStr;
  213. else {
  214. $res=fwrite($handle,"config.php upload test");
  215. if (!$res) $warnings.=$tempStr;
  216. }
  217. } catch (Exception $e) {
  218. $warnings.=$tempStr;
  219. }
  220. // check for write access to uploaded file directories - PATH_UPLOAD_SUBMISSIONS
  221. try {
  222. $tempStr=' <p><span style="color:yellow;"><strong>Warning:</strong></span> Uploading user submissions - could not open or write to '.PATH_UPLOAD_SUBMISSIONS.' - set ownership for Apache Web service e.g. chown www-user:www-user '.PATH_UPLOAD_SUBMISSIONS.' and set write permissions for the directory chmod -R 755 '.PATH_UPLOAD_SUBMISSIONS.'</p>';
  223. $handle = fopen(PATH_UPLOAD_SUBMISSIONS.'configTest.txt', "a");
  224. if (!$handle)
  225. $warnings.=$tempStr;
  226. else {
  227. $res=fwrite($handle,"config.php upload test");
  228. if (!$res) $warnings.=$tempStr;
  229. }
  230. } catch (Exception $e) {
  231. $warnings.=$tempStr;
  232. }
  233. return $warnings;
  234. }
  235. /* deprecated
  236. // initialize partner registration for this site and domain (if first time)
  237. require_once (PATH_CORE.'classes/systemStatus.class.php');
  238. $ssObj=new systemStatus($db);
  239. if ($ssObj->checkTable()) {
  240. $partnerid=$ssObj->getState('partnerid');
  241. if ($partnerid==0) {
  242. require_once (PATH_CORE.'/classes/apiCloud.class.php');
  243. $apiObj=new apiCloud($db,$init[apiKey]);
  244. $resp=$apiObj->partnerRegister(SITE_CLOUDID,URL_HOME,SITE_TITLE);
  245. if ($resp[result]) {
  246. $partnerid=$resp[items][0][partnerid];
  247. $ssObj->setState('partnerid',$partnerid);
  248. }
  249. }
  250. }
  251. */
  252. ?>