index.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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/4.0.2/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. </tr>
  170. {{#each this.users}}
  171. <tr style='font-weight:bold;' class='treegrid-{{this.id}} treegrid-parent-0'>
  172. <td>
  173. {{this.name}}
  174. </td>
  175. <td>
  176. {{#if ../canaccess}}
  177. <a onclick="window.ModifyChannelAccess('{{../../name}}','{{this.name}}',{{this.id}});" style="cursor:pointer;">
  178. <?php echo __('Modify'); ?>
  179. </a>
  180. {{/if}}
  181. </td>
  182. </tr>
  183. {{#each this.flags}}
  184. {{#if this.flag}}
  185. <tr class='treegrid-{{this.flag}} treegrid-parent-{{../id}}'>
  186. <td></td>
  187. <td>
  188. {{this.name}}
  189. </td>
  190. </tr>
  191. {{/if}}
  192. {{/each}}
  193. {{/each}}
  194. </table>
  195. </ul>
  196. {{#if this.canaccess}}
  197. <button value="<?php echo __('Add Access'); ?>" onclick="window.ModifyChannelAccess('{{this.name}}');">
  198. <?php echo __('Add Access'); ?>
  199. </button>
  200. {{/if}}
  201. {{#if this.candrop}}
  202. <button value="<?php echo __('Delete'); ?>" style="background-color:red;background-image:none;" onclick="window.DeleteChannel('{{this.name}}');">
  203. <?php echo __('Delete'); ?>
  204. </button>
  205. {{/if}}
  206. </div>
  207. {{/each}}
  208. </script>
  209. <?php }
  210. }
  211. ?>
  212. </head>
  213. <body style="display:none;">
  214. <?php
  215. $flag = is_verified();
  216. if($user && $flag){
  217. ?>
  218. <div class="tabs">
  219. <ul>
  220. <?php
  221. if(has_flag($user,'u')){ ?>
  222. <li><a href="#news"><?php echo __('News'); ?></a></li>
  223. <li><a href="#memos"><?php echo __('Memos'); ?></a></li>
  224. <li><a href="#channels"><?php echo __('Channels'); ?></a></li>
  225. <?php }
  226. echo has_flag($user,'n')?'<li><a href="#servers">'.__('Servers').'</a></li>':'';
  227. echo has_flag($user,'o')?'<li><a href="#opers">'.__('Opers').'</a></li>':'';
  228. echo has_flag($user,'a')?'<li><a href="#config">'.__('Configuration').'</a></li>':'';
  229. ?>
  230. <li><a href="#profile"><?php echo __('Profile'); ?></a></li>
  231. <div id="user-menu-button" class="right button">
  232. <?php echo $user['nick']; ?>
  233. </div>
  234. </ul>
  235. <?php if(has_flag($user,'n')){?>
  236. <div id="servers">
  237. <?php
  238. echo get_servers_list_html($servers);
  239. ?>
  240. </div>
  241. <?php }
  242. if(has_flag($user,'o')){?>
  243. <div id="opers">
  244. <?php echo get_opers_html($opers); ?>
  245. </div>
  246. <?php }
  247. if(has_flag($user,'a')){ ?>
  248. <div id="config">
  249. <?php echo render_configuration_table(); ?>
  250. </div>
  251. <?php }
  252. if(has_flag($user,'u')){ ?>
  253. <div id="news"></div>
  254. <div id="memos"></div>
  255. <div id="channels"></div>
  256. <?php
  257. array_push($dialogs,array(
  258. 'id'=>'memo-diag',
  259. 'type'=>'form',
  260. 'form_id'=>'memo',
  261. 'form_submit_label'=>__('Send'),
  262. 'form_fields'=>array(
  263. array(
  264. 'name'=>'to',
  265. 'label'=>__('To'),
  266. 'type'=>'string',
  267. 'value'=>''
  268. ),
  269. array(
  270. 'name'=>'message',
  271. 'label'=>__('Message'),
  272. 'type'=>'string',
  273. 'value'=>''
  274. ),
  275. array(
  276. 'name'=>'action',
  277. 'type'=>'hidden',
  278. 'value'=>'send-memo'
  279. )
  280. )
  281. ));
  282. array_push($dialogs,array(
  283. 'id'=>'channel-diag',
  284. 'type'=>'form',
  285. 'form_id'=>'channel',
  286. 'form_submit_label'=>__('Register'),
  287. 'form_fields'=>array(
  288. array(
  289. 'name'=>'channel',
  290. 'label'=>__('Channel Name'),
  291. 'type'=>'string',
  292. 'value'=>''
  293. ),
  294. array(
  295. 'name'=>'action',
  296. 'type'=>'hidden',
  297. 'value'=>'register-channel'
  298. )
  299. )
  300. ));
  301. array_push($dialogs,array(
  302. 'id'=>'channel-flags-diag',
  303. 'type'=>'form',
  304. 'form_id'=>'channel-flags',
  305. 'form_submit_label'=>__('Modify'),
  306. 'form_fields'=>array(
  307. array(
  308. 'name'=>'user',
  309. 'label'=>__('User'),
  310. 'type'=>'string',
  311. 'value'=>''
  312. ),
  313. array(
  314. 'name'=>'flags',
  315. 'label'=>__('Flags'),
  316. 'type'=>'multi',
  317. 'values'=>array(
  318. channel_flag_obj('A'),
  319. channel_flag_obj('F'),
  320. channel_flag_obj('O'),
  321. channel_flag_obj('R'),
  322. channel_flag_obj('V'),
  323. channel_flag_obj('a'),
  324. channel_flag_obj('f'),
  325. channel_flag_obj('h'),
  326. channel_flag_obj('i'),
  327. channel_flag_obj('o'),
  328. channel_flag_obj('q'),
  329. channel_flag_obj('r'),
  330. channel_flag_obj('s'),
  331. channel_flag_obj('t'),
  332. channel_flag_obj('v'),
  333. channel_flag_obj('b')
  334. )
  335. ),
  336. array(
  337. 'name'=>'channel',
  338. 'type'=>'hidden',
  339. 'value'=>''
  340. ),
  341. array(
  342. 'name'=>'action',
  343. 'type'=>'hidden',
  344. 'value'=>'channel-flags'
  345. )
  346. )
  347. ));
  348. } ?>
  349. <div id="profile">
  350. <?php
  351. echo get_user_html($user);
  352. if(has_flag($user,'a') || has_flag($user,'o') || has_flag($user,'n')){
  353. if(!isset($user['secret_key']) || is_null($user['secret_key']) || $user['secret_key'] == ''){
  354. switch(get_conf('2-factor-method')){
  355. case 'authy':
  356. echo '<div class="login-form">Enable 2-factor Authentication'.get_form_html('2-factor',array(
  357. array(
  358. 'name'=>'country-code',
  359. 'label'=>__('Country'),
  360. 'type'=>'text',
  361. 'attributes'=>array(
  362. 'id'=>'authy-countries'
  363. )
  364. ),
  365. array(
  366. 'name'=>'cellphone',
  367. 'label'=>__('Cell #'),
  368. 'type'=>'text',
  369. 'attributes'=>array(
  370. 'id'=>'authy-cellphone'
  371. )
  372. ),
  373. array(
  374. 'name'=>'action',
  375. 'type'=>'hidden',
  376. 'value'=>'2-factor-register'
  377. )
  378. ),'Submit').'</div>';
  379. break;
  380. case 'google-authenticator':
  381. $api = get_api();
  382. $_SESSION['secret_key'] = $api->createSecret();
  383. echo '<div class="login-form">Enable 2-factor Authentication'.get_form_html('2-factor',array(
  384. array(
  385. 'type'=>'custom',
  386. 'html'=>"<img src='data:image/png;base64,".base64_encode(file_get_contents($api->getQRCodeGoogleUrl('Omninet',$_SESSION['secret_key'])))."'/>"
  387. ),
  388. array(
  389. 'name'=>'token',
  390. 'label'=>__('Token'),
  391. 'type'=>'text'
  392. ),
  393. array(
  394. 'name'=>'action',
  395. 'type'=>'hidden',
  396. 'value'=>'2-factor-register'
  397. )
  398. ),'Submit').'</div>';
  399. break;
  400. default:
  401. }
  402. }else{
  403. switch(get_conf('2-factor-method')){
  404. case 'authy':case 'google-authenticator':
  405. echo "<button id='2-factor-disable' value='".('Disable 2-factor')."'>".__('Disable 2-factor')."</button>";
  406. break;
  407. default:
  408. }
  409. }
  410. if(get_conf('persona-endpoint') != 'none'){
  411. 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>";
  412. $emails = get_emails($user['id'],true);
  413. foreach($emails as $k => $email){
  414. echo "<div><button id='persona-remove-{$email['id']}' value='".__('Remove')."'>".__('Remove')."</button>{$email['email']}</div>";
  415. }
  416. }
  417. }
  418. ?>
  419. </div>
  420. </div>
  421. <ul class="menu" id="user-menu">
  422. <li><a id="roles-button"><?php echo __('Switch Role'); ?></a></li>
  423. <?php if(has_flag($user,'n')||has_flag($user,'a')){?>
  424. <li><a id="rehash-servers"><?php echo __('Rehash'); ?></a></li>
  425. <?php } ?>
  426. <li><a id="newpass-button"><?php echo __('Change Password'); ?></a></li>
  427. <?php if(has_flag($user,'u')){ ?>
  428. <li><a id="sync-pass"><?php echo __('Sync Password'); ?></a></li>
  429. <li><a id="sync-groups"><?php echo __('Sync Groups'); ?></a></li>
  430. <?php } ?>
  431. <li><a id="logout"><?php echo __('Logout'); ?></a></li>
  432. </ul>
  433. <?php
  434. array_push($dialogs,array(
  435. 'id'=>'newpass-diag',
  436. 'type'=>'form',
  437. 'form_id'=>'newpass',
  438. 'form_submit_label'=>__('Change Password'),
  439. 'form_fields'=>array(
  440. array(
  441. 'name'=>'password',
  442. 'label'=>__('Password'),
  443. 'type'=>'password',
  444. 'value'=>''
  445. ),
  446. array(
  447. 'name'=>'newpass',
  448. 'label'=>__('New Password'),
  449. 'type'=>'password',
  450. 'value'=>''
  451. ),
  452. array(
  453. 'name'=>'action',
  454. 'type'=>'hidden',
  455. 'value'=>'newpass'
  456. )
  457. )
  458. ));
  459. $roles = array(array(
  460. 'value'=>'user',
  461. 'label'=>__('User')
  462. ));
  463. 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']))){
  464. while($role = $res->fetch_assoc()){
  465. array_push($roles,$role);
  466. }
  467. }
  468. array_push($dialogs,array(
  469. 'id'=>'roles-diag',
  470. 'type'=>'form',
  471. 'form_id'=>'roles',
  472. 'form_submit_label'=>__('Switch'),
  473. 'form_fields'=>array(
  474. array(
  475. 'name'=>'type',
  476. 'label'=>__('Type'),
  477. 'type'=>'select',
  478. 'values'=>$roles,
  479. 'value'=>isset($_COOKIE['type'])?$_COOKIE['type']:'user'
  480. ),
  481. array(
  482. 'name'=>'action',
  483. 'type'=>'hidden',
  484. 'value'=>'role'
  485. )
  486. )
  487. ));
  488. }elseif($user && !$flag){
  489. array_push($dialogs,array(
  490. 'id'=>'verify-diag',
  491. 'type'=>'form',
  492. 'autocomplete'=>'off',
  493. 'form_id'=>'verify',
  494. 'form_submit_label'=>__('Login'),
  495. 'form_fields'=>array(
  496. array(
  497. 'name'=>'token',
  498. 'label'=>__('2-Factor Verification'),
  499. 'type'=>'text',
  500. 'attributes'=>array(
  501. 'id'=>'authy-token',
  502. 'style'=>'background-color:#F2DEDE;'
  503. )
  504. ),
  505. array(
  506. 'name'=>'action',
  507. 'type'=>'hidden',
  508. 'value'=>'verify'
  509. )
  510. )
  511. ));
  512. }else{
  513. $roles = array(array(
  514. 'value'=>'user',
  515. 'label'=>__('User')
  516. ));
  517. if($res = query("SELECT name AS value,description AS label FROM ircd.user_role_types")){
  518. while($role = $res->fetch_assoc()){
  519. array_push($roles,$role);
  520. }
  521. }
  522. array_push($dialogs,array(
  523. 'id'=>'login-diag',
  524. 'type'=>'form',
  525. 'form_id'=>'login',
  526. 'form_submit_label'=>__('Login'),
  527. 'form_fields'=>array(
  528. array(
  529. 'type'=>'custom',
  530. '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>":''
  531. ),
  532. array(
  533. 'name'=>'username',
  534. 'label'=>__('Username'),
  535. 'type'=>'text',
  536. 'value'=>''
  537. ),
  538. array(
  539. 'name'=>'password',
  540. 'label'=>__('Password'),
  541. 'type'=>'password',
  542. 'value'=>''
  543. ),
  544. array(
  545. 'name'=>'type',
  546. 'label'=>__('Type'),
  547. 'type'=>'select',
  548. 'values'=>$roles
  549. ),
  550. array(
  551. 'name'=>'action',
  552. 'type'=>'hidden',
  553. 'value'=>'login'
  554. )
  555. )
  556. ));
  557. }
  558. ?>
  559. <div id="dialogs">
  560. <?php
  561. foreach($dialogs as $k => $diag){
  562. echo "<div id='{$diag['id']}'>";
  563. switch($diag['type']){
  564. case 'form':
  565. array_push($diag['form_fields'],array(
  566. 'type'=>'submit',
  567. 'value'=>$diag['form_submit_label']
  568. ));
  569. $attributes = array(
  570. 'id'=>$diag['form_id']
  571. );
  572. if(isset($diag['autocomplete'])){
  573. $attributes['autocomplete'] = $diag['autocomplete'];
  574. }
  575. echo get_form_html_advanced($attributes,$diag['form_fields']);
  576. break;
  577. }
  578. echo "</div>";
  579. }
  580. ?>
  581. </div>
  582. </body>
  583. </html>