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
  
#include <config_interface.h> 
#include <roxen.h> 
 
//<locale-token project="roxen_config">LOCALE</locale-token> 
#define LOCALE(X,Y)     _DEF_LOCALE("roxen_config",X,Y) 
 
 
void get_dead( string cfg, int del ) 
{ 
}; 
 
constant tmpl = #" 
<use file='/template' /> 
<tmpl title='{{ title }}'> 
  <topmenu base='&cf.num-dotdots;' selected='sites'/> 
  <content><cv-split> 
    <subtablist> 
      <st-tabs></st-tabs> 
      <st-page> 
        <div class='notify warn'><b>{{ warning }}</b></div> 
      </st-page> 
    </subtablist> 
  </cv-split></content> 
</tmpl> 
"; 
 
string|mapping parse( RequestID id ) 
{ 
  if (!config_perm("Create Site")) { 
    return LOCALE(226, "Permission denied"); 
  } 
 
  if (!id->variables->site) { 
    return Roxen.http_redirect("/sites/", id); 
  } 
 
  Configuration cf = roxen->find_configuration(id->variables->site); 
 
  if (!cf) { 
    return "No such configuration: "+id->variables->site; 
  } 
 
  if (!id->variables["really.x"]) { 
    mapping mctx = ([ 
      "site"        : Roxen.html_encode_string(id->variables->site), 
      "title"       : LOCALE(249,"Drop old site"), 
      "warning"     : sprintf( 
                        (string)LOCALE(235,"Are you sure you want to disable " 
                                           "the site %s?"), 
                        cf->query_name()||""), 
      "ports_msg"   : LOCALE(468,"This site listens to the following ports:"), 
      "drop_db_msg" : LOCALE(469,"Databases that will no longer be used"), 
      "urls"        : ({}), 
      "dbs"         : ({}) 
    ]); 
 
    string res = 
      "<use file='/template' />\n" 
      "<tmpl title=' "+ LOCALE(249,"Drop old site") +"'>" 
      "<topmenu base='&cf.num-dotdots;' selected='sites'/>\n" 
      "<content><cv-split>" 
      "<subtablist width='100%'>" 
      "<st-tabs></st-tabs>" 
      "<st-page><div class='notify warn'><b>"+ 
      sprintf((string)(LOCALE(235,"Are you sure you want to disable the site %s?")+"\n"), 
               (cf->query_name()||""))+ 
      "</b></div>"; 
 
    // 1: Find databases that will be "dead" when this site is gone. 
    mapping q = DBManager.get_permission_map(); 
    array dead = ({}); 
 
    foreach (sort(indices(q)), string db) { 
      int ok; 
      foreach (indices(q[db]), string c) { 
        foreach ((roxen->configurations - ({ cf }))->name, string c) { 
          if (q[db][c] != DBManager.NONE) { 
            ok=1; 
            break; 
          } 
        } 
      } 
 
      if (!ok) { 
        dead += ({ db }); 
      } 
    } 
 
    // Never ever drop these. 
    dead -= ({ "roxen", "mysql", "local", "replicate" }); 
 
    res += "<b>"+ 
      LOCALE(468,"This site listens to the following ports:")+"</b><br />\n"; 
 
    res += "<ul>\n"; 
 
    foreach (cf->query("URLs"), string url) { 
      url = (url/"#")[0]; 
#if constant(gethostname) 
      res += "<li> "+replace(url,"*",gethostname())+"\n"; 
      url = replace(url, "*", gethostname()); 
#else 
      res += "<li> "+url+"\n"; 
#endif 
      mctx->urls += ({ url }); 
    } 
 
    res += "</ul\n>"; 
 
    if (sizeof(dead)) { 
      res += "<b>"+LOCALE(469,"Databases that will no longer be used")+ 
        "</b><br />"; 
 
      res += "<blockquote>"; 
 
      if (sizeof(dead) == 1) 
        res += LOCALE(470,"If you do not want to delete this database, " 
                      "uncheck the checkmark in front of it"); 
      else { 
        res += "<p>" + 
          LOCALE(471,"If you do not want to delete one or more of these " 
                 "databases, uncheck the checkmark in front of the ones" 
                 " you want to keep.") + 
          #"</p> 
          <p><button id='check_all_button' data-toggle-checkboxes='checkbox_list'>" + 
          LOCALE(1065, "Uncheck/Check All") + 
          "</button></p>\n"; 
      } 
      res += "<ul id='checkbox_list'>"; 
      int n; 
      foreach (dead, string d) { 
        mctx->dbs += ({ d }); 
        res += "<li style='list-style-image: none; list-style-type: none'>" 
          "<input name='del_db_"+d+"' id='del_db_"+d+"' type=checkbox checked=checked />" 
          "<label for='del_db_"+d+"'>"+d+"</label></li>\n"; 
      } 
      res += "</ul>"; 
      res += "</blockquote>"; 
    } 
    // 2: Tables 
 
 
    res += ("<input type=hidden name=site value='"+ 
            Roxen.html_encode_string(id->variables->site)+"' />"); 
 
    res += 
      "<hr><p><submit-gbutton2 name='really'> "+ 
      LOCALE(249,"Drop old site") + 
      " </submit-gbutton2> " 
      "<cf-cancel href='./'/>"; 
 
    TRACE("ctx: %O\n", mctx); 
 
    return res + 
      "</st-page></subtablist></td></tr></table>" 
      "</cv-split></content></tmpl>"; 
  } 
 
 
  report_notice(LOCALE(255, "Disabling old configuration %s")+"\n", 
                cf->name); 
 
  foreach( glob("del_db_*", indices(id->variables)), string d ) { 
    d = d[7..]; 
    DBManager.drop_db( d ); 
  } 
  string cfname = roxen.configuration_dir + "/" + cf->name; 
  mv (cfname, cfname + "~"); 
  roxen->remove_configuration( cf->name ); 
  cf->stop(); 
  destruct( cf ); 
 
  return Roxen.http_redirect( "/sites/", id ); 
}