| 
									
										
										
										
											2017-06-16 17:36:42 -06:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 13:27:09 -07:00
										 |  |  | /* This Source Code Form is subject to the terms of the Mozilla Public | 
					
						
							|  |  |  |  * License, v. 2.0. If a copy of the MPL was not distributed with this | 
					
						
							|  |  |  |  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-16 17:36:42 -06:00
										 |  |  | dieifnotloggedin(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-15 20:39:35 -06:00
										 |  |  | use Endroid\QrCode\ErrorCorrectionLevel; | 
					
						
							| 
									
										
										
										
											2017-06-16 17:36:42 -06:00
										 |  |  | use Endroid\QrCode\QrCode; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 03:27:08 -06:00
										 |  |  | if (MOBILE_ENABLED) { | 
					
						
							| 
									
										
										
										
											2017-06-16 17:36:42 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-09 23:16:43 -06:00
										 |  |  |     $APPS["sync_mobile"]["title"] = $Strings->get("sync mobile", false); | 
					
						
							| 
									
										
										
										
											2017-07-03 03:27:08 -06:00
										 |  |  |     $APPS["sync_mobile"]["icon"] = "mobile"; | 
					
						
							| 
									
										
										
										
											2017-06-16 17:36:42 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 03:27:08 -06:00
										 |  |  |     if (!is_empty($_GET['delsynccode'])) { | 
					
						
							|  |  |  |         if ($database->has("mobile_codes", ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['delsynccode']]])) { | 
					
						
							|  |  |  |             $database->delete("mobile_codes", ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['delsynccode']]]); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-06-16 17:36:42 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-03 03:27:08 -06:00
										 |  |  |     if ($_GET['mobilecode'] == "generate") { | 
					
						
							|  |  |  |         if (!is_empty($_GET['showsynccode']) && $database->has("mobile_codes", ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['showsynccode']]])) { | 
					
						
							|  |  |  |             $code = $database->get("mobile_codes", 'code', ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['showsynccode']]]); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $code = strtoupper(substr(md5(mt_rand() . uniqid("", true)), 0, 20)); | 
					
						
							|  |  |  |             $database->insert('mobile_codes', ['uid' => $_SESSION['uid'], 'code' => $code]); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-08-06 23:42:17 -06:00
										 |  |  |         if (strpos(URL, "http") !== FALSE) { | 
					
						
							|  |  |  |             $url = URL . "mobile/index.php"; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . (($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) ? ":" . $_SERVER['SERVER_PORT'] : "") . URL . "mobile/index.php"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-07-03 03:27:08 -06:00
										 |  |  |         $encodedurl = str_replace("/", "\\", $url); | 
					
						
							|  |  |  |         $codeuri = "bizsync://" . $encodedurl . "/" . $_SESSION['username'] . "/" . $code; | 
					
						
							|  |  |  |         $qrCode = new QrCode($codeuri); | 
					
						
							| 
									
										
										
										
											2018-04-15 20:39:35 -06:00
										 |  |  |         $qrCode->setWriterByName('svg'); | 
					
						
							|  |  |  |         $qrCode->setSize(550); | 
					
						
							|  |  |  |         $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH); | 
					
						
							|  |  |  |         $qrcode = $qrCode->writeDataUri(); | 
					
						
							| 
									
										
										
										
											2017-07-03 03:27:08 -06:00
										 |  |  |         $chunk_code = trim(chunk_split($code, 5, ' ')); | 
					
						
							| 
									
										
										
										
											2018-07-09 23:16:43 -06:00
										 |  |  |         $lang_done = $Strings->get("done adding sync code", false); | 
					
						
							| 
									
										
										
										
											2017-07-24 17:17:11 -06:00
										 |  |  |         $APPS["sync_mobile"]["content"] = '<div class="alert alert-info"><i class="fa fa-info-circle"></i> ' | 
					
						
							| 
									
										
										
										
											2018-07-09 23:16:43 -06:00
										 |  |  |                 . $Strings->get("scan sync qrcode", false) | 
					
						
							| 
									
										
										
										
											2017-07-24 17:17:11 -06:00
										 |  |  |                 . '</div>' | 
					
						
							|  |  |  |                 . <<<END | 
					
						
							| 
									
										
										
										
											2017-11-13 16:14:47 -07:00
										 |  |  | <style nonce="$SECURE_NONCE"> | 
					
						
							|  |  |  | .margintop-15px { | 
					
						
							|  |  |  |     margin-top: 15px; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | .mono-chunk { | 
					
						
							|  |  |  |     text-align: center; | 
					
						
							|  |  |  |     font-size: 110%; | 
					
						
							|  |  |  |     font-family: monospace; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | </style> | 
					
						
							| 
									
										
										
										
											2017-06-16 17:36:42 -06:00
										 |  |  | <img src="$qrcode" class="img-responsive qrcode" /> | 
					
						
							| 
									
										
										
										
											2017-11-13 16:14:47 -07:00
										 |  |  | <div class="panel panel-default margintop-15px"> | 
					
						
							| 
									
										
										
										
											2017-07-24 17:17:11 -06:00
										 |  |  | <div class="panel-body"> | 
					
						
							|  |  |  | END | 
					
						
							| 
									
										
										
										
											2018-07-09 23:16:43 -06:00
										 |  |  |                 . "<b>" . $Strings->get("manual setup", false) . "</b><br /><label>" . $Strings->get("username", false) . ":</label>" | 
					
						
							| 
									
										
										
										
											2017-11-13 16:14:47 -07:00
										 |  |  |                 . '<div class="well well-sm mono-chunk">' . $_SESSION['username'] . '</div>' | 
					
						
							| 
									
										
										
										
											2018-07-09 23:16:43 -06:00
										 |  |  |                 . "<label>" . $Strings->get("sync key", false) . "</label>" | 
					
						
							| 
									
										
										
										
											2017-07-24 17:17:11 -06:00
										 |  |  |                 . <<<END | 
					
						
							| 
									
										
										
										
											2017-11-13 16:14:47 -07:00
										 |  |  | <div class="well well-sm mono-chunk">$chunk_code</div> | 
					
						
							| 
									
										
										
										
											2017-07-24 17:17:11 -06:00
										 |  |  | END | 
					
						
							| 
									
										
										
										
											2018-07-09 23:16:43 -06:00
										 |  |  |                 . "<label>" . $Strings->get("url", false) . "</label>" | 
					
						
							| 
									
										
										
										
											2017-07-24 17:17:11 -06:00
										 |  |  |                 . <<<END | 
					
						
							| 
									
										
										
										
											2017-11-13 16:14:47 -07:00
										 |  |  | <div class="well well-sm mono-chunk">$url</div> | 
					
						
							| 
									
										
										
										
											2017-07-24 17:17:11 -06:00
										 |  |  | </div> | 
					
						
							|  |  |  | </div> | 
					
						
							| 
									
										
										
										
											2018-01-17 21:02:15 -07:00
										 |  |  | <a class="btn btn-success btn-sm btn-block" href="home.php?page=sync">$lang_done</a> | 
					
						
							| 
									
										
										
										
											2017-06-16 17:36:42 -06:00
										 |  |  | END; | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2017-07-03 03:27:08 -06:00
										 |  |  |         $activecodes = $database->select("mobile_codes", ["codeid", "code"], ["uid" => $_SESSION['uid']]); | 
					
						
							| 
									
										
										
										
											2018-07-09 23:16:43 -06:00
										 |  |  |         $content = '<div class="alert alert-info"><i class="fa fa-info-circle"></i> ' . $Strings->get("sync explained", false) . '</div>' | 
					
						
							| 
									
										
										
										
											2018-01-17 21:02:15 -07:00
										 |  |  |                 . '<a class="btn btn-success btn-sm btn-block" href="home.php?page=sync&mobilecode=generate">' | 
					
						
							| 
									
										
										
										
											2018-07-09 23:16:43 -06:00
										 |  |  |                 . $Strings->get("generate sync", false) . '</a>'; | 
					
						
							|  |  |  |         $content .= "<br /><b>" . $Strings->get("active sync codes", false) . ":</b><br />"; | 
					
						
							| 
									
										
										
										
											2017-07-03 03:27:08 -06:00
										 |  |  |         $content .= "<div class='list-group'>"; | 
					
						
							|  |  |  |         if (count($activecodes) > 0) { | 
					
						
							|  |  |  |             foreach ($activecodes as $c) { | 
					
						
							| 
									
										
										
										
											2018-01-17 21:02:15 -07:00
										 |  |  |                 $content .= "<div class='list-group-item mobilekey'><span id=\"mobilecode\">" . trim(chunk_split($c['code'], 5, ' ')) . "</span> <span class='tinybuttons'><a class='btn btn-primary btn-sm' href='home.php?page=sync&mobilecode=generate&showsynccode=" . $c['codeid'] . "'><i class='fa fa-qrcode'></i></a> <a class='btn btn-danger btn-sm' href='home.php?page=sync&delsynccode=" . $c['codeid'] . "'><i class='fa fa-trash'></i></a></span></div>"; | 
					
						
							| 
									
										
										
										
											2017-07-03 03:27:08 -06:00
										 |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2018-07-09 23:16:43 -06:00
										 |  |  |             $content .= "<div class='list-group-item'>" . $Strings->get("no active codes", false) . "</div>"; | 
					
						
							| 
									
										
										
										
											2017-07-03 03:27:08 -06:00
										 |  |  |         } | 
					
						
							|  |  |  |         $content .= "</div>"; | 
					
						
							|  |  |  |         $content .= <<<END | 
					
						
							| 
									
										
										
										
											2017-11-13 16:14:47 -07:00
										 |  |  |             <style nonce="$SECURE_NONCE"> | 
					
						
							| 
									
										
										
										
											2017-06-24 00:32:33 -06:00
										 |  |  |                 .mobilekey { | 
					
						
							|  |  |  |                     display: flex; | 
					
						
							|  |  |  |                     flex-wrap: wrap; | 
					
						
							|  |  |  |                     justify-content: space-between; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-11-13 16:14:47 -07:00
										 |  |  |                 .mobilekey #mobilecode {
 | 
					
						
							|  |  |  |                     font-family: Ubuntu Mono,monospace; | 
					
						
							|  |  |  |                     flex-shrink: 0; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-06-24 00:32:33 -06:00
										 |  |  |             </style> | 
					
						
							|  |  |  | END; | 
					
						
							| 
									
										
										
										
											2017-07-03 03:27:08 -06:00
										 |  |  |         $APPS["sync_mobile"]["content"] = $content; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-06-16 17:36:42 -06:00
										 |  |  | } |