PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/installation/modules/configuration.php

http://acp3.googlecode.com/
PHP | 237 lines | 212 code | 19 blank | 6 comment | 60 complexity | 27cfddf9832730f9052e61614dfced22 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, GPL-2.0
  1. <?php
  2. if (defined('IN_INSTALL') === false)
  3. exit;
  4. if (isset($_POST['submit'])) {
  5. $config_path = ACP3_ROOT . 'includes/config.php';
  6. $db = new ACP3_DB();
  7. if (empty($_POST['db_host']))
  8. $errors[] = $lang->t('installation', 'type_in_db_host');
  9. if (empty($_POST['db_user']))
  10. $errors[] = $lang->t('installation', 'type_in_db_username');
  11. if (empty($_POST['db_name']))
  12. $errors[] = $lang->t('installation', 'type_in_db_name');
  13. if (!empty($_POST['db_host']) && !empty($_POST['db_user']) && !empty($_POST['db_name']) &&
  14. $db->connect($_POST['db_host'], $_POST['db_name'], $_POST['db_user'], $_POST['db_password']) !== true)
  15. $errors[] = $lang->t('installation', 'db_connection_failed');
  16. if (empty($_POST['user_name']))
  17. $errors[] = $lang->t('installation', 'type_in_user_name');
  18. if ((empty($_POST['user_pwd']) || empty($_POST['user_pwd_wdh'])) ||
  19. (!empty($_POST['user_pwd']) && !empty($_POST['user_pwd_wdh']) && $_POST['user_pwd'] != $_POST['user_pwd_wdh']))
  20. $errors[] = $lang->t('installation', 'type_in_pwd');
  21. if (ACP3_Validate::email($_POST['mail']) === false)
  22. $errors[] = $lang->t('common', 'wrong_email_format');
  23. if (ACP3_Validate::isNumber($_POST['entries']) === false)
  24. $errors[] = $lang->t('common', 'select_records_per_page');
  25. if (ACP3_Validate::isNumber($_POST['flood']) === false)
  26. $errors[] = $lang->t('system', 'type_in_flood_barrier');
  27. if (empty($_POST['date_format_long']) || empty($_POST['date_format_short']))
  28. $errors[] = $lang->t('system', 'type_in_date_format');
  29. if (ACP3_Validate::timeZone($_POST['date_time_zone']) === false)
  30. $errors[] = $lang->t('common', 'select_time_zone');
  31. if (is_file($config_path) === false || is_writable($config_path) === false)
  32. $errors[] = $lang->t('installation', 'wrong_chmod_for_config_file');
  33. if (isset($errors)) {
  34. $tpl->assign('errors', $errors);
  35. $tpl->assign('error_msg', $tpl->fetch('error_box.tpl'));
  36. } else {
  37. // Systemkonfiguration erstellen
  38. $config = array(
  39. 'cache_images' => true,
  40. 'cache_minify' => 3600,
  41. 'date_format_long' => $_POST['date_format_long'],
  42. 'date_format_short' => $_POST['date_format_short'],
  43. 'date_time_zone' => $_POST['date_time_zone'],
  44. 'db_host' => $_POST['db_host'],
  45. 'db_name' => $_POST['db_name'],
  46. 'db_pre' => $_POST['db_pre'],
  47. 'db_password' => $_POST['db_password'],
  48. 'db_user' => $_POST['db_user'],
  49. 'db_version' => 21,
  50. 'design' => 'acp3',
  51. 'entries' => $_POST['entries'],
  52. 'flood' => $_POST['flood'],
  53. 'homepage' => 'news/list/',
  54. 'lang' => LANG,
  55. 'mailer_smtp_auth' => false,
  56. 'mailer_smtp_host' => '',
  57. 'mailer_smtp_password' => '',
  58. 'mailer_smtp_port' => 25,
  59. 'mailer_smtp_security' => '',
  60. 'mailer_smtp_user' => '',
  61. 'mailer_type' => 'mail',
  62. 'maintenance_mode' => false,
  63. 'maintenance_message' => $lang->t('installation', 'offline_message'),
  64. 'seo_aliases' => true,
  65. 'seo_meta_description' => '',
  66. 'seo_meta_keywords' => '',
  67. 'seo_mod_rewrite' => false,
  68. 'seo_robots' => 1,
  69. 'seo_title' => !empty($_POST['seo_title']) ? $_POST['seo_title'] : 'ACP3',
  70. 'version' => CONFIG_VERSION,
  71. 'wysiwyg' => 'ckeditor'
  72. );
  73. // Daten in die config.php schreiben und diese laden
  74. writeConfigFile($config);
  75. $db = new ACP3_DB();
  76. $db->connect($_POST['db_host'], $_POST['db_name'], $_POST['db_user'], $_POST['db_password'], $_POST['db_pre']);
  77. $sql_file = file_get_contents(ACP3_ROOT . 'installation/modules/install.sql');
  78. $sql_file = str_replace(array("\r\n", "\r"), "\n", $sql_file);
  79. $sql_file = str_replace('{engine}', 'ENGINE=MyISAM CHARACTER SET `utf8` COLLATE `utf8_general_ci`', $sql_file);
  80. $sql_file_arr = explode(";\n", $sql_file);
  81. $salt = salt(12);
  82. $current_date = gmdate('U');
  83. $other_arr = array(
  84. 1 => 'INSERT INTO `{pre}users` VALUES (\'\', 1, \'' . $db->escape($_POST['user_name']) . '\', \'' . generateSaltedPassword($salt, $_POST['user_pwd']) . ':' . $salt . '\', \'0\', \':1\', \'1:1\', \':1\', \'1\', \'' . $_POST['mail'] . ':1\', \':1\', \':1\', \':1\', \':1\', \'' . $db->escape($_POST['date_format_long']) . '\', \'' . $db->escape($_POST['date_format_short']) . '\', \'' . $_POST['date_time_zone'] . '\', \'' . $_POST['date_dst'] .'\', \'' . LANG . '\', \'' . $_POST['entries'] . '\', \'\')',
  85. 2 => 'INSERT INTO `{pre}news` VALUES (\'\', \'' . $current_date . '\', \'' . $current_date . '\', \'' . $lang->t('installation', 'news_headline') . '\', \'' . $lang->t('installation', 'news_text') . '\', \'1\', \'1\', \'1\', \'\', \'\', \'\', \'\')',
  86. 3 => 'INSERT INTO `{pre}menu_items` VALUES (\'\', 1, 1, 1, 0, 1, 2, 1, \'' . $lang->t('installation', 'pages_news') . '\', \'news\', 1), (\'\', 1, 1, 2, 0, 3, 4, 1, \'' . $lang->t('installation', 'pages_files') . '\', \'files\', 1), (\'\', 1, 1, 3, 0, 5, 6, 1, \'' . $lang->t('installation', 'pages_gallery') . '\', \'gallery\', 1), (\'\', 1, 1, 4, 0, 7, 8, 1, \'' . $lang->t('installation', 'pages_guestbook') . '\', \'guestbook\', 1), (\'\', 1, 1, 5, 0, 9, 10, 1, \'' . $lang->t('installation', 'pages_polls') . '\', \'polls\', 1), (\'\', 1, 1, 6, 0, 11, 12, 1, \'' . $lang->t('installation', 'pages_search') . '\', \'search\', 1), (\'\', 1, 2, 7, 0, 13, 14, 1, \'' . $lang->t('installation', 'pages_contact') . '\', \'contact\', 1), (\'\', 2, 2, 8, 0, 15, 16, 1, \'' . $lang->t('installation', 'pages_imprint') . '\', \'contact/imprint/\', 1)',
  87. 4 => 'INSERT INTO `{pre}menu_items_blocks` (`id`, `index_name`, `title`) VALUES (1, \'main\', \'' . $lang->t('installation', 'pages_main') . '\'), (2, \'sidebar\', \'' . $lang->t('installation', 'pages_sidebar') . '\')',
  88. 5 => 'INSERT INTO `{pre}seo` VALUES (\'news/details/id_1/\', \'' . $lang->t('installation', 'news_headline_alias') . '\', \'\', \'\', \'1\')',
  89. 6 => 'INSERT INTO `{pre}seo` VALUES (\'contact/imprint/\', \'' . $lang->t('installation', 'pages_imprint_alias') . '\', \'\', \'\', \'1\')',
  90. );
  91. $queries = array_merge($sql_file_arr, $other_arr);
  92. $data = NULL;
  93. $i = 0;
  94. foreach ($queries as $query) {
  95. if (!empty($query)) {
  96. $query.= ';';
  97. $data[$i]['query'] = htmlentities($query, ENT_QUOTES, 'UTF-8');
  98. $bool = $db->query($query, 3);
  99. $data[$i]['color'] = $bool !== false ? '090' : 'f00';
  100. $data[$i]['result'] = $bool !== false ? $lang->t('system', 'query_successfully_executed') : $lang->t('system', 'query_failed');
  101. ++$i;
  102. if ($bool === false) {
  103. $tpl->assign('install_error', true);
  104. break;
  105. }
  106. }
  107. }
  108. $tpl->assign('sql_queries', $data);
  109. $special_resources = array(
  110. 'comments' => array(
  111. 'create' => 2,
  112. ),
  113. 'gallery' => array(
  114. 'add_picture' => 4,
  115. ),
  116. 'guestbook' => array(
  117. 'create' => 2,
  118. ),
  119. 'newsletter' => array(
  120. 'compose' => 4,
  121. 'create' => 2,
  122. 'adm_activate' => 3,
  123. 'sent' => 4,
  124. ),
  125. 'system' => array(
  126. 'configuration' => 7,
  127. 'designs' => 7,
  128. 'extensions' => 7,
  129. 'languages' => 7,
  130. 'maintenance' => 7,
  131. 'modules' => 7,
  132. 'sql_export' => 7,
  133. 'sql_import' => 7,
  134. 'sql_optimisation' => 7,
  135. 'update_check' => 3,
  136. ),
  137. 'users' => array(
  138. 'edit_profile' => 1,
  139. 'edit_settings' => 1,
  140. ),
  141. );
  142. // Moduldaten in die ACL schreiben
  143. $modules = scandir(MODULES_DIR);
  144. foreach ($modules as $row) {
  145. if ($row !== '.' && $row !== '..' && is_dir(MODULES_DIR . $row . '/') === true) {
  146. $module = scandir(MODULES_DIR . $row . '/');
  147. $mod_id = $db->select('id', 'modules', 'name = \'' . $row . '\'');
  148. if (is_file(MODULES_DIR . $row . '/extensions/search.php') === true)
  149. $db->insert('acl_resources', array('id' => '', 'module_id' => $mod_id[0]['id'], 'page' => 'extensions/search', 'params' => '', 'privilege_id' => 1));
  150. if (is_file(MODULES_DIR . $row . '/extensions/feeds.php') === true)
  151. $db->insert('acl_resources', array('id' => '', 'module_id' => $mod_id[0]['id'], 'page' => 'extensions/feeds', 'params' => '', 'privilege_id' => 1));
  152. foreach ($module as $file) {
  153. if ($file !== '.' && $file !== '..' && is_file(MODULES_DIR . $row . '/' . $file) === true && strpos($file, '.php') !== false) {
  154. $file = substr($file, 0, -4);
  155. if (isset($special_resources[$row][$file])) {
  156. $privilege_id = $special_resources[$row][$file];
  157. } else {
  158. $privilege_id = 1;
  159. if (strpos($file, 'adm_list') === 0)
  160. $privilege_id = 3;
  161. if (strpos($file, 'create') === 0 || strpos($file, 'order') === 0)
  162. $privilege_id = 4;
  163. if (strpos($file, 'edit') === 0)
  164. $privilege_id = 5;
  165. if (strpos($file, 'delete') === 0)
  166. $privilege_id = 6;
  167. if (strpos($file, 'settings') === 0)
  168. $privilege_id = 7;
  169. }
  170. $db->insert('acl_resources', array('id' => '', 'module_id' => $mod_id[0]['id'], 'page' => $file, 'params' => '', 'privilege_id' => $privilege_id));
  171. }
  172. }
  173. }
  174. }
  175. $roles = $db->select('id', 'acl_roles');
  176. $modules = $db->select('id', 'modules');
  177. $privileges = $db->select('id', 'acl_privileges');
  178. foreach ($roles as $role) {
  179. foreach ($modules as $module) {
  180. foreach ($privileges as $privilege) {
  181. $permission = 0;
  182. if ($role['id'] == 1 && ($privilege['id'] == 1 || $privilege['id'] == 2))
  183. $permission = 1;
  184. if ($role['id'] > 1 && $role['id'] < 4)
  185. $permission = 2;
  186. if ($role['id'] == 3 && $privilege['id'] == 3)
  187. $permission = 1;
  188. if ($role['id'] == 4)
  189. $permission = 1;
  190. $db->insert('acl_rules', array('id' => '', 'role_id' => $role['id'], 'module_id' => $module['id'], 'privilege_id' => $privilege['id'], 'permission' => $permission));
  191. }
  192. }
  193. }
  194. // Modulkonfigurationsdateien schreiben
  195. ACP3_Config::module('contact', array('mail' => $_POST['mail'], 'disclaimer' => $db->escape($lang->t('installation', 'disclaimer'), 2)));
  196. ACP3_Config::module('newsletter', array('mail' => $_POST['mail'], 'mailsig' => $db->escape($lang->t('installation', 'sincerely') . "\n\n" . $lang->t('installation', 'newsletter_mailsig'))));
  197. }
  198. }
  199. if (isset($_POST['submit']) === false || isset($errors) === true && is_array($errors) === true) {
  200. // Eintr?ge pro Seite
  201. $tpl->assign('entries', recordsPerPage(20));
  202. // Zeitzonen
  203. $tpl->assign('time_zones', getTimeZones(date_default_timezone_get()));
  204. $defaults = array(
  205. 'db_host' => 'localhost',
  206. 'db_pre' => 'acp3_',
  207. 'db_user' => '',
  208. 'db_name' => '',
  209. 'user_name' => 'admin',
  210. 'mail' => '',
  211. 'flood' => '30',
  212. 'date_format_long' => 'd.m.y, H:i',
  213. 'date_format_short' => 'd.m.y',
  214. 'seo_title' => 'ACP3',
  215. );
  216. $tpl->assign('form', isset($_POST['submit']) ? $_POST : $defaults);
  217. }
  218. $content = $tpl->fetch('configuration.tpl');