2c065cab7b18a5bd571bb2e72abb588f973f583b
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

1) <?php
2) 
3) require_once('inc/base.php');
4) 
5) function create_new_webapp($appname, $directory, $url, $data)
6) {
bernd Doppelte webapp-installer-t...

bernd authored 14 years ago

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

bernd authored 14 years ago

8)     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

9)   $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
10)   $appname = mysql_real_escape_string($appname);
11)   $directory = mysql_real_escape_string($directory);
12)   $url = mysql_real_escape_string($url);
13)   $data = mysql_real_escape_string($data);
bernd Bugfixes beim Webapp-installer

bernd authored 14 years ago

14)   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

15) }
16) 
17) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 14 years ago

20)   if (directory_in_use($directory))
21)     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

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

bernd authored 14 years ago

26)   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

27) }
28) 
bernd Doppelte webapp-installer-t...

bernd authored 14 years ago

29) function directory_in_use($directory)
30) {
31)   $directory = mysql_real_escape_string($directory);
bernd Bugfixes beim Webapp-installer

bernd authored 14 years ago

32)   $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 14 years ago

33)   if (mysql_num_rows($result) > 0)
34)     return true;
35)   return false;
36) }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

37) 
38) function upgradeable($appname, $version)
39) {
40)   DEBUG("Is {$appname}-{$version} upgradeable?");
41)   if ($appname == 'Drupal')
42)   {
43)     DEBUG("found Drupal!");
bernd erlaube automatisches upgra...

bernd authored 14 years ago

44)     if (substr($version, 0, 2) == '5.')
45)     {
46)       DEBUG("found Drupal-5.*!");
47)       return 'drupal5';
48)     }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

49)     if (substr($version, 0, 2) == '6.')
50)     {
51)       DEBUG("found Drupal-6.*!");
52)       return 'drupal6';
53)     }
bernd Drupal-7 kann auch per Auto...

bernd authored 13 years ago

54)     if (substr($version, 0, 2) == '7.')
55)     {
56)       DEBUG("found Drupal-7.*!");
57)       return 'drupal7';
58)     }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 14 years ago

61)   elseif ($appname == 'MediaWiki')
62)   {
63)     DEBUG("found MediaWiki");
64)     return 'mediawiki';
65)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

66)   DEBUG("found no upgradeable webapp!");
67)   return NULL;
68) }
69) 
70) 
71) function get_url_for_dir($docroot, $cutoff = '')
72) {
73)   if (substr($docroot, -1) == '/')
74)     $docroot = substr($docroot, 0, -1);
75)   $docroot = mysql_real_escape_string($docroot);
76)   $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");
77)   if (mysql_num_rows($result) < 1)
78)   {
79)     if (!strstr($docroot, '/'))
80)       return NULL;
81)     return get_url_for_dir(substr($docroot, 0, strrpos($docroot, '/')), substr($docroot, strrpos($docroot, '/')).$cutoff);
82)   } 
83)   $tmp = mysql_fetch_assoc($result);
84)   $prefix = 'http://';
85)   if ($tmp['ssl'] == 'forward' || $tmp['ssl'] == 'https')
86)     $prefix = 'https://';
87)   return $prefix.$tmp['fqdn'].$cutoff;
88) }
89) 
90) 
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

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

bernd authored 15 years ago

92) {
93)   // dependet auf das mysql-modul
94)   require_once('modules/mysql/include/mysql.php'); 
95)   
96)   $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

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

bernd authored 14 years ago

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

bernd authored 15 years ago

105)     create_mysql_database($handle, $description);
106)     create_mysql_account($handle, $description);
107)     set_mysql_access($handle, $handle, true);
108)     $password = random_string(10);
109)     set_mysql_password($handle, $password);
110)     return array('dbuser' => $handle, 'dbname' => $handle, 'dbpass' => $password);
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

111)   }
112) 
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

120)       set_mysql_access($handle, $handle, true);
121)       $password = random_string(10);
122)       set_mysql_password($handle, $password);
123)       return array('dbuser' => $handle, 'dbname' => $handle, 'dbpass' => $password);
124)     }
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

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

bernd authored 15 years ago

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