PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/api/v1/index.php

https://gitlab.com/mycryptochatex/mycryptochatex
PHP | 241 lines | 190 code | 42 blank | 9 comment | 7 complexity | 7fbdfccccd02aeac4a5f9ef1a11c6fcf MD5 | raw file
  1. <?php
  2. $inc_dir = '../../inc/';
  3. require $inc_dir . 'constants.php';
  4. require $inc_dir . 'classes.php';
  5. require $inc_dir . 'functions.php';
  6. require $inc_dir . 'dbmanager.php';
  7. require 'conf.php';
  8. require 'classes.php';
  9. require 'functions.php';
  10. ?>
  11. <?php
  12. $ret = array(); //response
  13. try {
  14. // ---------------------------------------------------------------------------
  15. // #0 - header
  16. $ret['header'] = "MyCryptoChatEx by salikovi.cz";
  17. // #1 - settings tests
  18. $sqliAvailable = true;
  19. $showContent = true;
  20. $configIncluded = false;
  21. check_server($ret,
  22. $sqliAvailable,
  23. $showContent,
  24. $configIncluded
  25. );
  26. if (!$showContent) {
  27. throw new Exception(); //break try
  28. }
  29. // #2 - add usage stats
  30. add_usage_stats($ret);
  31. // #3 - decode parameters
  32. $par = array();
  33. $par[] = parse_get_params();
  34. $par[] = parse_post_params();
  35. // #4 - do job
  36. $group = nvl($par, 'group', 'room');
  37. if ($group == 'room') {
  38. $action = nvl($par, 'action', 'list');
  39. switch ($action) {
  40. case 'list':
  41. get_room_list($ret);
  42. break;
  43. case 'create':
  44. $name = nvl($par, 'name', 'Untitled room');
  45. $hidden = nvl($par, 'hidden', 0);
  46. $self_destroy = nvl($par, 'self_destroy', 0); //if more than me and 1 visitor in the room
  47. $minutes_to_live = nvl($par, 'minutes_to_live', 0);
  48. $is_removable = nvl($par, 'removable', 0);
  49. $remove_password = nvl($par, 'remove_pass', null);
  50. break;
  51. case 'read':
  52. $room_id = nvl($par, 'room_id', -1);
  53. $last_msg_check = nvl($par, 'last_msg_check', 0);
  54. $user_count = nvl($par, 'usr_cnt', 0);
  55. break;
  56. case 'write':
  57. $room_id = nvl($par, 'room_id', -1);
  58. $user_name = nvl($par, 'user_name', null);
  59. $msg = nvl($par, 'msg', null);
  60. break;
  61. case 'delete':
  62. $room_id = nvl($par, 'room_id', -1);
  63. $remove_password = nvl($par, 'remove_pass', null);
  64. break;
  65. default:
  66. get_room_list($ret);
  67. } //end-switch
  68. } //end-group-room
  69. // ---------------------------------------------------------------------------
  70. } catch (Exception $e) {
  71. logException($e);
  72. add_error($ret, "Error: unexpected",
  73. "Unexpected error during server settings checking. " . $e->getMessage()
  74. );
  75. };
  76. echo json_encode($ret);
  77. exit();
  78. ?>
  79. <!DOCTYPE html>
  80. <html lang="en">
  81. <head>
  82. <meta charset="utf-8" />
  83. <title>Home - MyCryptoChatEx by salikovi.cz</title>
  84. <link rel="icon" href="/favicon.ico" type="image/x-icon" />
  85. <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
  86. <meta name="viewport" content="width=device-width" />
  87. <link href="styles/myCryptoChat.css" rel="stylesheet" />
  88. <script src="scripts/modernizr.min.js"></script>
  89. <link href="styles/jquery.dataTables.css" rel="stylesheet" />
  90. </head>
  91. <body>
  92. <?php
  93. if($showContent) {
  94. ?>
  95. <noscript>
  96. This website needs JavaScript activated to work.
  97. <style>
  98. div {
  99. display: none;
  100. }
  101. </style>
  102. </noscript>
  103. <header>
  104. <div class="content-wrapper">
  105. <div class="float-left">
  106. <p class="site-title"><a href="index.php">MyCryptoChatEx</a></p>
  107. </div>
  108. <div class="float-right">
  109. <section id="login">
  110. </section>
  111. <nav>
  112. <ul id="menu">
  113. <li><a href="index.php">Home</a></li>
  114. <li><a href="stats.php">Stats</a></li>
  115. <li><a href="about.php">About</a></li>
  116. </ul>
  117. </nav>
  118. </div>
  119. </div>
  120. </header>
  121. <div id="body">
  122. <section class="content-wrapper main-content clear-fix">
  123. <h2>MyCryptoChatEx</h2>
  124. <div class="mb50">Chat with friends without anyone spying on what you say!</div>
  125. <div class="chatRoomList mb50">
  126. <table id="chatRoomTable" class="hover compact" cellspacing="0" width="100%">
  127. <thead>
  128. <tr>
  129. <th>Chat room name</th>
  130. <th>Users count</th>
  131. <th>Created</th>
  132. <th>Expiration</th>
  133. <th>Last message</th>
  134. <th>Link</th>
  135. </tr>
  136. </thead>
  137. <tfoot>
  138. <tr>
  139. <th>Chat room name</th>
  140. <th>Users count</th>
  141. <th>Created</th>
  142. <th>Expiration</th>
  143. <th>Last message</th>
  144. <th>Link</th>
  145. </tr>
  146. </tfoot>
  147. </table>
  148. </div>
  149. <form method="POST" action="newroom.php">
  150. <label for="roomName">Name of the chat room:</label>
  151. <input type="text" name="roomName" value="<?php echo $dbManager->GetNextRoomName(); ?>" />
  152. <br />
  153. <label for="nbMinutesToLive">Lifetime of the chat room:</label>
  154. <select id="nbMinutesToLive" name="nbMinutesToLive">
  155. <?php foreach ($allowedTimes as $minutes => $label) { ?>
  156. <option value="<?php echo $minutes; ?>"><?php echo $label; ?></option>
  157. <?php } ?>
  158. </select><br />
  159. <br />
  160. <input type="checkbox" name="isRemovable" id="isRemovable" value="true" onchange="if(this.checked) { $('#divRemovePassword').show(); } else { $('#divRemovePassword').hide(); }" />
  161. <label for="isRemovable" class="labelIndex">Is removable</label>
  162. <br />
  163. <div id="divRemovePassword">
  164. <br />
  165. <label for="removePassword">Password to remove:</label>
  166. <input type="password" name="removePassword" value="" />
  167. </div>
  168. <br />
  169. <input type="checkbox" name="selfDestroys" id="selfDestroys" value="true" />
  170. <label for="selfDestroys" class="labelIndex">Self-destroys if more than one visitor</label>
  171. <br />
  172. <br />
  173. <input type="checkbox" name="hiddenRoom" id="hiddenChatRoom" value="true" />
  174. <label for="hiddenChatRoom" class="labelIndex">Chat room will not be visible in rooms list</label>
  175. <br />
  176. <br />
  177. <input type="submit" value="Create a new chat room" />
  178. </form>
  179. </section>
  180. </div>
  181. <footer>
  182. <div class="content-wrapper">
  183. <div class="float-left">
  184. <p>&copy; 2016 - MyCryptoChatEx <?php echo MYCRYPTOCHAT_VERSION; ?> by salikovi.cz</p>
  185. </div>
  186. </div>
  187. </footer>
  188. <script src="scripts/jquery.min.js"></script>
  189. <script src="scripts/jquery.dataTables.min.js"></script>
  190. <script type="text/javascript">
  191. $('#chatRoomTable').DataTable( {
  192. //"processing": true,
  193. //"serverSide": true,
  194. "ajax": "roomslist.php"
  195. } );
  196. </script>
  197. <?php } //if-showcontent ?>
  198. </body>
  199. </html>