moved for svn-git switch
[mailer.git] / install_svn.php
1 <?php
2 /**
3  ******************************************************************************************************
4  ******************************************************************************************************
5  *** $HeadURL::                                                                                   $ ***
6  *** $Author::                                                                                    $ ***
7  *** $Revision::                                                                                  $ ***
8  *** $Date::                                                                                      $ ***
9  *** $Copyright:: ©2008, Profi-Concept aka Wolfgang Stelzhammer , All rights reserved.            $ ***
10  *** $ License:: The BSD License                                                                  $ ***
11  *** $ Redistribution and use in source and binary forms, with or without modification,           $ ***
12  *** $ are permitted provided that the following conditions are met:                              $ ***
13  *** $                                                                                            $ ***
14  *** $ - Redistributions of source code must retain the above copyright notice,                   $ ***
15  *** $   this list of conditions and the following disclaimer.                                    $ ***
16  *** $ - Redistributions in binary form must reproduce the above copyright notice,                $ ***
17  *** $   this list of conditions and the following disclaimer in the documentation and/or         $ ***
18  *** $   other materials provided with the distribution.                                          $ ***
19  *** $ - Neither the name "Profi-Concept" or "Wolfgang Stelzhammer" nor the names of its          $ ***
20  *** $   contributors may be used to endorse or promote products derived from this software       $ ***
21  *** $   without specific prior written permission.                                               $ ***
22  *** $                                                                                            $ ***
23  *** $ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY        $ ***
24  *** $ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF    $ ***
25  *** $ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL     $ ***
26  *** $ THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,        $ ***
27  *** $ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT   $ ***
28  *** $ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)  $ ***
29  *** $ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,      $ ***
30  *** $ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS      $ ***
31  *** $ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                               $ ***
32  ******************************************************************************************************
33  *** With some XHTML hacks and mcedit ("Cool Edit") improvements by Roland Haeder                   ***
34  ******************************************************************************************************
35  ******************************************************************************************************
36  **/
37 define('SVN_REPO_URL', "http://mxchange.org/repos/mailer/branches/0.2.1-FINAL");
38 //define('SVN_REPO_URL', "file:///E:/Webscripte/MXChange/local_mirror/branches/0.2.1-FINAL");
39 define('SVN_UUID', "");
40
41 ?>
42 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
43  "http://www.w3.org/TR/html4/loose.dtd">
44
45 <html>
46 <head>
47 <title>SVN-Installer --&gt; [Mailer - Mail Exchange] v0.2.1-FINAL</title>
48 <style type="text/css">
49 <!--
50 body {
51         background-color: #EEFFEE;
52         color: #000000;
53         font-family: Verdana, Arial, Geneva, Helvetica, sans-serif;
54         font-size: 12px;
55         letter-spacing: 1px;
56         scrollbar-base-color: #E9E4AE;
57         scrollbar-face-color: #CDEFCD;
58         scrollbar-highlight-color: #EEFFEE;
59         scrollbar-shadow-color: #CDEFCD;
60         scrollbar-3dlight-color: #DDDDDD;
61         scrollbar-arrow-color: #000000;
62         scrollbar-track-color: #CCEFCC;
63         scrollbar-darkshadow-color: #999999;
64         margin: 20px;
65 }
66
67 table {
68         table-layout: auto;
69         border-spacing: 0px;
70         overflow: auto;
71 }
72
73 td {
74         vertical-align: top;
75 }
76
77 A {
78         font-style: normal;
79         font-family: Verdana, Arial, Geneva, Helvetica, sans-serif;
80         text-decoration: none;
81 }
82
83 A:link {
84         color: #2e51a9;
85 }
86
87 A:visited {
88         color: #AA0044;
89 }
90
91 A:active {
92         color: #2e51a9;
93         background-color: transparent;
94 }
95
96 A:hover {
97         background-color: transparent;
98 }
99
100 input,textarea {
101         color: #009900;
102         background-color: #EEFFEE;
103         border: 1px solid #AA0044;
104         text-decoration: none;
105         border-style: groove;
106 }
107
108 select,option {
109         background-color: #EEFFEE;
110         border: solid 1px #009900;
111         color: #AA0044;
112         text-decoration: none;
113         border-style: groove;
114 }
115
116 ul,ol {
117         margin-top: 0px;
118         margin-bottom: 0px;
119 }
120
121 .hl {
122         font-weight: 900;
123 }
124
125 .pos {
126         color: #32cd32;
127         background-color: #fffff0;
128         padding: 10px;
129 }
130
131 .neg {
132         color: #ff0000;
133         background-color: #fffff0;
134         padding: 10px;
135 }
136 -->
137 </style>
138
139
140 </head>
141 <body>
142 <br />
143 <h2>SVN-Installer --&gt; [Mailer - Mail Exchange] v0.2.1-FINAL<br />
144 <span style="font-size: 8pt;">Installer-Version 0.1.1<br />
145 &copy;2008, Profi-Concept aka Wolfgang Stelzhammer , All rights
146 reserved.</span></h2>
147
148 <span class="hl">Pr&uuml;fe SVN-Version: </span>
149 ...
150 <br />
151 <br />
152 <?php
153 function doSetup () {
154         $rev = '';
155         if ((isset($_GET['revision'])) && (!empty($_GET['revision']))) {
156                 $rev = '-r '.$_GET['revision'];
157         } // END - if
158
159
160         switch ($_GET['type']) {
161                 case 'checkout':
162                         $befehl = 'svn checkout '.$rev.$_GET['svn_url'].' '.$_GET['path'];
163                         break;
164                 case 'export':
165                         $befehl = 'svn export --force '.$rev.$_GET['svn_url'].' '.$_GET['path'];
166                         break;
167         } // END - switch
168
169         $ausg = proc_get($befehl);
170         //echo '<pre>$befehl:'.print_r($befehl, true).'</pre>';
171
172         //echo '<pre>$ausg:'.print_r($ausg, true).'</pre>';
173         echo '<p class="hl">F&uuml;hre SVN-'.$_GET['type'].' durch ...</p>';
174
175         if (!isset($_GET['svn_detail']) || $_GET['svn_detail'] != '1') $t[] = $ausg[count($ausg)-1];
176         else $t = $ausg;
177
178
179         ?>
180 <table border="1" cellpadding="5" cellspacing="1"
181         style="margin-left: 20px;">
182         <tr>
183                 <td class="hl">SVN Ausgabe</td>
184                 <td class="pos" style="border: #00000 1px solid;"><?php echo implode("<br />\n",$t) ?></td>
185         </tr>
186 </table>
187 <br />
188 <br />
189         <?php
190
191         $owner = fileowner($_GET['path']);
192         $uid = uniqid();
193         mkdir($_GET['path']. $uid);
194         $nowner = fileowner($_GET['path']. $uid);
195         //$group = filegroup($_GET['path']);
196         rmdir($_GET['path']. $uid);
197
198
199         if ($owner != $nowner) {
200                 //echo '<pre>$owner:'.print_r($owner, true).'</pre>';
201                 //echo '<pre>$nowner:'.print_r($nowner, true).'</pre>';
202                 echo '<span class="hl">Setze Dateirechte, da Webserver-Benuzter von Ordner-Eigent&uuml;ber abweicht ...</span>';
203                 proc_get('chmod -R 0766 '.$_GET['path']);
204                 echo '<span class="pos">Dateirechte auf 0766 gesetzt</span><br /><br />';
205         } // END - if
206
207
208         ?>
209 <span class="pos">SVN-Installation erfolgreich abgeschlossen.</span>
210 <br />
211 <br />
212 <br />
213 <form action="<?php echo $_GET['mailer_url'] . "\"";  ?> method="GET">
214 <div style="margin-left: 20px;"><input type="submit" name="submit"
215         value="Installations-Script von Mailer aufrufen" /></div>
216 </form>
217         <?php
218         return $t;
219 }
220
221 function proc_get ($cmd) {
222
223         $res = popen($cmd, 'r');
224         $buffer = array();
225         while ($res && !feof($res)) {
226                 $t = trim(fgets($res));
227                 if (!empty($t)) {
228                         $buffer[] = t$t;
229                 } // END - if
230                 //echo $t;
231         } // END - while
232         pclose($res);
233         if (count($buffer) <= 0) {
234                 return false;
235         } else {
236                 return $buffer;
237         }
238 }
239
240 $ausg = proc_get('svn --version --quiet');
241
242 if (!$ausg) {
243         echo '<h2 style="text-align:center; padding-top: 10px; padding-bottom: 10px;" class="neg">Fehler: Es konnte kein SVN-Client gefunden werden!<br />
244         Bitte installieren Sie SVN (<a href="http://http://subversion.tigris.org/">http://subversion.tigris.org/</a>).</h2>';
245         exit;
246 } // END - if
247
248 echo '<span class="hl">Installierte SVN Version: </span><span class="pos">'.$ausg[0].'</span><br />';
249 //echo '<pre>$ausg:'.print_r($ausg, true).'</pre>';
250 if (!isset($_GET['step'])) {
251         $step = 1;
252 } else {
253         $step = $_GET['step'];
254 }
255
256 switch ($step) {
257         case '1':
258                 ?>
259 <br />
260 <form action="" method="GET">
261 <div style="margin-left: 20px;"><input type="hidden" name="step"
262         value="2" />
263 <p class="hl">Installations-Parameter</p>
264 <table border="1" cellpadding="5" cellspacing="1">
265         <tr>
266                 <td class="hl" nowrap style="border-bottom: 0px solid;">Setup-Art:</td>
267                 <td colspan="2"><select name="type">
268                         <option value="checkout">checkout (Standard)</option>
269                         <option value="export">export</option>
270                 </select></td>
271         </tr>
272         <tr>
273                 <td style="border-top: 0px solid; border-bottom: 0px solid;"></td>
274                 <td class="hl" nowrap>Chekout:<br />
275                 (Standard)</td>
276                 <td width="400">Bei dieser Option wird ein Working-Direktory erstellt.
277                 Hiermit kann ganz einfach mittels eines SVN-Updates das Script
278                 geupdated werden.</td>
279         </tr>
280         <tr>
281                 <td style="border-top: 0px solid;"></td>
282                 <td class="hl" nowrap>Export:</td>
283                 <td width="400">Hier wird nur ein &quot;einfacher&quot; Export
284                 ausgef&uuml;hrt und keine Versions-Information gespeichert.</td>
285         </tr>
286         <tr>
287                 <td class="hl" nowrap style="border-bottom: 0px solid;">Setup-Verzeichnis:</td>
288                 <td colspan="2"><input size="80" maxlength="254" type="text"
289                         name="path"
290                         value="<?php echo str_replace("\\", '/', dirname(__FILE__)) . "/\"";  ?> /></td>
291 </tr>
292 <tr>
293         <td style="border-top: 0px solid;"></td>
294         <td class="hl" nowrap>Absoluter Pfad:</td>
295         <td width="400">Standardm&auml;&szlig;ig ist hier der Pfad des Scriptes angegeben. Ein nicht vorhandenes Verzeichniss wird erstellt.</td>
296 </tr>
297 <tr>
298         <td class="hl" nowrap style="border-bottom: 0px solid;">Mailer-URL:</td>
299         <td colspan="2"><input size="80" maxlength="254" type="text" name="mailer_url" value="<?php echo 'http://' . getenv('SERVER_NAME') . str_replace("\\", '/', dirname($_SERVER['PHP_SELF']))."/\"";  ?> /></td>
300 </tr>
301 <tr>
302         <td style="border-top: 0px solid;"></td>
303         <td class="hl" nowrap>Mailer-URL:</td>
304         <td width="400">Dies ist die URL von wo aus der Mailer aufgerufen werden kann. Standardm&auml;&szlig;ig ist hier die URL des Scriptes angegeben.</td>
305 </tr>
306 <tr>
307         <td class="hl" nowrap style="border-bottom: 0px solid;">SVN-Repository:</td>
308         <td colspan="2"><input size="80" maxlength="254" type="text" name="svn_url" value="<?php echo constant('SVN_REPO_URL') . "\"";  ?> /></td>
309 </tr>
310 <tr>
311         <td style="border-top: 0px solid;"></td>
312         <td class="hl" nowrap>SVN-Server-URL:</td>
313         <td width="400">URL zum SVN-Server von [Mailer - Mail Exchange] v0.2.1-FINAL. Standard-URL ist hier <span class="hl"><?php echo constant('SVN_REPO_URL');  ?></span>. Bitte nur &auml;ndern, wenn Sie einen lokalen SVN-Mirror erstellt haben oder eine andere Version von Mailer-Project installieren m&ouml;chten.</td>
314 </tr>
315 <tr>
316         <td class="hl" nowrap style="border-bottom: 0px solid;">Optionen:</td>
317         <td colspan="2" class="hl">
318                 Head-Revision: <input type="checkbox" name="head_revision" value="1" checked="checked"><br />
319                 SVN Detail-Ausgabe: <input type="checkbox" name="svn_detail" value="1">
320 </tr>
321 <tr>
322         <td style="border-top: 0px solid;border-bottom: 0px solid;"></td>
323         <td class="hl" nowrap>Head-Revision:</td>
324         <td width="400">Wird diese Option gew&auml;hlt, so wird automatisch die HEAD-Revision verwendet. Sonst kann in einem weiteren Schritt eine entsprechende Revision ausgew&auml;hlt werden.</td>
325 </tr>
326 <tr>
327         <td style="border-top: 0px solid;"></td>
328         <td class="hl" nowrap>SVN Detail-Ausgabe:</td>
329         <td width="400">Aktiviert zeigt es s&auml;mtliche SVN-Detail-Ausgaben an. Sollte nur zum Debuggen aktiviert werden.</td>
330 </tr>
331
332 </table>
333 <br />
334 <input type="submit" name="submit" value="Setup fortsetzen">
335
336 </div>
337 </form>
338 <?php
339         break;
340         case '2':
341                 if (!preg_match('@(.*)/$@',$_GET['path'],$match)) {
342                         $_GET['path'] = $_GET['path'].'/';
343                         //echo '<pre>$_GET:'.print_r($_GET, true).'</pre>';
344                 } // END - if
345                 //echo '<pre>$_GET:'.print_r($_GET, true).'</pre>';
346 ?>
347 <br />
348 <span class="hl">Pr&uuml;fe Setup-Verzeichniss <?php echo $_GET['path']; ?> ...<br /><br />
349 <?php
350 $t = uniqid();
351 $erg = @mkdir($_GET['path']. $t.'/');
352 if (file_exists($_GET['path']) && $erg) {
353         echo $_GET['path'].'</span><span class="pos">vorhanden und beschreibar</span>';
354         rmdir($_GET['path']. $t.'/');
355 } elseif(file_exists($_GET['path']) && !$erg) {
356         echo '<span class="hl">'.$_GET['path'].' </span>';
357         echo '<span class="neg">Fehler</span><br /><br />';
358         echo '<h2 style="text-align:center; padding-top: 10px; padding-bottom: 10px;" class="neg">Fehler: Das Verzeichniss<br />'.$_GET['path'].'<br />hat Nicht gen&uuml;gende Schreibrechte.';
359         exit;
360
361 } elseif (!file_exists($_GET['path'])) {
362         //echo '<span class="neg">nicht vorhanden</span><br /><br />';
363         $t = explode('/',$_GET['path']);
364         //echo '<pre>$t:'.print_r($t, true).'</pre>';
365         $dir = '';
366         foreach($t as $last) {
367                 if (!empty($last)) {
368                         $tdir = $dir;
369                         $dir .= $last.'/';
370
371                         //echo '<pre>fileperms($tdir):'.print_r(fileperms($tdir), true).'</pre>';
372                         //echo '<pre>fileperms($dir):'.print_r(fileperms($dir), true).'</pre>';
373
374
375                         //echo '<pre>$dir:'.print_r($dir, true).'</pre>';
376
377                         if (!file_exists($dir)) {
378                                 $erg = @mkdir($dir);
379                                 if (!$erg) {
380                                         echo '<span class="hl">'.$dir.' </span>';
381                                         echo '<span class="neg">Fehler</span><br /><br />';
382                                         echo '<h2 style="text-align:center; padding-top: 10px; padding-bottom: 10px;" class="neg">Fehler: Das Verzeichniss<br />'.$tdir.'<br />hat Nicht gen&uuml;gende Schreibrechte.';
383                                         exit;
384                                 } else {
385                                         echo '<span class="hl">'.$dir.' </span>';
386                                         echo '<span class="pos">erstellt</span><br /><br />';
387                                 }
388                         }
389                 } // END - if
390         } // END - foreach
391 }
392 echo '<p class="hl">Pr&uuml;fe SVN-Server '.$_GET['svn_url']. ' ...</p>';
393 echo '<span class="hl">'.$_GET['svn_url'].' </span>';
394
395 $svn_server_readable = proc_get('svn info '.$_GET['svn_url'].'');
396 $svn_server = proc_get('svn info --xml '.$_GET['svn_url'].'');
397
398 if (!$svn_server_readable) {
399         echo '<span class="neg">Fehler</span><br />';
400         echo '<h2 style="text-align:center; padding-top: 10px; padding-bottom: 10px;" class="neg">Fehler: Kann den SVN-Server<br />'.$_GET['svn_url'].'<br />nicht erreichen.';
401         exit;
402 } // END - if
403
404 $svn_ausg = implode('<br />',$svn_server_readable);
405 $svn_server = implode("\n",$svn_server);
406 ?>
407 <span class="pos">erreichbar</span><br /><br />
408 <table border="1" cellpadding="5" cellspacing="1" style="margin-left: 20px;">
409 <tr>
410         <td class="hl">SVN Informationen</td>
411         <td class="pos" style="border: #00000 1px solid;"><?php echo $svn_ausg ?></td>
412 </tr>
413 </table>
414 <?php
415 if (!isset($_GET['head_revision']) || $_GET['head_revision'] != '1') {
416 ?>
417 <br />
418 <form action="" method="GET">
419 <div style="margin-left: 20px;">
420 <input type="hidden" name="step" value="3" />
421 <input type="hidden" name="past" value="<?php echo urlencode(serialize($_GET))."\""; ?> />
422 <table border="1" cellpadding="5" cellspacing="1">
423 <tr>
424         <td class="hl" nowrap style="border-bottom: 0px solid;">Revision:</td>
425         <td colspan="2"><input size="10" maxlength="10" type="text" name="revision" value="<?php
426 //echo '<pre>$svn_server:<textarea cols="80" rows="20" name="fgsgfsdg">'.print_r($svn_server, true).'</textarea></pre>';
427
428
429 $xml = new SimpleXMLElement($svn_server);
430 //echo '<pre>$xml:'.print_r($xml, true).'</pre>';
431 $t = $xml->entry[0]->commit[0]['revision'];
432 echo $t."\"";
433 ?>></td>
434
435 </tr>
436 <tr>
437         <td style="border-top: 0px solid;"></td>
438         <td class="hl" nowrap>Revision:</td>
439         <td width="400">Revision von [Mailer-Project - Mail Exchange] v0.2.1-FINAL die installiert werden soll. Nach m&ouml;glichkeit immer die HEAD-Revison benutzen um alle Updates bereits includiert zu erhalten.</td>
440 </tr>
441 </table>
442 <br />
443 <input type="submit" name="submit" value="Setup fortsetzen">
444
445 </div>
446 </form>
447 <?php
448 } else {
449         $ausg = doSetup();
450 }
451         break;
452
453         case '3':
454                 $t = unserialize(urldecode($_GET['past']));
455                 unset($_GET['past']);
456                 $_GET = array_merge($t, $_GET);
457                 echo '<p class="hl">Pr&uuml;fe SVN-Server '.$_GET['svn_url']. ' ...</p>';
458                 echo '<span class="hl">'.$_GET['svn_url'].' </span>';
459
460                 $svn_server_readable = proc_get('svn info '.$_GET['svn_url'].'');
461                 $svn_server = proc_get('svn info --xml '.$_GET['svn_url'].'');
462                 if (!$svn_server_readable) {
463                         echo '<span class="neg">Fehler</span><br />';
464                         echo '<h2 style="text-align:center; padding-top: 10px; padding-bottom: 10px;" class="neg">Fehler: Kann den SVN-Server<br />'.$_GET['svn_url'].'<br />nicht erreichen.';
465                         exit;
466                 } // END - if
467                 $svn_ausg = implode('<br />',$svn_server_readable);
468                 $svn_server = implode("\n",$svn_server);
469 ?>
470 <span class="pos">erreichbar</span><br /><br />
471 <table border="1" cellpadding="5" cellspacing="1" style="margin-left: 20px;">
472 <tr>
473         <td class="hl">SVN Informationen</td>
474         <td class="pos" style="border: #00000 1px solid;"><?php echo $svn_ausg ?></td>
475 </tr>
476 </table>
477 <?php
478                         $ausg = doSetup();
479                         break;
480 } // END - switch
481 ?>
482 </body>
483 </html>