Skip to content

Commit

Permalink
Copy from private repository
Browse files Browse the repository at this point in the history
  • Loading branch information
BSarmady committed Oct 28, 2022
1 parent db2795d commit c3f375b
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bin
obj
*.exe
*.suo
*.user
*.dll
*.pdb
.git
.vs
*.log
*.log.doc
15 changes: 15 additions & 0 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("Starts instance(s) of php in background")]
[assembly: AssemblyDescription("Starts instance(s) of php in background")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("JGhost")]
[assembly: AssemblyProduct("HiddenPHP")]
[assembly: AssemblyCopyright("© 2019-2022 JGhost")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
49 changes: 49 additions & 0 deletions HiddenPHP.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CD2A07B0-4C21-457C-8DC5-F82D89141DCD}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>HiddenPHP</RootNamespace>
<AssemblyName>HiddenPHP</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>.</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>.</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
25 changes: 25 additions & 0 deletions HiddenPHP.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31702.278
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HiddenPHP", "HiddenPHP.csproj", "{CD2A07B0-4C21-457C-8DC5-F82D89141DCD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CD2A07B0-4C21-457C-8DC5-F82D89141DCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CD2A07B0-4C21-457C-8DC5-F82D89141DCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD2A07B0-4C21-457C-8DC5-F82D89141DCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD2A07B0-4C21-457C-8DC5-F82D89141DCD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8C4D0B96-ECA9-49F0-A08D-92CC4CCF3C64}
EndGlobalSection
EndGlobal
97 changes: 97 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;

static class App {

private static bool StartPHP(string phpPath, UInt16 port) {
try {
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = phpPath;
psi.Arguments = " -b 127.0.0.1:" + port;
psi.CreateNoWindow = true;
psi.LoadUserProfile = false;
psi.RedirectStandardError = false;
psi.RedirectStandardOutput = false;
psi.UseShellExecute = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
//psi.WorkingDirectory = ".";
Process process = new Process();
process.StartInfo = psi;
process.Start();
return true;
} catch (Exception ex) {
Console.WriteLine(ex.Message);
return false;
}
}

[STAThread]
static int Main(string[] args) {
if (args.Length < 1) {
Console.WriteLine("Starts instance(s) of php in background.");
Console.WriteLine("Usage:");
Console.WriteLine(" HiddenPHP {Start Port[;End Port[;Increment]]");
Console.WriteLine("Example:");
Console.WriteLine(" HiddenPHP 9000 # starts one instance of php on port 9000");
Console.WriteLine(" HiddenPHP 9000;9500;100 # starts 5 instances of php on ports 9000,9100,9200,9300,9400");
return 0;
}

UInt16 start_port = 0;
UInt16 end_port = 0;
UInt16 increment = 1;

string[] parts = args[0].Split(';');
if (parts.Length < 1 || parts.Length > 3) {
Console.WriteLine("Error: invalid usage");
return -1;
}

try {
start_port = Convert.ToUInt16(parts[0]);
} catch {
Console.WriteLine(args[0] + " is not a valid port number");
return -1;
}

if (parts.Length > 1) {
try {
end_port = Convert.ToUInt16(parts[1]);
} catch {
Console.WriteLine(args[0] + " is not a valid port number");
return -1;
}
} else {
end_port = (ushort) (start_port + 1);
}
if (parts.Length > 2) {
try {
increment = Convert.ToUInt16(parts[2]);
if (increment < 1)
throw new Exception();
} catch {
Console.WriteLine("is not a valid increment number");
return -1;
}
}
if ((end_port - start_port) / increment > 32) {
Console.WriteLine("This utility can spawn maximum 32");
return -1;

}
string phpPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\php-cgi.exe";
if (!File.Exists(phpPath)) {
Console.WriteLine("php-cgi not found at '" + phpPath + "', this executable should be in same php folder that you want to run");
return 1;
}
Console.WriteLine("Executing PHP at " + phpPath);

for (UInt16 port = start_port;port < end_port;port += increment) {
Console.WriteLine("starting php on port " + port);
StartPHP(phpPath, port);
}
return 0;
}
}

0 comments on commit c3f375b

Please sign in to comment.