Removed placeholder code for admin, Added sharing, Changed Git links away from local server, Made get and search user functions global.

This commit is contained in:
xevidos 2018-11-19 13:30:49 -05:00
parent 574eb29b8e
commit 1d1f46a9df
16 changed files with 529 additions and 548 deletions

0
.gitignore vendored Normal file → Executable file
View file

171
admin.php
View file

@ -1,172 +1,3 @@
<?php <?php
/** //Silence is golden.
* Codiad admin module.
*
* This admin module should provide a new way to install plugins / themes,
* manage users, add permission levels,
*
* Copyright (c) Codiad, Kent Safranski (codiad.com), and Isaac Brown (telaaedifex.com), distributed
* as-is and without warranty under the MIT License. See
* [root]/license.txt for more. This information must remain intact.
*
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once( './common.php' );
require_once( './admin/assets/classes/initialize.php' );
new initialize();
// Read Components, Plugins, Themes
$components = Common::readDirectory( COMPONENTS );
$plugins = Common::readDirectory( PLUGINS );
$themes = Common::readDirectory( THEMES );
// Theme
$theme = THEME;
if( isset( $_SESSION['theme'] ) ) {
$theme = $_SESSION['theme'];
}
// Get Site name if set
if( defined( "SITE_NAME" ) && ! ( SITE_NAME === "" || SITE_NAME === null ) ) {
$site_name = SITE_NAME;
} else {
$site_name = "Codiad";
}
?> ?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo htmlentities( $site_name ); ?> - Admin</title>
<?php
// Load System CSS Files
$stylesheets = array(
"jquery.toastmessage.css",
"reset.css",
"fonts.css",
"screen.css"
);
foreach( $stylesheets as $sheet ) {
if( file_exists( THEMES . "/" . $theme . "/" . $sheet ) ) {
echo( '<link rel="stylesheet" href="themes/' . $theme . '/' . $sheet . '">' );
} else {
echo( '<link rel="stylesheet" href="themes/default/' . $sheet . '">' );
}
}
// Load Component CSS Files
foreach( $components as $component ) {
if( file_exists( THEMES . "/". $theme . "/" . $component . "/screen.css" ) ) {
echo( '<link rel="stylesheet" href="themes/' . $theme . '/' . $component . '/screen.css">' );
} else {
if( file_exists( "themes/default/" . $component . "/screen.css" ) ){
echo( '<link rel="stylesheet" href="themes/default/' . $component . '/screen.css">' );
} else {
if( file_exists( COMPONENTS . "/" . $component . "/screen.css" ) ){
echo( '<link rel="stylesheet" href="components/' . $component . '/screen.css">' );
}
}
}
}
// Load Plugin CSS Files
/*foreach( $plugins as $plugin ) {
if( file_exists( THEMES . "/". $theme . "/" . $plugin . "/screen.css" ) ) {
echo( '<link rel="stylesheet" href="themes/' . $theme . '/' . $plugin . '/screen.css">' );
} else {
if( file_exists( "themes/default/" . $plugin . "/screen.css" ) ){
echo( '<link rel="stylesheet" href="themes/default/' . $plugin . '/screen.css">' );
} else {
if( file_exists( PLUGINS . "/" . $plugin . "/screen.css" ) ) {
echo( '<link rel="stylesheet" href="plugins/' . $plugin . '/screen.css">' );
}
}
}
}*/
?>
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<script>
var i18n = ( function( lang ) {
return function( word, args ) {
var x;
var returnw = ( word in lang ) ? lang[word] : word;
for( x in args ) {
returnw = returnw.replace( "%{"+x+"}%", args[x] );
}
return returnw;
}
})( <?php echo json_encode( $lang ); ?> )
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/jquery-1.7.2.min.js"%3E%3C/script%3E'));</script>
<script src="js/jquery-ui-1.8.23.custom.min.js"></script>
<script src="js/jquery.css3.min.js"></script>
<script src="js/jquery.easing.js"></script>
<script src="js/jquery.toastmessage.js"></script>
<script src="js/amplify.min.js"></script>
<script src="js/jquery.hoverIntent.min.js"></script>
<script src="js/system.js"></script>
<script src="js/sidebars.js"></script>
<script src="js/modal.js"></script>
<script src="js/message.js"></script>
<script src="js/jsend.js"></script>
<script src="js/instance.js?v=<?php echo time();?>"></script>
<div id="message"></div>
</head>
<body>
<!-- COMPONENTS -->
<?php
//////////////////////////////////////////////////////////////////
// LOAD COMPONENTS
//////////////////////////////////////////////////////////////////
/*
// JS
foreach( $components as $component ) {
if( file_exists( COMPONENTS . "/" . $component . "/init.js" ) ) {
echo('<script src="components/' . $component . '/init.js"></script>');
}
}
foreach( $plugins as $plugin ) {
if( file_exists( PLUGINS . "/" . $plugin . "/init.js" ) ) {
echo( '<script src="plugins/' . $plugin . '/init.js"></script>' );
}
}
*/
?>
</body>
</html>

View file

@ -117,7 +117,7 @@ class Common {
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Check access to a project // Check access to a project
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
public static function check_project_access( $project_name, $project_path, $action ) { public static function check_project_access( $project_path, $action ) {
$sql = "SELECT * FROM `projects` WHERE `name`=? AND `path`=? AND ( `owner`=? OR `owner`='nobody' );"; $sql = "SELECT * FROM `projects` WHERE `name`=? AND `path`=? AND ( `owner`=? OR `owner`='nobody' );";
$bind = "sss"; $bind = "sss";
@ -151,13 +151,20 @@ class Common {
self::return( $return, $action ); self::return( $return, $action );
} }
public static function get_users( $return = "return" ) { public static function get_users( $return = "return", $exclude_current = false ) {
$sql = "SELECT `username` FROM `users`;"; $sql = "SELECT `username` FROM `users`";
$bind = ""; $bind = "";
$bind_variables = array(); $bind_variables = array();
$result = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error checking users." ) );
if( $exclude_current ) {
$sql .= " WHERE `username`!=?";
$bind .= "s";
array_push( $bind_variables, $_SESSION["user"] );
}
$result = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error checking users." ) );
$user_list = array(); $user_list = array();
foreach( $result as $row ) { foreach( $result as $row ) {
@ -220,6 +227,74 @@ class Common {
session_start(); session_start();
} }
//////////////////////////////////////////////////////////////////
// Search Users
//////////////////////////////////////////////////////////////////
public function search_users( $username, $return = "return", $exclude_current = false ) {
$sql = "SELECT `username` FROM `users` WHERE `username` LIKE ?";
$bind = "s";
$bind_variables = array( "%{$username}%" );
if( $exclude_current ) {
$sql .= " AND `username`!=?";
$bind .= "s";
array_push( $bind_variables, $_SESSION["user"] );
}
$result = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error selecting user information." ) );
$user_list = array();
foreach( $result as $row ) {
array_push( $user_list, $row["username"] );
}
if( mysqli_num_rows( $result ) > 0 ) {
switch( $return ) {
case( "exit" ):
exit( formatJSEND( "success", $user_list ) );
break;
case( "json" ):
$return = json_encode( $user_list );
break;
case( "return" ):
$return = $user_list;
break;
}
} else {
switch( $return ) {
case( "exit" ):
exit( formatJSEND( "error", "Error selecting user information." ) );
break;
case( "json" ):
$return = formatJSEND( "error", "Error selecting user information." );
break;
case( "return" ):
$return = null;
break;
}
}
return( $return );
}
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Start Sessions // Start Sessions
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -580,5 +655,6 @@ function checkAccess() { return Common::checkAccess(); }
function checkPath($path) { return Common::checkPath($path); } function checkPath($path) { return Common::checkPath($path); }
function isAvailable($func) { return Common::isAvailable($func); } function isAvailable($func) { return Common::isAvailable($func); }
function logout() { return Common::logout(); } function logout() { return Common::logout(); }
function get_users() { return Common::get_users(); } function get_users( $return = "return", $exclude_current = false ) { return Common::get_users( $return, $exclude_current ); }
function search_users( $username, $return = "return", $exclude_current = false ) { return Common::search_users( $username, $return, $exclude_current ); }
?> ?>

View file

@ -28,12 +28,12 @@ switch($_GET['action']){
$type = $_GET['type']; $type = $_GET['type'];
?> ?>
<label><?php i18n("Find:"); ?></label> <label><?php i18n("Find:"); ?></label>
<input type="text" name="find" autofocus="autofocus" autocomplete="off"> <textarea name="find" autofocus="autofocus" autocomplete="off"></textarea>
<?php if($type=='replace'){ ?> <?php if($type=='replace'){ ?>
<label><?php i18n("Replace:"); ?></label> <label><?php i18n("Replace:"); ?></label>
<input type="text" name="replace"> <textarea name="replace"></textarea>
<?php } ?> <?php } ?>
@ -52,7 +52,7 @@ switch($_GET['action']){
<script> <script>
$(function(){ $(function(){
<?php if($_GET['action']=='search'){ ?> <?php if($_GET['action']=='search'){ ?>
$('input[name="find"]').val(codiad.active.getSelectedText()); $('textarea[name="find"]').val(codiad.active.getSelectedText());
<?php } ?> <?php } ?>
}); });

View file

@ -1467,9 +1467,9 @@
search: function(action, i) { search: function(action, i) {
i = i || this.getActive(); i = i || this.getActive();
if (! i) return; if (! i) return;
var find = $('#modal input[name="find"]') var find = $('#modal textarea[name="find"]')
.val(); .val();
var replace = $('#modal input[name="replace"]') var replace = $('#modal textarea[name="replace"]')
.val(); .val();
switch (action) { switch (action) {
case 'find': case 'find':

View file

@ -17,31 +17,22 @@ checkSession();
?> ?>
<label><?php i18n("Upload Files"); ?></label> <label><?php i18n("Upload Files"); ?></label>
<div id="upload-drop-zone"> <div id="upload-drop-zone">
<span id="upload-wrapper"> <span id="upload-wrapper">
<input id="fileupload" type="file" name="upload[]" data-url="components/filemanager/controller.php?action=upload&path=<?php echo($_GET['path']); ?>" multiple directory webkitdirectory mozdirectory>
<input id="fileupload" type="file" name="upload[]" data-url="components/filemanager/controller.php?action=upload&path=<?php echo($_GET['path']); ?>" multiple>
<span id="upload-clicker"><?php i18n("Drag Files or Click Here to Upload"); ?></span> <span id="upload-clicker"><?php i18n("Drag Files or Click Here to Upload"); ?></span>
</span> </span>
<div id="upload-progress"><div class="bar"></div></div> <div id="upload-progress"><div class="bar"></div></div>
<div id="upload-complete"><?php i18n("Complete!"); ?></div> <div id="upload-complete"><?php i18n("Complete!"); ?></div>
</div> </div>
<button onclick="codiad.modal.unload();"><?php i18n("Close Uploader"); ?></button> <button onclick="codiad.modal.unload();"><?php i18n("Close Uploader"); ?></button>
<script> <script>
$(function () {
$(function () {
$('#fileupload').fileupload({ $('#fileupload').fileupload({
dataType: 'json', dataType: 'json',
dropZone: '#upload-drop-zone', dropZone: '#upload-drop-zone',
progressall: function(e, data){ progressall: function( e, data ) {
var progress = parseInt(data.loaded / data.total * 100, 10); var progress = parseInt(data.loaded / data.total * 100, 10);
$('#upload-progress .bar').css( $('#upload-progress .bar').css(
'width', 'width',
@ -50,6 +41,7 @@ $(function () {
if(progress>98){ $('#upload-complete').fadeIn(200); } if(progress>98){ $('#upload-complete').fadeIn(200); }
}, },
done: function(e, data){ done: function(e, data){
$.each(data.result, function (index, file){ $.each(data.result, function (index, file){
var path = '<?php echo($_GET['path']); ?>'; var path = '<?php echo($_GET['path']); ?>';
codiad.filemanager.createObject(path, path + "/" + file.name,'file'); codiad.filemanager.createObject(path, path + "/" + file.name,'file');
@ -62,6 +54,5 @@ $(function () {
},1000); },1000);
} }
}); });
}); });
</script> </script>

View file

@ -23,6 +23,7 @@ class Project extends Common {
public $assigned = false; public $assigned = false;
public $command_exec = ''; public $command_exec = '';
public $public_project = false; public $public_project = false;
public $user = '';
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// METHODS // METHODS
@ -61,6 +62,45 @@ class Project extends Common {
return( $return ); return( $return );
} }
public function add_user() {
$sql = "SELECT `access` FROM `projects` WHERE `path`=? AND `owner`=?";
$bind = "ss";
$bind_variables = array( $this->path, $_SESSION["user"] );
$result = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error fetching projects." ) );
if( mysqli_num_rows( $result ) > 0 ) {
$access = json_decode( mysqli_fetch_assoc( $result )["access"] );
if( is_array( $access ) ) {
if( ! in_array( $this->user, $access ) ) {
array_push( $access, $this->user );
}
} else {
$access = array(
$this->user
);
}
$access = json_encode( $access );
$sql = "UPDATE `projects` SET `access`=? WHERE `path`=? AND `owner`=?;";
$bind = "sss";
$bind_variables = array( $access, $this->path, $_SESSION["user"] );
$return = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error setting access for project." ) );
if( sql::check_sql_error( $return ) ) {
echo( formatJSEND( "success", "Successfully added {$this->user}." ) );
} else {
echo $return;
}
}
}
public function check_owner( $path = null, $exclude_public = false ) { public function check_owner( $path = null, $exclude_public = false ) {
if( $path === null ) { if( $path === null ) {
@ -162,9 +202,9 @@ class Project extends Common {
public function get_projects() { public function get_projects() {
$sql = "SELECT * FROM `projects` WHERE `owner`=? OR `owner`='nobody' ORDER BY `name`;"; $sql = "SELECT * FROM `projects` WHERE `owner`=? OR `owner`='nobody' OR `access` LIKE ? ORDER BY `name`;";
$bind = "s"; $bind = "ss";
$bind_variables = array( $_SESSION["user"] ); $bind_variables = array( $_SESSION["user"], '%"' . $_SESSION["user"] . '"%' );
$return = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error fetching projects." ) ); $return = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error fetching projects." ) );
if( mysqli_num_rows( $return ) > 0 ) { if( mysqli_num_rows( $return ) > 0 ) {
@ -178,6 +218,45 @@ class Project extends Common {
return( $return ); return( $return );
} }
public function remove_user() {
$sql = "SELECT `access` FROM `projects` WHERE `path`=? AND `owner`=?";
$bind = "ss";
$bind_variables = array( $this->path, $_SESSION["user"] );
$result = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error fetching projects." ) );
if( mysqli_num_rows( $result ) > 0 ) {
$access = json_decode( mysqli_fetch_assoc( $result )["access"] );
if( is_array( $access ) ) {
$key = array_search( $this->user, $access );
if ( $key !== false ) {
unset( $access[$key] );
} else {
echo( formatJSEND( "error", "{$this->user} is not in the access list." ) );
}
}
$access = json_encode( $access );
$sql = "UPDATE `projects` SET `access`=? WHERE `path`=? AND `owner`=?;";
$bind = "sss";
$bind_variables = array( $access, $this->path, $_SESSION["user"] );
$return = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error setting access for project." ) );
if( sql::check_sql_error( $return ) ) {
echo( formatJSEND( "success", "Successfully removed {$this->user}." ) );
} else {
echo $return;
}
}
}
public function rename_project( $old_name, $new_name, $path ) { public function rename_project( $old_name, $new_name, $path ) {
$sql = "SELECT * FROM `projects` WHERE `name`=? AND `path`=? AND ( `owner`=? OR `owner`='nobody' );"; $sql = "SELECT * FROM `projects` WHERE `name`=? AND `path`=? AND ( `owner`=? OR `owner`='nobody' );";
@ -243,9 +322,9 @@ class Project extends Common {
public function Open() { public function Open() {
$sql = "SELECT * FROM `projects` WHERE `path`=? AND ( `owner`=? OR `owner`='nobody' );"; $sql = "SELECT * FROM `projects` WHERE `path`=? AND ( `owner`=? OR `owner`='nobody' OR `access` LIKE ? );";
$bind = "ss"; $bind = "sss";
$bind_variables = array( $this->path, $_SESSION["user"] ); $bind_variables = array( $this->path, $_SESSION["user"], '%"' . $_SESSION["user"] . '"%' );
$return = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error fetching projects." ) ); $return = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error fetching projects." ) );
if( mysqli_num_rows( $return ) > 0 ) { if( mysqli_num_rows( $return ) > 0 ) {

View file

@ -18,6 +18,42 @@ checkSession();
$Project = new Project(); $Project = new Project();
if( $_GET['action'] == 'add_user' ) {
$invalid_users = array(
"",
"null",
"undefined"
);
if( ! in_array( $_GET['username'], $invalid_users ) ) {
$Project->user = $_GET['username'];
} else {
echo formatJSEND( "error", "No username set." );
return;
}
if( $_GET['project_path'] != '' ) {
$Project->path = $_GET['project_path'];
} else {
echo formatJSEND( "error", "No project path set." );
return;
}
if( $Project->check_owner( $_GET["project_path"], true ) ) {
$Project->add_user();
} else {
echo formatJSEND( "error", "You can not manage this project." );
}
}
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Create Project // Create Project
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -150,6 +186,41 @@ if( $_GET['action'] == 'open' ) {
$Project->Open(); $Project->Open();
} }
if( $_GET['action'] == 'remove_user' ) {
$invalid = array(
"",
"null",
"undefined"
);
if( ! in_array( $_GET['username'], $invalid ) ) {
$Project->user = $_GET['username'];
} else {
echo formatJSEND( "error", "No username set." );
return;
}
if( ! in_array( $_GET['project_path'], $invalid ) ) {
$Project->path = $_GET['project_path'];
} else {
echo formatJSEND( "error", "No project path set." );
return;
}
if( $Project->check_owner( $_GET["project_path"], true ) ) {
$Project->remove_user();
} else {
echo formatJSEND( "error", "You can not manage this project." );
}
}
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Rename Project // Rename Project
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////

View file

@ -204,13 +204,13 @@ switch( $_GET['action'] ) {
$path = $_GET['path']; $path = $_GET['path'];
$project = $Project->get_project( $path ); $project = $Project->get_project( $path );
$access = json_decode( $project["access"], true ); $access = json_decode( $project["access"], true );
$users = get_users(); $users = get_users( "return", true );
?> ?>
<form> <form>
<input type="hidden" name="project_path" value="<?php echo( $path );?>"> <input type="hidden" name="project_path" value="<?php echo( $path );?>">
<label><span class="icon-pencil"></span><?php i18n( "Add Users" );?></label> <label><span class="icon-pencil"></span><?php i18n( "Add Users" );?></label>
<input id="search_users" type="text" onkeyup="codiad.project.search_users();" /> <input id="search_users" type="text" onkeyup="codiad.project.search_users();" />
<select id="user_list"> <select id="user_list" name="user_list">
<?php <?php
foreach( $users as $user ) { foreach( $users as $user ) {
@ -250,7 +250,7 @@ switch( $_GET['action'] ) {
<?php <?php
} }
?> ?>
<button class="btn-left" onclick="codiad.project.save_access();"><?php i18n( "Save" );?></button>&nbsp;<button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n( "Cancel" );?></button> <button class="btn-right" onclick="codiad.modal.unload();return false;"><?php i18n( "Done" );?></button>
<form> <form>
<?php <?php
break; break;

View file

@ -51,13 +51,25 @@
// Add user access // Add user access
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
add_user: function( user ) { add_user: function() {
var _this = this; var _this = this;
$( '#modal-content form' ).live( 'submit', function( e ) { $( '#modal-content form' ).live( 'submit', function( e ) {
e.preventDefault(); e.preventDefault();
username = $( '#modal-content form select[name="user_list"]' ).val();
project_path = $( '#modal-content form input[name="project_path"]' ).val()
$.get( _this.controller + '?action=add_user&project_path=' + encodeURIComponent( project_path ) + '&username=' + encodeURIComponent( username ), function( data ) {
response = codiad.jsend.parse( data );
console.log( response );
if ( response != 'error' ) {
codiad.project.manage_access( project_path );
}
});
}); });
}, },
@ -331,9 +343,22 @@
remove_user: function( user ) { remove_user: function( user ) {
var _this = this;
$( '#modal-content form' ).live( 'submit', function( e ) { $( '#modal-content form' ).live( 'submit', function( e ) {
e.preventDefault(); e.preventDefault();
project_path = $( '#modal-content form input[name="project_path"]' ).val()
$.get( _this.controller + '?action=remove_user&project_path=' + encodeURIComponent( project_path ) + '&username=' + encodeURIComponent( user ), function( data ) {
response = codiad.jsend.parse( data );
console.log( response );
if ( response != 'error' ) {
codiad.project.manage_access( project_path );
}
});
}); });
}, },

View file

@ -87,7 +87,7 @@
"title": "Help", "title": "Help",
"admin": false, "admin": false,
"icon": "icon-help", "icon": "icon-help",
"onclick": "window.open('https://gitlab.telaaedifex.com/xevidos/codiad/wikis/home');" "onclick": "window.open('https://gitlab.com/xevidos/codiad/wikis/home');"
}, },
{ {
"title": "Logout", "title": "Logout",

View file

@ -8,6 +8,73 @@
class Settings { class Settings {
const DEFAULT_OPTIONS = array(
array(
"name" => "codiad.editor.fileManagerTrigger",
"value" => "false",
),
array(
"name" => "codiad.editor.fontSize",
"value" => "14px",
),
array(
"name" => "codiad.editor.highlightLine",
"value" => "true",
),
array(
"name" => "codiad.editor.indentGuides",
"value" => "true",
),
array(
"name" => "codiad.editor.overScroll",
"value" => "0.5",
),
array(
"name" => "codiad.editor.persistentModal",
"value" => "true",
),
array(
"name" => "codiad.editor.printMargin",
"value" => "true",
),
array(
"name" => "codiad.editor.printMarginColumn",
"value" => "80",
),
array(
"name" => "codiad.editor.rightSidebarTrigger",
"value" => "false",
),
array(
"name" => "codiad.editor.softTabs",
"value" => "false",
),
array(
"name" => "codiad.editor.tabSize",
"value" => "4",
),
array(
"name" => "codiad.editor.theme",
"value" => "twilight",
),
array(
"name" => "codiad.editor.wrapMode",
"value" => "false",
),
array(
"name" => "codiad.settings.autosave",
"value" => "true",
),
array(
"name" => "codiad.settings.plugin.sync",
"value" => "true",
),
array(
"name" => "codiad.settings.plugin.sync",
"value" => "true",
),
);
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// PROPERTIES // PROPERTIES
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////

View file

@ -39,10 +39,10 @@ class Update {
public function __construct() { public function __construct() {
ini_set("user_agent", "Codiad"); ini_set("user_agent", "Codiad");
$this->archive = "https://gitlab.telaaedifex.com/xevidos/codiad/-/archive/master/codiad-master.zip"; $this->archive = "https://gitlab.com/xevidos/codiad/-/archive/master/codiad-master.zip";
$this->commits = "https://gitlab.telaaedifex.com/api/v4/projects/3/repository/commits/"; $this->commits = "https://gitlab.com/api/v4/projects/8466613/repository/commits/";
$this->tags = "https://gitlab.telaaedifex.com/api/v4/projects/3/repository/tags/"; $this->tags = "https://gitlab.com/api/v4/projects/8466613/repository/tags/";
$this->update_file = "https://gitlab.telaaedifex.com/xevidos/codiad/raw/master/components/update/update.php"; $this->update_file = "https://gitlab.com/xevidos/codiad/raw/master/components/update/update.php";
$this->protocol = $this->CheckProtocol(); $this->protocol = $this->CheckProtocol();
} }
@ -183,16 +183,15 @@ class Update {
public function getLocalVersion(){ public function getLocalVersion(){
return getJSON('version.php');; return getJSON( 'version.php' );
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Get Remote Version // Get Remote Version
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
public function getRemoteVersion($action="check", $localversion = "") { public function getRemoteVersion( $action="check", $localversion = "" ) {
//$remoteurl = Common::getConstant('UPDATEURL', $this->remote);
if ( $this->protocol === "none" ) { if ( $this->protocol === "none" ) {
return; return;
@ -203,15 +202,15 @@ class Update {
case( "curl" ): case( "curl" ):
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->tags); curl_setopt( $curl, CURLOPT_URL, $this->tags );
//curl_setopt($curl, CURLOPT_POSTFIELDS, ""); //curl_setopt($curl, CURLOPT_POSTFIELDS, "");
curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt( $curl, CURLOPT_HEADER, 0 );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13'); curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13' );
$content = curl_exec($curl); $content = curl_exec( $curl );
curl_close($curl); curl_close( $curl );
$response = json_decode( $content, true ); $response = json_decode( $content, true );
//Return latest release //Return latest release
@ -222,7 +221,5 @@ class Update {
break; break;
} }
//return( json_decode( file_get_contents( $remoteurl ), true ) );
} }
} }

View file

@ -38,17 +38,17 @@ class updater {
public $archive = ""; public $archive = "";
public $path = ""; public $path = "";
public $protocol = ""; public $protocol = "";
public $update = null;
function __construct() { function __construct() {
$update = new Update(); $this->update = new Update();
$this->archive = $update->archive; /*$this->archive = $update->archive;
$this->path = Common::getConstant('BASE_PATH'); $this->path = Common::getConstant('BASE_PATH');
$this->protocol = $this->check_protocol(); $this->protocol = $this->check_protocol();
//Trigger update //Trigger update
$this->update(); $this->update();*/
} }
function check_protocol() { function check_protocol() {
@ -68,6 +68,21 @@ class updater {
} }
} }
function check_update() {
$response = $this->update->getRemoteVersion();
$local_version = $this->update::VERSION;
$remote_version = $response["name"];
$return = "false";
if( $local_version < $remote_version ) {
$return = "true";
}
return( $return );
}
function copyr( $source, $dest ) { function copyr( $source, $dest ) {
// Check for symlinks // Check for symlinks
if (is_link($source)) { if (is_link($source)) {
@ -246,6 +261,21 @@ class updater {
} }
} }
if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
$updater = new updater();
$action = $_GET["action"];
switch( $action ) {
case( "check_update" ):
echo $updater->check_update();
break;
}
exit();
}
?> ?>
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
@ -271,8 +301,6 @@ class updater {
color: #666; color: #666;
display: block; display: block;
//float: left;
//font-size: 15px;
font-weight: 500; font-weight: 500;
margin: 10px; margin: 10px;
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6); text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
@ -287,230 +315,77 @@ class updater {
} }
</style> </style>
<script src="../../js/jquery-1.7.2.min.js"></script>
<script> <script>
const codiad = {};
codiad.update = {
progress: null,
init: function() {
this.progress = document.getElementById( "progress" );
this.update();
},
check_update: function() {
this.progress.innerText = "Checking for update ... ";
return jQuery.ajax({
url: "update.php",
type: "GET",
dataType: 'html',
data: {
action: 'check_update',
},
success: function( result ) {
return result;
},
error: function( jqXHR, textStatus, errorThrown ) {
console.log( 'jqXHR:' );
console.log( jqXHR );
console.log( 'textStatus:' );
console.log( textStatus);
console.log( 'errorThrown:' );
console.log( errorThrown );
return null;
}
});
},
update: async function() {
let result = await this.check_update();
console.log( result );
if( result === "true" ) {
progress.innerText = "An update was found. Starting update.";
} else if( result === "false" ) {
progress.innerText = "No update was found ...";
} else {
progress.innerText = "Error, checking for updates failed.";
}
},
};
</script> </script>
</head> </head>
<body> <body>
<h1 class="title" style="text-align: center;"> <h1 class="title" style="text-align: center;">
Telaaedifex Codiad Updater Tela Codiad Updater
</h1> </h1>
<div id="progress"> <div>
Starting Update ... <p id="progress"></p>
</div> </div>
</body>
</html>
<?php
new updater();
?><?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once('../../common.php');
require_once('./class.update.php');
checkSession();
if ( ! checkAccess() ) {
echo "Error, you do not have access to update Codiad.";
exit;
}
/**
* Initiate the update class so we do not have to redefine their
* variables.
*/
class updater {
/**
* Telaaedifex Codiad updater
*
* This updater will extract an archive and then update each file
* with file put contents.
*/
/**
* Constants
*/
/**
* Properties
*/
public $archive = "";
public $path = "";
public $protocol = "";
function __construct() {
$update = new Update();
$this->archive = $update->archive;
$this->path = Common::getConstant('BASE_PATH');
$this->protocol = $this->check_protocol();
//Trigger update
$this->update();
//Delete File
unlink( __FILE__ );
}
function check_protocol() {
if( extension_loaded( 'curl' ) ) {
//Curl is loaded
return "curl";
} elseif( ini_get('allow_url_fopen') ) {
//Remote get file is enabled
return "fopen";
} else {
//None are enabled exit.
return "none";
}
}
//////////////////////////////////////////////////////////////////
// Download latest archive
//////////////////////////////////////////////////////////////////
function download() {
switch( $this->protocol ) {
case( "curl" ):
$filepath = $this->path . "/update.zip";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->archive);
//curl_setopt($curl, CURLOPT_POSTFIELDS, "");
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13');
$raw_file_data = curl_exec($curl);
curl_close($curl);
file_put_contents( $filepath, $raw_file_data );
return ( filesize( $filepath ) > 0 ) ? true : false;
break;
case( "fopen" ):
break;
}
}
function extract() {
if ( ! extension_loaded( 'zip' ) ) {
echo "<script>document.getElementById('progress').innerHTML = '<p class=\"error_box\">Error, the php zip extension does not seem to be installed. Can not continue with update. Please install the <a href=\"http://php.net/manual/en/book.zip.php\" target=\"_blank\">php zip extension</a></p>'> ... </p>';</script>";
return false;
}
$zip = new ZipArchive;
if ( $zip->open( $this->path . "/update.zip", ZipArchive::OVERWRITE ) === TRUE ) {
$zip->extractTo( $this->path );
$zip->close();
return true;
} else {
return false;
}
}
function update() {
echo "<script>document.getElementById('progress').innerHTML = '<p class=\"status_box\">Downloading latest version ... </p>';</script>";
if ( ! $this->download() ) {
echo "<script>document.getElementById('progress').innerHTML += '<br><p class=\"error_box\">Error downloading latest version</p>';</script>";
}
echo "<script>document.getElementById('progress').innerHTML = '<p class=\"status_box\">Extracting update ... </p>';</script>";
if ( ! $this->extract() ) {
echo "<script>document.getElementById('progress').innerHTML += '<br><p class=\"error_box\">Error extracting update</p>';</script>";
}
echo "<script>document.getElementById('progress').innerHTML = '<p class=\"status_box\">Updating ... </p>';</script>";
try {
exec( "cp -a " );
} catch ( exception $e ) {
echo "<script>document.getElementById('progress').innerHTML = '<p class=\"error_box\">Update Failed ... </p>';</script>";
return;
}
echo "<script>document.getElementById('progress').innerHTML = '<p class=\"status_box\">Removing Update ... </p>';</script>";
exec( "rm -rf " . $this->path . "/update.zip;rm -rf " . $this->path . "/codiad-master" );
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Codiad Update</title>
<style>
html {
}
body{
background-color: #1a1a1a;
color: #fff;
font: normal 13px 'Ubuntu', sans-serif;
height: 100%;
overflow: hidden;
width: 100%;
}
.title {
color: #666;
display: block;
//float: left;
//font-size: 15px;
font-weight: 500;
margin: 10px;
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
}
#progress {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
<script> <script>
codiad.update.init();
</script> </script>
</head>
<body>
<h1 class="title" style="text-align: center;">
Telaaedifex Codiad Updater
</h1>
<div id="progress">
Starting Update ...
</div>
</body> </body>
</html> </html>
<?php
new updater();
?>

View file

@ -6,6 +6,8 @@
* [root]/license.txt for more. This information must remain intact. * [root]/license.txt for more. This information must remain intact.
*/ */
require_once( "../settings/class.settings.php" );
class User { class User {
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -46,6 +48,7 @@ class User {
if( sql::check_sql_error( $return ) ) { if( sql::check_sql_error( $return ) ) {
$this->set_default_options();
echo formatJSEND( "success", array( "username" => $this->username ) ); echo formatJSEND( "success", array( "username" => $this->username ) );
} else { } else {
@ -53,6 +56,33 @@ class User {
} }
} }
public function delete_user() {
$sql = "DELETE FROM `user_options` WHERE `username`=?;";
$bind = "s";
$bind_variables = array( $this->username );
$return = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error deleting user information." ) );
if( sql::check_sql_error( $return ) ) {
$sql = "DELETE FROM `users` WHERE `username`=?;";
$bind = "s";
$bind_variables = array( $this->username );
$return = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error deleting user information." ) );
if( sql::check_sql_error( $return ) ) {
echo formatJSEND( "success", null );
} else {
echo $return;
}
} else {
echo $return;
}
}
public function get_user( $username ) { public function get_user( $username ) {
$sql = "SELECT * FROM `users` WHERE `username`=?"; $sql = "SELECT * FROM `users` WHERE `username`=?";
@ -79,6 +109,16 @@ class User {
return( $return ); return( $return );
} }
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 );
}
}
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Authenticate // Authenticate
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -252,18 +292,7 @@ class User {
public function Delete() { public function Delete() {
$sql = "DELETE FROM `users` WHERE `username`=?;"; $this->delete_user();
$bind = "ss";
$bind_variables = array( $this->username, $this->password );
$return = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error deleting user information." ) );
if( sql::check_sql_error( $return ) ) {
echo formatJSEND( "success", null );
} else {
echo $return;
}
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -315,66 +344,6 @@ class User {
} }
} }
//////////////////////////////////////////////////////////////////
// Search Users
//////////////////////////////////////////////////////////////////
public function search_users( $username, $return = "return" ) {
$sql = "SELECT `username` FROM `users` WHERE `username` LIKE ?;";
$bind = "s";
$bind_variables = array( "%{$username}%" );
$result = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error selecting user information." ) );
$user_list = array();
foreach( $result as $row ) {
array_push( $user_list, $row["username"] );
}
if( mysqli_num_rows( $result ) > 0 ) {
switch( $return ) {
case( "exit" ):
exit( formatJSEND( "success", $user_list ) );
break;
case( "json" ):
$return = json_encode( $user_list );
break;
case( "return" ):
$return = $user_list;
break;
}
} else {
switch( $return ) {
case( "exit" ):
exit( formatJSEND( "error", "Error selecting user information." ) );
break;
case( "json" ):
$return = formatJSEND( "error", "Error selecting user information." );
break;
case( "return" ):
$return = null;
break;
}
}
return( $return );
}
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
// Verify Account Exists // Verify Account Exists
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////

View file

@ -129,7 +129,7 @@ if ( $_GET['action'] == 'search_users' ) {
die( formatJSEND( "error", "Missing search term" ) ); die( formatJSEND( "error", "Missing search term" ) );
} }
$User->search_users( $_GET['search_term'], "exit" ); search_users( $_GET['search_term'], "exit", true );
} }
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////