reverted PHP version thet works with MySQL 5.7

php
Marc Wäckerlin 6 years ago
parent da7a51bedb
commit 72495b4b01
  1. 21
      ax_check_qt.m4
  2. 2
      ax_init_standard_project.m4
  3. 15
      bootstrap.sh
  4. 24
      build-in-docker.sh
  5. 1
      configure.ac
  6. 12
      docker/Dockerfile
  7. 33
      docker/README.md
  8. 3
      html/checknewuser.php
  9. 8
      html/functions.php
  10. 3
      html/index.html.in
  11. 10
      html/opendb.php
  12. 34
      html/schema.sql
  13. 2
      resolve-debbuilddeps.sh
  14. 4
      resolve-rpmbuilddeps.sh
  15. 6
      safechat-php.desktop.in
  16. 61
      safechat-php.spec.in
  17. 60
      safechat.spec.in

@ -119,10 +119,25 @@ AC_DEFUN([AX_CHECK_QT], [
AC_DEFINE([HAVE_$1])
QTDIR=$(${PKG_CONFIG} --variable=prefix Qt5Core)
qt_host_bins=$(${PKG_CONFIG} --variable=host_bins Qt5Core)
if test -d "${qt_host_bins}"; then
QT_PLUGIN_PATH=${qt_host_bins}/../plugins
qt_libdir=$(${PKG_CONFIG} --variable=libdir Qt5Core)
if test -d "${qt_libdir}" -a -d "${qt_libdir}/plugins"; then
QT_PLUGIN_PATH="${qt_libdir}/plugins"
elif test -d "${qt_libdir}/qt5" -a -d "${qt_libdir}/qt5/plugins"; then
QT_PLUGIN_PATH="${qt_libdir}/qt5/plugins"
elif test -d "${qt_host_bins}" -a -d "${qt_host_bins}/../plugins"; then
QT_PLUGIN_PATH="${qt_host_bins}/../plugins"
elif test -d "${QTDIR}/plugins; then
QT_PLUGIN_PATH="${QTDIR}/plugins"
elif test -d "${QTDIR}/share/qt5/plugins; then
QT_PLUGIN_PATH="${QTDIR}/share/qt5/plugins"
else
QT_PLUGIN_PATH=${QTDIR}/share/qt5/plugins
AC_MSG_ERROR([QT_PLUGIN_PATH not found
- not in: ${qt_libdir}/plugins
- not in: ${qt_libdir}/qt5/plugins
- not in: ${qt_host_bins}/../plugins
- not in: ${QTDIR}/plugins
- not in: ${QTDIR}/share/qt5/plugins
])
fi
MOC_FLAGS+=" -DHAVE_$1=1 ${[$1]5_CFLAGS}"
[$1]_CPPFLAGS="${[$1]5_CFLAGS}"

@ -218,7 +218,7 @@ AC_DEFUN([AX_INIT_STANDARD_PROJECT], [
AX_SUBST(AUTHOR_URL)
AX_SUBST(AUTHOR_MAIL)
AX_SUBST(PACKAGER)
PROJECT_URL="${PROJECT_URL:-${AUTHOR_URL}/projects/${PACKAGE_NAME}}"
#PROJECT_URL="${PROJECT_URL:-${AUTHOR_URL}}"
SOURCE_DOWNLOAD="${SOURCE_DOWNLOAD:-${AUTHOR_URL}/downloads/${PACKAGE_NAME}}"
AX_SUBST(PROJECT_URL)
AX_SUBST(SOURCE_DOWNLOAD)

@ -1678,7 +1678,7 @@ fi)
$(if testtag AX_RPM_DEPEND; then echo "Requires: @RPM_DEPEND@"; fi)
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: which, pkgconfig, pandoc, gnupg, expect, ${VCSDEPENDS_RPM}make, automake, autoconf, rpm-build$(
BuildRequires: which, pkgconfig, gnupg, expect, ${VCSDEPENDS_RPM}make, automake, autoconf, rpm-build$(
if testtag AX_USE_CXX; then
echo -n ", binutils-devel, gcc-c++"
fi
@ -1700,13 +1700,17 @@ BuildRequires: lsb-release$(
echo -n ", libqt5-qtbase-devel, libqt5-qttools, libqt5-linguist-devel, libQt5WebKit5-devel libqt5-qtwebengine-devel libQt5WebKitWidgets-devel";
fi)
%else
%if 0%{?mageia}
BuildRequires: rpm-sign, lsb-release
$(
if testtag AX_REQUIRE_QT || testtag AX_CHECK_QT; then
echo -n "BuildRequires: qt5-qtbase-devel, qt5-qttools-devel, qt5-qtwebkit-devel";
echo -n "BuildRequires: qtbase5-common-devel, qttools5, lib64qt5webkit-devel, lib64qt5webkitwidgets-devel";
fi)
%if 0%{?mageia}
BuildRequires: rpm-sign, lsb-release
%else
$(
if testtag AX_REQUIRE_QT || testtag AX_CHECK_QT; then
echo -n "BuildRequires: qt5-qtbase-devel, qt5-qttools-devel, qt5-qtwebkit-devel";
fi)
BuildRequires: rpm-sign, redhat-lsb
%global debug_package %{nil}
%endif
@ -1715,6 +1719,9 @@ $(
if testtag AX_USE_DOXYGEN; then cat <<EOS
%if ! 0%{?centos}
BuildRequires: mscgen
%if ! 0%{?mageia}
BuildRequires: pandoc
%endif
%endif
EOS
fi

@ -248,16 +248,18 @@ case $mode in
docker exec ${DOCKER_ID} update-locale LANG=${LANG}
fi
OPTIONS='-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confnew -y --force-yes --no-install-suggests --no-install-recommends'
for f in 'libpam-systemd:amd64' 'policykit*' 'colord'; do
docker exec ${DOCKER_ID} bash -c "echo 'Package: $f' >> /etc/apt/preferences"
PREVENT='libpam-systemd policykit.* colord dconf-service'
for f in ${PREVENT}; do
docker exec ${DOCKER_ID} bash -c "echo 'Package: ${f}' >> /etc/apt/preferences"
docker exec ${DOCKER_ID} bash -c "echo 'Pin-Priority: -100' >> /etc/apt/preferences"
docker exec ${DOCKER_ID} bash -c "echo >> /etc/apt/preferences"
done
docker exec ${DOCKER_ID} apt-get update ${OPTIONS}
docker exec ${DOCKER_ID} apt-mark hold ${PREVENT}
docker exec ${DOCKER_ID} apt-get upgrade ${OPTIONS}
docker exec ${DOCKER_ID} apt-get install ${OPTIONS} python-software-properties software-properties-common apt-transport-https dpkg-dev lsb-release wget || \
docker exec ${DOCKER_ID} apt-get install ${OPTIONS} software-properties-common apt-transport-https dpkg-dev lsb-release wget || \
docker exec ${DOCKER_ID} apt-get install ${OPTIONS} python-software-properties apt-transport-https dpkg-dev lsb-release wget;
docker exec ${DOCKER_ID} apt-get install ${OPTIONS} ${PREVENT// /- }- python-software-properties software-properties-common apt-transport-https dpkg-dev lsb-release wget || \
docker exec ${DOCKER_ID} apt-get install ${OPTIONS} ${PREVENT// /- }- software-properties-common apt-transport-https dpkg-dev lsb-release wget || \
docker exec ${DOCKER_ID} apt-get install ${OPTIONS} ${PREVENT// /- }- python-software-properties apt-transport-https dpkg-dev lsb-release wget;
for key in "${keys[@]}"; do
wget -O- "$key" \
| docker exec -i ${DOCKER_ID} apt-key add -
@ -265,9 +267,12 @@ case $mode in
for repo in "${repos[@]}"; do
ifthenelse "${repo}" "apt-add-repository 'ARG'"
done
docker exec ${DOCKER_ID} apt-get update ${OPTIONS}
for package in "${packages[@]}"; do
ifthenelse "${package}" "apt-get install ${OPTIONS} ARG"
ifthenelse "${package}" "apt-get install ${OPTIONS} ${PREVENT} ARG"
done
for command in "${commands[@]}"; do
ifthenelse "${command}" "ARG"
@ -294,11 +299,14 @@ EOF
LSB_RELEASE=/usr/bin/lsb_release
fi
docker exec ${DOCKER_ID} ${INSTALL_TOOL} rpm-build automake libtool subversion gcc-c++ pkgconfig wget $LSB_RELEASE
if docker exec ${DOCKER_ID} test -x /usr/bin/dnf; then
docker exec ${DOCKER_ID} dnf install -y 'dnf-command(config-manager)'
fi
i=0
for key in "${keys[@]}"; do
wget -Orpm-key "$key"
docker exec -i ${DOCKER_ID} wget -Orpm-key "$key"
docker exec -i ${DOCKER_ID} rpm --import rpm-key
rm rpm-key
docker exec -i ${DOCKER_ID} rm rpm-key
done
for repo in "${repos[@]}"; do
INSTALL_REPO=$((docker exec ${DOCKER_ID} test -x /usr/bin/zypper && echo zypper ar) || (docker exec ${DOCKER_ID} test -x /usr/bin/dnf && echo dnf config-manager --add-repo) || (docker exec ${DOCKER_ID} test -x /usr/bin/yum && echo wget -O/etc/yum.repos.d/additional$i.repo) || (docker exec ${DOCKER_ID} test -x /usr/sbin/urpmi && echo false))

@ -12,6 +12,7 @@ m4_define(x_minor, 3) # project's minor version
m4_include(ax_init_standard_project.m4)
AC_INIT(x_package_name, x_version, x_package_name)
AM_INIT_AUTOMAKE([1.9 tar-pax])
PROJECT_URL="https://mrw.sh/webservices/safechat"
AX_INIT_STANDARD_PROJECT
# requirements, uncomment, what you need:

@ -0,0 +1,12 @@
FROM mwaeckerlin/php-fpm
MAINTAINER mwaeckerlin
ENV CONTAINERNAME safechat
ENV WEB_ROOT_PATH /usr/share/safechat-php/html/
USER root
RUN apk add mysql-client gpgme gpgme-dev musl-dev gcc make && \
pecl install gnupg && \
echo extension=gnupg.so >> /etc/php7/php.ini && \
apk del gpgme-dev musl-dev gcc make
ADD usr /usr
USER $WWWUSER

@ -0,0 +1,33 @@
Docker Image for SafeChat
=========================
For a running example see: https://safechat.ch
Run SafeChat
------------
Safechat exposts port 8080 as it is based on [mwaeckerlin/php-fpm].
You need a [mysql] database (less than version 8). The hostname must be `mysql` and the root password must be set in `MYSQL_ENV_MYSQL_ROOT_PASSWORD`, e.g.
```bash
docker run -d --name safechat-mysql -e MYSQL_ROOT_PASSWORD=$(pwgen 20 1) mysql:5
docker run -d --name safechat -p 8005:8080 --link safechat-mysql:mysql mwaeckerlin/safechat
```
Build Docker Image
------------------
Install safechat into path `docker/usr`, then build the image, e.g.:
```bash
cd ~/git/safechat
./bootstrap.sh -t "all install" --prefix=$(pwd)/docker/usr
docker build --rm --force-rm -t mwaeckerlin/safechat docker
```
[mwaeckerlin/php-fpm]: https://hub.docker.com/r/mwaeckerlin/php-fpm "image on docker hub"
[mysql]: https://hub.docker.com/_/mysql "image on docker hub"

@ -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";

@ -24,7 +24,7 @@ else
fi
function install() {
if ${SUDO} apt-get -y install $*; then
if ${SUDO} apt-get install -y --force-yes --no-install-suggests --no-install-recommends $*; then
return 0
else
return 1

@ -97,12 +97,12 @@ fi
if test -n "${SCHROOTNAME}"; then
FILES=$(LANG= schroot -c ${SCHROOTNAME} -- rpmbuild -bb --clean --nobuild --define "_topdir ." --define "_sourcedir ." ${PACKAGE_NAME}.spec 2>&1 | sed -n 's, is needed by.*,,p')
if test -n "${FILES}"; then
if test -n "${FILES}${DEPS}"; then
schroot -c ${SCHROOTNAME} -u root -- ${INSTALL_TOOL} ${FILES} ${DEPS}
fi
else
FILES=$(LANG= rpmbuild -bb --clean --nobuild --define "_topdir ." --define "_sourcedir ." ${PACKAGE_NAME}.spec 2>&1 | sed -n 's, is needed by.*,,p')
if test -n "${FILES}"; then
if test -n "${FILES}${DEPS}"; then
${INSTALL_TOOL} ${FILES} ${DEPS}
fi
fi

@ -1,9 +1,9 @@
[Desktop Entry]
Type=Application
Name=safechat
GenericName=safechat
Name=safechat-php
GenericName=safechat-php
Comment=@DESCRIPTION@
Icon=@prefix@/share/@PACKAGE_NAME@/@PACKAGE_ICON@
Exec=safechat %u
Exec=safechat-php %u
Terminal=false
Categories=Qt;Utility;

@ -0,0 +1,61 @@
Summary: @DESCRIPTION@
Name: @PACKAGE_NAME@
Version: @VERSION@
Release: @BUILD_NUMBER@.@DISTRO@
License: LGPL
Group: @RPM_GROUP@
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: which, pkgconfig, pandoc, gnupg, expect, git, make, automake, autoconf, rpm-build, doxygen, graphviz, java-openjdk @RPM_BUILD_DEPEND@ @RPM_DEPEND_IFEXISTS@
#### os dependent definitions ####
%if 0%{?suse_version} || 0%{?sles_version}
BuildRequires: lsb-release
%else
%if 0%{?mageia}
BuildRequires: rpm-sign, lsb-release
%else
BuildRequires: rpm-sign, redhat-lsb
%global debug_package %{nil}
%endif
%endif
%if ! 0%{?centos}
BuildRequires: mscgen
%endif
%description
@README@
%global debug_package %{nil}
%prep
%setup -q
./configure --prefix=/usr \
--sysconfdir=/etc \
--docdir=/usr/share/doc/packages/@PACKAGE_NAME@ \
--libdir=/usr/%_lib
%build
make
%install
DESTDIR=$RPM_BUILD_ROOT make install
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
/usr/bin
/usr/share/applications
/usr/share/@PACKAGE_NAME@
%doc
/usr/share/doc
%changelog

@ -1,60 +0,0 @@
Summary: @DESCRIPTION@
Name: @PACKAGE_NAME@
Version: @VERSION@
Release: @BUILD_NUMBER@%{?dist}
License: LGPL
Group: Applications/...
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: gnupg, subversion, automake, autoconf, doxygen
%if 0%{?fedora} != 20
BuildRequires: graphviz
%endif
%if 0%{?fedora} || 0%{?rhel} || 0%{?rhl} || 0%{?centos} || 0%{?centos_ver} || 0%{?centos_version}
BuildRequires: pkgconfig, redhat-lsb
%if ! ( 0%{?centos} || 0%{?centos_ver} || 0%{?centos_version} )
BuildRequires: mscgen
%else
%endif
%else%if 0%{?suse_version} || 0%{?sles_version}
BuildRequires: pkg-config, lsb-release
%if 0%{?suse_version} < 1200 || 0%{?sles_version} < 1200
%else
%endif
%endif%endif
%description
@README@
%prep
%setup -q
./configure --prefix=/usr \
--sysconfdir=/etc \
--docdir=/usr/share/doc/packages/@PACKAGE_NAME@ \
--libdir=/usr/%_lib
%build
make
%install
DESTDIR=$RPM_BUILD_ROOT make install
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
/usr/bin/*
%doc
/usr/share/*
%changelog
Loading…
Cancel
Save