Exemplo n.º 1
0
/**
 * Triggered on login_success
 * 
 * Redirect user to profile page and displays a message to make him change his password for synch with FluxBB
 * 
 */
function Register_FluxBB_Login()
{
    global $conf, $user;
    if (Reg_FluxBB_PwdSynch($user['id'])) {
        redirect(PHPWG_ROOT_PATH . 'profile.php');
    }
}
Exemplo n.º 2
0
function Audit_PWG_FluxBB()
{
    global $page, $conf, $errors;
    $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']);
    $msg_error_PWG_Dup = '';
    $msg_error_FluxBB_Dup = '';
    $msg_error_Link_Break = '';
    $msg_error_Link_Bad = '';
    $msg_error_Synchro = '';
    $msg_ok_Synchro = '';
    $msg_error_PWG2FluxBB = '';
    $msg_error_FluxBB2PWG = '';
    // Check duplicate accounts in Piwigo users table
    // ----------------------------------------------
    $query = '
SELECT COUNT(*) AS nbr_dup, id, username
FROM ' . USERS_TABLE . '
WHERE username NOT IN ("18","16")
GROUP BY BINARY username
HAVING COUNT(*) > 1
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        $msg_error_PWG_Dup .= '<br>' . l10n('Error_PWG_Dup') . $row['nbr_dup'] . ' x ' . stripslashes($row['username']);
    }
    // Display OK message or build errors
    if ($msg_error_PWG_Dup == '') {
        array_push($page['infos'], l10n('Audit_PWG_Dup') . '<br>' . l10n('Audit_OK'));
    } else {
        $msg_error_PWG_Dup = l10n('Audit_PWG_Dup') . $msg_error_PWG_Dup . '<br>' . l10n('Advise_PWG_Dup');
    }
    // Check duplicate accounts in FluxBB users table
    // ----------------------------------------------
    $query = '
SELECT COUNT(*) AS nbr_dup, username
FROM ' . FluxBB_USERS_TABLE . ' 
GROUP BY BINARY username
HAVING COUNT(*) > 1
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        $msg_error_FluxBB_Dup .= '<br>' . l10n('Error_FluxBB_Dup') . $row['nbr_dup'] . ' x ' . stripslashes($row['username']);
        $subquery = '
SELECT id, username, email
FROM ' . FluxBB_USERS_TABLE . ' 
WHERE BINARY username = BINARY "' . $row['username'] . '"
;';
        $subresult = pwg_query($subquery);
        while ($subrow = pwg_db_fetch_assoc($subresult)) {
            $msg_error_FluxBB_Dup .= '<br>id:' . $subrow['id'] . '=' . stripslashes($subrow['username']) . ' (' . $subrow['email'] . ')';
            // Action : Delete duplicate user from FluxBB
            $msg_error_FluxBB_Dup .= ' <a href="';
            $msg_error_FluxBB_Dup .= add_url_params(REGFLUXBB_ADMIN, array('action' => 'del_user', 'id' => $subrow['id']));
            $msg_error_FluxBB_Dup .= '" title="' . l10n('Del_User') . stripslashes($subrow['username']) . '"';
            $msg_error_FluxBB_Dup .= $conf_Register_FluxBB['FLUXBB_CONFIRM'] == 'false' ? ' onclick="return confirm(\'' . l10n('Are you sure?') . '\');" ' : ' ';
            $msg_error_FluxBB_Dup .= '><img src="' . REGFLUXBB_PATH . '/admin/template/icon/user_delete.png" alt="' . l10n('Del_User') . $subrow['username'] . '" /></a>';
        }
    }
    // Display OK message or build errors
    if ($msg_error_FluxBB_Dup == '') {
        array_push($page['infos'], l10n('Audit_FluxBB_Dup') . '<br>' . l10n('Audit_OK'));
    } else {
        $msg_error_FluxBB_Dup = l10n('Audit_FluxBB_Dup') . $msg_error_FluxBB_Dup . '<br>' . l10n('Advise_FluxBB_Dup');
    }
    // Check links between Piwigo and FluxBB users
    // -------------------------------------------
    // Check fixable broken links between Piwigo and FluxBB users
    // ----------------------------------------------------------
    $query = '
SELECT pwg.id as pwg_id, bb.id as bb_id, pwg.username as pwg_user, pwg.mail_address as pwg_mail
FROM ' . FluxBB_USERS_TABLE . ' AS bb, ' . USERS_TABLE . ' as pwg
WHERE bb.id NOT in (
  SELECT id_user_FluxBB
  FROM ' . Register_FluxBB_ID_TABLE . '
  )
AND pwg.id NOT in (
  SELECT id_user_pwg
  FROM ' . Register_FluxBB_ID_TABLE . '
  )
AND pwg.username = bb.username
AND pwg.username NOT IN ("18","16")
AND pwg.mail_address = bb.email
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        $msg_error_Link_Break .= '<br>' . l10n('Error_Link_Break') . stripslashes($row['pwg_user']) . ' (' . $row['pwg_mail'] . ')';
        // Action : Create new link
        $msg_error_Link_Break .= ' <a href="';
        $msg_error_Link_Break .= add_url_params(REGFLUXBB_ADMIN, array('action' => 'new_link', 'pwg_id' => $row['pwg_id'], 'bb_id' => $row['bb_id']));
        $msg_error_Link_Break .= '" title="' . l10n('New_Link') . stripslashes($row['pwg_user']) . '"';
        $msg_error_Link_Break .= $conf_Register_FluxBB['FLUXBB_CONFIRM'] == 'false' ? ' onclick="return confirm(\'' . l10n('Are you sure?') . '\');" ' : ' ';
        $msg_error_Link_Break .= '><img src="' . REGFLUXBB_PATH . '/admin/template/icon/link_break.png" alt="' . l10n('New_Link') . stripslashes($row['pwg_user']) . '" /></a>';
    }
    // Display OK message or build errors
    if ($msg_error_Link_Break == '') {
        array_push($page['infos'], l10n('Audit_Link_Break') . '<br>' . l10n('Audit_OK'));
    } else {
        $msg_error_Link_Break = l10n('Audit_Link_Break') . $msg_error_Link_Break;
    }
    // Check not fixable broken links between Piwigo and FluxBB users
    // --------------------------------------------------------------
    $query = '
SELECT pwg.username as pwg_user, pwg.id as pwg_id, pwg.mail_address as pwg_mail, bb.id as bb_id, bb.username as bb_user, bb.email as bb_mail
FROM ' . FluxBB_USERS_TABLE . ' AS bb 
INNER JOIN ' . Register_FluxBB_ID_TABLE . ' AS link ON link.id_user_FluxBB = bb.id
INNER JOIN ' . USERS_TABLE . ' as pwg ON link.id_user_pwg = pwg.id
WHERE pwg.username <> bb.username
AND pwg.username NOT IN ("18","16")
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        $msg_error_Link_Bad .= '<br>' . l10n('Error_Link_Del') . stripslashes($row['pwg_user']) . ' (' . $row['pwg_mail'] . ')' . ' -- ' . stripslashes($row['bb_user']) . ' (' . $row['bb_mail'] . ')';
        // Action : Delete obsolete links
        $msg_error_Link_Bad .= ' <a href="';
        $msg_error_Link_Bad .= add_url_params(REGFLUXBB_ADMIN, array('action' => 'link_del', 'pwg_id' => $row['pwg_id'], 'bb_id' => $row['bb_id']));
        $msg_error_Link_Bad .= '" title="' . l10n('Link_Del') . stripslashes($row['pwg_user']) . ' -- ' . stripslashes($row['bb_user']) . '"';
        $msg_error_Link_Bad .= $conf_Register_FluxBB['FLUXBB_CONFIRM'] == 'false' ? ' onclick="return confirm(\'' . l10n('Are you sure?') . '\');" ' : ' ';
        $msg_error_Link_Bad .= '><img src="' . REGFLUXBB_PATH . '/admin/template/icon/link_delete.png" alt="' . l10n('Link_Del') . stripslashes($row['pwg_user']) . ' -- ' . stripslashes($row['bb_user']) . '" /></a>';
        // Action : Synch users data
        $msg_error_Link_Bad .= ' -- <a href="';
        $msg_error_Link_Bad .= add_url_params(REGFLUXBB_ADMIN, array('action' => 'sync_user', 'username' => stripslashes($row['pwg_user'])));
        $msg_error_Link_Bad .= '" title="' . l10n('Sync_User') . stripslashes($row['pwg_user']) . ' --> ' . stripslashes($row['bb_user']) . '"';
        $msg_error_Link_Bad .= $conf_Register_FluxBB['FLUXBB_CONFIRM'] == 'false' ? ' onclick="return confirm(\'' . l10n('Are you sure?') . '\');" ' : ' ';
        $msg_error_Link_Bad .= '><img src="' . REGFLUXBB_PATH . '/admin/template/icon/arrow_switch.png" alt="' . l10n('Sync_User') . stripslashes($row['pwg_user']) . ' --> ' . stripslashes($row['bb_user']) . '" /></a>';
    }
    // Check dead links between Piwigo and FluxBB users
    // ------------------------------------------------
    $query = '
SELECT COUNT(*) as nbr_dead
FROM ' . Register_FluxBB_ID_TABLE . ' AS Link
WHERE id_user_FluxBB NOT IN (
  SELECT id
  FROM ' . FluxBB_USERS_TABLE . '
  )
OR id_user_pwg NOT IN (
  SELECT id
  FROM ' . USERS_TABLE . '
  )
;';
    $Compteur = pwg_db_fetch_assoc(pwg_query($query));
    if (!empty($Compteur) and $Compteur['nbr_dead'] > 0) {
        $msg_error_Link_Bad .= '<br>' . l10n('Error_Link_Dead') . $Compteur['nbr_dead'];
        // Action : Repair dead links
        $msg_error_Link_Bad .= ' <a href="';
        $msg_error_Link_Bad .= add_url_params(REGFLUXBB_ADMIN, array('action' => 'link_dead'));
        $msg_error_Link_Bad .= '" title="' . l10n('Link_Dead') . $Compteur['nbr_dead'] . '"';
        $msg_error_Link_Bad .= $conf_Register_FluxBB['FLUXBB_CONFIRM'] == 'false' ? ' onclick="return confirm(\'' . l10n('Are you sure?') . '\');" ' : ' ';
        $msg_error_Link_Bad .= '><img src="' . REGFLUXBB_PATH . '/admin/template/icon/link_delete.png" alt="' . l10n('Link_Dead') . $Compteur['nbr_dead'] . '" /></a>';
    }
    // Check duplicated links between Piwigo and FluxBB users
    // ------------------------------------------------------
    $query = '
SELECT COUNT(*) AS nbr_dup, pwg.id AS pwg_id, pwg.username AS pwg_user, bb.username AS bb_user, bb.id AS bb_id
FROM ' . FluxBB_USERS_TABLE . ' AS bb 
INNER JOIN ' . Register_FluxBB_ID_TABLE . ' AS link ON link.id_user_FluxBB = bb.id
INNER JOIN ' . USERS_TABLE . ' as pwg ON link.id_user_pwg = pwg.id
WHERE pwg.username NOT IN ("18","16")
GROUP BY link.id_user_pwg, link.id_user_FluxBB
HAVING COUNT(*) > 1
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        $msg_error_Link_Bad .= '<br>' . l10n('Error_Link_Dup') . $row['nbr_dup'] . ' = ' . stripslashes($row['pwg_user']) . ' -- ' . stripslashes($row['bb_user']) . ')';
        // Action : Repair links
        $msg_error_Link_Bad .= ' <a href="';
        $msg_error_Link_Bad .= add_url_params(REGFLUXBB_ADMIN, array('action' => 'new_link', 'pwg_id' => $row['pwg_id'], 'bb_id' => $row['bb_id']));
        $msg_error_Link_Bad .= '" title="' . l10n('Link_Dup') . stripslashes($row['pwg_user']) . ' -- ' . stripslashes($row['bb_user']) . '"';
        $msg_error_Link_Bad .= $conf_Register_FluxBB['FLUXBB_CONFIRM'] == 'false' ? ' onclick="return confirm(\'' . l10n('Are you sure?') . '\');" ' : ' ';
        $msg_error_Link_Bad .= '><img src="' . REGFLUXBB_PATH . '/admin/template/icon/link_error.png" alt="' . l10n('Link_Dup') . stripslashes($row['pwg_user']) . ' -- ' . stripslashes($row['bb_user']) . '" /></a>';
    }
    // Display OK message or build errors
    if ($msg_error_Link_Bad == '') {
        array_push($page['infos'], l10n('Audit_Link_Bad') . '<br>' . l10n('Audit_OK'));
    } else {
        $msg_error_Link_Bad = l10n('Audit_Link_Bad') . $msg_error_Link_Bad;
    }
    // Check synch between Piwigo and FluxBB users
    // -------------------------------------------
    $query = '
SELECT pwg.id as pwg_id, pwg.username as username, pwg.mail_address as pwg_eml, FluxBB.email as bb_eml
FROM ' . FluxBB_USERS_TABLE . ' AS FluxBB 
INNER JOIN ' . Register_FluxBB_ID_TABLE . ' AS link ON link.id_user_FluxBB = FluxBB.id
INNER JOIN ' . USERS_TABLE . ' as pwg ON link.id_user_pwg = pwg.id
WHERE BINARY pwg.username = BINARY FluxBB.username
AND pwg.username NOT IN ("18","16")
ORDER BY LOWER(pwg.username)
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        if ($row['pwg_eml'] != $row['bb_eml'] or Reg_FluxBB_PwdSynch($row['pwg_id'])) {
            if ($row['pwg_eml'] != $row['bb_eml'] and Reg_FluxBB_PwdSynch($row['pwg_id'])) {
                $msg_error_Synchro .= '<br>' . l10n('Error_Synchro') . stripslashes($row['username']);
                // Action : Synch users data from Piwigo to FluxBB
                $msg_error_Synchro .= ' <a href="';
                $msg_error_Synchro .= add_url_params(REGFLUXBB_ADMIN, array('action' => 'sync_user', 'username' => stripslashes($row['username'])));
                $msg_error_Synchro .= '" title="' . l10n('Sync_User') . stripslashes($row['username']) . '"';
                $msg_error_Synchro .= $conf_Register_FluxBB['FLUXBB_CONFIRM'] == 'false' ? ' onclick="return confirm(\'' . l10n('Are you sure?') . '\');" ' : ' ';
                $msg_error_Synchro .= '><img src="' . REGFLUXBB_PATH . '/admin/template/icon/user_refresh.png" alt="' . l10n('Sync_User') . stripslashes($row['username']) . '" /></a>';
                $msg_error_Synchro .= '<br>' . l10n('Error_Synchro_Mail') . '<br>-- PWG = ' . $row['pwg_eml'] . '<br>-- FluxBB = ' . $row['bb_eml'];
                $msg_error_Synchro .= '<br>' . l10n('Error_Synchro_Pswd');
            } elseif ($row['pwg_eml'] != $row['bb_eml'] and !Reg_FluxBB_PwdSynch($row['pwg_id'])) {
                $msg_error_Synchro .= '<br>' . l10n('Error_Synchro') . stripslashes($row['username']);
                // Action : Synch users data from Piwigo to FluxBB
                $msg_error_Synchro .= ' <a href="';
                $msg_error_Synchro .= add_url_params(REGFLUXBB_ADMIN, array('action' => 'sync_user', 'username' => stripslashes($row['username'])));
                $msg_error_Synchro .= '" title="' . l10n('Sync_User') . stripslashes($row['username']) . '"';
                $msg_error_Synchro .= $conf_Register_FluxBB['FLUXBB_CONFIRM'] == 'false' ? ' onclick="return confirm(\'' . l10n('Are you sure?') . '\');" ' : ' ';
                $msg_error_Synchro .= '><img src="' . REGFLUXBB_PATH . '/admin/template/icon/user_refresh.png" alt="' . l10n('Sync_User') . stripslashes($row['username']) . '" /></a>';
                $msg_error_Synchro .= '<br>' . l10n('Error_Synchro_Mail') . '<br>-- PWG = ' . $row['pwg_eml'] . '<br>-- FluxBB = ' . $row['bb_eml'];
            } elseif ($row['pwg_eml'] = $row['bb_eml'] and Reg_FluxBB_PwdSynch($row['pwg_id'])) {
                $msg_error_Synchro .= '<br>' . l10n('Error_Synchro') . stripslashes($row['username']);
                $msg_error_Synchro .= '<br>' . l10n('Error_Synchro_Pswd');
            }
        } else {
            if ($conf_Register_FluxBB['FLUXBB_DETAIL'] == 'true') {
                $msg_ok_Synchro .= '<br> - ' . stripslashes($row['username']) . ' (' . $row['pwg_eml'] . ')' . l10n('Audit_Synchro_OK');
            }
        }
    }
    // Display OK message or build errors
    if ($msg_error_Synchro != '') {
        $msg_error_Synchro = l10n('Audit_Synchro') . $msg_error_Synchro;
    }
    if ($msg_ok_Synchro != '') {
        if ($msg_error_Synchro != '') {
            array_push($page['infos'], l10n('Audit_Synchro') . $msg_ok_Synchro . '<br><br>');
        } else {
            array_push($page['infos'], l10n('Audit_Synchro') . $msg_ok_Synchro . '<br><br>' . l10n('Audit_OK'));
        }
    }
    // Check Piwigo accounts not in FluxBB
    // -----------------------------------
    $query = '
SELECT username, mail_address FROM ' . USERS_TABLE . '
WHERE BINARY username <> BINARY "guest"
AND username NOT IN ("18","16")
AND id not in (
  SELECT id_user_pwg FROM ' . Register_FluxBB_ID_TABLE . '
  )
AND BINARY username not in (
  SELECT username FROM ' . FluxBB_USERS_TABLE . '
  )
ORDER BY LOWER(username)
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        $msg_error_PWG2FluxBB .= '<br>' . l10n('Error_PWG2FluxBB') . stripslashes($row['username']) . ' (' . $row['mail_address'] . ')';
        // Action : Add user to FluxBB
        $msg_error_PWG2FluxBB .= ' <a href="';
        $msg_error_PWG2FluxBB .= add_url_params(REGFLUXBB_ADMIN, array('action' => 'add_user', 'username' => stripslashes($row['username'])));
        $msg_error_PWG2FluxBB .= '" title="' . l10n('Add_User') . stripslashes($row['username']) . '" ';
        $msg_error_PWG2FluxBB .= $conf_Register_FluxBB['FLUXBB_CONFIRM'] == 'false' ? ' onclick="return confirm(\'' . l10n('Are you sure?') . '\');" ' : ' ';
        $msg_error_PWG2FluxBB .= '><img src="' . REGFLUXBB_PATH . '/admin/template/icon/user_add.png" alt="' . l10n('Add_User') . stripslashes($row['username']) . '" /></a>';
    }
    // Display OK message or build errors
    if ($msg_error_PWG2FluxBB == '') {
        array_push($page['infos'], l10n('Audit_PWG2FluxBB') . '<br>' . l10n('Audit_OK'));
    } else {
        $msg_error_PWG2FluxBB = l10n('Audit_PWG2FluxBB') . $msg_error_PWG2FluxBB;
    }
    // Check FluxBB accounts not in Piwigo
    // -----------------------------------
    $query = '
SELECT id, username, email FROM ' . FluxBB_USERS_TABLE . '
WHERE BINARY username <> BINARY "' . $conf_Register_FluxBB['FLUXBB_GUEST'] . '"
AND id not in (
  SELECT id_user_FluxBB FROM ' . Register_FluxBB_ID_TABLE . '
  )
AND BINARY username not in (
  SELECT username FROM ' . USERS_TABLE . '
  )
ORDER BY LOWER(username)
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        $msg_error_FluxBB2PWG .= '<br>' . l10n('Error_FluxBB2PWG') . stripslashes($row['username']) . ' (' . $row['email'] . ')';
        // Action : Delete user from FluxBB
        $msg_error_FluxBB2PWG .= ' <a href="';
        $msg_error_FluxBB2PWG .= add_url_params(REGFLUXBB_ADMIN, array('action' => 'del_user', 'id' => $row['id']));
        $msg_error_FluxBB2PWG .= '" title="' . l10n('Del_User') . stripslashes($row['username']) . '"';
        $msg_error_FluxBB2PWG .= $conf_Register_FluxBB['FLUXBB_CONFIRM'] == 'false' ? ' onclick="return confirm(\'' . l10n('Are you sure?') . '\');" ' : ' ';
        $msg_error_FluxBB2PWG .= '><img src="' . REGFLUXBB_PATH . '/admin/template/icon/user_delete.png" alt="' . l10n('Del_User') . stripslashes($row['username']) . '" /></a>';
        // Action : Add user from FluxBB to Piwigo
        $msg_error_FluxBB2PWG .= ' <a href="';
        $msg_error_FluxBB2PWG .= add_url_params(REGFLUXBB_ADMIN, array('action' => 'add2pwg', 'id' => $row['id'], 'username' => $row['username'], 'email' => $row['email']));
        $msg_error_FluxBB2PWG .= '" title="' . l10n('Add_User2pwg') . stripslashes($row['username']) . '"';
        $msg_error_FluxBB2PWG .= $conf_Register_FluxBB['FLUXBB_CONFIRM'] == 'false' ? ' onclick="return confirm(\'' . l10n('Are you sure?') . '\');" ' : ' ';
        $msg_error_FluxBB2PWG .= '><img src="' . REGFLUXBB_PATH . '/admin/template/icon/user_add.png" alt="' . l10n('Add_User2pwg') . stripslashes($row['username']) . '" /></a>';
    }
    // Display OK message or build errors
    if ($msg_error_FluxBB2PWG == '') {
        array_push($page['infos'], l10n('Audit_FluxBB2PWG') . '<br>' . l10n('Audit_OK'));
    } else {
        $msg_error_FluxBB2PWG = l10n('Audit_FluxBB2PWG') . $msg_error_FluxBB2PWG;
    }
    if ($msg_error_PWG_Dup != '') {
        $errors[] = $msg_error_PWG_Dup . (($msg_error_FluxBB_Dup == '' and $msg_error_Link_Break == '' and $msg_error_Link_Bad == '' and $msg_error_Synchro == '' and $msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br><br>');
    }
    if ($msg_error_FluxBB_Dup != '') {
        $errors[] = $msg_error_FluxBB_Dup . (($msg_error_Link_Break == '' and $msg_error_Link_Bad == '' and $msg_error_Synchro == '' and $msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br><br>');
    }
    if ($msg_error_Link_Break != '') {
        $errors[] = $msg_error_Link_Break . (($msg_error_Link_Bad == '' and $msg_error_Synchro == '' and $msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br><br>');
    }
    if ($msg_error_Link_Bad != '') {
        $errors[] = $msg_error_Link_Bad . (($msg_error_Synchro == '' and $msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br><br>');
    }
    if ($msg_error_Synchro != '') {
        $errors[] = $msg_error_Synchro . (($msg_error_PWG2FluxBB == '' and $msg_error_FluxBB2PWG == '') ? '' : '<br><br>');
    }
    if ($msg_error_PWG2FluxBB != '') {
        $errors[] = $msg_error_PWG2FluxBB . ($msg_error_FluxBB2PWG == '' ? '' : '<br><br>');
    }
    if ($msg_error_FluxBB2PWG != '') {
        $errors[] = $msg_error_FluxBB2PWG;
    }
    if (isset($errors) and count($errors) != 0) {
        foreach ($errors as $error) {
            array_push($page['errors'], $error);
        }
    }
}