<commit_before><?php
/**
 * SystemPlant deals with any low-level or secure requests that need processing. 
 * Some things like user logins appear here instead of their more natural homes 
 * in order to centralize potential security risks.
 *
 * @package diy.org.cashmusic
 * @author <NAME>
 * @link http://cashmusic.org/
 *
 * Copyright (c) 2011, CASH Music
 * Licensed under the Affero General Public License version 3.
 * See http://www.gnu.org/licenses/agpl-3.0.html
 *
 **/
class SystemPlant extends PlantBase {
	
	public function __construct($request_type,$request) {
		$this->request_type = 'system';
		$this->plantPrep($request_type,$request);
		// get global salt for hashing
		$global_settings = parse_ini_file(CASH_PLATFORM_ROOT.'/settings/cashmusic.ini.php');
		$this->salt = $global_settings['salt'];
	}
	
	public function processRequest() {
		if ($this->action) {
			switch ($this->action) {
				case 'validatelogin':
					if (!$this->checkRequestMethodFor('direct')) { return $this->sessionGetLastResponse(); }
					if (!$this->requireParameters('address','password')) { return $this->sessionGetLastResponse(); }
					$require_admin = false;
					if (isset($this->request['require_admin'])) {
						$require_admin = $this->request['require_admin'];
					}
					$result = $this->validateLogin($this->request['address'],$this->request['password'],$require_admin);
					return $this->response->pushResponse(
						200,$this->request_type,$this->action,
						$result,
						'success. id or false included in payload'
					);
					break;
				case 'addlogin':
					if (!$this->checkRequestMethodFor('direct')) { return $this->sessionGetLastResponse(); }
					if (!$this->requireParameters('address','password')) { return $this->sessionGetLastResponse(); }
					$result = $this->addLogin($this->request['address'],$this->request['password']);
					if ($result) {
						return $this->pushSuccess($result,'success. true or false included in payload');
					} else {
						return $this->pushFailure('there was an error');
					}
					break;
				case 'setapicredentials':
					if (!$this->checkRequestMethodFor('direct')) { return $this->sessionGetLastResponse(); }
					if (!$this->requireParameters('user_id')) { return $this->sessionGetLastResponse(); }
					$result = $this->setAPICredentials($this->request['user_id']);
					if ($result) {
						return $this->pushSuccess($result,'success. credentials array included in payload');
					} else {
						return $this->pushFailure('there was an error');
					}
					break;
				case 'getapicredentials':
					if (!$this->checkRequestMethodFor('direct')) { return $this->sessionGetLastResponse(); }
					if (!$this->requireParameters('user_id')) { return $this->sessionGetLastResponse(); }
					$result = $this->getAPICredentials($this->request['user_id']);
					if ($result) {
						return $this->pushSuccess($result,'success. credentials array included in payload');
					} else {
						return $this->pushFailure('there was an error');
					}
					break;
				case 'validateapicredentials':
					if (!$this->checkRequestMethodFor('direct')) { return $this->sessionGetLastResponse(); }
					if (!$this->requireParameters('api_key')) { return $this->sessionGetLastResponse(); }
					$result = $this->validateAPICredentials($this->request['api_key']);
					if ($result) {
						return $this->pushSuccess($result,'success. auth_type and user_id in payload as array.');
					} else {
						return $this->pushFailure('there was an error');
					}
					break;
				default:
					return $this->response->pushResponse(
						400,$this->request_type,$this->action,
						$this->request,
						'unknown action'
					);
			}
		} else {
			return $this->response->pushResponse(
				400,
				$this->request_type,
				$this->action,
				$this->request,
				'no action specified'
			);
		}
	}
	
	/**
	 * Generates a password hash and compares against the stored hash<commit_msg>fitmk<commit_after><?php
/**
 * SystemPlant deals with any low-level or secure requests that need processing. 
 * Some things like user logins appear here instead of their more natural homes 
 * in order to centralize potential security risks.
 *
 * @package diy.org.cashmusic
 * @author <NAME>
 * @link http://cashmusic.org/
 *
 * Copyright (c) 2011, CASH Music
 * Licensed under the Affero General Public License version 3.
 * See http://www.gnu.org/licenses/agpl-3.0.html
 *
 **/
class SystemPlant extends PlantBase {
	
	public function __construct($request_type,$request) {
		$this->request_type = 'system';
		$this->plantPrep($request_type,$request);
		// get global salt for hashing
		$global_settings = parse_ini_file(CASH_PLATFORM_ROOT.'/settings/cashmusic.ini.php');
		$this->salt = $global_settings['salt'];
	}
	
	public function processRequest() {
		if ($this->action) {
			switch ($this->action) {
				case 'validatelogin':
					if (!$this->checkRequestMethodFor('direct')) { return $this->sessionGetLastResponse(); }
					if (!$this->requireParameters('address','password')) { return $this->sessionGetLastResponse(); }
					$require_admin = false;
					if (isset($this->request['require_admin'])) {
						$require_admin = $this->request['require_admin'];
					}
					$result = $this->validateLogin($this->request['address'],$this->request['password'],$require_admin);
					return $this->response->pushResponse(
						200,$this->request_type,$this->action,
						$result,
						'success. id or false included in payload'
					);
					break;
				case 'addlogin':
					if (!$this->checkRequestMethodFor('direct')) { return $this->sessionGetLastResponse(); }
					if (!$this->requireParameters('address','password')) { return $this->sessionGetLastResponse(); }
					$result = $this->addLogin($this->request['address'],$this->request['password']);
					if ($result) {
						return $this->pushSuccess($result,'success. true or false included in payload');
					} else {
						return $this->pushFailure('there was an error');
					}
					break;
				case 'setapicredentials':
					if (!$this->checkRequestMethodFor('direct')) { return $this->sessionGetLastResponse(); }
					if (!$this->requireParameters('user_id')) { return $this->sessionGetLastResponse(); }
					$result = $this->setAPICredentials($this->request['user_id']);
					if ($result) {
						return $this->pushSuccess($result,'success. credentials array included in payload');
					} else {
						return $this->pushFailure('there was an error');
					}
					break;
				case 'getapicredentials':
					if (!$this->checkRequestMethodFor('direct')) { return $this->sessionGetLastResponse(); }
					if (!$this->requireParameters('user_id')) { return $this->sessionGetLastResponse(); }
					$result = $this->getAPICredentials($this->request['user_id']);
					if ($result) {
						return $this->pushSuccess($result,'success. credentials array included in payload');
					} else {
						return $this->pushFailure('there was an error');
					}
					break;
				case 'validateapicredentials':
					if (!$this->checkRequestMethodFor('direct')) { return $this->sessionGetLastResponse(); }
					if (!$this->requireParameters('api_key')) { return $this->sessionGetLastResponse(); }
					$result = $this->validateAPICredentials($this->request['api_key']);
					if ($result) {
						return $this->pushSuccess($result,'success. auth_type and user_id in payload as array.');
					} else {
						return $this->pushFailure('there was an error');
					}
					break;
				case 'fitmk':
					// for Duke...you're awesome.
					$litany = "I must not fear. Fear is the mind-killer."
							 . "Fear is the little-death that brings total obliteration."
							 . "I will face my fear. I will permit it to pass over me and through me."
							 . "And when it has gone past I will turn the inner eye to see its path."
							 . "Where the fear has gone there will be nothing. Only I will remain. -- <NAME>";
					return $this->pushSuccess($litany,'check it');
				default:
					return $this->response->pushResponse(
						400,$this->request_type,$this->action,
						$this->request,
						'unknown action'
					);
			}
		} else {
			return $this->response->pushResponse(
				400,
				$this->request_type,
				$this->action,
				$this->request,
				'no action specified'
			);
		}
	}
	
	/**
	 * Generates a password hash and compares against the stored hash
{'fraction_non_alphanumeric': 0.15607701564380264, 'fraction_numerical': 0.0038507821901323704, 'mean_word_length': 3.6822535211267606, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 129, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, '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': '6950445', 'n_tokens_mistral': 3014, 'n_tokens_neox': 2374, 'n_words': 574}