modules/mysql/save.php
89108733
 <?php
 /*
 This file belongs to the Webinterface of schokokeks.org Hosting
 
cf54502a
 Written 2008-2018 by schokokeks.org Hosting, namely
89108733
   Bernd Wurst <bernd@schokokeks.org>
   Hanno Böck <hanno@schokokeks.org>
 
 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.
 
2626dd47
 You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
89108733
 http://creativecommons.org/publicdomain/zero/1.0/
 
 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.
 */
 
 require_once('session/start.php');
 require_once('inc/icons.php');
 require_role(array(ROLE_SYSTEMUSER));
 
 global $prefix;
 
 require_once('mysql.php');
 
 if (isset($_GET['action']) && $_GET['action'] == 'permchange') {
2626dd47
     check_form_token('mysql_permchange');
     set_mysql_access($_GET['db'], $_GET['user'], ($_GET['access'] == 1));
     redirect('overview');
89108733
 }
 
 if (isset($_GET['action']) && $_GET['action'] == 'newdb') {
2626dd47
     check_form_token('mysql_newdb');
     $dbname = $_POST['newdb'];
     $desc = $_POST['description'];
     $server = null;
     if (isset($_POST['server'])) {
         $server = $_POST['server'];
89108733
     }
2626dd47
     create_mysql_database($dbname, $desc, $server);
     if (isset($_POST['access'])) {
         foreach ($_POST['access'] as $user) {
             set_mysql_access($dbname, $user, true);
         }
     }
     redirect('overview');
89108733
 }
 
 if (isset($_GET['action']) && $_GET['action'] == 'newuser') {
2626dd47
     check_form_token('mysql_newuser');
     $username = $_POST['newuser'];
     $desc = $_POST['description'];
     $password = $_POST['newpass'];
     create_mysql_account($username, $desc);
     set_mysql_password($username, $password);
     if (isset($_POST['access'])) {
         foreach ($_POST['access'] as $dbname) {
             set_mysql_access($dbname, $username, true);
         }
89108733
     }
2626dd47
     redirect('overview');
89108733
 }
 
 if (isset($_GET['action']) && $_GET['action'] == 'description') {
2626dd47
     check_form_token('mysql_description');
     if (isset($_GET['db'])) {
         $db = $_GET['db'];
         $description = $_POST['description'];
         set_database_description($db, $description);
     }
     if (isset($_GET['username'])) {
         $user = $_GET['username'];
         $description = $_POST['description'];
         set_dbuser_description($user, $description);
     }
     redirect('overview');
89108733
 }
 
 
 if (isset($_GET['action'])) {
2626dd47
     switch ($_GET['action']) {
89108733
     case 'delete_db':
2626dd47
       if (! has_mysql_database($_GET['db'])) {
           system_failure('Ungültige Datenbank');
89108733
       }
2626dd47
       $sure = user_is_sure();
       if ($sure === null) {
           are_you_sure("action=delete_db&db={$_GET['db']}", "Möchten Sie die Datenbank »{$_GET['db']}« wirklich löschen?");
       } elseif ($sure === true) {
           delete_mysql_database($_GET['db']);
           redirect('overview');
       } elseif ($sure === false) {
           redirect('overview');
89108733
       }
       break;
     case 'delete_user':
2626dd47
       if (! has_mysql_user($_GET['user'])) {
           system_failure('Ungültiger Benutzer');
89108733
       }
2626dd47
       $sure = user_is_sure();
       if ($sure === null) {
           are_you_sure("action=delete_user&user={$_GET['user']}", "Möchten Sie den Benutzer »{$_GET['user']}« wirklich löschen?");
       } elseif ($sure === true) {
           delete_mysql_account($_GET['user']);
           redirect('overview');
       } elseif ($sure === false) {
           redirect('overview');
89108733
       }
       break;
     case 'change_pw':
       check_form_token('mysql_databases');
32418e06
       set_mysql_password($_POST['mysql_username'], $_POST['newpass']);
89108733
       redirect('overview');
       break;
     default:
       system_failure("Diese Funktion scheint noch nicht eingebaut zu sein!");
   }
 }
 
 $dbs = get_mysql_databases($_SESSION['userinfo']['uid']);
 $users = get_mysql_accounts($_SESSION['userinfo']['uid']);
 
2626dd47
 if (isset($_POST['accesseditor'])) {
     check_form_token('mysql_databases');
9086c9ad
 
2626dd47
     foreach ($dbs as $db) {
         $db = $db['name'];
         foreach ($users as $user) {
             $user = $user['username'];
             if (! isset($_POST['access'][$db])) {
                 set_mysql_access($db, $user, false);
             } else {
                 set_mysql_access($db, $user, in_array($user, $_POST['access'][$db]));
             }
         }
89108733
     }
2626dd47
     $mysql_access = null;
89108733
 }