70d2c0a3f9c56ba53f26c7c9b5d0dbdb3a47a91c
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 Lizenzinfos in eigenes Modu...

Bernd Wurst authored 10 years ago

5) Written 2008-2014 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 * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

23)   $args = array(":username" => $_SESSION['userinfo']['username'],
24)                 ":appname" => $appname,
25)                 ":dir" => $directory,
26)                 ":url" => $url,
27)                 ":data" => $data);
28)   db_query("INSERT INTO vhosts.webapp_installer (appname, directory, url, state, username, data) VALUES (:appname, :dir, :url, 'new', :username, :data)", $args);
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 * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

36)   $args = array(":username" => $_SESSION['userinfo']['username'],
37)                 ":appname" => $appname,
38)                 ":dir" => $directory,
39)                 ":url" => $url);
40)   db_query("INSERT INTO vhosts.webapp_installer (appname, directory, url, state, username) VALUES (:appname, :dir, :url, 'old', :username)", $args);
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 * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

45)   $result = db_query("SELECT id FROM vhosts.webapp_installer WHERE (state IN ('new','old') OR DATE(lastchange)=CURDATE()) AND directory=?", array($directory));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 14 years ago

47)     return true;
48)   return false;
49) }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 12 years ago

54)   if ($appname == 'Drupal6') 
55)   {
Bernd Wurst Drupal-7 ist auch upgrade-f...

Bernd Wurst authored 11 years ago

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

bernd authored 12 years ago

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

Bernd Wurst authored 11 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 13 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

84)   elseif ($appname == 'MediaWiki')
85)   {
86)     DEBUG("found MediaWiki");
87)     return 'mediawiki';
88)   }
Bernd Wurst Auto-updater für OwnCloud e...

Bernd Wurst authored 9 years ago

89)   /*elseif ($appname == 'owncloud') 
Bernd Wurst Es gibt jetzt einen Auto-Up...

Bernd Wurst authored 11 years ago

90)   {
91)     DEBUG('found OwnCloud');
92)     return 'owncloud';
Bernd Wurst Auto-updater für OwnCloud e...

Bernd Wurst authored 9 years ago

93)   }*/
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

Bernd Wurst authored 10 years ago

103)   $result = db_query("SELECT `ssl`, IF(FIND_IN_SET('aliaswww', options), CONCAT('www.',fqdn), fqdn) AS fqdn FROM vhosts.v_vhost WHERE docroot IN (?, ?)", array($docroot, $docroot.'/'));
Bernd Wurst Umstellung auf PDO-Datenban...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

119) {
120)   // dependet auf das mysql-modul
121)   require_once('modules/mysql/include/mysql.php'); 
122)   
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

138)   }
139) 
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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