reverted PHP version thet works with MySQL 5.7
This commit is contained in:
@@ -21,6 +21,7 @@ function checknewuser($user) {
|
||||
require_once("opendb.php");
|
||||
$dbuser = $db->real_escape_string($user);
|
||||
$q = $db->query("select * from user where name='$dbuser';");
|
||||
if (!$q) error("server database error: ".$db->error);
|
||||
if ($q->num_rows==0) {
|
||||
echo json_encode($user);
|
||||
} else {
|
||||
@@ -31,4 +32,4 @@ function checknewuser($user) {
|
||||
}
|
||||
}
|
||||
checknewuser($_REQUEST['user']);
|
||||
?>
|
||||
?>
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
global $db;
|
||||
|
||||
/// Send Error To Client
|
||||
/** @return error message from server to client
|
||||
|
||||
@@ -13,6 +15,10 @@
|
||||
}
|
||||
@endcode */
|
||||
function error($txt) {
|
||||
error_log("**** ERROR: ".$txt);
|
||||
if (isset($db) && is_object($db)) {
|
||||
error_log("**** DATABASE ERROR: ".$db->error);
|
||||
}
|
||||
echo json_encode(array('success' => false, 'txt' => $txt));
|
||||
exit;
|
||||
}
|
||||
@@ -83,4 +89,4 @@ EOT;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
@@ -28,7 +28,8 @@
|
||||
<li id="groups" onclick="groups()">Edit Groups</li>
|
||||
<li id="removeKey" style="display: none" onclick="removeKey()">Password Forgotten</li>
|
||||
<li id="android-download" href="safechat.apk"><a href="safechat.apk">Download Android-App</a></li>
|
||||
<li href="https://dev.marc.waeckerlin.org/redmine/projects/safechat/embedded/index.html" target="_blank"><a href="https://dev.marc.waeckerlin.org/redmine/projects/safechat/embedded/index.html" target="_blank">About Safe Chat</a></li>
|
||||
<li href="@PROJECT_URL@" target="_blank"><a href="@PROJECT_URL@" target="_blank">About the Project</a></li>
|
||||
<li href="@AUTHOR_URL@" target="_blank"><a href="@AUTHOR_URL@" target="_blank">About the Author</a></li>
|
||||
</ul>
|
||||
<script type="text/javascript">
|
||||
$(function() { // on load: without cordova, remove andoid-download
|
||||
|
@@ -23,12 +23,12 @@ try {
|
||||
if (!isset($db)) {
|
||||
$db = new mysqli("mysql", "root", $_SERVER["MYSQL_ENV_MYSQL_ROOT_PASSWORD"]);
|
||||
if (!$db) error("database connection failed on server");
|
||||
$db->query("create database if not exists safechat;");
|
||||
$db->select_db("safechat");
|
||||
if (!$db) error("cannot create database for safechat");
|
||||
$db->query(file_get_contents("schema.sql"));
|
||||
if (!$db) error("cannot create database tables");
|
||||
if (!$db->query("create database if not exists safechat;")) error("cannot create database");
|
||||
if (!$db->select_db("safechat")) error("cannot use database");
|
||||
if (!$db->multi_query(file_get_contents("schema.sql"))) error("cannot create database tables");
|
||||
}
|
||||
$db = new mysqli("mysql", "root", $_SERVER["MYSQL_ENV_MYSQL_ROOT_PASSWORD"]);
|
||||
if (!$db->select_db("safechat")) error("cannot use database");
|
||||
} catch (Exception $e) {
|
||||
error('database error on server');
|
||||
}
|
||||
|
@@ -1,22 +1,14 @@
|
||||
CREATE TABLE IF NOT EXISTS `user` (
|
||||
`name` varchar(50) NOT NULL UNIQUE COMMENT 'unique name of the user',
|
||||
`pubkey` text NOT NULL COMMENT 'armored gnupg public key of the user',
|
||||
PRIMARY KEY (`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='list of all registered users and their public keys';
|
||||
create table if not exists `user` (
|
||||
`name` varchar(50) not null unique comment 'unique name of the user',
|
||||
`pubkey` text not null comment 'armored gnupg public key of the user',
|
||||
primary key (`name`)
|
||||
) engine=InnoDB default charset=utf8 comment='list of all registered users and their public keys';
|
||||
|
||||
create table if not exists `message` (
|
||||
`id`
|
||||
int not null auto_increment
|
||||
comment "id of the message, it is used in the client to check if a message has already been downloaded or not",
|
||||
`time`
|
||||
timestamp default current_timestamp
|
||||
comment "time when the message has been stored on the server",
|
||||
`user`
|
||||
varchar(50) not null
|
||||
comment "name of the user that sent the message",
|
||||
`msg`
|
||||
longtext not null
|
||||
comment "message content, must be armored gnupg encrypted format",
|
||||
`id` int not null auto_increment comment "id of the message, it is used in the client to check if a message has already been downloaded or not",
|
||||
`time` timestamp default current_timestamp comment "time when the message has been stored on the server",
|
||||
`user` varchar(50) not null comment "name of the user that sent the message",
|
||||
`msg` longtext not null comment "message content, must be armored gnupg encrypted format",
|
||||
primary key (id),
|
||||
foreign key (user)
|
||||
references user(name)
|
||||
@@ -26,8 +18,8 @@ create table if not exists `message` (
|
||||
comment="table to hold all messages for later download by the receiver";
|
||||
|
||||
/* table to sore arbitrary options */
|
||||
create table if not exists options (
|
||||
name varchar(50) not null unique comment "option name",
|
||||
value text not null comment "option value",
|
||||
create table if not exists `options` (
|
||||
`name` varchar(50) not null unique comment "option name",
|
||||
`value` text not null comment "option value",
|
||||
primary key (name)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 comment="table for system settings";
|
||||
) engine=InnoDB default charset=utf8 comment="table for system settings";
|
||||
|
Reference in New Issue
Block a user