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

173
admin.php
View File

@ -1,172 +1,3 @@
<?php
/**
* 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>
//Silence is golden.
?>

View File

@ -117,7 +117,7 @@ class Common {
//////////////////////////////////////////////////////////////////
// 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' );";
$bind = "sss";
@ -151,13 +151,20 @@ class Common {
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_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();
foreach( $result as $row ) {
@ -220,6 +227,74 @@ class Common {
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
//////////////////////////////////////////////////////////////////
@ -580,5 +655,6 @@ function checkAccess() { return Common::checkAccess(); }
function checkPath($path) { return Common::checkPath($path); }
function isAvailable($func) { return Common::isAvailable($func); }
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'];
?>
<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'){ ?>
<label><?php i18n("Replace:"); ?></label>
<input type="text" name="replace">
<textarea name="replace"></textarea>
<?php } ?>
@ -52,7 +52,7 @@ switch($_GET['action']){
<script>
$(function(){
<?php if($_GET['action']=='search'){ ?>
$('input[name="find"]').val(codiad.active.getSelectedText());
$('textarea[name="find"]').val(codiad.active.getSelectedText());
<?php } ?>
});

View File

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

View File

@ -17,51 +17,42 @@ checkSession();
?>
<label><?php i18n("Upload Files"); ?></label>
<div id="upload-drop-zone">
<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>
<span id="upload-clicker"><?php i18n("Drag Files or Click Here to Upload"); ?></span>
</span>
<div id="upload-progress"><div class="bar"></div></div>
<div id="upload-complete"><?php i18n("Complete!"); ?></div>
<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>
<span id="upload-clicker"><?php i18n("Drag Files or Click Here to Upload"); ?></span>
</span>
<div id="upload-progress"><div class="bar"></div></div>
<div id="upload-complete"><?php i18n("Complete!"); ?></div>
</div>
<button onclick="codiad.modal.unload();"><?php i18n("Close Uploader"); ?></button>
<script>
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
dropZone: '#upload-drop-zone',
progressall: function(e, data){
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#upload-progress .bar').css(
'width',
progress + '%'
);
if(progress>98){ $('#upload-complete').fadeIn(200); }
},
done: function(e, data){
$.each(data.result, function (index, file){
var path = '<?php echo($_GET['path']); ?>';
codiad.filemanager.createObject(path, path + "/" + file.name,'file');
/* Notify listeners. */
amplify.publish('filemanager.onUpload', {file: file, path: path});
});
setTimeout(function(){
$('#upload-progress .bar').animate({'width':0},700);
$('#upload-complete').fadeOut(200);
},1000);
}
});
});
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
dropZone: '#upload-drop-zone',
progressall: function( e, data ) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#upload-progress .bar').css(
'width',
progress + '%'
);
if(progress>98){ $('#upload-complete').fadeIn(200); }
},
done: function(e, data){
$.each(data.result, function (index, file){
var path = '<?php echo($_GET['path']); ?>';
codiad.filemanager.createObject(path, path + "/" + file.name,'file');
/* Notify listeners. */
amplify.publish('filemanager.onUpload', {file: file, path: path});
});
setTimeout(function(){
$('#upload-progress .bar').animate({'width':0},700);
$('#upload-complete').fadeOut(200);
},1000);
}
});
});
</script>

View File

@ -23,6 +23,7 @@ class Project extends Common {
public $assigned = false;
public $command_exec = '';
public $public_project = false;
public $user = '';
//////////////////////////////////////////////////////////////////
// METHODS
@ -61,6 +62,45 @@ class Project extends Common {
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 ) {
if( $path === null ) {
@ -162,9 +202,9 @@ class Project extends Common {
public function get_projects() {
$sql = "SELECT * FROM `projects` WHERE `owner`=? OR `owner`='nobody' ORDER BY `name`;";
$bind = "s";
$bind_variables = array( $_SESSION["user"] );
$sql = "SELECT * FROM `projects` WHERE `owner`=? OR `owner`='nobody' OR `access` LIKE ? ORDER BY `name`;";
$bind = "ss";
$bind_variables = array( $_SESSION["user"], '%"' . $_SESSION["user"] . '"%' );
$return = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error fetching projects." ) );
if( mysqli_num_rows( $return ) > 0 ) {
@ -178,6 +218,45 @@ class Project extends Common {
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 ) {
$sql = "SELECT * FROM `projects` WHERE `name`=? AND `path`=? AND ( `owner`=? OR `owner`='nobody' );";
@ -243,9 +322,9 @@ class Project extends Common {
public function Open() {
$sql = "SELECT * FROM `projects` WHERE `path`=? AND ( `owner`=? OR `owner`='nobody' );";
$bind = "ss";
$bind_variables = array( $this->path, $_SESSION["user"] );
$sql = "SELECT * FROM `projects` WHERE `path`=? AND ( `owner`=? OR `owner`='nobody' OR `access` LIKE ? );";
$bind = "sss";
$bind_variables = array( $this->path, $_SESSION["user"], '%"' . $_SESSION["user"] . '"%' );
$return = sql::sql( $sql, $bind, $bind_variables, formatJSEND( "error", "Error fetching projects." ) );
if( mysqli_num_rows( $return ) > 0 ) {

View File

@ -18,6 +18,42 @@ checkSession();
$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
//////////////////////////////////////////////////////////////////
@ -150,6 +186,41 @@ if( $_GET['action'] == '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
//////////////////////////////////////////////////////////////////

View File

@ -204,13 +204,13 @@ switch( $_GET['action'] ) {
$path = $_GET['path'];
$project = $Project->get_project( $path );
$access = json_decode( $project["access"], true );
$users = get_users();
$users = get_users( "return", true );
?>
<form>
<input type="hidden" name="project_path" value="<?php echo( $path );?>">
<label><span class="icon-pencil"></span><?php i18n( "Add Users" );?></label>
<input id="search_users" type="text" onkeyup="codiad.project.search_users();" />
<select id="user_list">
<select id="user_list" name="user_list">
<?php
foreach( $users as $user ) {
@ -250,7 +250,7 @@ switch( $_GET['action'] ) {
<?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>
<?php
break;

View File

@ -51,13 +51,25 @@
// Add user access
//////////////////////////////////////////////////////////////////
add_user: function( user ) {
add_user: function() {
var _this = this;
$( '#modal-content form' ).live( 'submit', function( e ) {
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 ) {
var _this = this;
$( '#modal-content form' ).live( 'submit', function( e ) {
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",
"admin": false,
"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",

View File

@ -8,6 +8,73 @@
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
//////////////////////////////////////////////////////////////////

View File

@ -39,10 +39,10 @@ class Update {
public function __construct() {
ini_set("user_agent", "Codiad");
$this->archive = "https://gitlab.telaaedifex.com/xevidos/codiad/-/archive/master/codiad-master.zip";
$this->commits = "https://gitlab.telaaedifex.com/api/v4/projects/3/repository/commits/";
$this->tags = "https://gitlab.telaaedifex.com/api/v4/projects/3/repository/tags/";
$this->update_file = "https://gitlab.telaaedifex.com/xevidos/codiad/raw/master/components/update/update.php";
$this->archive = "https://gitlab.com/xevidos/codiad/-/archive/master/codiad-master.zip";
$this->commits = "https://gitlab.com/api/v4/projects/8466613/repository/commits/";
$this->tags = "https://gitlab.com/api/v4/projects/8466613/repository/tags/";
$this->update_file = "https://gitlab.com/xevidos/codiad/raw/master/components/update/update.php";
$this->protocol = $this->CheckProtocol();
}
@ -183,16 +183,15 @@ class Update {
public function getLocalVersion(){
return getJSON('version.php');;
return getJSON( 'version.php' );
}
//////////////////////////////////////////////////////////////////
// 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" ) {
return;
@ -203,15 +202,15 @@ class Update {
case( "curl" ):
$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_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');
$content = curl_exec($curl);
curl_close($curl);
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' );
$content = curl_exec( $curl );
curl_close( $curl );
$response = json_decode( $content, true );
//Return latest release
@ -222,7 +221,5 @@ class Update {
break;
}
//return( json_decode( file_get_contents( $remoteurl ), true ) );
}
}

View File

@ -38,17 +38,17 @@ class updater {
public $archive = "";
public $path = "";
public $protocol = "";
public $update = null;
function __construct() {
$update = new Update();
$this->archive = $update->archive;
$this->update = new Update();
/*$this->archive = $update->archive;
$this->path = Common::getConstant('BASE_PATH');
$this->protocol = $this->check_protocol();
//Trigger update
$this->update();
$this->update();*/
}
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 ) {
// Check for symlinks
if (is_link($source)) {
@ -158,7 +173,7 @@ class updater {
}
function remove_directory( $path ) {
$files = glob($path . '/*');
foreach ($files as $file) {
@ -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>
<html>
@ -271,8 +301,6 @@ class updater {
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);
@ -287,230 +315,77 @@ class updater {
}
</style>
<script src="../../js/jquery-1.7.2.min.js"></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>
</head>
<body>
<h1 class="title" style="text-align: center;">
Telaaedifex Codiad Updater
Tela Codiad Updater
</h1>
<div id="progress">
Starting Update ...
<div>
<p id="progress"></p>
</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>
codiad.update.init();
</script>
</head>
<body>
<h1 class="title" style="text-align: center;">
Telaaedifex Codiad Updater
</h1>
<div id="progress">
Starting Update ...
</div>
</body>
</html>
<?php
new updater();
?>

View File

@ -6,6 +6,8 @@
* [root]/license.txt for more. This information must remain intact.
*/
require_once( "../settings/class.settings.php" );
class User {
//////////////////////////////////////////////////////////////////
@ -46,6 +48,7 @@ class User {
if( sql::check_sql_error( $return ) ) {
$this->set_default_options();
echo formatJSEND( "success", array( "username" => $this->username ) );
} 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 ) {
$sql = "SELECT * FROM `users` WHERE `username`=?";
@ -78,6 +108,16 @@ class User {
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
@ -252,18 +292,7 @@ class User {
public function Delete() {
$sql = "DELETE FROM `users` WHERE `username`=?;";
$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;
}
$this->delete_user();
}
//////////////////////////////////////////////////////////////////
@ -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
//////////////////////////////////////////////////////////////////

View File

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