index.php 17 KB

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