Browse Source

Updates

Show access lists for channels.
Show loading spinner when ajax requests are happening.
Nathaniel van Diepen 10 years ago
parent
commit
518c7d5670
6 changed files with 125 additions and 55 deletions
  1. 23 0
      lib/irc.php
  2. 43 47
      site/api/index.php
  3. BIN
      site/img/loading.gif
  4. 19 0
      site/index.css
  5. 30 7
      site/index.php
  6. 10 1
      site/js/index.js

+ 23 - 0
lib/irc.php

@@ -323,4 +323,27 @@
 			'log'=>$msg
 		);
 	}
+	function channel_flag_name($flag){
+		switch($flag){
+			case 'v':$name=__('Voice');break;
+			case 'V':$name=__('Automatic voice');break;
+			case 'h':$name=__('Halfop');break;
+			case 'H':$name=__('Automatic Halfop');break;
+			case 'o':$name=__('Op');break;
+			case 'O':$name=__('Automatic Op');break;
+			case 'a':$name=__('Admin');break;
+			case 'q':$name=__('Owner');break;
+			case 's':$name=__('Set');break;
+			case 'i':$name=__('Invite/Getkey');break;
+			case 'r':$name=__('Kick/Ban');break;
+			case 'R':$name=__('Recover/Clear');break;
+			case 'f':$name=__('Modify access lists');break;
+			case 't':$name=__('Topic');break;
+			case 'A':$name=__('View access lists');break;
+			case 'F':$name=__('Founder');break;
+			case 'b':$name=__('Banned');break;
+			default:$name=$flag;
+		}
+		return $name;
+	}
 ?>

+ 43 - 47
site/api/index.php

@@ -3,7 +3,7 @@
 	header('Access-Control-Allow-Origin: *');
 	require_once("../../header.php");
 	if(!isset($_GET['action'])){
-		$opts = getopt('a:',Array('action:'));
+		$opts = getopt('a:',array('action:'));
 		$_GET['action'] = isset($opts['action'])?$opts['action']:(isset($opts['a'])?$opts['a']:'');
 	}
 	$u = is_logged_in();
@@ -45,18 +45,18 @@
 			$res = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$_COOKIE['user'],$_SESSION['password'],'MemoServ','list');
 			if($res[0]){
 				$res = explode('
',$res[1]);
-				$memos = Array();
+				$memos = array();
 				foreach($res as $k => $row){
 					if($k != 0 && $k != 1){
 						$row = preg_split('/^-\s/',$row);
 						if(isset($row[1])){
 							$row = explode(' ',$row[1]);
-							$memo = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$_COOKIE['user'],$_SESSION['password'],'MemoServ','read',Array($row[0]));
+							$memo = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$_COOKIE['user'],$_SESSION['password'],'MemoServ','read',array($row[0]));
 							$memo = explode('
',$memo[1]);
-							array_push($memos,Array(
+							array_push($memos,array(
 								'id'=>$row[0],
 								'from'=>$row[2],
-								'date'=>Array(
+								'date'=>array(
 									'month'=>$row[4],
 									'day'=>$row[5],
 									'time'=>$row[6],
@@ -78,14 +78,14 @@
 			$res = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$_COOKIE['user'],$_SESSION['password'],'InfoServ','list');
 			if($res[0]){
 				$res = explode('
',$res[1]);
-				$news = Array();
+				$news = array();
 				foreach($res as $k => $row){
 					if($k != count($res)-1){
-						array_push($news,Array(
+						array_push($news,array(
 							'id'=>preg_replace('/^(\d)+:.+$/i','\1',$row),
 							'title'=>preg_replace('/^\d+: \[(.+)\] .+/i','\1',$row),
 							'from'=>preg_replace('/^\d+: \[.+\] by (.+) at \d\d?:\d\d? on (\d\d)\/\d\d\/\d\d\d\d: .+/i','\1',$row),
-							'date'=>Array(
+							'date'=>array(
 								'time'=>preg_replace('/^\d+: \[.+\] by .+ at (\d\d?:\d\d?) on .+/','\1',$row),
 								'day'=>preg_replace('/^\d+: \[.+\] by .+ at \d\d?:\d\d? on (\d\d)\/\d\d\/\d\d\d\d: .+/i','\1',$row),
 								'month'=>preg_replace('/^\d+: \[.+\] by .+ at \d\d?:\d\d? on \d\d\/(\d\d)\/\d\d\d\d: .+/i','\1',$row),
@@ -106,45 +106,41 @@
 			$res = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$_COOKIE['user'],$_SESSION['password'],'NickServ','listchans');
 			if($res[0]){
 				$res = explode('
',$res[1]);
-				$channels = Array();
+				$channels = array();
 				foreach($res as $k => $row){
 					if($k != count($res)-1){
 						$flags_list = str_split(preg_replace('/^Access flag\(s\) \+(.+) in .+$/i','\1',$row));
-						$flags = array();
-						foreach($flags_list as $kk => $flag){
-							switch($flag){
-								case 'v':$name=__('Voice');break;
-								case 'V':$name=__('Automatic voice');break;
-								case 'h':$name=__('Halfop');break;
-								case 'H':$name=__('Automatic Halfop');break;
-								case 'o':$name=__('Op');break;
-								case 'O':$name=__('Automatic Op');break;
-								case 'a':$name=__('Admin');break;
-								case 'q':$name=__('Owner');break;
-								case 's':$name=__('Set');break;
-								case 'i':$name=__('Invite/Getkey');break;
-								case 'r':$name=__('Kick/Ban');break;
-								case 'R':$name=__('Recover/Clear');break;
-								case 'f':$name=__('Modify access lists');break;
-								case 't':$name=__('Topic');break;
-								case 'A':$name=__('View access lists');break;
-								case 'F':$name=__('Founder');break;
-								case 'b':$name=__('Banned');break;
-								default:$name=$flag;
-							}
-							array_push($flags,array(
-								'flag'=>$flag,
-								'name'=>$name
-							));
-						}
 						$name = preg_replace('/^Access flag\(s\) \+.+ in (.+)$/i','\1',$row);
 						$chan = array(
-							'name'=>$name,
-							'flags'=>$flags
+							'name'=>$name
 						);
 						if(in_array('F',$flags_list)){
 							$chan['candrop'] = true;
 						}
+						$res2 = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$_COOKIE['user'],$_SESSION['password'],'ChanServ','flags',array($name));
+						if($res2[0]){
+							$res2 = explode('
',$res2[1]);
+							$users = array();
+							foreach($res2 as $kk => $row2){
+								if($kk > 1 && $kk < count($res2)-2){
+									$user = array(
+										'id'=>preg_replace('/^(\d+)\b.+$/','\1',$row2),
+										'name'=>preg_replace('/^\d+\s+(.+)\s+\+.+/','\1',$row2),
+										'flags'=>array()
+									);
+									$flags_list = str_split(preg_replace('/^\d+\s+.+\s+\+(.+)\s+\[.+/i','\1',$row2));
+									foreach($flags_list as $kk => $flag){
+										$name = channel_flag_name($flag);
+										array_push($user['flags'],array(
+											'flag'=>$flag,
+											'name'=>$name
+										));
+									}
+									array_push($users,$user);
+								}
+							}
+						}
+						$chan['users'] = $users;
 						array_push($channels,$chan);
 					}
 				}
@@ -156,7 +152,7 @@
 		case 'send-memo':
 			$u or die('{"code":1,"message":"'.__('You have been logged out').'"}');
 			isset($_GET['to']) && isset($_GET['message']) or die('{"code":1,"message":"'.__('No message or user entered').'"}');
-			$res = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$_COOKIE['user'],$_SESSION['password'],'MemoServ','send',Array($_GET['to'],$_GET['message']));
+			$res = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$_COOKIE['user'],$_SESSION['password'],'MemoServ','send',array($_GET['to'],$_GET['message']));
 			if($res[0]){
 				if(substr($res[1],-19) == ' is not registered.'){
 					die('{"code":1,"message":"'.__('User').' '.$_GET['to'].' '.__('does not exist').'"}');
@@ -170,7 +166,7 @@
 		case 'delete-memo':
 			$u or die('{"code":1,"message":"'.__('You have been logged out').'"}');
 			isset($_GET['id']) or die('{"code":1,"message":"'.__('No id given').'"}');
-			$res = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$_COOKIE['user'],$_SESSION['password'],'MemoServ','delete',Array($_GET['id']));
+			$res = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$_COOKIE['user'],$_SESSION['password'],'MemoServ','delete',array($_GET['id']));
 			if(!$res[0]){
 				die('{"code":1,"message":"'.__('Cannot delete memo').': '+$res[1]+'"}');
 			}
@@ -179,7 +175,7 @@
 		case 'delete-channel':
 			$u or die('{"code":1,"message":"'.__('You have been logged out').'"}');
 			isset($_GET['channel']) or die('{"code":1,"message":"'.__('No channel given').'"}');
-			$res = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$_COOKIE['user'],$_SESSION['password'],'ChanServ','drop',Array($_GET['channel']));
+			$res = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$_COOKIE['user'],$_SESSION['password'],'ChanServ','drop',array($_GET['channel']));
 			if(!$res[0]){
 				die('{"code":1,"message":"'.__('Cannot drop channel').': '+$res[1]+'"}');
 			}
@@ -293,14 +289,14 @@
 			$u['password'] == mkpasswd($_GET['password'],$u['salt']) or die('{"code":2,"message":"'.__('Invalid password').'"}');
 			$u['api_key'] == $_COOKIE['key'] or die('{"code":3,"message":"Not Logged in to use '.$u['nick'].' with key '.$u['api_key'].' != '.$_COOKIE['key'].'."}');
 			if($_COOKIE['type'] == 'user'){
-				$res = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$u['nick'],$_GET['password'],'NickServ','set',Array('password',trim($_GET['newpass'])));
+				$res = atheme_command(get_conf('xmlrpc-server'),get_conf('xmlrpc-port'),get_conf('xmlrpc-path'),USER_IP,$u['nick'],$_GET['password'],'NickServ','set',array('password',trim($_GET['newpass'])));
 				if($res[0] === false){
 					die('{"code":2,"message":"'.__('Could not update password with nickserv').': '.$res[1].'"}');
 				}else{
 					$_SESSION['password'] = $_GET['newpass'];
 				}
 			}
-			query("UPDATE users u SET u.password='%s' WHERE u.id=%d",Array(mkpasswd($_GET['newpass']),$u['id']));
+			query("UPDATE users u SET u.password='%s' WHERE u.id=%d",array(mkpasswd($_GET['newpass']),$u['id']));
 			die('{"code":0}');
 		break;
 		case 'sync-pass':
@@ -311,7 +307,7 @@
 			if($res[0] === false){
 				die('{"code":2,"message":"'.__('Could not verify with nickserv').': '.$res[1].'"}');
 			}
-			query("UPDATE users u SET u.password='%s' WHERE u.id=%d",Array(mkpasswd($_SESSION['password']),$u['id']));
+			query("UPDATE users u SET u.password='%s' WHERE u.id=%d",array(mkpasswd($_SESSION['password']),$u['id']));
 			die('{"code":0,"message":"'.__('Nickserv password synchronized with main account').'"}');
 		break;
 		case 'role':
@@ -329,7 +325,7 @@
 			if($u['id'] == $user['id']){
 				setcookie('user',$_GET['nick'],null,'/');
 			}
-			query("UPDATE users u SET u.nick='%s', u.real_name='%s', u.email='%s' WHERE u.id=%d",Array($_GET['nick'],$_GET['real_name'],$_GET['email'],$_GET['id'])) or die('{"code":2,"message":"'.__('Unable to update user').'"}');
+			query("UPDATE users u SET u.nick='%s', u.real_name='%s', u.email='%s' WHERE u.id=%d",array($_GET['nick'],$_GET['real_name'],$_GET['email'],$_GET['id'])) or die('{"code":2,"message":"'.__('Unable to update user').'"}');
 			die(ircrehash());
 		break;
 		case 'oper':
@@ -339,9 +335,9 @@
 			isset($_GET['swhois']) or die('{"code":2,"message":"'.__('No profile set.').'"}');
 			$oper = get_oper_from_id_obj($_GET['id']) or die('{"code":2,"message":"'.__('Oper with id').' '.$_GET['id'].' '.__('does not exist. You should reload the page.').'"}');
 			if(isset($_GET['password']) && $_GET['password'] != ""){
-				query("UPDATE opers o SET o.nick='%s', o.swhois='%s', o.password='%s', o.password_type_id=2 WHERE o.id=%d",Array($_GET['nick'],$_GET['swhois'],mkpasswd($_GET['password']),$_GET['id'])) or die('{"code":2,"message":"'.__('Unable to update oper').'"}');
+				query("UPDATE opers o SET o.nick='%s', o.swhois='%s', o.password='%s', o.password_type_id=2 WHERE o.id=%d",array($_GET['nick'],$_GET['swhois'],mkpasswd($_GET['password']),$_GET['id'])) or die('{"code":2,"message":"'.__('Unable to update oper').'"}');
 			}else{
-				query("UPDATE opers o SET o.nick='%s', o.swhois='%s' WHERE o.id=%d",Array($_GET['nick'],$_GET['swhois'],$_GET['id'])) or die('{"code":2,"message":"'.__('Unable to update oper').'"}');
+				query("UPDATE opers o SET o.nick='%s', o.swhois='%s' WHERE o.id=%d",array($_GET['nick'],$_GET['swhois'],$_GET['id'])) or die('{"code":2,"message":"'.__('Unable to update oper').'"}');
 			}
 			die(ircrehash());
 		break;

BIN
site/img/loading.gif


+ 19 - 0
site/index.css

@@ -14,6 +14,25 @@ html,body{
 	background-size: auto auto;
 	color: white;
 }
+#loading{
+	position: absolute;
+	left: 0px;
+	top: 0px;
+	width: 100%;
+	height: 100%;
+	z-index: 100;
+	background-color: rgba(0, 0, 0, 0.5);
+}
+#loading>div{
+	background-image: url(img/loading.gif);
+	left: 50%;
+	top: 50%;
+	position: relative;
+	width: 20px;
+	height: 20px;
+	background-repeat: no-repeat;
+	background-position: center center;
+}
 .ui-state-default.ui-widget .link{
 	text-decoration: underline;
 	cursor: pointer;

+ 30 - 7
site/index.php

@@ -63,7 +63,7 @@
 		</script>
 		<?php
 			if($user){
-				echo "<script>$(document).ready(function(){";
+				echo "<script>function delayedload(){";
 				if(is_logged_in() && is_verified()){
 					echo "runWhenExists('ServerPing');";
 				}
@@ -72,7 +72,7 @@
 					echo "runWhenExists('FetchNews');";
 					echo "runWhenExists('FetchChannels');";
 				}
-				echo "});</script>";
+				echo "};</script>";
 				if(has_flag($user,'u')){ ?>
 					<script id="template-memos" type="text/x-handlebars-template">
 						<button class="button" value="<?php echo __('Refresh'); ?>" onclick="window.FetchMemos(true);">
@@ -160,12 +160,32 @@
 						{{#each channels}}
 							<div id="channel-{{this.name}}" class="ui-widget ui-state-default ui-corner-all" style="padding:5px;">
 								{{this.name}}
-								<br/>
-								<?php echo __('Flags:'); ?>
-								<ul>
-									{{#each this.flags}}
-										<li>{{this.name}}</li>
+								<table class="tree">
+									<tr style='font-weight:bold;' class='treegrid-0'>
+										<td>
+											<?php echo __('Access'); ?>
+										</td>
+										<td></td>
+									</tr>
+									{{#each this.users}}
+										<tr style='font-weight:bold;' class='treegrid-{{this.id}} treegrid-parent-0'>
+											<td>
+												{{this.name}}
+											</td>
+											<td>
+												<?php echo __('Flags'); ?>
+											</td>
+										</tr>
+										{{#each this.flags}}
+											<tr class='treegrid-{{this.flag}} treegrid-parent-{{../id}}'>
+												<td></td>
+												<td>
+													{{this.name}}
+												</td>
+											</tr>
+										{{/each}}
 									{{/each}}
+									</table>
 								</ul>
 								{{#if this.candrop}}
 									<button value="<?php echo __('Delete'); ?>" style="background-color:red;background-image:none;" onclick="window.DeleteChannel('{{this.name}}');">
@@ -500,5 +520,8 @@
 					}
 				?>
 			</div>
+			<div id="loading">
+				<div class="ui-widget ui-state-default ui-corner-all"></div>
+			</div>
 	</body>
 </html>

+ 10 - 1
site/js/index.js

@@ -382,7 +382,6 @@ $(function(){
 		if(!Modernizr.inputtypes.number){
 			$('input[type=number]').spinner();
 		}
-		$('body').show();
 		window.ServerPing = function(){
 			console.log(_("Server Ping"));
 			$.ajax(__HOSTNAME__+'site/api/?action=ping',{
@@ -547,6 +546,9 @@ $(function(){
 					}
 					$('#channels').html(templates.channels(d)).find('button').button();
 					translate('#channels');
+					$('#channels').find('.tree').treegrid({
+						initialState: 'collapsed'
+					});
 					$('body').resize();
 				},
 				error: function(xhr,msg,e){
@@ -623,6 +625,13 @@ $(function(){
 				location.reload();
 			}
 		},1000);
+		delayedload();
+		$(document).ajaxStart(function(){
+			$("#loading").show();
+		}).ajaxStop(function(){
+			$("#loading").hide();
+		});
+		$('body').show();
 		$('body').resize();
 	});
 });