436ac808b062994e5539751e9da20453298d21eb
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)     }
54)     DEBUG("Version: ".substr($version, 0, 2));
55)   }
bernd Bugfixes beim Webapp-installer

bernd authored 14 years ago

56)   elseif ($appname == 'MediaWiki')
57)   {
58)     DEBUG("found MediaWiki");
59)     return 'mediawiki';
60)   }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

87) {
88)   // dependet auf das mysql-modul
89)   require_once('modules/mysql/include/mysql.php'); 
90)   
91)   $username = mysql_real_escape_string($_SESSION['userinfo']['username']);
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

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

bernd authored 15 years ago

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

bernd authored 15 years ago

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

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

bernd authored 14 years ago

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

bernd authored 15 years ago

100)     create_mysql_database($handle, $description);
101)     create_mysql_account($handle, $description);
102)     set_mysql_access($handle, $handle, true);
103)     $password = random_string(10);
104)     set_mysql_password($handle, $password);
105)     return array('dbuser' => $handle, 'dbname' => $handle, 'dbpass' => $password);
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

106)   }
107) 
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

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

bernd authored 14 years ago

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

bernd authored 14 years ago

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

bernd authored 15 years ago

115)       set_mysql_access($handle, $handle, true);
116)       $password = random_string(10);
117)       set_mysql_password($handle, $password);
118)       return array('dbuser' => $handle, 'dbname' => $handle, 'dbpass' => $password);
119)     }
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

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

bernd authored 15 years ago

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