plugins/SpecialUserFuncs.php
changeset 684 15dbbe7e7674
parent 621 68f8a9cc0a18
child 685 17ebe24cdf85
equal deleted inserted replaced
683:fcc494e02baf 684:15dbbe7e7674
   119 {
   119 {
   120   global $db, $session, $paths, $template, $plugins; // Common objects
   120   global $db, $session, $paths, $template, $plugins; // Common objects
   121   global $__login_status;
   121   global $__login_status;
   122   global $lang;
   122   global $lang;
   123   
   123   
       
   124   require_once( ENANO_ROOT . '/includes/diffiehellman.php' );
       
   125   global $dh_supported, $_math;
       
   126   
   124   $pubkey = $session->rijndael_genkey();
   127   $pubkey = $session->rijndael_genkey();
   125   $challenge = $session->dss_rand();
   128   $challenge = $session->dss_rand();
   126   
   129   
   127   $locked_out = false;
   130   $locked_out = false;
   128   // are we locked out?
   131   // are we locked out?
   178       }
   181       }
   179       unset($x, $y);
   182       unset($x, $y);
   180     }
   183     }
   181     
   184     
   182     // 1.1.3: generate diffie hellman key
   185     // 1.1.3: generate diffie hellman key
   183     require_once( ENANO_ROOT . '/includes/diffiehellman.php' );
       
   184     global $dh_supported, $_math;
       
   185     
       
   186     $response['dh_supported'] = $dh_supported;
   186     $response['dh_supported'] = $dh_supported;
   187     if ( $dh_supported )
   187     if ( $dh_supported )
   188     {
   188     {
   189       $dh_key_priv = dh_gen_private();
   189       $dh_key_priv = dh_gen_private();
   190       $dh_key_pub = dh_gen_public($dh_key_priv);
   190       $dh_key_pub = dh_gen_public($dh_key_priv);
   373            echo '<p>' . $lang->get('user_login_usecrypt_countrylist') . '</p>';
   373            echo '<p>' . $lang->get('user_login_usecrypt_countrylist') . '</p>';
   374            
   374            
   375            echo '  </td>
   375            echo '  </td>
   376            </tr>';
   376            </tr>';
   377          }
   377          }
       
   378          else if ( $level > USER_LEVEL_MEMBER && !strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') && $dh_supported )
       
   379          {
       
   380            echo '<tr>';
       
   381            echo '<td class="row3" colspan="3">';
       
   382            echo '<p>' . $lang->get('user_login_dh_notice') . '</p>';
       
   383            echo '</td>';
       
   384            echo '</tr>';
       
   385          }
   378          ?>
   386          ?>
   379          
   387          
   380          <tr>
   388          <tr>
   381            <th colspan="3" style="text-align: center" class="subhead"><input type="submit" name="login" value="Log in" tabindex="<?php echo ( $level <= USER_LEVEL_MEMBER ) ? '3' : '2'; ?>" /></th>
   389            <th colspan="3" style="text-align: center" class="subhead"><input type="submit" name="login" value="Log in" tabindex="<?php echo ( $level <= USER_LEVEL_MEMBER ) ? '3' : '2'; ?>" /></th>
   382          </tr>
   390          </tr>
   588   }
   596   }
   589 }
   597 }
   590 
   598 
   591 function SpecialLogin_SendResponse_PasswordReset($user_id, $passkey)
   599 function SpecialLogin_SendResponse_PasswordReset($user_id, $passkey)
   592 {
   600 {
   593   
       
   594   $response = Array(
   601   $response = Array(
   595       'result' => 'success_reset',
   602       'result' => 'success_reset',
   596       'user_id' => $user_id,
   603       'user_id' => $user_id,
   597       'temppass' => $passkey
   604       'temppass' => $passkey
   598     );
   605     );
   599   
   606   
   600   $response = enano_json_encode($response);
   607   $response = enano_json_encode($response);
   601   echo $response;
   608   echo $response;
   602   
   609   
   603   $db->close();
   610   $db->close();
   604   
       
   605   exit;
   611   exit;
   606 }
   612 }
   607 
   613 
   608 function page_Special_Logout()
   614 function page_Special_Logout()
   609 {
   615 {
   656   
   662   
   657   if(getConfig('account_activation') == 'disable' && ( ( $session->user_level >= USER_LEVEL_ADMIN && !isset($_GET['IWannaPlayToo']) ) || $session->user_level < USER_LEVEL_ADMIN || !$session->user_logged_in ))
   663   if(getConfig('account_activation') == 'disable' && ( ( $session->user_level >= USER_LEVEL_ADMIN && !isset($_GET['IWannaPlayToo']) ) || $session->user_level < USER_LEVEL_ADMIN || !$session->user_logged_in ))
   658   {
   664   {
   659     $s = ($session->user_level >= USER_LEVEL_ADMIN) ? '<p>' . $lang->get('user_reg_err_disabled_body_adminblurb', array( 'reg_link' => makeUrl($paths->page, 'IWannaPlayToo&coppa=no', true) )) . '</p>' : '';
   665     $s = ($session->user_level >= USER_LEVEL_ADMIN) ? '<p>' . $lang->get('user_reg_err_disabled_body_adminblurb', array( 'reg_link' => makeUrl($paths->page, 'IWannaPlayToo&coppa=no', true) )) . '</p>' : '';
   660     die_friendly($lang->get('user_reg_err_disabled_title'), '<p>' . $lang->get('user_reg_err_disabled_body') . '</p>' . $s);
   666     die_friendly($lang->get('user_reg_err_disabled_title'), '<p>' . $lang->get('user_reg_err_disabled_body') . '</p>' . $s);
       
   667   }
       
   668   // are we locked out from logging in? if so, also lock out registration
       
   669   if ( getConfig('lockout_policy') === 'lockout' )
       
   670   {
       
   671     $ip = $db->escape($_SERVER['REMOTE_ADDR']);
       
   672     $threshold = time() - ( 60 * intval(getConfig('lockout_duration')) );
       
   673     $limit = intval(getConfig('lockout_threshold'));
       
   674     $q = $db->sql_query('SELECT * FROM ' . table_prefix . "lockout WHERE timestamp >= $threshold ORDER BY timestamp DESC;");
       
   675     if ( !$q )
       
   676       $db->_die();
       
   677     if ( $db->numrows() >= $limit )
       
   678     {
       
   679       $row = $db->fetchrow();
       
   680       $db->free_result();
       
   681       $time_rem = intval(getConfig('lockout_duration')) - round((time() - $row['timestamp']) / 60);
       
   682       die_friendly($lang->get('user_reg_err_disabled_title'), '<p>' . $lang->get('user_reg_err_locked_out', array('time' => $time_rem)) . '</p>');
       
   683     }
       
   684     $db->free_result();
   661   }
   685   }
   662   if ( $session->user_level < USER_LEVEL_ADMIN && $session->user_logged_in )
   686   if ( $session->user_level < USER_LEVEL_ADMIN && $session->user_logged_in )
   663   {
   687   {
   664     $paths->main_page();
   688     $paths->main_page();
   665   }
   689   }
  1780   }
  1804   }
  1781   echo '    </tr>
  1805   echo '    </tr>
  1782           </table>
  1806           </table>
  1783         </div>';
  1807         </div>';
  1784   
  1808   
  1785   // formatter parameters
       
  1786   $formatter = new MemberlistFormatter();
       
  1787   $formatters = array(
       
  1788     'username' => array($formatter, 'username'),
       
  1789     'user_level' => array($formatter, 'user_level'),
       
  1790     'email' => array($formatter, 'email'),
       
  1791     'reg_time' => array($formatter, 'reg_time')
       
  1792     );
       
  1793   
       
  1794   // User search             
  1809   // User search             
  1795   if ( isset($_GET['finduser']) )
  1810   if ( isset($_GET['finduser']) )
  1796   {
  1811   {
  1797     $finduser = str_replace(array(  '%',   '_'),
  1812     $finduser = str_replace(array(  '%',   '_'),
  1798                             array('\\%', '\\_'),
  1813                             array('\\%', '\\_'),
  1853     }
  1868     }
  1854     echo "<h3>$str</h3>";
  1869     echo "<h3>$str</h3>";
  1855   }
  1870   }
  1856   
  1871   
  1857   // main selector
  1872   // main selector
  1858   $q = $db->sql_unbuffered_query('SELECT u.user_id, u.username, u.reg_time, u.email, u.user_level, u.reg_time, x.email_public FROM '.table_prefix.'users AS u
  1873   $pgsql_additional_group_by = ( ENANO_DBLAYER == 'PGSQL' ) ? ', u.username, u.reg_time, u.email, u.user_level, u.user_has_avatar, u.avatar_type, x.email_public' : '';
       
  1874   $q = $db->sql_unbuffered_query('SELECT \'\' AS infobit, u.user_id, u.username, u.reg_time, u.email, u.user_level, u.user_has_avatar, u.avatar_type, x.email_public, COUNT(c.comment_id) AS num_comments FROM '.table_prefix.'users AS u
  1859                                     LEFT JOIN '.table_prefix.'users_extra AS x
  1875                                     LEFT JOIN '.table_prefix.'users_extra AS x
  1860                                       ON ( u.user_id = x.user_id )
  1876                                       ON ( u.user_id = x.user_id )
       
  1877                                     LEFT JOIN ' . table_prefix . 'comments AS c
       
  1878                                       ON ( u.user_id = c.user_id )
  1861                                     WHERE ' . $username_where . ' AND u.username != \'Anonymous\'
  1879                                     WHERE ' . $username_where . ' AND u.username != \'Anonymous\'
       
  1880                                     GROUP BY u.user_id' . $pgsql_additional_group_by . '
  1862                                     ORDER BY ' . $sort_sqllet . ' ' . $target_order . ';');
  1881                                     ORDER BY ' . $sort_sqllet . ' ' . $target_order . ';');
  1863   if ( !$q )
  1882   if ( !$q )
  1864     $db->_die();
  1883     $db->_die();
       
  1884   
       
  1885   // formatter parameters
       
  1886   $formatter = new MemberlistFormatter();
       
  1887   $formatters = array(
       
  1888     'username' => array($formatter, 'username'),
       
  1889     'user_level' => array($formatter, 'user_level'),
       
  1890     'email' => array($formatter, 'email'),
       
  1891     'reg_time' => array($formatter, 'reg_time'),
       
  1892     'infobit' => array($formatter, 'infobit')
       
  1893     );
  1865   
  1894   
  1866   $html = paginate(
  1895   $html = paginate(
  1867             $q,                                                                                                       // MySQL result resource
  1896             $q,                                                                                                       // MySQL result resource
  1868             '<tr>
  1897             '<tr>
  1869                <td class="{_css_class}">{user_id}</td>
  1898                <td class="{_css_class}">{user_id}</td>
  1870                <td class="{_css_class}" style="text-align: left;">{username}</td>
  1899                <td class="{_css_class}" style="text-align: left;">{username}</td>
  1871                <td class="{_css_class}">{user_level}</td>
  1900                <td class="{_css_class}">{user_level}</td>
  1872                <td class="{_css_class}">{email}</small></td>
  1901                <td class="{_css_class}">{email}</small></td>
  1873                <td class="{_css_class}">{reg_time}</td>
  1902                <td class="{_css_class}">{reg_time}</td>
       
  1903              </tr>
       
  1904              <tr>
       
  1905                <td colspan="5" class="row3" style="text-align: left;">
       
  1906                  <div id="ml_moreinfo_{user_id}" style="display: none;">
       
  1907                    {infobit}
       
  1908                  </div>
       
  1909                </td>
  1874              </tr>
  1910              </tr>
  1875              ',                                                                                                       // TPL code for rows
  1911              ',                                                                                                       // TPL code for rows
  1876              $num_rows,                                                                                               // Number of results
  1912              $num_rows,                                                                                               // Number of results
  1877              makeUrlNS('Special', 'Memberlist', ( str_replace('%', '%%', $finduser_url) ) . 'letter=' . $startletter . '&offset=%s&sort=' . $sortby . '&orderby=' . $target_order ), // Result URL
  1913              makeUrlNS('Special', 'Memberlist', ( str_replace('%', '%%', $finduser_url) ) . 'letter=' . $startletter . '&offset=%s&sort=' . $sortby . '&orderby=' . $target_order ), // Result URL
  1878              $offset,                                                                                                 // Start at this number
  1914              $offset,                                                                                                 // Start at this number
  1920   {
  1956   {
  1921     global $db, $session, $paths, $template, $plugins; // Common objects
  1957     global $db, $session, $paths, $template, $plugins; // Common objects
  1922     global $lang;
  1958     global $lang;
  1923     
  1959     
  1924     $userpage = $paths->nslist['User'] . sanitize_page_id($username);
  1960     $userpage = $paths->nslist['User'] . sanitize_page_id($username);
  1925     $class = ( isPage($userpage) ) ? ' title="' . $lang->get('userfuncs_ml_tip_userpage') . '"' : ' class="wikilink-nonexistent" title="' . $lang->get('userfuncs_ml_tip_nouserpage') . '"';
  1961     $class = ( isPage($userpage) ) ? '' : ' class="wikilink-nonexistent"';
  1926     $anchor = '<a href="' . makeUrlNS('User', sanitize_page_id($username)) . '"' . $class . '>' . htmlspecialchars($username) . '</a>';
  1962     $anchor = '<a href="' . makeUrlNS('User', sanitize_page_id($username)) . '"' . $class . ' onclick="load_component(\'SpryEffects\'); var el = document.getElementById(\'ml_moreinfo_' . $row['user_id'] . '\'); if ( !el.fx ) el.fx = new Spry.Effect.Blind(el, { duration: 500, from: \'0%\', to: \'100%\', toggle: true }); el.fx.start(); return false;">' . htmlspecialchars($username) . '</a>';
  1927     if ( $session->user_level >= USER_LEVEL_ADMIN )
  1963     if ( $session->user_level >= USER_LEVEL_ADMIN )
  1928     {
  1964     {
  1929       $anchor .= ' <small>- <a href="' . makeUrlNS('Special', 'Administration', 'module=' . $paths->nslist['Admin'] . 'UserManager&src=get&username=' . urlencode($username), true) . '"
  1965       $anchor .= ' <small>- <a href="' . makeUrlNS('Special', 'Administration', 'module=' . $paths->nslist['Admin'] . 'UserManager&src=get&username=' . urlencode($username), true) . '"
  1930                                onclick="ajaxAdminUser(\'' . addslashes(htmlspecialchars($username)) . '\'); return false;">' . $lang->get('userfuncs_ml_btn_adminuser') . '</a></small>';
  1966                                onclick="ajaxAdminUser(\'' . addslashes(htmlspecialchars($username)) . '\'); return false;">' . $lang->get('userfuncs_ml_btn_adminuser') . '</a></small>';
  1931     }
  1967     }
  2017   }
  2053   }
  2018   function reg_time($time, $row)
  2054   function reg_time($time, $row)
  2019   {
  2055   {
  2020     return $this->format_date($time);
  2056     return $this->format_date($time);
  2021   }
  2057   }
       
  2058   function infobit($_, $row)
       
  2059   {
       
  2060     global $db, $session, $paths, $template, $plugins; // Common objects
       
  2061     global $lang;
       
  2062     
       
  2063     $bit = '';
       
  2064     if ( $row['user_has_avatar'] == 1 )
       
  2065     {
       
  2066       $bit .= '<div style="float: left; margin-right: 10px;">
       
  2067         <img alt=" " src="' . make_avatar_url(intval($row['user_id']), $row['avatar_type'], $row['email']) . '" />
       
  2068       </div>';
       
  2069     }
       
  2070     $rank_data = $session->get_user_rank(intval($row['user_id']));
       
  2071     $userpage = $paths->nslist['User'] . sanitize_page_id($row['username']);
       
  2072     $title = ( isPage($userpage) ) ? ' title="' . $lang->get('userfuncs_ml_tip_userpage') . '"' : ' title="' . $lang->get('userfuncs_ml_tip_nouserpage') . '"';
       
  2073     $bit .= '<a' . $title . ' href="' . makeUrlNS('User', $row['username'], false, true) . '" style="font-size: x-large; ' . $rank_data['rank_style'] . '">' . htmlspecialchars($row['username']) . '</a><br />';
       
  2074     if ( $rank_data['user_title'] )
       
  2075       $bit .= htmlspecialchars($rank_data['user_title']) . '<br />';
       
  2076     if ( $rank_data['rank_title'] )
       
  2077       $bit .= '<small>' . htmlspecialchars($lang->get($rank_data['rank_title'])) . '</small><br />';
       
  2078     
       
  2079     $bit .= '<div style="text-align: right;">
       
  2080                <a href="' . makeUrlNS('Special', "PrivateMessages/Compose/To/{$row['username']}", false, true) . '" class="abutton abutton_blue"><img alt=" " src="' . cdnPath . '/images/icons/send_pm.png" /> ' . $lang->get('comment_btn_send_privmsg') . '</a>
       
  2081                <a href="' . makeUrlNS('Special', "PrivateMessages/FriendList/Add/{$row['username']}", false, true) . '" class="abutton abutton_green"><img alt=" " src="' . cdnPath . '/images/icons/add_buddy.png" /> ' . $lang->get('comment_btn_add_buddy') . '</a>
       
  2082              </div>';
       
  2083     
       
  2084     return $bit;
       
  2085   }
  2022 }
  2086 }
  2023 
  2087 
  2024 function page_Special_LangExportJSON()
  2088 function page_Special_LangExportJSON()
  2025 {
  2089 {
  2026   global $db, $session, $paths, $template, $plugins; // Common objects
  2090   global $db, $session, $paths, $template, $plugins; // Common objects
  2141     header("Last-Modified: $avi_mod_time");
  2205     header("Last-Modified: $avi_mod_time");
  2142     header("Content-Length: $avi_size");
  2206     header("Content-Length: $avi_size");
  2143     header("Content-Type: image/$avi_type");
  2207     header("Content-Type: image/$avi_type");
  2144     // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
  2208     // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
  2145     header("Cache-Control: public");
  2209     header("Cache-Control: public");
       
  2210     // expire it 30 days from now
       
  2211     $expiry_time = time() + ( 86400 * 30 );
       
  2212     header("Expires: " . date('r', $expiry_time));
  2146     
  2213     
  2147     $fh = @fopen($avi_path, 'r');
  2214     $fh = @fopen($avi_path, 'r');
  2148     if ( !$fh )
  2215     if ( !$fh )
  2149     {
  2216     {
  2150       echo 'Could not open file';
  2217       echo 'Could not open file';