index.php 16 KB

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