f1f231f5e074dfa038e70a67d39849e80f2b4b4d
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) 
Bernd Wurst Updated copyright notice (2...

Bernd Wurst authored 11 years ago

5) Written 2008-2013 by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

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 14 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 Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

23)   $username = db_escape_string($_SESSION['userinfo']['username']);
24)   $appname = db_escape_string($appname);
25)   $directory = db_escape_string($directory);
26)   $url = db_escape_string($url);
27)   $data = db_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 14 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 Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

36)   $username = db_escape_string($_SESSION['userinfo']['username']);
37)   $appname = db_escape_string($appname);
38)   $directory = db_escape_string($directory);
39)   $url = maybe_null(db_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 14 years ago

43) function directory_in_use($directory)
44) {
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

45)   $directory = db_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 Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

47)   if ($result->rowCount() > 0)
bernd Doppelte webapp-installer-t...

bernd authored 14 years ago

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)   {
Bernd Wurst Drupal-7 ist auch upgrade-f...

Bernd Wurst authored 11 years ago

57)     DEBUG("found Drupal-6.*!");
bernd Erkenne »Druapl6«

bernd authored 12 years ago

58)     return 'drupal6';
59)   }
Bernd Wurst Drupal-7 ist auch upgrade-f...

Bernd Wurst authored 11 years ago

60)   if ($appname == 'Drupal7') 
61)   {
62)     DEBUG("found Drupal-7.*!");
63)     return 'drupal7';
64)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

65)   if ($appname == 'Drupal')
66)   {
67)     DEBUG("found Drupal!");
bernd erlaube automatisches upgra...

bernd authored 14 years ago

68)     if (substr($version, 0, 2) == '5.')
69)     {
70)       DEBUG("found Drupal-5.*!");
71)       return 'drupal5';
72)     }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

73)     if (substr($version, 0, 2) == '6.')
74)     {
75)       DEBUG("found Drupal-6.*!");
76)       return 'drupal6';
77)     }
bernd Drupal-7 kann auch per Auto...

bernd authored 13 years ago

78)     if (substr($version, 0, 2) == '7.')
79)     {
80)       DEBUG("found Drupal-7.*!");
81)       return 'drupal7';
82)     }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 14 years ago

85)   elseif ($appname == 'MediaWiki')
86)   {
87)     DEBUG("found MediaWiki");
88)     return 'mediawiki';
89)   }
Bernd Wurst Es gibt jetzt einen Auto-Up...

Bernd Wurst authored 11 years ago

90)   elseif ($appname == 'owncloud') 
91)   {
92)     DEBUG('found OwnCloud');
93)     return 'owncloud';
94)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

95)   DEBUG("found no upgradeable webapp!");
96)   return NULL;
97) }
98) 
99) 
100) function get_url_for_dir($docroot, $cutoff = '')
101) {
102)   if (substr($docroot, -1) == '/')
103)     $docroot = substr($docroot, 0, -1);
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

104)   $docroot = db_escape_string($docroot);
bernd * alle internen Links sinnv...

bernd authored 15 years ago

105)   $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");
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

106)   if ($result->rowCount() < 1)
bernd * alle internen Links sinnv...

bernd authored 15 years ago

107)   {
108)     if (!strstr($docroot, '/'))
109)       return NULL;
110)     return get_url_for_dir(substr($docroot, 0, strrpos($docroot, '/')), substr($docroot, strrpos($docroot, '/')).$cutoff);
111)   } 
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

112)   $tmp = $result->fetch();
bernd * alle internen Links sinnv...

bernd authored 15 years ago

113)   $prefix = 'http://';
114)   if ($tmp['ssl'] == 'forward' || $tmp['ssl'] == 'https')
115)     $prefix = 'https://';
116)   return $prefix.$tmp['fqdn'].$cutoff;
117) }
118) 
119) 
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

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

bernd authored 15 years ago

121) {
122)   // dependet auf das mysql-modul
123)   require_once('modules/mysql/include/mysql.php'); 
124)   
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

125)   $username = db_escape_string($_SESSION['userinfo']['username']);
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

128)   // zuerst versuchen wir username_webappname. Wenn das nicht klappt, dann wird hochgezählt
129)   $handle = $username.'_'.$application;
130)   
131)   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

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

bernd authored 14 years ago

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

bernd authored 15 years ago

134)     create_mysql_database($handle, $description);
135)     create_mysql_account($handle, $description);
136)     set_mysql_access($handle, $handle, true);
137)     $password = random_string(10);
138)     set_mysql_password($handle, $password);
139)     return array('dbuser' => $handle, 'dbname' => $handle, 'dbpass' => $password);
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

140)   }
141) 
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

149)       set_mysql_access($handle, $handle, true);
150)       $password = random_string(10);
151)       set_mysql_password($handle, $password);
152)       return array('dbuser' => $handle, 'dbname' => $handle, 'dbpass' => $password);
153)     }
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

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

bernd authored 15 years ago

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