"Fossies" - the Fresh Open Source Software Archive

Member "cgiirc-0.5.13/interfaces/interface-make/fwindowlist.pm" (24 Apr 2019, 17551 Bytes) of package /linux/privat/cgiirc-0.5.13.tar.gz:


The requested HTML page contains a <FORM> tag that is unusable on "Fossies" in "automatic" (rendered) mode so that page is shown as HTML source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "fwindowlist.pm" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.5.12_vs_0.5.13.

    1    my($self, $cgi, $config) = @_;
    2    my $string;
    3    for(keys %$cgi) {
    4       next if $_ eq 'item';
    5       $string .= main::cgi_encode($_) . '=' . main::cgi_encode($cgi->{$_}).'&';
    6    }
    7    $string =~ s/\&$//;
    8 
    9 print $standardheader;
   10 print q~
   11 <html>
   12 <head>
   13 <script language="JavaScript">
   14 <!--
   15 // This javascript code is released under the same terms as CGI:IRC itself
   16 // http://cgiirc.org/
   17 // Copyright (C) 2000-2003 David Leadbeater <http://dgl.cx>
   18 
   19 //               none      joins    talk       directed talk
   20 var activity = ['#000000','#000099','#990000', '#009999'];
   21 
   22 var Witems = {};
   23 var options = {};
   24 var currentwindow = '';
   25 var lastwindow = '';
   26 var connected = 0;
   27 var mynickname = '';
   28 var prefixchars = '@%+ ';
   29 
   30 .$just ie
   31 document.onselectstart = function() { return false; }
   32 document.onmouseup = function() {
   33    if(event.button != 2) return true;
   34    event.returnVal = false;
   35    return false;
   36 }
   37 document.oncontextmenu = function() {
   38    return false;
   39 }
   40 document.onhelp = function() {
   41    sendcmd('/help');
   42    return false;
   43 }
   44 .$end
   45 
   46 function witemadd(name, channel) {
   47    if(Witems[name] || findwin(name)) return;
   48    name = name.replace(/\"/g, '&quot;');
   49    Witems[ name ] = { activity: 0, text: new Array, channel: channel, speak: 1,  info: 0 };
   50    if(channel) {
   51       Witems[name].users = {};
   52       Witems[name].topic = '';
   53    }
   54    if(!currentwindow) currentwindow = name;
   55    wlistredraw();
   56 }
   57 
   58 function witemnospeak(name) {
   59    if(!Witems[name] && !(name = findwin(name))) return;
   60    Witems[name].speak = 0;
   61 }
   62 
   63 function witeminfo(name) {
   64    if(!Witems[name] && !(name = findwin(name))) return;
   65    Witems[name].info = 1;
   66 }
   67 
   68 function witemdel(name) {
   69    if(!Witems[name] && !(name = findwin(name))) return;
   70    if(name == 'Status') return;
   71    delete Witems[name];
   72    if(currentwindow == name) witemchg(lastwindow ? lastwindow : 'Status');
   73 }
   74 
   75 function witemclear(name) {
   76    if(!Witems[name] && !(name = findwin(name))) return;
   77    Witems[name].text.length = 0;
   78    witemredraw();
   79 }
   80 
   81 
   82 function channeladdusers(channel, users) {
   83    for(var i = 0;i < users.length;i++) {
   84       channeladduser(channel, users[i]);
   85    }
   86    userlist();
   87 }
   88 
   89 function channeladduser(channel, user) {
   90    var o = user.substr(0,1)
   91    if(prefixchars.lastIndexOf(o) != -1) {
   92       user = user.substr(1)
   93       while(prefixchars.lastIndexOf(user.substr(0,1)) != -1)
   94          user = user.substr(1)
   95    }
   96 
   97    if(!Witems[channel] && !(channel = findwin(channel))) return;
   98 
   99    Witems[channel].users[user] = { };
  100 
  101    if(o == '@') Witems[channel].users[user].op = 1;
  102    else if(o == '%') Witems[channel].users[user].halfop = 1;
  103    else if(o == '+') Witems[channel].users[user].voice = 1;
  104    else if(prefixchars.lastIndexOf(o) != -1)
  105       Witems[channel].users[user].other = o;
  106 }
  107 
  108 function channelsdeluser(channels, user) {
  109    if(channels == '-all-') {
  110       for(var i in Witems) {
  111          if(!Witems[i].channel) continue;
  112          if(!Witems[i].users[user]) continue;
  113          channeldeluser(i, user);
  114       }
  115       return;
  116    }
  117    for(var i = 0;i < channels.length; i++) {
  118       channeldeluser(channels[i], user);
  119    }
  120    userlist();
  121 }
  122 
  123 function channeldeluser(channel, user) {
  124    if(!Witems[channel] && !(channel = findwin(channel))) return;
  125    delete Witems[channel].users[user];
  126    userlist();
  127 }
  128 
  129 function channelsusernick(olduser, newuser) {
  130    for(var channel in Witems) {
  131       if(!Witems[channel].channel) continue;
  132       for(var nick in Witems[channel].users) {
  133           if(nick == olduser) {
  134             Witems[channel].users[newuser] = Witems[channel].users[olduser];
  135             delete Witems[channel].users[olduser];
  136            }
  137        }
  138    }
  139    userlist();
  140 }
  141 
  142 function channelusermode(channel, user, action, type) {
  143    if(!Witems[channel] && !(channel = findwin(channel))) return;
  144    if(!Witems[channel].users[user]) return;
  145 
  146    if(action == '+') {
  147       Witems[channel].users[user][type] = 1;
  148    }else{
  149       delete(Witems[channel].users[user][type]);
  150    }
  151    userlist();
  152 }
  153 
  154 function channellist(channel) {
  155    if(!Witems[channel] && !(channel = findwin(channel))) return;
  156    var users = new Array();
  157 
  158    for (var i in Witems[channel].users) {
  159       var user = Witems[channel].users[i];
  160       if(user.other) i = user.other + i;
  161      else if(user.op == 1) i = '@' + i
  162       else if(user.halfop == 1) i = '%' + i;
  163       else if(user.voice == 1) i = '+' + i;
  164      else   i = ' ' + i;
  165 
  166       users[users.length] = i;
  167    }
  168 
  169    users = users.sort(usersort);
  170    return users;
  171 }
  172 
  173 function usersort(user1,user2) {
  174    var m1 = user1.substr(0,1);
  175    var m2 = user2.substr(0,1);
  176 
  177    if(m1 == m2) {
  178       if(user1.toUpperCase() < user2.toUpperCase()) return -1
  179        return 1
  180    }
  181 
  182    if(prefixchars.lastIndexOf(m1) < prefixchars.lastIndexOf(m2)) return -1
  183    return 1
  184 }
  185 
  186 function witemchg(name) {
  187    if(!Witems[name] && !(name = findwin(name))) name = 'Status';
  188    if(Witems[name].activity > 0) Witems[name].activity = 0;
  189    lastwindow = (Witems[currentwindow] ? currentwindow : 'Status');
  190    currentwindow = name;
  191    wlistredraw();
  192    witemredraw();
  193    formfocus();
  194    userlist();
  195    retitle();
  196 }
  197 
  198 function retitle() {
  199    parent.document.title = 'CGI:IRC - ' + (Witems[currentwindow].info ? currentwindow.substr(1) : currentwindow) + (Witems[currentwindow].channel == 1 ? ' [' + countit(Witems[currentwindow].users) + '] ' : '');
  200 }
  201 
  202 function setoption(option, value) {
  203    options[option] = value;
  204    if(option == 'shownick' && value == 1)
  205       mynick(mynickname)
  206    else if(option == 'shownick') {
  207       if(parent.fform && parent.fform.nickchange) parent.fform.nickchange('');
  208    }else if(option == 'font')
  209       fontset(value)
  210 .$just ie
  211    else if((option == 'actsound' || option == 'joinsound') && value == 1)
  212     enable_sounds();
  213 .$end
  214 }
  215 
  216 function mynick(mynick) {
  217    mynickname = mynick;
  218    if(options.shownick != 1) return;
  219    if(parent.fform && parent.fform.nickchange) parent.fform.nickchange(mynick);
  220 }
  221 
  222 function maincolor(bg, fg) {
  223    var maindoc = parent.fmain.document;
  224    if(!maindoc) return;
  225    maindoc.bgColor = bg;
  226    maindoc.fgColor = fg;
  227 }
  228 
  229 function prefix(chars) {
  230    if(!/ /.test(chars))
  231       chars += ' '
  232    prefixchars = chars;
  233 }
  234 
  235 function witemchgnum(num) {
  236    var count = 1;
  237    for(var name in Witems) {
  238       if(count++ == num) return name;
  239    }
  240    return false;
  241 }
  242 
  243 function countit(obj) {
  244    var i = 0;
  245    for(var foo in obj) i++;
  246    return i;
  247 }
  248 
  249 function witemaddtext(name, text, activity, redraw) {
  250    if(name == '-all') {
  251       for(var window in Witems) {
  252         if(window == '-all') return
  253         if(Witems[window].info) continue;
  254          witemaddtext(window, text, activity, redraw);
  255       }
  256       return;
  257    }
  258    if(name == '-active') name = currentwindow
  259 
  260    if(!Witems[name] && !(name = findwin(name))) {
  261       if(!Witems["Status"]) return;
  262       name = "Status";
  263    }
  264    
  265    if(options["timestamp"] == 1 && !Witems[name].info) {
  266       var D = new Date();
  267       text = '[' + (D.getHours() < 10 ? '0' + D.getHours() : D.getHours()) + ':' + (D.getMinutes() < 10 ? '0' + D.getMinutes() : D.getMinutes()) + '] ' + text;
  268    }
  269   
  270    if(options["scrollback"] == 0)
  271       Witems[name].text = Witems[name].text.slice(Witems[name].text.length - 200);
  272    if(!Witems[name].info)
  273       text = "<div class='main-item'>" + text + "</div>";
  274    Witems[name].text[Witems[name].text.length] = text;
  275 
  276    if(options["actsound"] == 1 && activity >= 3)
  277       playsound("actmsg");
  278 
  279    if(currentwindow != name && activity > Witems[name].activity)
  280        witemact(name, activity);
  281    if(redraw != 0 && currentwindow == name) witemredraw();
  282 }
  283 
  284 function witemact(name, activity) {
  285    if(!Witems[name] && !(name = findwin(name))) return;
  286    Witems[name].activity = activity;
  287    wlistredraw();
  288 }
  289 
  290 function witemredraw() {
  291    if(!parent.fmain.document) {
  292       setTimeout("witemredraw()", 1000);
  293       return;
  294    }
  295    var doc = parent.fmain.document.body;
  296    var scrollok = 1;
  297    if(!currentwindow) currentwindow = 'Status';
  298 .$just ie
  299    if(doc.scrollTop < (doc.scrollHeight - doc.clientHeight - 5))
  300       scrollok = 0;
  301 .$end
  302    parent.fmain.document.getElementById('text').innerHTML = Witems[currentwindow].text.join('');
  303    if(Witems[currentwindow].info == 1) return;
  304    var count = 0;
  305    var span = parent.fmain.document.getElementById('text');
  306    if (span.scrollHeight) {
  307      var count = 0;
  308      while(span.scrollTop < span.scrollHeight && count < 20) {
  309        span.scrollTop = span.scrollHeight;
  310        count++;
  311      }
  312    } else if(doc.scrollHeight && scrollok == 1) {
  313       while(doc.scrollTop < doc.scrollHeight && count < 20) {
  314          doc.scrollTop = doc.scrollHeight;
  315          count++;
  316       }
  317    } else {
  318      var doc = parent.fmain.window;
  319      var scroll = -1;
  320      while(doc.scrollY > scroll) {
  321             scroll = doc.scrollY;
  322             doc.scrollBy(0, 500);
  323      }
  324   }
  325 }
  326 
  327 function wlistredraw() {
  328    var output='';
  329    for (var i in Witems) {
  330       output += '<span class="' + (i == currentwindow ? 'wlist-active' : 'wlist-chooser') + '" style="color: ' + activity[Witems[i].activity] + ';" onclick="witemchg(\'' + (i == currentwindow ? escapejs(lastwindow) : escapejs(i)) + '\')" onmouseover="this.className = \'wlist-mouseover\'" onmouseout="this.className = \'' + (i == currentwindow ? 'wlist-active' : 'wlist-chooser') + '\'">' + escapehtml(Witems[i].info ? i.substr(1) : i) + '</span>\r\n';
  331    }
  332    document.getElementById('windowlist').innerHTML = output;
  333 }
  334 
  335 function findwin(name) {
  336    var wname = new String(name);
  337    wname = wname.replace(/\"/g, '&quot;');
  338    for (var i in Witems) {
  339       if (i.toUpperCase() == wname.toUpperCase())
  340          return i;
  341    }
  342    return false;
  343 }
  344 
  345 function escapejs(string) {
  346    out = string.replace(/\\\\/g,'\\\\\\\\').replace(/\\'/g, '\\\\\\'').replace(/\"/g, '&quot;');
  347    return out;
  348 }
  349 
  350 function escapehtml(string) {
  351    var out = string;
  352    out = out.replace(/</g, '&lt;');
  353    out = out.replace(/>/g, '&gt;');
  354    out = out.replace(/\"/g, '&quot;');
  355    return out;
  356 }
  357 
  358 function reconnect() {
  359       do_quit();
  360      Witems = { };
  361      if(document.getElementById('iframe').src.match(/\&token=/)) {
  362        window.location.reload()
  363      } else {
  364        document.getElementById('iframe').src = document.getElementById('iframe').src + '&xx=yy';
  365      }
  366 }
  367 
  368 function sendcmd(cmd) {
  369    if(cmd.substr(0, 10) == '/reconnect') {
  370       reconnect();
  371       return;
  372    }
  373 
  374    if(!connected && cmd.substr(0,5) != '/quit') {
  375       alert('Not connected to IRC!');
  376       return;
  377    }
  378    if(Witems[currentwindow] && !Witems[currentwindow].speak && cmd.substr(0,1) != '/') {
  379      alert("You can't speak here, select a channel or query tab.");
  380      return;
  381    }
  382    sendcmd_real('say', cmd, currentwindow);
  383 }
  384 
  385 function sendcmd_userlist(action, user) {
  386    if(!Witems[currentwindow].channel) return;
  387    if(!connected) {
  388       alert('Not connected to IRC!');
  389       return;
  390    }
  391    sendcmd_real('say', '/' + action + ' ' + user, currentwindow);
  392 }
  393 
  394 function sendcmd_real(type, say, target) {
  395    send_make({ item: 'say', cmd: type, say: say, target: target })
  396 }
  397 
  398 function senditem(item) {
  399    send_make({ item: item })
  400 }
  401 
  402 function send_option(name, value) {
  403    send_make({ cmd: 'options', name: name, value: value })
  404 }
  405 
  406 function send_make(data) {
  407 .$just ie mozilla
  408    var xmlhttp = xmlhttp_new()
  409 .$else
  410    var xmlhttp = 0
  411 .$end
  412 
  413    if(xmlhttp) {
  414      try {
  415        xmlhttp_send(xmlhttp, data)
  416      } catch(e) {
  417        xmlhttp = 0
  418      }
  419    }
  420 
  421    if(!xmlhttp) {
  422       for(var i in data) {
  423          document.hsubmit[i].value = data[i]
  424       }
  425       document.hsubmit.submit();
  426       for(var i in data) {
  427          document.hsubmit[i].value = ""
  428       }
  429    }
  430 }
  431 
  432 function userlist() {
  433    if(!parent.fuserlist.userlist) {
  434       setTimeout(1000, "userlist()");
  435       return;
  436    }
  437    if(Witems[currentwindow] && Witems[currentwindow].channel == 1) {
  438       userlistupdate(channellist(currentwindow));
  439    }else{
  440       userlistupdate([' No channel']);
  441    }
  442    retitle();
  443 }
  444 
  445 function userlistupdate(list) {
  446    if(!parent.fuserlist.userlist) return;
  447    parent.fuserlist.userlist(list);
  448 }
  449 
  450 function formfocus() {
  451    if(parent.fform.location) parent.fform.fns();
  452 }
  453 
  454 function disconnected() {
  455    if(connected == 1) {
  456       connected = 0;
  457       do_quit();
  458       witemaddtext('-all', '<b>Disconnected</b>', 1, 1);
  459    }
  460 }
  461 
  462 function doinfowin(name, text) {
  463    witemadd(name, 0);
  464    witemnospeak(name);
  465    witeminfo(name);
  466    witemclear(name);
  467    witemaddtext(name, text, 0, 1);
  468    witemchg(name);
  469 }
  470 
  471 function fontset(font) {
  472    if(parent.frames.fmain.document.getElementById('text')) {
  473       parent.frames.fmain.document.getElementById('text').style.fontFamily = font;
  474    }
  475 }
  476 
  477 function playsound(soundname) {
  478 .$just ie
  479    var sound = document.getElementById("sound-" + soundname);
  480    if(sound)
  481       sound.play();
  482    else
  483 .$end
  484       top.window.focus();
  485 }
  486 
  487 function joinsound() {
  488    if(options["joinsound"] == 1)
  489       playsound("join");
  490 }
  491 
  492 ~;
  493 # ' (fix syntax hilight)
  494 print <<EOF;
  495 imghelpdn = new Image();
  496 imghelpdn.src = "$config->{image_path}/helpdn.gif";
  497 imghelpup = new Image();
  498 imghelpup.src = "$config->{image_path}/helpup.gif";
  499 
  500 imgoptionsdn = new Image();
  501 imgoptionsdn.src = "$config->{image_path}/optionsdn.gif";
  502 imgoptionsup = new Image();
  503 imgoptionsup.src = "$config->{image_path}/optionsup.gif";
  504 
  505 imgclosedn = new Image();
  506 imgclosedn.src = "$config->{image_path}/closedn.gif";
  507 imgcloseup = new Image();
  508 imgcloseup.src = "$config->{image_path}/closeup.gif";
  509 
  510 function do_quit() {
  511    var i = new Image();
  512    i.src = "$config->{script_form}?R=$cgi->{R}&cmd=quit";
  513 }
  514 .$just ie mozilla
  515 function xmlhttp_new() {
  516    if(window.XMLHttpRequest)
  517       xmlhttp = new XMLHttpRequest()
  518    else if (window.ActiveXObject)
  519       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
  520    return xmlhttp
  521 }
  522 
  523 function xmlhttp_send(xmlhttp, data) {
  524    var send = "";
  525    xmlhttp.open("POST", "$config->{script_form}", 1)
  526    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8")
  527    xmlhttp.onreadystatechange = post_results
  528    data.R = "$cgi->{R}";
  529    data.xmlhttp = 1; // should be header (needs client.cgi proto changes...)
  530    for(var i in data)
  531      send += i + "=" + escape(data[i]).replace('+', '%2b') + "&"
  532    xmlhttp.send(send)
  533    return false
  534 }
  535 
  536 function post_results() {
  537    if(xmlhttp.readyState < 4)
  538       return
  539 
  540    if(xmlhttp.status != 200) {
  541       var w = window.open()
  542       w.document.write(xmlhttp.responseText)
  543       w.document.close()
  544       return
  545    }
  546 }
  547 .$end
  548 // -->
  549 </script>
  550 <link rel="stylesheet" href="$config->{script_login}?interface=**BROWSER&item=style&style=$cgi->{style}" />
  551 </head>
  552 <body onload="wlistredraw()" onkeydown="formfocus()" onbeforeunload="do_quit()" onunload="do_quit()" class="wlist-body">
  553 <noscript>Scripting is required for this interface</noscript>
  554 <table class="wlist-table">
  555 <tr><td width="1">
  556 <iframe src="$config->{script_login}?interface=**BROWSER&item=blank" id="iframe" width="1" height="1" style="display:none;border:0;" ></iframe>
  557 <script>
  558   var nph_iframe_src = '$config->{script_nph}?$string';
  559   if (navigator.userAgent.match(/(iPad|iPhone);/)) {
  560     // Apple special, iOS 12 appears to have issues with loading several resources at a time.
  561     var wait_counter = [2];
  562     var wait_func = function() {
  563       if (--wait_counter[0] == 0) start_load_process();
  564     };
  565     setTimeout(wait_func, 1000);
  566     document.addEventListener('DOMContentLoaded', wait_func);
  567   } else {
  568     // Don't delay other browsers
  569     start_load_process();
  570   }
  571 
  572   function start_load_process() {
  573     document.getElementById('iframe').src = nph_iframe_src;
  574   }
  575 </script>
  576 
  577 <iframe src="$config->{script_login}?interface=**BROWSER&item=blank" width="1" height="1" style="display:none; border:0; " name="hiddenframe"></iframe>
  578 </td>
  579 <td id="windowlist" class="wlist-container">
  580 </td><td class="wlist-buttons">
  581 <img src="$config->{image_path}/helpup.gif" onclick="if(connected == 0)return;sendcmd('/help');" class="wlist-button" onmousedown="this.src=imghelpdn.src" onmouseup="this.src=imghelpup.src;" onmouseout="this.src=imghelpup.src;" title="Help">
  582 </td><td class="wlist-buttons">
  583 <img src="$config->{image_path}/optionsup.gif" onclick="senditem('options');" class="wlist-button" onmousedown="if(connected == 0)return;this.src=imgoptionsdn.src" onmouseup="this.src=imgoptionsup.src;" onmouseout="this.src=imgoptionsup.src;" title="Options">
  584 </td><td class="wlist-buttons">
  585 <img src="$config->{image_path}/closeup.gif" onclick="if(connected == 0)return;if(currentwindow != 'Status'){sendcmd('/winclose')}else if(confirm('Are you sure you want to quit?')){do_quit();parent.location='$config->{script_login}'}" class="wlist-button" onmousedown="this.src=imgclosedn.src" onmouseup="this.src=imgcloseup.src;" onmouseout="this.src=imgcloseup.src;" title="Close">
  586 </td></tr></table>
  587 
  588 <form name="hsubmit" method="post" action="$config->{script_form}" target="hiddenframe">
  589 <input type="hidden" name="R" value="$cgi->{R}">
  590 <input type="hidden" name="cmd" value="say">
  591 <input type="hidden" name="item" value="say">
  592 <input type="hidden" name="say" value="">
  593 <input type="hidden" name="target" value="">
  594 <input type="hidden" name="name" value="">
  595 <input type="hidden" name="value" value="">
  596 </form>
  597 .$just ie
  598 <span style="display:none" id="sounds"></span>
  599 <script>
  600 function enable_sounds() {
  601    if(document.getElementById('sounds').innerHTML == "")
  602       document.getElementById('sounds').innerHTML = "<embed src='$config->{image_path}/join.wav' hidden='false' loop='false' autostart='false' type='audio/x-wav' id='sound-join'><embed src='$config->{image_path}/actmsg.wav' hidden='false' loop='false' autostart='false' type='audio/x-wav' id='sound-actmsg'>"
  603 }
  604 </script>
  605 .$end
  606 </body></html>
  607 EOF
  608