Commit 5fa744c2 by Daniel Ruf Committed by Scott

support IPv6 using inet_pton

parent cb812352
......@@ -549,7 +549,7 @@
}
if (@$options['whoview']) {
$fields['who']=qa_who_to_html($isbyuser, @$post['userid'], $usershtml, @$options['ipview'] ? @$post['createip'] : null, $microdata, $post['name']);
$fields['who']=qa_who_to_html($isbyuser, @$post['userid'], $usershtml, @$options['ipview'] ? inet_ntop()@$post['createip']) : null, $microdata, $post['name']);
if (isset($post['points'])) {
if (@$options['pointsview'])
......@@ -628,7 +628,7 @@
}
if (isset($post['lastuserid']) && @$options['whoview'])
$fields['who_2']=qa_who_to_html(isset($userid) && ($post['lastuserid']==$userid), $post['lastuserid'], $usershtml, @$options['ipview'] ? $post['lastip'] : null, false);
$fields['who_2']=qa_who_to_html(isset($userid) && ($post['lastuserid']==$userid), $post['lastuserid'], $usershtml, @$options['ipview'] ? inet_ntop($post['lastip']) : null, false);
}
......@@ -890,7 +890,7 @@
if (@$options['whoview']) {
$isbyuser=qa_post_is_by_user(array('userid' => $question['ouserid'], 'cookieid' => @$question['ocookieid']), $userid, $cookieid);
$fields['who']=qa_who_to_html($isbyuser, $question['ouserid'], $usershtml, @$options['ipview'] ? @$question['oip'] : null, false, @$question['oname']);
$fields['who']=qa_who_to_html($isbyuser, $question['ouserid'], $usershtml, @$options['ipview'] ? inet_ntop(@$question['oip']) : null, false, @$question['oname']);
if (isset($question['opoints'])) {
if (@$options['pointsview'])
$fields['who']['points']=($question['opoints']==1) ? qa_lang_html_sub_split('main/1_point', '1', '1')
......
......@@ -159,8 +159,7 @@
*/
{
return qa_db_read_all_values(qa_db_query_sub(
"SELECT postid FROM ^posts WHERE createip=INET_ATON($) AND type IN ('Q', 'A', 'C', 'Q_QUEUED', 'A_QUEUED', 'C_QUEUED')",
$ip
"SELECT postid FROM ^posts WHERE createip=".inet_pton($ip)." AND type IN ('Q', 'A', 'C', 'Q_QUEUED', 'A_QUEUED', 'C_QUEUED')"
));
}
......@@ -187,7 +186,7 @@
*/
{
$results=qa_db_read_all_assoc(qa_db_query_sub(
"SELECT ^users.userid, UNIX_TIMESTAMP(created) AS created, INET_NTOA(createip) AS createip, email, handle, flags, title, content FROM ^users LEFT JOIN ^userprofile ON ^users.userid=^userprofile.userid AND LENGTH(content)>0 WHERE level<# AND NOT (flags&#) ORDER BY created DESC LIMIT #",
"SELECT ^users.userid, UNIX_TIMESTAMP(created) AS created, createip, email, handle, flags, title, content FROM ^users LEFT JOIN ^userprofile ON ^users.userid=^userprofile.userid AND LENGTH(content)>0 WHERE level<# AND NOT (flags&#) ORDER BY created DESC LIMIT #",
QA_USER_LEVEL_APPROVED, QA_USER_FLAGS_USER_BLOCKED, $count
));
......@@ -195,6 +194,7 @@
foreach ($results as $result) {
$userid=$result['userid'];
$result['createip']=inet_ntop($result['createip']);
if (!isset($users[$userid])) {
$users[$result['userid']]=$result;
......
......@@ -40,8 +40,8 @@
continue;
qa_db_query_sub(
'INSERT INTO ^blobs (blobid, format, content, filename, userid, cookieid, createip, created) VALUES (#, $, $, $, $, #, INET_ATON($), NOW())',
$blobid, $format, $content, $sourcefilename, $userid, $cookieid, $ip
'INSERT INTO ^blobs (blobid, format, content, filename, userid, cookieid, createip, created) VALUES (#, $, $, $, $, #, '.inet_pton($ip).', NOW())',
$blobid, $format, $content, $sourcefilename, $userid, $cookieid
);
return $blobid;
......@@ -107,4 +107,4 @@
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
*/
......@@ -39,8 +39,8 @@
qa_db_query_sub(
'INSERT INTO ^cookies (cookieid, created, createip) '.
'VALUES (#, NOW(), COALESCE(INET_ATON($), 0))',
$cookieid, $ipaddress
'VALUES (#, NOW(), '.inet_pton($ipaddress).')',
$cookieid
);
return $cookieid;
......@@ -56,8 +56,8 @@
*/
{
qa_db_query_sub(
'UPDATE ^cookies SET written=NOW(), writeip=COALESCE(INET_ATON($), 0) WHERE cookieid=#',
$ipaddress, $cookieid
'UPDATE ^cookies SET written=NOW(), writeip='.inet_pton($ipaddress).' WHERE cookieid=#',
$cookieid
);
}
......@@ -76,4 +76,4 @@
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
*/
......@@ -44,7 +44,7 @@
'(a.acount+0.0)*# + '.
'(a.netvotes+0.0)*# + '.
'(a.views+0.0+#)*#'.
')'.($viewincrement ? ', x.views=x.views+1, x.lastviewip=INET_ATON($)' : '').' WHERE x.postid=a.postid';
')'.($viewincrement ? ', x.views=x.views+1, x.lastviewip='.inet_pton(qa_remote_ip_address()) : '').' WHERE x.postid=a.postid';
// Additional multiples based on empirical analysis of activity on Q2A meta site to give approx equal influence for all factors
......@@ -59,9 +59,6 @@
qa_opt('hot_weight_views')*4000,
);
if ($viewincrement)
$arguments[]=qa_remote_ip_address();
qa_db_query_raw(qa_db_apply_sub($query, $arguments));
}
}
......@@ -69,4 +66,4 @@
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
*/
......@@ -42,8 +42,7 @@
}
if (isset($ip)) {
$selects[]="(SELECT 'ip' AS limitkey, period, count FROM ^iplimits WHERE ip=COALESCE(INET_ATON($), 0) AND action=$)";
$arguments[]=$ip;
$selects[]="(SELECT 'ip' AS limitkey, period, count FROM ^iplimits WHERE ip=".inet_pton($ip)." AND action=$)";
$arguments[]=$action;
}
......@@ -75,13 +74,13 @@
*/
{
qa_db_query_sub(
'INSERT INTO ^iplimits (ip, action, period, count) VALUES (COALESCE(INET_ATON($), 0), $, #, #) '.
'INSERT INTO ^iplimits (ip, action, period, count) VALUES ('.inet_pton($ip).', $, #, #) '.
'ON DUPLICATE KEY UPDATE count=IF(period=#, count+#, #), period=#',
$ip, $action, $period, $count, $period, $count, $count, $period
$action, $period, $count, $period, $count, $count, $period
);
}
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
*/
......@@ -33,8 +33,8 @@
{
qa_db_query_sub(
'INSERT INTO ^posts (categoryid, type, parentid, userid, cookieid, createip, title, content, format, tags, notify, name, created) '.
'VALUES (#, $, #, $, #, INET_ATON($), $, $, $, $, $, $, NOW())',
$categoryid, $type, $parentid, $userid, $cookieid, $ip, $title, $content, $format, $tagstring, $notify, $name
'VALUES (#, $, #, $, #, '.inet_pton($ip).', $, $, $, $, $, $, NOW())',
$categoryid, $type, $parentid, $userid, $cookieid, $title, $content, $format, $tagstring, $notify, $name
);
return qa_db_last_insert_id();
......@@ -410,4 +410,4 @@
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
*/
......@@ -48,8 +48,8 @@
if (isset($selchildid) && isset($lastuserid) && isset($lastip))
qa_db_query_sub(
"UPDATE ^posts SET updated=NOW(), updatetype=$, lastuserid=$, lastip=INET_ATON($) WHERE postid=#",
QA_UPDATE_SELECTED, $lastuserid, $lastip, $selchildid
"UPDATE ^posts SET updated=NOW(), updatetype=$, lastuserid=$, lastip=".inet_pton($lastip)." WHERE postid=#",
QA_UPDATE_SELECTED, $lastuserid, $selchildid
);
}
......@@ -62,8 +62,8 @@
{
if (isset($lastuserid) || isset($lastip)) {
qa_db_query_sub(
"UPDATE ^posts SET closedbyid=#, updated=NOW(), updatetype=$, lastuserid=$, lastip=INET_ATON($) WHERE postid=#",
$closedbyid, QA_UPDATE_CLOSED, $lastuserid, $lastip, $questionid
"UPDATE ^posts SET closedbyid=#, updated=NOW(), updatetype=$, lastuserid=$, lastip=".inet_pton($lastip)." WHERE postid=#",
$closedbyid, QA_UPDATE_CLOSED, $lastuserid, $questionid
);
} else
qa_db_query_sub(
......@@ -80,8 +80,8 @@
{
if (isset($lastuserid) || isset($lastip)) {
qa_db_query_sub(
'UPDATE ^posts SET type=$, updated=NOW(), updatetype=$, lastuserid=$, lastip=INET_ATON($) WHERE postid=#',
$type, $updatetype, $lastuserid, $lastip, $postid
'UPDATE ^posts SET type=$, updated=NOW(), updatetype=$, lastuserid=$, lastip='.inet_pton($lastip).' WHERE postid=#',
$type, $updatetype, $lastuserid, $postid
);
} else
qa_db_query_sub(
......@@ -98,8 +98,8 @@
{
if (isset($lastuserid) || isset($lastip))
qa_db_query_sub(
"UPDATE ^posts SET parentid=#, updated=NOW(), updatetype=$, lastuserid=$, lastip=INET_ATON($) WHERE postid=#",
$parentid, QA_UPDATE_PARENT, $lastuserid, $lastip, $postid
"UPDATE ^posts SET parentid=#, updated=NOW(), updatetype=$, lastuserid=$, lastip=".inet_pton($lastip)." WHERE postid=#",
$parentid, QA_UPDATE_PARENT, $lastuserid, $postid
);
else
qa_db_query_sub(
......@@ -118,8 +118,8 @@
{
if (isset($lastuserid) || isset($lastip)) // use COALESCE() for name since $name=null means it should not be modified (for backwards compatibility)
qa_db_query_sub(
'UPDATE ^posts SET title=$, content=$, format=$, tags=$, name=COALESCE($, name), notify=$, updated=NOW(), updatetype=$, lastuserid=$, lastip=INET_ATON($) WHERE postid=#',
$title, $content, $format, $tagstring, $name, $notify, $updatetype, $lastuserid, $lastip, $postid
'UPDATE ^posts SET title=$, content=$, format=$, tags=$, name=COALESCE($, name), notify=$, updated=NOW(), updatetype=$, lastuserid=$, lastip='.inet_pton($lastip).' WHERE postid=#',
$title, $content, $format, $tagstring, $name, $notify, $updatetype, $lastuserid, $postid
);
else
qa_db_query_sub(
......@@ -148,8 +148,8 @@
{
if (isset($lastuserid) || isset($lastip))
qa_db_query_sub(
"UPDATE ^posts SET categoryid=#, updated=NOW(), updatetype=$, lastuserid=$, lastip=INET_ATON($) WHERE postid=#",
$categoryid, QA_UPDATE_CATEGORY, $lastuserid, $lastip, $postid
"UPDATE ^posts SET categoryid=#, updated=NOW(), updatetype=$, lastuserid=$, lastip=".inet_pton($lastip)." WHERE postid=#",
$categoryid, QA_UPDATE_CATEGORY, $lastuserid, $postid
);
else
qa_db_query_sub(
......@@ -363,4 +363,4 @@
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
*/
......@@ -166,15 +166,15 @@
$selectspec['columns']['updatetype']='^posts.updatetype';
$selectspec['columns'][]='^posts.format';
$selectspec['columns'][]='^posts.lastuserid';
$selectspec['columns']['lastip']='INET_NTOA(^posts.lastip)';
$selectspec['columns']['lastip']='^posts.lastip';
$selectspec['columns'][]='^posts.parentid';
$selectspec['columns']['lastviewip']='INET_NTOA(^posts.lastviewip)';
$selectspec['columns']['lastviewip']='^posts.lastviewip';
}
if ($user) {
$selectspec['columns'][]='^posts.userid';
$selectspec['columns'][]='^posts.cookieid';
$selectspec['columns']['createip']='INET_NTOA(^posts.createip)';
$selectspec['columns']['createip']='^posts.createip';
$selectspec['columns'][]='^userpoints.points';
if (!QA_FINAL_EXTERNAL_USERS) {
......@@ -216,7 +216,7 @@
$selectspec['columns']['ouserid']=$poststable.($fromupdated ? '.lastuserid' : '.userid');
$selectspec['columns']['ocookieid']=$poststable.'.cookieid';
$selectspec['columns']['oname']=$poststable.'.name';
$selectspec['columns']['oip']='INET_NTOA('.$poststable.($fromupdated ? '.lastip' : '.createip').')';
$selectspec['columns']['oip']=$poststable.($fromupdated ? '.lastip' : '.createip');
$selectspec['columns']['otime']='UNIX_TIMESTAMP('.$poststable.($fromupdated ? '.updated' : '.created').')';
$selectspec['columns']['oflagcount']=$poststable.'.flagcount';
......@@ -323,12 +323,9 @@
$selectspec['source'].=" JOIN (SELECT postid FROM ^posts WHERE ".
qa_db_categoryslugs_sql_args($categoryslugs, $selectspec['arguments']).
(isset($createip) ? "createip=INET_ATON($) AND " : "").
(isset($createip) ? "createip=".inet_pton($createip)." AND " : "").
"type=$ ".$sortsql." LIMIT #,#) y ON ^posts.postid=y.postid";
if (isset($createip))
$selectspec['arguments'][]=$createip;
array_push($selectspec['arguments'], $type, $start, $count);
$selectspec['sortdesc']=$sort;
......@@ -406,13 +403,10 @@
" LEFT JOIN ^userpoints AS auserpoints ON aposts.userid=auserpoints.userid".
" JOIN (SELECT postid FROM ^posts WHERE ".
qa_db_categoryslugs_sql_args($categoryslugs, $selectspec['arguments']).
(isset($createip) ? "createip=INET_ATON($) AND " : "").
(isset($createip) ? "createip=".inet_pton($createip)." AND " : "").
"type=$ ORDER BY ^posts.created DESC LIMIT #,#) y ON aposts.postid=y.postid".
($specialtype ? '' : " WHERE ^posts.type='Q'");
if (isset($createip))
$selectspec['arguments'][]=$createip;
array_push($selectspec['arguments'], $type, $start, $count);
$selectspec['sortdesc']='otime';
......@@ -449,13 +443,10 @@
" LEFT JOIN ^userpoints AS cuserpoints ON cposts.userid=cuserpoints.userid".
" JOIN (SELECT postid FROM ^posts WHERE ".
qa_db_categoryslugs_sql_args($categoryslugs, $selectspec['arguments']).
(isset($createip) ? "createip=INET_ATON($) AND " : "").
(isset($createip) ? "createip=".inet_pton($createip)." AND " : "").
"type=$ ORDER BY ^posts.created DESC LIMIT #,#) y ON cposts.postid=y.postid".
($specialtype ? '' : " WHERE ^posts.type='Q' AND ((parentposts.type='Q') OR (parentposts.type='A'))");
if (isset($createip))
$selectspec['arguments'][]=$createip;
array_push($selectspec['arguments'], $type, $start, $count);
$selectspec['sortdesc']='otime';
......@@ -487,14 +478,11 @@
" LEFT JOIN ^userpoints AS edituserpoints ON editposts.lastuserid=edituserpoints.userid".
" JOIN (SELECT postid FROM ^posts WHERE ".
qa_db_categoryslugs_sql_args($categoryslugs, $selectspec['arguments']).
(isset($lastip) ? "lastip=INET_ATON($) AND " : "").
(isset($lastip) ? "lastip=".inet_pton($lastip)." AND " : "").
($onlyvisible ? "type IN ('Q', 'A', 'C')" : "1").
" ORDER BY ^posts.updated DESC LIMIT #,#) y ON editposts.postid=y.postid".
($onlyvisible ? " WHERE parentposts.type IN ('Q', 'A', 'C') AND ^posts.type IN ('Q', 'A', 'C')" : "");
if (isset($lastip))
$selectspec['arguments'][]=$lastip;
array_push($selectspec['arguments'], $start, $count);
$selectspec['sortdesc']='otime';
......@@ -1199,7 +1187,7 @@
'columns' => array(
'^users.userid', 'passsalt', 'passcheck' => 'HEX(passcheck)', 'passhash', 'email', 'level', 'emailcode', 'handle',
'created' => 'UNIX_TIMESTAMP(created)', 'sessioncode', 'sessionsource', 'flags', 'loggedin' => 'UNIX_TIMESTAMP(loggedin)',
'loginip' => 'INET_NTOA(loginip)', 'written' => 'UNIX_TIMESTAMP(written)', 'writeip' => 'INET_NTOA(writeip)',
'loginip', 'written' => 'UNIX_TIMESTAMP(written)', 'writeip',
'avatarblobid' => 'BINARY avatarblobid', // cast to BINARY due to MySQL bug which renders it signed in a union
'avatarwidth', 'avatarheight', 'points', 'wallposts',
),
......@@ -1678,8 +1666,7 @@
{
return array(
'columns' => array('action', 'period', 'count'),
'source' => '^iplimits WHERE ip=COALESCE(INET_ATON($), 0)',
'arguments' => array($ip),
'source' => '^iplimits WHERE ip='.inet_pton($ip),
'arraykey' => 'action',
);
}
......@@ -1711,4 +1698,4 @@
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
*/
......@@ -47,16 +47,16 @@
if (QA_PASSWORD_HASH) {
qa_db_query_sub(
'INSERT INTO ^users (created, createip, email, passhash, level, handle, loggedin, loginip) '.
'VALUES (NOW(), COALESCE(INET_ATON($), 0), $, $, #, $, NOW(), COALESCE(INET_ATON($), 0))',
$ip, $email, isset($password) ? password_hash($password, PASSWORD_BCRYPT) : null, (int)$level, $handle, $ip
'VALUES (NOW(), '.inet_pton($ip).', $, $, #, $, NOW(), '.inet_pton($ip).')',
$email, isset($password) ? password_hash($password, PASSWORD_BCRYPT) : null, (int)$level, $handle
);
} else {
$salt = isset($password) ? qa_random_alphanum(16) : null;
qa_db_query_sub(
'INSERT INTO ^users (created, createip, email, passsalt, passcheck, level, handle, loggedin, loginip) '.
'VALUES (NOW(), COALESCE(INET_ATON($), 0), $, $, UNHEX($), #, $, NOW(), COALESCE(INET_ATON($), 0))',
$ip, $email, $salt, isset($password) ? qa_db_calc_passcheck($password, $salt) : null, (int)$level, $handle, $ip
'VALUES (NOW(), '.inet_pton($ip).', 0), $, $, UNHEX($), #, $, NOW(), '.inet_pton($ip).')',
$email, $salt, isset($password) ? qa_db_calc_passcheck($password, $salt) : null, (int)$level, $handle
);
}
......@@ -236,8 +236,8 @@
*/
{
qa_db_query_sub(
'UPDATE ^users SET loggedin=NOW(), loginip=COALESCE(INET_ATON($), 0) WHERE userid=$',
$ip, $userid
'UPDATE ^users SET loggedin=NOW(), loginip='.inet_pton($ip).' WHERE userid=$',
$userid
);
}
......@@ -248,8 +248,8 @@
*/
{
qa_db_query_sub(
'UPDATE ^users SET written=NOW(), writeip=COALESCE(INET_ATON($), 0) WHERE userid=$',
$ip, $userid
'UPDATE ^users SET written=NOW(), writeip='.inet_pton($ip).' WHERE userid=$',
$userid
);
}
......
......@@ -86,7 +86,7 @@
$message['content']=qa_lang_html('users/registered_label').' '.
strtr(qa_lang_html('users/x_ago_from_y'), array(
'^1' => qa_time_to_string(qa_opt('db_time')-$user['created']),
'^2' => qa_ip_anchor_html($user['createip']),
'^2' => qa_ip_anchor_html(inet_ntop($user['createip'])),
)).'<br/>';
$htmlemail=qa_html($user['email']);
......
......@@ -430,8 +430,8 @@
(!qa_is_http_post()) &&
qa_is_human_probably() &&
( (!$question['views']) || ( // if it has more than zero views
( ($question['lastviewip']!=qa_remote_ip_address()) || (!isset($question['lastviewip'])) ) && // then it must be different IP from last view
( ($question['createip']!=qa_remote_ip_address()) || (!isset($question['createip'])) ) && // and different IP from the creator
( (inet_ntop($question['lastviewip'])!=qa_remote_ip_address()) || (!isset($question['lastviewip'])) ) && // then it must be different IP from last view
( (inet_ntop($question['createip'])!=qa_remote_ip_address()) || (!isset($question['createip'])) ) && // and different IP from the creator
( ($question['userid']!=$userid) || (!isset($question['userid'])) ) && // and different user from the creator
( ($question['cookieid']!=$cookieid) || (!isset($question['cookieid'])) ) // and different cookieid from the creator
) )
......@@ -444,4 +444,4 @@
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
*/
......@@ -583,7 +583,7 @@
'value' =>
strtr(qa_lang_html('users/x_ago_from_y'), array(
'^1' => qa_time_to_string(qa_opt('db_time')-$useraccount['loggedin']),
'^2' => qa_ip_anchor_html($useraccount['loginip']),
'^2' => qa_ip_anchor_html(inet_ntop($useraccount['loginip'])),
)),
'note' => $userediting ? null : qa_lang_html('users/only_shown_moderators'),
'id' => 'lastlogin',
......@@ -596,7 +596,7 @@
'value' =>
strtr(qa_lang_html('users/x_ago_from_y'), array(
'^1' => qa_time_to_string(qa_opt('db_time')-$useraccount['written']),
'^2' => qa_ip_anchor_html($useraccount['writeip']),
'^2' => qa_ip_anchor_html(inet_ntop($useraccount['writeip'])),
)),
'note' => $userediting ? null : qa_lang_html('users/only_shown_moderators'),
'id' => 'lastwrite',
......@@ -979,4 +979,4 @@
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment