Browse Source

Permissions. Emails. Install

Nathaniel van Diepen 10 years ago
parent
commit
1ba87a7979
9 changed files with 34 additions and 9 deletions
  1. 2 5
      api.php
  2. 1 1
      config.default.json
  3. 1 0
      data/.htaccess
  4. 3 0
      data/emails/welcome.template
  5. 3 2
      install/api.php
  6. 8 0
      install/index.template.html
  7. 1 0
      php/.htaccess
  8. 1 1
      php/database.php
  9. 14 0
      php/emails.php

+ 2 - 5
api.php

@@ -36,11 +36,7 @@
 				case 'page':
 					if(file_exists(PATH_DATA.'pages/'.$id.'.template')){
 						$ret['template'] = file_get_contents(PATH_DATA.'pages/'.$id.'.template');
-						if(file_exists(PATH_DATA.'context/'.$id.'.json')){
-							$context = objectToArray(json_decode(file_get_contents(PATH_DATA.'context/'.$id.'.json')));
-						}else{
-							$context = Array();
-						}
+						$context = Array();
 						if($LOGGEDIN){
 							$context['key'] = true;
 							$context['user'] = userObj($_SESSION['username']);
@@ -83,6 +79,7 @@
 									if(addUser($_GET['username'],$_GET['password'],$_GET['email'])){
 										$key = login($_GET['username'],$_GET['password']);
 										$_SESSION['username'] = $_GET['username'];
+										sendMail('welcome',$_GET['email'],get('email'),Array($_GET['username'],$_GET['password'],get('email')));
 									}else{
 										$ret['error'] = "Could not add user. ".$mysqli->error;
 									}

+ 1 - 1
config.default.json

@@ -1 +1 @@
-{"host":"localhost","user":"bugs","password":"bugs","database":"bugs","timeout":216000}
+{"host":"localhost","user":"bugs","password":"bugs","database":"bugs","timeout":216000,"email":"[email protected]"}

+ 1 - 0
data/.htaccess

@@ -0,0 +1 @@
+Deny from all

+ 3 - 0
data/emails/welcome.template

@@ -0,0 +1,3 @@
+Welcome to bugs! Information for your account is as follows:
+Username: %s
+Password: %s

+ 3 - 2
install/api.php

@@ -114,17 +114,18 @@
 				case 'install':
 					if($id == "run"){
 						$path = realpath(dirname(__FILE__));
-						if(isset($_GET['dbuser'])&&isset($_GET['dbpass'])&&isset($_GET['dbname'])&&isset($_GET['dbhost'])&&isset($_GET['dbtemplate'])){
+						if(isset($_GET['dbuser'])&&isset($_GET['dbpass'])&&isset($_GET['dbname'])&&isset($_GET['dbhost'])&&isset($_GET['dbtemplate'])&&isset($_GET['email'])){
 							$dbuser = $_GET['dbuser'];
 							$dbpass = $_GET['dbpass'];
 							$dbname = $_GET['dbname'];
 							$dbhost = $_GET['dbhost'];
+							$email = $_GET['email'];
 							$dbms_schema = $_GET['dbtemplate'].'.sql';
 							$sql_query = @fread(@fopen($dbms_schema, 'r'), @filesize($dbms_schema)) or die("Can't access template: ".$_GET['dbtemplate'].".sql");
 							$sql_query = remove_comments($sql_query);
 							$sql_query = remove_remarks($sql_query);
 							$sql_query = split_sql_file($sql_query, ';');
-							file_put_contents('../config.default.json',"{\"host\":\"{$dbhost}\",\"user\":\"{$dbuser}\",\"password\":\"{$dbpass}\",\"database\":\"{$dbname}\",\"timeout\":216000}");
+							file_put_contents('../config.default.json',"{\"host\":\"{$dbhost}\",\"user\":\"{$dbuser}\",\"password\":\"{$dbpass}\",\"database\":\"{$dbname}\",\"timeout\":216000,\"email\":\"{$email}\""}");
 							require_once('../php/database.php');
 							foreach($sql_query as $sql){
 								query($sql) or die('error in query');

+ 8 - 0
install/index.template.html

@@ -45,5 +45,13 @@
 			<input name="dbpass" type="password"/>
 		</span>
 	</div>
+	<div>
+		<span>
+			Admin Email:
+		</span>
+		<span>
+			<input name="email" type="email"/>
+		</span>
+	</div>
 	<input type="submit" value="Install" id="install"/>
 </form>

+ 1 - 0
php/.htaccess

@@ -0,0 +1 @@
+Deny from all

+ 1 - 1
php/database.php

@@ -5,7 +5,7 @@
 		echo "Failed to connect to MySQL: ".$mysqli->connect_error;
 	}
 	$mysqli->autocommit(true);
-	function query($query,$args = Array()){
+	function query($query,$args=Array()){
 		global $mysqli;
 		for ($i=0;$i<count($args);$i++){
 			if(is_string($args[$i])){

+ 14 - 0
php/emails.php

@@ -0,0 +1,14 @@
+<?php
+	require_once(realpath(dirname(__FILE__)).'/config.php');
+	require_once(PATH_PHP.'database.php');
+	require_once(PATH_PHP.'security.php');
+	require_once(PATH_PHP.'user.php');
+	function sendMail($template,$to=get('email'),$from=get('email'),$context=Array()){
+		if(file_exists(PATH_DATA."/emails/{$template}.template")){
+			$message = vsprintf(file_get_contents(PATH_DATA."/emails/{$template}.template"),$context);
+			return mail($to,$subject,$message,"From: {$from}\r\nMIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n");
+		}else{
+			return false;
+		}
+	}
+?>