/** * Implementation of hook_init. */ function ft_fileinfo_init() { // Check if DB plugin is loaded. if (!ft_plugin_exists('db')) { ft_set_message(t('!name plugin not enabled because required !required plugin was not found.', array('!name' => 'Fileinfo', '!required' => 'db')), 'error'); ft_plugin_unload('fileinfo'); } else { // Check if we need to create new table. $sql = "CREATE TABLE fileinfo (\n dir TEXT NOT NULL,\n file TEXT NOT NULL,\n description TEXT\n )"; ft_db_install_table('fileinfo', $sql); } }
/** * Load external configuration file. * * @param $file * Path to external file to load. * @return Array of settings, users, groups and plugins. */ function ft_settings_external($file) { if (file_exists($file)) { @(include_once $file); $json = ft_settings_external_load(); if (!$json) { // Not translateable. Language info is not available yet. ft_set_message('Could not load external configuration.', 'error'); return FALSE; } return $json; } return FALSE; }
/** * Implementation of hook_action. */ function ft_edit_action($act) { global $ft; if ($act == 'savefile') { $file = trim(ft_stripslashes($_REQUEST["file"])); if (ft_check_fileactions() === TRUE) { // Save a file that has been edited. // Delete any locks on this file. ft_edit_lock_clear($file, ft_get_dir()); // Check for edit or cancel if (strtolower($_REQUEST["submit"]) != strtolower(t("Cancel"))) { // Check if file type can be edited. if (ft_check_dir(ft_get_dir()) && ft_check_edit($file) && ft_check_fileactions() === TRUE && ft_check_filetype($file) && ft_check_filetype($file)) { $filecontent = ft_stripslashes($_REQUEST["filecontent"]); if ($_REQUEST["convertspaces"] != "") { $filecontent = str_replace(" ", "\t", $filecontent); } if (is_writeable(ft_get_dir() . "/{$file}")) { $fp = @fopen(ft_get_dir() . "/{$file}", "wb"); if ($fp) { fputs($fp, $filecontent); fclose($fp); ft_set_message(t("!old was saved.", array('!old' => $file))); ft_redirect("dir={$_REQUEST['dir']}"); } else { ft_set_message(t("!old could not be edited.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } else { ft_set_message(t("!old could not be edited.", array('!old' => $file)), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } else { ft_set_message(t("Could not edit file. This file type is not editable."), 'error'); ft_redirect("dir={$_REQUEST['dir']}"); } } else { ft_redirect("dir=" . rawurlencode($_REQUEST['dir'])); } } } }
/** * Implementation of hook_action. */ function ft_db_action($act) { global $ft; // Delete a database table. if ($act == 'db_delete_submit' && isset($ft['plugins']['db']['settings']['flushtables']) && $ft['plugins']['db']['settings']['flushtables'] === TRUE) { // Check for cancel. if (strtolower($_REQUEST["ft_submit"]) == strtolower(t("Cancel"))) { ft_redirect("act=db"); } // Check if table exists. $display_value = htmlentities($_POST['value']); if (is_array($ft['db']) && is_array($ft['db']['tables']) && count($ft['db']['tables']) > 0) { // Drop table. $result = $ft['db']['link']->query('DROP TABLE ' . $ft['db']['link']->quote($_POST['value'])); if ($result) { ft_set_message(t('Database table !table dropped.', array('!table' => $display_value))); } else { ft_set_message(t("Database table !table could not be dropped.", array('!table' => $display_value)), 'error'); } } else { ft_set_message(t("Database table !table could not be removed because it doesn't exists.", array('!table' => $display_value)), 'error'); } // Redirect. ft_redirect("act=db"); } }
/** * Implementation of hook_action. */ function ft_log_action($act) { global $ft; // Prune old records. if ($act == 'log_prune' && isset($ft['plugins']['log']['settings']['viewlogs']) && $ft['plugins']['log']['settings']['viewlogs'] === TRUE) { $offset = date('Y-m-d', strtotime('-7 months', gmmktime())); $sql = "DELETE FROM log WHERE timestamp <= '" . $ft['db']['link']->quote($offset) . "'"; $result = $ft['db']['link']->query($sql); ft_set_message(t('Log pruned')); // Redirect. ft_redirect("act=log"); } // View CSV log. if ($act == 'log_csv' && isset($ft['plugins']['log']['settings']['viewlogs']) && $ft['plugins']['log']['settings']['viewlogs'] === TRUE) { header('Content-type: text/plain;charset=UTF-8'); $headers = array(t('Type'), t('Message'), t('Location'), t('Timestamp'), t('User')); $items = ft_log_do_query($_GET['type'], $_GET['from_day'], $_GET['from'], $_GET['to_day'], $_GET['to']); print str_putcsv($headers, ';') . "\n"; foreach ($items as $row) { print str_putcsv($row, ';') . "\n"; } exit; } }
/** * Implementation of hook_action. */ function ft_config_action($act) { global $ft; // Change the default settings and plugins. if ($act == 'config_default_submit') { // Check for cancel. if (strtolower($_REQUEST["ft_submit"]) == strtolower(t("Cancel"))) { ft_redirect("act=config"); } // Loop through settings. $ext = ft_settings_external_load(); foreach ($ft['default_settings'] as $k => $v) { if (isset($_POST['setting_setting'][$k])) { if ($_POST['setting_setting'][$k] == 'TRUE') { $ext['settings'][$k] = TRUE; } elseif ($_POST['setting_setting'][$k] == 'FALSE') { $ext['settings'][$k] = FALSE; } elseif (($k == 'UPLOAD' || $k == 'FILEACTIONS') && $_POST['setting_setting'][$k] == 'OTHER') { // UPLOAD and FILEACTIONS can have an 'other' value. if (empty($_POST['setting_other_setting'][$k])) { // If the other value is empty, turn off the setting. $ext['settings'][$k] = FALSE; } else { $ext['settings'][$k] = ft_settings_external_clean($_POST['setting_other_setting'][$k]); } } else { $ext['settings'][$k] = ft_settings_external_clean($_POST['setting_setting'][$k]); } } } // Loop through plugins. Reset existing plugins. $ext['plugins'] = array(); foreach ($_POST['plugins'] as $plugin_name => $plugin_status) { if ($plugin_status != '') { // Plugin enabled. $ext['plugins'][$plugin_name] = TRUE; // Check if there are settings attached to this plugin. if (isset($_POST['setting_plugins']) && is_array($_POST['setting_plugins']) && isset($_POST['setting_plugins'][$plugin_name])) { $ext['plugins'][$plugin_name] = array(); $ext['plugins'][$plugin_name]['settings'] = array(); foreach ($_POST['setting_plugins'][$plugin_name] as $plugin_setting_name => $plugin_setting_value) { if ($plugin_setting_value == 'TRUE') { $ext['plugins'][$plugin_name]['settings'][$plugin_setting_name] = TRUE; } elseif ($plugin_setting_value == 'FALSE') { $ext['plugins'][$plugin_name]['settings'][$plugin_setting_name] = FALSE; } else { $ext['plugins'][$plugin_name]['settings'][$plugin_setting_name] = ft_settings_external_clean($plugin_setting_value); } } } } } // Save new settings. if (function_exists('ft_settings_external_load') && function_exists('ft_settings_external_save')) { // Save. if (ft_settings_external_save($ext)) { ft_set_message(t("Settings saved."), 'ok'); } else { ft_set_message(t("Settings could not be saved. Config file could not be updated."), 'error'); } } else { ft_set_message(t("External config file not found."), 'error'); ft_redirect("act=config_default"); } ft_redirect("act=config"); // Add new group or edit group. } elseif ($act == 'user_add_submit_group' || $act == 'user_edit_submit_group') { // Check for cancel. if (strtolower($_REQUEST["ft_submit"]) == strtolower(t("Cancel"))) { ft_redirect("act=config"); } $group = array(); $group_name = (string) $_POST['user_group']; $group_name = ft_settings_external_clean($group_name); $group_old = ''; if ($act == 'user_edit_submit_group') { $group_old = (string) $_POST['group_old']; $group_old = ft_settings_external_clean($group_old); } // Loop through defaults. if (!empty($_POST['setting_default']) && is_array($_POST['setting_default'])) { foreach ($_POST['setting_default'] as $setting => $v) { // Differs from default. Add setting. if ($v != '') { if ($_POST['setting_setting'][$setting] == 'TRUE') { $group[$setting] = TRUE; } elseif ($_POST['setting_setting'][$setting] == 'FALSE') { $group[$setting] = FALSE; } elseif (($setting == 'UPLOAD' || $setting == 'FILEACTIONS') && $_POST['setting_setting'][$setting] == 'OTHER') { // UPLOAD and FILEACTIONS can have an 'other' value. if (empty($_POST['setting_other_setting'][$setting])) { // If the other value is empty, turn off the setting. $group[$setting] = FALSE; } else { $group[$setting] = ft_settings_external_clean($_POST['setting_other_setting'][$setting]); } } else { $group[$setting] = ft_settings_external_clean($_POST['setting_setting'][$setting]); } } } } // Loop through group plugins. if (!empty($_POST['plugins']) && is_array($_POST['plugins'])) { $group['plugins'] = array(); foreach ($_POST['plugins'] as $plugin_name => $plugin_status) { if ($plugin_status != '') { // Plugin enabled. Add to group. $group['plugins'][$plugin_name] = TRUE; // Check if there are settings attached to this plugin. if (isset($_POST['setting_plugins']) && is_array($_POST['setting_plugins']) && isset($_POST['setting_plugins'][$plugin_name])) { // $group['plugins'][$plugin_name] = array('test', 'test2'); $group['plugins'][$plugin_name] = array(); $group['plugins'][$plugin_name]['settings'] = array(); foreach ($_POST['setting_plugins'][$plugin_name] as $plugin_setting_name => $plugin_setting_value) { if ($plugin_setting_value == 'TRUE') { $group['plugins'][$plugin_name]['settings'][$plugin_setting_name] = TRUE; } elseif ($plugin_setting_value == 'FALSE') { $group['plugins'][$plugin_name]['settings'][$plugin_setting_name] = FALSE; } else { $group['plugins'][$plugin_name]['settings'][$plugin_setting_name] = ft_settings_external_clean($plugin_setting_value); } } } } } } // Make sure group name is not in use or that we're editing without changing name. if (!isset($ft['groups'][$group_name]) || $act == 'user_edit_submit_group' && $group_name == $group_old) { // New group okay. if (function_exists('ft_settings_external_load') && function_exists('ft_settings_external_save')) { $ext = ft_settings_external_load(); if (!isset($ext['groups'])) { $ext['groups'] = array(); } // Splice in new/updated user. $ext['groups'][$group_name] = $group; // Save. if (ft_settings_external_save($ext)) { ft_set_message(t("!group was added/updated.", array('!group' => $group_name)), 'ok'); } else { ft_set_message(t("Group could not be added/updated. Config file could not be updated."), 'error'); } } else { ft_set_message(t("External config file not found."), 'error'); ft_redirect("act=user_add_group"); } } else { // New group name already in use. ft_set_message(t("Group could not be added. Name already in use."), 'error'); ft_redirect("act=user_add_group"); } ft_redirect("act=config"); } elseif ($act == 'user_add_submit' || $act == 'user_edit_submit') { // Adding new user or editing user. // Check for cancel. if (strtolower($_REQUEST["ft_submit"]) == strtolower(t("Cancel"))) { ft_redirect("act=config"); } $user = (string) $_POST['user_user']; $user_old = ''; if (!empty($_POST['user_old'])) { $user_old = (string) $_POST['user_old']; } $pass = (string) $_POST['user_pass']; $pass2 = (string) $_POST['user_pass2']; $group = (string) $_POST['user_group']; // Make sure passwords match. if ($pass == $pass2) { // Strip tags and other nasty characters. $user = ft_settings_external_clean($user); $user_old = ft_settings_external_clean($user_old); $pass = ft_settings_external_clean($pass); $group = ft_settings_external_clean($group); // Make sure there are no empty strings. if (strlen($user) > 0 && (strlen($pass) > 0 || $act == 'user_edit_submit')) { // Check that user doesn't already exists. Or that we're editing a user. if (!ft_check_user($user) || $act == 'user_edit_submit' && $user == $user_old) { // Make new user. $new = array(); $new['password'] = $pass; if (!empty($group) && isset($ft['groups']) && isset($ft['groups'][$group])) { $new['group'] = $group; } // If we're editing and the password is blank load existing password. if ($act == 'user_edit_submit' && empty($pass)) { $new['password'] = $ft['users'][$user_old]['password']; } if (function_exists('ft_settings_external_load') && function_exists('ft_settings_external_save')) { $ext = ft_settings_external_load(); // Splice in new/updated user. $ext['users'][$user] = $new; // Remove old user. if ($act == 'user_edit_submit' && $user != $user_old) { unset($ext['users'][$user_old]); } // Save. if (ft_settings_external_save($ext)) { ft_set_message(t("!user was added/updated.", array('!user' => $user)), 'ok'); } else { ft_set_message(t("User could not be added/updated. Config file could not be updated."), 'error'); } } else { ft_set_message(t("External config file not found."), 'error'); } } else { ft_set_message(t("User could not be added. Username already in use."), 'error'); } } else { ft_set_message(t("You must enter both a username and a password."), 'error'); } } else { ft_set_message(t("Passwords didn't match."), 'error'); } ft_redirect("act=config"); } elseif ($act == 'user_delete_submit') { // Check for cancel. if (strtolower($_REQUEST["ft_submit"]) == strtolower(t("Cancel"))) { ft_redirect("act=config"); } $ext = ft_settings_external_load(); if ($_POST['type'] == 'user') { $msg = t("User was deleted."); // Remove user. unset($ext['users'][$_POST['value']]); } elseif ($_POST['type'] == 'group') { $msg = t("Group was deleted."); // Remove group. unset($ext['groups'][$_POST['value']]); // Loop through users and remove. foreach ($ext['users'] as $user => $v) { if ($v['group'] == $_POST['value']) { unset($ext['users'][$user]); } } } // Save config file. if (ft_settings_external_save($ext)) { ft_set_message($msg); } else { ft_set_message(t("Config file could not be updated."), 'error'); } ft_redirect("act=config"); } }