index.php 16 KB

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