Skip to content

Commit

Permalink
support ban outside Taiwan phone from SMS verification and verifydb
Browse files Browse the repository at this point in the history
Signed-off-by: Pichu Chen <[email protected]>
  • Loading branch information
PichuChen committed May 1, 2022
1 parent 2fae744 commit fb63a83
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void log_crosspost_in_allpost(const char *brd, const fileheader_t *postfile);
#ifdef USE_COOLDOWN
int check_cooldown(boardheader_t *bp);
#endif
bool is_user_sms_verified();

/* board */
#define setutmpbid(bid) currutmp->brc_id=bid;
Expand Down
1 change: 1 addition & 0 deletions include/pttstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ typedef struct boardheader_t { /* 256 bytes */
#define BRD_ALIGNEDCMT 0x04000000 /* 對齊式的推文 */
#define BRD_NOSELFDELPOST 0x08000000 /* 不可自刪 */
#define BRD_BM_MASK_CONTENT 0x10000000 /* 允許板主刪除特定文字 */
#define BRD_NEEDS_SMS_VERIFICATION 0x20000000 /* 允許版主設定看板發文需完成過簡訊認證 */

// Board group linked-list type. Used for array index of firstchild and next.
#define BRD_GROUP_LL_TYPE_NAME (0)
Expand Down
32 changes: 32 additions & 0 deletions mbbsd/bbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,38 @@ int IsFreeBoardName(const char *brdname)
return 0;
}

/*
* Check if user phone number is verified by sms
*
* This function will check is current user have already register their
* phone number with verifydb library.
* The verify process is modified from verifydb_check_vmethod_unused,
* it will pass cuser.userid and cuser.firstlogin as parameter and find
* VMETHOD_SMS record.
*
* Note that, ptt system might has two different user has the same userid
* but won't be happen in same time, so we need firstlogin as second
* parameter, and ptt accept Taiwan phone register only since Jul. 2021
* so we can just verify whether in database.
*
* Return true when user has verified phone, false when no register record
*/
bool
is_user_sms_verified()
{
Bytes buf;
const VerifyDb::GetReply *reply;
if (!verifydb_getuser(cuser.userid, cuser.firstlogin, &buf, &reply)) {
// The verifydb may occur some problem, maybe we should log it and
// notifiy SYSOP?
return false;
}
if (verifydb_find_vmethod(reply, VMETHOD_SMS)) {
return true;
}
return false;
}

int
CheckModifyPerm(const char **preason)
{
Expand Down
10 changes: 10 additions & 0 deletions mbbsd/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ b_config(void)
(bp->brdattr & BRD_OVER18) ?
ANSI_COLOR(1) "禁止 " : "允許\ " );

prints( " " ANSI_COLOR(1;36) "t" ANSI_RESET
" - %s" ANSI_RESET "已驗證台灣門號發/推文\n",
(bp->brdattr & BRD_TAIWAN_PHONE_ONLY) ?
ANSI_COLOR(1) "限定 " : "不限定 " );

if (!canpost)
outs(ANSI_COLOR(1;31)" ★ 您在此看板無發文或推文權限,"
"詳細原因請參考上面顯示為紅色或有 * 的項目。"ANSI_RESET"\n");
Expand Down Expand Up @@ -813,6 +818,11 @@ b_config(void)
}
break;

case 't':
bp->brdattr ^= BRD_NEEDS_SMS_VERIFICATION;
touched = 1;
break;

case 'v':
clear();
friend_edit(BOARD_VISABLE);
Expand Down
4 changes: 4 additions & 0 deletions mbbsd/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ postperm_msg(const char *bname)
assert(0<=i-1 && i-1<MAX_BOARD);
bp = getbcache(i);

if (bp->brdattr & BRD_TAIWAN_PHONE_ONLY)
if (!is_user_sms_verified())
return "看板限定已驗證台灣門號發/推文";

if (bp->brdattr & BRD_GUESTPOST)
return NULL;

Expand Down

0 comments on commit fb63a83

Please sign in to comment.