Skip to content

Commit

Permalink
added editKey to prevent editing of old snippets (#19)
Browse files Browse the repository at this point in the history
* added editKey to prevent editing of old snippets
  • Loading branch information
AlexHaxe authored Aug 14, 2024
1 parent 265e6d9 commit 0bc2c54
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ jobs:
run: |
haxelib install utest
- name: Install hx4compat
if: matrix.haxe-version == 'latest'
run: |
haxelib git hx4compat https://github.com/HaxeFoundation/hx4compat.git
- name: Build
run: |
cd tests
Expand Down
2 changes: 1 addition & 1 deletion .haxerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "4.3.1",
"version": "4.3.6",
"resolveLibs": "scoped"
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN groupadd docker; \
gpasswd -a $(whoami) docker; \
gpasswd -a www-data docker
RUN echo "{\n\"storage-driver\": \"vfs\"\n}\n" > /etc/docker/daemon.json
RUN echo "92.243.7.117 try.haxe.org" >> /etc/hosts
# RUN echo "92.243.7.117 try.haxe.org" >> /etc/hosts
# RUN nohup dockerd &
# RUN dockerd & sleep 5; cd dind; \
# docker-compose -f docker-compose-dind.yml create
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ cp -a ~/haxe/neko lixSetup/haxe/neko
cp -a ~/haxe/versions/4.1.5 lixSetup/haxe/versions
```

or

```bash
export HAXESHIM_ROOT=lixSetup/haxe
lix install haxe 4.3.6
```

### Recompile haxe code after you change source code outside

`haxe build.hxml`
Expand Down
2 changes: 1 addition & 1 deletion hashlink-bin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WORKDIR /srv/program
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates build-essential gcc g++ libpcre3 libpcre3-dev git cmake make libpng-dev libopenal-dev libsdl2-dev libmbedtls-dev libuv1-dev libjpeg-turbo8-dev libvorbis-dev libglu1-mesa-dev nodejs npm
RUN npm i lix --global
RUN lix scope create --global
RUN lix install --global haxe 4.2.1
RUN lix install --global haxe 4.3.6
RUN haxelib setup /root/haxe/haxelib
RUN haxelib install hashlink
CMD rm -rf hashlink; \
Expand Down
6 changes: 3 additions & 3 deletions haxe_libraries/format.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @install: lix --silent download "haxelib:/format#3.5.0" into format/3.5.0/haxelib
-cp ${HAXE_LIBCACHE}/format/3.5.0/haxelib/
-D format=3.5.0
# @install: lix --silent download "haxelib:/format#3.7.0" into format/3.7.0/haxelib
-cp ${HAXE_LIBCACHE}/format/3.7.0/haxelib/
-D format=3.7.0
8 changes: 4 additions & 4 deletions haxe_libraries/formatter.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @install: lix --silent download "haxelib:/formatter#1.14.6" into formatter/1.14.6/haxelib
# @run: haxelib run-dir formatter "${HAXE_LIBCACHE}/formatter/1.14.6/haxelib"
-cp ${HAXE_LIBCACHE}/formatter/1.14.6/haxelib/src
-D formatter=1.14.6
# @install: lix --silent download "haxelib:/formatter#1.16.0" into formatter/1.16.0/haxelib
# @run: haxelib run-dir formatter "${HAXE_LIBCACHE}/formatter/1.16.0/haxelib"
-cp ${HAXE_LIBCACHE}/formatter/1.16.0/haxelib/src
-D formatter=1.16.0
4 changes: 2 additions & 2 deletions haxe_libraries/haxeparser.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/haxeparser#f0a7f07101c14dc32b0964dd52af8dcaa322e178" into haxeparser/4.3.0-rc.1/github/f0a7f07101c14dc32b0964dd52af8dcaa322e178
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/haxeparser#a5fce2ecf5fb3bdfebfd7efd8b05329d456ec0d2" into haxeparser/4.3.0-rc.1/github/a5fce2ecf5fb3bdfebfd7efd8b05329d456ec0d2
-lib hxparse
-cp ${HAXE_LIBCACHE}/haxeparser/4.3.0-rc.1/github/f0a7f07101c14dc32b0964dd52af8dcaa322e178/src
-cp ${HAXE_LIBCACHE}/haxeparser/4.3.0-rc.1/github/a5fce2ecf5fb3bdfebfd7efd8b05329d456ec0d2/src
-D haxeparser=4.3.0-rc.1
4 changes: 2 additions & 2 deletions haxe_libraries/hx3compat.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @install: lix --silent download "gh://github.com/HaxeFoundation/hx3compat#91edf63bfd82d0d110a51c96028905b962c7968e" into hx3compat/1.0.3/github/91edf63bfd82d0d110a51c96028905b962c7968e
-cp ${HAXE_LIBCACHE}/hx3compat/1.0.3/github/91edf63bfd82d0d110a51c96028905b962c7968e/std
# @install: lix --silent download "gh://github.com/HaxeFoundation/hx3compat#abcb97053906d349c8b8172f61934d66074e65be" into hx3compat/1.0.3/github/abcb97053906d349c8b8172f61934d66074e65be
-cp ${HAXE_LIBCACHE}/hx3compat/1.0.3/github/abcb97053906d349c8b8172f61934d66074e65be/std
-D hx3compat=1.0.3
3 changes: 3 additions & 0 deletions haxe_libraries/hx4compat.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @install: lix --silent download "gh://github.com/HaxeFoundation/hx4compat#bcfa1ee78bca457c0db38e10aa3e7d5ba816943c" into hx4compat/1.0.0/github/bcfa1ee78bca457c0db38e10aa3e7d5ba816943c
-cp ${HAXE_LIBCACHE}/hx4compat/1.0.0/github/bcfa1ee78bca457c0db38e10aa3e7d5ba816943c/std
-D hx4compat=1.0.0
6 changes: 3 additions & 3 deletions haxe_libraries/hxparse.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @install: lix --silent download "gh://github.com/simn/hxparse#32e376f80c4b0e999e9f3229947d4dac2138382b" into hxparse/4.0.1/github/32e376f80c4b0e999e9f3229947d4dac2138382b
-cp ${HAXE_LIBCACHE}/hxparse/4.0.1/github/32e376f80c4b0e999e9f3229947d4dac2138382b/src
-D hxparse=4.0.1
# @install: lix --silent download "gh://github.com/simn/hxparse#876070ec62a4869de60081f87763e23457a3bda8" into hxparse/4.3.0/github/876070ec62a4869de60081f87763e23457a3bda8
-cp ${HAXE_LIBCACHE}/hxparse/4.3.0/github/876070ec62a4869de60081f87763e23457a3bda8/src
-D hxparse=4.3.0
6 changes: 3 additions & 3 deletions haxe_libraries/tokentree.hxml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @install: lix --silent download "haxelib:/tokentree#1.2.8" into tokentree/1.2.8/haxelib
-cp ${HAXE_LIBCACHE}/tokentree/1.2.8/haxelib/src
-D tokentree=1.2.8
# @install: lix --silent download "haxelib:/tokentree#1.2.13" into tokentree/1.2.13/haxelib
-cp ${HAXE_LIBCACHE}/tokentree/1.2.13/haxelib/src
-D tokentree=1.2.13
5 changes: 5 additions & 0 deletions haxe_libraries/utest.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @install: lix --silent download "haxelib:/utest#1.13.2" into utest/1.13.2/haxelib
-cp ${HAXE_LIBCACHE}/utest/1.13.2/haxelib/src
-D utest=1.13.2
--macro utest.utils.Macro.checkHaxe()
--macro utest.utils.Macro.importEnvSettings()
2 changes: 1 addition & 1 deletion lixSetup/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ RUN npm install --global lix || true
CMD export HAXESHIM_ROOT=/srv/lixSetup/haxe; \
lix download; \
lix install haxe nightly; \
lix install haxe 4.1.5
lix install haxe 4.3.6
7 changes: 4 additions & 3 deletions src/Api.hx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import api.Compiler;
import api.Program.ProgramV2;
import haxe.io.Path;
import haxe.remoting.Context;
import haxe.web.Dispatch;
import php.Lib;
import sys.FileSystem;
import sys.io.File;
import api.Compiler;
import api.Program.ProgramV2;
import template.Templates;

class Api {
Expand Down Expand Up @@ -138,14 +138,15 @@ class Api {
req.onData = function(src) {
var program:ProgramV2 = {
uid: uid,
editKey: null,
mainClass: main,
modules: [
{
name: main,
source: src
},
],
haxeVersion: Haxe_4_1_5,
haxeVersion: Haxe_4_3_6,
dce: dce,
analyzer: analyzer,
target: JS("test", ES6),
Expand Down
4 changes: 3 additions & 1 deletion src/Editor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,15 @@ class Editor {

program = {
uid: null,
editKey: null,
mainClass: "Test",
modules: [
for (src in haxeEditors)
{name: src.nameElement.val(), source: src.codeMirror.getValue()}
],
dce: "full",
analyzer: "yes",
haxeVersion: Haxe_4_1_5,
haxeVersion: Haxe_4_3_6,
target: JS("test", ES6),
libs: new Array()
};
Expand Down Expand Up @@ -802,6 +803,7 @@ class Editor {

output = o;
program.uid = output.uid;
program.editKey = o.editKey;
window.location.hash = "#" + output.uid;
document.title = 'Try Haxe #${output.uid}';

Expand Down
37 changes: 32 additions & 5 deletions src/api/Compiler.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package api;

import haxe.Exception;
import haxe.crypto.Md5;
import haxe.crypto.Sha256;
import haxe.io.Path;
import api.Completion.CompletionItem;
import api.Completion.CompletionResult;
Expand All @@ -21,8 +23,8 @@ class Compiler {
var programFolder:String;
var mainFile:String;

public static var haxePath = "haxe";
public static var dockerContainer = "try-haxe_compiler";
public static final haxePath = "haxe";
public static final dockerContainer = "try-haxe_compiler";

public function new() {}

Expand All @@ -49,7 +51,7 @@ class Compiler {
return v.gitHash;
}
}
return Haxe_4_1_5;
return Haxe_4_3_6;
}

public function prepareProgram(program:ProgramV2) {
Expand All @@ -69,11 +71,27 @@ class Compiler {
Api.checkSanity(program.uid);
Api.checkSanity(program.mainClass);
Api.checkDCE(program.dce);
var editKey:String = program.editKey;

if (editKey == null) {
editKey = haxe.crypto.Md5.encode(Std.string(Math.random()) + Std.string(Date.now().getTime()));
}

programFolder = Path.join([Api.programsRootFolder, program.uid.substr(0, 2), program.uid]);
var keyFile:String = Path.join([programFolder, editKey + ".key"]);

if (!FileSystem.isDirectory(programFolder)) {
FileSystem.createDirectory(programFolder);
} else {
if (!FileSystem.exists(keyFile)) {
for (name in FileSystem.readDirectory(programFolder)) {
if (Path.extension(name) == "key") {
var path = Path.join([programFolder, name]);
FileSystem.deleteFile(path);
}
}
throw "readonly program";
}
}

for (name in FileSystem.readDirectory(programFolder)) {
Expand All @@ -95,15 +113,19 @@ class Compiler {
checkMacros(src);
File.saveContent(file, src);
}
File.saveContent(keyFile, "");

var s = program.modules.copy();
for (module in program.modules)
module.source = null;

// don't store editKey in serialised program
program.editKey = null;
File.saveContent(Path.join([programFolder, "program"]), haxe.Serializer.run(program));
program.modules = s;
program.editKey = editKey;
}

// public function getProgram(uid:String):{p:Program, o:Program.Output}
public function getProgram(uid:String):ProgramV2 {
Api.checkSanity(uid);

Expand Down Expand Up @@ -138,6 +160,7 @@ class Compiler {
var old:Dynamic = haxe.Unserializer.run(s);
p = {
uid: old.uid,
editKey: null,
mainClass: old.main.name,
target: old.target,
libs: old.libs,
Expand All @@ -154,7 +177,7 @@ class Compiler {
}
}
if ((p.haxeVersion == null) || (p.haxeVersion == "null")) {
p.haxeVersion = Haxe_4_1_5;
p.haxeVersion = Haxe_4_3_6;
}

for (module in p.modules) {
Expand Down Expand Up @@ -195,6 +218,7 @@ class Compiler {
}
var program:ProgramV2 = {
uid: uid,
editKey: null,
mainClass: oldProgram.main.name,
modules: [
oldProgram.main,
Expand Down Expand Up @@ -359,6 +383,7 @@ class Compiler {
} catch (err:String) {
return {
uid: program.uid,
editKey: null,
args: [],
stderr: err,
stdout: "",
Expand Down Expand Up @@ -446,6 +471,7 @@ class Compiler {
var output:Program.Output = if (out.exitCode == 0) {
{
uid: program.uid,
editKey: program.editKey,
stderr: err,
stdout: out.out,
args: args,
Expand All @@ -461,6 +487,7 @@ class Compiler {
} else {
{
uid: program.uid,
editKey: program.editKey,
stderr: err,
stdout: out.out,
args: args,
Expand Down
3 changes: 1 addition & 2 deletions src/api/Completion.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ typedef Completion = {
contents:String
}

@:enum
abstract CompletionType(Int) {
enum abstract CompletionType(Int) {
var DEFAULT = 0;
var TOP_LEVEL = 1;
}
Expand Down
5 changes: 4 additions & 1 deletion src/api/Program.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef Program = {

typedef ProgramV2 = {
uid:String,
editKey:Null<String>,
mainClass:String,
modules:Array<Module>,
target:TargetV2,
Expand Down Expand Up @@ -48,15 +49,17 @@ enum ECMAScriptVersion {
}

@:transitive
@:enum abstract HaxeVersion(String) to String from String {
enum abstract HaxeVersion(String) to String from String {
// var Haxe_3_3_0_rc_1 = "3.3.0-rc.1";
// var Haxe_3_2_1 = "3.2.1";
var Haxe_4_1_5 = "4.1.5";
var Haxe_4_3_0 = "4.3.0";
var Haxe_4_3_6 = "4.3.6";
}

typedef Output = {
uid:String,
editKey:Null<String>,
stderr:String,
stdout:String,
args:Array<String>,
Expand Down
4 changes: 4 additions & 0 deletions tests/RunCi.hx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ class RunCi {
static inline var EXAMPLES_DIR = "../www/examples/";
static var examplesToSkip = [#if (haxe_ver < "4.2.0") "Example-23.hx" #end];
static var exampleTargets = ["Example-20.hx" => Js];
#if (haxe_ver >= 5.00)
static var librariesForExamples = ["Example-22.hx" => ["utest", "hx4compat"]];
#else
static var librariesForExamples = ["Example-22.hx" => ["utest"]];
#end

public static function main():Void {
var target:Target = Sys.args()[0];
Expand Down

0 comments on commit 0bc2c54

Please sign in to comment.