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
  
#include <roxen.h> 
 
//<locale-token project="admin_tasks">_</locale-token> 
#define _(X,Y)  _DEF_LOCALE("admin_tasks",X,Y) 
 
constant action = "maintenance"; 
 
LocaleString name = _(46,"Change Roxen version")+"..."; 
LocaleString doc =  _(42,"If you have more than one Roxen version installed\n" 
                     "in the same location, you can use this action to\n" 
                     "change the currently running version."); 
 
class Server(string dir, 
             string version, 
             string version_h ) 
{ 
  Calendar.Day reldate() 
  { 
    Stdio.Stat st = file_stat("../" + dir + "/VERSION.DIST"); 
    return st && Calendar.Day("unix", st->mtime); 
  } 
 
  protected string _sprintf() 
  { 
    return sprintf("Server(%O,%O,%O)", dir,version, reldate() ); 
  } 
} 
 
array available_versions() 
{ 
  array res = ({}); 
  foreach( glob("server*",get_dir( ".." )), string f ) 
  { 
    if( file_stat( "../"+f+"/etc/include/version.h" ) ) 
    { 
      catch { 
        string s = Stdio.read_file( "../"+f+"/etc/include/version.h" ); 
        string a, b; 
        sscanf( s, "%*sroxen_ver%*s\"%s\"", a ); 
        sscanf( s, "%*sroxen_build%*s\"%s\"", b ); 
        if( a && b ) 
          res += ({ Server( f, a+"."+b,s ) }); 
      }; 
    } 
  } 
  return res; 
} 
 
string nice_relative_date( object t ) 
{ 
  if (!t) 
    return "n/a"; 
  if( t->how_many( Calendar.Month() ) ) 
    if( t->how_many( Calendar.Month() ) == 1 ) 
      return sprintf( (string)_(43,"1 month") ); 
    else 
      return sprintf( (string)_(44,"%d months"), 
                      t->how_many( Calendar.Month() ) ); 
  if( t->how_many( Calendar.Day() ) == 1 )    return (string)_(139,"one day"); 
 
  if( t->how_many( Calendar.Day() ) == 0 )    return "-"; 
  return sprintf( (string)_(45,"%d days"), 
                  t->how_many( Calendar.Day() ) ); 
} 
 
string parse( RequestID id ) 
{ 
  string res = 
    "<h2 class='no-margin-top'>"+_(46,"Change Roxen version")+"</h2>\n" 
    "<p>"; 
 
  if( id->variables->server ) 
  { 
    werror("Change to "+id->variables->server+"\n" ); 
    mv("../local/environment", "../local/environment~"); 
    Stdio.write_file( combine_path(roxen.configuration_dir, 
                                   "server_version"), 
                      id->variables->server ); 
       roxen->shutdown(0.5); 
    return (string)_(47,"Shutting down and changing Roxen version"); 
  } 
 
  res += "<input type=hidden name='action' value='change_version.pike' />"; 
 
  res += 
    "<table class='nice'>" 
    "<thead>" 
    "<tr>" 
    "<th></th>" 
    "<th>"+_(48,"Version")+"</th>" 
    "<th></th>" 
    "<th>"+_(85,"Release date")+"</th>" 
    "<th>"+_(86,"Age")+"</th>" 
    "<th>"+_(136,"Directory")+"</th>" 
    "</tr>" 
    "</thead>"; 
  foreach( available_versions(), Server f ) 
  { 
    res += "<tr><td>"; 
    if( f->version != roxen.roxen_ver+"."+roxen.roxen_build ) 
      res += "<input type='radio' name='server' value='"+f->dir+"' /> "; 
    else 
      res += ""; 
    res += "</td>"; 
 
    Calendar.Day d = f->reldate(); 
    Calendar.Day diff = d && d->distance( Calendar.now() ); 
 
    res += 
      "<td>"+f->version+"</td>" 
      "<td>"+(f->cannot_change_back?"<div class='notify warn inline'>&nbsp;</div>":"")+ 
      "</td>" 
      "<td>"+(d ? d->set_language( roxen.get_locale()+"_UNICODE" ) 
              ->format_ext_ymd() : "n/a")+ 
      "</td>" 
      "<td>"+nice_relative_date( diff )+"</td>" 
      "<td>"+f->dir+"</td></tr>\n"; 
  } 
  res += 
    "</table>\n"; 
 
  if( warn ) 
    res += "<p class='notify warn inline'>" + 
      sprintf((string) 
      _(137,"If you change to one these Roxen versions, you will not be " 
        "able to change back from the administration interface, you will " 
        "instead have to edit the file %O manually, shutdown the server, " 
        "and execute %O again"), 
              combine_path(getcwd(), 
                           roxen.configuration_dir, 
                           "server_version"), 
              combine_path(getcwd(),"../start") ) 
      +"</p>"; 
 
  res += 
    "<p class='notify warn inline'>" + 
    _(154,"Note that you will have to start the new server manually because " 
    "you may have to answer a few questions for the new environment file.")+ 
    "</p>"; 
 
  res += "<p><submit-gbutton>"+_(138,"Change version")+"</submit-gbutton> " 
    "<cf-cancel href='./?class="+action+"&amp;&usr.set-wiz-id;'/></p>"; 
 
  return res; 
}