index.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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/js/pomo.min.js"></script>
  25. <script src="<?php echo HOSTNAME; ?>site/js/Modernizr.js"></script>
  26. <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
  27. <script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
  28. <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.min.js"></script>
  29. <script src="//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/js/selectize.min.js"></script>
  30. <script src="<?php echo HOSTNAME; ?>site/js/jquery.treegrid.js"></script>
  31. <script src="//cdnjs.cloudflare.com/ajax/libs/history.js/1.8/bundled/html5/jquery.history.min.js"></script>
  32. <script src="<?php echo HOSTNAME; ?>site/js/jquery.timepicker.js"></script>
  33. <script src="<?php echo HOSTNAME; ?>site/js/jquery.ba-resize.min.js"></script>
  34. <?php if(get_conf('2-factor-method') == 'authy'){ ?>
  35. <script src="//cdnjs.cloudflare.com/ajax/libs/authy-forms.js/2.0/form.authy.min.js"></script>
  36. <?php } ?>
  37. <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-url-parser/2.3.1/purl.min.js"></script>
  38. <script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.min.js"></script>
  39. <?php if(get_conf('persona-endpoint') != 'none'){ ?>
  40. <script src="//login.persona.org/include.js"></script>
  41. <?php } ?>
  42. <script src="<?php echo HOSTNAME; ?>site/js/index.js"></script>
  43. <link href="//code.jquery.com/ui/1.10.4/themes/dot-luv/jquery-ui.css" rel="stylesheet"/>
  44. <link href="//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.css" rel="stylesheet"/>
  45. <link href="//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.8.5/css/selectize.default.css" rel="stylesheet"/>
  46. <link href="<?php echo HOSTNAME; ?>site/jquery.treegrid.css" rel="stylesheet"/>
  47. <link href="<?php echo HOSTNAME; ?>site/jquery.timepicker.css" rel="stylesheet"/>
  48. <?php if(get_conf('2-factor-method') == 'authy'){ ?>
  49. <link href="//cdnjs.cloudflare.com/ajax/libs/authy-forms.css/2.0/form.authy.min.css" rel="stylesheet"/>
  50. <?php } ?>
  51. <link href="<?php echo HOSTNAME; ?>site/index.css" rel="stylesheet"/>
  52. <script>
  53. function runWhenExists(name){
  54. var run = function(){
  55. if(typeof window[name] != 'function'){
  56. setTimeout(run,10);
  57. }else{
  58. window[name]();
  59. }
  60. };
  61. run();
  62. }
  63. </script>
  64. <?php
  65. if($user){
  66. echo "<script>function delayedload(){";
  67. if(is_logged_in() && is_verified()){
  68. echo "runWhenExists('ServerPing');";
  69. }
  70. if(has_flag($user,'u')){
  71. echo "runWhenExists('FetchMemos');";
  72. echo "runWhenExists('FetchNews');";
  73. echo "runWhenExists('FetchChannels');";
  74. }
  75. echo "};</script>";
  76. if(has_flag($user,'u')){ ?>
  77. <script id="template-memos" type="text/x-handlebars-template">
  78. <button class="button" value="<?php echo __('Refresh'); ?>" onclick="window.FetchMemos(true);">
  79. <?php echo __('Refresh'); ?>
  80. </button>
  81. <button style="background-color:green;background-image:none;" class="button" value="<?php echo __('New Memo'); ?>" id="send-memo" onclick="$('#memo-diag').dialog('open');">
  82. <?php echo __('New Memo'); ?>
  83. </button>
  84. <button class="button" style="background-color:red;background-image:none;" value="<?php echo __('Delete All'); ?>" onclick="return window.DeleteMemos();">
  85. <?php echo __('Delete All'); ?>
  86. </button>
  87. {{#each memos}}
  88. <div style="padding: 5px;" class="ui-widget ui-state-default ui-corner-all" id="memo-{{this.id}}">
  89. <div>
  90. <span>
  91. <?php echo __('From'); ?>:
  92. </span>
  93. <span style="font-weight:normal;" class='memo-from'>
  94. {{this.from}}
  95. </span>
  96. </div>
  97. <div>
  98. <span>
  99. <?php echo __('Sent'); ?>:
  100. </span>
  101. <span style="font-weight:normal;" class='memo-date'>
  102. {{this.date}}
  103. </span>
  104. </div>
  105. <div>
  106. <span>
  107. <?php echo __('Body'); ?>:
  108. </span>
  109. <span style="font-weight:normal;" class="memo-body">
  110. {{html this.body}}
  111. </span>
  112. </div>
  113. <button class="button" value="<?php echo __('Reply'); ?>" onclick="return window.ReplyToMemo('{{this.from}}');">
  114. <?php echo __('Reply'); ?>
  115. </button>
  116. <button style="background-color:red;background-image:none;" class="button" value="<?php echo __('Delete'); ?>" onclick="return window.DeleteMemo({{this.id}});">
  117. <?php echo __('Delete'); ?>
  118. </button>
  119. </div>
  120. {{/each}}
  121. </script>
  122. <script id="template-news" type="text/x-handlebars-template">
  123. <button value="<?php echo __('Refresh'); ?>" onclick="window.FetchNews(true);">
  124. <?php echo __('Refresh'); ?>
  125. </button>
  126. {{#each news}}
  127. <div id="news-{{this.id}}" class="ui-widget ui-state-default ui-corner-all" style="padding:5px;">
  128. <h2>
  129. {{this.title}}
  130. </h2>
  131. <div>
  132. <span>
  133. <?php echo __('From'); ?>:
  134. </span>
  135. <span style="font-weight:normal;">
  136. {{this.from}}
  137. </span>
  138. </div>
  139. <div>
  140. <span>
  141. <?php echo __('Sent'); ?>:
  142. </span>
  143. <span style="font-weight:normal;">
  144. {{this.date}}
  145. </span>
  146. </div>
  147. <p style="font-weight:normal;">
  148. {{html this.body}}
  149. </p>
  150. </div>
  151. {{/each}}
  152. </script>
  153. <script id="template-channels" type="text/x-handlebars-template">
  154. <button value="<?php echo __('Refresh'); ?>" onclick="window.FetchChannels(true);">
  155. <?php echo __('Refresh'); ?>
  156. </button>
  157. <button value="<?php echo __('New Channel'); ?>" style="background-color:green;background-image:none;" onclick="$('#channel-diag').dialog('open');">
  158. <?php echo __('New Channel'); ?>
  159. </button>
  160. {{#each channels}}
  161. <div id="channel-{{this.name}}" class="ui-widget ui-state-default ui-corner-all" style="padding:5px;">
  162. {{this.name}}
  163. <table class="tree">
  164. <tr style='font-weight:bold;' class='treegrid-0'>
  165. <td>
  166. <?php echo __('Access'); ?>
  167. </td>
  168. <td></td>
  169. <td></td>
  170. </tr>
  171. {{#each this.users}}
  172. <tr style='font-weight:bold;' class='treegrid-{{this.id}} treegrid-parent-0'>
  173. <td>
  174. {{this.name}}
  175. </td>
  176. <td>
  177. <?php echo __('Flags'); ?>
  178. </td>
  179. <td>
  180. {{#if ../canaccess}}
  181. <a onclick="window.ModifyChannelAccess('{{../../name}}','{{this.name}}',{{this.id}});" style="cursor:pointer;">
  182. <?php echo __('Modify'); ?>
  183. </a>
  184. {{/if}}
  185. </td>
  186. </tr>
  187. {{#each this.flags}}
  188. <tr class='treegrid-{{this.flag}} treegrid-parent-{{../id}}'>
  189. <td></td>
  190. <td>
  191. {{this.name}}
  192. </td>
  193. <td></td>
  194. </tr>
  195. {{/each}}
  196. {{/each}}
  197. </table>
  198. </ul>
  199. {{#if this.canaccess}}
  200. <button value="<?php echo __('Add Access'); ?>" onclick="window.ModifyChannelAccess('{{this.name}}');">
  201. <?php echo __('Add Access'); ?>
  202. </button>
  203. {{/if}}
  204. {{#if this.candrop}}
  205. <button value="<?php echo __('Delete'); ?>" style="background-color:red;background-image:none;" onclick="window.DeleteChannel('{{this.name}}');">
  206. <?php echo __('Delete'); ?>
  207. </button>
  208. {{/if}}
  209. </div>
  210. {{/each}}
  211. </script>
  212. <?php }
  213. }
  214. ?>
  215. </head>
  216. <body style="display:none;">
  217. <?php
  218. $flag = is_verified();
  219. if($user && $flag){
  220. ?>
  221. <div class="tabs">
  222. <ul>
  223. <?php
  224. if(has_flag($user,'u')){ ?>
  225. <li><a href="#news"><?php echo __('News'); ?></a></li>
  226. <li><a href="#memos"><?php echo __('Memos'); ?></a></li>
  227. <li><a href="#channels"><?php echo __('Channels'); ?></a></li>
  228. <?php }
  229. echo has_flag($user,'n')?'<li><a href="#servers">'.__('Servers').'</a></li>':'';
  230. echo has_flag($user,'o')?'<li><a href="#opers">'.__('Opers').'</a></li>':'';
  231. echo has_flag($user,'a')?'<li><a href="#config">'.__('Configuration').'</a></li>':'';
  232. ?>
  233. <li><a href="#profile"><?php echo __('Profile'); ?></a></li>
  234. <div id="user-menu-button" class="right button">
  235. <?php echo $user['nick']; ?>
  236. </div>
  237. </ul>
  238. <?php if(has_flag($user,'n')){?>
  239. <div id="servers">
  240. <?php
  241. echo get_servers_list_html($servers);
  242. ?>
  243. </div>
  244. <?php }
  245. if(has_flag($user,'o')){?>
  246. <div id="opers">
  247. <?php echo get_opers_html($opers); ?>
  248. </div>
  249. <?php }
  250. if(has_flag($user,'a')){ ?>
  251. <div id="config">
  252. <?php echo render_configuration_table(); ?>
  253. </div>
  254. <?php }
  255. if(has_flag($user,'u')){ ?>
  256. <div id="news"></div>
  257. <div id="memos"></div>
  258. <div id="channels"></div>
  259. <?php
  260. array_push($dialogs,array(
  261. 'id'=>'memo-diag',
  262. 'type'=>'form',
  263. 'form_id'=>'memo',
  264. 'form_submit_label'=>__('Send'),
  265. 'form_fields'=>array(
  266. array(
  267. 'name'=>'to',
  268. 'label'=>__('To'),
  269. 'type'=>'string',
  270. 'value'=>''
  271. ),
  272. array(
  273. 'name'=>'message',
  274. 'label'=>__('Message'),
  275. 'type'=>'string',
  276. 'value'=>''
  277. ),
  278. array(
  279. 'name'=>'action',
  280. 'type'=>'hidden',
  281. 'value'=>'send-memo'
  282. )
  283. )
  284. ));
  285. array_push($dialogs,array(
  286. 'id'=>'channel-diag',
  287. 'type'=>'form',
  288. 'form_id'=>'channel',
  289. 'form_submit_label'=>__('Register'),
  290. 'form_fields'=>array(
  291. array(
  292. 'name'=>'channel',
  293. 'label'=>__('Channel Name'),
  294. 'type'=>'string',
  295. 'value'=>''
  296. ),
  297. array(
  298. 'name'=>'action',
  299. 'type'=>'hidden',
  300. 'value'=>'register-channel'
  301. )
  302. )
  303. ));
  304. array_push($dialogs,array(
  305. 'id'=>'channel-flags-diag',
  306. 'type'=>'form',
  307. 'form_id'=>'channel-flags',
  308. 'form_submit_label'=>__('Modify'),
  309. 'form_fields'=>array(
  310. array(
  311. 'name'=>'user',
  312. 'label'=>__('User'),
  313. 'type'=>'string',
  314. 'value'=>''
  315. ),
  316. array(
  317. 'name'=>'flags',
  318. 'label'=>__('Flags'),
  319. 'type'=>'multi',
  320. 'values'=>array(
  321. channel_flag_obj('A'),
  322. channel_flag_obj('F'),
  323. channel_flag_obj('O'),
  324. channel_flag_obj('R'),
  325. channel_flag_obj('V'),
  326. channel_flag_obj('a'),
  327. channel_flag_obj('f'),
  328. channel_flag_obj('h'),
  329. channel_flag_obj('i'),
  330. channel_flag_obj('o'),
  331. channel_flag_obj('q'),
  332. channel_flag_obj('r'),
  333. channel_flag_obj('s'),
  334. channel_flag_obj('t'),
  335. channel_flag_obj('v'),
  336. channel_flag_obj('b')
  337. )
  338. ),
  339. array(
  340. 'name'=>'channel',
  341. 'type'=>'hidden',
  342. 'value'=>''
  343. ),
  344. array(
  345. 'name'=>'action',
  346. 'type'=>'hidden',
  347. 'value'=>'channel-flags'
  348. )
  349. )
  350. ));
  351. } ?>
  352. <div id="profile">
  353. <?php
  354. echo get_user_html($user);
  355. if(has_flag($user,'a') || has_flag($user,'o') || has_flag($user,'n')){
  356. if(!isset($user['secret_key']) || is_null($user['secret_key']) || $user['secret_key'] == ''){
  357. switch(get_conf('2-factor-method')){
  358. case 'authy':
  359. echo '<div class="login-form">Enable 2-factor Authentication'.get_form_html('2-factor',array(
  360. array(
  361. 'name'=>'country-code',
  362. 'label'=>__('Country'),
  363. 'type'=>'text',
  364. 'attributes'=>array(
  365. 'id'=>'authy-countries'
  366. )
  367. ),
  368. array(
  369. 'name'=>'cellphone',
  370. 'label'=>__('Cell #'),
  371. 'type'=>'text',
  372. 'attributes'=>array(
  373. 'id'=>'authy-cellphone'
  374. )
  375. ),
  376. array(
  377. 'name'=>'action',
  378. 'type'=>'hidden',
  379. 'value'=>'2-factor-register'
  380. )
  381. ),'Submit').'</div>';
  382. break;
  383. case 'google-authenticator':
  384. $api = get_api();
  385. $_SESSION['secret_key'] = $api->createSecret();
  386. echo '<div class="login-form">Enable 2-factor Authentication'.get_form_html('2-factor',array(
  387. array(
  388. 'type'=>'custom',
  389. 'html'=>"<img src='data:image/png;base64,".base64_encode(file_get_contents($api->getQRCodeGoogleUrl('Omninet',$_SESSION['secret_key'])))."'/>"
  390. ),
  391. array(
  392. 'name'=>'token',
  393. 'label'=>__('Token'),
  394. 'type'=>'text'
  395. ),
  396. array(
  397. 'name'=>'action',
  398. 'type'=>'hidden',
  399. 'value'=>'2-factor-register'
  400. )
  401. ),'Submit').'</div>';
  402. break;
  403. default:
  404. }
  405. }else{
  406. switch(get_conf('2-factor-method')){
  407. case 'authy':case 'google-authenticator':
  408. echo "<button id='2-factor-disable' value='".('Disable 2-factor')."'>".__('Disable 2-factor')."</button>";
  409. break;
  410. default:
  411. }
  412. }
  413. if(get_conf('persona-endpoint') != 'none'){
  414. 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>";
  415. $emails = get_emails($user['id'],true);
  416. foreach($emails as $k => $email){
  417. echo "<div><button id='persona-remove-{$email['id']}' value='".__('Remove')."'>".__('Remove')."</button>{$email['email']}</div>";
  418. }
  419. }
  420. }
  421. ?>
  422. </div>
  423. </div>
  424. <ul class="menu" id="user-menu">
  425. <li><a id="roles-button"><?php echo __('Switch Role'); ?></a></li>
  426. <?php if(has_flag($user,'n')||has_flag($user,'a')){?>
  427. <li><a id="rehash-servers"><?php echo __('Rehash'); ?></a></li>
  428. <?php } ?>
  429. <li><a id="newpass-button"><?php echo __('Change Password'); ?></a></li>
  430. <?php if(has_flag($user,'u')){ ?>
  431. <li><a id="sync-pass"><?php echo __('Sync Password'); ?></a></li>
  432. <?php } ?>
  433. <li><a id="logout"><?php echo __('Logout'); ?></a></li>
  434. </ul>
  435. <?php
  436. array_push($dialogs,array(
  437. 'id'=>'newpass-diag',
  438. 'type'=>'form',
  439. 'form_id'=>'newpass',
  440. 'form_submit_label'=>__('Change Password'),
  441. 'form_fields'=>array(
  442. array(
  443. 'name'=>'password',
  444. 'label'=>__('Password'),
  445. 'type'=>'password',
  446. 'value'=>''
  447. ),
  448. array(
  449. 'name'=>'newpass',
  450. 'label'=>__('New Password'),
  451. 'type'=>'password',
  452. 'value'=>''
  453. ),
  454. array(
  455. 'name'=>'action',
  456. 'type'=>'hidden',
  457. 'value'=>'newpass'
  458. )
  459. )
  460. ));
  461. $roles = array(array(
  462. 'value'=>'user',
  463. 'label'=>__('User')
  464. ));
  465. 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']))){
  466. while($role = $res->fetch_assoc()){
  467. array_push($roles,$role);
  468. }
  469. }
  470. array_push($dialogs,array(
  471. 'id'=>'roles-diag',
  472. 'type'=>'form',
  473. 'form_id'=>'roles',
  474. 'form_submit_label'=>__('Switch'),
  475. 'form_fields'=>array(
  476. array(
  477. 'name'=>'type',
  478. 'label'=>__('Type'),
  479. 'type'=>'select',
  480. 'values'=>$roles,
  481. 'value'=>isset($_COOKIE['type'])?$_COOKIE['type']:'user'
  482. ),
  483. array(
  484. 'name'=>'action',
  485. 'type'=>'hidden',
  486. 'value'=>'role'
  487. )
  488. )
  489. ));
  490. }elseif($user && !$flag){
  491. array_push($dialogs,array(
  492. 'id'=>'verify-diag',
  493. 'type'=>'form',
  494. 'autocomplete'=>'off',
  495. 'form_id'=>'verify',
  496. 'form_submit_label'=>__('Login'),
  497. 'form_fields'=>array(
  498. array(
  499. 'name'=>'token',
  500. 'label'=>__('2-Factor Verification'),
  501. 'type'=>'text',
  502. 'attributes'=>array(
  503. 'id'=>'authy-token',
  504. 'style'=>'background-color:#F2DEDE;'
  505. )
  506. ),
  507. array(
  508. 'name'=>'action',
  509. 'type'=>'hidden',
  510. 'value'=>'verify'
  511. )
  512. )
  513. ));
  514. }else{
  515. $roles = array(array(
  516. 'value'=>'user',
  517. 'label'=>__('User')
  518. ));
  519. if($res = query("SELECT name AS value,description AS label FROM ircd.user_role_types")){
  520. while($role = $res->fetch_assoc()){
  521. array_push($roles,$role);
  522. }
  523. }
  524. array_push($dialogs,array(
  525. 'id'=>'login-diag',
  526. 'type'=>'form',
  527. 'form_id'=>'login',
  528. 'form_submit_label'=>__('Login'),
  529. 'form_fields'=>array(
  530. array(
  531. 'type'=>'custom',
  532. '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>":''
  533. ),
  534. array(
  535. 'name'=>'username',
  536. 'label'=>__('Username'),
  537. 'type'=>'text',
  538. 'value'=>''
  539. ),
  540. array(
  541. 'name'=>'password',
  542. 'label'=>__('Password'),
  543. 'type'=>'password',
  544. 'value'=>''
  545. ),
  546. array(
  547. 'name'=>'type',
  548. 'label'=>__('Type'),
  549. 'type'=>'select',
  550. 'values'=>$roles
  551. ),
  552. array(
  553. 'name'=>'action',
  554. 'type'=>'hidden',
  555. 'value'=>'login'
  556. )
  557. )
  558. ));
  559. }
  560. ?>
  561. <div id="dialogs">
  562. <?php
  563. foreach($dialogs as $k => $diag){
  564. echo "<div id='{$diag['id']}'>";
  565. switch($diag['type']){
  566. case 'form':
  567. array_push($diag['form_fields'],array(
  568. 'type'=>'submit',
  569. 'value'=>$diag['form_submit_label']
  570. ));
  571. $attributes = array(
  572. 'id'=>$diag['form_id']
  573. );
  574. if(isset($diag['autocomplete'])){
  575. $attributes['autocomplete'] = $diag['autocomplete'];
  576. }
  577. echo get_form_html_advanced($attributes,$diag['form_fields']);
  578. break;
  579. }
  580. echo "</div>";
  581. }
  582. ?>
  583. </div>
  584. <div id="loading">
  585. <div class="ui-widget ui-state-default ui-corner-all"></div>
  586. </div>
  587. </body>
  588. </html>