$id_new = pj_input(pj_POST('newid'));
 // Check ID syntax
 if (preg_match('/[^0-9a-zA-Z_\\-\\.]/', $id_new)) {
     $error_buffer['id'] = 'Invalid link ID. Leave it empty or use only these chars: a-z A-Z 0-9 _ - .';
 } elseif (strlen($id_new) > 0 && $id_new != $id_old) {
     // A duplicate ID?
     if (isset($ccount_database[$id_new])) {
         $error_buffer['id'] = 'Link with this ID already exists! Each link requires a unique ID (leave empty to use current one).';
     } else {
         $warn_new_link = true;
     }
 }
 // Total clicks
 $ccount_database[$id_old]['C'] = intval(pj_POST('total', 0));
 // Unique clicks
 $ccount_database[$id_old]['U'] = intval(pj_POST('unique', 0));
 // If no errors, save changes
 if (count($error_buffer) == 0) {
     // Replace ID?
     if ($warn_new_link) {
         $ccount_database = pj_array_key_replace($ccount_database, $id_old, $id_new);
     }
     // Update database file
     if (@file_put_contents($ccount_settings['db_file'], "<?php die();//" . serialize($ccount_database), LOCK_EX) === false) {
         $_SESSION['PJ_MESSAGES']['ERROR'] = 'Error writing to database file, please try again later.';
     } else {
         $_SESSION['PJ_MESSAGES']['SUCCESS'] = 'Link changes saved.';
         if ($warn_new_link) {
             $_SESSION['PJ_MESSAGES']['WARNING'] = 'Link ID has changed to: <b>' . $id_new . '</b><br /><br />' . '<b>Make sure you update your tracking link to use the new ID:</b><br />' . '<input value="' . $ccount_settings['click_url'] . '?id=' . $id_new . '" class="form-control" />';
         }
         header('Location: admin.php');
function pj_REQUEST($in, $default = false)
{
    return isset($_GET[$in]) ? pj_input(pj_GET($in)) : (isset($_POST[$in]) ? pj_input(pj_POST($in)) : $default);
}
    $ccount_settings['admin_pass'] = pj_input(pj_POST('admin_pass')) or $error_buffer['admin_pass'] = '******';
    // click.php URL
    $ccount_settings['click_url'] = pj_validateURL(pj_POST('click_url')) or $error_buffer['click_url'] = 'Enter a valid URL address of the click.php file on your server.';
    // Database file
    $ccount_settings['db_file'] = pj_input(pj_POST('db_file', 'ccount_database.php'));
    // Check database file
    if (preg_match('/[^0-9a-zA-Z_\\-\\.]/', $ccount_settings['db_file'])) {
        $error_buffer['db_file'] = 'Invalid file name. Use only these chars: a-z A-Z 0-9 _ - .';
    }
    // Unique hours
    $ccount_settings['unique_hours'] = intval(pj_POST('unique_hours', 24));
    if ($ccount_settings['unique_hours'] < 0) {
        $ccount_settings['unique_hours'] = 0;
    }
    // Notation
    $ccount_settings['notation'] = pj_input(pj_POST('notation', 'US'));
    if (!in_array($ccount_settings['notation'], array('US', 'UK', 'FR', 'X1', 'X2'))) {
        $ccount_settings['notation'] = 'US';
    }
    // If no errors, check for duplicates/generate a new ID
    if (count($error_buffer) == 0) {
        // Update settings file
        if (@file_put_contents('../ccount_settings.php', "<?php\nerror_reporting(0);\nif (!defined('IN_SCRIPT')) {die('Invalid attempt!');}\n\n// Password hash for admin area\n\$ccount_settings['admin_pass']='******'admin_pass']}';\n\n// URL of the click.php file\n\$ccount_settings['click_url']='{$ccount_settings['click_url']}';\n\n// Number of hours a visitor is considered as \"unique\"\n\$ccount_settings['unique_hours']={$ccount_settings['unique_hours']};\n\n// Sets the preferred number notation (US, UK, FR, X1, X2)\n\$ccount_settings['notation']='{$ccount_settings['notation']}';\n\n// Name of the log file\n\$ccount_settings['db_file']='{$ccount_settings['db_file']}';\n\n// Version information\n\$ccount_settings['version']='{$ccount_settings['version']}';", LOCK_EX) === false) {
            $_SESSION['PJ_MESSAGES']['ERROR'] = 'Error writing to settings file, please try again later.';
        } else {
            $_SESSION['PJ_MESSAGES']['SUCCESS'] = 'Settings have been saved.';
        }
    }
}
if (count($error_buffer)) {
    $_SESSION['PJ_MESSAGES']['ERROR'] = 'Missing or invalid data, see below for details.';
                $_SESSION['PJ_MESSAGES']['SUCCESS'] = 'Backup file has been restored';
            }
        }
        if ($restore_existing) {
            // Update database file
            if (@file_put_contents($ccount_settings['db_file'], $existing, LOCK_EX) === false) {
                $_SESSION['PJ_MESSAGES']['ERROR'] = 'Could not restore: Error writing to database file, please try again later.';
            }
        }
        unset($existing);
        unset($data);
    }
}
// END restore backup
// Import legacy backup?
if (pj_POST('legacy') && pj_token_check()) {
    // Check demo mode
    pj_demo('backups.php');
    // File uploaded?
    if (empty($_FILES['backupfile']['name'])) {
        $_SESSION['PJ_MESSAGES']['ERROR'] = 'No legacy backup file uploaded.';
    } else {
        $restore_existing = false;
        // Save current contents just in case
        $existing = file_get_contents($ccount_settings['db_file']);
        // Replace existing with new file
        if (!move_uploaded_file($_FILES['backupfile']['tmp_name'], dirname(dirname(__FILE__)) . '/' . substr($ccount_settings['db_file'], 3))) {
            $_SESSION['PJ_MESSAGES']['ERROR'] = 'Could not copy uploaded backup file over the existing one.';
        } else {
            $data = array();
            // Verify backup file
// Add a new link?
if (pj_POST('action') == 'add' && pj_token_check()) {
    // Check demo mode
    pj_demo('new_link.php');
    // Link URL
    $url = pj_validateURL(pj_POST('url')) or $error_buffer['url'] = 'Enter a valid URL address.';
    // Link title
    $title = stripslashes(pj_input(pj_POST('title'))) or $title = '';
    // Link ID
    $id = pj_input(pj_POST('id')) or $id = '';
    // Check ID
    if (preg_match('/[^0-9a-zA-Z_\\-\\.]/', $id)) {
        $error_buffer['id'] = 'Invalid link ID. Leave it empty or use only these chars: a-z A-Z 0-9 _ - .';
    }
    // Count
    $count = intval(pj_POST('count', 0));
    // If no errors, check for duplicates/generate a new ID
    if (count($error_buffer) == 0) {
        // Get links database
        $data = explode('//', file_get_contents($ccount_settings['db_file']), 2);
        // Convert contents into an array
        $ccount_database = isset($data[1]) ? unserialize($data[1]) : array();
        unset($data);
        // ID exists?
        if (strlen($id)) {
            if (isset($ccount_database[$id])) {
                $error_buffer['id'] = 'A link with this ID already exists.';
            }
        } else {
            $id = 0;
            foreach ($ccount_database as $key => $value) {
Example #6
0
    // Delete cookie
    setcookie('ccount_hash', '');
    // Stop session
    pj_session_stop();
    // Define a success message
    $_SESSION['PJ_MESSAGES']['SUCCESS'] = 'You have logged out successfuly.';
} elseif (pj_isLoggedIn()) {
    header('Location: admin.php');
    die;
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Check password etc
    if (stripslashes(pj_input(pj_POST('pass', false))) == $ccount_settings['admin_pass']) {
        // Set session variable
        $_SESSION['LOGGED_IN'] = true;
        // Remember user?
        if (pj_POST('remember') == 'yes') {
            setcookie('ccount_hash', pj_Pass2Hash($ccount_settings['admin_pass']), strtotime('+1 year'));
        }
        // Redirect to admin
        header('Location: admin.php');
        die;
    } else {
        $_SESSION['PJ_MESSAGES']['ERROR'] = 'Invalid password.';
    }
} elseif (isset($_GET['notice'])) {
    $_SESSION['PJ_MESSAGES']['INFO'] = 'Session expired, please login again.';
}
// Nothing of above, print the sign in form...
// Get header
include 'admin_header.inc.php';
// Sign in form