Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bfitech/zapmin-smtp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.4.1
Choose a base ref
...
head repository: bfitech/zapmin-smtp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Sep 17, 2017

  1. Remove a stray semicolon.

    rsur committed Sep 17, 2017
    Copy the full SHA
    a77b6b5 View commit details

Commits on Aug 8, 2018

  1. Upgrade dependencies.

    rsur committed Aug 8, 2018
    Copy the full SHA
    07d7799 View commit details
  2. Refactor tests.

    rsur committed Aug 8, 2018
    Copy the full SHA
    aa47d16 View commit details
  3. Copy the full SHA
    7c2be7f View commit details

Commits on Jun 16, 2019

  1. Copy the full SHA
    46df062 View commit details
  2. Copy the full SHA
    b9b725c View commit details
  3. Simplify CONTRIBUTING.md.

    rsur committed Jun 16, 2019
    Copy the full SHA
    8c2c31e View commit details

Commits on Jul 17, 2019

  1. Upgrade zapmin to 2.1.

    rsur committed Jul 17, 2019
    Copy the full SHA
    866f6f2 View commit details
  2. Upgrade PHPMailer to 6.0.

    rsur committed Jul 17, 2019
    Copy the full SHA
    3bf49f9 View commit details
  3. Fix documentation.

    rsur committed Jul 17, 2019
    Copy the full SHA
    3c8d2db View commit details
  4. Add Jenkinsfile.

    rsur committed Jul 17, 2019
    Copy the full SHA
    56fe17f View commit details
  5. Fix coding style.

    rsur committed Jul 17, 2019
    Copy the full SHA
    5b1b485 View commit details
  6. Upgrade Travis YAML.

    rsur committed Jul 17, 2019
    Copy the full SHA
    280d981 View commit details
  7. Re-delegate some of auth routing flow to add_user.

    - Previously, SMTPRouteDefault::route_smtp_auth takes care of existing
      session verification. Restore it back to what it used to be.
    - Fix misleading apidoc. Data returned by
      SMTPRouteDefault::route_smtp_auth is not as comprehensive as those by
      RouteDefault::route_status.
    - Improve coverage on SMTPRouteDev::route_smtp_auth.
    - Only use 7.0 and 7.3 for Travis.
    rsur committed Jul 17, 2019
    Copy the full SHA
    e13417b View commit details

Commits on Jul 16, 2020

  1. Upgrade zapmin to 2.3.

    rsur committed Jul 16, 2020
    Copy the full SHA
    056ed35 View commit details
  2. Copy the full SHA
    8555e00 View commit details
  3. Move SMTPError to separate file.

    rsur committed Jul 16, 2020
    Copy the full SHA
    0a6f4c0 View commit details
  4. Copy the full SHA
    2909d1b View commit details
  5. Improve logging.

    rsur committed Jul 16, 2020
    Copy the full SHA
    14b7400 View commit details
  6. Track php{mc,cs}.xml.

    rsur committed Jul 16, 2020
    Copy the full SHA
    740053e View commit details
  7. Improve manifest.

    - Suggest Redis and Predis.
    - Move ZapAdminDev to autoload-dev.
    rsur committed Jul 16, 2020
    Copy the full SHA
    e1252d8 View commit details

Commits on Jul 28, 2020

  1. Copy the full SHA
    976d872 View commit details
  2. Clean up Doxyfile.

    rsur committed Jul 28, 2020
    Copy the full SHA
    aec75de View commit details
Showing with 1,179 additions and 583 deletions.
  1. +2 −6 .travis.yml
  2. +8 −5 CONTRIBUTING.md
  3. +4 −5 Doxyfile
  4. +34 −0 Jenkinsfile
  5. +9 −5 composer.json
  6. +150 −0 dev/SMTPRouteDev.php
  7. +163 −0 phpcs.xml
  8. +20 −0 phpmd.xml
  9. +2 −3 phpunit.xml
  10. +213 −0 src/SMTPAuthManage.php
  11. +28 −0 src/SMTPError.php
  12. +0 −68 src/SMTPRoute.php
  13. +107 −0 src/SMTPRouteDefault.php
  14. +0 −222 src/SMTPStore.php
  15. +106 −0 tests/SMTPAuthManageTest.php
  16. +105 −0 tests/SMTPCommon.php
  17. +116 −0 tests/SMTPRouteDevTest.php
  18. +112 −0 tests/SMTPRouteTest.php
  19. +0 −269 tests/SMTPStoreTest.php
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -2,19 +2,15 @@
language: php

php:
- 5.5
- 5.6
- 7.1
- 7.0
- 7.4

before_script:
- composer install -no

script:
- php ./vendor/bin/phpunit -c phpunit.xml

after_success:
- curl -s https://codecov.io/bash | bash

notifications:
email:
on_success: never
13 changes: 8 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -44,19 +44,22 @@ Find a bug? Help us fix it.
5. Make sure coding convention is met as much as possible. For
automated check, use [code sniffer](https://github.com/squizlabs/PHP_CodeSniffer)
and [mess detector](https://github.com/phpmd/phpmd) rulesets
that come with [`zapcore`](https://github.com/bfitech/zapcore)
repository:
that come with this repository:
```txt
$ export PATH=~/.composer/vendor/bin:$PATH
$
$ # coding convention compliance with phpcs
$ wget https://raw.githubusercontent.com/bfitech/zapcore/master/phpcs.xml
$ composer global require squizlabs/php_codesniffer
$ phpcs
$ phpcs \
> --standard=./phpcs.xml \
> --extensions=php \
> --runtime-set ignore_warnings_on_exit 1 \
> --report-width=72 \
> --no-cache \
> src
$
$ # static analysis with phpmd
$ wget https://raw.githubusercontent.com/bfitech/zapcore/master/phpmd.xml
$ composer global require phpmd/phpmd
$ phpmd ./src text ./phpmd.xml
```
9 changes: 4 additions & 5 deletions Doxyfile
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "Zapmin SMTP"
PROJECT_NUMBER = "1.4"
PROJECT_NUMBER = "2.3"
PROJECT_BRIEF = "SMTP extension for zapmin."
PROJECT_LOGO =
OUTPUT_DIRECTORY = ./docs
@@ -28,6 +28,7 @@ INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 4
ALIASES = codeCoverageIgnore="" \
SuppressWarnings="" \
fixme="@todo"
TCL_SUBST =
OPTIMIZE_OUTPUT_FOR_C = NO
@@ -102,8 +103,7 @@ WARN_LOGFILE =
#---------------------------------------------------------------------------
# Configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = src \
vendor/bfitech
INPUT = src dev README.md
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.php
RECURSIVE = YES
@@ -119,7 +119,7 @@ INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
FILTER_SOURCE_PATTERNS =
USE_MDFILE_AS_MAINPAGE =
USE_MDFILE_AS_MAINPAGE = README.md
#---------------------------------------------------------------------------
# Configuration options related to source browsing
#---------------------------------------------------------------------------
@@ -200,7 +200,6 @@ EXTRA_SEARCH_MAPPINGS =
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
MSCGEN_PATH =
DIA_PATH =
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = YES
34 changes: 34 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pipeline {
agent any
environment {
PROJECT = 'bfin--zapmin-smtp'
}
stages {
stage('branch: master') {
when {
branch 'master'
}
steps {
sh 'docker-phpunit 7.0 7.4'
}
post {
success {
sh 'jenkins-postproc'
}
}
}
stage('release') {
when {
tag '*'
}
steps {
sh 'docker-phpunit 7.0 7.4'
}
post {
success {
sh 'jenkins-postproc'
}
}
}
}
}
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -10,15 +10,18 @@
}
],
"require": {
"bfitech/zapmin": "~1.4.1",
"phpmailer/phpmailer": "~5.2.0"
"php": ">=7.0 <7.5",
"bfitech/zapmin": "2.3.*",
"phpmailer/phpmailer": "6.1.*"
},
"require-dev": {
"phpunit/phpunit": "4.8.*"
"phpunit/phpunit": "6.*"
},
"suggest": {
"bfitech/zapstore-mysql": "Use MySQL as database backend.",
"bfitech/zapstore-pgsql": "Use PostgreSQL as database backend."
"bfitech/zapstore-pgsql": "Use PostgreSQL as database backend.",
"bfitech/zapstore-redis": "Use Redis as additional backend.",
"bfitech/zapstore-predis": "Use Predis as additional backend."
},
"autoload": {
"psr-4": {
@@ -27,12 +30,13 @@
},
"autoload-dev": {
"psr-4": {
"BFITech\\ZapAdminDev\\": "dev",
"BFITech\\ZapCoreDev\\": "vendor/bfitech/zapcore/dev"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
"dev-master": "2.3.x-dev"
}
}
}
150 changes: 150 additions & 0 deletions dev/SMTPRouteDev.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php


namespace BFITech\ZapAdminDev;


use BFITech\ZapAdmin\SMTPRouteDefault;
use BFITech\ZapAdmin\Error;
use BFITech\ZapAdmin\SMTPError;
use BFITech\ZapCore\Common;


/**
* SMTP router for development.
*/
class SMTPRouteDev extends SMTPRouteDefault {

/**
* Fake authentication.
*
* Username is anything as long as it ends with @$host. Password
* is simply MD5 of the username. `ZAPMIN_SMTP_DEV` must be
* defined.
*
* @see apidoc
*
* @if TRUE
* @api {post} /smtp/fake-auth SMTPAuthFake
* @apiDescription
* Authenticate a fake user. For development only.
* @apiName SMTPAuthFake
* @apiGroup SMTP
* @apiParam (POST) {String} host SMTP host.
* @apiParam (POST) {Int} port SMTP port.
* @apiParam (POST) {String} username Username.
* @apiParam (POST) {String} password Password.
* @apiSuccess {Int=0} errno Success.
* @apiSuccess {Object} data User data.
* @apiSuccess {Int} data.uid User ID.
* @apiSuccess {String} data.uname Zapmin user identifier.
* @apiSuccess {String} data.token Session token.
* @apiError (401) {Int=
* Error::USER_ALREADY_LOGGED_IN
* } errno User already signed in.
* @apiError (403) {Int=SMTPError::*} errno Specific error number.
* See code documentation.
* @endif
*/
public function route_smtp_auth(array $args) {
$core = self::$core;
$manage = self::$manage;
$log = $manage::$logger;

if (!defined('ZAPMIN_SMTP_DEV'))
return $core::pj([1], 401);

if ($manage->is_logged_in()) {
# already signed in
$log->info(sprintf(
"SMTP: Auth already signed in: '%s'.",
$manage->get_user_data()['token']
));
return $core::pj([Error::USER_ALREADY_LOGGED_IN], 401);
}

$post = $args['post'];
$host = $port = $username = $password = null;
if (!Common::check_idict($post, [
'host', 'port', 'username', 'password'
]))
return $core::pj([SMTPError::AUTH_INCOMPLETE_DATA], 403);
extract($post);

$srv = array_filter(
$manage->list_services(),
function($ele) use($host, $port){
return $ele[0] == $host && $ele[1] == $port;
}
);
if (!$srv)
return $core::pj([SMTPError::SRV_NOT_FOUND]);

$shost = '@' . preg_replace('!^.+://(.+)$!', '$1', $host);
if (
substr_compare($username, $shost, -strlen($shost)) !== 0 ||
$password != md5($username)
)
return $core::pj([SMTPError::AUTH_FAILED]);

$username = rawurlencode($username);
$uservice = sprintf('smtp[%s:%s]', $host, $port);
$ret = $manage->self_add_passwordless([
'uname' => $username,
'uservice' => $uservice,
]);

$token_name = $this->token_name;
$token_value = $ret[1]['token'];

# alway autologin on success
$admin = $manage::$admin;
$expires = $admin::$store->time() + $admin->get_expiration();
$core::send_cookie_with_opts($token_name, $token_value, [
'path' => '/',
'expires' => $expires,
'httponly' => true,
'samesite' => 'Lax',
]);
$log->debug(sprintf(
"SMTP: Set cookie: [%s -> %s].",
$token_name, $token_value));

return $core::pj($ret);
}

/**
* Fake status.
*
* This is identical to non-fake
* BFITech\\ZapAdmin\\RouteDefault::route_status. Included for
* completeness sake.
*
* @see apidoc
*
* @if TRUE
* @api {get} /smtp/fake-status SMTPStatusFake
* @apiDescription
* Get user status. For development only.
* @apiName SMTPStatusFake
* @apiGroup SMTP
* @apiSuccess {Int=0} errno Success.
* @apiSuccess {Object} data User data.
* @apiSuccess {Int} data.uid User ID.
* @apiSuccess {String} data.uname Zapmin user identifier.
* @apiSuccess {String} data.email=null Email address.
* @apiSuccess {Int} data.email_verified=0 Whether email
* address is verified.
* @apiSuccess {String} data.fname=null Full name.
* @apiSuccess {String} data.site=null User website.
* @apiSuccess {Date} data.since Registration date.
* @apiError (401) {Int=
* Error::USER_NOT_LOGGED_IN
* } errno User not signed in.
* @endif
*/
public function route_fake_status() {
return self::$core->pj(self::$ctrl->get_safe_user_data());
}

}
Loading