2020-12-26 01:42:23 +08:00
<? php
2023-01-05 18:29:31 +08:00
2021-01-13 19:32:26 +08:00
require_once ( "../include/bittorrent.php" );
2020-12-26 01:42:23 +08:00
dbconn ();
cur_user_check ();
2025-04-21 11:57:24 +07:00
//require_once(get_langfile_path("",true));
2020-12-26 01:42:23 +08:00
require_once ( get_langfile_path ( "" , false , get_langfolder_cookie ()));
2023-08-24 02:28:58 +08:00
$isPreRegisterEmailAndUsername = get_setting ( "system.is_invite_pre_email_and_username" ) == "yes" ;
2020-12-26 01:42:23 +08:00
function bark ( $msg ) {
global $lang_takesignup ;
stdhead ();
stdmsg ( $lang_takesignup [ 'std_signup_failed' ], $msg );
stdfoot ();
exit ;
}
2025-10-01 12:01:53 +07:00
$type = $_POST [ 'type' ] ?? '' ;
2020-12-26 01:42:23 +08:00
if ( $type == 'invite' ){
registration_check ();
failedloginscheck ( "Invite Signup" );
if ( $iv == "yes" )
2025-10-11 23:38:27 +08:00
check_code ( $_POST [ 'imagehash' ] ?? null , $_POST [ 'imagestring' ] ?? null , 'signup.php?type=invite&invitenumber=' . htmlspecialchars ( $_POST [ 'hash' ]));
2020-12-26 01:42:23 +08:00
}
else {
registration_check ( "normal" );
failedloginscheck ( "Signup" );
if ( $iv == "yes" )
2025-10-11 23:38:27 +08:00
check_code ( $_POST [ 'imagehash' ] ?? null , $_POST [ 'imagestring' ] ?? null );
2020-12-26 01:42:23 +08:00
}
function isportopen ( $port )
{
$sd = @ fsockopen ( $_SERVER [ "REMOTE_ADDR" ], $port , $errno , $errstr , 1 );
if ( $sd )
{
fclose ( $sd );
return true ;
}
else
return false ;
}
function isproxy ()
{
$ports = array ( 80 , 88 , 1075 , 1080 , 1180 , 1182 , 2282 , 3128 , 3332 , 5490 , 6588 , 7033 , 7441 , 8000 , 8080 , 8085 , 8090 , 8095 , 8100 , 8105 , 8110 , 8888 , 22788 );
for ( $i = 0 ; $i < count ( $ports ); ++ $i )
if ( isportopen ( $ports [ $i ])) return true ;
return false ;
}
if ( $type == 'invite' )
{
$inviter = $_POST [ "inviter" ];
int_check ( $inviter );
$code = unesc ( $_POST [ "hash" ]);
//check invite code
2023-08-24 02:28:58 +08:00
$sq = sprintf ( "SELECT * FROM invites WHERE valid = %s and hash ='%s'" , \App\Models\Invite :: VALID_YES , mysql_real_escape_string ( $code ));
2020-12-26 01:42:23 +08:00
$res = sql_query ( $sq ) or sqlerr ( __FILE__ , __LINE__ );
$inv = mysql_fetch_assoc ( $res );
if ( ! $inv )
bark ( 'invalid invite code' );
2021-05-04 14:21:18 +08:00
if ( $inv [ 'inviter' ] != $inviter ) {
2021-05-10 20:05:52 +08:00
\App\Models\Invite :: query () -> where ( 'id' , $inv [ 'id' ]) -> update ([ 'valid' => \App\Models\Invite :: VALID_NO ]);
2021-05-04 14:21:18 +08:00
stderr ( nexus_trans ( 'nexus.invalid_argument' ), nexus_trans ( 'invite.invalid_inviter' ));
exit ();
}
2020-12-26 01:42:23 +08:00
$ip = getip ();
$res = sql_query ( "SELECT username FROM users WHERE id = $inviter " ) or sqlerr ( __FILE__ , __LINE__ );
$arr = mysql_fetch_assoc ( $res );
2021-02-28 02:57:50 +08:00
$invusername = $arr [ 'username' ];
2020-12-26 01:42:23 +08:00
}
2025-04-05 15:38:40 +07:00
if ( ! mkglobal ( "wantusername:wantpassword:email" )) {
2023-08-24 02:28:58 +08:00
die ();
}
2023-08-28 02:54:17 +08:00
if ( $isPreRegisterEmailAndUsername && $type == 'invite' && ! empty ( $inv [ "pre_register_username" ]) && ! empty ( $inv [ "pre_register_email" ])) {
2023-08-24 02:28:58 +08:00
$wantusername = $inv [ "pre_register_username" ];
$email = $inv [ "pre_register_email" ];
}
2020-12-26 01:42:23 +08:00
$email = htmlspecialchars ( trim ( $email ));
$email = safe_email ( $email );
if ( ! check_email ( $email ))
bark ( $lang_takesignup [ 'std_invalid_email_address' ]);
2021-05-04 14:21:18 +08:00
2020-12-26 01:42:23 +08:00
if ( EmailBanned ( $email ))
bark ( $lang_takesignup [ 'std_email_address_banned' ]);
if ( ! EmailAllowed ( $email ))
bark ( $lang_takesignup [ 'std_wrong_email_address_domains' ] . allowedemails ());
$country = $_POST [ "country" ];
int_check ( $country );
if ( $showschool == 'yes' ){
$school = $_POST [ "school" ];
int_check ( $school );
}
2021-05-04 14:21:18 +08:00
$gender = htmlspecialchars ( trim ( $_POST [ "gender" ]));
2020-12-26 01:42:23 +08:00
$allowed_genders = array ( "Male" , "Female" , "male" , "female" );
if ( ! in_array ( $gender , $allowed_genders , true ))
bark ( $lang_takesignup [ 'std_invalid_gender' ]);
2021-05-04 14:21:18 +08:00
2020-12-26 01:42:23 +08:00
if ( empty ( $wantusername ) || empty ( $wantpassword ) || empty ( $email ) || empty ( $country ) || empty ( $gender ))
bark ( $lang_takesignup [ 'std_blank_field' ]);
2021-05-04 14:21:18 +08:00
2020-12-26 01:42:23 +08:00
if ( strlen ( $wantusername ) > 12 )
bark ( $lang_takesignup [ 'std_username_too_long' ]);
2025-04-05 15:38:40 +07:00
//if ($wantpassword != $passagain)
// bark($lang_takesignup['std_passwords_unmatched']);
2020-12-26 01:42:23 +08:00
2025-04-05 15:38:40 +07:00
//if (strlen($wantpassword) < 6)
// bark($lang_takesignup['std_password_too_short']);
//
//if (strlen($wantpassword) > 40)
// bark($lang_takesignup['std_password_too_long']);
//
//if ($wantpassword == $wantusername)
// bark($lang_takesignup['std_password_equals_username']);
2020-12-26 01:42:23 +08:00
if ( ! validemail ( $email ))
bark ( $lang_takesignup [ 'std_wrong_email_address_format' ]);
if ( ! validusername ( $wantusername ))
bark ( $lang_takesignup [ 'std_invalid_username' ]);
2021-05-04 14:21:18 +08:00
2020-12-26 01:42:23 +08:00
// make sure user agrees to everything...
if ( $_POST [ "rulesverify" ] != "yes" || $_POST [ "faqverify" ] != "yes" || $_POST [ "ageverify" ] != "yes" )
stderr ( $lang_takesignup [ 'std_signup_failed' ], $lang_takesignup [ 'std_unqualified' ]);
// check if email addy is already in use
2025-04-17 01:39:40 +07:00
$a = ( @ mysql_fetch_row ( @ sql_query ( "select count(*) from users where BINARY email='" . mysql_real_escape_string ( $email ) . "'" ))) or sqlerr ( __FILE__ , __LINE__ );
2020-12-26 01:42:23 +08:00
if ( $a [ 0 ] != 0 )
bark ( $lang_takesignup [ 'std_email_address' ] . $email . $lang_takesignup [ 'std_in_use' ]);
2021-05-04 14:21:18 +08:00
2020-12-26 01:42:23 +08:00
/*
// do simple proxy check
if (isproxy())
bark("You appear to be connecting through a proxy server. Your organization or ISP may use a transparent caching HTTP proxy. Please try and access the site on <a href="." . get_protocol_prefix() . "$BASEURL.":81/signup.php>port 81</a> (this should bypass the proxy server). <p><b>Note:</b> if you run an Internet-accessible web server on the local machine you need to shut it down until the sign-up is complete.");
$res = sql_query("SELECT COUNT(*) FROM users") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_row($res);
*/
$secret = mksecret ();
2025-04-05 15:38:40 +07:00
//$wantpasshash = md5($secret . $wantpassword . $secret);
$wantpasshash = hash ( 'sha256' , $secret . $wantpassword );
2020-12-26 01:42:23 +08:00
$editsecret = ( $verification == 'admin' ? '' : $secret );
$invite_count = ( int ) $invite_count ;
2024-10-10 21:04:35 +08:00
$passkey = md5 ( $wantusername . date ( "Y-m-d H:i:s" ) . $wantpasshash );
2020-12-26 01:42:23 +08:00
$wantusername = sqlesc ( $wantusername );
$wantpasshash = sqlesc ( $wantpasshash );
$secret = sqlesc ( $secret );
$editsecret = sqlesc ( $editsecret );
$send_email = $email ;
$email = sqlesc ( $email );
$country = sqlesc ( $country );
$gender = sqlesc ( $gender );
$sitelangid = sqlesc ( get_langid_from_langcookie ());
2025-04-05 15:38:40 +07:00
$authKey = sqlesc ( mksecret ());
2020-12-26 01:42:23 +08:00
$res_check_user = sql_query ( "SELECT * FROM users WHERE username = " . $wantusername );
if ( mysql_num_rows ( $res_check_user ) == 1 )
bark ( $lang_takesignup [ 'std_username_exists' ]);
2025-04-05 15:38:40 +07:00
$ret = sql_query ( "INSERT INTO users (username, passhash, passkey, secret, auth_key, editsecret, email, country, gender, status, class, invites, " . ( $type == 'invite' ? "invited_by," : "" ) . " added, last_access, lang, stylesheet" . ( $showschool == 'yes' ? ", school" : "" ) . ", uploaded) VALUES (" . $wantusername . "," . $wantpasshash . "," . sqlesc ( $passkey ) . "," . $secret . "," . $authKey . "," . $editsecret . "," . $email . "," . $country . "," . $gender . ", 'pending', " . $defaultclass_class . "," . $invite_count . ", " . ( $type == 'invite' ? "' $inviter '," : "" ) . " '" . date ( "Y-m-d H:i:s" ) . "' , " . " '" . date ( "Y-m-d H:i:s" ) . "' , " . $sitelangid . "," . $defcss . ( $showschool == 'yes' ? "," . $school : "" ) . "," . ( $iniupload_main > 0 ? $iniupload_main : 0 ) . ")" ) or sqlerr ( __FILE__ , __LINE__ );
2020-12-26 01:42:23 +08:00
$id = mysql_insert_id ();
2025-06-19 13:13:26 +07:00
$userInfo = \App\Models\User :: query () -> find ( $id , \App\Models\User :: $commonFields );
fire_event ( "user_created" , $userInfo );
2023-01-05 18:29:31 +08:00
$tmpInviteCount = get_setting ( 'main.tmp_invite_count' );
if ( $tmpInviteCount > 0 ) {
$userRep = new \App\Repositories\UserRepository ();
$userRep -> addTemporaryInvite ( null , $id , 'increment' , $tmpInviteCount , 7 );
}
2025-05-22 02:18:07 +07:00
$dt = date ( "Y-m-d H:i:s" );
$subject = $lang_takesignup [ 'msg_subject' ] . $SITENAME . "!" ;
2025-04-19 02:06:51 +07:00
$siteName = \App\Models\Setting :: getSiteName ();
2025-06-19 13:13:26 +07:00
$msg = \App\Models\MessageTemplate :: forRegisterWelcome ( $userInfo -> lang , [ 'username' => $userInfo -> username ]);
if ( empty ( $msg )) {
$msg = $lang_takesignup [ 'msg_congratulations' ] . $wantusername . sprintf ( $lang_takesignup [ 'msg_you_are_a_member' ], $siteName , $siteName );
}
2025-05-22 02:18:07 +07:00
\App\Models\Message :: add ([
'sender' => 0 ,
'receiver' => $id ,
'subject' => $subject ,
'added' => $dt ,
'msg' => $msg ,
]);
2020-12-26 01:42:23 +08:00
//write_log("User account $id ($wantusername) was created");
$res = sql_query ( "SELECT passhash, secret, editsecret, status FROM users WHERE id = " . sqlesc ( $id )) or sqlerr ( __FILE__ , __LINE__ );
$row = mysql_fetch_assoc ( $res );
$psecret = md5 ( $row [ 'secret' ]);
$ip = getip ();
$usern = htmlspecialchars ( $wantusername );
$title = $SITENAME . $lang_takesignup [ 'mail_title' ];
2021-02-28 02:57:50 +08:00
$confirmUrl = getSchemeAndHttpHost () . "/confirm.php?id= $id &secret= $psecret " ;
$confirmResendUrl = getSchemeAndHttpHost () . "/confirm_resend.php" ;
2025-04-19 02:06:51 +07:00
$mailTwo = sprintf ( $lang_takeinvite [ 'mail_two' ], $siteName );
$mailFive = sprintf ( $lang_takeinvite [ 'mail_five' ], $siteName , $siteName , $REPORTMAIL , $siteName );
2020-12-26 01:42:23 +08:00
$body = <<< EOD
2025-04-19 02:06:51 +07:00
{$lang_takesignup['mail_one']}$usern{$mailTwo}($email){$lang_takesignup['mail_three']}$ip{$lang_takesignup['mail_four']}
2021-02-28 02:57:50 +08:00
<b><a href="javascript:void(null)" onclick="window.open($confirmUrl)">
2020-12-26 01:42:23 +08:00
{$lang_takesignup['mail_this_link']} </a></b><br />
2021-02-28 02:57:50 +08:00
$confirmUrl
2020-12-26 01:42:23 +08:00
{$lang_takesignup['mail_four_1']}
2021-02-28 02:57:50 +08:00
<b><a href="javascript:void(null)" onclick="window.open($confirmResendUrl)">{$lang_takesignup['mail_here']}</a></b><br />
$confirmResendUrl
2020-12-26 01:42:23 +08:00
<br />
2025-04-19 02:06:51 +07:00
{$mailFive}
2020-12-26 01:42:23 +08:00
EOD ;
if ( $type == 'invite' )
{
2021-05-10 20:05:52 +08:00
//don't forget to delete confirmed invitee's hash code from table invites
//sql_query("DELETE FROM invites WHERE hash = '".mysql_real_escape_string($code)."'");
// set invalid
$update = [
'valid' => \App\Models\Invite :: VALID_NO ,
'invitee_register_uid' => $id ,
2021-05-11 02:44:43 +08:00
'invitee_register_email' => $_POST [ 'email' ],
'invitee_register_username' => $_POST [ 'wantusername' ],
2021-05-10 20:05:52 +08:00
];
\App\Models\Invite :: query () -> where ( 'id' , $inv [ 'id' ]) -> update ( $update );
2025-05-23 01:38:41 +07:00
$dt = date ( "Y-m-d H:i:s" );
2025-04-21 02:53:56 +07:00
$locale = get_user_locale ( $inviter );
2025-05-23 01:38:41 +07:00
$subject = nexus_trans ( "user.msg_invited_user_has_registered" , [], $locale );
2025-06-09 02:29:15 +07:00
$msg = nexus_trans ( "user.msg_user_you_invited" , [], $locale ) . $wantusername . nexus_trans ( "user.msg_has_registered" , [], $locale );
2021-05-10 20:05:52 +08:00
//sql_query("UPDATE users SET uploaded = uploaded + 10737418240 WHERE id = $inviter"); //add 10GB to invitor's uploading credit
2025-05-23 01:38:41 +07:00
\App\Models\Message :: add ([
'sender' => 0 ,
'receiver' => $inviter ,
'subject' => $subject ,
'added' => $dt ,
'msg' => $msg ,
]);
2021-05-10 20:05:52 +08:00
$Cache -> delete_value ( 'user_' . $inviter . '_unread_message_count' );
$Cache -> delete_value ( 'user_' . $inviter . '_inbox_count' );
2020-12-26 01:42:23 +08:00
}
if ( $verification == 'admin' ){
if ( $type == 'invite' )
header ( "Location: " . get_protocol_prefix () . " $BASEURL /ok.php?type=inviter" );
else
header ( "Location: " . get_protocol_prefix () . " $BASEURL /ok.php?type=adminactivate" );
}
elseif ( $verification == 'automatic' || $smtptype == 'none' ){
header ( "Location: " . get_protocol_prefix () . " $BASEURL /confirm.php?id= $id &secret= $psecret " );
}
else {
2021-02-04 19:28:27 +08:00
sent_mail ( $send_email , $SITENAME , $SITEEMAIL , $title , $body , "signup" , false , false , '' );
2020-12-26 01:42:23 +08:00
header ( "Location: " . get_protocol_prefix () . " $BASEURL /ok.php?type=signup&email=" . rawurlencode ( $send_email ));
}
?>