/
login.php
282 lines (247 loc) · 8.63 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<?php
/**
* rep2 - ログイン
*/
require_once './conf/conf.inc.php';
$_login->authorize(); // ユーザ認証
$csrfid = P2Util::getCsrfId(__FILE__);
//=========================================================
// 書き出し用変数
//=========================================================
$p_htm = array();
// 表示文字
$p_str = array(
'ptitle' => 'rep2認証ユーザ管理',
'autho_user' => '認証ユーザ',
'logout' => 'ログアウト',
'password' => 'パスワード',
'login' => 'ログイン',
'user' => 'ユーザ'
);
// 携帯用表示文字列変換
if ($_conf['ktai'] && function_exists('mb_convert_kana')) {
foreach ($p_str as $k => $v) {
$p_str[$k] = mb_convert_kana($v, 'rnsk');
}
}
// (携帯)ログイン用URL
//$user_u_q = $_conf['ktai'] ? "?user={$_login->user_u}" : '';
//$url = rtrim(dirname(P2Util::getMyUrl()), '/') . '/' . $user_u_q . '&b=k';
$url = rtrim(dirname(P2Util::getMyUrl()), '/') . '/?b=k';
$p_htm['ktai_url'] = '携帯'.$p_str['login'].'用URL <a href="'.$url.'" target="_blank">'.$url.'</a><br>';
//====================================================
// ユーザ登録処理
//====================================================
if (isset($_POST['form_new_login_pass'])) {
if (!isset($_POST['csrfid']) or $_POST['csrfid'] != $csrfid) {
p2die('不正なポストです');
}
$new_login_pass = $_POST['form_new_login_pass'];
// 入力チェック
if (!preg_match('/^[0-9A-Za-z_]+$/', $new_login_pass)) {
P2Util::pushInfoHtml("<p>rep2 error: {$p_str['password']}を半角英数字で入力して下さい。</p>");
} elseif ($new_login_pass != $_POST['form_new_login_pass2']) {
P2Util::pushInfoHtml("<p>rep2 error: {$p_str['password']} と {$p_str['password']} (確認) が一致しませんでした。</p>");
// パスワード変更登録処理を行う
} else {
$crypted_login_pass = sha1($new_login_pass);
$auth_user_cont = <<<EOP
<?php
\$rec_login_user_u = '{$_login->user_u}';
\$rec_login_pass_x = '{$crypted_login_pass}';
?>
EOP;
FileCtl::make_datafile($_conf['auth_user_file'], $_conf['pass_perm']); // ファイルがなければ生成
$fp = @fopen($_conf['auth_user_file'], 'wb');
if (!$fp) {
p2die("{$_conf['auth_user_file']} を保存できませんでした。認証ユーザ登録失敗。");
}
flock($fp, LOCK_EX);
fputs($fp, $auth_user_cont);
flock($fp, LOCK_UN);
fclose($fp);
P2Util::pushInfoHtml('<p>○認証パスワードを変更登録しました</p>');
}
}
//====================================================
// 補助認証
//====================================================
$mobile = Net_UserAgent_Mobile::singleton();
$p_htm['auth_ctl'] = '';
// docomo認証
if ($mobile->isDoCoMo()) {
if (file_exists($_conf['auth_imodeid_file'])) {
$p_htm['auth_ctl'] .= <<<EOP
iモードID認証登録済[<a href="{$_SERVER['SCRIPT_NAME']}?ctl_regist_imodeid=1{$_conf['k_at_a']}">解除</a>]<br>
EOP;
}
if (file_exists($_conf['auth_docomo_file'])) {
$p_htm['auth_ctl'] .= <<<EOP
端末ID認証登録済[<a href="{$_SERVER['SCRIPT_NAME']}?ctl_regist_docomo=1{$_conf['k_at_a']}">解除</a>]<br>
EOP;
}
if ($p_htm['auth_ctl'] == '' && $_login->pass_x) {
if (empty($_SERVER['HTTPS'])) {
$p_htm['auth_ctl'] = <<<EOP
[<a href="{$_SERVER['SCRIPT_NAME']}?ctl_regist_imodeid=1&regist_imodeid=1&guid=ON{$_conf['k_at_a']}">iモードIDで認証を登録</a>]<br>
EOP;
} else {
$p_htm['auth_ctl'] = <<<EOP
[<a href="{$_SERVER['SCRIPT_NAME']}?ctl_regist_docomo=1&regist_docomo=1{$_conf['k_at_a']}" utn>端末IDで認証を登録</a>]<br>
EOP;
}
}
// EZ認証
} elseif ($mobile->isEZweb()) {
if (file_exists($_conf['auth_ez_file'])) {
$p_htm['auth_ctl'] = <<<EOP
端末ID認証登録済[<a href="{$_SERVER['SCRIPT_NAME']}?ctl_regist_ez=1{$_conf['k_at_a']}">解除</a>]<br>
EOP;
} elseif ($mobile->getUID() !== null) {
if ($_login->pass_x) {
$p_htm['auth_ctl'] = <<<EOP
[<a href="{$_SERVER['SCRIPT_NAME']}?ctl_regist_ez=1&regist_ez=1{$_conf['k_at_a']}">端末IDで認証を登録</a>]<br>
EOP;
}
}
// Y!認証
} elseif ($mobile->isSoftBank()) {
if (file_exists($_conf['auth_jp_file'])) {
$p_htm['auth_ctl'] = <<<EOP
端末ID認証登録済[<a href="{$_SERVER['SCRIPT_NAME']}?ctl_regist_jp=1{$_conf['k_at_a']}">解除</a>]<br>
EOP;
} elseif ($mobile->getSerialNumber() !== null) {
if ($_login->pass_x) {
$p_htm['auth_ctl'] = <<<EOP
[<a href="{$_SERVER['SCRIPT_NAME']}?ctl_regist_jp=1&regist_jp=1{$_conf['k_at_a']}">端末IDで認証を登録</a>]<br>
EOP;
}
}
// Cookie認証
} else {
if ($_login->checkUserPwWithCid($_COOKIE['cid'])) {
$p_htm['auth_cookie'] = <<<EOP
cookie認証登録済[<a href="cookie.php?ctl_regist_cookie=1{$_conf['k_at_a']}">解除</a>]<br>
EOP;
} else {
if ($_login->pass_x) {
$p_htm['auth_cookie'] = <<<EOP
[<a href="cookie.php?ctl_regist_cookie=1&regist_cookie=1{$_conf['k_at_a']}">cookieで認証を登録</a>]<br>
EOP;
}
}
}
//====================================================
// Cookie認証チェック
//====================================================
if (!empty($_REQUEST['check_regist_cookie'])) {
if ($_login->checkUserPwWithCid($_COOKIE['cid'])) {
if ($_REQUEST['regist_cookie'] == '1') {
$info_msg_ht = '<p>○cookie認証登録完了</p>';
} else {
$info_msg_ht = '<p>×cookie認証解除失敗</p>';
}
} else {
if ($_REQUEST['regist_cookie'] == '1') {
$info_msg_ht = '<p>×cookie認証登録失敗</p>';
} else {
$info_msg_ht = '<p>○cookie認証解除完了</p>';
}
}
P2Util::pushInfoHtml($info_msg_ht);
}
//====================================================
// 認証ユーザ登録フォーム
//====================================================
if ($_conf['ktai']) {
$login_form_ht = <<<EOP
<hr>
<form id="login_change" method="POST" action="{$_SERVER['SCRIPT_NAME']}" target="_self">
{$p_str['password']}の変更<br>
{$_conf['k_input_ht']}
<input type="hidden" name="csrfid" value="{$csrfid}">
新しい{$p_str['password']}:<br>
<input type="password" name="form_new_login_pass"><br>
新しい{$p_str['password']} (確認):<br>
<input type="password" name="form_new_login_pass2"><br>
<input type="submit" name="submit" value="変更登録">
</form>
<hr>
<div class="center">{$_conf['k_to_index_ht']}</div>
EOP;
} else {
$login_form_ht = <<<EOP
<form id="login_change" method="POST" action="{$_SERVER['SCRIPT_NAME']}" target="_self">
{$p_str['password']}の変更<br>
{$_conf['k_input_ht']}
<input type="hidden" name="csrfid" value="{$csrfid}">
<table border="0">
<tr>
<td>新しい{$p_str['password']}</td>
<td><input type="password" name="form_new_login_pass"></td>
</tr>
<tr>
<td>新しい{$p_str['password']} (確認)</td>
<td><input type="password" name="form_new_login_pass2"></td>
</tr>
</table>
<input type="submit" name="submit" value="変更登録">
</form>
EOP;
}
//=========================================================
// HTMLプリント
//=========================================================
P2Util::header_nocache();
echo $_conf['doctype'];
echo <<<EOP
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
{$_conf['extra_headers_ht']}
<title>{$p_str['ptitle']}</title>\n
EOP;
if (!$_conf['ktai']) {
echo <<<EOP
<link rel="stylesheet" type="text/css" href="css.php?css=style&skin={$skin_en}">
<link rel="stylesheet" type="text/css" href="css.php?css=login&skin={$skin_en}">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<script type="text/javascript" src="js/basic.js?{$_conf['p2_version_id']}"></script>\n
EOP;
}
$body_at = ($_conf['ktai']) ? $_conf['k_colors'] : ' onload="setWinTitle();"';
echo <<<EOP
</head>
<body{$body_at}>
EOP;
if (!$_conf['ktai']) {
echo <<<EOP
<p id="pan_menu"><a href="setting.php">ログイン管理</a> > {$p_str['ptitle']}</p>
EOP;
}
// 情報表示
P2Util::printInfoHtml();
echo '<p id="login_status">';
echo <<<EOP
{$p_str['autho_user']}: {$_login->user_u}<br>
{$p_htm['auth_ctl']}
{$p_htm['auth_cookie']}
<br>
[<a href="./index.php?logout=1" target="_parent">{$p_str['logout']}する</a>]
EOP;
echo '</p>';
echo $login_form_ht;
echo '</body></html>';
/*
* Local Variables:
* mode: php
* coding: cp932
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker: