index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <?php
  2. require_once(dirname(dirname(__FILE__)).'/header.php');
  3. header('X-UA-Compatible: IE=Edge');
  4. global $user;
  5. if($user = is_logged_in()){
  6. if(has_flag($user,'a')){
  7. $servers = get_servers_obj();
  8. $opers = get_opers_obj();
  9. }else{
  10. $servers = get_servers_for_current_user_obj();
  11. $opers = get_opers_for_current_user_obj();
  12. }
  13. }
  14. $dialogs = array();
  15. ?>
  16. <html>
  17. <head>
  18. <meta charset="UTF-8">
  19. <title>Omninet</title>
  20. <script>
  21. __HOSTNAME__ = '<?php echo HOSTNAME; ?>';
  22. </script>
  23. <link href="<?php echo HOSTNAME; ?>site/favicon.ico" rel="icon" type="image/x-icon" />
  24. <script src="<?php echo HOSTNAME; ?>site/Modernizr.js"></script>
  25. <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
  26. <script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
  27. <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.min.js"></script>
  28. <script src="//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/js/selectize.min.js"></script>
  29. <script src="<?php echo HOSTNAME; ?>site/jquery.treegrid.js"></script>
  30. <script src="//cdnjs.cloudflare.com/ajax/libs/history.js/1.8/bundled/html5/jquery.history.min.js"></script>
  31. <script src="<?php echo HOSTNAME; ?>site/jquery.timepicker.js"></script>
  32. <script src="<?php echo HOSTNAME; ?>site/jquery.ba-resize.min.js"></script>
  33. <?php if(get_conf('2-factor-method') == 'authy'){ ?>
  34. <script src="//cdnjs.cloudflare.com/ajax/libs/authy-forms.js/2.0/form.authy.min.js"></script>
  35. <?php } ?>
  36. <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-url-parser/2.3.1/purl.min.js"></script>
  37. <script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.min.js"></script>
  38. <?php if(get_conf('persona-endpoint') != 'none'){ ?>
  39. <script src="//login.persona.org/include.js"></script>
  40. <?php } ?>
  41. <script src="<?php echo HOSTNAME; ?>site/index.js"></script>
  42. <link href="//code.jquery.com/ui/1.10.4/themes/dot-luv/jquery-ui.css" rel="stylesheet"/>
  43. <link href="//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.css" rel="stylesheet"/>
  44. <link href="//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.default.css" rel="stylesheet"/>
  45. <link href="<?php echo HOSTNAME; ?>site/jquery.treegrid.css" rel="stylesheet"/>
  46. <link href="<?php echo HOSTNAME; ?>site/jquery.timepicker.css" rel="stylesheet"/>
  47. <?php if(get_conf('2-factor-method') == 'authy'){ ?>
  48. <link href="//cdnjs.cloudflare.com/ajax/libs/authy-forms.css/2.0/form.authy.min.css" rel="stylesheet"/>
  49. <?php } ?>
  50. <link href="<?php echo HOSTNAME; ?>site/index.css" rel="stylesheet"/>
  51. <?php
  52. if($user){
  53. echo "<script>$(function(){";
  54. if(is_logged_in() && is_verified()){
  55. echo "window.ServerPing();";
  56. }
  57. if(has_flag($user,'u')){
  58. echo "window.FetchMemos();";
  59. echo "window.FetchNews();";
  60. echo "window.FetchChannels();";
  61. }
  62. echo "});</script>";
  63. if(has_flag($user,'u')){ ?>
  64. <script id="template-memos" type="text/x-handlebars-template">
  65. <button class="button" value="Refresh" onclick="window.FetchMemos(true);">
  66. Refresh
  67. </button>
  68. <button style="background-color:green;background-image:none;" class="button" value="New Memo" id="send-memo" onclick="$('#memo-diag').dialog('open');">
  69. New Memo
  70. </button>
  71. <button class="button" style="background-color:red;background-image:none;" value="Delete All" onclick="return window.DeleteMemos();">
  72. Delete All
  73. </button>
  74. {{#each memos}}
  75. <div style="padding: 5px;" class="ui-widget ui-state-default ui-corner-all" id="memo-{{this.id}}">
  76. <div>
  77. <span>
  78. From:
  79. </span>
  80. <span style="font-weight:normal;" class='memo-from'>
  81. {{this.from}}
  82. </span>
  83. </div>
  84. <div>
  85. <span>
  86. Sent:
  87. </span>
  88. <span style="font-weight:normal;" class='memo-date'>
  89. {{this.date}}
  90. </span>
  91. </div>
  92. <div>
  93. <span>
  94. Body:
  95. </span>
  96. <span style="font-weight:normal;" class="memo-body">
  97. {{html this.body}}
  98. </span>
  99. </div>
  100. <button class="button" value="Reply" onclick="return window.ReplyToMemoFromButton.call(this);">
  101. Reply
  102. </button>
  103. <button style="background-color:red;background-image:none;" class="button" value="Delete" onclick="return window.DeleteMemoFromButton.call(this);">
  104. Delete
  105. </button>
  106. </div>
  107. {{/each}}
  108. </script>
  109. <script id="template-news" type="text/x-handlebars-template">
  110. <button value="Refresh" onclick="window.FetchNews(true);">
  111. Refresh
  112. </button>
  113. {{#each news}}
  114. <div id="news-{{this.id}}" class="ui-widget ui-state-default ui-corner-all" style="padding:5px;">
  115. <h2>
  116. {{this.title}}
  117. </h2>
  118. <div>
  119. <span>
  120. From:
  121. </span>
  122. <span style="font-weight:normal;">
  123. {{this.from}}
  124. </span>
  125. </div>
  126. <div>
  127. <span>
  128. Sent:
  129. </span>
  130. <span style="font-weight:normal;">
  131. {{this.date}}
  132. </span>
  133. </div>
  134. <p style="font-weight:normal;">
  135. {{html this.body}}
  136. </p>
  137. </div>
  138. {{/each}}
  139. </script>
  140. <script id="template-channels" type="text/x-handlebars-template">
  141. <button value="Refresh" onclick="window.FetchChannels(true);">
  142. Refresh
  143. </button>
  144. <button value="New Channel" style="background-color:green;background-image:none;" onclick="">
  145. New Channel
  146. </button>
  147. {{#each channels}}
  148. <div id="channel-{{this.name}}" class="ui-widget ui-state-default ui-corner-all" style="padding:5px;">
  149. {{this.name}}
  150. <br/>
  151. Flags:
  152. <ul>
  153. {{#each this.flags}}
  154. <li>{{this.name}}</li>
  155. {{/each}}
  156. </ul>
  157. <button value="Delete" style="background-color:red;background-image:none;" onclick="">
  158. Delete
  159. </button>
  160. </div>
  161. {{/each}}
  162. </script>
  163. <?php }
  164. }
  165. ?>
  166. </head>
  167. <body style="display:none;">
  168. <?php
  169. $flag = is_verified();
  170. if($user && $flag){
  171. ?>
  172. <div class="tabs">
  173. <ul>
  174. <?php
  175. if(has_flag($user,'u')){ ?>
  176. <li><a href="#news">News</a></li>
  177. <li><a href="#memos">Memos</a></li>
  178. <li><a href="#channels">Channels</a></li>
  179. <?php }
  180. echo has_flag($user,'n')?'<li><a href="#servers">Servers</a></li>':'';
  181. echo has_flag($user,'o')?'<li><a href="#opers">Opers</a></li>':'';
  182. echo has_flag($user,'a')?'<li><a href="#config">Configuration</a></li>':'';
  183. ?>
  184. <li><a href="#profile">Profile</a></li>
  185. <div id="user-menu-button" class="right button">
  186. <?php echo $user['nick']; ?>
  187. </div>
  188. </ul>
  189. <?php if(has_flag($user,'n')){?>
  190. <div id="servers">
  191. <?php
  192. echo get_servers_list_html($servers);
  193. ?>
  194. </div>
  195. <?php }
  196. if(has_flag($user,'o')){?>
  197. <div id="opers">
  198. <?php echo get_opers_html($opers); ?>
  199. </div>
  200. <?php }
  201. if(has_flag($user,'a')){ ?>
  202. <div id="config">
  203. <?php echo render_configuration_table(); ?>
  204. </div>
  205. <?php }
  206. if(has_flag($user,'u')){ ?>
  207. <div id="news"></div>
  208. <div id="memos"></div>
  209. <div id="channels"></div>
  210. <?php
  211. array_push($dialogs,array(
  212. 'id'=>'memo-diag',
  213. 'type'=>'form',
  214. 'form_id'=>'memo',
  215. 'form_submit_label'=>'Send',
  216. 'form_fields'=>array(
  217. array(
  218. 'name'=>'to',
  219. 'label'=>'To',
  220. 'type'=>'string',
  221. 'value'=>''
  222. ),
  223. array(
  224. 'name'=>'message',
  225. 'label'=>'Message',
  226. 'type'=>'string',
  227. 'value'=>''
  228. ),
  229. array(
  230. 'name'=>'action',
  231. 'type'=>'hidden',
  232. 'value'=>'send-memo'
  233. )
  234. )
  235. ));
  236. } ?>
  237. <div id="profile">
  238. <?php
  239. echo get_user_html($user);
  240. if(has_flag($user,'a') || has_flag($user,'o') || has_flag($user,'n')){
  241. if(!isset($user['secret_key']) || is_null($user['secret_key']) || $user['secret_key'] == ''){
  242. switch(get_conf('2-factor-method')){
  243. case 'authy':
  244. echo '<div class="login-form">Enable 2-factor Authentication'.get_form_html('2-factor',array(
  245. array(
  246. 'name'=>'country-code',
  247. 'label'=>'Country',
  248. 'type'=>'text',
  249. 'attributes'=>array(
  250. 'id'=>'authy-countries'
  251. )
  252. ),
  253. array(
  254. 'name'=>'cellphone',
  255. 'label'=>'Cell #',
  256. 'type'=>'text',
  257. 'attributes'=>array(
  258. 'id'=>'authy-cellphone'
  259. )
  260. ),
  261. array(
  262. 'name'=>'action',
  263. 'type'=>'hidden',
  264. 'value'=>'2-factor-register'
  265. )
  266. ),'Submit').'</div>';
  267. break;
  268. case 'google-authenticator':
  269. $api = get_api();
  270. $_SESSION['secret_key'] = $api->createSecret();
  271. echo '<div class="login-form">Enable 2-factor Authentication'.get_form_html('2-factor',array(
  272. array(
  273. 'type'=>'custom',
  274. 'html'=>"<img src='data:image/png;base64,".base64_encode(file_get_contents($api->getQRCodeGoogleUrl('Omninet',$_SESSION['secret_key'])))."'/>"
  275. ),
  276. array(
  277. 'name'=>'token',
  278. 'label'=>'Token',
  279. 'type'=>'text'
  280. ),
  281. array(
  282. 'name'=>'action',
  283. 'type'=>'hidden',
  284. 'value'=>'2-factor-register'
  285. )
  286. ),'Submit').'</div>';
  287. break;
  288. default:
  289. }
  290. }else{
  291. switch(get_conf('2-factor-method')){
  292. case 'authy':case 'google-authenticator':
  293. echo "<button id='2-factor-disable' value='Disable 2-factor'>Disable 2-factor</button>";
  294. break;
  295. default:
  296. }
  297. }
  298. if(get_conf('persona-endpoint') != 'none'){
  299. echo "<div><span id='persona-register' class='ui-button ui-widget ui-state-default ui-corner-all' style='overflow:hidden;height:42px;padding:0px 20px 0px 0px;vertical-align:middle;'><img style='height:100%;float:left;' src='img/persona-logo.png'/><span style='display:inline-block;line-height:42px;'>Link Persona</span></span></div>";
  300. $emails = get_emails($user['id'],true);
  301. foreach($emails as $k => $email){
  302. echo "<div><button id='persona-remove-{$email['id']}' value='Remove'>Remove</button>{$email['email']}</div>";
  303. }
  304. }
  305. }
  306. ?>
  307. </div>
  308. </div>
  309. <ul class="menu" id="user-menu">
  310. <li><a id="roles-button">Switch Role</a></li>
  311. <?php if(has_flag($user,'n')||has_flag($user,'a')){?>
  312. <li><a id="rehash-servers">Rehash</a></li>
  313. <?php } ?>
  314. <li><a id="newpass-button">Change Password</a></li>
  315. <?php if(has_flag($user,'u')){ ?>
  316. <li><a id="sync-pass">Sync Pass</a></li>
  317. <?php } ?>
  318. <li><a id="logout">Logout</a></li>
  319. </ul>
  320. <?php
  321. array_push($dialogs,array(
  322. 'id'=>'newpass-diag',
  323. 'type'=>'form',
  324. 'form_id'=>'newpass',
  325. 'form_submit_label'=>'Change Password',
  326. 'form_fields'=>array(
  327. array(
  328. 'name'=>'password',
  329. 'label'=>'Password',
  330. 'type'=>'password',
  331. 'value'=>''
  332. ),
  333. array(
  334. 'name'=>'newpass',
  335. 'label'=>'New Password',
  336. 'type'=>'password',
  337. 'value'=>''
  338. ),
  339. array(
  340. 'name'=>'action',
  341. 'type'=>'hidden',
  342. 'value'=>'newpass'
  343. )
  344. )
  345. ));
  346. $roles = array(array(
  347. 'value'=>'user',
  348. 'label'=>'User'
  349. ));
  350. if($res = query("SELECT rt.name AS value,rt.description AS label FROM user_role_types rt JOIN user_roles r ON r.user_role_id = rt.id JOIN users u ON r.user_id = u.id WHERE u.id = %d",array($user['id']))){
  351. while($role = $res->fetch_assoc()){
  352. array_push($roles,$role);
  353. }
  354. }
  355. array_push($dialogs,array(
  356. 'id'=>'roles-diag',
  357. 'type'=>'form',
  358. 'form_id'=>'roles',
  359. 'form_submit_label'=>'Switch',
  360. 'form_fields'=>array(
  361. array(
  362. 'name'=>'type',
  363. 'label'=>'Type',
  364. 'type'=>'select',
  365. 'values'=>$roles,
  366. 'value'=>isset($_COOKIE['type'])?$_COOKIE['type']:'user'
  367. ),
  368. array(
  369. 'name'=>'action',
  370. 'type'=>'hidden',
  371. 'value'=>'role'
  372. )
  373. )
  374. ));
  375. }elseif($user && !$flag){
  376. array_push($dialogs,array(
  377. 'id'=>'verify-diag',
  378. 'type'=>'form',
  379. 'autocomplete'=>'off',
  380. 'form_id'=>'verify',
  381. 'form_submit_label'=>'Login',
  382. 'form_fields'=>array(
  383. array(
  384. 'name'=>'token',
  385. 'label'=>'2-Factor Verification',
  386. 'type'=>'text',
  387. 'attributes'=>array(
  388. 'id'=>'authy-token',
  389. 'style'=>'background-color:#F2DEDE;'
  390. )
  391. ),
  392. array(
  393. 'name'=>'action',
  394. 'type'=>'hidden',
  395. 'value'=>'verify'
  396. )
  397. )
  398. ));
  399. }else{
  400. $roles = array(array(
  401. 'value'=>'user',
  402. 'label'=>'User'
  403. ));
  404. if($res = query("SELECT name AS value,description AS label FROM ircd.user_role_types")){
  405. while($role = $res->fetch_assoc()){
  406. array_push($roles,$role);
  407. }
  408. }
  409. array_push($dialogs,array(
  410. 'id'=>'login-diag',
  411. 'type'=>'form',
  412. 'form_id'=>'login',
  413. 'form_submit_label'=>'Login',
  414. 'form_fields'=>array(
  415. array(
  416. 'type'=>'custom',
  417. 'html'=>get_conf('persona-endpoint') != 'none'?"<div><span id='persona-register' class='ui-button ui-widget ui-state-default ui-corner-all' style='overflow:hidden;height:42px;padding:0px 20px 0px 0px;vertical-align:middle;'><img style='height:100%;float:left;' src='img/persona-logo.png'/><span style='display:inline-block;line-height:42px;'>Persona</span></span></div>":''
  418. ),
  419. array(
  420. 'name'=>'username',
  421. 'label'=>'Username',
  422. 'type'=>'text',
  423. 'value'=>''
  424. ),
  425. array(
  426. 'name'=>'password',
  427. 'label'=>'Password',
  428. 'type'=>'password',
  429. 'value'=>''
  430. ),
  431. array(
  432. 'name'=>'type',
  433. 'label'=>'Type',
  434. 'type'=>'select',
  435. 'values'=>$roles
  436. ),
  437. array(
  438. 'name'=>'action',
  439. 'type'=>'hidden',
  440. 'value'=>'login'
  441. )
  442. )
  443. ));
  444. }
  445. ?>
  446. <div id="dialogs">
  447. <?php
  448. foreach($dialogs as $k => $diag){
  449. echo "<div id='{$diag['id']}'>";
  450. switch($diag['type']){
  451. case 'form':
  452. array_push($diag['form_fields'],array(
  453. 'type'=>'submit',
  454. 'value'=>$diag['form_submit_label']
  455. ));
  456. $attributes = array(
  457. 'id'=>$diag['form_id']
  458. );
  459. if(isset($diag['autocomplete'])){
  460. $attributes['autocomplete'] = $diag['autocomplete'];
  461. }
  462. echo get_form_html_advanced($attributes,$diag['form_fields']);
  463. break;
  464. }
  465. echo "</div>";
  466. }
  467. ?>
  468. </div>
  469. </body>
  470. </html>