2626dd47daad110c63a82c0560b134e2364eeac3
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 Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 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) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

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) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

21)     if (directory_in_use($directory)) {
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.');
23)     }
24)     $args = array(":username" => $_SESSION['userinfo']['username'],
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

25)                 ":appname" => $appname,
26)                 ":dir" => $directory,
27)                 ":url" => $url,
28)                 ":data" => $data);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

30) }
31) 
32) 
bernd * alle internen Links sinnv...

bernd authored 15 years ago

33) function request_update($appname, $directory, $url)
34) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

35)     if (directory_in_use($directory)) {
36)         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.');
37)     }
38)     $args = array(":username" => $_SESSION['userinfo']['username'],
Bernd Wurst * Weitere Module auf prepar...

Bernd Wurst authored 10 years ago

39)                 ":appname" => $appname,
40)                 ":dir" => $directory,
41)                 ":url" => $url);
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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

43) }
44) 
bernd Doppelte webapp-installer-t...

bernd authored 15 years ago

45) function directory_in_use($directory)
46) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

47)     $result = db_query("SELECT id FROM vhosts.webapp_installer WHERE (state IN ('new','old') OR DATE(lastchange)=CURDATE()) AND directory=?", array($directory));
48)     if ($result->rowCount() > 0) {
49)         return true;
50)     }
51)     return false;
bernd Doppelte webapp-installer-t...

bernd authored 15 years ago

52) }
bernd * alle internen Links sinnv...

bernd authored 15 years ago

53) 
54) function upgradeable($appname, $version)
55) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

56)     DEBUG("Is {$appname}-{$version} upgradeable?");
57)     if ($appname == 'Drupal7') {
58)         DEBUG("found Drupal-7.*!");
59)         return 'drupal7';
bernd Drupal-7 kann auch per Auto...

bernd authored 13 years ago

60)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

61)     if ($appname == 'Drupal') {
62)         DEBUG("found Drupal!");
63)         if (substr($version, 0, 2) == '7.') {
64)             DEBUG("found Drupal-7.*!");
65)             return 'drupal7';
66)         }
67)         DEBUG("Version: ".substr($version, 0, 2));
68)     } elseif ($appname == 'MediaWiki') {
69)         DEBUG("found MediaWiki");
70)         return 'mediawiki';
71)     }
72)     /*elseif ($appname == 'owncloud')
73)     {
74)       DEBUG('found OwnCloud');
75)       return 'owncloud';
76)     }*/
77)     DEBUG("found no upgradeable webapp!");
78)     return null;
bernd * alle internen Links sinnv...

bernd authored 15 years ago

79) }
80) 
81) 
82) function get_url_for_dir($docroot, $cutoff = '')
83) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

84)     if (substr($docroot, -1) == '/') {
85)         $docroot = substr($docroot, 0, -1);
86)     }
87)     $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.'/'));
88)     if ($result->rowCount() < 1) {
89)         if (!strstr($docroot, '/')) {
90)             return null;
91)         }
92)         return get_url_for_dir(substr($docroot, 0, strrpos($docroot, '/')), substr($docroot, strrpos($docroot, '/')).$cutoff);
93)     }
94)     $tmp = $result->fetch();
95)     $prefix = 'http://';
96)     if ($tmp['ssl'] == 'forward' || $tmp['ssl'] == 'https') {
97)         $prefix = 'https://';
98)     }
99)     return $prefix.$tmp['fqdn'].$cutoff;
bernd * alle internen Links sinnv...

bernd authored 15 years ago

100) }
101) 
102) 
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

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

bernd authored 15 years ago

104) {
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

105)     // dependet auf das mysql-modul
106)     require_once('modules/mysql/include/mysql.php');
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

107)   
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

108)     $username = $_SESSION['userinfo']['username'];
109)     $description = "Automatisch erzeugte Datenbank für {$application} ({$sitename})";
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

110)   
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

111)     // zuerst versuchen wir username_webappname. Wenn das nicht klappt, dann wird hochgezählt
112)     $handle = $username.'_'.$application;
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

113)   
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

114)     if (validate_mysql_username($handle) && validate_mysql_dbname($handle) && ! (has_mysql_user($handle) || has_mysql_database($handle))) {
115)         logger(LOG_INFO, "webapps/include/webapp-installer", "create", "creating db and user »{$handle}«");
116)         create_mysql_database($handle, $description);
117)         create_mysql_account($handle, $description);
118)         set_mysql_access($handle, $handle, true);
119)         $password = random_string(10);
120)         set_mysql_password($handle, $password);
121)         return array('dbuser' => $handle, 'dbname' => $handle, 'dbpass' => $password);
122)     }
bernd Webapp-Installer, erste Ver...

bernd authored 15 years ago

123) 
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

124)     for ($i = 0; $i < 100 ; $i++) {
125)         $handle = $username.'_'.$i;
126)         if (validate_mysql_username($handle) && validate_mysql_dbname($handle) && ! (has_mysql_user($handle) || has_mysql_database($handle))) {
127)             logger(LOG_INFO, "webapps/include/webapp-installer", "create", "creating db and user »{$handle}«");
128)             create_mysql_database($handle, $description);
129)             create_mysql_account($handle, $description);
130)             set_mysql_access($handle, $handle, true);
131)             $password = random_string(10);
132)             set_mysql_password($handle, $password);
133)             return array('dbuser' => $handle, 'dbname' => $handle, 'dbpass' => $password);
134)         }
bernd Frage Datenbank-Kürzel nich...

bernd authored 15 years ago

135)     }
Hanno Fix coding style with php-c...

Hanno authored 6 years ago

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