1) ? argv(1) : ''); // Provide a stored request for somebody desiring a connection // when they first need to register someplace. Once they've // created a channel, we'll try to revive the connection request // and process it. if($_REQUEST['connect']) $_SESSION['connect'] = $_REQUEST['connect']; switch($cmd) { case 'invite_check.json': $result = check_account_invite($_REQUEST['invite_code']); break; case 'email_check.json': $result = check_account_email($_REQUEST['email']); break; case 'password_check.json': $result = check_account_password($_REQUEST['password1']); break; default: break; } if($result) { json_return_and_die($result); } } function post() { check_form_security_token_redirectOnErr('/register', 'register'); /** * [hilmar:] * It may happen, the posted form arrives in a strange fashion. With the control of the duty hours * for registration, the input form was disabled at html. While receiving posted data, checks are * required if all is on the right road (most posts are not accepted during off duty). * */ $act = q("SELECT COUNT(*) AS act FROM account")[0]['act']; $duty = zar_register_dutystate(); $is247 = false; $ip = $_SERVER['REMOTE_ADDR']; $sameip = intval(get_config('system','register_sameip')); $arr = $_POST; $invite_code = ( (x($arr,'invite_code')) ? notags(trim($arr['invite_code'])) : ''); $email = ( (x($arr,'email')) ? notags(punify(trim($arr['email']))) : ''); $password = ( (x($arr,'password')) ? trim($arr['password']) : ''); $password2 = ( (x($arr,'password2')) ? trim($arr['password2']) : ''); $reonar = array(); // case when an invited prepares the own account by supply own pw, accept tos, prepage channel (if auto) if ($email && $invite_code) { if ( preg_match('/^.{2,64}\@[a-z0-9.-]{4,32}\.[a-z]{2,12}$/', $email ) ) { if ( preg_match('/^[a-z0-9]{12,12}$/', $invite_code ) ) { $is247 = true; } } } /* // assume someone tries to validate (dId2 C/D/E), because only field email entered if ( $email && ( ! $invite_code ) && ( ! $password ) && ( ! $_POST['password2'] ) ) { // dId2 logic if ( preg_match('/^\@{1,1}.{2,64}\@[a-z0-9.-]{4,32}\.[a-z]{2,12}$/', $email ) ) { // dId2 C channel - ffu } if ( preg_match('/^.{2,64}\@[a-z0-9.-]{4,32}\.[a-z]{2,12}$/', $email ) ) { // dId2 E email goaway(z_root() . '/regate/' . bin2hex($email) . 'e' ); } if ( preg_match('/^d{1,1}[0-9]{5,10}$/', $email ) ) { // dId2 A artifical & anonymous goaway(z_root() . '/regate/' . bin2hex($email) . 'a' ); } } */ $email_verify = get_config('system','verify_email'); if ($email_verify && ! $email) { notice(t('Email address required') . EOL); return; } if ($email) { if ( ! preg_match('/^.{2,64}\@[a-z0-9.-]{4,32}\.[a-z]{2,12}$/', $_POST['email'] ) ) { // msg! notice(t('Not a valid email address') . EOL); return; } } if ($act > 0 && !$is247 && !$duty['isduty']) { // normally (except very 1st timr after install), that should never arrive here (ie js hack or sth like) // log suitable for f2b also $logmsg = 'ZAR0230S Unexpected registration request off duty'; zar_log($logmsg); return; } if ($sameip) { $f = q("SELECT COUNT(reg_atip) AS atip FROM register WHERE reg_vital = 1 AND reg_atip = '%s' ", dbesc($ip) ); if ($f && $f[0]['atip'] >= $sameip) { $logmsg = 'ZAR0239S Exceeding same ip register request of ' . $sameip; notice('Registrations from same IP exceeded.'); zar_log($logmsg); return; } } // s2 max daily // msg? if ( !$is247 && self::check_reg_limits()['is'] ) return; if(!$password) { // msg! notice(t('No password provided') . EOL); return; } // pw1 == pw2 if($password !== $password2) { // msg! notice(t('Passwords do not match') . EOL); return; } $password_result = check_account_password($password); if(!empty($password_result['error'])) { $msg = $password_result['message']; notice($msg); zar_log($msg . ' ' . $did2); return; } // accept tos if(! x($_POST,'tos')) { // msg! notice(t('Terms of Service not accepted') . EOL); return; } $policy = get_config('system','register_policy'); $invonly = get_config('system','invitation_only'); $invalso = get_config('system','invitation_also'); $auto_create = get_config('system','auto_channel_create', 1); switch($policy) { case REGISTER_OPEN: $flags = ACCOUNT_OK; break; case REGISTER_APPROVE: $flags = ACCOUNT_PENDING; break; default: case REGISTER_CLOSED: if(! is_site_admin()) { notice( t('Permission denied.') . EOL ); return; } $flags = ACCOUNT_BLOCKED; break; } if($email_verify && ($policy == REGISTER_OPEN || $policy == REGISTER_APPROVE) ) $flags = ($flags | ACCOUNT_UNVERIFIED); // $arr has $_POST; $arr['account_flags'] = $flags; $now = datetime_convert(); $well = false; // s3 if ($invite_code) { if ($invonly || $invalso) { $reg = q("SELECT * from register WHERE reg_vital = 1 AND reg_didx = 'i' AND reg_hash = '%s'", dbesc($invite_code)); if ( $reg && count($reg) == 1 ) { $reg = $reg[0]; if ($reg['reg_email'] == ($email)) { if ($reg['reg_startup'] <= $now && $reg['reg_expires'] >= $now) { // is invitor admin $isa = get_account_by_id($reg['reg_uid']); $isa = ( $isa && ($isa['account_roles'] && ACCOUNT_ROLE_ADMIN) ); // approve contra invite by admin if ($isa && $policy == REGISTER_APPROVE) $flags &= $flags ^ ACCOUNT_PENDING; // if $flags == 0 ?? // transit ? // update reg vital 0 off //$icdone = q("UPDATE register SET reg_vital = 0 WHERE reg_id = %d ", //intval($reg['reg_id']) //); // update DB flags, password // TODO: what else? q("UPDATE register set reg_flags = %d, reg_pass = '%s', reg_stuff = '%s' WHERE reg_id = '%s'", intval($flags), dbesc(bin2hex($password)), intval($reg['reg_id']) ); $msg = t('Invitation code succesfully applied'); zar_log('ZAR0237I ' . $msg) . ', ' . $email; // msg! info($msg . EOL); // the invitecode has verified us and we have all the info we need // take the shortcut. $mod = new Regate(); $_REQUEST['form_security_token'] = get_form_security_token("regate"); App::$argc = 2; App::$argv[0] = 'regate'; App::$argv[1] = bin2hex($reg['reg_did2']) . 'i'; return $mod->post(); } else { // msg! notice(t('Invitation not in time or too late') . EOL); return; } } else { // no match email adr $msg = t('Invitation email failed'); zar_log('ZAR0235S ' . $msg); notice($msg . EOL); return; } } else { // no match invitecode $msg = t('Invitation code failed') ; zar_log('ZAR0234S ' . $msg); notice( $msg . EOL); return; } } else { notice(t('Invitations are not available') . EOL); return; } } else { $icdone = false; // no ivc entered if ( ! $invonly) { // possibly the email is just in use ? $reg = q("SELECT * from register WHERE reg_vital = 1 AND reg_email = '%s'", dbesc('e' . $email)); if ( ! $reg) $act = q("SELECT * from account WHERE account_email = '%s'", dbesc($email)); // in case an invitation was made but the invitecode was not entered, better ignore. // goaway(z_root() . '/regate/' . bin2hex($reg['email'])); if ( ! $reg && ! $act) { // email useable $well = true; } else { $msg = t('Email address already in use') . EOL; notice($msg); // problem, the msg tells to anonymous about existant email addrs // use another msg instead ? TODO ? // on the other hand can play the fail2ban game zar_log('ZAR0237E ' . $msg . ' (' . $email . ')'); return; } } else { $msg = t('Registration on this hub is by invitation only') . EOL; notice($msg); zar_log('ZAR0233E ' . $msg); return; } } if ($well) { if($policy == REGISTER_OPEN || $policy == REGISTER_APPROVE ) { $cfgdelay = get_config( 'system', 'register_delay' ); $reg_delayed = calculate_adue( $cfgdelay ); $regdelay = (($reg_delayed) ? datetime_convert(date_default_timezone_get(), 'UTC', $reg_delayed['due']) : $now); $cfgexpire = get_config('system','register_expire' ); $reg_expires = calculate_adue( $cfgexpire ); $regexpire = (($reg_expires) ? datetime_convert(date_default_timezone_get(), 'UTC', $reg_expires['due']) : datetime_convert('UTC', 'UTC', 'now + 99 years')); // handle an email request that will be verified or an ivitation associated with an email address if ($email > '' && $email_verify) { // enforce in case of icdone $flags |= ACCOUNT_UNVERIFIED; $empin = $pass2 = random_string(24); $did2 = $email; $didx = 'e'; push_lang(($reg['lang']) ? $reg['lang'] : 'en'); $reonar['from'] = get_config('system', 'from_email'); $reonar['to'] = $email; $reonar['subject'] = sprintf( t('Registration confirmation for %s'), get_config('system','sitename')); $reonar['txttemplate']= replace_macros(get_intltext_template('register_verify_member.tpl'), [ '$sitename' => get_config('system','sitename'), '$siteurl' => z_root(), '$email' => $email, '$timeframe' => [$regdelay, $regexpire], '$mail' => bin2hex($email) . 'e', '$ko' => bin2hex(substr($empin,0,4)), '$hash' => $empin ] ); pop_lang(); zar_reg_mail($reonar); } else { // that is an anonymous request without email or with email not to verify $acpin = $pass2 = rand(100000,999999); $did2 = rand(10,99); $didx = 'a'; // enforce delayed verify $flags = ($flags | ACCOUNT_UNVERIFIED); if ($email) { $reonar['email.untrust'] = $email; $reonar['email.comment'] = 'received, but no need for'; } } if ( $auto_create ) { $reonar['chan.name'] = notags(trim($arr['name'])); $reonar['chan.did1'] = notags(trim($arr['nickname'])); } $salt = random_string(32); $password = $salt . ',' . hash('whirlpool', $salt . $password); $reg = q("INSERT INTO register (" . "reg_flags,reg_didx,reg_did2,reg_hash,reg_created,reg_startup,reg_expires," . "reg_email,reg_pass,reg_lang,reg_atip,reg_stuff)" . " VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", intval($flags), dbesc($didx), dbesc($did2), dbesc($pass2), dbesc($now), dbesc($regdelay), dbesc($regexpire), dbesc($email), dbesc($password), dbesc(substr(get_best_language(),0,2)), dbesc($ip), dbesc(json_encode( $reonar )) ); if ($didx == 'a') { $lid = q("SELECT reg_id FROM register WHERE reg_vital = 1 AND reg_did2 = '%s' AND reg_pass = '%s' ", dbesc($did2), dbesc($password) ); if ($lid && count($lid) == 1 ) { $didnew = ( $lid[0]['reg_id'] . $did2 ) . ( substr( base_convert( md5( $lid[0]['reg_id'] . $did2 ), 16, 10 ),-2 ) ); $reg = q("UPDATE register SET reg_did2 = CONCAT('d','%s') WHERE reg_id = %d ", dbesc($didnew), intval($lid[0]['reg_id']) ); zar_log( 'ZAR0239A ' . t('New register request') . ' d' . $didnew . ', ' . $regdelay . ' - ' . $regexpire); if($reg_delayed) { // this could be removed to make registration harder $_SESSION['zar']['pin'] = $pass2; $_SESSION['zar']['msg'] = t('Your validation token is') . EOL . '
' . datetime_convert('UTC', 'UTC', $regdelay, 'c') . '
' . t('and') . ' ' . datetime_convert('UTC', 'UTC', $regexpire, 'c') . '