Single-sign-on and self-serve account management. https://netsyms.biz/apps/accounthub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sync_mobile.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. dieifnotloggedin();
  6. use Endroid\QrCode\ErrorCorrectionLevel;
  7. use Endroid\QrCode\QrCode;
  8. if (MOBILE_ENABLED) {
  9. $APPS["sync_mobile"]["title"] = $Strings->get("sync mobile", false);
  10. $APPS["sync_mobile"]["icon"] = "mobile";
  11. if (!is_empty($_GET['delsynccode'])) {
  12. if ($database->has("mobile_codes", ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['delsynccode']]])) {
  13. $database->delete("mobile_codes", ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['delsynccode']]]);
  14. }
  15. }
  16. if ($_GET['mobilecode'] == "generate") {
  17. if (!is_empty($_GET['showsynccode']) && $database->has("mobile_codes", ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['showsynccode']]])) {
  18. $code = $database->get("mobile_codes", 'code', ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['showsynccode']]]);
  19. } else {
  20. $code = strtoupper(substr(md5(mt_rand() . uniqid("", true)), 0, 20));
  21. $database->insert('mobile_codes', ['uid' => $_SESSION['uid'], 'code' => $code]);
  22. }
  23. if (strpos(URL, "http") !== FALSE) {
  24. $url = URL . "mobile/index.php";
  25. } else {
  26. $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . (($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) ? ":" . $_SERVER['SERVER_PORT'] : "") . URL . "mobile/index.php";
  27. }
  28. $encodedurl = str_replace("/", "\\", $url);
  29. $codeuri = "bizsync://" . $encodedurl . "/" . $_SESSION['username'] . "/" . $code;
  30. $qrCode = new QrCode($codeuri);
  31. $qrCode->setWriterByName('svg');
  32. $qrCode->setSize(550);
  33. $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH);
  34. $qrcode = $qrCode->writeDataUri();
  35. $chunk_code = trim(chunk_split($code, 5, ' '));
  36. $lang_done = $Strings->get("done adding sync code", false);
  37. $APPS["sync_mobile"]["content"] = '<div class="alert alert-info"><i class="fa fa-info-circle"></i> '
  38. . $Strings->get("scan sync qrcode", false)
  39. . '</div>'
  40. . <<<END
  41. <style nonce="$SECURE_NONCE">
  42. .margintop-15px {
  43. margin-top: 15px;
  44. }
  45. .mono-chunk {
  46. text-align: center;
  47. font-size: 110%;
  48. font-family: monospace;
  49. }
  50. </style>
  51. <img src="$qrcode" class="img-responsive qrcode" />
  52. <div class="panel panel-default margintop-15px">
  53. <div class="panel-body">
  54. END
  55. . "<b>" . $Strings->get("manual setup", false) . "</b><br /><label>" . $Strings->get("username", false) . ":</label>"
  56. . '<div class="well well-sm mono-chunk">' . $_SESSION['username'] . '</div>'
  57. . "<label>" . $Strings->get("sync key", false) . "</label>"
  58. . <<<END
  59. <div class="well well-sm mono-chunk">$chunk_code</div>
  60. END
  61. . "<label>" . $Strings->get("url", false) . "</label>"
  62. . <<<END
  63. <div class="well well-sm mono-chunk">$url</div>
  64. </div>
  65. </div>
  66. <a class="btn btn-success btn-sm btn-block" href="home.php?page=sync">$lang_done</a>
  67. END;
  68. } else {
  69. $activecodes = $database->select("mobile_codes", ["codeid", "code"], ["uid" => $_SESSION['uid']]);
  70. $content = '<div class="alert alert-info"><i class="fa fa-info-circle"></i> ' . $Strings->get("sync explained", false) . '</div>'
  71. . '<a class="btn btn-success btn-sm btn-block" href="home.php?page=sync&mobilecode=generate">'
  72. . $Strings->get("generate sync", false) . '</a>';
  73. $content .= "<br /><b>" . $Strings->get("active sync codes", false) . ":</b><br />";
  74. $content .= "<div class='list-group'>";
  75. if (count($activecodes) > 0) {
  76. foreach ($activecodes as $c) {
  77. $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>";
  78. }
  79. } else {
  80. $content .= "<div class='list-group-item'>" . $Strings->get("no active codes", false) . "</div>";
  81. }
  82. $content .= "</div>";
  83. $content .= <<<END
  84. <style nonce="$SECURE_NONCE">
  85. .mobilekey {
  86. display: flex;
  87. flex-wrap: wrap;
  88. justify-content: space-between;
  89. }
  90. .mobilekey #mobilecode {
  91. font-family: Ubuntu Mono,monospace;
  92. flex-shrink: 0;
  93. }
  94. </style>
  95. END;
  96. $APPS["sync_mobile"]["content"] = $content;
  97. }
  98. }