OwnCloud Tools

Tutorials on ownCloud administration
Forum rules
The forums were migrated over to https://central.owncloud.org which is based on the forum software Discourse. The forums here is put into read-only mode starting from today.

More background information about this move and the reasoning behind it is available in this blogpost:

https://daniel.molkentin.net/2016/07/20 ... d-central/
snapr
Admin
Posts: 108
Joined: Mon Jan 30, 2012 9:32 pm

OwnCloud Tools

Postby snapr » Thu Jun 14, 2012 2:09 pm

Note: I wrote this script quite some time ago. I no longer maintain it, but it may be kept up to date by the community (leave one of the administrators a message to contribute).

This script is designed to help users finding errors in their OwnCloud installation. Please do not use features you don't understand. If you have any suggestions or error reports, please PM me or send me an email.

Notes
Some functions directly interact with the database and can cause errors in the OwnCloud software. Interface built with the help of bootstrap. Javascript and Stylesheets required are hosted by Dennis Kuypers (snapr) at kycdn.net. This means that I could (in theory) log your IP and track down your owncloud installations (I don't, of course! ;) ).

How To Use
  1. create a PHP file in the owncloud directory (ex. tools.php)
  2. copy and paste the code from the codebox to the file
  3. on line 1: set a password in the parenthesis
  4. open your browser and navigate to the file you created (ex. http://myowncloud.com/owncloud/tools.php)

Code: Select all

                    <?php
                $PASSWORD = '';
                /* Please enter a password here ;) ***** Tools Script for OwnCloud 4 by Dennis Kuypers (snapr) -
                 * adapted for hosted css/js by (RandolphCarter)
                 * please report problems or experiences at http://forum.owncloud.org/viewtopic.php?f=8&t=2921 */
                define('version', 'rev.02');
                if (isset($_GET['PING']))
                    die("pong");
                if (!session_start())
                    die("Either your client does not allow/support cookies OR the server can not start a session");
                if (isset($_POST['tpw']))
                  {
                    $_SESSION['tpw'] = $_POST['tpw'];
                  }
                $do = (isset($_GET["do"]) ? $_GET["do"] : 'home');
                if (isset($_SESSION['tpw']) && $_SESSION['tpw'] == $PASSWORD && isset($_GET['phpinfo']))
                  {
                    phpinfo();
                    exit;
                  }
                ?><!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>OwnCloud Tools</title><link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.0/css/bootstrap.min.css" rel="stylesheet"></head><body><div class="container"><div class="row" style="margin-top: 20px"><div class="span2"><ul class="well nav nav-list"><?php
                if (isset($_SESSION['tpw']) && $_SESSION['tpw'] == $PASSWORD)
                  {
                ?><li class="<?php
                    echo ($do == 'home' ? 'active' : '');
                ?>"><a href="?do=home"><i class="icon-home"></i> Overview</a></li><li class="<?php
                    echo ($do == 'serverinfo' ? 'active' : '');
                ?>"><a href="?do=serverinfo"><i class="icon-info-sign"></i> Serverinfo</a></li><li class="<?php
                    echo ($do == 'test' ? 'active' : '');
                ?>"><a href="?do=test"><i class="icon-question-sign"></i> Run Tests</a></li><li class="<?php
                    echo (substr($do, 0, 4) == 'tool' ? 'active' : '');
                ?>"><a href="?do=tool"><i class="icon-wrench"></i> Tools</a></li><li><a href="?phpinfo=show"><i class="icon-th-list"></i> PHPinfo</a></li><li class="<?php
                    echo ($do == 'fs' ? 'active' : '');
                ?>"><a href="?do=perm"><i class="icon-file"></i> File Perm.</a></li><!--<li class="nav-header">OC4</li><li class="<?php
                    echo (substr($do, 0, 7) == 'install' ? 'active' : '');
                ?>"><a href="#" onclick="alert('Sorry, not working right now');"><i class="icon-download-alt"></i> Install</a></li><li class="<?php
                    echo (substr($do, 0, 7) == 'browser' ? 'active' : '');
                ?>"><a href="?do=browser"><i class="icon-share"></i> Browse Data</a></li><li class="<?php
                    echo (substr($do, 0, 5) == 'login' ? 'active' : '');
                ?>"><a href="?do=login-pre"><i class="icon-user"></i> Fake Login</a></li>--><li class="nav-header">Menu</li><li><a href="./index.php"><i class="icon-globe"></i> visit this OC</a></li><li><a href="?do=logout"><i class="icon-remove"></i> Logout</a></li><?php
                  }
                ?><li class="nav-header">External</li><li><a href="http://owncloud.org/"><i class="icon-share"></i> OC.org</a></li><li><a href="http://owncloud.com/"><i class="icon-share"></i> OC.com</a></li><li><a href="http://forum.owncloud.org/"><i class="icon-share"></i> Forum</a></li><li><a href="https://github.com/owncloud/"><i class="icon-share"></i> Bugtracker</a></li></ul><?php
                echo "</div>";
                if ($PASSWORD == "")
                  {
                ?><div class="modal" id="noModal"><div class="modal-header"><h3>Before we can start</h3></div><div class="modal-body"><p>Please edit line 1 in <?php
                    echo basename(__FILE__);
                ?></p></div><div class="modal-footer"><a href="?do=home" class="btn btn-info">Continue</a></div></div><?php
                  }
                elseif (!isset($_SESSION['tpw']) || $_SESSION['tpw'] != $PASSWORD)
                  {
                ?><div class="span5"><h3>Login</h3><form action="" method="post"><input name="tpw" type="password" placeholder="Password"><br><button type="submit" class="btn btn-danger">Use at own risk</button></form></div><?php
                  }
                else
                  {
                    function success($txt)
                      {
                        return '<span class="label label-success">' . $txt . '</span>';
                      }
                    function warning($txt)
                      {
                        return '<span class="label label-warning">' . $txt . '</span>';
                      }
                    function important($txt)
                      {
                        return '<span class="label label-important">' . $txt . '</span>';
                      }
                    switch ($do)
                    {
                        case 'test':
                ?><div class="span10"><h3>Tests</h3><p>Some tests are apache2 specific. Please note that various features might work on other servers, although this script states the opposite.<br><span class="label">value not available</span><span class="label label-success">good result</span><span class="label label-warning">possible problems/restrictions</span><span class="label label-important">serious issue, OC will most likely not work</span></p><table class="table table-bordered table-striped"><thead><tr id="test"><th>Test</th><th>Result</th><th>Description</th></tr></thead><tbody><tr><td>PHP Version</td><td><?php
                            if (version_compare("5.3", phpversion()) == -1)
                                echo '<span class="label label-success">You are running ' . phpversion() . '</span>';
                            else
                                echo '<span class="label label-important">Your PHP is outdated! You are running ' . phpversion() . '</span>';
                ?></td><td>Minimum version required for OwnCloud: 5.3.x</td></tr><tr><td>PHP Integer Size</td><td><?php
                            echo ((PHP_INT_SIZE == 8) ? '<span class="label label-success">64 bits</span>' : '<span class="label label-warning">32 bits</span>');
                ?></td><td>If this version of PHP uses 32-bit integers, file uploads are limited to 2GB</td></tr>
<td>Disabled PHP functions</td><td><?php
                            echo ((function_exists('disk_free_space') == 1) ? '<span class="label label-success">disk_free_space enabled</span>' : '<span class="label label-warning">disk_free_space disabled</span>');
                ?></td><td>OC needs the disk_free_space for the calculation of the free disk space on your server.</td></tr>
<tr><td>HTACCESS</td><td><?php
                            echo (getenv('htaccessWorking') !== false) ? '<span class="label label-success">htaccess environment variable detected</span>' : '<span class="label label-warning">htaccess might not be working</span>';
                ?></td><td>Checks if the server parses htaccess files</td></tr><tr><td>PHP Safe Mode</td><td><?php
                            echo (ini_get("safe_mode")) ? '<span class="label label-warning">Safe Mode On</span>' : '<span class="label label-success">Safe Mode is Off</span>';
                ?></td><td>Checks for the php safe_mode. It should be disabled.</td></tr><tr><td>Apache Modules</td><td><?php
                            echo (function_exists("apache_get_modules") ? '<span class="label label-success">Module List Available</span>' : '<span class="label">apache_get_modules not available</span>');
                ?></td><td>Use apache_get_modules() to show more information</td></tr><tr><td>Apache Mod Rewrite</td><td><?php
                            if (function_exists("apache_get_modules"))
                              {
                                echo (in_array('mod_rewrite', apache_get_modules()) ? '<span class="label label-success">Server Running Mod Rewrite</span>' : '<span class="label label-warning">mod_rewrite could not be detected</span>');
                              }
                            else
                                echo '<span class="label">apache_get_modules not available</span>';
                ?></td><td>mod_rewrite is used for nice urls like 'server.com/apps/calendar' instead of 'server.com/index.php?app=calendar'</td></tr><tr><td>File Permissions</td><td><?php
                            echo ((posix_getuid() == fileowner("./config")) ? '<span class="label label-success">I own the /config directory</span>' : '<span class="label label-warning">I do not own the /config directory</span>');
                            echo '<br>';
                            echo ((posix_getuid() == fileowner("./data")) ? '<span class="label label-success">I own the /data directory</span>' : '<span class="label label-warning">I do not own the /data directory</span>');
                ?></td><td>Check some file permissions as stated on <a href="http://owncloud.org/install/">OwnCloud Support Centre - Install</a></td></tr><tr><td>OwnCloud Config.php</td><td><?php
                            if ((file_exists("./config/config.php")))
                              {
                                echo ('<span class="label label-success">Found config.php</span><br>' . ((is_writable("./config/config.php") ? '<span class="label label-success">Writeable</span>' : '<span class="label label-warning">Not Writeable</span>')));
                              }
                            else
                              {
                                echo '<span class="label label-info">I can not find the config.php</span>';
                              }
                ?></td><td>Check if config.php is present. Also check if it is writable</td></tr><tr><td></td><td><?php
                            echo '';
                ?></td><td></td></tr></tbody></table></div><?php
                            break;
                        case 'serverinfo':
                ?><div class="span10"><h3>Serverinfo</h3><p><span class="label label-info">informational</span><span class="label">value not available</span></p><table class="table table-bordered table-striped"><thead><tr id="info"><th>Information</th><th>Value</th><th>Description</th></tr></thead><tbody><tr><td>Path</td><td><?php
                            echo '<span class="label label-info">' . dirname(__FILE__) . '</span>';
                ?></td><td>The full path to the tools script/your OwnCloud installation</td></tr><tr><td>OS</td><td><?php
                            echo '<span class="label label-info">' . php_uname('s') . '</span><br><span class="label label-info">' . php_uname('v') . '</span>';
                ?></td><td>The operating system of your server</td></tr><tr><td>Machine Type</td><td><?php
                            echo '<span class="label label-info">' . php_uname('m') . '</span>';
                ?></td><td>The machine type</td></tr><tr><td>Server Software</td><td><?php
                            echo '<span class="label label-info">' . $_SERVER['SERVER_SOFTWARE'] . '</span>';
                ?></td><td>HTTP server software used to serve these pages</td></tr><tr><td>PHP.ini</td><td><?php
                            echo (($tmp = php_ini_loaded_file()) !== false) ? '<span class="label label-info">' . realpath($tmp) . '</span>' : '<span class="label">No php.ini loaded</span>';
                ?></td><td>The location of the php.ini file</td></tr><tr><td>Session Directory</td><td><?php
                            echo (($tmp = session_save_path()) !== false) ? '<span class="label label-info">' . realpath($tmp) . '</span>' : '<span class="label">Unable to read the session dir</span>';
                ?></td><td>The location where sessions are saved to</td></tr></tbody></table></div><?php
                            break;
                        case 'perm':
                ?><div class="span5"><h3>File/Directory Permissions</h3><p>On the right side you can see the most important file permission checks.</p><p>Below you can see the complete list of all files and directories. Everything should be readable; write permissions are only required for the config/config.php and the data directory.</p></div><div class="span5"><h4>Permission Tests</h4><p>The config.php is <?php
                            echo (is_writeable('./config/config.php') ? '<span class="label label-success">writeable</span>' : '<span class="label label-warning">not writeable</span>');
                ?>.<br>The data directory is <?php
                            echo (is_writeable('./data/') ? '<span class="label label-success">writeable</span>' : '<span class="label label-warning">not writeable</span>');
                ?></p></div><div class="span10"><table class="table table-bordered table-striped"><thead><tr><th>File/Dir</th><th>READ</th><th>WRITE</th></tr></thead><tbody><?php
                            function printDirTable($d)
                              {
                                $handle = dir($d);
                                while (($f = $handle->read()) !== false)
                                  {
                                    if (in_array($f, array(
                                        '.',
                                        '..',
                                        'README',
                                        'COPYING-AGPL',
                                        'COPYING-README',
                                        'AUTHORS'
                                    )))
                                        continue;
                                    if (is_dir($d . '/' . $f))
                                      {
                                        echo '<tr><th>' . $d . '/' . $f . '</th><td>' . (is_readable($d . '/' . $f) ? success('read') : warning('read')) . '</td><td>' . (is_writable($d . '/' . $f) ? success('write') : warning('write')) . '</td></tr>';
                                        printDirTable($d . '/' . $f);
                                      }
                                    else
                                      {
                                        echo '<tr><td>' . $d . '/' . $f . '</td><td>' . (is_readable($d . '/' . $f) ? success('read') : warning('read')) . '</td><td>' . (is_writable($d . '/' . $f) ? success('write') : warning('write')) . '</td></tr>';
                                      }
                                    /* if */
                                  }
                                /* while */
                              }
                            /* function */
                            printDirTable('.');
                            echo '</tbody></table></div>';
                            break;
                        case 'tool':
                            if (true || PHP_OS == "Linux")
                              {
                ?><div class="span5"><h3>chmod-Tool</h3><p>This tool allows you to change the permissions on your data folder. Please note that this may open the way for everybody to steal your files off the data directory!</p><a class="btn btn-danger" href="?do=toolchmod&mask=0777">Set to 777</a><a class="btn btn-primary" href="?do=toolchmod&mask=0770">Set to 770</a></div><?php
                              }
                            /* IF LINUX */
                ?><div class="span5"><h3>Ping Tool</3><p>With the ping tool you can check whether your OwnCloud instance is reachable from the internet. For that, OC Tools will contact an external server at <span class="label label-inverse">kycdn.net</span>.</p><a class="btn btn-inverse" href="?do=toolping">ask kycdn.net</a></div><?php
                            break;
                        case 'toolping':
                            function myErrorHandler($fehlercode, $fehlertext, $fehlerdatei, $fehlerzeile)
                              {
                                echo "kycdn could not be contacted.";
                              }
                            set_error_handler('myErrorHandler');
                            $fh = fopen("http://oc.kycdn.net/tools/ping.php?host=" . $_SERVER['HTTP_HOST'] . "&url=" . $_SERVER['REQUEST_URI'], "r");
                            restore_error_handler();
                            echo ("<span class='span5'><h3>Ping Tool</h3><p>Server response:</p><span class='label label-inverse'>" . htmlspecialchars(fread($fh, 1024)) . "</span></div>");
                            fclose($fh);
                            break;
                        case 'toolchmod':
                            function chmod_R($path, $filemode, $dirmode)
                              {
                                if (is_dir($path))
                                  {
                                    if (!chmod($path, $dirmode))
                                      {
                                        $dirmode_str = decoct($dirmode);
                                        echo "Failed applying filemode '$dirmode_str' on directory '$path'\n";
                                        return;
                                      }
                                    $dh = opendir($path);
                                    while (($file = readdir($dh)) !== false)
                                      {
                                        if ($file != '.' && $file != '..')
                                          {
                                            $fullpath = $path . '/' . $file;
                                            chmod_R($fullpath, $filemode, $dirmode);
                                          }
                                      }
                                    closedir($dh);
                                  }
                                else
                                  {
                                    if (is_link($path))
                                      {
                                        echo "link '$path' is skipped\n";
                                        return;
                                      }
                                    if (!chmod($path, $filemode))
                                      {
                                        $filemode_str = decoct($filemode);
                                        print "Failed applying filemode '$filemode_str' on file '$path'\n";
                                        return;
                                      }
                                  }
                              }
                            if ($_GET['mask'] == "0777")
                                chmod_R("./data", 0777, 0777);
                            else
                                chmod_R("./data", 0770, 0770);
                            echo '<div class="span5"><h3>chmod-Tool</h3><p>Permissions set to ' . $_GET['mask'] . '</p><a href="?do=tool">back to Tools</a></div>';
                            break;
                        case 'install-cancel':
                            if (file_exists('./owncloud.tar.gz'))
                                unlink('./owncloud.tar.gz');
                            if (file_exists('./owncloud.dev.tar.gz'))
                                unlink('./owncloud.dev.tar.gz');
                            echo ('<div class="span5"><h3>Operation canceled</h3></div>');
                            break;
                        case 'install-pre':
                            echo ('<div class="span5"><h3>Install</h3><p>This will install OwnCloud in the current directory. Please note that the page will load as long as the download is in progress...depending on the servers internet connection, this may take a while.</p>' . (is_writeable('.') ? '<a href="#" rel="tooltip" title="Currently not available" class="btn btn-inverse disabled">OwnCloud.org::Stable Release</a><a href="?do=install-dl-dev" rel="tooltip" title="Development releases may be unstable!" class="btn btn-inverse">OwnCloud.org::Development Release</a>' : important('The directory is not writeable')) . '<a href="?do=install-cancel" class="btn btn-danger">Cancel</a></div>');
                            break;
                        case 'install-dl':
                            echo ("nonono!");
                            break;
                        case 'install-dl-dev':
                            file_put_contents("owncloud.dev.tar", readgzfile("owncloud.dev.tar.gz"));
                            break;
                        case 'install-1':
                            break;
                        case 'user':
                ?><div class="span10"><h3>User Batch Tool</h3><p>Some little tools to manage users</p><div class="row"><div class="span5"><h4>Batch Import</h4><p>This feature allows you to add a lot of users at once. Possible formats are:</p><h5>CSV</h5><code>USER,PASSWORD_SHA1ed</code><hr><p><button class="btn btn-primary">Upload CSV</button></p></div><!-- span5 --><div class="span5"><h4>User Modification</h4><p>Add, Edit or Delete a user. Be careful :)</p><form id="usrform"><input name="username" type="text" placeholder="Username OR ID"><br><button class="btn btn-success" type="submit">Add</button> <button class="btn btn-info" type="submit">Edit</button><button class="btn btn-danger" type="button" onclick="$('#myModal').modal('show')">Delete</button></form><div class="modal hide" id="myModal"><div class="modal-header"><button class="close" data-dismiss="modal">×</button><h3>User Management Tool</h3></div><div class="modal-body"><p>You are about to delete a user record off the database.</p><p class="label label-info">You should not use this feature unless you are 100% sure about what you're doing ;)</p></div><div class="modal-footer"><a href="#" onclick="$('#usrform').submit()"class="btn">Delete User</a><a href="#" onclick="$('#myModal').modal('hide')" class="btn btn-primary">Close</a></div><!-- modal-footer--></div><!-- modal --></div><!-- span5 --></div><!-- row in span10 --></div><!-- span10 --><?php
                            break;
                        case 'logout':
                            session_destroy();
                ?><div class="span6"><h4>Logout complete</h4><a href=".">Contine to OC</a></div><?php
                            break;
                        case 'home':
                            echo ('<div class="span10"><h3>OwnCloud Tools [' . version . ']</h3><p>You are connecting from IP</p><code>' . $_SERVER['REMOTE_ADDR'] . '</code><p>Your client is</p><code>' . $_SERVER['HTTP_USER_AGENT'] . '</code></div><div class="span10" style="text-align: center"><hr>' . $_SERVER['SERVER_SIGNATURE'] . '</div>');
                            break;
                    }
                    /*switch*/
                  }
                ?></div><!-- row(1) --><div class="row"><div class="span6 offset3"><p style="text-align: center"><a onclick="$('#kyModal').modal('show')" href="#">About this script</a></p></div></div><!-- row(2) --></div><!-- content --><div class="modal hide" id="kyModal"><div class="modal-header"><button class="close" data-dismiss="modal">×</button><h3>Information</h3><span class="label label-info">OwnCloud Tools <?php
                echo (version);
                ?></span></div><div class="modal-body"><p>This script is designed to help end users to find errors in their OwnCloud installation. Please do not use features you dont understand. Some functions directly interact with the database and can cause errors in the OwnCloud software.</p><p>Interface built with the help of <a class="label label-inverse" href="http://twitter.github.com/bootstrap/">bootstrap</a>. Javascript and Stylesheets required are hosted by <a class="label label-inverse" href="http://forum.owncloud.org/memberlist.php?mode=viewprofile&u=93">Dennis Kuypers (snapr)</a> at <a class="label label-inverse" href="http://kycdn.net">kycdn.net</a></p><hr><h5>Colorcodes:</h5><span class="label">not available</span><span class="label label-info">Information</span><span class="label label-inverse">external resource, requires internet connection</span><br><span class="label label-success">Success, Good</span><span class="label label-warning">warning, possible problem</span><span class="label label-important">error, failure, bad value</span></div><div class="modal-footer"><a href="#" onclick="$('#kyModal').modal('hide')" class="btn btn-inverse">Close</a></div></div><script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.0/js/bootstrap.min.js"></script></body></html>
Last edited by snapr on Fri Apr 04, 2014 5:58 pm, edited 6 times in total.
I am currently not active on these forums.

Best regards
snapr

ovidiu
Beginner
Posts: 44
Joined: Sun Jun 24, 2012 10:16 pm

Re: OwnCloud Tools

Postby ovidiu » Fri Jul 06, 2012 7:58 am

I tried using this script of yours and it kinda works but it also gives me error messages in my server logs, see here please.

I don't understand why this tool would try to look/access /var/www/conf/web47/php.ini when I have OC installed in /var/www/conf/web47/web/ which is my web root folder.

Code: Select all

[Fri Jul 06 07:52:51 2012] [warn] [client 196.215.70.23] mod_fcgid: stderr: PHP Warning:  realpath(): open_basedir restriction in effect. File(/var/www/conf/web47/php.ini) is not within the allowed path(s): (/var/www/clients/client20/web47/web:/var/www/clients/client20/web47/tmp:/var/www/cloud.premaman.co.za/web:/usr/share/php5:/usr/share/php/PEAR:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin:/usr/share/php:/usr/share/squirrelmail:/srv/www/cloud.premaman.co.za/web:/var/www/clients/client20/web47/data:/var/www/cloud.premaman.co.za/web:/srv/www/cloud.premaman.co.za/data:) in /var/www/clients/client20/web47/web/check.php on line 1, referer: http://cloud.premaman.co.za/check.php
Environment: Debian 6.0.5
Server: own root server
Database: MySQL 5.1.63
Client: MAC Lion
OC-Version: 4.0.4
PHP-Version: 5.3.3-7+squeeze13

rakekniven
Inventory
Posts: 2019
Joined: Sun May 06, 2012 3:31 pm
ownCloud version: 9.0.1
Webserver: Apache
Database: MySQL
OS: Linux Hosting Package
PHP version: 5.6.x
Contact:

Re: OwnCloud Tools

Postby rakekniven » Fri Aug 24, 2012 5:37 pm

Just used your script.
Works flawlessly.

Could you format your source nicely. Makes it easier when looking into it in detail.

Thx.
ownCloud is not only about files. There is so much more. Explore the apps to extend your ownCloud.

RosaWeiss
Newbie
Posts: 1
Joined: Wed Oct 03, 2012 1:01 pm

Re: OwnCloud Tools

Postby RosaWeiss » Wed Oct 03, 2012 1:20 pm

Thanks a lot for this tutorial! The code was very useful, especially for those who have just begun learning it
mp4 to wmv http://mp4towmvconverter.net/

User avatar
RandolphCarter
ownCloud master
Posts: 5134
Joined: Wed May 30, 2012 8:42 am
ownCloud version: 8.1.1
Webserver: Apache
Database: MySQL
OS: Linux
PHP version: 5.5.x

Re: OwnCloud Tools

Postby RandolphCarter » Tue Oct 30, 2012 11:28 am

Hm, 'oc.kycdn.net' doesn't seem to be available at the moment...

One small enhancement request on the script itself: It doesn't consider the 'datadirectory' setting in the config.php yet, but fixedly checks the 'data' subdirectory for permissions&ownership.

rakekniven
Inventory
Posts: 2019
Joined: Sun May 06, 2012 3:31 pm
ownCloud version: 9.0.1
Webserver: Apache
Database: MySQL
OS: Linux Hosting Package
PHP version: 5.6.x
Contact:

Re: OwnCloud Tools

Postby rakekniven » Tue Oct 30, 2012 4:19 pm

Looks like user snapr ist not active at all anymore :(

@RandolphCarter Could you provide a change to handle 'datadirectory'.
I can modify the script.

We have to change 'oc.kycdn.net' if nothing happens from snapr side.
ownCloud is not only about files. There is so much more. Explore the apps to extend your ownCloud.

User avatar
RandolphCarter
ownCloud master
Posts: 5134
Joined: Wed May 30, 2012 8:42 am
ownCloud version: 8.1.1
Webserver: Apache
Database: MySQL
OS: Linux
PHP version: 5.5.x

Re: OwnCloud Tools

Postby RandolphCarter » Tue Oct 30, 2012 4:26 pm

I have a first version using bootstrap versions from bootstrapcdn (as suggested here) already.

This doesn't yet include the fix for the 'datadirectory', don't have time for that at the moment; with 'oc.kycdn.net' gone, also the ping tool doesn't work anymore. Anybody got a replacement for that?

Code: Select all

        <?php
    $PASSWORD = '';
    /* Please enter a password here ;) ***** Tools Script for OwnCloud 4 by Dennis Kuypers (snapr) -
     * adapted for hosted css/js by (RandolphCarter)
    * please report problems or experiences at http://forum.owncloud.org/viewtopic.php?f=8&t=2921 */
    define('version', 'rev.02');
    if (isset($_GET['PING']))
        die("pong");
    if (!session_start())
        die("Either your client does not allow/support cookies OR the server can not start a session");
    if (isset($_POST['tpw']))
      {
        $_SESSION['tpw'] = $_POST['tpw'];
      }
    $do = (isset($_GET["do"]) ? $_GET["do"] : 'home');
    if (isset($_SESSION['tpw']) && $_SESSION['tpw'] == $PASSWORD && isset($_GET['phpinfo']))
      {
        phpinfo();
        exit;
      }
    ?><!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>OwnCloud Tools</title><link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.0/css/bootstrap.min.css" rel="stylesheet"></head><body><div class="container"><div class="row" style="margin-top: 20px"><div class="span2"><ul class="well nav nav-list"><?php
    if (isset($_SESSION['tpw']) && $_SESSION['tpw'] == $PASSWORD)
      {
    ?><li class="<?php
        echo ($do == 'home' ? 'active' : '');
    ?>"><a href="?do=home"><i class="icon-home"></i> Overview</a></li><li class="<?php
        echo ($do == 'serverinfo' ? 'active' : '');
    ?>"><a href="?do=serverinfo"><i class="icon-info-sign"></i> Serverinfo</a></li><li class="<?php
        echo ($do == 'test' ? 'active' : '');
    ?>"><a href="?do=test"><i class="icon-question-sign"></i> Run Tests</a></li><li class="<?php
        echo (substr($do, 0, 4) == 'tool' ? 'active' : '');
    ?>"><a href="?do=tool"><i class="icon-wrench"></i> Tools</a></li><li><a href="?phpinfo=show"><i class="icon-th-list"></i> PHPinfo</a></li><li class="<?php
        echo ($do == 'fs' ? 'active' : '');
    ?>"><a href="?do=perm"><i class="icon-file"></i> File Perm.</a></li><!--<li class="nav-header">OC4</li><li class="<?php
        echo (substr($do, 0, 7) == 'install' ? 'active' : '');
    ?>"><a href="#" onclick="alert('Sorry, not working right now');"><i class="icon-download-alt"></i> Install</a></li><li class="<?php
        echo (substr($do, 0, 7) == 'browser' ? 'active' : '');
    ?>"><a href="?do=browser"><i class="icon-share"></i> Browse Data</a></li><li class="<?php
        echo (substr($do, 0, 5) == 'login' ? 'active' : '');
    ?>"><a href="?do=login-pre"><i class="icon-user"></i> Fake Login</a></li>--><li class="nav-header">Menu</li><li><a href="./index.php"><i class="icon-globe"></i> visit this OC</a></li><li><a href="?do=logout"><i class="icon-remove"></i> Logout</a></li><?php
      }
    ?><li class="nav-header">External</li><li><a href="http://owncloud.org/"><i class="icon-share"></i> OC.org</a></li><li><a href="http://owncloud.com/"><i class="icon-share"></i> OC.com</a></li><li><a href="http://forum.owncloud.org/"><i class="icon-share"></i> Forum</a></li><li><a href="http://bugs.owncloud.org/"><i class="icon-share"></i> Bugtracker</a></li></ul><?php
    echo "</div>";
    if ($PASSWORD == "")
      {
    ?><div class="modal" id="noModal"><div class="modal-header"><h3>Before we can start</h3></div><div class="modal-body"><p>Please edit line 1 in <?php
        echo basename(__FILE__);
    ?></p></div><div class="modal-footer"><a href="?do=home" class="btn btn-info">Continue</a></div></div><?php
      }
    elseif (!isset($_SESSION['tpw']) || $_SESSION['tpw'] != $PASSWORD)
      {
    ?><div class="span5"><h3>Login</h3><form action="" method="post"><input name="tpw" type="password" placeholder="Password"><br><button type="submit" class="btn btn-danger">Use at own risk</button></form></div><?php
      }
    else
      {
        function success($txt)
          {
            return '<span class="label label-success">' . $txt . '</span>';
          }
        function warning($txt)
          {
            return '<span class="label label-warning">' . $txt . '</span>';
          }
        function important($txt)
          {
            return '<span class="label label-important">' . $txt . '</span>';
          }
        switch ($do)
        {
            case 'test':
    ?><div class="span10"><h3>Tests</h3><p>Some tests are apache2 specific. Please note that various features might work on other servers, although this script states the opposite.<br><span class="label">value not available</span><span class="label label-success">good result</span><span class="label label-warning">possible problems/restrictions</span><span class="label label-important">serious issue, OC will most likely not work</span></p><table class="table table-bordered table-striped"><thead><tr id="test"><th>Test</th><th>Result</th><th>Description</th></tr></thead><tbody><tr><td>PHP Version</td><td><?php
                if (version_compare("5.3", phpversion()) == -1)
                    echo '<span class="label label-success">You are running ' . phpversion() . '</span>';
                else
                    echo '<span class="label label-important">Your PHP is outdated! You are running ' . phpversion() . '</span>';
    ?></td><td>Minimum version required for OwnCloud: 5.3.x</td></tr><tr><td>HTACCESS</td><td><?php
                echo (getenv('htaccessWorking') !== false) ? '<span class="label label-success">htaccess environment variable detected</span>' : '<span class="label label-warning">htaccess might not be working</span>';
    ?></td><td>Checks if the server parses htaccess files</td></tr><tr><td>PHP Safe Mode</td><td><?php
                echo (ini_get("safe_mode")) ? '<span class="label label-warning">Safe Mode On</span>' : '<span class="label label-success">Safe Mode is Off</span>';
    ?></td><td>Checks for the php safe_mode. It should be disabled.</td></tr><tr><td>Apache Modules</td><td><?php
                echo (function_exists("apache_get_modules") ? '<span class="label label-success">Module List Available</span>' : '<span class="label">apache_get_modules not available</span>');
    ?></td><td>Use apache_get_modules() to show more information</td></tr><tr><td>Apache Mod Rewrite</td><td><?php
                if (function_exists("apache_get_modules"))
                  {
                    echo (in_array('mod_rewrite', apache_get_modules()) ? '<span class="label label-success">Server Running Mod Rewrite</span>' : '<span class="label label-warning">mod_rewrite could not be detected</span>');
                  }
                else
                    echo '<span class="label">apache_get_modules not available</span>';
    ?></td><td>mod_rewrite is used for nice urls like 'server.com/apps/calendar' instead of 'server.com/index.php?app=calendar'</td></tr><tr><td>File Permissions</td><td><?php
                echo ((getmyuid() == fileowner("./config")) ? '<span class="label label-success">I own the /config directory</span>' : '<span class="label label-warning">I do not own the /config directory</span>');
                echo '<br>';
                echo ((getmyuid() == fileowner("./data")) ? '<span class="label label-success">I own the /data directory</span>' : '<span class="label label-warning">I do not own the /data directory</span>');
    ?></td><td>Check some file permissions as stated on <a href="http://owncloud.org/install/">OwnCloud Support Centre - Install</a></td></tr><tr><td>OwnCloud Config.php</td><td><?php
                if ((file_exists("./config/config.php")))
                  {
                    echo ('<span class="label label-success">Found config.php</span><br>' . ((is_writable("./config/config.php") ? '<span class="label label-success">Writeable</span>' : '<span class="label label-warning">Not Writeable</span>')));
                  }
                else
                  {
                    echo '<span class="label label-info">I can not find the config.php</span>';
                  }
    ?></td><td>Check if config.php is present. Also check if it is writable</td></tr><tr><td></td><td><?php
                echo '';
    ?></td><td></td></tr></tbody></table></div><?php
                break;
            case 'serverinfo':
    ?><div class="span10"><h3>Serverinfo</h3><p><span class="label label-info">informational</span><span class="label">value not available</span></p><table class="table table-bordered table-striped"><thead><tr id="info"><th>Information</th><th>Value</th><th>Description</th></tr></thead><tbody><tr><td>Path</td><td><?php
                echo '<span class="label label-info">' . dirname(__FILE__) . '</span>';
    ?></td><td>The full path to the tools script/your OwnCloud installation</td></tr><tr><td>OS</td><td><?php
                echo '<span class="label label-info">' . php_uname('s') . '</span><br><span class="label label-info">' . php_uname('v') . '</span>';
    ?></td><td>The operating system of your server</td></tr><tr><td>Machine Type</td><td><?php
                echo '<span class="label label-info">' . php_uname('m') . '</span>';
    ?></td><td>The machine type</td></tr><tr><td>Server Software</td><td><?php
                echo '<span class="label label-info">' . $_SERVER['SERVER_SOFTWARE'] . '</span>';
    ?></td><td>HTTP server software used to serve these pages</td></tr><tr><td>PHP.ini</td><td><?php
                echo (($tmp = php_ini_loaded_file()) !== false) ? '<span class="label label-info">' . realpath($tmp) . '</span>' : '<span class="label">No php.ini loaded</span>';
    ?></td><td>The location of the php.ini file</td></tr><tr><td>Session Directory</td><td><?php
                echo (($tmp = session_save_path()) !== false) ? '<span class="label label-info">' . realpath($tmp) . '</span>' : '<span class="label">Unable to read the session dir</span>';
    ?></td><td>The location where sessions are saved to</td></tr></tbody></table></div><?php
                break;
            case 'perm':
    ?><div class="span5"><h3>File/Directory Permissions</h3><p>On the right side you can see the most important file permission checks.</p><p>Below you can see the complete list of all files and directories. Everything should be readable; write permissions are only required for the config/config.php and the data directory.</p></div><div class="span5"><h4>Permission Tests</h4><p>The config.php is <?php
                echo (is_writeable('./config/config.php') ? '<span class="label label-success">writeable</span>' : '<span class="label label-warning">not writeable</span>');
    ?>.<br>The data directory is <?php
                echo (is_writeable('./data/') ? '<span class="label label-success">writeable</span>' : '<span class="label label-warning">not writeable</span>');
    ?></p></div><div class="span10"><table class="table table-bordered table-striped"><thead><tr><th>File/Dir</th><th>READ</th><th>WRITE</th></tr></thead><tbody><?php
                function printDirTable($d)
                  {
                    $handle = dir($d);
                    while (($f = $handle->read()) !== false)
                      {
                        if (in_array($f, array(
                            '.',
                            '..',
                            'README',
                            'COPYING-AGPL',
                            'COPYING-README',
                            'AUTHORS'
                        )))
                            continue;
                        if (is_dir($d . '/' . $f))
                          {
                            echo '<tr><th>' . $d . '/' . $f . '</th><td>' . (is_readable($d . '/' . $f) ? success('read') : warning('read')) . '</td><td>' . (is_writable($d . '/' . $f) ? success('write') : warning('write')) . '</td></tr>';
                            printDirTable($d . '/' . $f);
                          }
                        else
                          {
                            echo '<tr><td>' . $d . '/' . $f . '</td><td>' . (is_readable($d . '/' . $f) ? success('read') : warning('read')) . '</td><td>' . (is_writable($d . '/' . $f) ? success('write') : warning('write')) . '</td></tr>';
                          }
                        /* if */
                      }
                    /* while */
                  }
                /* function */
                printDirTable('.');
                echo '</tbody></table></div>';
                break;
            case 'tool':
                if (true || PHP_OS == "Linux")
                  {
    ?><div class="span5"><h3>chmod-Tool</h3><p>This tool allows you to change the permissions on your data folder. Please note that this may open the way for everybody to steal your files off the data directory!</p><a class="btn btn-danger" href="?do=toolchmod&mask=0777">Set to 777</a><a class="btn btn-primary" href="?do=toolchmod&mask=0770">Set to 770</a></div><?php
                  }
                /* IF LINUX */
    ?><div class="span5"><h3>Ping Tool</3><p>With the ping tool you can check wether your OwnCloud instance is reachable from the internet. For that, OC Tools will contact an external server at <span class="label label-inverse">kycdn.net</span>.</p><a class="btn btn-inverse" href="?do=toolping">ask kycdn.net</a></div><?php
                break;
            case 'toolping':
                function myErrorHandler($fehlercode, $fehlertext, $fehlerdatei, $fehlerzeile)
                  {
                    echo "kycdn could not be contacted.";
                  }
                set_error_handler('myErrorHandler');
                $fh = fopen("http://oc.kycdn.net/tools/ping.php?host=" . $_SERVER['HTTP_HOST'] . "&url=" . $_SERVER['REQUEST_URI'], "r");
                restore_error_handler();
                echo ("<span class='span5'><h3>Ping Tool</h3><p>Server response:</p><span class='label label-inverse'>" . htmlspecialchars(fread($fh, 1024)) . "</span></div>");
                fclose($fh);
                break;
            case 'toolchmod':
                function chmod_R($path, $filemode, $dirmode)
                  {
                    if (is_dir($path))
                      {
                        if (!chmod($path, $dirmode))
                          {
                            $dirmode_str = decoct($dirmode);
                            echo "Failed applying filemode '$dirmode_str' on directory '$path'\n";
                            return;
                          }
                        $dh = opendir($path);
                        while (($file = readdir($dh)) !== false)
                          {
                            if ($file != '.' && $file != '..')
                              {
                                $fullpath = $path . '/' . $file;
                                chmod_R($fullpath, $filemode, $dirmode);
                              }
                          }
                        closedir($dh);
                      }
                    else
                      {
                        if (is_link($path))
                          {
                            echo "link '$path' is skipped\n";
                            return;
                          }
                        if (!chmod($path, $filemode))
                          {
                            $filemode_str = decoct($filemode);
                            print "Failed applying filemode '$filemode_str' on file '$path'\n";
                            return;
                          }
                      }
                  }
                if ($_GET['mask'] == "0777")
                    chmod_R("./data", 0777, 0777);
                else
                    chmod_R("./data", 0770, 0770);
                echo '<div class="span5"><h3>chmod-Tool</h3><p>Permissions set to ' . $_GET['mask'] . '</p><a href="?do=tool">back to Tools</a></div>';
                break;
            case 'install-cancel':
                if (file_exists('./owncloud.tar.gz'))
                    unlink('./owncloud.tar.gz');
                if (file_exists('./owncloud.dev.tar.gz'))
                    unlink('./owncloud.dev.tar.gz');
                echo ('<div class="span5"><h3>Operation canceled</h3></div>');
                break;
            case 'install-pre':
                echo ('<div class="span5"><h3>Install</h3><p>This will install OwnCloud in the current directory. Please note that the page will load as long as the download is in progress...depending on the servers internet connection, this may take a while.</p>' . (is_writeable('.') ? '<a href="#" rel="tooltip" title="Currently not available" class="btn btn-inverse disabled">OwnCloud.org::Stable Release</a><a href="?do=install-dl-dev" rel="tooltip" title="Development releases may be unstable!" class="btn btn-inverse">OwnCloud.org::Development Release</a>' : important('The directory is not writeable')) . '<a href="?do=install-cancel" class="btn btn-danger">Cancel</a></div>');
                break;
            case 'install-dl':
                echo ("nonono!");
                break;
            case 'install-dl-dev':
                file_put_contents("owncloud.dev.tar", readgzfile("owncloud.dev.tar.gz"));
                break;
            case 'install-1':
                break;
            case 'user':
    ?><div class="span10"><h3>User Batch Tool</h3><p>Some little tools to manage users</p><div class="row"><div class="span5"><h4>Batch Import</h4><p>This feature allows you to add a lot of users at once. Possible formats are:</p><h5>CSV</h5><code>USER,PASSWORD_SHA1ed</code><hr><p><button class="btn btn-primary">Upload CSV</button></p></div><!-- span5 --><div class="span5"><h4>User Modification</h4><p>Add, Edit or Delete a user. Be careful :)</p><form id="usrform"><input name="username" type="text" placeholder="Username OR ID"><br><button class="btn btn-success" type="submit">Add</button> <button class="btn btn-info" type="submit">Edit</button><button class="btn btn-danger" type="button" onclick="$('#myModal').modal('show')">Delete</button></form><div class="modal hide" id="myModal"><div class="modal-header"><button class="close" data-dismiss="modal">×</button><h3>User Management Tool</h3></div><div class="modal-body"><p>You are about to delete a user record off the database.</p><p class="label label-info">You should not use this feature unless you are 100% sure about what you're doing ;)</p></div><div class="modal-footer"><a href="#" onclick="$('#usrform').submit()"class="btn">Delete User</a><a href="#" onclick="$('#myModal').modal('hide')" class="btn btn-primary">Close</a></div><!-- modal-footer--></div><!-- modal --></div><!-- span5 --></div><!-- row in span10 --></div><!-- span10 --><?php
                break;
            case 'logout':
                session_destroy();
    ?><div class="span6"><h4>Logout complete</h4><a href=".">Contine to OC</a></div><?php
                break;
            case 'home':
                echo ('<div class="span10"><h3>OwnCloud Tools [' . version . ']</h3><p>You are connecting from IP</p><code>' . $_SERVER['REMOTE_ADDR'] . '</code><p>Your client is</p><code>' . $_SERVER['HTTP_USER_AGENT'] . '</code></div><div class="span10" style="text-align: center"><hr>' . $_SERVER['SERVER_SIGNATURE'] . '</div>');
                break;
        }
        /*switch*/
      }
    ?></div><!-- row(1) --><div class="row"><div class="span6 offset3"><p style="text-align: center"><a onclick="$('#kyModal').modal('show')" href="#">About this script</a></p></div></div><!-- row(2) --></div><!-- content --><div class="modal hide" id="kyModal"><div class="modal-header"><button class="close" data-dismiss="modal">×</button><h3>Information</h3><span class="label label-info">OwnCloud Tools <?php
    echo (version);
    ?></span></div><div class="modal-body"><p>This script is designed to help end users to find errors in their OwnCloud installation. Please do not use features you dont understand. Some functions directly interact with the database and can cause errors in the OwnCloud software.</p><p>Interface built with the help of <a class="label label-inverse" href="http://twitter.github.com/bootstrap/">bootstrap</a>. Javascript and Stylesheets required are hosted by <a class="label label-inverse" href="http://forum.owncloud.org/memberlist.php?mode=viewprofile&u=93">Dennis Kuypers (snapr)</a> at <a class="label label-inverse" href="http://kycdn.net">kycdn.net</a></p><hr><h5>Colorcodes:</h5><span class="label">not available</span><span class="label label-info">Information</span><span class="label label-inverse">external resource, requires internet connection</span><br><span class="label label-success">Success, Good</span><span class="label label-warning">warning, possible problem</span><span class="label label-important">error, failure, bad value</span></div><div class="modal-footer"><a href="#" onclick="$('#kyModal').modal('hide')" class="btn btn-inverse">Close</a></div></div><script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.0/js/bootstrap.min.js"></script></body></html>

Andybike10
Newbie
Posts: 1
Joined: Sat Nov 03, 2012 1:46 pm

Re: OwnCloud Tools

Postby Andybike10 » Sat Nov 03, 2012 2:18 pm

Really its very effective tools and thanks to shared this.

rakekniven
Inventory
Posts: 2019
Joined: Sun May 06, 2012 3:31 pm
ownCloud version: 9.0.1
Webserver: Apache
Database: MySQL
OS: Linux Hosting Package
PHP version: 5.6.x
Contact:

Re: OwnCloud Tools

Postby rakekniven » Fri Nov 23, 2012 6:33 pm

RandolphCarter wrote:I have a first version using bootstrap versions from bootstrapcdn (as suggested here) already.


Just updated first post with your changes.

Now we have to solve ping function.
ownCloud is not only about files. There is so much more. Explore the apps to extend your ownCloud.

snapr
Admin
Posts: 108
Joined: Mon Jan 30, 2012 9:32 pm

Re: OwnCloud Tools

Postby snapr » Fri Nov 30, 2012 2:13 pm

The original code for the ping script is

Code: Select all

<?php
die("!R(JDWLKA");
if(!isset($_GET['url']) || !isset($_GET['host'])) die("Invalid Request");
if(! gethostbyname($_GET['host'])) die($_GET["host"]." is not a valid internet host name.");
$url = explode("?",$_GET['url']);$url=$url[0];
if($url=="") die("Invalid URL");
$fh = fopen("http://".$_GET['host'].$url."?PING=kycdn.net","r");
if(fread($fh,4)=="pong") die("Success!");
echo ("Unable to reach ".$_GET['host'].$url); ?>
I am currently not active on these forums.

Best regards
snapr


Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 1 guest