Changeset 932

Show
Ignore:
Timestamp:
10/09/07 21:20:45 (1 year ago)
Author:
arc
Message:

2007-10-09 Alberto Ruiz <aruiz@gnome.org>

  • server.py, admin.py: initial support for virtual server settings editing,
    patch from Dave Anderson <cherokee@davious.org>.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • cherokee-admin/trunk/admin.html

    r929 r932  
    22<head> 
    33<link rel="stylesheet" type="text/css" href="js/resources/css/ext-all.css" /> 
    4 </head> 
    5 <body> 
    64<script text="text/javascript" src="js/adapter/ext/ext-base.js"></script> 
    75<script text="text/javascript" src="js/ext-all.js"></script> 
    86<script type="text/javascript" src="admin.js"></script> 
     7<style> 
     8  .section { padding: 0 0 0 1em; } 
     9</style> 
     10</head> 
     11<body> 
     12 
    913<div id="vserver-list" style="width: 180px;"></div> 
    1014<div id="vserver-options"></div> 
  • cherokee-admin/trunk/admin.js

    r929 r932  
     1/* 
     2ConfigObject : 
     3{ 'simple value key' : 'simple value' 
     4, 'just child values key' : ConfigObject 
     5, 'value + child values key' : [ 'simple value', ConfigObject ] 
     6} 
     7*/ 
     8 
     9// main call for turning configNodes into form objects 
     10function formDisplayResponse(container, response) { 
     11  container.innerHTML = ""; 
     12  var configObject = Ext.util.JSON.decode(response.responseText); 
     13  var configObjectDom = configObjectToDom(configObject); 
     14  container.appendChild(configObjectDom); 
     15} 
     16 
     17// top call, recursable call for turning configObjects 
     18// into form fields 
     19function configObjectToDom(configObject, depth) { 
     20 
     21  // contain fields in a section 
     22  var div = document.createElement("div"); 
     23  div.className = "section"; 
     24 
     25  // first collect keys by type... simple and complex 
     26  var simpleKeys = []; 
     27  var complexKeys = []; 
     28  for(var entry in configObject) { 
     29    var value = configObject[entry]; 
     30    if(typeof(value) == "string") { 
     31      simpleKeys[simpleKeys.length] = entry; 
     32    } else { 
     33      complexKeys[complexKeys.length] = entry; 
     34    } 
     35  } 
     36 
     37  // first display simple key value pairs, sorted alphabetically 
     38  simpleKeys.sort(); 
     39  for(var i = 0; i < simpleKeys.length; i++) { 
     40    var key = simpleKeys[i]; 
     41    var node = toFormField(key, configObject[key]); 
     42    div.appendChild(node); 
     43  } 
     44 
     45  // now display move complex information sections, sorted alphabetically 
     46  if(!depth) depth = 1; 
     47  complexKeys.sort(); 
     48  for(var i = 0; i < complexKeys.length; i++) { 
     49    var key = complexKeys[i]; 
     50     
     51    // toSection will recurse back this function when child information is complex 
     52    var node = toSection(key, configObject[key], depth); 
     53    div.appendChild(node); 
     54  } 
     55 
     56  return div; 
     57} 
     58 
     59// given key and value, return a div with a label and an imput box 
     60// TODO: add a name to assocate with it 
     61function toFormField(key, value) { 
     62  var div = document.createElement("div"); 
     63  div.className = "entry"; 
     64  var label = document.createElement("label"); 
     65  label.appendChild(document.createTextNode(key + ": ")); 
     66  var input = toInput(value); 
     67  label.appendChild(input); 
     68  div.appendChild(label); 
     69  return div; 
     70} 
     71 
     72// given a value, return an imput object 
     73// length adjusted based on current value 
     74// TODO: add a name to assocate with it 
     75function toInput(value) { 
     76  var input = document.createElement("input"); 
     77  input.value = value; 
     78  input.size = value.length; 
     79  return input; 
     80} 
     81 
     82// give a key, complexConfigObject, and depth 
     83// return a header  
     84// followed (ala configObjectToDom) by key/value inputs, then more complex sections 
     85function toSection(key, complexConfigObject, depth) { 
     86  var div = document.createElement("div"); 
     87  var hNumber = Math.min(depth, 6); // limit h tags to h6 
     88  var h = document.createElement("h" + hNumber); 
     89  h.appendChild(document.createTextNode(key)); 
     90  var kids = complexConfigObject; 
     91  if(complexConfigObject.length) { 
     92    // this is an array... [value, kids] 
     93    value = complexConfigObject[0]; 
     94    var input = toInput(value); 
     95    h.appendChild(document.createTextNode(" ")); 
     96    h.appendChild(input); 
     97    kids = complexConfigObject[1]; 
     98  } 
     99  var innerSection = configObjectToDom(kids, depth + 1); 
     100 
     101  div.appendChild(h); 
     102  div.appendChild(innerSection); 
     103  return div; 
     104} 
     105 
     106// just show us the JSON 
     107function simpleDisplayResponse(container, response) { 
     108  container.innerHTML = response.responseText; 
     109} 
     110 
     111// swith between JSON display and form field display 
     112//var processResponse = simpleDisplayResponse; 
     113var processResponse = formDisplayResponse; 
     114 
    1115Ext.onReady(function () { 
    2116 
     
    4118                function onSuccess (response) { 
    5119                        var targetElement = document.getElementById("vserver-options"); 
    6                         targetElement.innerHTML = response.responseText; 
    7                          
     120      // display config options for selected vserver 
     121                        processResponse(targetElement, response);                       
    8122                } 
    9123                var connection = new Ext.data.Connection(); 
  • cherokee-admin/trunk/run_admin.sh

    r926 r932  
    22 
    33CHEROKEE_06=/usr/local/sbin/cherokee 
     4echo "SCGI service running at port 4000                 [ OK ]" 
     5echo "Cherokee administrator instance up and running at http://localhost:8080/admin" 
    46$CHEROKEE_06 -C admin_server.conf | ./server.py 
    5  
    6 #sleep 2 
    7 #while [ 1 ] 
    8 #do 
    9 #       echo "### Server started, to stop it, press q and enter ###" 
    10 #       read input 
    11 #       if $input == "q" 
    12 #       then 
    13 #               jobs -p | xargs kill -9  
    14 #       fi 
    15 #done 
  • cherokee-admin/trunk/server.py

    r929 r932  
    7272            
    7373        if config_node: 
    74             self._return_node_as_json(config_node) 
     74            self._node_as_json(config_node) 
    7575     
    7676    def _admin_request(self, request_uri): 
     
    103103 
    104104 
    105  
    106105    def _return_vserver_treeview(self, config_node): 
    107106        """JSON formatted EXT JS vserver treeview response.""" 
     
    122121         
    123122        self.wfile.write("]") 
    124              
     123 
     124    def _node_as_json(self, config_node): 
     125        """Recursive JSON formatted response 
     126  
     127ConfigObject : 
     128{ 'simple value key' : 'simple value' 
     129, 'just child values key' : ConfigObject 
     130, 'value + child values key' : [ 'simple value', ConfigObject ] 
     131
     132        """ 
     133        children = [] 
     134        for child in config_node: 
     135            children.append(child) 
     136        children.sort() 
     137 
     138        if not children: 
     139            value = config_node.value or "" 
     140            self.wfile.write('"%s"' % value) 
     141 
     142        else: 
     143            if config_node.value: 
     144                self.wfile.write('[ "%s" ,' % config_node.value) 
     145 
     146            self.wfile.write('{ ') 
     147 
     148            comma = "" 
     149            for child in children: 
     150                self.wfile.write('%s"%s" : ' % (comma, child)) 
     151                comma = ", " 
     152                self._node_as_json(config_node[child]) 
     153              
     154            self.wfile.write(' }') 
     155 
     156            if config_node.value: 
     157                self.wfile.write(' ]')    
    125158 
    126159    def _return_node_as_json(self, config_node):