Changed $path to __DIR__ for config location, Updated auto reload variables, Removed unload listener for auto reload, Changed project default to array so that if no projects exist the program does not crash, Updated autosave to use let instead of vars, Fixed capitalization for sideExpanded variable, Added try catch to pdo initialization on install, Added more error checks on install, Removed password function on install query, Changed default settings array, Added loading div to user delete, Updated queries that threw errors when a default value was zero, Added blank username and password check,

This commit is contained in:
xevidos 2019-02-09 16:14:27 -05:00
parent 10f2bcb86b
commit 81338b1e65
15 changed files with 156 additions and 157 deletions

View file

@ -44,9 +44,9 @@ class Common {
}
}
if( file_exists( $path . 'config.php' ) ) {
if( file_exists( __DIR__ . '/config.php' ) ) {
require_once( $path . 'config.php' );
require_once( __DIR__ . '/config.php' );
}
if( ! defined( 'BASE_PATH' ) ) {

View file

@ -151,7 +151,7 @@
if( content == _this.content ) {
var session = codiad.active.sessions[path];
let session = codiad.active.sessions[path];
if( typeof session != 'undefined' ) {
session.untainted = content;
@ -171,7 +171,7 @@
/*
_this code caused issues even though it is the proper way to save something.
this code caused issues even though it is the proper way to save something.
Whenever in collaboration, the server constantly gave a wrong file version error.
let path = codiad.active.getPath();
@ -183,7 +183,7 @@
_this.content = content;
codiad.active.save;
codiad.filemanager.saveFile( path, content, localStorage.removeItem( path ), false );
var session = codiad.active.sessions[path];
let session = codiad.active.sessions[path];
if( typeof session != 'undefined' ) {
session.untainted = content;

View file

@ -59,13 +59,13 @@
// Initialize node listener
this.nodeListener();
this.auto_reload = ( await codiad.settings.get_option( "codiad.filemanager.auto_reload_preview" ) == "true" );
this.auto_reload = ( await codiad.settings.get_option( "codiad.filemanager.autoReloadPreview" ) == "true" );
console.log( this.auto_reload );
amplify.subscribe( 'settings.save', async function() {
let option = ( await codiad.settings.get_option( "codiad.filemanager.auto_reload_preview" ) == "true" );
let option = ( await codiad.settings.get_option( "codiad.filemanager.autoReloadPreview" ) == "true" );
if( option != codiad.filemanager.auto_reload ) {
//codiad.auto_save.reload_interval();
@ -81,7 +81,6 @@
if( _this.auto_reload && editor !== null ) {
_this.preview.addEventListener( "beforeunload", _this.closePreview );
codiad.editor.getActive().addEventListener( "change", _this.refreshPreview );
}
});
@ -483,7 +482,6 @@
if( _this.auto_reload && editor !== null ) {
_this.preview.addEventListener( "beforeunload", _this.closePreview );
codiad.editor.getActive().addEventListener( "change", _this.refreshPreview );
}
@ -494,12 +492,6 @@
});
},
closePreview: function( event ) {
_this = codiad.filemanager;
_this.preview = null;
},
refreshPreview: function( event ) {
_this = codiad.filemanager;
@ -509,7 +501,22 @@
return;
}
_this.preview.location.reload();
try {
if( ( typeof _this.preview.location.reload ) == "undefined" ) {
_this.preview = null;
codiad.editor.getActive().removeEventListener( "change", _this.refreshPreview );
return;
}
_this.preview.location.reload();
} catch( e ) {
console.log( e );
codiad.message.error( 'Please close your previously opened preview window.' );
_this.preview = null;
codiad.editor.getActive().removeEventListener( "change", _this.refreshPreview );
}
},
openInModal: function(path) {

View file

@ -94,43 +94,28 @@ if ( ! ( defined( "DBHOST" ) && defined( "DBNAME" ) && defined( "DBUSER" ) && de
$dbuser = $_POST['dbuser'];
$dbpass = $_POST['dbpass'];
$connection = new PDO( "{$dbtype}:host={$dbhost};dbname={$dbname}", $dbuser, $dbpass );
try {
$connection = new PDO( "{$dbtype}:host={$dbhost};dbname={$dbname}", $dbuser, $dbpass );
} catch( exception $e ) {
die( "Could not connect to database." );
die();
}
$bind_vars = array();
$bind = "";
$sql = "
-- phpMyAdmin SQL Dump
-- version 4.6.6deb5
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Dec 11, 2018 at 05:31 PM
-- Server version: 5.7.24-0ubuntu0.18.04.1
-- PHP Version: 7.2.10-0ubuntu0.18.04.1
SET SQL_MODE = 'NO_AUTO_VALUE_ON_ZERO';
SET time_zone = '+00:00';
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: code_test
--
-- --------------------------------------------------------
--
-- Table structure for table options
--
CREATE TABLE IF NOT EXISTS options (
id int(11) NOT NULL,
id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(255) NOT NULL,
value text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
value text NOT NULL,
CONSTRAINT option_name UNIQUE (name)
);
-- --------------------------------------------------------
@ -139,12 +124,13 @@ CREATE TABLE IF NOT EXISTS options (
--
CREATE TABLE IF NOT EXISTS projects (
id int(11) NOT NULL,
id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(255) NOT NULL,
path varchar(255) NOT NULL,
owner varchar(255) NOT NULL,
access text
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
access text,
CONSTRAINT project UNIQUE (path, owner)
);
-- --------------------------------------------------------
@ -153,7 +139,7 @@ CREATE TABLE IF NOT EXISTS projects (
--
CREATE TABLE IF NOT EXISTS users (
id int(11) NOT NULL,
id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name varchar(255) DEFAULT NULL,
last_name varchar(255) DEFAULT NULL,
username varchar(255) NOT NULL,
@ -162,79 +148,22 @@ CREATE TABLE IF NOT EXISTS users (
project varchar(255) DEFAULT NULL,
access varchar(255) NOT NULL,
groups text,
token text
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
token text,
CONSTRAINT username UNIQUE (username)
);
--
-- Table structure for table user_options
--
CREATE TABLE IF NOT EXISTS user_options (
id int(11) NOT NULL,
id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(255) NOT NULL,
username varchar(255) NOT NULL,
value text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
value text NOT NULL,
CONSTRAINT option_name UNIQUE (name,username)
);
--
-- Indexes for dumped tables
--
--
-- Indexes for table options
--
ALTER TABLE options
ADD PRIMARY KEY (id),
ADD UNIQUE KEY option_name (name);
--
-- Indexes for table projects
--
ALTER TABLE projects
ADD PRIMARY KEY (id),
ADD UNIQUE KEY project_path (path,owner);
--
-- Indexes for table users
--
ALTER TABLE users
ADD PRIMARY KEY (id),
ADD UNIQUE KEY username (username);
--
-- Indexes for table user_options
--
ALTER TABLE user_options
ADD PRIMARY KEY (id),
ADD UNIQUE KEY option_name (name,username);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table options
--
ALTER TABLE options
MODIFY id int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table projects
--
ALTER TABLE projects
MODIFY id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=41;
--
-- AUTO_INCREMENT for table users
--
ALTER TABLE users
MODIFY id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=79;
--
-- AUTO_INCREMENT for table user_options
--
ALTER TABLE user_options
MODIFY id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2541;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
";
try {
@ -242,8 +171,13 @@ ALTER TABLE user_options
$result = $connection->exec($sql);
} catch( PDOException $e ) {
echo $e->getMessage();
die();
die($e->getMessage());
}
$error = $connection->errorInfo();
if( ! $error[0] == "00000" ) {
die( $error[2] );
}
//////////////////////////////////////////////////////////////////
@ -281,7 +215,7 @@ ALTER TABLE user_options
}
}
$bind_vars = array(
$bind_variables = array(
$project_name,
$project_path,
$username
@ -289,8 +223,14 @@ ALTER TABLE user_options
$query = "INSERT INTO projects(name, path, owner) VALUES (?,?,?);";
$statement = $connection->prepare( $query );
$statement->execute( $bind_variables );
$error = $statement->errorInfo();
$bind_vars = array(
if( ! $error[0] == "00000" ) {
die( $error[2] );
}
$bind_variables = array(
"",
"",
$username,
@ -301,19 +241,23 @@ ALTER TABLE user_options
"",
""
);
$query = "INSERT INTO users(first_name, last_name, username, password, email, project, access, groups, token) VALUES (?,?,?,PASSWORD(?),?,?,?,?,?)";
$query = "INSERT INTO users(first_name, last_name, username, password, email, project, access, groups, token) VALUES (?,?,?,?,?,?,?,?,?)";
$statement = $connection->prepare( $query );
$statement->execute( $bind_variables );
$error = $statement->errorInfo();
if( ! $error[0] == "00000" ) {
die( $error[2] );
}
/**
* Create sessions path.
*/
if ( ! is_dir( $sessions ) ) {
mkdir( $sessions, 00755 );
}

View file

@ -345,7 +345,7 @@ if ($newrelic) {
if(data=='success'){
window.location.reload();
}else{
alert("An Error Occoured<br><br>"+data);
alert("An Error Occoured\n"+data);
}
});
}

View file

@ -18,7 +18,7 @@ class Project extends Common {
public $path = '';
public $gitrepo = false;
public $gitbranch = '';
public $projects = '';
public $projects = array();
public $no_return = false;
public $assigned = false;
public $command_exec = '';
@ -58,12 +58,9 @@ class Project extends Common {
$bind_variables = array( $project_name, $project_path, $owner );
$return = $sql->query( $query, $bind_variables, 0, "rowCount" );
if( $return > 0 ) {
if( ! ( $return > 0 ) ) {
formatJSEND( "success", "Created project $project_name" );
} else {
formatJSEND( "error", "Error creating project $project_name" );
exit( formatJSEND( "error", "Error creating project $project_name" ) );
}
}
@ -377,6 +374,13 @@ class Project extends Common {
if( ! $this->public_project && ! $this->isAbsPath( $this->path ) ) {
$user_path = WORKSPACE . '/' . preg_replace( '/[^\w-]/', '', strtolower( $_SESSION["user"] ) );
if( ! is_dir( $user_path ) ) {
mkdir( $user_path, 0755, true );
}
$this->path = $_SESSION["user"] . '/' . $this->path;
}

View file

@ -6,7 +6,6 @@
* [root]/license.txt for more. This information must remain intact.
*/
require_once('../../common.php');
require_once('./class.project.php');
@ -19,6 +18,12 @@ checkSession();
$Project = new Project();
$Project->projects = $Project->get_projects();
if( ! is_array( $Project->projects ) ) {
$Project->projects = array();
}
if( $_GET['action'] == 'add_user' ) {
$invalid_users = array(

View file

@ -275,7 +275,7 @@
//////////////////////////////////////////////////////////////////
loadSide: async function() {
this._sideExpanded = ( await codiad.settings.get_option( "codiad.projects.SideExpaned" ) == "true" );
this._sideExpanded = ( await codiad.settings.get_option( "codiad.projects.sideExpanded" ) == "true" );
$( '.sb-projects-content' ).load( this.dialog + '?action=sidelist&trigger='+ await codiad.settings.get_option( 'codiad.editor.fileManagerTrigger' ) );
if ( ! this._sideExpanded ) {
@ -323,7 +323,7 @@
projectsExpand: function() {
this._sideExpanded = true;
codiad.settings.update_option( 'codiad.projects.SideExpaned', this._sideExpanded );
codiad.settings.update_option( 'codiad.projects.sideExpanded', this._sideExpanded );
$( '#side-projects' ).css( 'height', 276 + 'px' );
$( '.project-list-title' ).css( 'right', 0 );
$( '.sb-left-content' ).css( 'bottom', 276 + 'px' );
@ -335,7 +335,7 @@
projectsCollapse: function() {
this._sideExpanded = false;
codiad.settings.update_option( 'codiad.projects.SideExpaned', this._sideExpanded );
codiad.settings.update_option( 'codiad.projects.sideExpanded', this._sideExpanded );
$( '#side-projects' ).css( 'height', 33 + 'px' );
$( '.project-list-title' ).css( 'right', 0 );
$( '.sb-left-content' ).css( 'bottom', 33 + 'px' );

View file

@ -11,10 +11,6 @@ class Settings {
const DEFAULT_OPTIONS = array(
array(
"name" => "codiad.editor.autocomplete",
"value" => "false",
),
array(
"name" => "codiad.editor.autosave",
"value" => "true",
),
array(
@ -67,14 +63,18 @@ class Settings {
),
array(
"name" => "codiad.editor.wrapMode",
"value" => "false",
),
array(
"name" => "codiad.settings.autosave",
"value" => "true",
),
array(
"name" => "codiad.settings.plugin.sync",
"name" => "codiad.filemanager.autoReloadPreview",
"value" => "true",
),
array(
"name" => "codiad.projects.sideExpanded",
"value" => "true",
),
array(
"name" => "codiad.settings.autosave",
"value" => "true",
),
array(

View file

@ -140,7 +140,7 @@
case "codiad.settings.autosave":
var bool_val = (val == "true");
break;
case "codiad.filemanager.auto_reload_preview":
case "codiad.filemanager.autoReloadPreview":
var bool_val = (val == "true");
break;
}

View file

@ -17,7 +17,7 @@
<tr>
<td><?php i18n("Auto Reload Preview"); ?></td>
<td>
<select class="setting" data-setting="codiad.filemanager.auto_reload_preview">
<select class="setting" data-setting="codiad.filemanager.autoReloadPreview">
<option value="false" default><?php i18n("False") ?></option>
<option value="true"><?php i18n("True") ?></option>
</select>

View file

@ -92,10 +92,10 @@ class sql {
}
$error = $statement->errorInfo();
if( ! $error[0] == "00000" ) {
echo var_export( $return, $error );
echo var_export( $error );
echo var_export( $return );
$return = $default;
}

View file

@ -61,24 +61,40 @@ class User {
global $sql;
$query = "DELETE FROM user_options WHERE username=?;";
$bind_variables = array( $this->username );
$return = $sql->query( $query, $bind_variables, 0, "rowCount" );
if( $return > 0 ) {
$return = $sql->query( $query, $bind_variables, -1, "rowCount" );
if( $return > -1 ) {
$query = "DELETE FROM users WHERE username=?;";
$bind_variables = array( $this->username );
$return = $sql->query( $query, $bind_variables, 0, "rowCount" );
$query = "DELETE FROM projects WHERE owner=? AND access IN ( ?,?,?,?,? );";
$bind_variables = array(
$this->username,
"null",
null,
"[]",
"",
json_encode( array( $this->username ) )
);
$return = $sql->query( $query, $bind_variables, -1, "rowCount" );
if( $return > 0 ) {
if( $return > -1 ) {
echo formatJSEND( "success", null );
$query = "DELETE FROM users WHERE username=?;";
$bind_variables = array( $this->username );
$return = $sql->query( $query, $bind_variables, 0, "rowCount" );
if( $return > 0 ) {
echo formatJSEND( "success", null );
} else {
echo formatJSEND( "error", "Error deleting user information." );
}
} else {
echo formatJSEND( "error", "Error deleting user information." );
echo formatJSEND( "error", "Error deleting user project information." );
}
} else {
echo formatJSEND( "error", "Error deleting user information." );
echo formatJSEND( "error", "Error deleting user option information." );
}
}
@ -116,11 +132,27 @@ class User {
public function set_default_options() {
$Settings = new Settings();
$Settings->username = $this->username;
foreach( Settings::DEFAULT_OPTIONS as $id => $option ) {
$Settings->update_option( $option["name"], $option["value"], true );
global $sql;
$query = "INSERT INTO user_options ( name, username, value ) VALUES ( ?, ?, ? );";
$bind_variables = array(
$option["name"],
$this->username,
$option["value"],
);
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
if( $result == 0 ) {
$query = "UPDATE user_options SET value=? WHERE name=? AND username=?;";
$bind_variables = array(
$option["value"],
$option["name"],
$this->username,
);
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
}
}
}
@ -130,6 +162,12 @@ class User {
public function Authenticate() {
if( $this->username == "" || $this->password == "" ) {
echo( formatJSEND( "error", "Username or password can not be blank." ) );
return;
}
if( ! is_dir( SESSIONS_PATH ) ) {
mkdir( SESSIONS_PATH, 00755 );

View file

@ -107,6 +107,7 @@
<pre><?php i18n("Account:"); ?> <?php echo($_GET['username']); ?></pre>
<button class="btn-left"><?php i18n("Confirm"); ?></button>
<button class="btn-right" onclick="codiad.user.list();return false;"><?php i18n("Cancel"); ?></button>
<div class="loading"></div>
<?php
break;

View file

@ -143,7 +143,6 @@
if (pass) {
$.post(_this.controller + '?action=create', {'username' : username , 'password' : password1 }, function(data) {
var createResponse = codiad.jsend.parse(data);
console.log( data );
if (createResponse != 'error') {
codiad.message.success(i18n('User Account Created'))
_this.list();
@ -165,6 +164,7 @@
e.preventDefault();
var username = $('#modal-content form input[name="username"]')
.val();
codiad.modal.show_loading();
$.get(_this.controller + '?action=delete&username=' + username, function(data) {
var deleteResponse = codiad.jsend.parse(data);
if (deleteResponse != 'error') {