Example #1
0
  private void _loadConfig() {
    try {

      _configScope.set("__instance__", this);

      _loadConfigFromCloudObject(getSiteObject());
      _loadConfigFromCloudObject(getEnvironmentObject());

      File f;
      if (!_admin) {
        f = getFileSafe("_config.js");
        if (f == null || !f.exists()) f = getFileSafe("_config");
      } else
        f =
            new File(
                Module.getModule("core-modules/admin").getRootFile(getVersionForLibrary("admin")),
                "_config.js");

      _libraryLogger.info("config file [" + f + "] exists:" + f.exists());

      if (f == null || !f.exists()) return;

      Convert c = new Convert(f);
      JSFunction func = c.get();
      func.setUsePassedInScope(true);
      func.call(_configScope);

      _logger.debug("config things " + _configScope.keySet());
    } catch (Exception e) {
      throw new RuntimeException("couldn't load config", e);
    }
  }
Example #2
0
 static void LoadModule(String s, int i, String s1, boolean flag) {
   DatagramSocket datagramsocket = null;
   Object obj = null;
   System.out.println("Loading from " + s + ":" + i);
   try {
     datagramsocket = new DatagramSocket();
     datagramsocket.setSoTimeout(10000);
     InetAddress inetaddress = InetAddress.getByName(s);
     Module module = LoadModule(datagramsocket, inetaddress, i, s1, flag);
     if (module != null) module.write();
   } catch (Exception exception) {
     exception.printStackTrace();
     if (datagramsocket != null)
       try {
         datagramsocket.close();
       } catch (Exception exception2) {
       }
     return;
   }
   try {
     datagramsocket.close();
   } catch (Exception exception1) {
   }
 }
Example #3
0
  static Module LoadModule(
      DatagramSocket datagramsocket, InetAddress inetaddress, int i, String s, boolean flag) {
    try {
      Module module = new Module();
      module.Name = s;
      int j = Challenge(datagramsocket, inetaddress, i);
      System.out.print("Sending the get request, file '" + s);
      if (flag) System.out.print(" [beta] ");
      byte abyte0[] = Cmd_Get(s, j, flag);
      datagramsocket.send(new DatagramPacket(abyte0, abyte0.length, inetaddress, i));
      try {
        Thread.sleep(50L);
      } catch (Exception exception2) {
      }
      System.out.print("' ...");
      abyte0 = new byte[256];
      DatagramPacket datagrampacket = new DatagramPacket(abyte0, abyte0.length);
      datagramsocket.receive(datagrampacket);
      System.out.println(" ok ");
      ReqFile reqfile = new ReqFile(abyte0);
      if (!((Req) (reqfile)).legal) {
        System.out.println("Can't download module " + s);
        return null;
      }
      module.Size = reqfile.Size;
      module.Header = reqfile.Header;
      module.Data = new byte[module.Size];
      Module module1 = null;
      try {
        module1 = new Module(s);
      } catch (Exception exception3) {
        module1 = null;
      }
      if (module1 != null && module1.compareHeader(module)) {
        byte abyte1[] = Cmd_Abort("");
        datagramsocket.send(new DatagramPacket(abyte1, abyte1.length, inetaddress, i));
        System.out.println(s + " is already the newest version.");
        return null;
      }
      System.out.print("downloading data");
      int k = 0;
      do {
        byte abyte2[] = Cmd_Next(k);
        datagramsocket.send(new DatagramPacket(abyte2, abyte2.length, inetaddress, i));
        try {
          Thread.sleep(50L);
        } catch (Exception exception4) {
        }
        abyte2 = new byte[16534];
        DatagramPacket datagrampacket1 = new DatagramPacket(abyte2, abyte2.length);

        try {
          datagramsocket.receive(datagrampacket1);
        } catch (InterruptedIOException e) {
          continue;
        }

        ReqBlock reqblock = new ReqBlock(abyte2);
        if (!((Req) (reqblock)).legal) {
          if (!"FINISH".equals(((Req) (reqblock)).Cmd)) throw new Exception("Protocol violation");
          break;
        }
        System.arraycopy(reqblock.Data, 0, module.Data, k, reqblock.Size);
        k += reqblock.Size;
        System.out.print(".");
      } while (true);
      if (k != module.Size) {
        throw new Exception("File size mismatch");
      } else {
        System.out.println("done");
        Module.decode(module.Data, j);
        return module;
      }
    } catch (Exception exception) {
      exception.printStackTrace();
    }
    if (datagramsocket != null)
      try {
        datagramsocket.close();
      } catch (Exception exception1) {
      }
    System.out.println("Can't download module " + s);
    return null;
  }
Example #4
0
  /** Initializes the base scope for the application */
  private void _baseScopeInit() {
    // --- libraries

    if (_admin) _scope.put("local", new JSObjectBase(), true);
    else _setLocalObject(new JSFileLibrary(_rootFile, "local", this));

    _loadConfig();

    _core = CoreJS.get().getLibrary(getCoreJSVersion(), this, null, true);
    _logger.info("corejs : " + _core.getRoot());
    _scope.put("core", _core, true);

    _external =
        Module.getModule("external").getLibrary(getVersionForLibrary("external"), this, null, true);
    _scope.put("external", _external, true);

    _scope.put("__instance__", this, true);
    _scope.lock("__instance__");

    // --- db

    if (!_isGrid) {
      _scope.put("db", DBProvider.get(this), true);
      _scope.put(
          "setDB",
          new JSFunctionCalls1() {

            public Object call(Scope s, Object name, Object extra[]) {
              if (name.equals(_lastSetTo)) return true;

              DBBase db = (DBBase) AppContext.this._scope.get("db");
              if (!db.allowedToAccess(name.toString()))
                throw new JSException("you are not allowed to access db [" + name + "]");

              if (name.equals(db.getName())) return true;

              AppContext.this._scope.put(
                  "db", DBProvider.get(AppContext.this, name.toString()), false);
              _lastSetTo = name.toString();

              if (_adminContext != null) {
                // yes, i do want a new copy so Constructors don't get copied for both
                _adminContext._scope.put(
                    "db", DBProvider.get(AppContext.this, name.toString()), false);
              }

              return true;
            }

            String _lastSetTo = null;
          },
          true);
    }

    // --- output

    _scope.put(
        "SYSOUT",
        new JSFunctionCalls1() {
          public Object call(Scope s, Object str, Object foo[]) {
            System.out.println(AppContext.this._name + " \t " + str);
            return true;
          }
        },
        true);

    _scope.put("log", _logger, true);

    // --- random?

    _scope.put(
        "openFile",
        new JSFunctionCalls1() {
          public Object call(Scope s, Object name, Object extra[]) {
            return new JSLocalFile(_rootFile, name.toString());
          }
        },
        true);

    _scope.put("globalHead", _globalHead, true);

    Map<String, JSFileLibrary> rootFileMap = new HashMap<String, JSFileLibrary>();
    for (String rootKey : new String[] {"local", "core", "external"}) {
      Object temp = _scope.get(rootKey);
      if (temp instanceof JSFileLibrary) rootFileMap.put(rootKey, (JSFileLibrary) temp);
    }

    _scope.put(
        "fork",
        new JSFunctionCalls1() {
          public Object call(final Scope scope, final Object funcJS, final Object extra[]) {

            if (!(funcJS instanceof JSFunction))
              throw new JSException("fork has to take a function");

            return queueWork("forked", (JSFunction) funcJS, extra);
          }
        });
    _scope.lock("fork");

    ed.appserver.templates.djang10.JSHelper.install(_scope, rootFileMap, _logger);

    _scope.lock("user"); // protection against global user object
  }