ff1c4232468fe639c46f8f2c6a95c42db3bec138
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?");
bernd Erkenne »Druapl6«

bernd authored 12 years ago

41)   if ($appname == 'Drupal6') 
42)   {
43)     return 'drupal6';
44)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

45)   if ($appname == 'Drupal')
46)   {
47)     DEBUG("found Drupal!");
bernd erlaube automatisches upgra...

bernd authored 14 years ago

48)     if (substr($version, 0, 2) == '5.')
49)     {
50)       DEBUG("found Drupal-5.*!");
51)       return 'drupal5';
52)     }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 13 years ago

58)     if (substr($version, 0, 2) == '7.')
59)     {
60)       DEBUG("found Drupal-7.*!");
61)       return 'drupal7';
62)     }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 14 years ago

65)   elseif ($appname == 'MediaWiki')
66)   {
67)     DEBUG("found MediaWiki");
68)     return 'mediawiki';
69)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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