<commit_before><?php

/*
 * ejabberd extauth script for the integration with friendica
 *
 * Originally written for joomla by <NAME> <<EMAIL>>
 * modified for Friendica by <NAME> <<EMAIL>>
 * published under GPL
 *
 * Latest version of the original script for joomla is available at:
 * http://192.168.3.11/~dado/ejabberd/joomla-login
 *
 * Installation:
 *
 * 	- Change it's owner to whichever user is running the server, ie. ejabberd
 * 	  $ chown ejabberd:ejabberd /path/to/friendica/bin/auth_ejabberd.php
 *
 * 	- Change the access mode so it is readable only to the user ejabberd and has exec
 * 	  $ chmod 700 /path/to/friendica/bin/auth_ejabberd.php
 *
 * 	- Edit your ejabberd.cfg file, comment out your auth_method and add:
 * 	  {auth_method, external}.
 * 	  {extauth_program, "/path/to/friendica/bin/auth_ejabberd.php"}.
 *
 * 	- Restart your ejabberd service, you should be able to login with your friendica auth info
 *
 * Other hints:
 * 	- if your users have a space or a @ in their nickname, they'll run into trouble
 * 	  registering with any client so they should be instructed to replace these chars
 * 	  " " (space) is replaced with "%20"
 * 	  "@" is replaced with "(a)"
 *
 */

namespace Friendica\Util;

use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User;

class ExAuth
{
	private $bDebug;
	private $host;

	/**
	 * Create the class
	 *
	 */
	public function __construct()
	{
		$this->bDebug = (int) DI::config()->get('jabber', 'debug');

		openlog('auth_ejabberd', LOG_PID, LOG_USER);

		$this->writeLog(LOG_NOTICE, 'start');
	}

	/**
	 * Standard input reading function, executes the auth with the provided
	 * parameters
	 *
	 * @return null
	 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
	 */
	public function readStdin()
	{
		while (!feof(STDIN)) {
			// Quit if the database connection went down
			if (!DBA::connected()) {
				$this->writeLog(LOG_ERR, 'the database connection went down');
				return;
			}

			$iHeader = fgets(STDIN, 3);
			$aLength = unpack('n', $iHeader);
			$iLength = $aLength['1'];

			// No data? Then quit
			if ($iLength == 0) {
				$this->writeLog(LOG_ERR, 'we got no data, quitting');
				return;
			}

			// Fetching the data
			$sData = fgets(STDIN, $iLength + 1);
			$this->writeLog(LOG_DEBUG, 'received data: ' . $sData);
			$aCommand = explode(':', $sData);
			if (is_array($aCommand)) {
				switch ($aCommand[0]) {
					case 'isuser':
						// Check the existance of a given username
						$this->isUser($aCommand);
						break;
					case 'auth':
						// Check if the givven password is correct
						$this->auth($aCommand);
						break;
					case 'setpass':<commit_msg>Daemon: Added check for empty data<commit_after><?php

/*
 * ejabberd extauth script for the integration with friendica
 *
 * Originally written for joomla by <NAME> <<EMAIL>>
 * modified for Friendica by <NAME> <<EMAIL>>
 * published under GPL
 *
 * Latest version of the original script for joomla is available at:
 * http://87.230.15.86/~dado/ejabberd/joomla-login
 *
 * Installation:
 *
 * 	- Change it's owner to whichever user is running the server, ie. ejabberd
 * 	  $ chown ejabberd:ejabberd /path/to/friendica/bin/auth_ejabberd.php
 *
 * 	- Change the access mode so it is readable only to the user ejabberd and has exec
 * 	  $ chmod 700 /path/to/friendica/bin/auth_ejabberd.php
 *
 * 	- Edit your ejabberd.cfg file, comment out your auth_method and add:
 * 	  {auth_method, external}.
 * 	  {extauth_program, "/path/to/friendica/bin/auth_ejabberd.php"}.
 *
 * 	- Restart your ejabberd service, you should be able to login with your friendica auth info
 *
 * Other hints:
 * 	- if your users have a space or a @ in their nickname, they'll run into trouble
 * 	  registering with any client so they should be instructed to replace these chars
 * 	  " " (space) is replaced with "%20"
 * 	  "@" is replaced with "(a)"
 *
 */

namespace Friendica\Util;

use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User;

class ExAuth
{
	private $bDebug;
	private $host;

	/**
	 * Create the class
	 *
	 */
	public function __construct()
	{
		$this->bDebug = (int) DI::config()->get('jabber', 'debug');

		openlog('auth_ejabberd', LOG_PID, LOG_USER);

		$this->writeLog(LOG_NOTICE, 'start');
	}

	/**
	 * Standard input reading function, executes the auth with the provided
	 * parameters
	 *
	 * @return null
	 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
	 */
	public function readStdin()
	{
		while (!feof(STDIN)) {
			// Quit if the database connection went down
			if (!DBA::connected()) {
				$this->writeLog(LOG_ERR, 'the database connection went down');
				return;
			}

			$iHeader = fgets(STDIN, 3);
			if (empty($iHeader)) {
				$this->writeLog(LOG_ERR, 'empty stdin');
				return;
			}

			$aLength = unpack('n', $iHeader);
			$iLength = $aLength['1'];

			// No data? Then quit
			if ($iLength == 0) {
				$this->writeLog(LOG_ERR, 'we got no data, quitting');
				return;
			}

			// Fetching the data
			$sData = fgets(STDIN, $iLength + 1);
			$this->writeLog(LOG_DEBUG, 'received data: ' . $sData);
			$aCommand = explode(':', $sData);
			if (is_array($aCommand)) {
				switch ($aCommand[0]) {
					case 'isuser':
						// Check the existance of a given username
						$this->isUser($aCommand);
						break;
					case 'auth':
						// Check if the givven password is correct
						$this->auth($aCommand);
						break;
					case 'setpass':
{'fraction_non_alphanumeric': 0.13106973347937204, 'fraction_numerical': 0.006936838262139467, 'mean_word_length': 3.2276234567901234, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3263773', 'n_tokens_mistral': 2132, 'n_tokens_neox': 1831, 'n_words': 548}