/**
  * @access private
  * @return string
  */
 function _SavePage()
 {
     // Load the main-preferences file
     $this->_Preferences->Load('system/settings.php');
     // Load the preferences files of the modules (if there are some)
     // get the activated modules
     $modulesActivated = unserialize($this->_Config->Get('modules_activated'));
     // some data aviailable?
     if (is_array($modulesActivated)) {
         if (count($modulesActivated) >= 0) {
             foreach ($modulesActivated as $moduleName) {
                 $settingsFile = "modules/{$moduleName}/{$moduleName}_settings.php";
                 if (file_exists($settingsFile)) {
                     // Load the config file of this module
                     $this->_Preferences->Load($settingsFile);
                 }
             }
         }
     }
     if (count($this->_Preferences->Settings) <= 0) {
         return $this->GetPage('');
     }
     // Go through all preferences entries
     foreach ($this->_Preferences->Settings as $settings) {
         foreach ($settings as $setting) {
             $settingValue = GetPostOrGet('setting_' . $setting['name']);
             //TODO : value-type-check!!
             if (!empty($settingValue) || is_numeric($settingValue) && $settingValue == 0 || $setting['datatype'] == 'string0') {
                 $currentValue = $this->_Config->Get($setting['name']);
                 // Check if something has changed
                 if ($currentValue != $settingValue) {
                     // TODO: check the data before saving
                     $this->_Config->Save($setting['name'], $settingValue);
                 }
             }
         }
     }
     // Show the 'main-view'
     return $this->GetPage('');
 }
Example #2
0
 public function update_ipblacklist()
 {
     $db = Loader::db();
     if ($this->token->validate("update_ipblacklist")) {
         Loader::model('user_banned_ip');
         //configs from top part form
         $ip_ban_lock_ip_enable = 1 == $this->post('ip_ban_lock_ip_enable') ? 1 : 0;
         Config::save('IP_BAN_LOCK_IP_ENABLE', $ip_ban_lock_ip_enable);
         Config::save('IP_BAN_LOCK_IP_ATTEMPTS', $this->post('ip_ban_lock_ip_attempts'));
         Config::Save('IP_BAN_LOCK_IP_TIME', $this->post('ip_ban_lock_ip_time'));
         if (self::IP_BAN_LOCK_IP_HOW_LONG_TYPE_FOREVER != $this->post('ip_ban_lock_ip_how_long_type')) {
             Config::Save('IP_BAN_LOCK_IP_HOW_LONG_MIN', $this->post('ip_ban_lock_ip_how_long_min'));
         } else {
             Config::Save('IP_BAN_LOCK_IP_HOW_LONG_MIN', 0);
         }
         //ip table actions
         //use a single sql query, more efficient than active record
         $ip_ban_changes = $this->post('ip_ban_changes');
         if (count($ip_ban_changes) > 0) {
             $ip_ban_change_to = $this->post('ip_ban_change_to');
             $q = 'UPDATE UserBannedIPs SET expires = ? WHERE ';
             $v = array();
             switch ($ip_ban_change_to) {
                 case self::IP_BLACKLIST_CHANGE_MAKEPERM:
                     $v[] = 0;
                     //expires 0 is a perma-ban
                     break;
                 case self::IP_BLACKLIST_CHANGE_REMOVE:
                     $v[] = 1;
                     //expires 1 is really far in past, defacto expire
                     break;
             }
             $utility = new UserBannedIP();
             foreach ($ip_ban_changes as $key) {
                 $q .= '(ipFrom = ? AND ipTo = ?) OR';
                 $ids = $utility->parseUniqueID($key);
                 $v[] = $ids['ipFrom'];
                 $v[] = $ids['ipTo'];
             }
             $q = substr($q, 0, strlen($q) - 3);
             $db->execute($q, $v);
         }
         //textarea actions
         $ip_ranges = $this->parseIPBlacklistIntoRanges();
         $db = Loader::db();
         $db->StartTrans();
         $q = 'DELETE FROM UserBannedIPs WHERE isManual = 1';
         $db->execute($q);
         //no batch insert in adodb? :(
         foreach ($ip_ranges as $ip_range) {
             $ip = new UserBannedIP();
             $ip->ipFrom = ip2long($ip_range['ipFrom']);
             $ip->ipTo = $ip_range['ipTo'];
             if ($ip->ipTo != 0) {
                 echo $ip->ipTo . "\n";
                 $ip->ipTo = ip2long($ip_range['ipTo']);
             }
             $ip->banCode = UserBannedIP::IP_BAN_CODE_REGISTRATION_THROTTLE;
             $ip->expires = 0;
             $ip->isManual = 1;
             try {
                 $ip->save();
             } catch (Exception $e) {
                 //silently discard duplicates
             }
         }
         $db->CompleteTrans();
         $this->redirect('/dashboard/settings', 'set_permissions', 'saved_ipblacklist');
     } else {
         $this->set('error', array($this->token->getErrorMessage()));
     }
 }
Example #3
0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
define('TUBEX_CONTROL_PANEL', true);
require_once 'includes/cp-global.php';
if (Config::Get('db_username') !== null) {
    include_once 'install-already-installed.php';
} else {
    if (isset($_REQUEST['db_username'])) {
        if (DatabaseTest()) {
            $control_panel_url = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . "/index.php";
            $password = InitializeTables();
            Config::Save($_REQUEST);
            TemplateRecompileAll();
            include_once 'install-complete.php';
        }
    } else {
        if (PreTest()) {
            $_REQUEST['db_hostname'] = 'localhost';
            include_once 'install-main.php';
        }
    }
}
function PreTest()
{
    $errors = array();
    // Test template file permissions
    foreach (glob(TEMPLATES_DIR . '/*.*') as $filename) {
Example #4
0
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
if (!preg_match('~/admin$~', realpath(dirname(__FILE__)))) {
    echo "This file must be located in the admin directory of your TubeX installation";
    exit;
}
define('TUBEX_CONTROL_PANEL', true);
require_once 'includes/cp-global.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $DB = GetDB();
    $tables = GetDBTables();
    $reset = true;
    $settings = array('cookie_path' => '/', 'dec_point' => '.', 'thousands_sep' => ',', 'timezone' => 'America/Chicago', 'template' => 'Default-Blue-Rewrite', 'language' => 'en_US', 'video_extensions' => 'avi,mpg,mpeg,flv,f4v,rm,asf,wmv,mov,mp4,ts,m2t', 'video_size' => '512x384', 'video_bitrate' => '26', 'audio_bitrate' => '128', 'thumb_size' => '120x90', 'thumb_quality' => '90', 'thumb_amount' => '15', 'max_upload_size' => '50MB', 'max_upload_duration' => '00:20:00', 'flag_mod_rewrite' => '1', 'mailer' => 'mail', 'flag_user_confirm_email' => '0', 'date_format' => 'm-d-Y', 'time_format' => 'h:i:s', 'avatar_dimensions' => '200x200', 'avatar_filesize' => '100KB', 'avatar_extensions' => 'jpg,gif,png', 'flag_user_strip_tags' => '1', 'video_format' => '0', 'flag_allow_uploads' => '1', 'flag_upload_reject_duplicates' => '1', 'flag_upload_allow_private' => '1', 'flag_upload_convert' => '', 'flag_upload_review' => '', 'upload_extensions' => 'avi,mpg,mpeg,flv,f4v,rm,asf,wmv,mov,mp4,ts,m2t', 'title_min_length' => '10', 'title_max_length' => '100', 'description_min_length' => '10', 'description_max_length' => '500', 'tags_min' => '1', 'tags_max' => '10', 'flag_video_strip_tags' => '1', 'comment_max_length' => '500', 'comment_throttle_period' => '120', 'flag_comment_strip_tags' => '1', 'captcha_min_length' => '4', 'captcha_max_length' => '6', 'flag_captcha_words' => '1', 'flag_captcha_on_signup' => '1', 'flag_captcha_on_upload' => '0', 'flag_captcha_on_comment' => '1', 'cache_main' => '3600', 'cache_search' => '3600', 'cache_categories' => '3600', 'cache_browse' => '3600', 'cache_video' => '3600', 'cache_profile' => '3600', 'cache_comments' => '3600', 'cache_custom' => '3600');
    // Reset Config.php file
    Config::Save($settings, true);
    // Reset database.xml file
    $schema = GetDBSchema();
    $custom_tables = array(array('name' => 'tbx_user_custom', 'field' => 'username'), array('name' => 'tbx_video_custom', 'field' => 'video_id'), array('name' => 'tbx_category_custom', 'field' => 'category_id'), array('name' => 'tbx_sponsor_custom', 'field' => 'sponsor_id'));
    foreach ($custom_tables as $table) {
        $xtable = $schema->el('//table[name="' . $table['name'] . '"]');
        foreach ($xtable->xpath('./columns/column') as $xcolumn) {
            if ($xcolumn->name->val() != $table['field']) {
                XML_Schema::DeleteColumn($table['name'], $xcolumn->name->val());
            }
        }
    }
    // Remove all database tables
    foreach ($tables as $table) {
        $DB->Update('DROP TABLE IF EXISTS #', array($table));
    }
Example #5
0
function tbxGlobalSettingsSave()
{
    Privileges::CheckSuper();
    $si = ServerInfo::GetCached();
    $required = array('site_name' => 'Site Name', 'meta_description' => 'Meta Description', 'meta_keywords' => 'Meta Keywords', 'document_root' => 'Document Root', 'base_url' => 'TubeX URL', 'cookie_domain' => 'Cookie Domain', 'cookie_path' => 'Cookie Path', 'email_address' => 'E-mail Address', 'email_name' => 'E-mail Name', 'date_format' => 'Date Format', 'time_format' => 'Time Format', 'dec_point' => 'Decimal Point', 'thousands_sep' => 'Thousands Separator', 'video_extensions' => 'File Extensions');
    switch (Request::Get('mailer')) {
        case Mailer::SMTP:
            $required['smtp_hostname'] = 'SMTP Hostname';
            $required['smtp_port'] = 'SMTP Port';
            break;
        case Mailer::SENDMAIL:
            $required['sendmail_path'] = 'Sendmail Path';
            break;
    }
    $v = Validator::Get();
    foreach ($required as $field => $label) {
        $v->Register(Request::Get($field), Validator_Type::NOT_EMPTY, 'The ' . $label . ' field is required');
    }
    if (!$v->Validate()) {
        $output['message'] = 'Settings could not be saved; please fix the following items';
        $output['errors'] = $v->GetErrors();
        return JSON::Failure($output);
    }
    unset($_REQUEST['r']);
    // Setup mcf file for VP6 encoding
    if ($_REQUEST['video_format'] == Video_Converter::FORMAT_VP6 && preg_match('~^[0-9]+$~', $_REQUEST['video_bitrate'])) {
        $fp = fopen(INCLUDES_DIR . '/vp6.mcf', 'r+');
        fseek($fp, 0x14);
        fwrite($fp, pack('s', $_REQUEST['video_bitrate']));
        fclose($fp);
    }
    $_REQUEST['max_upload_size'] = Format::BytesToString(min(Format::StringToBytes($si->php_settings[ServerInfo::PHP_UPLOAD_MAX_FILESIZE]), Format::StringToBytes($_REQUEST['max_upload_size'])));
    $_REQUEST['document_root'] = Dir::StripTrailingSlash($_REQUEST['document_root']);
    $_REQUEST['base_url'] = Dir::StripTrailingSlash($_REQUEST['base_url']);
    $_REQUEST['base_uri'] = parse_url($_REQUEST['base_url'], PHP_URL_PATH);
    $_REQUEST['template_uri'] = $_REQUEST['base_uri'] . '/templates/' . $_REQUEST['template'];
    if (Config::Get('template') != $_REQUEST['template']) {
        tbxTemplateCacheFlush(true);
        TemplateRecompileAll(BASE_DIR . '/templates/' . $_REQUEST['template']);
    }
    ServerInfo::Get(true);
    Config::Save($_REQUEST);
    JSON::Success('Global software settings have been saved');
}
Example #6
0
function processUpgradeDB()
{
    // Update Scheme to Include EF & AF Booster Pack Info
    $cfg = new Config();
    // Store New/Changed config items
    showLog("Saving Config...");
    foreach ($_POST as $item => $val) {
        $key = explode('__', $item);
        if ($key[0] == 'cfg') {
            showLog(" -> Found Key: '{$key[1]}' => '" . (is_array($cfg->get($key[1])) ? str_replace("\r\n", ",", $val) : $val) . "' (Old: " . (is_array($cfg->get($key[1])) ? implode(',', $cfg->get($key[1])) : $cfg->get($key[1])) . ")...");
            $cfg->set($key[1], $val);
        }
    }
    $cfg->Save();
    // Get DB Version
    $curdbver = verCmp(getDbVer());
    // Open Database connection
    $connection = @mysql_connect($cfg->get('db_host'), $cfg->get('db_user'), $cfg->get('db_pass'));
    @mysql_select_db($cfg->get('db_name'), $connection) or die("Database Error: " . mysql_error());
    // Upgrade Schema
    require 'includes/db/sql.dbupgrade.php';
    showLog("Upgrading Database Schema");
    foreach ($sqlupgrade as $query) {
        if ($curdbver < verCmp($query[1])) {
            if (mysql_query($query[2])) {
                showLog(" -> " . $query[0] . " Success");
            } else {
                showLog(" -> <font color='red'>ERROR:</font> " . $query[0] . " *FAILED*: " . mysql_error());
            }
        } else {
            showLog(" -> <font color='blue'>Skipping:</font> " . $query[0]);
        }
    }
    // Close database connection
    @mysql_close($connection);
    showLog("Done! :)");
}