1. Меняем таблицу %users
1.1. Добавляем столбец pgp_setting tinyint(1)
1.2. Добавляем столбец pgp_key text, не забываем указать сравнние столбца utf8_general_ci
2. Добавляем значения в языковые файлы
2.1. Файл /lang/Russian/common.php
Перед
);
Добавить
//myFix start pgp
'PGP Error Password' => 'Неверный пароль, попробуйте еще раз.',
//myFix end pgp
2.2. Файл /lang/Russian/login.php
Перед
);
Добавить
//myFix start pgp
'pgp_two_factor_error' => 'Второй этап аутентификации прошел как то не так.. попробуйте еще раз.',
'Two factor auth enable' => 'Двухфакторая аутентификация включена.',
'Secret key' => 'Секретный ключ',
'Send' => 'Отправить',
'Crypt Message' => 'Зашифрованное сообщение',
//myFix end pgp
2.3. Файл /lang/Russian/profile.php
Перед
);
Добавить
//myFix start pgp
'pgp_two_factor' => 'Двухфакторная аутентификация',
'pgp_enter_public_key' => 'Введите публичный ключ',
'pgp_on_pgp_auth' => 'Включить PGP аутентификацию',
'pgp_enter_password' => 'Введите свой пароль',
//myFix end pgp
3. Файл /login.php
3.1. Находим
$expire = ($save_pass == '1') ? time() + 1209600 : time() + $pun_config['o_timeout_visit'];
pun_setcookie($cur_user['id'], $form_password_hash, $expire);
// Reset tracked topics
set_tracked_topics(null);
// Try to determine if the data in redirect_url is valid (if not, we redirect to index.php after login)
$redirect_url = validate_redirect($_POST['redirect_url'], 'index.php');
redirect(pun_htmlspecialchars($redirect_url), $lang_login['Login redirect']);
Меняем на
//myFix start
$expire = ($save_pass == '1') ? time() + 1209600 : time() + $pun_config['o_timeout_visit'];
if($cur_user['pgp_setting'] == 1){
$_SESSION['pgp2']['cur_user_id'] = $cur_user['id'];
$_SESSION['pgp2']['pgp_key'] = $cur_user['pgp_key'];
$_SESSION['pgp2']['form_password_hash'] = $form_password_hash;
$_SESSION['pgp2']['expire'] = $expire;
$_SESSION['pgp2']['redirect_url'] = $_POST['redirect_url'];
header('Location: login.php?action=in2');
exit;
} else {
pun_setcookie($cur_user['id'], $form_password_hash, $expire);
// Reset tracked topics
set_tracked_topics(null);
// Try to determine if the data in redirect_url is valid (if not, we redirect to index.php after login)
$redirect_url = validate_redirect($_POST['redirect_url'], 'index.php');
redirect(pun_htmlspecialchars($redirect_url), $lang_login['Login redirect']);
}
//myFix end
3.2. Находим
else if ($action == 'out')
Ставим ПЕРЕД
//myFix start
else if ($action == 'in2'){
if (empty($_SESSION['pgp2']['cur_user_id']) || empty($_SESSION['pgp2']['pgp_key']) || empty($_SESSION['pgp2']['form_password_hash']) || empty($_SESSION['pgp2']['expire']))
{
header('Location: index.php');
exit;
}
require PUN_ROOT.'pgp-2fa.php';
$pgp = new pgp_2fa();
if($_SERVER['REQUEST_METHOD'] == 'POST' and isset($_SESSION['pgp2']['pgp_key'])){
if($pgp->compare($_POST['user-input'])){
pun_setcookie($_SESSION['pgp2']['cur_user_id'], $_SESSION['pgp2']['form_password_hash'], $_SESSION['pgp2']['expire']);
// Reset tracked topics
set_tracked_topics(null);
// Try to determine if the data in redirect_url is valid (if not, we redirect to index.php after login)
$redirect_url = validate_redirect($_SESSION['pgp2']['redirect_url'], 'index.php');
$_SESSION['pgp2']['cur_user_id'] = '';
$_SESSION['pgp2']['pgp_key'] = '';
$_SESSION['pgp2']['form_password_hash'] = '';
$_SESSION['pgp2']['expire'] = '';
$_SESSION['pgp2']['redirect_url'] = '';
redirect(pun_htmlspecialchars($redirect_url), $lang_login['Login redirect']);
}else{
$_SESSION['pgp2']['cur_user_id'] = '';
$_SESSION['pgp2']['pgp_key'] = '';
$_SESSION['pgp2']['form_password_hash'] = '';
$_SESSION['pgp2']['expire'] = '';
$_SESSION['pgp2']['redirect_url'] = '';
redirect(pun_htmlspecialchars('login.php'), $lang_login['pgp_two_factor_error']);
}
}
$pgp->generateSecret();
$pgpmessage = $pgp->encryptSecret($_SESSION['pgp2']['pgp_key']);
require PUN_ROOT.'header.php';
?>
<div class="blockform">
<h2><span><?php echo $lang_login['Login redirect'] ?></span></h2>
<div class="box">
<form method="post">
<div class="inform">
<fieldset>
<legend><?php echo $lang_login['Crypt Message'] ?></legend>
<div class="infldset">
<textarea readonly="readonly" style="width:100%; height:300px;" name="pgp-msg"><?php echo $pgpmessage; ?></textarea>
<?php echo $lang_login['Secret key'] ?>: <input type="text" name="user-input">
</div>
</fieldset>
<p class="buttons"><input type="submit" value="<?php echo $lang_login['Send'] ?>"></p>
</div>
</form>
</div>
</div>
<?php
require PUN_ROOT.'footer.php';
die();
}
//myFix end
4. Файл /include/function.php
4.1. Находим
<li<?php if ($page == 'privacy') echo ' class="isactive"'; ?>><a href="profile.php?section=privacy&id=<?php echo $id ?>"><?php echo $lang_profile['Section privacy'] ?></a></li>
Ставим ПОСЛЕ
<!-- myFix start pgp -->
<li<?php if ($page == 'pgp') echo ' class="isactive"'; ?>><a href="profile.php?section=pgp&id=<?php echo $id ?>"><?php echo $lang_profile['pgp_two_factor'] ?></a></li>
<!-- myFix end pgp -->
5. Файл /profile.php
5.1. Находим
case 'privacy':
{
$form = array(
'email_setting' => intval($_POST['form']['email_setting']),
'notify_with_post' => isset($_POST['form']['notify_with_post']) ? '1' : '0',
'auto_notify' => isset($_POST['form']['auto_notify']) ? '1' : '0',
);
if ($form['email_setting'] < 0 || $form['email_setting'] > 2)
$form['email_setting'] = $pun_config['o_default_email_setting'];
break;
}
Добавляем ПОСЛЕ
//myFix start pgp
case 'pgp':
{
$form = array(
'pgp_setting' => isset($_POST['form']['pgp_setting']) ? '1' : '0',
'pgp_key' => isset($_POST['form']['pgp_key']) ? $_POST['form']['pgp_key'] : '',
);
$result = $db->query('SELECT * FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch new password', __FILE__, __LINE__, $db->error());
$cur_user = $db->fetch_assoc($result);
$pgp_form_password_hash = pun_hash($_POST['form']['pgp_enter_password']); // Will result in a SHA-1 hash
$pgp_authorized = pun_hash_equals($cur_user['password'], $pgp_form_password_hash);
if (!$pgp_authorized){
message($lang_common['PGP Error Password'], false, '404 Not Found');
}
break;
}
//myFix end pgp
5.2. Находим
$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.location, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.notify_with_post, u.auto_notify, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.dst, u.language, u.style, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, u.date_format, u.time_format, u.last_visit, g.g_id, g.g_user_title, g.g_moderator FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
Заменяем на
//myFix start pgp add u.pgp_setting, u.pgp_key
$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.location, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.notify_with_post, u.auto_notify, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.dst, u.language, u.style, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, u.date_format, u.time_format, u.last_visit, g.g_id, g.g_user_title, g.g_moderator, u.pgp_setting, u.pgp_key FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
//myFix end pgp add u.pgp_setting, u.pgp_key
5.3. Находим
else if ($section == 'admin')
Ставим ПЕРЕД
//myFix start pgp
else if ($section == 'pgp')
{
$page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_common['Profile'], $lang_profile['pgp_two_factor']);
define('PUN_ACTIVE_PAGE', 'profile');
require PUN_ROOT.'header.php';
generate_profile_menu('pgp');
?>
<div class="blockform">
<h2><span><?php echo pun_htmlspecialchars($user['username']).' - '.$lang_profile['pgp_two_factor'] ?></span></h2>
<div class="box">
<form id="profile6" method="post" action="profile.php?section=pgp&id=<?php echo $id ?>">
<div class="inform">
<fieldset>
<legend><?php echo $lang_profile['pgp_enter_public_key'] ?></legend>
<div class="infldset">
<input type="hidden" name="form_sent" value="1" />
<label>
<input type="checkbox" name="form[pgp_setting]" value="0"<?php if ($user['pgp_setting'] == '1') echo ' checked="checked"' ?> /><?php echo $lang_profile['pgp_on_pgp_auth'] ?>
<br />
</label>
<label><textarea name="form[pgp_key]" rows="35" style="width:100%;"><?php echo pun_htmlspecialchars($user['pgp_key']) ?></textarea><br /></label>
<label><?php echo $lang_profile['pgp_enter_password'] ?>: <input type="password" name="form[pgp_enter_password]" size="16"></label>
</div>
</fieldset>
</div>
<p class="buttons"><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /> <?php echo $lang_profile['Instructions'] ?></p>
</form>
</div>
</div>
<?php
}
//myFix end pgp