function admin_svn_log($user, $path) { $userdata = setup_paths($user); $svn_url = "file://" . $userdata['svn'] . "/" . $path; $ws_url = $userdata['workspace']; $revert_possible = !is_dir($ws_url); $svn_log = svn_log($svn_url); if (empty($svn_log)) { ?> <p>Path <b><?php echo $path; ?> </b> is not on SVN repository.</p> <?php if (file_exists($ws_url)) { print "<p>Kontaktirajte administratora!</p>\n"; } } print "<ul class=\"svn_log\">\n"; foreach ($svn_log as $entry) { ?> <li class="svn_log_entry">(r<?php echo $entry['rev']; ?> ) <?php echo date("d. m. Y. H:i:s", strtotime($entry['date'])); ?> - <?php echo $entry['msg']; ?> <ul> <?php foreach ($entry['paths'] as $svnpath) { $the_path = $svnpath['path']; if ($the_path[0] == "/") { $the_path = substr($the_path, 1); } ?> <li><a href="?user=<?php echo $user; ?> &path=<?php echo urlencode($the_path); ?> &svn_rev=<?php echo $entry['rev']; ?> "><?php echo $svnpath['path']; ?> </a></li> <?php } print "</ul></li>\n"; } }
function last_access($username) { global $conf_base_path, $is_svn_node, $is_control_node, $svn_node_addr; $userdata = setup_paths($username); $last_path = $conf_base_path . "/last/" . $userdata['efn'] . ".last"; if (file_exists($last_path)) { return intval(file_get_contents($last_path)); } // No last file, check svn data if (!file_exists($userdata['workspace'])) { return 0; } if ($is_svn_node) { run_as($username, "cd " . $userdata['workspace'] . "; svn update"); $svn_output = shell_exec("cd " . $userdata['workspace'] . "; svn log -l 1 | cut -d \" \" -f 5-6"); foreach (explode("\n", $svn_output) as $svn_line) { $time = strtotime($svn_line); if ($time > 0) { return $time; } } } else { if ($is_control_node) { $last = run_on($svn_node_addr, "{$conf_base_path}/bin/webidectl last " . $userdata['esa']); return intval($last); } } // This is too slow! //$time = exec("find $student_workspace -type f -printf '%T@\n' | sort -n | tail -1"); // Timestamp of last modified file //return $time;; return 0; }
function pwi_editor($username, $cur_path, $editable) { global $conf_base_path; $svn_user_path = setup_paths($username)['svn']; $content = ""; $ace_mode = "c_cpp"; // fixme $isdir = `sudo {$conf_base_path}/bin/wsaccess {$username} isdir "{$cur_path}"`; if (isset($_REQUEST['svn_rev'])) { $rev = intval($_REQUEST['svn_rev']); $svn_file_path = "file://" . $svn_user_path . "/{$cur_path}"; $content = htmlspecialchars(svn_cat($svn_file_path, $rev)); } else { if (isset($_REQUEST['git_rev'])) { $rev = $_REQUEST['git_rev']; $content = htmlspecialchars(`sudo {$conf_base_path}/bin/wsaccess {$username} git-show "{$cur_path}" "{$rev}"`); } else { if ($isdir != 1) { $content = htmlspecialchars(`sudo {$conf_base_path}/bin/wsaccess {$username} read "{$cur_path}"`); } } } ?> <div id="editor"><?php echo $content; ?> </div> <div id="status"></div> <script src="https://zamger.etf.unsa.ba/js/ace/ace.js" type="text/javascript" charset="utf-8"></script> <script> var editor = ace.edit("editor"); //editor.setTheme("ace/theme/monokai"); editor.getSession().setMode("ace/mode/<?php echo $ace_mode; ?> "); console.log(window.innerHeight); console.log(document.getElementById('editor').style.top); // Zašto ne radi??? console.log(document.getElementById('phpwebide_tree').clientHeight); var newbottom = window.innerHeight - 220 - document.getElementById('phpwebide_tree').clientHeight; console.log(newbottom); newbottom = "" + newbottom; newbottom = newbottom + "px"; document.getElementById('editor').style.bottom = newbottom; editor.focus(); <?php if (!$editable) { ?> editor.setOptions({ readOnly: true, highlightActiveLine: false, highlightGutterLine: false }) editor.renderer.$cursorLayer.element.style.opacity=0 editor.textInput.getElement().tabIndex=-1 editor.commands.commmandKeyBinding={} <?php } else { ?> editor.getSession().on("change", scheduleSave); var timeout, has_timeout=0; function scheduleSave(e) { //alert("hello"); if (has_timeout) clearTimeout(timeout); timeout = setTimeout('doSave()', 5000); has_timeout = 1; } function doSave() { has_timeout = 0; var mypostrequest=new ajaxRequest() mypostrequest.onreadystatechange=function() { if (mypostrequest.readyState==4){ if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){ var xmldata=mypostrequest.responseText; //retrieve result as an text if (xmldata.indexOf("GRESKA") > -1) document.getElementById('status').innerHTML = xmldata; //"Greška pri snimanju A"; else document.getElementById('status').innerHTML = "Program snimljen"; } else { document.getElementById('status').innerHTML = "Greška pri snimanju B"; } } } var editor = ace.edit("editor"); var code = encodeURIComponent(editor.getSession().getValue()) var sta = encodeURIComponent('<?php echo $_REQUEST['sta']; ?> '); var akcija = encodeURIComponent("slanje"); var student = encodeURIComponent(<?php echo $student; ?> ); var zadaca = encodeURIComponent(<?php echo $zadaca; ?> ); var zadatak = encodeURIComponent(<?php echo $zadatak; ?> ); var projekat = encodeURIComponent(<?php echo $projekat; ?> ); var parameters="sta="+sta+"&akcija="+akcija+"&student="+student+"&zadaca="+zadaca+"&zadatak="+zadatak+"&projekat="+projekat+"&code="+code; mypostrequest.open("POST", "index.php", true) mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded") mypostrequest.send(parameters) } function ajaxRequest() { var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken) for (var i=0; i<activexmodes.length; i++){ try{ return new ActiveXObject(activexmodes[i]) } catch(e){ //suppress error } } } else if (window.XMLHttpRequest) // if Mozilla, Safari etc return new XMLHttpRequest() else return false } <?php } print "</script>\n"; }
// Args if ($argc == 1) { die("ERROR: username is required\n"); } $username = $argv[1]; $sleep = 60; if ($argc > 2) { $sleep = $argv[2]; } //$banned_users = array("egradanin1", "bdzanko1", "test"); $banned_users = array("test"); if (in_array($username, $banned_users)) { die("ERROR: username banned\n"); } sleep($sleep); $userdata = setup_paths($username); $users_file = $conf_base_path . "/users"; eval(file_get_contents($users_file)); if ($users[$username]['status'] == 'active') { print "ERROR: User is logged in\n"; exit(0); } // Perform the following actions fixsvn("find . -name .valgrind.out.core.* -print0 | xargs -0 --no-run-if-empty svn remove --force"); fixsvn("svn ci -m fixsvn ."); fixsvn("svn add *"); fixsvn("svn add */*"); fixsvn("svn add */*/*"); fixsvn("svn add */*/*/*"); fixsvn("svn ci -m fixsvn ."); function fixsvn($command)
function reconstruct_file($username, $filename, $timestamp) { global $stats, $base_path; $userdata = setup_paths($username); if (!array_key_exists($filename, $stats)) { die("ERROR: File doesn't exist in stats log"); } $file_workspace_path = $userdata['workspace'] . "/{$filename}"; if (!file_exists($file_workspace_path)) { print "File doesn't exist in workspace...\nCreating from blank (possibly with errors!)\n\n"; $work_file = array(); } else { $work_file = file($file_workspace_path); } $file_log = $stats[$filename]['events']; $evtcount = count($file_log); // We reconstruct the file backwards from its current state for ($i = $evtcount - 1; $i >= 0; $i--) { //print "$i,"; if ($file_log[$i]['time'] < $timestamp) { break; } if ($i < -$timestamp) { break; } if ($file_log[$i]['text'] != "modified") { continue; } if (array_key_exists("change", $file_log[$i]['diff'])) { foreach ($file_log[$i]['diff']['change'] as $lineno => $text) { // Editing last line - special case! if ($lineno - 1 == count($work_file)) { $lineno--; } // Since php arrays are associative, we must initialize missing members in correct order if ($lineno - 1 > count($work_file)) { if ($lineno == 2) { $lineno = 1; } else { for ($j = count($work_file); $j < $lineno; $j++) { $work_file[$j] = "\n"; } } } $work_file[$lineno - 1] = $text . "\n"; } } if (array_key_exists("add_lines", $file_log[$i]['diff'])) { $offset = 1; foreach ($file_log[$i]['diff']['add_lines'] as $lineno => $text) { if ($offset == 0 && $lineno == 0) { $offset = 1; } if ($lineno - $offset > count($work_file)) { for ($j = count($work_file); $j < $lineno - $offset + 1; $j++) { $work_file[$j] = "\n"; } } array_splice($work_file, $lineno - $offset, 1); $offset++; } } if (array_key_exists("remove_lines", $file_log[$i]['diff'])) { $offset = -1; foreach ($file_log[$i]['diff']['remove_lines'] as $lineno => $text) { if ($lineno + $offset > count($work_file)) { for ($j = count($work_file); $j < $lineno + $offset + 1; $j++) { $work_file[$j] = "\n"; } } if ($text == "false" || $text === false) { $text = ""; } array_splice($work_file, $lineno + $offset, 0, $text . "\n"); } } } $output_path = "/tmp/reconstruct"; if (!file_exists($output_path)) { mkdir($output_path); } $output_path .= "/" . basename($filename); file_put_contents($output_path, join("", $work_file)); print "Written file {$output_path}, merged " . ($evtcount - $i) . " changes.\n"; }
<?php require dirname(__FILE__) . "/../lib/config.php"; require dirname(__FILE__) . "/../lib/webidelib.php"; $users_file = $conf_base_path . "/users"; eval(file_get_contents($users_file)); ksort($users); $total = count($users); $current = 1; foreach ($users as $username => $options) { print "{$username} ({$current}/{$total}):\n"; $current++; $ws = setup_paths($username)['workspace']; if (!file_exists($ws)) { continue; } print run_as($username, "cd {$ws}; find . -name \"*core*\" -exec svn delete {} \\; ; svn ci -m corovi ."); print run_as($username, "cd {$ws}; find . -name \"*core*\" -delete"); }