Page MenuHomeGitPull.it

No OneTemporary

Authored By
Unknown
Size
21 KB
Referenced Files
None
Subscribers
None
diff --git a/include/class-Domain.php b/include/class-Domain.php
index e6ea78e..cf5df76 100644
--- a/include/class-Domain.php
+++ b/include/class-Domain.php
@@ -1,77 +1,86 @@
<?php
# Copyright (C) 2018 Valerio Bozzolan
# Boz Libre Hosting Panel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
/**
* A domain handled by the user
*/
class Domain extends Queried {
const T = 'domain';
const UID = 'domain_name';
public function __construct() {
$this->integers( 'domain_ID' );
$this->booleans( 'domain_active' );
$this->dates( 'domain_born', 'domain_expiration' );
}
/**
* Get domain ID
*
* @return int
*/
public function getDomainID() {
return $this->get( 'domain_ID' );
}
/**
* Get domain name
*
* @return string
*/
public function getDomainName() {
return $this->get( 'domain_name' );
}
/**
* Get the domain edit URl
*
* @return string
*/
public function getDomainPermalink( $absolute = false ) {
return ROOT . '/domain.php/' . $this->get( 'domain_name' );
}
/**
* Factory mailbox from this domain
*
* @return MailboxFullAPI
*/
public function factoryMailbox() {
return ( new MailboxFullAPI() )->whereDomain( $this );
}
/**
* Factory e-mail forward from this domain
*
* @return MailforwardFullAPI
*/
public function factoryMailforwardfrom() {
return ( new MailforwardfromAPI() )->whereDomain( $this );
}
+ /**
+ * Factory FTP users from this domain
+ *
+ * @return FTPAPI
+ */
+ public function factoryFTP() {
+ return ( new FTPAPI() )->whereDomain( $this );
+ }
+
}
diff --git a/include/class-FTP.php b/include/class-FTP.php
new file mode 100644
index 0000000..97e9d7c
--- /dev/null
+++ b/include/class-FTP.php
@@ -0,0 +1,84 @@
+<?php
+# Copyright (C) 2019 Valerio Bozzolan
+# Boz Libre Hosting Panel
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * An FTP user
+ */
+class FTP extends Domain {
+
+ const T = 'ftp';
+
+ /**
+ * Constructor
+ *
+ * Normalize the object obtained from the database
+ */
+ public function __construct() {
+ $this->booleans( 'ftp_active' );
+ $this->integers( 'ftp_ulbandwidth',
+ 'ftp_dlbandwidth',
+ 'ftp_quotasize',
+ 'ftp_quotafiles' );
+ }
+
+ /**
+ * Get the FTP login username
+ *
+ * @return string E-mail
+ */
+ public function getFTPLogin() {
+ return $this->get( 'ftp_login' );
+ }
+
+ /**
+ * Check if this FTP account is active
+ *
+ * @return bool
+ */
+ public function isFTPActive() {
+ return $this->get( 'ftp_active' );
+ }
+
+ /**
+ * Get the mailbox permalink
+ *
+ * @return string
+ */
+ public function getFTPPermalink( $absolute = false ) {
+ return FTP::permalink(
+ $this->getDomainName(),
+ $this->getFTPLogin()
+ );
+ }
+
+ /**
+ * Get the FTP permalink from domain name and FTP login
+ *
+ * @param string $domain Domain name
+ * @param string $login FTP user login
+ * @return string
+ */
+ public static function permalink( $domain, $login ) {
+ return sprintf(
+ '%s/%s/%s',
+ ROOT . '/ftp.php',
+ $domain,
+ $login
+ );
+ }
+
+}
diff --git a/include/class-FTPAPI.php b/include/class-FTPAPI.php
new file mode 100644
index 0000000..cd47a1f
--- /dev/null
+++ b/include/class-FTPAPI.php
@@ -0,0 +1,65 @@
+<?php
+# Copyright (C) 2019 Valerio Bozzolan
+# Boz Libre Hosting Panel
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * FTP users API
+ */
+class FTPAPI extends DomainAPI {
+
+ public function __construct() {
+ Query::__construct();
+ $this->from( FTP::T );
+ $this->defaultClass( 'FTP' );
+ }
+
+ /**
+ * Join FTP and domain tables (once)
+ *
+ * @return self
+ */
+ public function joinFTPDomain() {
+ if( empty( $this->joinedFTPDomain ) ) {
+ $this->joinedFTPDomain = true;
+
+ $this->from( 'domain' );
+ $this->equals( 'domain.domain_ID', 'ftp.domain_ID' );
+ }
+ return $this;
+ }
+
+ /**
+ * Filter to a certain FTP login
+ *
+ * @param string $login
+ * @return self
+ */
+ public function whereFTPLogin( $login ) {
+ return $this->whereStr( 'ftp_login', $login );
+ }
+
+ /**
+ * Filter to a certain domain ID
+ *
+ * @param int $id int
+ * @return self
+ * @override
+ */
+ public function whereDomainID( $id ) {
+ return $this->whereInt( 'ftp.domain_ID', $id );
+ }
+
+}
diff --git a/load-post.php b/load-post.php
index 34b3cdf..999a756 100644
--- a/load-post.php
+++ b/load-post.php
@@ -1,84 +1,85 @@
<?php
# Copyright (C) 2018 Valerio Bozzolan
# Boz Libre Hosting Panel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
// include path
define_default( 'INCLUDE_PATH', ABSPATH . __ . 'include' );
// template path
define_default( 'TEMPLATE_PATH', ABSPATH . __ . 'template' );
// autoload classes from the /include directory
spl_autoload_register( function( $name ) {
$path = INCLUDE_PATH . __ . "class-$name.php";
if( is_file( $path ) ) {
require $path;
}
} );
// load common functions
require INCLUDE_PATH . __ . 'functions.php';
// jquery URL
// provided by the libjs-jquery package as default
define_default( 'JQUERY_URL', '/javascript/jquery/jquery.min.js' );
// Bootstrap CSS/JavaScript files without trailing slash
// provided by the libjs-bootstrap package as default
define_default( 'BOOTSTRAP_DIR_URL', '/javascript/bootstrap' );
// path to the Net SMTP class
// provided by the php-net-smtp package as default
define_default( 'NET_SMTP', '/usr/share/php/Net/SMTP.php' );
// register JavaScript/CSS files
register_js( 'jquery', JQUERY_URL );
register_js( 'bootstrap', BOOTSTRAP_DIR_URL . '/js/bootstrap.min.js' );
register_css( 'bootstrap', BOOTSTRAP_DIR_URL . '/css/bootstrap.min.css' );
register_css( 'custom-css', ROOT . '/content/style.css' );
// GNU Gettext i18n
define( 'GETTEXT_DOMAIN', 'reyboz-hosting-panel' );
define( 'GETTEXT_DIRECTORY', 'l10n' );
define( 'GETTEXT_DEFAULT_ENCODE', CHARSET ); // UTF-8
// common strings
define_default( 'SITE_NAME', "Boz Libre Hosting Panel" );
define_default( 'CONTACT_EMAIL', 'support@' . DOMAIN );
define_default( 'REPO_URL', 'https://github.com/valerio-bozzolan/boz-libre-hosting-panel' );
// limit session duration to 5 minutes (60s * 100m)
define_default( 'SESSION_DURATION', 6000 );
// register web pages
add_menu_entries( [
new MenuEntry( 'index', '/', __( "Dashboard" ) ),
new MenuEntry( 'login', 'login.php', __( "Login" ) ),
new MenuEntry( 'profile', 'profile.php', __( "Profile" ) ),
new MenuEntry( 'logout', 'logout.php', __( "Logout" ) ),
new MenuEntry( 'password-reset', 'password-reset.php', __( "Password reset" ) ),
] );
// permissions
register_permissions( 'user', [
'read',
'backend',
] );
inherit_permissions( 'admin', 'user', [
'edit-user-all',
'edit-email-all',
'edit-domain-all',
+ 'edit-ftp-all',
] );
diff --git a/template/domain.php b/template/domain.php
index 95259f3..f6e3092 100644
--- a/template/domain.php
+++ b/template/domain.php
@@ -1,32 +1,35 @@
<?php
# Copyright (C) 2018 Valerio Bozzolan
# Boz Libre Hosting Panel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
* This is the template for the website domain dashboard page
*
* Called from:
* domain.php
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
// spawn the mailboxes list
-template( 'mailboxes', [ 'domain' => $domain ] );
+template( 'mailboxes', [ 'domain' => $domain ] );
// spawn the mail forwardings list
template( 'mailforwards', [ 'domain' => $domain ] );
+
+// spawn the ftp list
+template( 'ftp-users', [ 'domain' => $domain ] );
diff --git a/template/domain.php b/template/ftp-access.php
similarity index 61%
copy from template/domain.php
copy to template/ftp-access.php
index 95259f3..42af6fc 100644
--- a/template/domain.php
+++ b/template/ftp-access.php
@@ -1,32 +1,41 @@
<?php
-# Copyright (C) 2018 Valerio Bozzolan
+# Copyright (C) 2019 Valerio Bozzolan
# Boz Libre Hosting Panel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
- * This is the template for the website domain dashboard page
+ * This is the template for FTP instructions
*
* Called from:
- * domain.php
+ * ftp.php
+ *
+ * Available variables:
+ * $domain Domain object
+ * $ftp FTP object
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
+?>
-// spawn the mailboxes list
-template( 'mailboxes', [ 'domain' => $domain ] );
+ <p><?php _e( "To enter in your website with this FTP user you can copy this address into your file manager (then it should ask for the related password):" ) ?></p>
-// spawn the mail forwardings list
-template( 'mailforwards', [ 'domain' => $domain ] );
+ <blockquote>
+ <code>ftp://<?php
+ _esc_html( $ftp->getFTPLogin() );
+ echo '@';
+ _esc_html( $domain->getDomainName() );
+ ?></code>
+ </blockquote>
diff --git a/template/domain.php b/template/ftp-description.php
similarity index 72%
copy from template/domain.php
copy to template/ftp-description.php
index 95259f3..82ce878 100644
--- a/template/domain.php
+++ b/template/ftp-description.php
@@ -1,32 +1,29 @@
<?php
-# Copyright (C) 2018 Valerio Bozzolan
+# Copyright (C) 2019 Valerio Bozzolan
# Boz Libre Hosting Panel
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
/*
- * This is the template for the website domain dashboard page
+ * This is the template for the description of an FTP account
*
* Called from:
- * domain.php
+ * template/ftp-list.php
*/
// unuseful when load directly
defined( 'BOZ_PHP' ) or die;
+?>
-// spawn the mailboxes list
-template( 'mailboxes', [ 'domain' => $domain ] );
-
-// spawn the mail forwardings list
-template( 'mailforwards', [ 'domain' => $domain ] );
+ <p><?php _e( "With an FTP user you can read and write files of your website. You can create various users limited to specific directories of your website." ) ?></p>
diff --git a/template/ftp-users.php b/template/ftp-users.php
new file mode 100644
index 0000000..e5df027
--- /dev/null
+++ b/template/ftp-users.php
@@ -0,0 +1,71 @@
+<?php
+# Copyright (C) 2019 Valerio Bozzolan
+# Boz Libre Hosting Panel
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+/*
+ * This is the template for the FTP user list
+ *
+ * Called from:
+ * domain.php
+ *
+ * Available variables:
+ * $domain Domain object
+ */
+
+// unuseful when load directly
+defined( 'BOZ_PHP' ) or die;
+
+// domain FTP users
+$ftps = $domain->factoryFTP()
+ ->select( [
+ 'ftp_login',
+ ] )
+ ->queryGenerator();
+?>
+ <!-- FTP users -->
+ <h3><?php printf(
+ __( "Your %s" ),
+ __( "FTP users" )
+ ) ?></h3>
+ <?php if( $ftps->valid() ): ?>
+
+ <?php template( 'ftp-description' ) ?>
+
+ <ul>
+ <?php foreach( $ftps as $ftp ): ?>
+ <li>
+ <code><?php echo HTML::a(
+ FTP::permalink(
+ $domain->getDomainName(),
+ $ftp->getFTPLogin()
+ ),
+ $ftp->getFTPLogin()
+ ) ?></code>
+ </li>
+ <?php endforeach ?>
+ </ul>
+ <?php else: ?>
+ <p><?php _e( "None yet.") ?></p>
+ <?php endif ?>
+
+ <?php if( has_permission( 'edit-ftp-all' ) ): ?>
+ <p><?php the_link(
+ FTP::permalink( $domain->getDomainName() ),
+ __( "Create" )
+ ) ?></p>
+ <?php endif ?>
+
+ <!-- end FTP users -->
diff --git a/template/ftp.php b/template/ftp.php
new file mode 100644
index 0000000..0f4feed
--- /dev/null
+++ b/template/ftp.php
@@ -0,0 +1,57 @@
+<?php
+# Copyright (C) 2019 Valerio Bozzolan
+# Boz Libre Hosting Panel
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+/*
+ * This is the template for a single FTP account
+ *
+ * Called from:
+ * ftp.php
+ *
+ * Available variables:
+ * $domain Domain object
+ * $ftp FTP object
+ */
+
+// unuseful when load directly
+defined( 'BOZ_PHP' ) or die;
+?>
+
+ <?php template( 'ftp-description' ) ?>
+
+ <?php if( $ftp ) {
+ template( 'ftp-access', [
+ 'domain' => $domain,
+ 'ftp' => $ftp,
+ ] );
+ } ?>
+
+ <form method="post">
+ <p>
+ <?php if( $ftp ): ?>
+ <input type="hidden" readonly<?php _value( $ftp->getFTPLogin() ) ?> />
+ <?php else: ?>
+ <label for="ftp-login"><?php _e( "FTP login:") ?></label><br />
+ <input type="text" id="ftp-login" name="ftp_login" />
+ <?php endif ?>
+
+ <?php if( $ftp ): ?>
+ <button type="submit" class="btn btn-danger" name="action" value="ftp-delete"><?php _e( "Delete" ) ?></button>
+ <?php else: ?>
+ <button type="submit" class="btn btn-default" name="action" value="ftp-save"><?php _e( "Create" ) ?></button>
+ <?php endif ?>
+ </p>
+ </form>
diff --git a/www/ftp.php b/www/ftp.php
new file mode 100644
index 0000000..b93724d
--- /dev/null
+++ b/www/ftp.php
@@ -0,0 +1,154 @@
+<?php
+# Copyright (C) 2019 Valerio Bozzolan
+# Boz Libre Hosting Panel
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+/*
+ * This is the single FTP account creation/edit page
+ */
+
+// load framework
+require '../load.php';
+
+// wanted informations
+$domain = null;
+$ftp = null;
+
+// URL paramenters (maximum both domain and FTP login, minimum just domain)
+list( $domain_name, $ftp_login ) = url_parts( 2, 1 );
+
+// eventually retrieve mailforward from database
+if( $ftp_login ) {
+ $ftp = ( new FTPAPI() )
+ ->select( [
+ 'domain.domain_ID',
+ 'domain_name',
+ 'ftp_login',
+ ] )
+ ->joinFTPDomain()
+ ->whereDomainName( $domain_name )
+ ->whereFTPLogin( $ftp_login )
+ ->whereDomainIsEditable()
+ ->queryRow();
+
+ // 404
+ $ftp or PageNotFound::spawn();
+
+ // recycle the mailforward object that has domain informations
+ $domain = $ftp;
+}
+
+// eventually retrieve domain from database
+if( ! $domain ) {
+ $domain = ( new DomainAPI() )
+ ->select( [
+ 'domain.domain_ID',
+ 'domain.domain_name',
+ ] )
+ ->whereDomainName( $domain_name )
+ ->whereDomainIsEditable()
+ ->queryRow();
+
+ // 404
+ $domain or PageNotFound::spawn();
+}
+
+if( ! $ftp ) {
+ // to create an FTP user, must edit all FTP users
+ require_permission( 'edit-ftp-all' );
+}
+
+// save destination action
+if( is_action( 'ftp-save' ) ) {
+
+ // save source only during creation
+ if( ! $ftp ) {
+
+ // sanitize
+ if( ! isset( $_POST[ 'ftp_login' ] ) ) {
+ BadRequest::spawn( __( "missing parameter" ) );
+ }
+ $username = luser_input( $_POST[ 'ftp_login' ], 128 );
+ if( ! validate_mailbox_username( $username ) ) {
+ BadRequest::spawn( __( "invalid mailbox name" ) );
+ }
+
+ // check existence
+ $ftp_exists = ( new MailforwardfromAPI )
+ ->select( 1 )
+ ->whereDomain( $domain )
+ ->whereFTPLogin( $source )
+ ->queryRow();
+
+ // die if exists
+ if( $ftp_exists ) {
+ BadRequest::spawn( __( "e-mail forwarding already existing" ) );
+ }
+
+ // insert as new row
+ insert_row( 'ftp', [
+ new DBCol( 'domain_ID', $domain->getDomainID(), 'd' ),
+ new DBCol( 'ftp_login', $username, 's' ),
+ ] );
+
+ // POST/redirect/GET
+ http_redirect( Mailforwardfrom::permalink(
+ $domain->getDomainName(),
+ $username,
+ true
+ ), 303 );
+ }
+}
+
+// delete action
+if( $ftp ) {
+
+ // action fired when deleting a whole mailforward
+ if( is_action( 'ftp-delete' ) ) {
+
+ // drop th
+ query( sprintf(
+ "DELETE FROM %s WHERE domain_ID = %d AND ftp_login = '%s'",
+ T( 'ftp' ),
+ $ftp->getDomainID(),
+ $ftp->getFTPLogin()
+ ) );
+
+ // POST/redirect/GET
+ http_redirect( $domain->getDomainPermalink( true ), 303 );
+
+ }
+
+}
+
+// spawn header
+Header::spawn( [
+ 'title-prefix' => __( "FTP user" ),
+ 'title' => $ftp
+ ? $ftp->getFTPLogin()
+ : __( "create" ),
+ 'breadcrumb' => [
+ new MenuEntry( null, $domain->getDomainPermalink(), $domain->getDomainName() ),
+ ],
+] );
+
+// spawn the page content
+template( 'ftp', [
+ 'domain' => $domain,
+ 'ftp' => $ftp,
+] );
+
+// spawn the footer
+Footer::spawn();

File Metadata

Mime Type
text/x-diff
Expires
Thu, Nov 19, 04:44 (18 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264817
Default Alt Text
(21 KB)

Event Timeline