diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b33323 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# boz-php configuration +load.php diff --git a/include/class-Footer.php b/include/class-Footer.php new file mode 100644 index 0000000..0c73c38 --- /dev/null +++ b/include/class-Footer.php @@ -0,0 +1,31 @@ +. + +/** + * The footer of the web page + */ +class Footer { + + /** + * Spawn the footer to standard output + * + * @param $args array arguments + */ + public static function spawn() { + template( 'footer', Header::$args ); + } +} diff --git a/include/class-Header.php b/include/class-Header.php new file mode 100644 index 0000000..3cb9c58 --- /dev/null +++ b/include/class-Header.php @@ -0,0 +1,61 @@ +. + +/** + * The header of the web page + */ +class Header { + + /** + * Header arguments + * + * It's public because the Footer reads it. + * + * @var array + */ + public static $args; + + /** + * Spawn the header to standard output + * + * @param $args array arguments where: + * title: document title + * h1: site title (as default, it's the document title) + */ + public static function spawn( $args = [] ) { + + // store arguments for future reads + self::$args = & $args; + + // set default arguments + $args = array_replace( [ + 'h1' => $args[ 'title' ], + 'container' => true, + ], $args ); + + // load Bootstrap stuff + enqueue_js( 'jquery' ); + enqueue_js( 'bootstrap' ); + enqueue_css( 'bootstrap' ); + + // charset is usually UTF-8 + header( 'Content-Type: text/html; charset=' . CHARSET ); + + // spawn header template + template( 'header', $args ); + } +} diff --git a/include/class-SMTPMail.php b/include/class-SMTPMail.php new file mode 100644 index 0000000..b47e013 --- /dev/null +++ b/include/class-SMTPMail.php @@ -0,0 +1,107 @@ +. + +/** + * Another Net_SMTP wrapper + */ +class SMTPMail { + + /** + * @var object + */ + private $smtp; + + /** + * Get the singleton instance + */ + public static function instance() { + static $instance = false; + if( ! $instance ) { + $instance = new self(); + } + return $instance; + } + + /** + * Constructor + */ + public function __construct() { + if( ! class_exists( 'Net_SMTP' ) ) { + require NET_SMTP; + } + + $this->smtp = new Net_SMTP( SMTP_SERVER ); + if( ! $this->smtp ) { + die( "Unable to instantiate Net_SMTP object\n" ); + } + + /* Connect to the SMTP server. */ + if( PEAR::isError($e = $this->smtp->connect()) ) { + die( $e->getMessage() . "\n" ); + } + $this->smtp->auth( SMTP_USERNAME, SMTP_PASSWORD, SMTP_AUTH, SMTP_TLS ); + + /* Send the 'MAIL FROM:' SMTP command. */ + if( PEAR::isError( $this->smtp->mailFrom( MAIL_FROM ) ) ) { + die("Unable to set sender to <$from>\n"); + } + } + + /** + * Add a recipient + * + * @param $to string E-mail + */ + public function to( $to ) { + if( PEAR::isError( $res = $this->smtp->rcptTo( $to ) ) ) { + die( "Unable to add recipient <$to>: " . $res->getMessage() . "\n" ); + } + return $this; + } + + /** + * Specify subject and message body + * + * @param $subject string + * @param $body string + */ + public function message( $subject, $body ) { + $data = ''; + + $headers = [ 'Subject' => $subject ]; + foreach( $headers as $header => $value ) { + $value = str_replace( "\n", '', $value ); + $data .= "$header: $value\n"; + } + + $data .= "\r\n$subject"; + + if (PEAR::isError( $this->smtp->data( $data ) ) ) { + die( "Unable to send data\n" ); + } + + return $this; + } + + /** + * Disconnect to the SMTP server + */ + public function disconnect() { + $this->smtp->disconnect(); + unset( $this->smtp ); + } +} diff --git a/include/functions.php b/include/functions.php new file mode 100644 index 0000000..d336ef5 --- /dev/null +++ b/include/functions.php @@ -0,0 +1,58 @@ +. + +/** + * Require a certain page from the template directory + * + * @param $name string page name (to be sanitized) + * @param $args mixed arguments to be passed to the page scope + */ +function template( $name, $args = [] ) { + require TEMPLATE_PATH . __ . "$name.php"; +} + +/** + * Print an e-mail (safe for bots) + * + * @param $email string + */ +function email_blur( $email ) { + $dot = strip_tags( __( " dot " ) ); + $at = strip_tags( __( " at " ) ); + $email = esc_html( $email ); + echo str_replace( [ '.', '@' ], [ $dot, $at ], $email ); +} + +/** + * Send an e-mail to someone + * + * @param $subject string E-mail subject + * @param $message string E-mail message + * @param $to string E-mail recipient (from current logged-in user as default) + */ +function send_email( $subject, $message, $to = false ) { + if( ! $to ) { + if( ! is_logged() ) { + die( "can't retrieve e-mail address from anon user" ); + } + $to = get_user( 'user_email' ); + } + return SMTPMail::instance() + ->to( $to ) + ->message( $subject, $message ) + ->disconnect(); +} diff --git a/index.php b/index.php new file mode 100644 index 0000000..a8c7bbb --- /dev/null +++ b/index.php @@ -0,0 +1,45 @@ +. + +require 'load.php'; + +/* + * This is the homepage of your hosting panel + */ + +if( isset( $_POST[ 'user_password' ] ) ) { + login(); +} + +if( ! is_logged() ) { + http_response_code( 401 ); +} + +// spawn header +Header::spawn( [ + 'title' => __( "Home" ), +] ); +?> + + + + + + + +. + +/* + * This is an example configuration file + * + * Please fill this file and save as 'load.php'! + */ + +// database credentials +$username = 'insert here database username'; +$password = 'insert here database password'; +$database = 'insert here database name'; +$location = 'localhost'; + +// database prefix (if any) +$prefix = ''; + +// your contact e-mail +define( 'CONTACT_EMAIL', 'services@example.org' ); + +// your SMTP credentials +define( 'MAIL_FROM', 'noreply@example.org' ); +define( 'SMTP_USERNAME', 'noreply@example.org' ); +define( 'SMTP_PASSWORD', 'insert here smtp password' ); +define( 'SMTP_AUTH', 'PLAIN' ); +define( 'SMTP_TLS', true ); +define( 'SMTP_SERVER', 'mail.example.org' ); +define( 'SMTP_PORT', 465 ); + +// absolute path to the project directory without trailing slash +define( 'ABSPATH', __DIR__ ); + +// absolute web directory without trailing slash +define( 'ROOT', '' ); + +// path to the boz-php framework +require '/usr/share/php/boz-php/load.php'; diff --git a/load-post.php b/load-post.php new file mode 100644 index 0000000..a323ad9 --- /dev/null +++ b/load-post.php @@ -0,0 +1,61 @@ +. + +// 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/twitter-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' ); + +// 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', "Reyboz Libre Hosting Panel" ); + +// generic contact e-mail +define_default( 'CONTACT_EMAIL', 'support@' . DOMAIN ); diff --git a/template/dashboard.php b/template/dashboard.php new file mode 100644 index 0000000..ca408a8 --- /dev/null +++ b/template/dashboard.php @@ -0,0 +1,29 @@ +. + +/* + * This is the template for the website dashboard + */ + +// unuseful when load directly +defined( 'BOZ_PHP' ) or die; +?> + +
diff --git a/template/footer.php b/template/footer.php new file mode 100644 index 0000000..48b09fd --- /dev/null +++ b/template/footer.php @@ -0,0 +1,40 @@ +. + +/* + * This is the template for the website footer + */ + +// unuseful when load directly +defined( 'BOZ_PHP' ) or die; + +load_module( 'footer' ); +?> + + + + + +
+
+
+