1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
201
  
202
  
203
  
204
  
205
  
206
  
207
  
208
  
209
  
210
  
211
  
212
  
213
  
214
  
215
  
216
  
217
  
218
  
219
  
220
  
221
  
222
  
223
  
224
  
225
  
226
  
227
  
228
  
229
  
230
  
231
  
232
  
233
  
234
  
235
  
236
  
237
  
238
  
239
  
240
  
241
  
242
  
243
  
244
  
245
  
246
  
247
  
248
  
249
  
250
  
251
  
252
  
// Copyright 2007 - 2009 Roxen Internet Software 
// Contributed by: 
// Digital Fractions 2007 
// www.digitalfractions.net 
 
#include <config_interface.h> 
#include <config.h> 
#include <roxen.h> 
//<locale-token project="roxen_config">_</locale-token> 
#define _(X,Y)        _STR_LOCALE("roxen_config",X,Y) 
 
#define CU_AUTH id->misc->config_user->auth 
 
 
string get_conf_name( string c ) 
{ 
  Configuration cfg = roxen.find_configuration( c ); 
  return cfg->query_name(); 
} 
 
string format_table_owner (mapping(string:string) mod_info, void|int skip_conf) 
{ 
  // Note: Code duplication in browser.pike. 
 
  if ((<0, "">)[mod_info->conf]) return 0; 
 
  Configuration c = roxen.find_configuration( mod_info->conf ); 
  // Make sure that the configuration is enabled. 
  // Otherwise we get spurious "the deleted module XXX in YYY" below. 
  c && c->low_init(); 
  RoxenModule m = c && !(<0, "">)[mod_info->module] && 
    c->find_module( mod_info->module ); 
  ModuleInfo i = 
    !(<0, "">)[mod_info->module] && 
    roxen.find_module( (mod_info->module/"#")[0] ); 
  string mn; 
 
  if (!skip_conf) { 
    if (c) { 
      mn = "<a href='../sites/site.html/" + 
        Roxen.http_encode_url (mod_info->conf) + "/'>" + 
        Roxen.html_encode_string (c->query_name()) + "</a>"; 
    } 
    else 
      mn = Roxen.html_encode_string ( 
        sprintf ((string) _(542, "the deleted site %O"), mod_info->conf)); 
  } 
 
  if( m ) { 
    string module = "<a href='../sites/site.html/"+ 
      Roxen.http_encode_url(mod_info->conf)+"/n!n/"+ 
      replace(mod_info->module,"#","!")+"/"+ 
      "'>"+ Roxen.html_encode_string (i->get_name())+"</a>"; 
    if (mn) 
      mn = sprintf ((string) _(543, "%s in %s"), module, mn); 
    else 
      mn = module; 
  } 
  else if( i ) { 
    if (mn) 
      mn = sprintf ( 
        (string) _(544, "the deleted module %s in %s"), 
        Roxen.html_encode_string (sprintf ("%O", (string) i->get_name())), 
        mn); 
    else 
      mn = sprintf ( 
        (string) _(545, "the deleted module %s"), 
        Roxen.html_encode_string (sprintf ("%O", (string) i->get_name()))); 
  } 
 
  return mn; 
} 
 
string|mapping parse( RequestID id ) 
{ 
  int view_mode; 
  if ( !(CU_AUTH( "Edit Global Variables" )) ) 
    view_mode = 1; 
 
  if( id->variables->db  && !view_mode ) 
  { 
    if( id->variables->set_read ) 
      DBManager.set_permission( id->variables->db, 
                                roxen.find_configuration(id->variables->set_read), 
                                DBManager.READ ); 
    if( id->variables->set_write ) 
      DBManager.set_permission( id->variables->db, 
                                roxen.find_configuration(id->variables->set_write), 
                                DBManager.WRITE ); 
    if( id->variables->set_none ) 
      DBManager.set_permission( id->variables->db, 
                                roxen.find_configuration(id->variables->set_none), 
                                DBManager.NONE ); 
  } 
 
  mapping(string:mapping(string:int)) q = DBManager.get_permission_map( ); 
  if( !sizeof( q ) ) 
    return _(549, "No defined databases.\n"); 
         
  string res = "<style type='text/css'>\n" 
    "#tbl {" 
    " font-size: smaller;" 
    " text-align: left;" 
    " empty-cells: show;" 
    "}\n" 
    "#tbl a {" 
    " color: #0033aa;" 
    " text-decoration: none;" 
    "}\n" 
    "#tbl a:hover {" 
    " color: #0055ff;" 
    " text-decoration: underline;" 
    "}\n" 
    "#tbl tr > * {" // Cell defaults. 
    " padding-left: 1em;" 
    " border-bottom: 1px solid &usr.matrix22;;" 
    "}\n" 
    "#tbl tr > *:first-child {" 
    " white-space: nowrap;" // No wrapping between the table icon and the name. 
    " padding-left: 0;" 
    "}\n" 
    "#tbl .num {" 
    " text-align: right;" 
    " white-space: nowrap;" 
    "}\n" 
    "#tbl tr.group-hdr > * {"       // The cells in the database group name rows. 
    " font-weight: bold;" 
    " border-bottom-color: black;" 
    "}\n" 
    "#tbl tr.column-hdr > * {"      // The cells in the column header rows. 
    " font-weight: bold;" 
    " background-color: &usr.matrix12;;" 
    "}\n" 
    "</style>\n" 
    "<table id='tbl' border='0' cellpadding='2' cellspacing='0'>\n"; 
 
  mapping(string:string) rres = ([]); 
  foreach( DBManager.list_groups(), string g ) 
    rres[g]=""; 
 
  foreach( sort(indices(q)), string db ) 
  { 
    string db_group = DBManager.db_group(db); 
    string db_url = DBManager.db_url( db ); 
 
    string res = 
      "<tr><td class='db'>" + 
      (view_mode ? "" : "<a href='browser.pike?db="+db+"&amp;&usr.set-wiz-id;'>") + 
      "<cimg style='vertical-align: -2px' border='0' format='gif'" 
      " src='&usr.database-small;' alt='' max-height='12'/> " + 
      db + 
      (view_mode ? "" : "</a>") + 
      "</td>"; 
 
    mapping(string:int) db_stats; 
    if ( mixed e = catch { 
        db_stats = DBManager.db_stats( db ) || ([]); 
      } ) { 
      string em = describe_error(e); 
      sscanf( em, "%*sreconnect to SQL-server%s", em); 
      rres[db_group] += res + 
        "<td colspan='4'>" + 
        (db_url ? Roxen.html_encode_string (db_url) + "<br />" : "") + 
        "<font color='&usr.warncolor;'>" + em + "</font></td>" 
        "</tr>\n"; 
      continue; 
    } 
 
    res += "<td class='num'>" + 
      (zero_type (db_stats->tables) ? "" : (string) db_stats->tables) + "</td>" 
      // "<td class='num'>" + 
      // (zero_type (db_stats->rows) ? "" : (string) db_stats->rows) + "</td>" 
      "<td class='num'>" + 
      (zero_type (db_stats->size) ? "" : 
       db_stats->size ? 
       sprintf ("%.1f MiB", db_stats->size / (1024.0 * 1024.0)) : 
       "empty") + "</td>"; 
 
    // Type column 
 
    if( !db_url ) 
      res += "<td>internal</td>"; 
    else 
    { 
      if( mixed err = catch( DBManager.cached_get( db ) ) ) 
        res += "<td><font color='&usr.warncolor;'>" + 
          _(381,"Failed to connect") + ": " + 
          describe_error(err) + "</font></td>"; 
      else 
        res += "<td>remote</td>"; 
    } 
 
    // Backup schedule 
 
    res += "<td>" + (DBManager.db_schedule(db) || 
                     ("<i>" + _(1116, "NONE") + "</i>")) + "</td>"; 
 
    // Owner/info column 
 
    mapping(string:string) db_mod_info = DBManager.module_table_info( db, "" ); 
 
    if (db == "local") 
      res += "<td>" + 
        _(546, "Internal data that cannot be shared between servers.") + 
        "</td>"; 
    else if (db == "shared") 
      res += "<td>" + 
        _(547, "Internal data that may be shared between servers.") + 
        "</td>"; 
    else if (db == "docs") 
      res += "<td>" + _(1024, "Contains all documentation.") + "</td>"; 
    else if (!sizeof (db_mod_info)) 
      res += "<td>" + _(1025, "Unknown database") + "</td>"; 
    else if (string owner = format_table_owner (db_mod_info)) 
      res += "<td>" + String.capitalize (owner) + "</td>"; 
    else 
      res += "<td>" + 
        Roxen.html_encode_string (db_mod_info->comment || "") + "</td>"; 
 
    rres[db_group] += res + "</tr>\n"; 
  } 
 
  array(array(string)) cats = ({}); 
  foreach( indices(rres), string c ) 
    if( c != "internal" ) 
      cats += ({ ({DBManager.get_group(c)->lname, c}) }); 
    else 
      cats = ({ ({DBManager.get_group(c)->lname, c}) }) + cats; 
         
  foreach( cats[0..0]+sort(cats[1..]); int i; array q ) { 
    res += "<tbody>\n" 
      "<tr class='group-hdr'><th colspan='6'>" + (i ? "<br/>" : "") + 
      "<a style='font-size: larger'" 
      " href='edit_group.pike?group=" + q[1] + "&amp;&usr.set-wiz-id;'>" + q[0] + "</a>" 
      "</th></tr>\n" 
      "<tr class='column-hdr'>" 
      "<th>Name</th>" 
      "<th class='num'>Tables</th>" 
      // "<th class='num'>Rows</th>" 
      "<th class='num'>Size</th>" 
      "<th>Type</th>" 
      "<th>Backup Schedule</th>" 
      "<th>Owner/info</th>" 
      "</tr>\n" + 
      rres[ q[1] ] + 
      "</tbody>\n"; 
  } 
 
  return Roxen.http_string_answer(res+"</table>"); 
}