@@ -9,112 +9,112 @@ |
||
| 9 | 9 | use SKien\PNServer\PNPayload; |
| 10 | 10 | use SKien\PNServer\PNServer; |
| 11 | 11 | |
| 12 | - // check, if PHP version is sufficient and all required extensions are installed |
|
| 13 | - $bExit = false; |
|
| 14 | - if (version_compare(phpversion(), '7.1', '<')) {
|
|
| 15 | - trigger_error('At least PHP Version 7.1 is required (current Version is ' . phpversion() . ')!', E_USER_WARNING);
|
|
| 16 | - $bExit = true; |
|
| 17 | - } |
|
| 18 | - $aExt = array('curl', 'gmp', 'mbstring', 'openssl', 'bcmath');
|
|
| 19 | - foreach ($aExt as $strExt) {
|
|
| 20 | - if (!extension_loaded($strExt)) {
|
|
| 21 | - trigger_error('Extension ' . $strExt . ' must be installed!', E_USER_WARNING);
|
|
| 22 | - $bExit = true; |
|
| 23 | - } |
|
| 24 | - } |
|
| 25 | - if ($bExit) {
|
|
| 26 | - exit(); |
|
| 27 | - } |
|
| 12 | + // check, if PHP version is sufficient and all required extensions are installed |
|
| 13 | + $bExit = false; |
|
| 14 | + if (version_compare(phpversion(), '7.1', '<')) {
|
|
| 15 | + trigger_error('At least PHP Version 7.1 is required (current Version is ' . phpversion() . ')!', E_USER_WARNING);
|
|
| 16 | + $bExit = true; |
|
| 17 | + } |
|
| 18 | + $aExt = array('curl', 'gmp', 'mbstring', 'openssl', 'bcmath');
|
|
| 19 | + foreach ($aExt as $strExt) {
|
|
| 20 | + if (!extension_loaded($strExt)) {
|
|
| 21 | + trigger_error('Extension ' . $strExt . ' must be installed!', E_USER_WARNING);
|
|
| 22 | + $bExit = true; |
|
| 23 | + } |
|
| 24 | + } |
|
| 25 | + if ($bExit) {
|
|
| 26 | + exit(); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - // for test use SQLite database - will be cretaed at first instantiation |
|
| 30 | - $oDP = new PNDataProviderSQLite(); |
|
| 29 | + // for test use SQLite database - will be cretaed at first instantiation |
|
| 30 | + $oDP = new PNDataProviderSQLite(); |
|
| 31 | 31 | |
| 32 | - // or may use any MySQL database |
|
| 33 | - // $oDP = new PNDataProviderMySQL('localhost', 'username', 'password', 'db-name');
|
|
| 32 | + // or may use any MySQL database |
|
| 33 | + // $oDP = new PNDataProviderMySQL('localhost', 'username', 'password', 'db-name');
|
|
| 34 | 34 | |
| 35 | - if (!$oDP->isConnected()) {
|
|
| 36 | - echo $oDP->getError(); |
|
| 37 | - exit(); |
|
| 38 | - } |
|
| 35 | + if (!$oDP->isConnected()) {
|
|
| 36 | + echo $oDP->getError(); |
|
| 37 | + exit(); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - // just add expired (unsubscribed) subscription to demonstrate response of |
|
| 41 | - // push service and the auto-remove option |
|
| 42 | - if (!$oDP->saveSubscription( |
|
| 43 | - '{'
|
|
| 44 | - .' "endpoint": "https://fcm.googleapis.com/fcm/send/f8PIq7EL6xI:APA91bFgD2qA0Goo_6sWgWVDKclh5Sm1Gf1BtYZw3rePs_GHqmC9l2N92I4QhLQtPmyB18HYYseFHLhvMbpq-oGz2Jtt8AVExmNU9R3K9Z-Gaiq6rQxig1WT4ND_5PSXTjuth-GoGggt",' |
|
| 45 | - .' "expirationTime": "1589291569000",' |
|
| 46 | - .' "keys": {'
|
|
| 47 | - .' "p256dh": "BEQrfuNX-ZrXPf0Mm-IdVMO1LMpu5N3ifgcyeUD2nYwuUhRUDmn_wVOM3eQyYux5vW2B8-TyTYco4-bFKKR02IA",' |
|
| 48 | - .' "auth": "jOfywakW_srfHhMF-NiZ3Q"' |
|
| 49 | - .' }' |
|
| 50 | - .'}' |
|
| 51 | - )) {
|
|
| 52 | - echo $oDP->getError(); |
|
| 53 | - exit(); |
|
| 54 | - } |
|
| 40 | + // just add expired (unsubscribed) subscription to demonstrate response of |
|
| 41 | + // push service and the auto-remove option |
|
| 42 | + if (!$oDP->saveSubscription( |
|
| 43 | + '{'
|
|
| 44 | + .' "endpoint": "https://fcm.googleapis.com/fcm/send/f8PIq7EL6xI:APA91bFgD2qA0Goo_6sWgWVDKclh5Sm1Gf1BtYZw3rePs_GHqmC9l2N92I4QhLQtPmyB18HYYseFHLhvMbpq-oGz2Jtt8AVExmNU9R3K9Z-Gaiq6rQxig1WT4ND_5PSXTjuth-GoGggt",' |
|
| 45 | + .' "expirationTime": "1589291569000",' |
|
| 46 | + .' "keys": {'
|
|
| 47 | + .' "p256dh": "BEQrfuNX-ZrXPf0Mm-IdVMO1LMpu5N3ifgcyeUD2nYwuUhRUDmn_wVOM3eQyYux5vW2B8-TyTYco4-bFKKR02IA",' |
|
| 48 | + .' "auth": "jOfywakW_srfHhMF-NiZ3Q"' |
|
| 49 | + .' }' |
|
| 50 | + .'}' |
|
| 51 | + )) {
|
|
| 52 | + echo $oDP->getError(); |
|
| 53 | + exit(); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - echo 'Count of subscriptions: ' . $oDP->count() . '<br/><br/>' . PHP_EOL; |
|
| 57 | - if ($oDP->init()) {
|
|
| 58 | - while (($strJsonSub = $oDP->fetch()) !== false) {
|
|
| 59 | - echo 'UA: ' . $oDP->getColumn(PNDataProvider::COL_USERAGENT); |
|
| 60 | - echo ' (Lastupdated: ' . date('Y-m-d H:i:s', $oDP->getColumn(PNDataProvider::COL_LASTUPDATED)) . ')<br/>' . PHP_EOL;
|
|
| 61 | - $strPrintable = json_encode(json_decode($strJsonSub), JSON_PRETTY_PRINT); |
|
| 62 | - $strPrintable = str_replace("\n", '<br/>', $strPrintable);
|
|
| 63 | - $strPrintable = str_replace(" ", ' ', $strPrintable);
|
|
| 64 | - echo '<span style="font-size: 10pt; font-family: courier; overflow:scroll; white-space: nowrap">' . $strPrintable . '</span><br/><br/>' . PHP_EOL; |
|
| 65 | - } |
|
| 66 | - } else {
|
|
| 67 | - echo $oDP->getError(); |
|
| 68 | - exit(); |
|
| 69 | - } |
|
| 56 | + echo 'Count of subscriptions: ' . $oDP->count() . '<br/><br/>' . PHP_EOL; |
|
| 57 | + if ($oDP->init()) {
|
|
| 58 | + while (($strJsonSub = $oDP->fetch()) !== false) {
|
|
| 59 | + echo 'UA: ' . $oDP->getColumn(PNDataProvider::COL_USERAGENT); |
|
| 60 | + echo ' (Lastupdated: ' . date('Y-m-d H:i:s', $oDP->getColumn(PNDataProvider::COL_LASTUPDATED)) . ')<br/>' . PHP_EOL;
|
|
| 61 | + $strPrintable = json_encode(json_decode($strJsonSub), JSON_PRETTY_PRINT); |
|
| 62 | + $strPrintable = str_replace("\n", '<br/>', $strPrintable);
|
|
| 63 | + $strPrintable = str_replace(" ", ' ', $strPrintable);
|
|
| 64 | + echo '<span style="font-size: 10pt; font-family: courier; overflow:scroll; white-space: nowrap">' . $strPrintable . '</span><br/><br/>' . PHP_EOL; |
|
| 65 | + } |
|
| 66 | + } else {
|
|
| 67 | + echo $oDP->getError(); |
|
| 68 | + exit(); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - // the server to handle all |
|
| 72 | - $oServer = new PNServer($oDP); |
|
| 71 | + // the server to handle all |
|
| 72 | + $oServer = new PNServer($oDP); |
|
| 73 | 73 | |
| 74 | - // set the VAPID key |
|
| 75 | - /* |
|
| 74 | + // set the VAPID key |
|
| 75 | + /* |
|
| 76 | 76 | $oVapid = new PNVapid( |
| 77 | 77 | "mailto:[email protected]", |
| 78 | 78 | "the-generated-public-key", |
| 79 | 79 | "the-generated-private-key" |
| 80 | 80 | ); |
| 81 | 81 | */ |
| 82 | - $oVapid = new PNVapid( |
|
| 83 | - "mailto:[email protected]", |
|
| 84 | - "BDtOCcUUTYvuUzx9ktgYs3mB6tQCjFLNfOkuiaIi_2LNosLbHQY6P91eMzQ8opTDLK_PjJHsjMSiJ-MUOeSjV8E", |
|
| 85 | - "juLDCbPNbObvn-89_o0SEbnBZLMWxlVEjGypyxHEh2M" |
|
| 86 | - ); |
|
| 82 | + $oVapid = new PNVapid( |
|
| 83 | + "mailto:[email protected]", |
|
| 84 | + "BDtOCcUUTYvuUzx9ktgYs3mB6tQCjFLNfOkuiaIi_2LNosLbHQY6P91eMzQ8opTDLK_PjJHsjMSiJ-MUOeSjV8E", |
|
| 85 | + "juLDCbPNbObvn-89_o0SEbnBZLMWxlVEjGypyxHEh2M" |
|
| 86 | + ); |
|
| 87 | 87 | |
| 88 | - $oServer->setVapid($oVapid); |
|
| 88 | + $oServer->setVapid($oVapid); |
|
| 89 | 89 | |
| 90 | - // create payload |
|
| 91 | - // - we don't set a title - so service worker uses default |
|
| 92 | - // - URL to icon can be |
|
| 93 | - // * relative to the origin location of the service worker |
|
| 94 | - // * absolute from the homepage (begining with a '/') |
|
| 95 | - // * complete URL (beginning with https://) |
|
| 96 | - $oPayload = new PNPayload('', "...first text to display.", './elephpant.png');
|
|
| 97 | - // set tag to group the notifications but always show the popup |
|
| 98 | - $oPayload->setTag('news', true);
|
|
| 99 | - // and lead the user to thr page of your choice |
|
| 100 | - $oPayload->setURL('/where-to-go.php');
|
|
| 90 | + // create payload |
|
| 91 | + // - we don't set a title - so service worker uses default |
|
| 92 | + // - URL to icon can be |
|
| 93 | + // * relative to the origin location of the service worker |
|
| 94 | + // * absolute from the homepage (begining with a '/') |
|
| 95 | + // * complete URL (beginning with https://) |
|
| 96 | + $oPayload = new PNPayload('', "...first text to display.", './elephpant.png');
|
|
| 97 | + // set tag to group the notifications but always show the popup |
|
| 98 | + $oPayload->setTag('news', true);
|
|
| 99 | + // and lead the user to thr page of your choice |
|
| 100 | + $oPayload->setURL('/where-to-go.php');
|
|
| 101 | 101 | |
| 102 | - $oServer->setPayload($oPayload); |
|
| 102 | + $oServer->setPayload($oPayload); |
|
| 103 | 103 | |
| 104 | - // load subscriptions from database (incluing the expired one created above...) |
|
| 105 | - if (!$oServer->loadSubscriptions()) {
|
|
| 106 | - echo $oDP->getError(); |
|
| 107 | - exit(); |
|
| 108 | - } |
|
| 104 | + // load subscriptions from database (incluing the expired one created above...) |
|
| 105 | + if (!$oServer->loadSubscriptions()) {
|
|
| 106 | + echo $oDP->getError(); |
|
| 107 | + exit(); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - // ... and finally push ! |
|
| 111 | - if (!$oServer->push()) {
|
|
| 112 | - echo '<h2>' . $oServer->getError() . '</h2>' . PHP_EOL; |
|
| 113 | - } else {
|
|
| 114 | - $aLog = $oServer->getLog(); |
|
| 115 | - echo '<h2>Push - Log:</h2>' . PHP_EOL; |
|
| 116 | - foreach ($aLog as $strEndpoint => $aMsg ) {
|
|
| 117 | - echo '<h3>' . PNSubscription::getOrigin($strEndpoint) . '</h3>' . PHP_EOL; |
|
| 118 | - echo $aMsg['msg'] . '<br/>resonse code: ' . $aMsg['curl_response_code'] . ' (' . $aMsg['curl_response'] . ')';
|
|
| 119 | - } |
|
| 120 | - } |
|
| 110 | + // ... and finally push ! |
|
| 111 | + if (!$oServer->push()) {
|
|
| 112 | + echo '<h2>' . $oServer->getError() . '</h2>' . PHP_EOL; |
|
| 113 | + } else {
|
|
| 114 | + $aLog = $oServer->getLog(); |
|
| 115 | + echo '<h2>Push - Log:</h2>' . PHP_EOL; |
|
| 116 | + foreach ($aLog as $strEndpoint => $aMsg ) {
|
|
| 117 | + echo '<h3>' . PNSubscription::getOrigin($strEndpoint) . '</h3>' . PHP_EOL; |
|
| 118 | + echo $aMsg['msg'] . '<br/>resonse code: ' . $aMsg['curl_response_code'] . ' (' . $aMsg['curl_response'] . ')';
|
|
| 119 | + } |
|
| 120 | + } |
|
@@ -119,18 +119,18 @@ |
||
| 119 | 119 | return $result; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - public static function modSub($minuend, $subtrahend, $modulus) |
|
| 123 | - { |
|
| 124 | - return self::mod(self::sub($minuend, $subtrahend), $modulus); |
|
| 125 | - } |
|
| 122 | + public static function modSub($minuend, $subtrahend, $modulus) |
|
| 123 | + { |
|
| 124 | + return self::mod(self::sub($minuend, $subtrahend), $modulus); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - public static function modMul($multiplier, $muliplicand, $modulus) |
|
| 128 | - { |
|
| 129 | - return self::mod(self::mul($multiplier, $muliplicand), $modulus); |
|
| 130 | - } |
|
| 127 | + public static function modMul($multiplier, $muliplicand, $modulus) |
|
| 128 | + { |
|
| 129 | + return self::mod(self::mul($multiplier, $muliplicand), $modulus); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - public static function modDiv($dividend, $divisor, $modulus) |
|
| 133 | - { |
|
| 134 | - return self::mul($dividend, self::inverseMod($divisor, $modulus), $modulus); |
|
| 135 | - } |
|
| 132 | + public static function modDiv($dividend, $divisor, $modulus) |
|
| 133 | + { |
|
| 134 | + return self::mul($dividend, self::inverseMod($divisor, $modulus), $modulus); |
|
| 135 | + } |
|
| 136 | 136 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | if (!file_exists($this->strDBName)) { |
| 67 | 67 | $strDir = pathinfo($this->strDBName, PATHINFO_DIRNAME) == '' ? __DIR__ : pathinfo($this->strDBName, PATHINFO_DIRNAME); |
| 68 | 68 | if (!is_writable($strDir)) { |
| 69 | - $this->strLastError .= ' (no rights to write on directory ' . $strDir . ')'; |
|
| 69 | + $this->strLastError .= ' (no rights to write on directory ' . $strDir . ')'; |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | } else if (!$this->tableExist()) { |
| 85 | 85 | if (strlen($this->strLastError) == 0) { |
| 86 | - $this->strLastError = 'database table ' . $this->strTableName . ' not exist!'; |
|
| 86 | + $this->strLastError = 'database table ' . $this->strTableName . ' not exist!'; |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | return ($this->db && $this->bTableExist); |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | if ($this->isConnected()) { |
| 210 | 210 | $iCount = $this->db->querySingle("SELECT count(*) FROM " . $this->strTableName); |
| 211 | 211 | if ($iCount === false) { |
| 212 | - $this->strLastError = 'SQLite3: ' . $this->db->lastErrorMsg(); |
|
| 212 | + $this->strLastError = 'SQLite3: ' . $this->db->lastErrorMsg(); |
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | return $iCount; |
@@ -6,23 +6,23 @@ |
||
| 6 | 6 | $result = array(); |
| 7 | 7 | // only serve POST request containing valid json data |
| 8 | 8 | if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
|
| 9 | - if (isset($_SERVER['CONTENT_TYPE']) && trim(strtolower($_SERVER['CONTENT_TYPE']) == 'application/json')) {
|
|
| 10 | - // get posted json data |
|
| 11 | - if (($strJSON = trim(file_get_contents('php://input'))) === false) {
|
|
| 12 | - $result['msg'] = 'invalid JSON data!'; |
|
| 13 | - } else {
|
|
| 14 | - $oDP = new PNDataProviderSQLite(); |
|
| 15 | - if ($oDP->saveSubscription($strJSON) !== false) {
|
|
| 16 | - $result['msg'] = 'subscription saved on server!'; |
|
| 17 | - } else {
|
|
| 18 | - $result['msg'] = 'error saving subscription!'; |
|
| 19 | - } |
|
| 20 | - } |
|
| 21 | - } else {
|
|
| 22 | - $result['msg'] = 'invalid content type!'; |
|
| 23 | - } |
|
| 9 | + if (isset($_SERVER['CONTENT_TYPE']) && trim(strtolower($_SERVER['CONTENT_TYPE']) == 'application/json')) {
|
|
| 10 | + // get posted json data |
|
| 11 | + if (($strJSON = trim(file_get_contents('php://input'))) === false) {
|
|
| 12 | + $result['msg'] = 'invalid JSON data!'; |
|
| 13 | + } else {
|
|
| 14 | + $oDP = new PNDataProviderSQLite(); |
|
| 15 | + if ($oDP->saveSubscription($strJSON) !== false) {
|
|
| 16 | + $result['msg'] = 'subscription saved on server!'; |
|
| 17 | + } else {
|
|
| 18 | + $result['msg'] = 'error saving subscription!'; |
|
| 19 | + } |
|
| 20 | + } |
|
| 21 | + } else {
|
|
| 22 | + $result['msg'] = 'invalid content type!'; |
|
| 23 | + } |
|
| 24 | 24 | } else {
|
| 25 | - $result['msg'] = 'no post request!'; |
|
| 25 | + $result['msg'] = 'no post request!'; |
|
| 26 | 26 | } |
| 27 | 27 | // let the service-worker know the result |
| 28 | 28 | echo json_encode($result); |