Webapp-Installer, erste Version die funktioniert
bernd

bernd commited on 2009-02-28 12:14:27
Zeige 8 geänderte Dateien mit 398 Einfügungen und 3 Löschungen.


git-svn-id: https://svn.schokokeks.org/repos/tools/webinterface/trunk@1276 87cf0b9e-d624-0410-a070-f6ee81989793
... ...
@@ -18,5 +18,5 @@ RewriteRule ^go/(.*)$  dispatch.php?go=$1&%{QUERY_STRING}
18 18
 </IfModule>
19 19
 
20 20
 # allow client certs
21
-#SSLVerifyClient optional_no_ca
22
-#SSLoptions +StdEnvVars +ExportCertData
21
+SSLVerifyClient optional_no_ca
22
+SSLoptions +StdEnvVars +ExportCertData
... ...
@@ -61,7 +61,7 @@ $output = "";
61 61
 $html_header = "";
62 62
 require_once("inc/base.php");
63 63
 /* setup module include path */
64
-ini_set('include_path',ini_get('include_path').':./modules/'.dirname($go).'/include:');
64
+ini_set('include_path',ini_get('include_path').':./modules/'.$module.'/include:');
65 65
 
66 66
 /* Look where we are (but let the module override) */
67 67
 $section = str_replace("/", "_", $go);
... ...
@@ -0,0 +1,35 @@
1
+<?php
2
+
3
+require_once('inc/debug.php');
4
+
5
+require_once('webapp-installer.php');
6
+
7
+
8
+function validate_data($post)
9
+{
10
+  DEBUG('Validating Data:');
11
+  DEBUG($post);
12
+  $fields = array('adminuser', 'adminpassword', 'adminemail', 'wikiname', 'dbhandle');
13
+  foreach ($fields AS $field)
14
+    if ((! isset($post[$field])) || $post[$field] == '')
15
+      system_failure('Nicht alle Werte angegeben ('.$field.')');
16
+
17
+  $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
18
+  $dbname = $username.'_'.$post['dbhandle'];
19
+  $dbpassword = create_webapp_mysqldb($post['dbhandle']);
20
+
21
+  $salt = random_string(8);
22
+  $salthash = ':B:' . $salt . ':' . md5( $salt . '-' . md5( $post['adminpassword'] ));
23
+  
24
+  $data = "adminuser={$post['adminuser']}
25
+adminpassword={$salthash}
26
+adminemail={$post['adminemail']}
27
+wikiname={$post['wikiname']}
28
+dbname={$dbname}
29
+dbuser={$dbname}
30
+dbpass={$dbpassword}";
31
+  DEBUG($data);
32
+  return $data;
33
+}
34
+
35
+
... ...
@@ -0,0 +1,44 @@
1
+<?php
2
+
3
+require_once('inc/base.php');
4
+
5
+function create_new_webapp($appname, $directory, $url, $data)
6
+{
7
+  $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
8
+  $appname = mysql_real_escape_string($appname);
9
+  $directory = mysql_real_escape_string($directory);
10
+  $url = mysql_real_escape_string($url);
11
+  $data = mysql_real_escape_string($data);
12
+  db_query("INSERT INTO vhosts.webapp_installer VALUES (NULL, '{$appname}', '{$directory}', '{$url}', 'new', '{$username}', '{$data}')");
13
+}
14
+
15
+
16
+function create_webapp_mysqldb($handle)
17
+{
18
+  // dependet auf das mysql-modul
19
+  require_once('modules/mysql/include/mysql.php'); 
20
+  
21
+  $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
22
+  if ($handle == '')
23
+    input_error('Kein Datenbank-Handle angegeben');
24
+  $handle = $username.'_'.$handle;
25
+  
26
+  if (! validate_mysql_username($handle))
27
+  {
28
+    system_failure('Ungültiges MySQL-Handle');
29
+  }
30
+
31
+  if (has_mysql_user($handle) || has_mysql_database($handle))
32
+  {
33
+    system_failure('Eine Datenbank oder einen Datenbank-Benutzer mit diesem Namen gibt es bereits!');
34
+  }
35
+
36
+  create_mysql_database($handle);
37
+  create_mysql_account($handle);
38
+  set_mysql_access($handle, $handle, true);
39
+  $password = random_string(10);
40
+  set_mysql_password($handle, $password);
41
+  return $password; 
42
+}
43
+
44
+
... ...
@@ -0,0 +1,81 @@
1
+<?php
2
+
3
+require_once('inc/base.php');
4
+require_once('session/start.php');
5
+
6
+require_once('modules/vhosts/include/vhosts.php');
7
+
8
+require_role(ROLE_SYSTEMUSER);
9
+
10
+$title = 'Web-Anwendung einrichten';
11
+
12
+output('<h2>Web-Anwendung installieren</h2>
13
+
14
+<p>Richten Sie hiermit unkompliziert eine neue Web-Anwendung ein. Sie können dafür entweder eine vorhandene Domain bzw. Subdomain benutzen oder eine neue anlegen.</p>
15
+<p>Wählen Sie bitte auf dieser Seite aus, welche Anwendung Sie installieren möchten und unter welcher Domain/Subdomain dies geschehen soll. Nach dieser Seite werden noch ein paar Details zur betreffenden Anwendung erfasst.</p>
16
+');
17
+
18
+
19
+$form = '<h4>Anwendung auswählen</h4>
20
+<div style="margin-left: 2em;">
21
+  <p><input checked="checked" type="radio" name="application" id="application_mediawiki" value="mediawiki" /> <label for="application_mediawiki">MediaWiki</label></p>
22
+  <p style="margin-left: 2em;">MediaWiki ist eine Wiki-Software, mit der Seiteninhalte von Besuchern geändert werden können. MediaWiki ist u.A. die Grundlage der Online-Enzyklopädie »Wikipedia«.</p>
23
+</div>
24
+';
25
+
26
+$form .= '<h4>Installationsort:</h4>
27
+<div style="margin-left: 2em;">
28
+  <p><input type="radio" name="target" value="new" id="radio_new" checked="checked" />&#160;<label for="radio_new">Neue Domain/Subdomain erstellen</label></p>
29
+<div style="margin-left: 2em;">
30
+<h5>Name</h5>
31
+';
32
+$form .= "<div style=\"margin-left: 2em;\"><input type=\"text\" name=\"hostname\" id=\"hostname\" size=\"10\" value=\"{$vhost['hostname']}\" onkeyup=\"document.getElementById('radio_new').checked=true\" /><strong>.</strong>".domainselect('', 'onchange="document.getElementById(\'radio_new\').checked=true"');
33
+$form .= "<br /><input type=\"checkbox\" name=\"options[]\" id=\"aliaswww\" value=\"aliaswww\" {$s}/> <label for=\"aliaswww\">Auch mit <strong>www</strong> davor.</label></div>";
34
+$form .= "
35
+    <h5>SSL-Verschlüsselung</h5>
36
+    <div style=\"margin-left: 2em;\">
37
+    <select name=\"ssl\" id=\"ssl\">
38
+      <option value=\"none\" selected=\"selected\">SSL optional anbieten</option>
39
+      <option value=\"http\">kein SSL</option>
40
+      <option value=\"https\">nur SSL</option>
41
+      <option value=\"forward\">Immer auf SSL umleiten</option>
42
+    </select>
43
+    </div>
44
+    <h5>Logfiles</h5>
45
+    <div style=\"margin-left: 2em;\">
46
+      <select name=\"logtype\" id=\"logtype\">
47
+        <option value=\"none\">keine Logfiles</option>
48
+        <option value=\"anonymous\">anonymisiert</option>
49
+        <option value=\"default\">vollständige Logfile</option>
50
+      </select><br />
51
+      <input type=\"checkbox\" id=\"errorlog\" name=\"errorlog\" value=\"1\" />&#160;<label for=\"errorlog\">Fehlerprotokoll (error_log) einschalten</label>
52
+    </div>
53
+</div>
54
+</div>
55
+";
56
+
57
+$vhosts = list_vhosts();
58
+
59
+$options = array();
60
+foreach ($vhosts AS $vhost)
61
+{
62
+  $options[$vhost['docroot']] = $vhost['fqdn'];
63
+}
64
+
65
+$form .= '
66
+<div style="margin-left: 2em;">
67
+  <p><input type="radio" name="target" value="vhost" id="radio_vhost" />&#160;<label for="radio_vhost">Vorhandene Domain/Subdomain benutzen</label></p>
68
+  <div style="margin-left: 2em;">
69
+  '.html_select('vhost', $options, '', 'onchange="document.getElementById(\'docroot\').firstChild.textContent=document.getElementById(\'vhost\').options.item(document.getElementById(\'vhost\').options.selectedIndex).value ; document.getElementById(\'radio_vhost\').checked=true"').'
70
+  <p>Datei-Verzeichnis: <strong id="docroot">'.$vhosts[0]['docroot'].'</strong></p>
71
+  <p>Beachten Sie bitte: Die Installation wird nur funktionieren, wenn das Verzeichnis dieser Domain bzw. Subdomain leer oder nicht vorhanden ist. Sofern Sie dort bereits eigene Dateien hinterlegt haben oder eine andere Web-Anwendung installiert ist, wird die Installation nicht durchgeführt.</p>
72
+  </div>
73
+</div>
74
+
75
+<p><input type="submit" name="submit" value="Weiter" /></p>
76
+';
77
+
78
+output(html_form('webapp_install', 'save.php', '', $form));
79
+
80
+
81
+
... ...
@@ -0,0 +1,83 @@
1
+<?php
2
+
3
+require_once('inc/base.php');
4
+require_once('session/start.php');
5
+
6
+global $config;
7
+
8
+
9
+require_role(ROLE_SYSTEMUSER);
10
+
11
+$title = 'MediaWiki einrichten';
12
+$section = 'webapps_install';
13
+
14
+// Wurde beim Schreiben in die Session schon verifiziert
15
+$docroot = $_SESSION['webapp_docroot'];
16
+$url = $_SESSION['webapp_url'];
17
+
18
+if (! $docroot)
19
+{
20
+  system_failure('Kann die Session-Daten nicht auslesen. So geht das nicht.');
21
+}
22
+
23
+
24
+if (isset($_POST['submit']))
25
+{
26
+  require_once('install-mediawiki.php');
27
+  require_once('webapp-installer.php');
28
+  
29
+  check_form_token('install_mediawiki');
30
+
31
+  $data = validate_data($_POST);
32
+  if (! $data)
33
+    system_failure('wtf?!');
34
+  create_new_webapp('mediawiki', $docroot, $url, $data); 
35
+  
36
+  output('<h2>MediaWiki installieren</h2>
37
+
38
+<p>Ihr MediaWiki wird jetzt installiert. Sie erhalten eine E-Mail, sobald das Wiki betriebsbereit ist.</p>
39
+');
40
+  die();
41
+
42
+}
43
+
44
+
45
+require_once('modules/vhosts/include/vhosts.php');
46
+$vhosts = list_vhosts();
47
+
48
+output('<h2>MediaWiki installieren</h2>
49
+
50
+<p>Die Einrichtung von MediaWiki erfordert die Angabe ein paar weniger Daten.</p>
51
+');
52
+
53
+$form = '
54
+<h4>Basisdaten</h4>
55
+<div style="margin-left: 2em;">
56
+  <h5>Ort des neuen Wikis</h5>
57
+  <p>Das Wiki wird im Verzeichnis <strong>'.$docroot.'</strong> installiert und wird später voraussichtlich unter <strong>'.$url.'</strong> abrufbar sein.</p>
58
+  <p>Beachten Sie bitte: Die Installation wird in Ihrem Home-Verzeichnis durchgeführt und es wird ein normaler Host im Webinterface dafür angelegt. Sie können diese Einstellungen also jederzeit verändern.</p>
59
+  
60
+  <h5>Name des Wikis</h5>
61
+  <p>Jedes MediaWiki benötigt einen griffigen Namen. Der Name kann entweder in »WikiSchreibweise« (zusammengezogene Wörter mit großgeschriebenen Anfangsbuchstaben) oder in normaler Schreibweise sein.</p>
62
+  <p><label for="wikiname">Wiki-Name:</label> <input type="text" id="wikiname" name="wikiname" /></p>
63
+  
64
+  <h5>Datenbank-Kürzel</h5>
65
+  <p>Ein MediaWiki benötigt eine MySQL-Datenbank. Dieses Programm wird automatisch eine Datenbank für Sie anlegen. Damit Sie diese später erkennen und verwalten können, wird ein Kürzel benötigt. Der Name der Datenbank wird nachher aus Ihrem Benutzernamen und diesem Kürzel erzeugt. Die Eingabe hier darf keine Leer- oder Sonderzeichen enthalten und nur wenige Zeichen lang sein.</p>
66
+  <p><label for="dbhandle">Kürzel für Datenbankname:</label> <input type="text" name="dbhandle" id="dbhandle" value="wiki" /></p>
67
+</div>
68
+
69
+<h4>Wiki-Administrator</h4>
70
+<div style="margin-left: 2em;">
71
+  <p>Der Wiki-Administrator kann später im Wiki neue Benutzer anlegen, Seiten sperren oder sonstige Verwaltungsaufgaben durchführen.</p>
72
+  <p><label for="adminuser">Benutzername:</label> <input type="text" id="adminuser" name="adminuser" value="WikiSysop" /></p>
73
+  <p><label for="adminpassword">Passwort:</label> <input type="password" id="adminpassword" name="adminpassword" /></p>
74
+  <p><label for="adminemail">E-Mail-Adresse:</label> <input type="text" id="adminemail" name="adminemail" value="'.$_SESSION['userinfo']['username'].'@'.$config['masterdomain'].'" /></p>
75
+</div>
76
+
77
+<p><input type="submit" name="submit" value="Wiki installieren!" /></p>
78
+';
79
+
80
+output(html_form('install_mediawiki', '', '', $form));
81
+
82
+
83
+
... ...
@@ -5,4 +5,5 @@ $role = $_SESSION['role'];
5 5
 if ($role & ROLE_SYSTEMUSER)
6 6
 {
7 7
   $menu["webapps_freewvs"] = array("label" => "freewvs", "file" => "freewvs", "weight" => 1, "submenu" => "vhosts_vhosts");
8
+  $menu["webapps_install"] = array("label" => "Anwendung installieren", "file" => "install", "weight" => 1, "submenu" => "vhosts_vhosts");
8 9
 }
... ...
@@ -0,0 +1,151 @@
1
+<?php
2
+
3
+require_once('inc/security.php');
4
+
5
+require_once('modules/vhosts/include/vhosts.php');
6
+require_once('class/domain.php');
7
+
8
+$url = '';
9
+$docroot = '';
10
+
11
+if ($_POST['target'] == 'new')
12
+{
13
+  check_form_token('webapp_install');
14
+  $vhost = empty_vhost();
15
+
16
+  $hostname = filter_input_hostname($_POST['hostname']);
17
+
18
+  $domainid = (int) $_POST['domain'];
19
+  if ($domainid != -1) {
20
+    $domain = new Domain( (int) $_POST['domain'] );
21
+    if ($domain->useraccount != $_SESSION['userinfo']['uid'])
22
+      system_failure('Ungültige Domain');
23
+    $domainid = $domain->id;
24
+  }
25
+
26
+  if (! is_array($_POST['options']))
27
+    $_POST['options'] = array();
28
+  $aliaswww = in_array('aliaswww', $_POST['options']);
29
+
30
+  $vhost['is_dav'] = 0;
31
+  $vhost['is_svn'] = 0;
32
+  $vhost['is_webapp'] = 0;
33
+  
34
+  $ssl = '';
35
+  switch ($_POST['ssl']) {
36
+    case 'http':
37
+      $ssl = 'http';
38
+      break;
39
+    case 'https':
40
+      $ssl = 'https';
41
+      break;
42
+    case 'forward':
43
+      $ssl = 'forward';
44
+      break;
45
+    /* Wenn etwas anderes kommt, ist das "beides". So einfach ist das. */
46
+  }
47
+
48
+  $logtype = '';
49
+  switch ($_POST['logtype']) {
50
+    case 'anonymous':
51
+      $logtype = 'anonymous';
52
+      break;
53
+    case 'default':
54
+      $logtype = 'default';
55
+      break;
56
+    /* Wenn etwas anderes kommt, ist das "kein Logging". So einfach ist das. */
57
+  }
58
+
59
+  $errorlog = 0;
60
+  if (isset($_POST['errorlog']) and ($_POST['errorlog'] == 1))
61
+    $errorlog = 1;
62
+
63
+  DEBUG("Logging: {$logtype}");
64
+
65
+  $old_options = explode(',', $vhost['options']);
66
+  $new_options = array();
67
+  foreach ($old_options AS $op)
68
+  {
69
+    if ($op != 'aliaswww')
70
+      array_push($new_options, $op);
71
+  }
72
+  if ($aliaswww)
73
+    array_push($new_options, 'aliaswww');
74
+
75
+  DEBUG($old_options);
76
+  DEBUG($new_options);
77
+  $options = implode(',', $new_options);
78
+  DEBUG('New options: '.$options);
79
+
80
+  $vhost['hostname'] = $hostname;
81
+  $vhost['domainid'] = $domainid;
82
+  $vhost['docroot'] = '';
83
+  $vhost['php'] = 'fastcgi';
84
+  $vhost['ssl'] = $ssl;
85
+  $vhost['logtype'] = $logtype;
86
+  $vhost['errorlog'] = $errorlog; 
87
+  $vhost['options'] = $options;
88
+  
89
+  $domain = $domain->fqdn;
90
+  if ($domainid == -1)
91
+  {
92
+    $domain = $_SESSION['userinfo']['username'].'.'.$config['masterdomain'];
93
+  }
94
+
95
+  $url = ($ssl == 'forward' || $ssl == 'https' ? 'https://' : 'http://').($aliaswww ? 'www.' : '').((strlen($hostname) > 0) ? $hostname.'.' : '').$domain;
96
+  $docroot = $vhost['homedir'].'/websites/'.((strlen($hostname) > 0) ? $hostname.'.' : '').($domain).'/htdocs';
97
+  DEBUG($vhost);
98
+  DEBUG("New Vhost: {$url} / {$docroot}");
99
+  save_vhost($vhost);
100
+}
101
+elseif ($_POST['target'] == 'vhost')
102
+{
103
+  $docroot = $_POST['vhost'];
104
+
105
+  $vhosts = list_vhosts();
106
+  foreach ($vhosts AS $vhost)
107
+  {
108
+    if ($docroot == $vhost['docroot'])
109
+    {
110
+      $url = $vhost['fqdn'];
111
+      if (strstr($vhost['options'], 'aliaswww'))
112
+        $url = 'www.'.$url;
113
+
114
+      if ($vhost['ssl'] == 'forward' || $vhost['ssl'] == 'https')
115
+        $url = 'https://'.$url;
116
+      else
117
+        $url = 'http://'.$url;
118
+    }
119
+  }
120
+  if (! $url)
121
+  {
122
+    system_failure('Datenchaos, so geht das nicht.');
123
+  }
124
+  DEBUG("Existing Vhost: {$url} / {$docroot}");
125
+}
126
+else
127
+{
128
+  input_error('Fehler im System');
129
+}
130
+
131
+if ($docroot && $url)
132
+{
133
+  $application = $_POST['application'];
134
+  if (! $application)
135
+    system_failure('Keine Web-Anwendung ausgewählt');
136
+
137
+  if (! check_path($application))
138
+    system_failure('HTML-Krams im Namen der Anwendung');
139
+
140
+  if (! file_exists(dirname(__FILE__).'/install/'.$application.'.php'))
141
+    system_failure('Unbekannte Web-Anwendung.');
142
+
143
+  $_SESSION['webapp_docroot'] = $docroot;
144
+  $_SESSION['webapp_url'] = $url;
145
+  
146
+  if (!$debugmode)
147
+    header('Location: install/'.$application);
148
+}
149
+
150
+
151
+
0 152