PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/www/admin/account-settings-banner-storage.php

https://bitbucket.org/blackriver/openx
PHP | 308 lines | 232 code | 18 blank | 58 comment | 30 complexity | 37eb5f342cb232ceb8f1d4b972357c5a MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id: account-settings-banner-storage.php 81772 2012-09-11 00:07:29Z chris.nutting $
  25. */
  26. // Require the initialisation file
  27. require_once '../../init.php';
  28. // Required files
  29. require_once MAX_PATH . '/lib/OA/Admin/Option.php';
  30. require_once MAX_PATH . '/lib/OA/Admin/Settings.php';
  31. require_once MAX_PATH . '/lib/max/Plugin/Translation.php';
  32. require_once MAX_PATH . '/www/admin/config.php';
  33. // Security check
  34. OA_Permission::enforceAccount(OA_ACCOUNT_ADMIN);
  35. // Create a new option object for displaying the setting's page's HTML form
  36. $oOptions = new OA_Admin_Option('settings');
  37. $prefSection = "banner-storage";
  38. // Prepare an array for storing error messages
  39. $aErrormessage = array();
  40. // If the settings page is a submission, deal with the form data
  41. if (isset($_POST['submitok']) && $_POST['submitok'] == 'true') {
  42. // Prepare an array of the HTML elements to process, and the
  43. // location to save the values in the settings configuration
  44. // file
  45. $aElements = array();
  46. // Allowed Banner Types
  47. $aElements += array(
  48. 'allowedBanners_sql' => array(
  49. 'allowedBanners' => 'sql',
  50. 'bool' => true
  51. ),
  52. 'allowedBanners_web' => array(
  53. 'allowedBanners' => 'web',
  54. 'bool' => true
  55. ),
  56. 'allowedBanners_url' => array(
  57. 'allowedBanners' => 'url',
  58. 'bool' => true
  59. ),
  60. 'allowedBanners_html' => array(
  61. 'allowedBanners' => 'html',
  62. 'bool' => true
  63. ),
  64. 'allowedBanners_text' => array(
  65. 'allowedBanners' => 'text',
  66. 'bool' => true
  67. )
  68. );
  69. // Webserver Local Banner Storage Settings
  70. $aElements += array(
  71. 'store_mode' => array('store' => 'mode'),
  72. 'store_webDir' => array('store' => 'webDir'),
  73. 'store_ftpHost' => array('store' => 'ftpHost'),
  74. 'store_ftpPath' => array('store' => 'ftpPath'),
  75. 'store_ftpUsername' => array('store' => 'ftpUsername'),
  76. 'store_ftpPassword' => array('store' => 'ftpPassword'),
  77. 'store_ftpPassive' => array(
  78. 'store' => 'ftpPassive',
  79. 'bool' => 'true'
  80. )
  81. );
  82. // Test the writablility of the web or FTP storage, if required
  83. phpAds_registerGlobal('store_webDir');
  84. if (isset($store_webDir)) {
  85. // Check that the web directory is writable
  86. if (is_writable($store_webDir)) {
  87. // If web store path has changed, copy the 1x1.gif to the
  88. // new location, else create it
  89. if ($conf['store']['webDir'] != $store_webDir) {
  90. if (file_exists($conf['store']['webDir'] .'/1x1.gif')) {
  91. copy($conf['store']['webDir'].'/1x1.gif', $store_webDir.'/1x1.gif');
  92. } else {
  93. $fp = fopen($store_webDir.'/1x1.gif', 'w');
  94. fwrite($fp, base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='));
  95. fclose($fp);
  96. }
  97. }
  98. } else {
  99. $aErrormessage[0][] = $strTypeDirError;
  100. }
  101. }
  102. phpAds_registerGlobal('store_ftpHost');
  103. if (isset($store_ftpHost)) {
  104. phpAds_registerGlobal('store_ftpUsername');
  105. phpAds_registerGlobal('store_ftpPassword');
  106. phpAds_registerGlobal('store_ftpPassive');
  107. phpAds_registerGlobal('store_ftpPath');
  108. // Check that PHP has support for FTP
  109. if (function_exists('ftp_connect')) {
  110. // Check that the FTP host can be contacted
  111. if ($ftpsock = @ftp_connect($store_ftpHost)) {
  112. // Check that the details to log into the FTP host are correct
  113. if (@ftp_login($ftpsock, $store_ftpUsername, $store_ftpPassword)) {
  114. if ($store_ftpPassive) {
  115. ftp_pasv($ftpsock, true);
  116. }
  117. //Check path to ensure there is not a leading slash
  118. if (($store_ftpPath != "") && (substr($store_ftpPath, 0, 1) == "/")) {
  119. $store_ftpPath = substr($store_ftpPath, 1);
  120. }
  121. if (empty($store_ftpPath) || @ftp_chdir($ftpsock, $store_ftpPath)) { // Changes path if store_ftpPath is not empty!
  122. // Save the 1x1.gif temporarily
  123. $filename = MAX_PATH . '/var/1x1.gif';
  124. $fp = @fopen($filename, 'w+');
  125. @fwrite($fp, base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='));
  126. // Upload to server
  127. if (!@ftp_put($ftpsock, '1x1.gif', MAX_PATH.'/var/1x1.gif', FTP_BINARY)){
  128. $aErrormessage[0][] = $strTypeFTPErrorUpload;
  129. }
  130. // Chmod file so that it's world readable
  131. if (function_exists('ftp_chmod') && !@ftp_chmod($ftpsock, 0644, '1x1.gif')) {
  132. OA::debug('Unable to modify FTP permissions for file: '. $store_ftpPath .'/1x1.gif', PEAR_LOG_INFO);
  133. }
  134. // Delete temp 1x1.gif file
  135. @fclose($fp);
  136. @ftp_close($ftpsock);
  137. unlink($filename);
  138. } else {
  139. $aErrormessage[0][] = $strTypeFTPErrorDir;
  140. }
  141. } else {
  142. $aErrormessage[0][] = $strTypeFTPErrorConnect;
  143. }
  144. @ftp_quit($ftpsock);
  145. } else {
  146. $aErrormessage[0][] = $strTypeFTPErrorHost;
  147. }
  148. } else {
  149. $aErrormessage[0][] = $strTypeFTPErrorNoSupport;
  150. }
  151. }
  152. if (empty($aErrormessage)) {
  153. // Create a new settings object, and save the settings!
  154. $oSettings = new OA_Admin_Settings();
  155. $result = $oSettings->processSettingsFromForm($aElements);
  156. if ($result) {
  157. // Queue confirmation message
  158. $setPref = $oOptions->getSettingsPreferences($prefSection);
  159. $title = $setPref[$prefSection]['name'];
  160. $translation = new OX_Translation ();
  161. $translated_message = $translation->translate($GLOBALS['strXSettingsHaveBeenUpdated'],
  162. array(htmlspecialchars($title)));
  163. OA_Admin_UI::queueMessage($translated_message, 'local', 'confirm', 0);
  164. // The settings configuration file was written correctly,
  165. // go to the "next" settings page from here
  166. OX_Admin_Redirect::redirect(basename($_SERVER['SCRIPT_NAME']));
  167. }
  168. // Could not write the settings configuration file, store this
  169. // error message and continue
  170. $aErrormessage[0][] = $strUnableToWriteConfig;
  171. }
  172. }
  173. // Set the correct section of the settings pages and display the drop-down menu
  174. $setPref = $oOptions->getSettingsPreferences($prefSection);
  175. $title = $setPref[$prefSection]['name'];
  176. // Display the settings page's header and sections
  177. $oHeaderModel = new OA_Admin_UI_Model_PageHeaderModel($title);
  178. phpAds_PageHeader('account-settings-index', $oHeaderModel);
  179. // Prepare an array of HTML elements to display for the form, and
  180. // output using the $oOption object
  181. $aSettings = array(
  182. array (
  183. 'text' => $strAllowedBannerTypes,
  184. 'items' => array (
  185. array (
  186. 'type' => 'checkbox',
  187. 'name' => 'allowedBanners_sql',
  188. 'text' => $strTypeSqlAllow
  189. ),
  190. array (
  191. 'type' => 'checkbox',
  192. 'name' => 'allowedBanners_web',
  193. 'text' => $strTypeWebAllow
  194. ),
  195. array (
  196. 'type' => 'checkbox',
  197. 'name' => 'allowedBanners_url',
  198. 'text' => $strTypeUrlAllow
  199. ),
  200. array (
  201. 'type' => 'checkbox',
  202. 'name' => 'allowedBanners_html',
  203. 'text' => $strTypeHtmlAllow
  204. ),
  205. array (
  206. 'type' => 'checkbox',
  207. 'name' => 'allowedBanners_text',
  208. 'text' => $strTypeTxtAllow
  209. )
  210. )
  211. ),
  212. array (
  213. 'text' => $strTypeWebSettings,
  214. 'items' => array (
  215. array (
  216. 'type' => 'select',
  217. 'name' => 'store_mode',
  218. 'text' => $strTypeWebMode,
  219. 'items' => array('local' => $strTypeWebModeLocal,
  220. 'ftp' => $strTypeWebModeFtp),
  221. 'depends' => 'allowedBanners_web==1',
  222. ),
  223. array (
  224. 'type' => 'break',
  225. 'size' => 'full'
  226. ),
  227. array (
  228. 'type' => 'text',
  229. 'name' => 'store_webDir',
  230. 'text' => $strTypeWebDir,
  231. 'size' => 35,
  232. 'depends' => 'allowedBanners_web==1 && store_mode==0'
  233. ),
  234. array (
  235. 'type' => 'break',
  236. 'size' => 'full'
  237. ),
  238. array (
  239. 'type' => 'text',
  240. 'name' => 'store_ftpHost',
  241. 'text' => $strTypeFTPHost,
  242. 'size' => 35,
  243. 'depends' => 'allowedBanners_web==1 && store_mode==1'
  244. ),
  245. array (
  246. 'type' => 'break'
  247. ),
  248. array (
  249. 'type' => 'text',
  250. 'name' => 'store_ftpPath',
  251. 'text' => $strTypeFTPDirectory,
  252. 'size' => 35,
  253. 'depends' => 'allowedBanners_web==1 && store_mode==1'
  254. ),
  255. array (
  256. 'type' => 'break'
  257. ),
  258. array (
  259. 'type' => 'text',
  260. 'name' => 'store_ftpUsername',
  261. 'text' => $strTypeFTPUsername,
  262. 'size' => 35,
  263. 'depends' => 'allowedBanners_web==1 && store_mode==1'
  264. ),
  265. array (
  266. 'type' => 'break'
  267. ),
  268. array (
  269. 'type' => 'password',
  270. 'name' => 'store_ftpPassword',
  271. 'text' => $strTypeFTPPassword,
  272. 'size' => 35,
  273. 'depends' => 'allowedBanners_web==1 && store_mode==1'
  274. ),
  275. array (
  276. 'type' => 'break'
  277. ),
  278. array (
  279. 'type' => 'checkbox',
  280. 'name' => 'store_ftpPassive',
  281. 'text' => $strTypeFTPPassive,
  282. 'depends' => 'allowedBanners_web==1 && store_mode==1'
  283. )
  284. )
  285. )
  286. );
  287. $oOptions->show($aSettings, $aErrormessage);
  288. // Display the page footer
  289. phpAds_PageFooter();
  290. ?>