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.php 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /*
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. */
  7. use Endroid\QrCode\ErrorCorrectionLevel;
  8. use Endroid\QrCode\QrCode;
  9. if (!empty($_GET['delsynccode'])) {
  10. if ($database->has("mobile_codes", ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['delsynccode']]])) {
  11. $database->delete("mobile_codes", ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['delsynccode']]]);
  12. }
  13. }
  14. ?>
  15. <div class="row justify-content-center">
  16. <div class="col-sm-10 col-md-6 col-lg-4 col-xl-4">
  17. <div class="card mb-4">
  18. <div class="card-body">
  19. <h5 class="card-title"><i class="fas fa-mobile-alt"></i> <?php $Strings->get("sync mobile"); ?></h5>
  20. <hr />
  21. <?php
  22. if (!empty($_GET['mobilecode']) && $_GET['mobilecode'] == "generate") {
  23. if (!empty($_GET['showsynccode']) && $database->has("mobile_codes", ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['showsynccode']]])) {
  24. $code = $database->get("mobile_codes", 'code', ["AND" => ["uid" => $_SESSION['uid'], "codeid" => $_GET['showsynccode']]]);
  25. } else {
  26. $code = strtoupper(substr(md5(mt_rand() . uniqid("", true)), 0, 20));
  27. $desc = htmlspecialchars($_POST['desc']);
  28. $database->insert('mobile_codes', ['uid' => $_SESSION['uid'], 'code' => $code, 'description' => $desc]);
  29. }
  30. if (strpos(URL, "http") === 0) {
  31. $url = URL . "mobile/index.php";
  32. } else {
  33. $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . (($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) ? ":" . $_SERVER['SERVER_PORT'] : "") . URL . "mobile/index.php";
  34. }
  35. $encodedurl = str_replace("/", "\\", $url);
  36. $codeuri = "bizsync://" . $encodedurl . "/" . $_SESSION['username'] . "/" . $code;
  37. $qrCode = new QrCode($codeuri);
  38. $qrCode->setWriterByName('svg');
  39. $qrCode->setSize(550);
  40. $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH);
  41. $qrcode = $qrCode->writeDataUri();
  42. $chunk_code = trim(chunk_split($code, 5, ' '));
  43. $lang_done = $Strings->get("done adding sync code", false);
  44. ?>
  45. <p class="card-text"><?php $Strings->get("scan sync qrcode"); ?></p>
  46. </div>
  47. <img src="<?php echo $qrcode; ?>" class="card-img px-4" />
  48. <div class="card-body">
  49. <a class="btn btn-success btn-block" href="app.php?page=sync"><?php $Strings->get("done adding sync code"); ?></a>
  50. </div>
  51. <div class="list-group list-group-flush">
  52. <div class="list-group-item">
  53. <b><?php $Strings->get("manual setup"); ?></b>
  54. </div>
  55. <div class="list-group-item d-flex justify-content-between align-items-baseline">
  56. <div><?php $Strings->get("username"); ?>:</div>
  57. <div class="text-monospace text-right"><?php echo $_SESSION['username']; ?></div>
  58. </div>
  59. <div class="list-group-item d-flex justify-content-between align-items-baseline">
  60. <div><?php $Strings->get("sync key"); ?></div>
  61. <div class="text-monospace text-right"><?php echo $chunk_code; ?></div>
  62. </div>
  63. <div class="list-group-item d-flex justify-content-between align-items-baseline">
  64. <div><?php $Strings->get("url"); ?></div>
  65. <div class="text-monospace text-right"><?php echo $url; ?></div>
  66. </div>
  67. </div>
  68. <?php
  69. } else {
  70. $activecodes = $database->select("mobile_codes", ["codeid", "code", "description"], ["uid" => $_SESSION['uid']]);
  71. ?>
  72. <p class="card-text">
  73. <?php $Strings->get("sync explained"); ?>
  74. </p>
  75. <form action="app.php?page=sync&mobilecode=generate" method="POST">
  76. <input type="text" name="desc" class="form-control" placeholder="<?php $Strings->get("sync code name"); ?>" required />
  77. <button class="btn btn-success btn-block mt-2" type="submit">
  78. <?php $Strings->get("generate sync"); ?>
  79. </button>
  80. </form>
  81. </div>
  82. <div class="list-group list-group-flush">
  83. <div class="list-group-item">
  84. <b><?php $Strings->get("active sync codes"); ?></b>
  85. </div>
  86. <?php
  87. if (count($activecodes) > 0) {
  88. foreach ($activecodes as $c) {
  89. ?>
  90. <div class="list-group-item d-flex justify-content-between align-items-center">
  91. <div>
  92. <div class="text-monospace">
  93. <?php echo trim(chunk_split($c['code'], 5, ' ')); ?>
  94. </div>
  95. <div class="text-muted">
  96. <i class="fas fa-mobile-alt"></i> <?php echo $c['description']; ?>
  97. </div>
  98. </div>
  99. <div>
  100. <a class="btn btn-primary btn-sm m-1" href="app.php?page=sync&mobilecode=generate&showsynccode=<?php echo $c['codeid']; ?>">
  101. <i class="fas fa-qrcode"></i>
  102. </a>
  103. <a class="btn btn-danger btn-sm m-1" href="app.php?page=sync&delsynccode=<?php echo $c['codeid']; ?>">
  104. <i class='fas fa-trash'></i>
  105. </a>
  106. </div>
  107. </div>
  108. <?php
  109. }
  110. } else {
  111. ?>
  112. <div class="list-group-item">
  113. <?php $Strings->get("no active codes"); ?>
  114. </div>
  115. <?php
  116. }
  117. ?>
  118. </div>
  119. <?php
  120. }
  121. ?>
  122. </div>
  123. </div>
  124. <div class="col-sm-10 col-md-6 col-lg-4 col-xl-4">
  125. <div class="card">
  126. <div class="card-body">
  127. <h5 class="card-title"><i class="fas fa-rss-square"></i> <?php $Strings->get("Notifications"); ?></h5>
  128. <hr />
  129. <p class="card-text">
  130. <?php $Strings->get("notification feed explained"); ?>
  131. </p>
  132. <?php
  133. if ($database->has('userkeys', ['AND' => ['uid' => $_SESSION['uid'], 'typeid' => 1]])) {
  134. $key = $database->get('userkeys', 'key', ['AND' => ['uid' => $_SESSION['uid'], 'typeid' => 1]]);
  135. } else {
  136. $key = RandomString::generate(50);
  137. while ($database->has('userkeys', ['key' => $key])) {
  138. $key = RandomString::generate(50);
  139. }
  140. $database->insert('userkeys', ['uid' => $_SESSION['uid'], 'typeid' => 1, 'created' => date('Y-m-d H:i:s'), 'key' => $key]);
  141. }
  142. if (strpos(URL, "http") === 0) {
  143. $url = URL;
  144. } else {
  145. $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . (($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) ? ":" . $_SERVER['SERVER_PORT'] : "") . URL;
  146. }
  147. $url = $url . "feed.php?key=$key";
  148. ?>
  149. <a href="<?php echo $url; ?>&type=rss2" target="_BLANK" class="btn btn-orange mr-2"><i class="fas fa-rss"></i> RSS 2.0</a>
  150. <a href="<?php echo $url; ?>&type=rss1" target="_BLANK" class="btn btn-orange mr-2"><i class="fas fa-rss"></i> RSS 1.0</a>
  151. <a href="<?php echo $url; ?>&type=atom" target="_BLANK" class="btn btn-blue"><i class="fas fa-atom"></i> ATOM</a>
  152. <hr />
  153. RSS 2.0: <input type="text" readonly class="form-control" value="<?php echo $url; ?>&type=rss2" />
  154. <br />
  155. RSS 1.0: <input type="text" readonly class="form-control" value="<?php echo $url; ?>&type=rss1" />
  156. <br />
  157. ATOM: <input type="text" readonly class="form-control" value="<?php echo $url; ?>&type=atom" />
  158. <hr />
  159. <form action="action.php" method="POST">
  160. <input type="hidden" name="source" value="sync" />
  161. <input type="hidden" name="action" value="resetfeedkey" />
  162. <button type="submit" class="btn btn-danger"><i class="fas fa-sync"></i> <?php $Strings->get('Reset'); ?></button>
  163. </form>
  164. </div>
  165. </div>
  166. </div>
  167. </div>