c208bd906b3991555db11b9229846c4601ca408c
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
5) Written 2008-2012 by schokokeks.org Hosting, namely
6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
15) */
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

16) 
17) require_once('inc/base.php');
18) 
19) function create_new_webapp($appname, $directory, $url, $data)
20) {
bernd Doppelte webapp-installer-t...

bernd authored 15 years ago

21)   if (directory_in_use($directory))
bernd Bugfixes beim Webapp-installer

bernd authored 14 years ago

22)     system_failure('Sie haben erst kürzlich eine Anwendung in diesem Verzeichnis installieren lassen. Aus Sicherheitsgründen können Sie in diesem Verzeichnis am selben Tag nicht schon wieder eine Anwendung installieren.');
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

23)   $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
24)   $appname = mysql_real_escape_string($appname);
25)   $directory = mysql_real_escape_string($directory);
26)   $url = mysql_real_escape_string($url);
27)   $data = mysql_real_escape_string($data);
bernd Bugfixes beim Webapp-installer

bernd authored 14 years ago

28)   db_query("INSERT INTO vhosts.webapp_installer (appname, directory, url, state, username, data) VALUES ('{$appname}', '{$directory}', '{$url}', 'new', '{$username}', '{$data}')");
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

29) }
30) 
31) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

32) function request_update($appname, $directory, $url)
33) {
bernd Doppelte webapp-installer-t...

bernd authored 15 years ago

34)   if (directory_in_use($directory))
35)     system_failure('Sie haben erst kürzlich eine Anwendung in diesem Verzeichnis installieren lassen oder ein Update in diesem Verzeichnis angefordert. Bitte warten Sie bis diese Aktion durchgeführt wurde.');
bernd * alle internen Links sinnv...

bernd authored 15 years ago

36)   $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
37)   $appname = mysql_real_escape_string($appname);
38)   $directory = mysql_real_escape_string($directory);
39)   $url = maybe_null(mysql_real_escape_string($url));
bernd Bugfixes beim Webapp-installer

bernd authored 14 years ago

40)   db_query("INSERT INTO vhosts.webapp_installer (appname, directory, url, state, username) VALUES ('{$appname}', '{$directory}', {$url}, 'old', '{$username}')");
bernd * alle internen Links sinnv...

bernd authored 15 years ago

41) }
42) 
bernd Doppelte webapp-installer-t...

bernd authored 15 years ago

43) function directory_in_use($directory)
44) {
45)   $directory = mysql_real_escape_string($directory);
bernd Bugfixes beim Webapp-installer

bernd authored 14 years ago

46)   $result = db_query("SELECT id FROM vhosts.webapp_installer WHERE (state IN ('new','old') OR DATE(lastchange)=CURDATE()) AND directory='{$directory}'");
bernd Doppelte webapp-installer-t...

bernd authored 15 years ago

47)   if (mysql_num_rows($result) > 0)
48)     return true;
49)   return false;
50) }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

51) 
52) function upgradeable($appname, $version)
53) {
54)   DEBUG("Is {$appname}-{$version} upgradeable?");
bernd Erkenne »Druapl6«

bernd authored 12 years ago

55)   if ($appname == 'Drupal6') 
56)   {
57)     return 'drupal6';
58)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

59)   if ($appname == 'Drupal')
60)   {
61)     DEBUG("found Drupal!");
bernd erlaube automatisches upgra...

bernd authored 14 years ago

62)     if (substr($version, 0, 2) == '5.')
63)     {
64)       DEBUG("found Drupal-5.*!");
65)       return 'drupal5';
66)     }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

67)     if (substr($version, 0, 2) == '6.')
68)     {
69)       DEBUG("found Drupal-6.*!");
70)       return 'drupal6';
71)     }
bernd Drupal-7 kann auch per Auto...

bernd authored 13 years ago

72)     if (substr($version, 0, 2) == '7.')
73)     {
74)       DEBUG("found Drupal-7.*!");
75)       return 'drupal7';
76)     }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

77)     DEBUG("Version: ".substr($version, 0, 2));
78)   }
bernd Bugfixes beim Webapp-installer

bernd authored 14 years ago

79)   elseif ($appname == 'MediaWiki')
80)   {
81)     DEBUG("found MediaWiki");
82)     return 'mediawiki';
83)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

84)   DEBUG("found no upgradeable webapp!");
85)   return NULL;
86) }
87) 
88) 
89) function get_url_for_dir($docroot, $cutoff = '')
90) {
91)   if (substr($docroot, -1) == '/')
92)     $docroot = substr($docroot, 0, -1);
93)   $docroot = mysql_real_escape_string($docroot);
94)   $result = db_query("SELECT `ssl`, IF(FIND_IN_SET('aliaswww', options), CONCAT('www.',fqdn), fqdn) AS fqdn FROM vhosts.v_vhost WHERE docroot IN ('{$docroot}', '{$docroot}/') LIMIT 1");
95)   if (mysql_num_rows($result) < 1)
96)   {
97)     if (!strstr($docroot, '/'))
98)       return NULL;
99)     return get_url_for_dir(substr($docroot, 0, strrpos($docroot, '/')), substr($docroot, strrpos($docroot, '/')).$cutoff);
100)   } 
101)   $tmp = mysql_fetch_assoc($result);
102)   $prefix = 'http://';
103)   if ($tmp['ssl'] == 'forward' || $tmp['ssl'] == 'https')
104)     $prefix = 'https://';
105)   return $prefix.$tmp['fqdn'].$cutoff;
106) }
107) 
108) 
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

109) function create_webapp_mysqldb($application, $sitename)
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

110) {
111)   // dependet auf das mysql-modul
112)   require_once('modules/mysql/include/mysql.php'); 
113)   
114)   $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

115)   $description = "Automatisch erzeugte Datenbank für {$application} ({$sitename})";
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

116)   
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

117)   // zuerst versuchen wir username_webappname. Wenn das nicht klappt, dann wird hochgezählt
118)   $handle = $username.'_'.$application;
119)   
120)   if (validate_mysql_username($handle) && validate_mysql_dbname($handle) && ! (has_mysql_user($handle) || has_mysql_database($handle)))
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

121)   {
bernd stringlänge mit strlen und...

bernd authored 14 years ago

122)     logger(LOG_INFO, "webapps/include/webapp-installer", "create", "creating db and user »{$handle}«");
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

123)     create_mysql_database($handle, $description);
124)     create_mysql_account($handle, $description);
125)     set_mysql_access($handle, $handle, true);
126)     $password = random_string(10);
127)     set_mysql_password($handle, $password);
128)     return array('dbuser' => $handle, 'dbname' => $handle, 'dbpass' => $password);
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

129)   }
130) 
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

131)   for ($i = 0; $i < 100 ; $i++) {
132)     $handle = $username.'_'.$i;
133)     if (validate_mysql_username($handle) && validate_mysql_dbname($handle) && ! (has_mysql_user($handle) || has_mysql_database($handle)))
134)     {
bernd stringlänge mit strlen und...

bernd authored 14 years ago

135)       logger(LOG_INFO, "webapps/include/webapp-installer", "create", "creating db and user »{$handle}«");
bernd Bugfixes beim Webapp-installer

bernd authored 14 years ago

136)       create_mysql_database($handle, $description);
137)       create_mysql_account($handle, $description);
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

138)       set_mysql_access($handle, $handle, true);
139)       $password = random_string(10);
140)       set_mysql_password($handle, $password);
141)       return array('dbuser' => $handle, 'dbname' => $handle, 'dbpass' => $password);
142)     }
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

143)   }
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

144)   system_failure('Konnte keine Datenbank erzeugen. Bitte melden Sie diesen Umstand den Administratoren!');